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