kopia lustrzana https://github.com/jameshball/osci-render
Add Lua function clear() to clear console from Lua
rodzic
b5969bfd7a
commit
beca0215cb
|
@ -27,6 +27,10 @@ OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioPr
|
|||
console.print(message);
|
||||
};
|
||||
|
||||
LuaParser::onClear = [this]() {
|
||||
console.clear();
|
||||
};
|
||||
|
||||
if (!usingNativeMenuBar) {
|
||||
menuBar.setModel(&menuBarModel);
|
||||
addAndMakeVisible(menuBar);
|
||||
|
|
|
@ -12,7 +12,7 @@ LuaConsole::LuaConsole() {
|
|||
startTimerHz(10);
|
||||
|
||||
clearConsoleButton.onClick = [this] {
|
||||
clear();
|
||||
clear(true);
|
||||
};
|
||||
|
||||
addAndMakeVisible(console);
|
||||
|
@ -42,18 +42,20 @@ void LuaConsole::print(const std::string& text) {
|
|||
}
|
||||
}
|
||||
|
||||
void LuaConsole::clear() {
|
||||
void LuaConsole::clear(bool forceClear) {
|
||||
juce::SpinLock::ScopedLockType l(lock);
|
||||
|
||||
document.replaceAllContent("");
|
||||
document.clearUndoHistory();
|
||||
consoleLines = 0;
|
||||
buffer.clear();
|
||||
if (forceClear || !pauseConsoleButton.getToggleState()) {
|
||||
document.replaceAllContent("");
|
||||
document.clearUndoHistory();
|
||||
consoleLines = 0;
|
||||
buffer.clear();
|
||||
|
||||
juce::MessageManager::callAsync([this] {
|
||||
console.setVisible(false);
|
||||
emptyConsoleLabel.setVisible(true);
|
||||
});
|
||||
juce::MessageManager::callAsync([this] {
|
||||
console.setVisible(false);
|
||||
emptyConsoleLabel.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void LuaConsole::timerCallback() {
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
~LuaConsole();
|
||||
|
||||
void print(const std::string& text);
|
||||
void clear();
|
||||
void clear(bool forceClear = false);
|
||||
void timerCallback() override;
|
||||
void setConsoleOpen(bool open);
|
||||
bool getConsoleOpen() { return consoleOpen; }
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
#include "luaimport.h"
|
||||
|
||||
std::function<void(const std::string&)> LuaParser::onPrint;
|
||||
std::function<void()> LuaParser::onClear;
|
||||
|
||||
static int customPrint(lua_State* L) {
|
||||
static int luaPrint(lua_State* L) {
|
||||
int nargs = lua_gettop(L);
|
||||
|
||||
for (int i = 1; i <= nargs; ++i) {
|
||||
|
@ -14,14 +15,20 @@ static int customPrint(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const struct luaL_Reg printlib[] = {
|
||||
{"print", customPrint},
|
||||
static int luaClear(lua_State* L) {
|
||||
LuaParser::onClear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct luaL_Reg luaLib[] = {
|
||||
{"print", luaPrint},
|
||||
{"clear", luaClear},
|
||||
{NULL, NULL} /* end of array */
|
||||
};
|
||||
|
||||
extern int luaopen_customprintlib(lua_State* L) {
|
||||
lua_getglobal(L, "_G");
|
||||
luaL_setfuncs(L, printlib, 0);
|
||||
luaL_setfuncs(L, luaLib, 0);
|
||||
lua_pop(L, 1);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
void close(lua_State*& L);
|
||||
|
||||
static std::function<void(const std::string&)> onPrint;
|
||||
static std::function<void()> onClear;
|
||||
|
||||
private:
|
||||
void reset(lua_State*& L, juce::String script);
|
||||
|
|
Ładowanie…
Reference in New Issue