aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/libraries
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/libraries/Runnr.c66
-rw-r--r--src/libraries/Runnr.h1
2 files changed, 67 insertions, 0 deletions
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