diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GuiLua/GuiLua.c | 80 |
1 files changed, 78 insertions, 2 deletions
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 | |||
155 | */ | 155 | */ |
156 | 156 | ||
157 | 157 | ||
158 | static int traceBack(lua_State *L) | ||
159 | { | ||
160 | const char *msg = ""; | ||
161 | int top = lua_gettop(L); | ||
162 | // int i; | ||
163 | |||
164 | // printf("Stack is %d deep\n", top); | ||
165 | // for (i = 1; i <= top; i++) | ||
166 | // dumpStack(L, i); | ||
167 | |||
168 | if (top) | ||
169 | msg = lua_tostring(L, 1); | ||
170 | lua_getglobal(L, "debug"); | ||
171 | push_lua(L, "@ ( )", lua_gettop(L), "traceback", 1); | ||
172 | lua_pushstring(L, "\n"); | ||
173 | lua_pushstring(L, msg); | ||
174 | lua_concat(L, 3); | ||
175 | |||
176 | return 1; | ||
177 | } | ||
178 | |||
179 | |||
158 | // TODO - Should be able to open external and internal windows, and even switch between them on the fly. | 180 | // TODO - Should be able to open external and internal windows, and even switch between them on the fly. |
159 | static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) | 181 | static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) |
160 | { | 182 | { |
@@ -165,8 +187,62 @@ static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED | |||
165 | lua_State *L = wid->data; | 187 | lua_State *L = wid->data; |
166 | 188 | ||
167 | PD("Doing action %s", wid->action); | 189 | PD("Doing action %s", wid->action); |
168 | if (0 != luaL_dostring(L, wid->action)) | 190 | |
169 | PE("Error running - %s", wid->action); | 191 | /* |
192 | get the table wid->win->module from C registry | ||
193 | int lua_setfenv (lua_State *L, int index); // pop table from stack and set it as the environment for the value at index | ||
194 | // 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. | ||
195 | |||
196 | lauL_doString -> (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0)) | ||
197 | luaL_loadstring(L, str) -> lua_load -> pushes a function | ||
198 | */ | ||
199 | if (wid->win->module) | ||
200 | { | ||
201 | int _M, _T; | ||
202 | |||
203 | lua_getfield(L, LUA_REGISTRYINDEX, wid->win->module); | ||
204 | _M = lua_gettop(L); | ||
205 | lua_pushcfunction(L, traceBack); | ||
206 | _T = lua_gettop(L); | ||
207 | |||
208 | // Consistancy would be good, just sayin'. | ||
209 | if (luaL_loadstring(L, wid->action)) | ||
210 | { | ||
211 | const char *err = lua_tostring(L, 1); | ||
212 | |||
213 | PE("Error parsing - %s, ERROR %s", wid->action, err); | ||
214 | } | ||
215 | else | ||
216 | { | ||
217 | if (0 == lua_setfenv(L, _M)) | ||
218 | { | ||
219 | int err; | ||
220 | |||
221 | if ((err = lua_pcall(L, 0, LUA_MULTRET, _T))) | ||
222 | { | ||
223 | const char *err_type; | ||
224 | |||
225 | switch (err) | ||
226 | { | ||
227 | case LUA_ERRRUN: err_type = "runtime"; break; | ||
228 | case LUA_ERRSYNTAX: err_type = "syntax"; break; | ||
229 | case LUA_ERRMEM: err_type = "memory allocation"; break; | ||
230 | case LUA_ERRERR: err_type = "error handler"; break; | ||
231 | default: err_type = "unknown"; break; | ||
232 | } | ||
233 | PE("Error running - %s, \n%s - %s", wid->action, err_type, lua_tostring(L, -1)); | ||
234 | } | ||
235 | } | ||
236 | else | ||
237 | PE("Error setting environment for - %s", wid->action); | ||
238 | } | ||
239 | |||
240 | } | ||
241 | else | ||
242 | { | ||
243 | if (0 != luaL_dostring(L, wid->action)) | ||
244 | PE("Error running - %s", wid->action); | ||
245 | } | ||
170 | } | 246 | } |
171 | } | 247 | } |
172 | 248 | ||