From f5475a9c4287a9d36306d2f5fac5931dd1c8da24 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Fri, 16 May 2014 19:06:37 +1000 Subject: Try to do actions in the environment of the window that owns the widget this is the action for. Still failing somehow, but not getting any useful errors. --- src/GuiLua/GuiLua.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) (limited to 'src/GuiLua/GuiLua.c') diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index 211f4e7..a3b5a58 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c @@ -155,6 +155,28 @@ 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; +} + + // TODO - Should be able to open external and internal windows, and even switch between them on the fly. static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) { @@ -165,8 +187,62 @@ static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED lua_State *L = wid->data; PD("Doing action %s", wid->action); - if (0 != luaL_dostring(L, wid->action)) - PE("Error running - %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. + +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) + { + int _M, _T; + + lua_getfield(L, LUA_REGISTRYINDEX, wid->win->module); + _M = lua_gettop(L); + lua_pushcfunction(L, traceBack); + _T = lua_gettop(L); + + // Consistancy would be good, just sayin'. + if (luaL_loadstring(L, wid->action)) + { + const char *err = lua_tostring(L, 1); + + PE("Error parsing - %s, ERROR %s", wid->action, err); + } + else + { + if (0 == lua_setfenv(L, _M)) + { + 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); + } + + } + else + { + if (0 != luaL_dostring(L, wid->action)) + PE("Error running - %s", wid->action); + } } } -- cgit v1.1