From f9e9da606e887ad367109df1763fe2eb500dc1a5 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 17 May 2014 08:06:29 +1000 Subject: Move the new pcall stuff to Runnr.c. --- src/GuiLua/GuiLua.c | 64 ++----------------------------------------------- src/libraries/Runnr.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/libraries/Runnr.h | 1 + 3 files changed, 69 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index 3bdada9..92254ea 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c @@ -144,6 +144,7 @@ and ordinary elementary widgets. Proper introspection can come later. #include "LumbrJack.h" #include "GuiLua.h" +#include "Runnr.h" static int logDom; // Our logging domain. @@ -158,77 +159,16 @@ win.quitter.colour.r = 5 -> direct access to the table, well "direct" via Th */ -static int traceBack(lua_State *L) -{ - const char *msg = ""; - int top = lua_gettop(L); -// int i; - -// printf("Stack is %d deep\n", top); -// for (i = 1; i <= top; i++) -// dumpStack(L, i); - - if (top) - msg = lua_tostring(L, 1); - lua_getglobal(L, "debug"); - push_lua(L, "@ ( )", lua_gettop(L), "traceback", 1); - lua_pushstring(L, "\n"); - lua_pushstring(L, msg); - lua_concat(L, 3); - - return 1; -} - static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) { Widget *wid = data; if (wid) { - int _T, _A, err; lua_State *L = wid->data; PD("Doing action %s", wid->action); - - lua_pushcfunction(L, traceBack); - _T = lua_gettop(L); - - if (luaL_loadstring(L, wid->action)) - { - const char *err = lua_tostring(L, 1); - - PE("Error parsing - %s, ERROR %s", wid->action, err); - } - else - { - _A = lua_gettop(L); - if (wid->win->module) - { - lua_getfield(L, LUA_REGISTRYINDEX, wid->win->module); - - // Consistancy would be good, just sayin'. - if (0 == lua_setfenv(L, _A)) - { - PE("Error setting environment for - %s", wid->action); - return; - } - } - - if ((err = lua_pcall(L, 0, LUA_MULTRET, _T))) - { - const char *err_type; - - switch (err) - { - case LUA_ERRRUN: err_type = "runtime"; break; - case LUA_ERRSYNTAX: err_type = "syntax"; break; - case LUA_ERRMEM: err_type = "memory allocation"; break; - case LUA_ERRERR: err_type = "error handler"; break; - default: err_type = "unknown"; break; - } - PE("Error running - %s, \n%s - %s", wid->action, err_type, lua_tostring(L, -1)); - } - } + doLuaString(L, wid->action, wid->win->module); } } diff --git a/src/libraries/Runnr.c b/src/libraries/Runnr.c index cff402e..238bfb2 100644 --- a/src/libraries/Runnr.c +++ b/src/libraries/Runnr.c @@ -38,6 +38,72 @@ void dumpStack(lua_State *L, int i) } } +static int traceBack(lua_State *L) +{ + const char *msg = ""; + int top = lua_gettop(L); +// int i; + +// printf("Stack is %d deep\n", top); +// for (i = 1; i <= top; i++) +// dumpStack(L, i); + + if (top) + msg = lua_tostring(L, 1); + lua_getglobal(L, "debug"); + push_lua(L, "@ ( )", lua_gettop(L), "traceback", 1); + lua_pushstring(L, "\n"); + lua_pushstring(L, msg); + lua_concat(L, 3); + + return 1; +} + +void doLuaString(lua_State *L, char *string, char *module) +{ + int _T, _A, err; + + lua_pushcfunction(L, traceBack); + _T = lua_gettop(L); + + if (luaL_loadstring(L, string)) + { + const char *err = lua_tostring(L, 1); + + printf("Error parsing - %s, ERROR %s", string, err); + } + else + { + _A = lua_gettop(L); + if (module) + { + lua_getfield(L, LUA_REGISTRYINDEX, module); + + // Consistancy would be good, just sayin'. + if (0 == lua_setfenv(L, _A)) + { + printf("Error setting environment for - %s", string); + return; + } + } + + if ((err = lua_pcall(L, 0, LUA_MULTRET, _T))) + { + const char *err_type; + + switch (err) + { + case LUA_ERRRUN: err_type = "runtime"; break; + case LUA_ERRSYNTAX: err_type = "syntax"; break; + case LUA_ERRMEM: err_type = "memory allocation"; break; + case LUA_ERRERR: err_type = "error handler"; break; + default: err_type = "unknown"; break; + } + printf("Error running - %s, \n%s - %s", string, err_type, lua_tostring(L, -1)); + } + } +} + // These are what the various symbols are for each type - // int % diff --git a/src/libraries/Runnr.h b/src/libraries/Runnr.h index d7386f6..5e3629d 100644 --- a/src/libraries/Runnr.h +++ b/src/libraries/Runnr.h @@ -13,6 +13,7 @@ void dumpStack(lua_State *L, int i); +void doLuaString(lua_State *L, char *string, char *module); int pull_lua(lua_State *L, int i, char *params, ...); int push_lua(lua_State *L, char *params, ...); -- cgit v1.1