diff options
Diffstat (limited to 'client/lua.cc')
-rw-r--r-- | client/lua.cc | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/client/lua.cc b/client/lua.cc index 3607a26..af64efb 100644 --- a/client/lua.cc +++ b/client/lua.cc @@ -106,39 +106,47 @@ void LUA::clear() register_widget(L); } -QString LUA::runParser(QString program) +QString LUA::runScriptS(QString script, Widget *widget, QString name) { if(L == NULL) { ERROR(lua, "LUA state not initialized!"); - return false; + return ""; } - DEBUG(lua, "Running %s\n", program.toStdString().c_str()); - int top = lua_gettop(L); + DEBUG(lua, "Running %s script %s on %s widget.\n", + name.toStdString().c_str(), + script.toStdString().c_str(), + widget?widget->name().toStdString().c_str():"NULL"); + + if(widget) { + wdg_make_widget(L, widget); + lua_setglobal(L, "this"); + } + if(luaL_loadbuffer(L, - program.toStdString().c_str(), - program.size(), - "parser")) { + script.toStdString().c_str(), + script.size(), + name.toStdString().c_str())) { ERROR(lua, "%s", lua_tostring(L, lua_gettop(L))); - return false; + return ""; } // Run the loaded code if(lua_pcall(L, 0, LUA_MULTRET, 0)) { ERROR(lua, "%s", lua_tostring(L, lua_gettop(L))); - return false; + return ""; } if(top != lua_gettop(L) - 1) { ERROR(lua, "Program did not return a single value.\n"); - return false; + return ""; } if(lua_isstring(L, lua_gettop(L)) == false) { ERROR(lua, "Program did not return a boolean value.\n"); - return false; + return ""; } QString res = lua_tostring(L, lua_gettop(L)); |