summaryrefslogtreecommitdiff
path: root/client/lua.cc
diff options
context:
space:
mode:
authordeva <deva>2010-08-17 14:29:05 +0000
committerdeva <deva>2010-08-17 14:29:05 +0000
commitd2295ad23ed22af07addc93b71e36f7bb688d534 (patch)
tree4915612e87646091275e291bae291951744585fc /client/lua.cc
parentb23c3c321b80449aa22e14d40115d1e4a764a1b3 (diff)
New format parser for metawidget et al. DBWidget is broken for the moment...
Diffstat (limited to 'client/lua.cc')
-rw-r--r--client/lua.cc30
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));