summaryrefslogtreecommitdiff
path: root/client/lua.cc
diff options
context:
space:
mode:
authordeva <deva>2010-08-17 11:14:04 +0000
committerdeva <deva>2010-08-17 11:14:04 +0000
commitc788e6a1b174afd154e589a76885731c2fc19723 (patch)
tree761a87ee3941d671dd41d8b6df7a39bd85c993b1 /client/lua.cc
parent2a9d0cf8c52a832c04729a4c65f07e6cd24eb19e (diff)
First shot at a debug console.
Diffstat (limited to 'client/lua.cc')
-rw-r--r--client/lua.cc39
1 files changed, 18 insertions, 21 deletions
diff --git a/client/lua.cc b/client/lua.cc
index eb9b8a3..3607a26 100644
--- a/client/lua.cc
+++ b/client/lua.cc
@@ -32,8 +32,7 @@
#include "luawidget.h"
-//#define DEBUG(fmt...) printf("LUA (%p)", this); printf(fmt); fflush(stdout)
-#define DEBUG(ftm...)
+#include "debug.h"
#define GLOBAL_POINTER "_pracroGlobalLUAObjectPointerThisShouldBeANameThatIsNotAccidentallyOverwritten"
@@ -61,7 +60,7 @@ static int get_widget(lua_State *L)
Widget *widget = lua->getWidget(name);
- // DEBUG("FIND: %s (%p)\n", name.toStdString().c_str(), widget);
+ DEBUG(lua, "FIND: %s (%p)\n", name.toStdString().c_str(), widget);
if(widget) {
wdg_make_widget(L, widget);
@@ -69,7 +68,7 @@ static int get_widget(lua_State *L)
lua_pushnil(L);
}
- // DEBUG("DONE\n");
+ DEBUG(lua, "DONE\n");
return 1;
}
@@ -93,7 +92,7 @@ void LUA::clear()
L = luaL_newstate();
if(L == NULL) {
- error("Could not create LUA state.");
+ ERROR(lua, "Could not create LUA state.");
return;
}
@@ -110,11 +109,11 @@ void LUA::clear()
QString LUA::runParser(QString program)
{
if(L == NULL) {
- error("LUA state not initialized!");
+ ERROR(lua, "LUA state not initialized!");
return false;
}
- DEBUG("Running %s\n", program.toStdString().c_str());
+ DEBUG(lua, "Running %s\n", program.toStdString().c_str());
int top = lua_gettop(L);
@@ -122,23 +121,23 @@ QString LUA::runParser(QString program)
program.toStdString().c_str(),
program.size(),
"parser")) {
- error(lua_tostring(L, lua_gettop(L)));
+ ERROR(lua, "%s", lua_tostring(L, lua_gettop(L)));
return false;
}
// Run the loaded code
if(lua_pcall(L, 0, LUA_MULTRET, 0)) {
- error(lua_tostring(L, lua_gettop(L)));
+ ERROR(lua, "%s", lua_tostring(L, lua_gettop(L)));
return false;
}
if(top != lua_gettop(L) - 1) {
- error("Program did not return a single value.\n");
+ ERROR(lua, "Program did not return a single value.\n");
return false;
}
if(lua_isstring(L, lua_gettop(L)) == false) {
- error("Program did not return a boolean value.\n");
+ ERROR(lua, "Program did not return a boolean value.\n");
return false;
}
@@ -151,11 +150,11 @@ QString LUA::runParser(QString program)
bool LUA::runScript(QString script, Widget *widget, QString name)
{
if(L == NULL) {
- error("LUA state not initialized!");
+ ERROR(lua, "LUA state not initialized!");
return false;
}
- DEBUG("Running %s script %s on %s widget.\n",
+ 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");
@@ -169,26 +168,24 @@ bool LUA::runScript(QString script, Widget *widget, QString name)
script.toStdString().c_str(),
script.size(),
name.toStdString().c_str())) {
- error(lua_tostring(L, lua_gettop(L)));
+ ERROR(lua, "%s", lua_tostring(L, lua_gettop(L)));
return false;
}
// Run the loaded code
if(lua_pcall(L, 0, LUA_MULTRET, 0)) {
- error(lua_tostring(L, lua_gettop(L)));
+ ERROR(lua, "%s", lua_tostring(L, lua_gettop(L)));
return false;
}
return true;
}
-void LUA::error(QString message)
-{
- printf("LUA ERROR: %s\n", message.toStdString().c_str());
-}
-
Widget *LUA::getWidget(QString name)
{
if(*rootwidget) return (*rootwidget)->findWidget(name, true);
- else return NULL;
+ else {
+ WARN(lua, "Could not find widget '%s'", name.toStdString().c_str());
+ return NULL;
+ }
}