diff options
Diffstat (limited to 'LuaSL')
-rwxr-xr-x | LuaSL/build.sh | 13 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.h | 7 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_main.c | 185 | ||||
-rw-r--r-- | LuaSL/testLua/luaprocTest0.lua | 7 | ||||
-rw-r--r-- | LuaSL/testLua/luaprocTest0_C.lua | 37 | ||||
-rw-r--r-- | LuaSL/testLua/luaprocTest1_C.lua | 28 | ||||
-rw-r--r-- | LuaSL/testLua/luaprocTest2_C.lua | 65 |
7 files changed, 331 insertions, 11 deletions
diff --git a/LuaSL/build.sh b/LuaSL/build.sh index 15e1d52..4433120 100755 --- a/LuaSL/build.sh +++ b/LuaSL/build.sh | |||
@@ -18,6 +18,9 @@ fi | |||
18 | # No need for a make file, or dependencies, the entire thing takes only a few seconds to build. | 18 | # No need for a make file, or dependencies, the entire thing takes only a few seconds to build. |
19 | 19 | ||
20 | CFLAGS="-g -Wall -I include -I $LOCALDIR/src" | 20 | CFLAGS="-g -Wall -I include -I $LOCALDIR/src" |
21 | CFLAGS="$CFLAGS -I ../../libraries" | ||
22 | CFLAGS="$CFLAGS -I ../../libraries/luajit-2.0/src" | ||
23 | #CFLAGS="$CFLAGS -I /usr/include/lua5.1" | ||
21 | CFLAGS="$CFLAGS -I $E17DIR/include/eina-1" | 24 | CFLAGS="$CFLAGS -I $E17DIR/include/eina-1" |
22 | CFLAGS="$CFLAGS -I $E17DIR/include/eina-1/eina" | 25 | CFLAGS="$CFLAGS -I $E17DIR/include/eina-1/eina" |
23 | CFLAGS="$CFLAGS -I $E17DIR/include/eet-1" | 26 | CFLAGS="$CFLAGS -I $E17DIR/include/eet-1" |
@@ -28,12 +31,13 @@ CFLAGS="$CFLAGS -I $E17DIR/include/ecore-1" | |||
28 | CFLAGS="$CFLAGS -I $E17DIR/include" | 31 | CFLAGS="$CFLAGS -I $E17DIR/include" |
29 | CFLAGS="$CFLAGS -DPACKAGE_DATA_DIR=\"$LOCALDIR\" $CFLAGOPTS" | 32 | CFLAGS="$CFLAGS -DPACKAGE_DATA_DIR=\"$LOCALDIR\" $CFLAGOPTS" |
30 | 33 | ||
31 | LDFLAGS="-L lib -L /usr/lib -L /lib -L $E17DIR/lib -L ../../libraries/luajit-2.0/src" | 34 | LDFLAGS="-L ../../libraries/luajit-2.0/src -L lib -L /usr/lib -L /lib -L $E17DIR/lib" |
32 | libs="-lecore -levas -ledje -lembryo -leet -leina -lluajit -lpthread" | 35 | libs="-lecore -levas -ledje -lembryo -leet -leina -lluajit -lpthread -lm" |
36 | #LDFLAGS="-L /usr/lib/lua/5.1 -L lib -L /usr/lib -L /lib -L $E17DIR/lib" | ||
37 | #libs="-lecore -levas -ledje -lembryo -leet -leina -llua5.1 -lpthread -lm" | ||
33 | # These need to be added to libs if linking staticaly, though some parts of EFL don't like that. | 38 | # These need to be added to libs if linking staticaly, though some parts of EFL don't like that. |
34 | #-lecore_evas \ | 39 | #-lecore_evas \ |
35 | #-lecore_file \ | 40 | #-lecore_file \ |
36 | #-lm \ | ||
37 | #-ldl \ | 41 | #-ldl \ |
38 | #-lfontconfig \ | 42 | #-lfontconfig \ |
39 | #-lfreetype \ | 43 | #-lfreetype \ |
@@ -43,6 +47,7 @@ libs="-lecore -levas -ledje -lembryo -leet -leina -lluajit -lpthread" | |||
43 | 47 | ||
44 | LFLAGS="-d" | 48 | LFLAGS="-d" |
45 | EDJE_FLAGS="-id images -fd fonts" | 49 | EDJE_FLAGS="-id images -fd fonts" |
50 | LD_RUN_PATH="../../libraries/luajit-2.0/src:" | ||
46 | 51 | ||
47 | 52 | ||
48 | # Run lemon first, flex depends on it to define the symbol values. | 53 | # Run lemon first, flex depends on it to define the symbol values. |
@@ -59,7 +64,7 @@ echo $command | |||
59 | $command | 64 | $command |
60 | 65 | ||
61 | names="LuaSL_main LuaSL_compile LuaSL_utilities LuaSL_lexer LuaSL_lemon_yaccer" | 66 | names="LuaSL_main LuaSL_compile LuaSL_utilities LuaSL_lexer LuaSL_lemon_yaccer" |
62 | objects="" | 67 | objects="../../libraries/luaproc/channel.o ../../libraries/luaproc/list.o ../../libraries/luaproc/luaproc.o ../../libraries/luaproc/sched.o " |
63 | for i in $names | 68 | for i in $names |
64 | do | 69 | do |
65 | command="gcc $CFLAGS -c -o $i.o $i.c" | 70 | command="gcc $CFLAGS -c -o $i.o $i.c" |
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 687c56c..20277b9 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h | |||
@@ -20,6 +20,13 @@ | |||
20 | #include <stdio.h> | 20 | #include <stdio.h> |
21 | #include <limits.h> // For PATH_MAX. | 21 | #include <limits.h> // For PATH_MAX. |
22 | 22 | ||
23 | #include <lua.h> | ||
24 | #include <luajit.h> | ||
25 | #include <lualib.h> | ||
26 | #include <lauxlib.h> | ||
27 | |||
28 | #include <luaproc/sched.h> | ||
29 | |||
23 | #include "LuaSL_lemon_yaccer.h" | 30 | #include "LuaSL_lemon_yaccer.h" |
24 | 31 | ||
25 | #define YYERRCODE 256 | 32 | #define YYERRCODE 256 |
diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index 3f20460..f2f4f17 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c | |||
@@ -106,6 +106,163 @@ static void dirListLua_cb(const char *name, const char *path, void *data) | |||
106 | } | 106 | } |
107 | } | 107 | } |
108 | } | 108 | } |
109 | |||
110 | #ifdef _WIN32 | ||
111 | # define FMT_SIZE_T "%Iu" | ||
112 | #else | ||
113 | # define FMT_SIZE_T "%zu" | ||
114 | #endif | ||
115 | |||
116 | #define MAX_LUA_MEM (4 * (1024 * 1024)) | ||
117 | |||
118 | #define _edje_lua2_error(L, err_code) _edje_lua2_error_full(__FILE__, __FUNCTION__, __LINE__, L, err_code) | ||
119 | |||
120 | /* | ||
121 | typedef struct _Edje_Lua_Alloc Edje_Lua_Alloc; | ||
122 | |||
123 | struct _Edje_Lua_Alloc | ||
124 | { | ||
125 | size_t max, cur; | ||
126 | }; | ||
127 | |||
128 | static void * | ||
129 | _elua_alloc(void *ud, void *ptr, size_t osize, size_t nsize) | ||
130 | { | ||
131 | Edje_Lua_Alloc *ela = ud; | ||
132 | void *ptr2 = NULL; | ||
133 | |||
134 | if (ela) | ||
135 | { | ||
136 | ela->cur += nsize - osize; | ||
137 | if (ela->cur > ela->max) | ||
138 | { | ||
139 | printf("Lua memory limit of " FMT_SIZE_T " bytes reached (" FMT_SIZE_T " allocated)", ela->max, ela->cur); | ||
140 | } | ||
141 | else if (nsize == 0) | ||
142 | { | ||
143 | free(ptr); | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | ptr2 = realloc(ptr, nsize); | ||
148 | if (NULL == ptr2) | ||
149 | printf("Lua cannot re-allocate " FMT_SIZE_T " bytes", nsize); | ||
150 | } | ||
151 | } | ||
152 | else | ||
153 | printf("Lua cannoct allocate memory, no Edje_Lua_Alloc"); | ||
154 | |||
155 | return ptr2; | ||
156 | } | ||
157 | |||
158 | static int panics = 0; | ||
159 | static int | ||
160 | _elua_custom_panic(lua_State *L) // Stack usage [-0, +0, m] | ||
161 | { | ||
162 | // If we somehow manage to have multiple panics, it's likely due to being out | ||
163 | // of memory in the following lua_tostring() call. | ||
164 | panics++; | ||
165 | if (panics) | ||
166 | { | ||
167 | printf("Lua PANICS!!!!!"); | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | printf("Lua PANIC!!!!!: %s", lua_tostring(L, -1)); // Stack usage [-0, +0, m] | ||
172 | } | ||
173 | // The docs say that this will cause an exit(EXIT_FAILURE) if we return, | ||
174 | // and that we we should long jump some where to avoid that. This is only | ||
175 | // called for things not called from a protected environment. We always | ||
176 | // use pcalls though, except for the library load calls. If we can't load | ||
177 | // the standard libraries, then perhaps a crash is the right thing. | ||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | static void | ||
182 | _edje_lua2_error_full(const char *file, const char *fnc, int line, | ||
183 | lua_State *L, int err_code) // Stack usage [-0, +0, m] | ||
184 | { | ||
185 | const char *err_type; | ||
186 | |||
187 | switch (err_code) | ||
188 | { | ||
189 | case LUA_ERRRUN: | ||
190 | err_type = "runtime"; | ||
191 | break; | ||
192 | case LUA_ERRSYNTAX: | ||
193 | err_type = "syntax"; | ||
194 | break; | ||
195 | case LUA_ERRMEM: | ||
196 | err_type = "memory allocation"; | ||
197 | break; | ||
198 | case LUA_ERRERR: | ||
199 | err_type = "error handler"; | ||
200 | break; | ||
201 | default: | ||
202 | err_type = "unknown"; | ||
203 | break; | ||
204 | } | ||
205 | printf("Lua %s error: %s\n", err_type, lua_tostring(L, -1)); // Stack usage [-0, +0, m] | ||
206 | } | ||
207 | |||
208 | static int errFunc(lua_State *L) | ||
209 | { | ||
210 | int i = 0; | ||
211 | lua_Debug ar; | ||
212 | |||
213 | while (lua_getstack(L, i++, &ar)) | ||
214 | { | ||
215 | if (lua_getinfo(L, "nSlu", &ar)) | ||
216 | { | ||
217 | if (NULL == ar.name) | ||
218 | ar.name = "DUNNO"; | ||
219 | 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); | ||
220 | } | ||
221 | } | ||
222 | return 0; | ||
223 | } | ||
224 | */ | ||
225 | |||
226 | static void runnerSetup(gameGlobals *game) | ||
227 | { | ||
228 | luaprocInit(); | ||
229 | |||
230 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
231 | PE("Error creating luaproc worker thread."); | ||
232 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
233 | PE("Error creating luaproc worker thread."); | ||
234 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
235 | PE("Error creating luaproc worker thread."); | ||
236 | if ( sched_create_worker( ) != LUAPROC_SCHED_OK ) | ||
237 | PE("Error creating luaproc worker thread."); | ||
238 | } | ||
239 | |||
240 | static void runnerTearDown(gameGlobals *game) | ||
241 | { | ||
242 | // TODO - this is what hangs the system. | ||
243 | sched_join_workerthreads(); | ||
244 | } | ||
245 | |||
246 | static void runLuaFile(gameGlobals *game, const char *filename) | ||
247 | { | ||
248 | newProc(filename, TRUE); | ||
249 | |||
250 | // TODO, should set up our panic and errfunc as below. Plus the other TODO stuff. | ||
251 | |||
252 | /* | ||
253 | // TODO - hack up LuaJIT so that we can limit memory per state. | ||
254 | // lua_setallocf(L, _elua_alloc, &ela); // LuaJIT uses a heavily hacked up dlmalloc. Seems that standard realloc is not so thread safe? | ||
255 | lua_atpanic(L, _elua_custom_panic); | ||
256 | // TODO - Sandbox out what this opens. See lib_init.c from LuaJIT. | ||
257 | luaL_openlibs(L); | ||
258 | |||
259 | lua_pushcfunction(L, errFunc); | ||
260 | ... | ||
261 | if ((err = lua_pcall(L, 0, 0, -2))) | ||
262 | _edje_lua2_error(L, err); | ||
263 | */ | ||
264 | } | ||
265 | |||
109 | #endif | 266 | #endif |
110 | 267 | ||
111 | int | 268 | int |
@@ -248,6 +405,7 @@ main(int argc, char **argv) | |||
248 | scriptCount = 0; | 405 | scriptCount = 0; |
249 | gettimeofday(&lastTime2, 0); | 406 | gettimeofday(&lastTime2, 0); |
250 | compilerSetup(&game); | 407 | compilerSetup(&game); |
408 | runnerSetup(&game); | ||
251 | snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR); | 409 | snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR); |
252 | eina_file_dir_list(buf, EINA_TRUE, dirList_cb, &game); | 410 | eina_file_dir_list(buf, EINA_TRUE, dirList_cb, &game); |
253 | diff = timeDiff(&thisTime2, &lastTime2); | 411 | diff = timeDiff(&thisTime2, &lastTime2); |
@@ -266,35 +424,46 @@ main(int argc, char **argv) | |||
266 | printf("Combined estimate of compiling speed is %f scripts per second.\n", 1 / ((diff0 / lslCount) + (diff / scriptCount))); | 424 | printf("Combined estimate of compiling speed is %f scripts per second.\n", 1 / ((diff0 / lslCount) + (diff / scriptCount))); |
267 | 425 | ||
268 | gettimeofday(&lastTime2, 0); | 426 | gettimeofday(&lastTime2, 0); |
269 | snprintf(buf, sizeof(buf), "cd %s/testLua; LUA_SOPATH='../../libraries/luaproc/' lua luaprocTest0.lua", PACKAGE_DATA_DIR); | 427 | snprintf(buf, sizeof(buf), "lua luaprocTest0.lua"); |
270 | system(buf); | 428 | system(buf); |
271 | diff = timeDiff(&thisTime2, &lastTime2); | 429 | diff = timeDiff(&thisTime2, &lastTime2); |
272 | printf("%s TOOK %f seconds.\n", buf, diff); | 430 | printf("%s TOOK %f seconds......................................................................................................\n", buf, diff); |
273 | 431 | ||
274 | gettimeofday(&lastTime2, 0); | 432 | gettimeofday(&lastTime2, 0); |
275 | snprintf(buf, sizeof(buf), "cd %s/testLua; LUA_SOPATH='../../libraries/luaproc/' lua luaprocTest1.lua", PACKAGE_DATA_DIR); | 433 | snprintf(buf, sizeof(buf), "%s/testLua/luaprocTest0_C.lua", PACKAGE_DATA_DIR); |
434 | runLuaFile(&game, buf); | ||
435 | diff = timeDiff(&thisTime2, &lastTime2); | ||
436 | printf("Running that last one locally TOOK %f seconds.\n",diff); | ||
437 | |||
438 | gettimeofday(&lastTime2, 0); | ||
439 | snprintf(buf, sizeof(buf), "lua luaprocTest1.lua"); | ||
276 | system(buf); | 440 | system(buf); |
277 | diff = timeDiff(&thisTime2, &lastTime2); | 441 | diff = timeDiff(&thisTime2, &lastTime2); |
278 | printf("%s TOOK %f seconds.\n", buf, diff); | 442 | printf("%s TOOK %f seconds.\n", buf, diff); |
279 | 443 | ||
280 | gettimeofday(&lastTime2, 0); | 444 | gettimeofday(&lastTime2, 0); |
281 | snprintf(buf, sizeof(buf), "cd %s/testLua; LUA_SOPATH='../../libraries/luaproc/' luajit luaprocTest1.lua", PACKAGE_DATA_DIR); | 445 | snprintf(buf, sizeof(buf), "../../libraries/luajit-2.0/src/luajit luaprocTest1.lua"); |
282 | system(buf); | 446 | system(buf); |
283 | diff = timeDiff(&thisTime2, &lastTime2); | 447 | diff = timeDiff(&thisTime2, &lastTime2); |
284 | printf("%s TOOK %f seconds.\n", buf, diff); | 448 | printf("%s TOOK %f seconds.\n", buf, diff); |
285 | 449 | ||
286 | gettimeofday(&lastTime2, 0); | 450 | gettimeofday(&lastTime2, 0); |
287 | snprintf(buf, sizeof(buf), "cd %s/testLua; LUA_SOPATH='../../libraries/luaproc/' lua luaprocTest2.lua", PACKAGE_DATA_DIR); | 451 | snprintf(buf, sizeof(buf), "lua luaprocTest2.lua"); |
288 | system(buf); | 452 | system(buf); |
289 | diff = timeDiff(&thisTime2, &lastTime2); | 453 | diff = timeDiff(&thisTime2, &lastTime2); |
290 | printf("%s TOOK %f seconds.\n", buf, diff); | 454 | printf("%s TOOK %f seconds.\n", buf, diff); |
291 | 455 | ||
292 | gettimeofday(&lastTime2, 0); | 456 | gettimeofday(&lastTime2, 0); |
293 | snprintf(buf, sizeof(buf), "cd %s/testLua; LUA_SOPATH='../../libraries/luaproc/' luajit luaprocTest2.lua", PACKAGE_DATA_DIR); | 457 | snprintf(buf, sizeof(buf), "../../libraries/luajit-2.0/src/luajit luaprocTest2.lua"); |
294 | system(buf); | 458 | system(buf); |
295 | diff = timeDiff(&thisTime2, &lastTime2); | 459 | diff = timeDiff(&thisTime2, &lastTime2); |
296 | printf("%s TOOK %f seconds.\n", buf, diff); | 460 | printf("%s TOOK %f seconds.\n", buf, diff); |
297 | 461 | ||
462 | gettimeofday(&lastTime2, 0); | ||
463 | snprintf(buf, sizeof(buf), "%s/testLua/luaprocTest2_C.lua", PACKAGE_DATA_DIR); | ||
464 | runLuaFile(&game, buf); | ||
465 | diff = timeDiff(&thisTime2, &lastTime2); | ||
466 | printf("Running that last one locally TOOK %f seconds.\n",diff); | ||
298 | #endif | 467 | #endif |
299 | 468 | ||
300 | if (game.ui) | 469 | if (game.ui) |
@@ -303,6 +472,10 @@ main(int argc, char **argv) | |||
303 | ecore_animator_del(ani); | 472 | ecore_animator_del(ani); |
304 | ecore_evas_free(game.ee); | 473 | ecore_evas_free(game.ee); |
305 | } | 474 | } |
475 | |||
476 | runnerTearDown(&game); | ||
477 | diff = timeDiff(&thisTime2, &lastTime2); | ||
478 | printf("Running that last one locally TOOK %f seconds.\n",diff); | ||
306 | edje_shutdown(); | 479 | edje_shutdown(); |
307 | ecore_evas_shutdown(); | 480 | ecore_evas_shutdown(); |
308 | } | 481 | } |
diff --git a/LuaSL/testLua/luaprocTest0.lua b/LuaSL/testLua/luaprocTest0.lua index 5868d6f..94a1d20 100644 --- a/LuaSL/testLua/luaprocTest0.lua +++ b/LuaSL/testLua/luaprocTest0.lua | |||
@@ -33,7 +33,12 @@ luaproc.createworker() | |||
33 | luaproc.newproc( [=[ | 33 | luaproc.newproc( [=[ |
34 | luaproc.newchannel( "testchannel" ) | 34 | luaproc.newchannel( "testchannel" ) |
35 | luaproc.newproc( "luaproc.send( 'testchannel', 'luaproc is working fine!' )" ) | 35 | luaproc.newproc( "luaproc.send( 'testchannel', 'luaproc is working fine!' )" ) |
36 | luaproc.newproc( "print( luaproc.receive( 'testchannel' ))" ) | 36 | luaproc.newproc( "print(luaproc.receive( 'testchannel'))" ) |
37 | print("End of parent proc") | ||
37 | ]=] ) | 38 | ]=] ) |
38 | 39 | ||
40 | print("About to luaproc.exit()!"); | ||
39 | luaproc.exit() | 41 | luaproc.exit() |
42 | print("Should have exited after the luaproc.exit()!"); | ||
43 | |||
44 | |||
diff --git a/LuaSL/testLua/luaprocTest0_C.lua b/LuaSL/testLua/luaprocTest0_C.lua new file mode 100644 index 0000000..0dd6078 --- /dev/null +++ b/LuaSL/testLua/luaprocTest0_C.lua | |||
@@ -0,0 +1,37 @@ | |||
1 | ---------------------------------------------------- | ||
2 | -- | ||
3 | -- Copyright 2008 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy | ||
4 | -- | ||
5 | -- Permission is hereby granted, free of charge, to any person obtaining a copy | ||
6 | -- of this software and associated documentation files (the "Software"), to deal | ||
7 | -- in the Software without restriction, including without limitation the rights | ||
8 | -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
9 | -- copies of the Software, and to permit persons to whom the Software is | ||
10 | -- furnished to do so, subject to the following conditions: | ||
11 | -- | ||
12 | -- The above copyright notice and this permission notice shall be included in | ||
13 | -- all copies or substantial portions of the Software. | ||
14 | -- | ||
15 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
18 | -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
20 | -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
21 | -- THE SOFTWARE. | ||
22 | -- | ||
23 | ----------------------------------------------------- | ||
24 | -- | ||
25 | -- test.lua | ||
26 | -- | ||
27 | ----------------------------------------------------- | ||
28 | |||
29 | luaproc.newproc( [=[ | ||
30 | luaproc.newchannel( "testchannel" ) | ||
31 | luaproc.newproc( "luaproc.send( 'testchannel', 'luaproc is working fine!' )" ) | ||
32 | luaproc.newproc( "print(luaproc.receive( 'testchannel'))" ) | ||
33 | print("End of parent proc") | ||
34 | ]=] ) | ||
35 | |||
36 | print("About to exit."); | ||
37 | |||
diff --git a/LuaSL/testLua/luaprocTest1_C.lua b/LuaSL/testLua/luaprocTest1_C.lua new file mode 100644 index 0000000..61cb461 --- /dev/null +++ b/LuaSL/testLua/luaprocTest1_C.lua | |||
@@ -0,0 +1,28 @@ | |||
1 | result, error_msg = luaproc.newproc( [=[ | ||
2 | |||
3 | local count = 0 | ||
4 | |||
5 | -- Hmm, luajit 2 beta 9 crashes at about 8140, lua can go up to 50000 at least. | ||
6 | for i = 1, 8000 do | ||
7 | local channel = "channel" .. i | ||
8 | -- local proc = 'print(luaproc.receive("channel' .. i .. '") .. " " .. ' .. i ..')' | ||
9 | local proc = 'luaproc.receive("' .. channel .. '")' | ||
10 | |||
11 | -- print(channel .. "\n" .. proc) | ||
12 | result, error_msg = luaproc.newchannel(channel) | ||
13 | if not result then print(error_msg) end | ||
14 | result, error_msg = luaproc.newproc(proc) | ||
15 | if not result then print(error_msg) else count = count + 1 end | ||
16 | end | ||
17 | |||
18 | print("Started " .. count .. " Lua threads") | ||
19 | |||
20 | if 0 ~= count then | ||
21 | for i = 1, count do | ||
22 | result, error_msg = luaproc.send("channel" .. i, 'luaproc is working fine! ' .. i) | ||
23 | if not result then print(error_msg .. " " .. i) end | ||
24 | end | ||
25 | end | ||
26 | ]=] ) | ||
27 | if not result then print(error_msg .. " for main proc") end | ||
28 | |||
diff --git a/LuaSL/testLua/luaprocTest2_C.lua b/LuaSL/testLua/luaprocTest2_C.lua new file mode 100644 index 0000000..e1a5a83 --- /dev/null +++ b/LuaSL/testLua/luaprocTest2_C.lua | |||
@@ -0,0 +1,65 @@ | |||
1 | count = 0 | ||
2 | |||
3 | proc = [=[ | ||
4 | require "string" | ||
5 | local channel = "channel%d" | ||
6 | local message | ||
7 | |||
8 | result, error_msg = luaproc.newchannel(channel) | ||
9 | if not result then print(error_msg) end | ||
10 | repeat | ||
11 | message = luaproc.receive(channel) | ||
12 | local x, y = string.find(message, "@") | ||
13 | if not x then | ||
14 | x, y = string.find(message, "@") | ||
15 | x, y = string.find(message, "@") | ||
16 | x, y = string.find(message, "@") | ||
17 | x, y = string.find(message, "@") | ||
18 | x, y = string.find(message, "@") | ||
19 | x, y = string.find(message, "@") | ||
20 | x, y = string.find(message, "@") | ||
21 | x, y = string.find(message, "@") | ||
22 | end | ||
23 | until "quit" == message | ||
24 | ]=] | ||
25 | |||
26 | mainProc = [=[ | ||
27 | local count = %d | ||
28 | local messages = 0 | ||
29 | local length = 0 | ||
30 | local message = "This is a test message. 56789 12" | ||
31 | |||
32 | if 0 ~= count then | ||
33 | for k = 0, 16 do | ||
34 | for j = 0, 199 do | ||
35 | for i = 1, count do | ||
36 | result, error_msg = luaproc.send("channel" .. i, message) | ||
37 | if not result then print(error_msg .. " " .. i) else | ||
38 | messages = messages + 1 | ||
39 | length = length + #message | ||
40 | end | ||
41 | end | ||
42 | end | ||
43 | message = message .. message | ||
44 | end | ||
45 | |||
46 | for i = 1, count do | ||
47 | result, error_msg = luaproc.send("channel" .. i, "quit") | ||
48 | if not result then print(error_msg .. " " .. i) end | ||
49 | end | ||
50 | end | ||
51 | |||
52 | print("Sent " .. messages .. " messages totalling " .. length .. " bytes. The largest message was " .. #message .. " bytes.") | ||
53 | ]=] | ||
54 | |||
55 | for i = 1, 10 do | ||
56 | result, error_msg = luaproc.newproc(string.format(proc, i)) | ||
57 | if not result then print(error_msg) else count = count + 1 end | ||
58 | end | ||
59 | |||
60 | print("Started " .. count .. " Lua threads.") | ||
61 | |||
62 | result, error_msg = luaproc.newproc(string.format(mainProc, count)) | ||
63 | if not result then print(error_msg) end | ||
64 | |||
65 | |||