From d2aa6fc31b7b867b9eba402ac25f4e0014837191 Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 18 Aug 2010 15:18:07 +0000 Subject: New debug CFunction --- client/lua.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/client/lua.cc b/client/lua.cc index af64efb..8a18b1e 100644 --- a/client/lua.cc +++ b/client/lua.cc @@ -60,19 +60,31 @@ static int get_widget(lua_State *L) Widget *widget = lua->getWidget(name); - DEBUG(lua, "FIND: %s (%p)\n", name.toStdString().c_str(), widget); - if(widget) { wdg_make_widget(L, widget); } else { lua_pushnil(L); } - DEBUG(lua, "DONE\n"); - return 1; } +static int debug(lua_State *L) +{ + int n = lua_gettop(L); // number of arguments + if(n != 1) { + char errstr[512]; + sprintf(errstr, "Number of args expected 1, got %d", n); + lua_pushstring(L, errstr); + lua_error(L); + return 1; + } + + DEBUG(lua, "%s", lua_tostring(L, lua_gettop(L))); + + return 0; +} + LUA::LUA(Widget **rootwidget) { this->rootwidget = rootwidget; @@ -102,6 +114,7 @@ void LUA::clear() lua_setglobal(L, GLOBAL_POINTER); // Assign it to a global lua var. lua_register(L, "widget", get_widget); + lua_register(L, "debug", debug); register_widget(L); } -- cgit v1.2.3