From 4d7617cbf20985b7cf2231675d8aadd01f77c3d2 Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 2 Jul 2008 07:49:31 +0000 Subject: Added disable/enable methods on widgets and exposed them to lua. --- client/lua.cc | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'client/lua.cc') 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) { -- cgit v1.2.3