aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/GuiLua
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-17 07:12:48 +1000
committerDavid Walter Seikel2014-05-17 07:12:48 +1000
commit312ca74b86dc0c59e0951533b25cc9a823de8414 (patch)
treea096528a4a3ba567794dbdb4773367c096c5c73a /src/GuiLua
parentMove a TODO. (diff)
downloadSledjHamr-312ca74b86dc0c59e0951533b25cc9a823de8414.zip
SledjHamr-312ca74b86dc0c59e0951533b25cc9a823de8414.tar.gz
SledjHamr-312ca74b86dc0c59e0951533b25cc9a823de8414.tar.bz2
SledjHamr-312ca74b86dc0c59e0951533b25cc9a823de8414.tar.xz
Clean up the complex pcall stuff.
Diffstat (limited to '')
-rw-r--r--src/GuiLua/GuiLua.c76
1 files changed, 31 insertions, 45 deletions
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
185 185
186 if (wid) 186 if (wid)
187 { 187 {
188 int _T, _A, err;
188 lua_State *L = wid->data; 189 lua_State *L = wid->data;
189 190
190 PD("Doing action %s", wid->action); 191 PD("Doing action %s", wid->action);
191 192
192/* 193 lua_pushcfunction(L, traceBack);
193get the table wid->win->module from C registry 194 _T = lua_gettop(L);
194int lua_setfenv (lua_State *L, int index); // pop table from stack and set it as the environment for the value at index
195 // 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.
196 195
197lauL_doString -> (luaL_loadstring(L, str) || lua_pcall(L, 0, LUA_MULTRET, 0)) 196 if (luaL_loadstring(L, wid->action))
198 luaL_loadstring(L, str) -> lua_load -> pushes a function
199*/
200 if (wid->win->module)
201 { 197 {
202 int _M, _T; 198 const char *err = lua_tostring(L, 1);
203
204 lua_getfield(L, LUA_REGISTRYINDEX, wid->win->module);
205 _M = lua_gettop(L);
206 lua_pushcfunction(L, traceBack);
207 _T = lua_gettop(L);
208 199
209 // Consistancy would be good, just sayin'. 200 PE("Error parsing - %s, ERROR %s", wid->action, err);
210 if (luaL_loadstring(L, wid->action)) 201 }
202 else
203 {
204 _A = lua_gettop(L);
205 if (wid->win->module)
211 { 206 {
212 const char *err = lua_tostring(L, 1); 207 PD("Setting environment for Lua pcall to %s", wid->win->module);
208 lua_getfield(L, LUA_REGISTRYINDEX, wid->win->module);
213 209
214 PE("Error parsing - %s, ERROR %s", wid->action, err); 210 // Consistancy would be good, just sayin'.
215 } 211 if (0 == lua_setfenv(L, _A))
216 else
217 {
218 if (0 == lua_setfenv(L, _M))
219 { 212 {
220 int err;
221
222 if ((err = lua_pcall(L, 0, LUA_MULTRET, _T)))
223 {
224 const char *err_type;
225
226 switch (err)
227 {
228 case LUA_ERRRUN: err_type = "runtime"; break;
229 case LUA_ERRSYNTAX: err_type = "syntax"; break;
230 case LUA_ERRMEM: err_type = "memory allocation"; break;
231 case LUA_ERRERR: err_type = "error handler"; break;
232 default: err_type = "unknown"; break;
233 }
234 PE("Error running - %s, \n%s - %s", wid->action, err_type, lua_tostring(L, -1));
235 }
236 }
237 else
238 PE("Error setting environment for - %s", wid->action); 213 PE("Error setting environment for - %s", wid->action);
214 return;
215 }
239 } 216 }
240 217
241 } 218 if ((err = lua_pcall(L, 0, LUA_MULTRET, _T)))
242 else 219 {
243 { 220 const char *err_type;
244 if (0 != luaL_dostring(L, wid->action)) 221
245 PE("Error running - %s", wid->action); 222 switch (err)
223 {
224 case LUA_ERRRUN: err_type = "runtime"; break;
225 case LUA_ERRSYNTAX: err_type = "syntax"; break;
226 case LUA_ERRMEM: err_type = "memory allocation"; break;
227 case LUA_ERRERR: err_type = "error handler"; break;
228 default: err_type = "unknown"; break;
229 }
230 PE("Error running - %s, \n%s - %s", wid->action, err_type, lua_tostring(L, -1));
231 }
246 } 232 }
247 } 233 }
248} 234}