From 312ca74b86dc0c59e0951533b25cc9a823de8414 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 17 May 2014 07:12:48 +1000 Subject: Clean up the complex pcall stuff. --- src/GuiLua/GuiLua.c | 76 ++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 45 deletions(-) (limited to 'src/GuiLua/GuiLua.c') diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index 70d836e..f2f5a6c 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c @@ -185,64 +185,50 @@ static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED if (wid) { + int _T, _A, err; lua_State *L = wid->data; PD("Doing action %s", wid->action); -/* -get the table wid->win->module from C registry -int lua_setfenv (lua_State *L, int index); // pop table from stack and set it as the environment for the value at index - // If the value at the given index is neither a function nor a thread nor a userdata, lua_setfenv returns 0. Otherwise it returns 1. + lua_pushcfunction(L, traceBack); + _T = lua_gettop(L); -lauL_doString -> (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0)) - luaL_loadstring(L, str) -> lua_load -> pushes a function -*/ - if (wid->win->module) + if (luaL_loadstring(L, wid->action)) { - int _M, _T; - - lua_getfield(L, LUA_REGISTRYINDEX, wid->win->module); - _M = lua_gettop(L); - lua_pushcfunction(L, traceBack); - _T = lua_gettop(L); + const char *err = lua_tostring(L, 1); - // Consistancy would be good, just sayin'. - if (luaL_loadstring(L, wid->action)) + PE("Error parsing - %s, ERROR %s", wid->action, err); + } + else + { + _A = lua_gettop(L); + if (wid->win->module) { - const char *err = lua_tostring(L, 1); + PD("Setting environment for Lua pcall to %s", wid->win->module); + lua_getfield(L, LUA_REGISTRYINDEX, wid->win->module); - PE("Error parsing - %s, ERROR %s", wid->action, err); - } - else - { - if (0 == lua_setfenv(L, _M)) + // Consistancy would be good, just sayin'. + if (0 == lua_setfenv(L, _A)) { - int err; - - 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)); - } - } - else PE("Error setting environment for - %s", wid->action); + return; + } } - } - else - { - if (0 != luaL_dostring(L, wid->action)) - PE("Error running - %s", wid->action); + 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)); + } } } } -- cgit v1.1