diff options
Diffstat (limited to 'client/lua.cc')
-rw-r--r-- | client/lua.cc | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/client/lua.cc b/client/lua.cc index 1be850c..22249a4 100644 --- a/client/lua.cc +++ b/client/lua.cc @@ -30,6 +30,60 @@ #define GLOBAL_POINTER "_pracroGlobalLUAObjectPointerThisShouldBeANameThatIsNotAccidentallyOverwritten" +static int _enable(lua_State *L) +{ + int n = lua_gettop(L); // number of arguments + if(n != 1) { + char errstr[512]; + sprintf(errstr, "Number of args expected 0, got %d", n); + lua_pushstring(L, errstr); + lua_error(L); + return 1; + } + + QString name = lua_tostring(L, lua_gettop(L)); + + lua_getglobal(L, GLOBAL_POINTER); + LUA *lua = (LUA*)lua_touserdata(L, lua_gettop(L)); + + if(!lua) { + lua_pushstring(L, "No LUA pointer!"); + lua_error(L); + return 1; + } + + lua->enable(name); + + return 0; +} + +static int _disable(lua_State *L) +{ + int n = lua_gettop(L); // number of arguments + if(n != 1) { + char errstr[512]; + sprintf(errstr, "Number of args expected 0, got %d", n); + lua_pushstring(L, errstr); + lua_error(L); + return 1; + } + + QString name = lua_tostring(L, lua_gettop(L)); + + lua_getglobal(L, GLOBAL_POINTER); + LUA *lua = (LUA*)lua_touserdata(L, lua_gettop(L)); + + if(!lua) { + lua_pushstring(L, "No LUA pointer!"); + lua_error(L); + return 1; + } + + lua->disable(name); + + return 0; +} + static int _getValue(lua_State *L) { int n = lua_gettop(L); // number of arguments @@ -105,6 +159,8 @@ LUA::LUA(MacroWindow *macrowindow) lua_register(L, "getValue", _getValue); lua_register(L, "setValue", _setValue); + lua_register(L, "enable", _enable); + lua_register(L, "disable", _disable); } LUA::~LUA() @@ -122,6 +178,16 @@ void LUA::setValue(QString name, QString value) macrowindow->setValue(name, value); } +void LUA::enable(QString name) +{ + return macrowindow->enable(name); +} + +void LUA::disable(QString name) +{ + return macrowindow->disable(name); +} + bool LUA::run(QString program, QString name, QString value) { if(L == NULL) { |