diff options
author | David Walter Seikel | 2012-02-05 13:09:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-02-05 13:09:13 +1000 |
commit | b8ac69f1c3e21822b1d4e0713b2d77331f29c9aa (patch) | |
tree | bc9c7396edfadc3b65312865749239839ef032d7 /LuaSL | |
parent | Merge doneParsing(), it's only used once. (diff) | |
download | SledjHamr-b8ac69f1c3e21822b1d4e0713b2d77331f29c9aa.zip SledjHamr-b8ac69f1c3e21822b1d4e0713b2d77331f29c9aa.tar.gz SledjHamr-b8ac69f1c3e21822b1d4e0713b2d77331f29c9aa.tar.bz2 SledjHamr-b8ac69f1c3e21822b1d4e0713b2d77331f29c9aa.tar.xz |
Turn on the script running stuff, clean out the now excess tests, then move the runner to it's own file.
Diffstat (limited to 'LuaSL')
-rwxr-xr-x | LuaSL/build.sh | 2 | ||||
-rw-r--r-- | LuaSL/src/LuaSL.h | 9 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_main.c | 245 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_runner.c | 160 |
4 files changed, 169 insertions, 247 deletions
diff --git a/LuaSL/build.sh b/LuaSL/build.sh index 4433120..edddb31 100755 --- a/LuaSL/build.sh +++ b/LuaSL/build.sh | |||
@@ -63,7 +63,7 @@ command="edje_cc $EDJE_FLAGS LuaSL.edc ../LuaSL.edj" | |||
63 | echo $command | 63 | echo $command |
64 | $command | 64 | $command |
65 | 65 | ||
66 | names="LuaSL_main LuaSL_compile LuaSL_utilities LuaSL_lexer LuaSL_lemon_yaccer" | 66 | names="LuaSL_main LuaSL_compile LuaSL_runner LuaSL_utilities LuaSL_lexer LuaSL_lemon_yaccer" |
67 | objects="../../libraries/luaproc/channel.o ../../libraries/luaproc/list.o ../../libraries/luaproc/luaproc.o ../../libraries/luaproc/sched.o " | 67 | objects="../../libraries/luaproc/channel.o ../../libraries/luaproc/list.o ../../libraries/luaproc/luaproc.o ../../libraries/luaproc/sched.o " |
68 | for i in $names | 68 | for i in $names |
69 | do | 69 | do |
diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h index e3b7065..c35b394 100644 --- a/LuaSL/src/LuaSL.h +++ b/LuaSL/src/LuaSL.h | |||
@@ -13,7 +13,7 @@ | |||
13 | #include <Edje.h> | 13 | #include <Edje.h> |
14 | #include <stdio.h> | 14 | #include <stdio.h> |
15 | #include <ctype.h> | 15 | #include <ctype.h> |
16 | 16 | ||
17 | #define WIDTH (1024) | 17 | #define WIDTH (1024) |
18 | #define HEIGHT (768) | 18 | #define HEIGHT (768) |
19 | 19 | ||
@@ -41,7 +41,7 @@ | |||
41 | // NEVER change this | 41 | // NEVER change this |
42 | typedef enum | 42 | typedef enum |
43 | { | 43 | { |
44 | FALSE = 0, | 44 | FALSE = 0, |
45 | TRUE = 1 | 45 | TRUE = 1 |
46 | } boolean; | 46 | } boolean; |
47 | #endif | 47 | #endif |
@@ -60,9 +60,12 @@ typedef struct | |||
60 | boolean compilerSetup(gameGlobals *game); | 60 | boolean compilerSetup(gameGlobals *game); |
61 | boolean compileLSL(gameGlobals *game, char *script, boolean doConstants); | 61 | boolean compileLSL(gameGlobals *game, char *script, boolean doConstants); |
62 | 62 | ||
63 | void runnerSetup(gameGlobals *game); | ||
64 | void runnerTearDown(gameGlobals *game); | ||
65 | void runLuaFile(gameGlobals *game, const char *filename); | ||
66 | |||
63 | void loggingStartup(gameGlobals *game); | 67 | void loggingStartup(gameGlobals *game); |
64 | char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); | 68 | char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); |
65 | float timeDiff(struct timeval *now, struct timeval *then); | 69 | float timeDiff(struct timeval *now, struct timeval *then); |
66 | 70 | ||
67 | #include "LuaSL_LSL_tree.h" | 71 | #include "LuaSL_LSL_tree.h" |
68 | |||
diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index 5601dde..247b360 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c | |||
@@ -1,7 +1,6 @@ | |||
1 | 1 | ||
2 | #include "LuaSL.h" | 2 | #include "LuaSL.h" |
3 | 3 | ||
4 | #define LUA_TEST 0 | ||
5 | 4 | ||
6 | static int scriptCount; | 5 | static int scriptCount; |
7 | 6 | ||
@@ -84,188 +83,13 @@ static void dirList_cb(const char *name, const char *path, void *data) | |||
84 | scriptCount++; | 83 | scriptCount++; |
85 | snprintf(buf, sizeof(buf), "%s/%s", path, name); | 84 | snprintf(buf, sizeof(buf), "%s/%s", path, name); |
86 | if (compileLSL(game, buf, FALSE)) | 85 | if (compileLSL(game, buf, FALSE)) |
87 | PD("Against all odds, the compile of %s worked! lol", buf); | 86 | PD("The compile of %s worked,", buf); |
88 | else | 87 | else |
89 | PE("The compile of %s failed!", buf); | 88 | PE("The compile of %s failed!", buf); |
90 | } | 89 | } |
91 | } | 90 | } |
92 | } | 91 | } |
93 | 92 | ||
94 | #if LUA_TEST | ||
95 | static void dirListLua_cb(const char *name, const char *path, void *data) | ||
96 | { | ||
97 | char buf[PATH_MAX]; | ||
98 | char *ext = rindex(name, '.'); | ||
99 | |||
100 | if (ext) | ||
101 | { | ||
102 | if (0 == strcmp(ext, ".lua")) | ||
103 | { | ||
104 | scriptCount++; | ||
105 | snprintf(buf, sizeof(buf), "luac %s/%s 2>/dev/null", path, name); | ||
106 | system(buf); | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | |||
111 | #ifdef _WIN32 | ||
112 | # define FMT_SIZE_T "%Iu" | ||
113 | #else | ||
114 | # define FMT_SIZE_T "%zu" | ||
115 | #endif | ||
116 | |||
117 | #define MAX_LUA_MEM (4 * (1024 * 1024)) | ||
118 | |||
119 | #define _edje_lua2_error(L, err_code) _edje_lua2_error_full(__FILE__, __FUNCTION__, __LINE__, L, err_code) | ||
120 | |||
121 | /* | ||
122 | typedef struct _Edje_Lua_Alloc Edje_Lua_Alloc; | ||
123 | |||
124 | struct _Edje_Lua_Alloc | ||
125 | { | ||
126 | size_t max, cur; | ||
127 | }; | ||
128 | |||
129 | static void * | ||
130 | _elua_alloc(void *ud, void *ptr, size_t osize, size_t nsize) | ||
131 | { | ||
132 | Edje_Lua_Alloc *ela = ud; | ||
133 | void *ptr2 = NULL; | ||
134 | |||
135 | if (ela) | ||
136 | { | ||
137 | ela->cur += nsize - osize; | ||
138 | if (ela->cur > ela->max) | ||
139 | { | ||
140 | printf("Lua memory limit of " FMT_SIZE_T " bytes reached (" FMT_SIZE_T " allocated)", ela->max, ela->cur); | ||
141 | } | ||
142 | else if (nsize == 0) | ||
143 | { | ||
144 | free(ptr); | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | ptr2 = realloc(ptr, nsize); | ||
149 | if (NULL == ptr2) | ||
150 | printf("Lua cannot re-allocate " FMT_SIZE_T " bytes", nsize); | ||
151 | } | ||
152 | } | ||
153 | else | ||
154 | printf("Lua cannoct allocate memory, no Edje_Lua_Alloc"); | ||
155 | |||
156 | return ptr2; | ||
157 | } | ||
158 | |||
159 | static int panics = 0; | ||
160 | static int | ||
161 | _elua_custom_panic(lua_State *L) // Stack usage [-0, +0, m] | ||
162 | { | ||
163 | // If we somehow manage to have multiple panics, it's likely due to being out | ||
164 | // of memory in the following lua_tostring() call. | ||
165 | panics++; | ||
166 | if (panics) | ||
167 | { | ||
168 | printf("Lua PANICS!!!!!"); | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | printf("Lua PANIC!!!!!: %s", lua_tostring(L, -1)); // Stack usage [-0, +0, m] | ||
173 | } | ||
174 | // The docs say that this will cause an exit(EXIT_FAILURE) if we return, | ||
175 | // and that we we should long jump some where to avoid that. This is only | ||
176 | // called for things not called from a protected environment. We always | ||
177 | // use pcalls though, except for the library load calls. If we can't load | ||
178 | // the standard libraries, then perhaps a crash is the right thing. | ||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | static void | ||
183 | _edje_lua2_error_full(const char *file, const char *fnc, int line, | ||
184 | lua_State *L, int err_code) // Stack usage [-0, +0, m] | ||
185 | { | ||
186 | const char *err_type; | ||
187 | |||
188 | switch (err_code) | ||
189 | { | ||
190 | case LUA_ERRRUN: | ||
191 | err_type = "runtime"; | ||
192 | break; | ||
193 | case LUA_ERRSYNTAX: | ||
194 | err_type = "syntax"; | ||
195 | break; | ||
196 | case LUA_ERRMEM: | ||
197 | err_type = "memory allocation"; | ||
198 | break; | ||
199 | case LUA_ERRERR: | ||
200 | err_type = "error handler"; | ||
201 | break; | ||
202 | default: | ||
203 | err_type = "unknown"; | ||
204 | break; | ||
205 | } | ||
206 | printf("Lua %s error: %s\n", err_type, lua_tostring(L, -1)); // Stack usage [-0, +0, m] | ||
207 | } | ||
208 | |||
209 | static int errFunc(lua_State *L) | ||
210 | { | ||
211 | int i = 0; | ||
212 | lua_Debug ar; | ||
213 | |||
214 | while (lua_getstack(L, i++, &ar)) | ||
215 | { | ||
216 | if (lua_getinfo(L, "nSlu", &ar)) | ||
217 | { | ||
218 | if (NULL == ar.name) | ||
219 | ar.name = "DUNNO"; | ||
220 | printf("Lua error in the %s %s %s @ line %d in %s\n%s!", ar.what, ar.namewhat, ar.name, ar.currentline, ar.short_src, ar.source); | ||
221 | } | ||
222 | } | ||
223 | return 0; | ||
224 | } | ||
225 | */ | ||
226 | |||
227 | static void runnerSetup(gameGlobals *game) | ||
228 | { | ||
229 | luaprocInit(); | ||
230 | |||
231 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
232 | PE("Error creating luaproc worker thread."); | ||
233 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
234 | PE("Error creating luaproc worker thread."); | ||
235 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
236 | PE("Error creating luaproc worker thread."); | ||
237 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
238 | PE("Error creating luaproc worker thread."); | ||
239 | } | ||
240 | |||
241 | static void runnerTearDown(gameGlobals *game) | ||
242 | { | ||
243 | // TODO - this is what hangs the system. | ||
244 | sched_join_workerthreads(); | ||
245 | } | ||
246 | |||
247 | static void runLuaFile(gameGlobals *game, const char *filename) | ||
248 | { | ||
249 | newProc(filename, TRUE); | ||
250 | |||
251 | // TODO, should set up our panic and errfunc as below. Plus the other TODO stuff. | ||
252 | |||
253 | /* | ||
254 | // TODO - hack up LuaJIT so that we can limit memory per state. | ||
255 | // lua_setallocf(L, _elua_alloc, &ela); // LuaJIT uses a heavily hacked up dlmalloc. Seems that standard realloc is not so thread safe? | ||
256 | lua_atpanic(L, _elua_custom_panic); | ||
257 | // TODO - Sandbox out what this opens. See lib_init.c from LuaJIT. | ||
258 | // Just noticed this in the LuaJIT docs - "To change or extend the list of standard libraries to load, copy src/lib_init.c to your project and modify it accordingly. Make sure the jit library is loaded or the JIT compiler will not be activated." | ||
259 | luaL_openlibs(L); | ||
260 | |||
261 | lua_pushcfunction(L, errFunc); | ||
262 | ... | ||
263 | if ((err = lua_pcall(L, 0, 0, -2))) | ||
264 | _edje_lua2_error(L, err); | ||
265 | */ | ||
266 | } | ||
267 | |||
268 | #endif | ||
269 | 93 | ||
270 | int | 94 | int |
271 | main(int argc, char **argv) | 95 | main(int argc, char **argv) |
@@ -329,10 +153,6 @@ main(int argc, char **argv) | |||
329 | struct timeval lastTime2; | 153 | struct timeval lastTime2; |
330 | struct timeval thisTime2; | 154 | struct timeval thisTime2; |
331 | float diff; | 155 | float diff; |
332 | #if LUA_TEST | ||
333 | unsigned int lslCount; | ||
334 | float diff0; | ||
335 | #endif | ||
336 | 156 | ||
337 | if (game.ui) | 157 | if (game.ui) |
338 | { | 158 | { |
@@ -405,71 +225,14 @@ main(int argc, char **argv) | |||
405 | 225 | ||
406 | // Do the compiles. | 226 | // Do the compiles. |
407 | scriptCount = 0; | 227 | scriptCount = 0; |
408 | gettimeofday(&lastTime2, 0); | ||
409 | compilerSetup(&game); | 228 | compilerSetup(&game); |
410 | #if LUA_TEST | ||
411 | runnerSetup(&game); | 229 | runnerSetup(&game); |
412 | #endif | 230 | gettimeofday(&lastTime2, 0); |
413 | snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR); | 231 | snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR); |
414 | eina_file_dir_list(buf, EINA_TRUE, dirList_cb, &game); | 232 | eina_file_dir_list(buf, EINA_TRUE, dirList_cb, &game); |
415 | diff = timeDiff(&thisTime2, &lastTime2); | 233 | diff = timeDiff(&thisTime2, &lastTime2); |
416 | printf("Compiling %d LSL scripts took %f seconds, that's %f scripts per second.\n", scriptCount, diff, scriptCount / diff); | 234 | printf("Compiling %d LSL scripts took %f seconds, that's %f scripts per second.\n", scriptCount, diff, scriptCount / diff); |
417 | 235 | ||
418 | #if LUA_TEST | ||
419 | lslCount = scriptCount; | ||
420 | diff0 = diff; | ||
421 | scriptCount = 0; | ||
422 | gettimeofday(&lastTime2, 0); | ||
423 | snprintf(buf, sizeof(buf), "%s/testLua", PACKAGE_DATA_DIR); | ||
424 | eina_file_dir_list(buf, EINA_TRUE, dirListLua_cb, &game); | ||
425 | diff = timeDiff(&thisTime2, &lastTime2); | ||
426 | printf("Compiling %d Lua scripts took %f seconds, that's %f scripts per second.\n\n", scriptCount, diff, scriptCount / diff); | ||
427 | |||
428 | printf("Combined estimate of compiling speed is %f scripts per second.\n", 1 / ((diff0 / lslCount) + (diff / scriptCount))); | ||
429 | |||
430 | gettimeofday(&lastTime2, 0); | ||
431 | snprintf(buf, sizeof(buf), "lua luaprocTest0.lua"); | ||
432 | system(buf); | ||
433 | diff = timeDiff(&thisTime2, &lastTime2); | ||
434 | printf("%s TOOK %f seconds......................................................................................................\n", buf, diff); | ||
435 | |||
436 | gettimeofday(&lastTime2, 0); | ||
437 | snprintf(buf, sizeof(buf), "%s/testLua/luaprocTest0_C.lua", PACKAGE_DATA_DIR); | ||
438 | runLuaFile(&game, buf); | ||
439 | diff = timeDiff(&thisTime2, &lastTime2); | ||
440 | printf("Running that last one locally TOOK %f seconds.\n",diff); | ||
441 | |||
442 | gettimeofday(&lastTime2, 0); | ||
443 | snprintf(buf, sizeof(buf), "lua luaprocTest1.lua"); | ||
444 | system(buf); | ||
445 | diff = timeDiff(&thisTime2, &lastTime2); | ||
446 | printf("%s TOOK %f seconds.\n", buf, diff); | ||
447 | |||
448 | gettimeofday(&lastTime2, 0); | ||
449 | snprintf(buf, sizeof(buf), "../../libraries/luajit-2.0/src/luajit luaprocTest1.lua"); | ||
450 | system(buf); | ||
451 | diff = timeDiff(&thisTime2, &lastTime2); | ||
452 | printf("%s TOOK %f seconds.\n", buf, diff); | ||
453 | |||
454 | gettimeofday(&lastTime2, 0); | ||
455 | snprintf(buf, sizeof(buf), "lua luaprocTest2.lua"); | ||
456 | system(buf); | ||
457 | diff = timeDiff(&thisTime2, &lastTime2); | ||
458 | printf("%s TOOK %f seconds.\n", buf, diff); | ||
459 | |||
460 | gettimeofday(&lastTime2, 0); | ||
461 | snprintf(buf, sizeof(buf), "../../libraries/luajit-2.0/src/luajit luaprocTest2.lua"); | ||
462 | system(buf); | ||
463 | diff = timeDiff(&thisTime2, &lastTime2); | ||
464 | printf("%s TOOK %f seconds.\n", buf, diff); | ||
465 | |||
466 | gettimeofday(&lastTime2, 0); | ||
467 | snprintf(buf, sizeof(buf), "%s/testLua/luaprocTest2_C.lua", PACKAGE_DATA_DIR); | ||
468 | runLuaFile(&game, buf); | ||
469 | diff = timeDiff(&thisTime2, &lastTime2); | ||
470 | printf("Running that last one locally TOOK %f seconds.\n",diff); | ||
471 | #endif | ||
472 | |||
473 | if (game.ui) | 236 | if (game.ui) |
474 | { | 237 | { |
475 | ecore_main_loop_begin(); | 238 | ecore_main_loop_begin(); |
@@ -477,11 +240,7 @@ main(int argc, char **argv) | |||
477 | ecore_evas_free(game.ee); | 240 | ecore_evas_free(game.ee); |
478 | } | 241 | } |
479 | 242 | ||
480 | #if LUA_TEST | ||
481 | runnerTearDown(&game); | 243 | runnerTearDown(&game); |
482 | diff = timeDiff(&thisTime2, &lastTime2); | ||
483 | printf("Running that last one locally TOOK %f seconds.\n",diff); | ||
484 | #endif | ||
485 | edje_shutdown(); | 244 | edje_shutdown(); |
486 | ecore_evas_shutdown(); | 245 | ecore_evas_shutdown(); |
487 | } | 246 | } |
diff --git a/LuaSL/src/LuaSL_runner.c b/LuaSL/src/LuaSL_runner.c new file mode 100644 index 0000000..411c437 --- /dev/null +++ b/LuaSL/src/LuaSL_runner.c | |||
@@ -0,0 +1,160 @@ | |||
1 | |||
2 | #include "LuaSL.h" | ||
3 | |||
4 | |||
5 | #ifdef _WIN32 | ||
6 | # define FMT_SIZE_T "%Iu" | ||
7 | #else | ||
8 | # define FMT_SIZE_T "%zu" | ||
9 | #endif | ||
10 | |||
11 | #define MAX_LUA_MEM (4 * (1024 * 1024)) | ||
12 | |||
13 | #define _edje_lua2_error(L, err_code) _edje_lua2_error_full(__FILE__, __FUNCTION__, __LINE__, L, err_code) | ||
14 | |||
15 | /* | ||
16 | typedef struct _Edje_Lua_Alloc Edje_Lua_Alloc; | ||
17 | |||
18 | struct _Edje_Lua_Alloc | ||
19 | { | ||
20 | size_t max, cur; | ||
21 | }; | ||
22 | |||
23 | static void * | ||
24 | _elua_alloc(void *ud, void *ptr, size_t osize, size_t nsize) | ||
25 | { | ||
26 | Edje_Lua_Alloc *ela = ud; | ||
27 | void *ptr2 = NULL; | ||
28 | |||
29 | if (ela) | ||
30 | { | ||
31 | ela->cur += nsize - osize; | ||
32 | if (ela->cur > ela->max) | ||
33 | { | ||
34 | printf("Lua memory limit of " FMT_SIZE_T " bytes reached (" FMT_SIZE_T " allocated)", ela->max, ela->cur); | ||
35 | } | ||
36 | else if (nsize == 0) | ||
37 | { | ||
38 | free(ptr); | ||
39 | } | ||
40 | else | ||
41 | { | ||
42 | ptr2 = realloc(ptr, nsize); | ||
43 | if (NULL == ptr2) | ||
44 | printf("Lua cannot re-allocate " FMT_SIZE_T " bytes", nsize); | ||
45 | } | ||
46 | } | ||
47 | else | ||
48 | printf("Lua cannoct allocate memory, no Edje_Lua_Alloc"); | ||
49 | |||
50 | return ptr2; | ||
51 | } | ||
52 | |||
53 | static int panics = 0; | ||
54 | static int | ||
55 | _elua_custom_panic(lua_State *L) // Stack usage [-0, +0, m] | ||
56 | { | ||
57 | // If we somehow manage to have multiple panics, it's likely due to being out | ||
58 | // of memory in the following lua_tostring() call. | ||
59 | panics++; | ||
60 | if (panics) | ||
61 | { | ||
62 | printf("Lua PANICS!!!!!"); | ||
63 | } | ||
64 | else | ||
65 | { | ||
66 | printf("Lua PANIC!!!!!: %s", lua_tostring(L, -1)); // Stack usage [-0, +0, m] | ||
67 | } | ||
68 | // The docs say that this will cause an exit(EXIT_FAILURE) if we return, | ||
69 | // and that we we should long jump some where to avoid that. This is only | ||
70 | // called for things not called from a protected environment. We always | ||
71 | // use pcalls though, except for the library load calls. If we can't load | ||
72 | // the standard libraries, then perhaps a crash is the right thing. | ||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | static void | ||
77 | _edje_lua2_error_full(const char *file, const char *fnc, int line, | ||
78 | lua_State *L, int err_code) // Stack usage [-0, +0, m] | ||
79 | { | ||
80 | const char *err_type; | ||
81 | |||
82 | switch (err_code) | ||
83 | { | ||
84 | case LUA_ERRRUN: | ||
85 | err_type = "runtime"; | ||
86 | break; | ||
87 | case LUA_ERRSYNTAX: | ||
88 | err_type = "syntax"; | ||
89 | break; | ||
90 | case LUA_ERRMEM: | ||
91 | err_type = "memory allocation"; | ||
92 | break; | ||
93 | case LUA_ERRERR: | ||
94 | err_type = "error handler"; | ||
95 | break; | ||
96 | default: | ||
97 | err_type = "unknown"; | ||
98 | break; | ||
99 | } | ||
100 | printf("Lua %s error: %s\n", err_type, lua_tostring(L, -1)); // Stack usage [-0, +0, m] | ||
101 | } | ||
102 | |||
103 | static int errFunc(lua_State *L) | ||
104 | { | ||
105 | int i = 0; | ||
106 | lua_Debug ar; | ||
107 | |||
108 | while (lua_getstack(L, i++, &ar)) | ||
109 | { | ||
110 | if (lua_getinfo(L, "nSlu", &ar)) | ||
111 | { | ||
112 | if (NULL == ar.name) | ||
113 | ar.name = "DUNNO"; | ||
114 | printf("Lua error in the %s %s %s @ line %d in %s\n%s!", ar.what, ar.namewhat, ar.name, ar.currentline, ar.short_src, ar.source); | ||
115 | } | ||
116 | } | ||
117 | return 0; | ||
118 | } | ||
119 | */ | ||
120 | |||
121 | void runnerSetup(gameGlobals *game) | ||
122 | { | ||
123 | luaprocInit(); | ||
124 | |||
125 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
126 | PE("Error creating luaproc worker thread."); | ||
127 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
128 | PE("Error creating luaproc worker thread."); | ||
129 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
130 | PE("Error creating luaproc worker thread."); | ||
131 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
132 | PE("Error creating luaproc worker thread."); | ||
133 | } | ||
134 | |||
135 | void runnerTearDown(gameGlobals *game) | ||
136 | { | ||
137 | // TODO - this is what hangs the system. | ||
138 | sched_join_workerthreads(); | ||
139 | } | ||
140 | |||
141 | void runLuaFile(gameGlobals *game, const char *filename) | ||
142 | { | ||
143 | newProc(filename, TRUE); | ||
144 | |||
145 | // TODO, should set up our panic and errfunc as below. Plus the other TODO stuff. | ||
146 | |||
147 | /* | ||
148 | // TODO - hack up LuaJIT so that we can limit memory per state. | ||
149 | // lua_setallocf(L, _elua_alloc, &ela); // LuaJIT uses a heavily hacked up dlmalloc. Seems that standard realloc is not so thread safe? | ||
150 | lua_atpanic(L, _elua_custom_panic); | ||
151 | // TODO - Sandbox out what this opens. See lib_init.c from LuaJIT. | ||
152 | // Just noticed this in the LuaJIT docs - "To change or extend the list of standard libraries to load, copy src/lib_init.c to your project and modify it accordingly. Make sure the jit library is loaded or the JIT compiler will not be activated." | ||
153 | luaL_openlibs(L); | ||
154 | |||
155 | lua_pushcfunction(L, errFunc); | ||
156 | ... | ||
157 | if ((err = lua_pcall(L, 0, 0, -2))) | ||
158 | _edje_lua2_error(L, err); | ||
159 | */ | ||
160 | } | ||