aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-17 08:06:29 +1000
committerDavid Walter Seikel2014-05-17 08:06:29 +1000
commitf9e9da606e887ad367109df1763fe2eb500dc1a5 (patch)
tree9741192ca68445b2eab244bc332dfa73e3801bc9 /src
parentFake LSL listen() event. (diff)
downloadSledjHamr-f9e9da606e887ad367109df1763fe2eb500dc1a5.zip
SledjHamr-f9e9da606e887ad367109df1763fe2eb500dc1a5.tar.gz
SledjHamr-f9e9da606e887ad367109df1763fe2eb500dc1a5.tar.bz2
SledjHamr-f9e9da606e887ad367109df1763fe2eb500dc1a5.tar.xz
Move the new pcall stuff to Runnr.c.
Diffstat (limited to 'src')
-rw-r--r--src/GuiLua/GuiLua.c64
-rw-r--r--src/libraries/Runnr.c66
-rw-r--r--src/libraries/Runnr.h1
3 files changed, 69 insertions, 62 deletions
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.
144 144
145#include "LumbrJack.h" 145#include "LumbrJack.h"
146#include "GuiLua.h" 146#include "GuiLua.h"
147#include "Runnr.h"
147 148
148 149
149static int logDom; // Our logging domain. 150static int logDom; // Our logging domain.
@@ -158,77 +159,16 @@ win.quitter.colour.r = 5 -> direct access to the table, well "direct" via Th
158*/ 159*/
159 160
160 161
161static int traceBack(lua_State *L)
162{
163 const char *msg = "";
164 int top = lua_gettop(L);
165// int i;
166
167// printf("Stack is %d deep\n", top);
168// for (i = 1; i <= top; i++)
169// dumpStack(L, i);
170
171 if (top)
172 msg = lua_tostring(L, 1);
173 lua_getglobal(L, "debug");
174 push_lua(L, "@ ( )", lua_gettop(L), "traceback", 1);
175 lua_pushstring(L, "\n");
176 lua_pushstring(L, msg);
177 lua_concat(L, 3);
178
179 return 1;
180}
181
182static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) 162static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
183{ 163{
184 Widget *wid = data; 164 Widget *wid = data;
185 165
186 if (wid) 166 if (wid)
187 { 167 {
188 int _T, _A, err;
189 lua_State *L = wid->data; 168 lua_State *L = wid->data;
190 169
191 PD("Doing action %s", wid->action); 170 PD("Doing action %s", wid->action);
192 171 doLuaString(L, wid->action, wid->win->module);
193 lua_pushcfunction(L, traceBack);
194 _T = lua_gettop(L);
195
196 if (luaL_loadstring(L, wid->action))
197 {
198 const char *err = lua_tostring(L, 1);
199
200 PE("Error parsing - %s, ERROR %s", wid->action, err);
201 }
202 else
203 {
204 _A = lua_gettop(L);
205 if (wid->win->module)
206 {
207 lua_getfield(L, LUA_REGISTRYINDEX, wid->win->module);
208
209 // Consistancy would be good, just sayin'.
210 if (0 == lua_setfenv(L, _A))
211 {
212 PE("Error setting environment for - %s", wid->action);
213 return;
214 }
215 }
216
217 if ((err = lua_pcall(L, 0, LUA_MULTRET, _T)))
218 {
219 const char *err_type;
220
221 switch (err)
222 {
223 case LUA_ERRRUN: err_type = "runtime"; break;
224 case LUA_ERRSYNTAX: err_type = "syntax"; break;
225 case LUA_ERRMEM: err_type = "memory allocation"; break;
226 case LUA_ERRERR: err_type = "error handler"; break;
227 default: err_type = "unknown"; break;
228 }
229 PE("Error running - %s, \n%s - %s", wid->action, err_type, lua_tostring(L, -1));
230 }
231 }
232 } 172 }
233} 173}
234 174
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)
38 } 38 }
39} 39}
40 40
41static int traceBack(lua_State *L)
42{
43 const char *msg = "";
44 int top = lua_gettop(L);
45// int i;
46
47// printf("Stack is %d deep\n", top);
48// for (i = 1; i <= top; i++)
49// dumpStack(L, i);
50
51 if (top)
52 msg = lua_tostring(L, 1);
53 lua_getglobal(L, "debug");
54 push_lua(L, "@ ( )", lua_gettop(L), "traceback", 1);
55 lua_pushstring(L, "\n");
56 lua_pushstring(L, msg);
57 lua_concat(L, 3);
58
59 return 1;
60}
61
62void doLuaString(lua_State *L, char *string, char *module)
63{
64 int _T, _A, err;
65
66 lua_pushcfunction(L, traceBack);
67 _T = lua_gettop(L);
68
69 if (luaL_loadstring(L, string))
70 {
71 const char *err = lua_tostring(L, 1);
72
73 printf("Error parsing - %s, ERROR %s", string, err);
74 }
75 else
76 {
77 _A = lua_gettop(L);
78 if (module)
79 {
80 lua_getfield(L, LUA_REGISTRYINDEX, module);
81
82 // Consistancy would be good, just sayin'.
83 if (0 == lua_setfenv(L, _A))
84 {
85 printf("Error setting environment for - %s", string);
86 return;
87 }
88 }
89
90 if ((err = lua_pcall(L, 0, LUA_MULTRET, _T)))
91 {
92 const char *err_type;
93
94 switch (err)
95 {
96 case LUA_ERRRUN: err_type = "runtime"; break;
97 case LUA_ERRSYNTAX: err_type = "syntax"; break;
98 case LUA_ERRMEM: err_type = "memory allocation"; break;
99 case LUA_ERRERR: err_type = "error handler"; break;
100 default: err_type = "unknown"; break;
101 }
102 printf("Error running - %s, \n%s - %s", string, err_type, lua_tostring(L, -1));
103 }
104 }
105}
106
41 107
42// These are what the various symbols are for each type - 108// These are what the various symbols are for each type -
43// int % 109// 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 @@
13 13
14 14
15void dumpStack(lua_State *L, int i); 15void dumpStack(lua_State *L, int i);
16void doLuaString(lua_State *L, char *string, char *module);
16int pull_lua(lua_State *L, int i, char *params, ...); 17int pull_lua(lua_State *L, int i, char *params, ...);
17int push_lua(lua_State *L, char *params, ...); 18int push_lua(lua_State *L, char *params, ...);
18 19