From d2295ad23ed22af07addc93b71e36f7bb688d534 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 17 Aug 2010 14:29:05 +0000 Subject: New format parser for metawidget et al. DBWidget is broken for the moment... --- client/lua.cc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'client/lua.cc') 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)); -- cgit v1.2.3