aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xLuaSL/build.sh13
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h7
-rw-r--r--LuaSL/src/LuaSL_main.c185
-rw-r--r--LuaSL/testLua/luaprocTest0.lua7
-rw-r--r--LuaSL/testLua/luaprocTest0_C.lua37
-rw-r--r--LuaSL/testLua/luaprocTest1_C.lua28
-rw-r--r--LuaSL/testLua/luaprocTest2_C.lua65
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
20CFLAGS="-g -Wall -I include -I $LOCALDIR/src" 20CFLAGS="-g -Wall -I include -I $LOCALDIR/src"
21CFLAGS="$CFLAGS -I ../../libraries"
22CFLAGS="$CFLAGS -I ../../libraries/luajit-2.0/src"
23#CFLAGS="$CFLAGS -I /usr/include/lua5.1"
21CFLAGS="$CFLAGS -I $E17DIR/include/eina-1" 24CFLAGS="$CFLAGS -I $E17DIR/include/eina-1"
22CFLAGS="$CFLAGS -I $E17DIR/include/eina-1/eina" 25CFLAGS="$CFLAGS -I $E17DIR/include/eina-1/eina"
23CFLAGS="$CFLAGS -I $E17DIR/include/eet-1" 26CFLAGS="$CFLAGS -I $E17DIR/include/eet-1"
@@ -28,12 +31,13 @@ CFLAGS="$CFLAGS -I $E17DIR/include/ecore-1"
28CFLAGS="$CFLAGS -I $E17DIR/include" 31CFLAGS="$CFLAGS -I $E17DIR/include"
29CFLAGS="$CFLAGS -DPACKAGE_DATA_DIR=\"$LOCALDIR\" $CFLAGOPTS" 32CFLAGS="$CFLAGS -DPACKAGE_DATA_DIR=\"$LOCALDIR\" $CFLAGOPTS"
30 33
31LDFLAGS="-L lib -L /usr/lib -L /lib -L $E17DIR/lib -L ../../libraries/luajit-2.0/src" 34LDFLAGS="-L ../../libraries/luajit-2.0/src -L lib -L /usr/lib -L /lib -L $E17DIR/lib"
32libs="-lecore -levas -ledje -lembryo -leet -leina -lluajit -lpthread" 35libs="-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
44LFLAGS="-d" 48LFLAGS="-d"
45EDJE_FLAGS="-id images -fd fonts" 49EDJE_FLAGS="-id images -fd fonts"
50LD_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
61names="LuaSL_main LuaSL_compile LuaSL_utilities LuaSL_lexer LuaSL_lemon_yaccer" 66names="LuaSL_main LuaSL_compile LuaSL_utilities LuaSL_lexer LuaSL_lemon_yaccer"
62objects="" 67objects="../../libraries/luaproc/channel.o ../../libraries/luaproc/list.o ../../libraries/luaproc/luaproc.o ../../libraries/luaproc/sched.o "
63for i in $names 68for i in $names
64do 69do
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/*
121typedef struct _Edje_Lua_Alloc Edje_Lua_Alloc;
122
123struct _Edje_Lua_Alloc
124{
125 size_t max, cur;
126};
127
128static 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
158static int panics = 0;
159static 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
181static 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
208static 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
226static 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
240static void runnerTearDown(gameGlobals *game)
241{
242// TODO - this is what hangs the system.
243 sched_join_workerthreads();
244}
245
246static 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
111int 268int
@@ -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()
33luaproc.newproc( [=[ 33luaproc.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
40print("About to luaproc.exit()!");
39luaproc.exit() 41luaproc.exit()
42print("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
29luaproc.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
36print("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 @@
1result, 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]=] )
27if 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 @@
1count = 0
2
3proc = [=[
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
26mainProc = [=[
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
55for 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
58end
59
60print("Started " .. count .. " Lua threads.")
61
62result, error_msg = luaproc.newproc(string.format(mainProc, count))
63if not result then print(error_msg) end
64
65