diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/src/LuaSL.h | 11 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.h | 3 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 19 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_main.c | 37 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_test.c | 18 |
5 files changed, 57 insertions, 31 deletions
diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h index 9f55e2a..f6a5fad 100644 --- a/LuaSL/src/LuaSL.h +++ b/LuaSL/src/LuaSL.h | |||
@@ -49,6 +49,17 @@ typedef enum | |||
49 | 49 | ||
50 | typedef struct | 50 | typedef struct |
51 | { | 51 | { |
52 | char SID[PATH_MAX]; | ||
53 | char fileName[PATH_MAX]; | ||
54 | struct timeval startTime; | ||
55 | float compileTime; | ||
56 | int bugs, warnings; | ||
57 | boolean running; | ||
58 | |||
59 | } script; | ||
60 | |||
61 | typedef struct | ||
62 | { | ||
52 | Ecore_Evas *ee; // Our window. | 63 | Ecore_Evas *ee; // Our window. |
53 | Evas *canvas; // The canvas for drawing directly onto. | 64 | Evas *canvas; // The canvas for drawing directly onto. |
54 | Evas_Object *bg; // Our background edje, also the game specific stuff. | 65 | Evas_Object *bg; // Our background edje, also the game specific stuff. |
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 600fb6f..cbc34b3 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h | |||
@@ -391,6 +391,7 @@ typedef struct | |||
391 | void *scanner; // This should be of type yyscan_t, which is typedef to void * anyway, but that does not get defined until LuaSL_lexer.h, which depends on this struct being defined first. | 391 | void *scanner; // This should be of type yyscan_t, which is typedef to void * anyway, but that does not get defined until LuaSL_lexer.h, which depends on this struct being defined first. |
392 | int argc; | 392 | int argc; |
393 | char **argv; | 393 | char **argv; |
394 | char SID[37]; | ||
394 | char fileName[PATH_MAX]; | 395 | char fileName[PATH_MAX]; |
395 | FILE *file; | 396 | FILE *file; |
396 | LSL_Leaf *ast; | 397 | LSL_Leaf *ast; |
@@ -416,7 +417,7 @@ typedef struct | |||
416 | 417 | ||
417 | 418 | ||
418 | boolean compilerSetup(gameGlobals *game); | 419 | boolean compilerSetup(gameGlobals *game); |
419 | boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, boolean doConstants); | 420 | boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *SID, char *script, boolean doConstants); |
420 | void burnLeaf(void *data); | 421 | void burnLeaf(void *data); |
421 | 422 | ||
422 | LSL_Leaf *addBlock(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); | 423 | LSL_Leaf *addBlock(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); |
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 8e9bd01..a4d54db 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c | |||
@@ -358,7 +358,7 @@ LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf | |||
358 | else | 358 | else |
359 | { | 359 | { |
360 | compiler->script.bugCount++; | 360 | compiler->script.bugCount++; |
361 | sendBack(game, compiler->client, compiler->fileName, "compilerError(%d,%d,NOT found %s)", identifier->line, identifier->column, identifier->value.stringValue); | 361 | sendBack(game, compiler->client, compiler->SID, "compilerError(%d,%d,NOT found %s)", identifier->line, identifier->column, identifier->value.stringValue); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | 364 | ||
@@ -402,7 +402,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, | |||
402 | if (OT_undeclared == lType) | 402 | if (OT_undeclared == lType) |
403 | { | 403 | { |
404 | compiler->script.warningCount++; | 404 | compiler->script.warningCount++; |
405 | sendBack(game, compiler->client, compiler->fileName, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); | 405 | sendBack(game, compiler->client, compiler->SID, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); |
406 | lval->basicType = OT_undeclared; | 406 | lval->basicType = OT_undeclared; |
407 | return lval; | 407 | return lval; |
408 | } | 408 | } |
@@ -430,7 +430,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, | |||
430 | if (OT_undeclared == rType) | 430 | if (OT_undeclared == rType) |
431 | { | 431 | { |
432 | compiler->script.warningCount++; | 432 | compiler->script.warningCount++; |
433 | sendBack(game, compiler->client, compiler->fileName, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); | 433 | sendBack(game, compiler->client, compiler->SID, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); |
434 | lval->basicType = OT_undeclared; | 434 | lval->basicType = OT_undeclared; |
435 | return lval; | 435 | return lval; |
436 | } | 436 | } |
@@ -587,7 +587,7 @@ else | |||
587 | } | 587 | } |
588 | 588 | ||
589 | compiler->script.bugCount++; | 589 | compiler->script.bugCount++; |
590 | sendBack(game, compiler->client, compiler->fileName, "compilerError(%d,%d,Invalid operation [%s(%s) %s %s(%s)])", lval->line, lval->column, leftType, leftToken, lval->toKen->toKen, rightType, rightToken); | 590 | sendBack(game, compiler->client, compiler->SID, "compilerError(%d,%d,Invalid operation [%s(%s) %s %s(%s)])", lval->line, lval->column, leftType, leftToken, lval->toKen->toKen, rightType, rightToken); |
591 | } | 591 | } |
592 | } | 592 | } |
593 | 593 | ||
@@ -2120,7 +2120,7 @@ boolean compilerSetup(gameGlobals *game) | |||
2120 | 2120 | ||
2121 | // Compile the constants. | 2121 | // Compile the constants. |
2122 | snprintf(buf, sizeof(buf), "%s/src/constants.lsl", PACKAGE_DATA_DIR); | 2122 | snprintf(buf, sizeof(buf), "%s/src/constants.lsl", PACKAGE_DATA_DIR); |
2123 | compileLSL(game, NULL, buf, TRUE); | 2123 | compileLSL(game, NULL, "FAKE_SID", buf, TRUE); |
2124 | 2124 | ||
2125 | return TRUE; | 2125 | return TRUE; |
2126 | } | 2126 | } |
@@ -2140,7 +2140,7 @@ static int luaWriter(lua_State *L, const void* p, size_t sz, void* ud) | |||
2140 | return result; | 2140 | return result; |
2141 | } | 2141 | } |
2142 | 2142 | ||
2143 | boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, boolean doConstants) | 2143 | boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *SID, char *script, boolean doConstants) |
2144 | { | 2144 | { |
2145 | boolean result = FALSE; | 2145 | boolean result = FALSE; |
2146 | LuaSL_compiler compiler; | 2146 | LuaSL_compiler compiler; |
@@ -2161,6 +2161,8 @@ boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, bo | |||
2161 | compiler.ignorable = eina_strbuf_new(); | 2161 | compiler.ignorable = eina_strbuf_new(); |
2162 | #endif | 2162 | #endif |
2163 | 2163 | ||
2164 | strncpy(compiler.SID, SID, 36); | ||
2165 | compiler.SID[36] = '\0'; | ||
2164 | strncpy(compiler.fileName, script, PATH_MAX - 1); | 2166 | strncpy(compiler.fileName, script, PATH_MAX - 1); |
2165 | compiler.fileName[PATH_MAX - 1] = '\0'; | 2167 | compiler.fileName[PATH_MAX - 1] = '\0'; |
2166 | compiler.file = fopen(compiler.fileName, "r"); | 2168 | compiler.file = fopen(compiler.fileName, "r"); |
@@ -2216,7 +2218,7 @@ boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, bo | |||
2216 | call->call->basicType = func->basicType; | 2218 | call->call->basicType = func->basicType; |
2217 | } | 2219 | } |
2218 | else | 2220 | else |
2219 | sendBack(game, compiler.client, compiler.fileName, "compilerError(%d,%d,Undeclared function %s called)", call->call->line, call->call->column, call->call->value.stringValue); | 2221 | sendBack(game, compiler.client, compiler.SID, "compilerError(%d,%d,Undeclared function %s called)", call->call->line, call->call->column, call->call->value.stringValue); |
2220 | } | 2222 | } |
2221 | } | 2223 | } |
2222 | secondPass(&compiler, compiler.ast); | 2224 | secondPass(&compiler, compiler.ast); |
@@ -2275,8 +2277,7 @@ boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, bo | |||
2275 | fprintf(out, "--// Generated code goes here.\n\n"); | 2277 | fprintf(out, "--// Generated code goes here.\n\n"); |
2276 | fprintf(out, "local _bit = require(\"bit\")\n"); | 2278 | fprintf(out, "local _bit = require(\"bit\")\n"); |
2277 | fprintf(out, "local _LSL = require(\"LSL\")\n\n"); | 2279 | fprintf(out, "local _LSL = require(\"LSL\")\n\n"); |
2278 | // TODO - Use the scripts UUID instead of the file name here, or something. | 2280 | fprintf(out, "local _SID = [=[%s]=]\n\n", compiler.SID); |
2279 | fprintf(out, "local _SID = [=[%s]=]\n\n", compiler.fileName); | ||
2280 | outputLeaf(out, OM_LUA, compiler.ast); | 2281 | outputLeaf(out, OM_LUA, compiler.ast); |
2281 | fprintf(out, "\n\n_LSL.mainLoop(_SID, _defaultState)\n"); // This actually starts the script running. | 2282 | fprintf(out, "\n\n_LSL.mainLoop(_SID, _defaultState)\n"); // This actually starts the script running. |
2282 | fprintf(out, "\n--// End of generated code.\n\n"); | 2283 | fprintf(out, "\n--// End of generated code.\n\n"); |
diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index 940e201..e56aaf3 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c | |||
@@ -15,6 +15,7 @@ static Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Ad | |||
15 | static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Data *ev) | 15 | static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Data *ev) |
16 | { | 16 | { |
17 | gameGlobals *game = data; | 17 | gameGlobals *game = data; |
18 | char buf[PATH_MAX]; | ||
18 | char SID[PATH_MAX]; | 19 | char SID[PATH_MAX]; |
19 | const char *command; | 20 | const char *command; |
20 | char *ext; | 21 | char *ext; |
@@ -28,25 +29,48 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D | |||
28 | strncpy(SID, command, length + 1); | 29 | strncpy(SID, command, length + 1); |
29 | SID[length] = '\0'; | 30 | SID[length] = '\0'; |
30 | eina_strbuf_remove(clientStream, 0, length + 1); | 31 | eina_strbuf_remove(clientStream, 0, length + 1); |
31 | ext = rindex(SID, '.'); | 32 | ext = index(SID, '.'); |
32 | if (ext) | 33 | if (ext) |
33 | { | 34 | { |
34 | ext[0] = '\0'; | 35 | ext[0] = '\0'; |
35 | command = ext + 1; | 36 | command = ext + 1; |
36 | if (0 == strcmp(command, "compile()")) | 37 | if (0 == strncmp(command, "compile(", 8)) |
37 | { | 38 | { |
38 | PD("Compiling %s.", SID); | 39 | char *temp; |
39 | if (compileLSL(game, ev->client, SID, FALSE)) | 40 | char *file; |
41 | |||
42 | strcpy(buf, &command[8]); | ||
43 | temp = buf; | ||
44 | file = temp; | ||
45 | while (')' != temp[0]) | ||
46 | temp++; | ||
47 | temp[0] = '\0'; | ||
48 | |||
49 | PD("Compiling %s, %s.", SID, file); | ||
50 | if (compileLSL(game, ev->client, SID, file, FALSE)) | ||
51 | { | ||
52 | script *me = calloc(1, sizeof(script)); | ||
53 | |||
54 | gettimeofday(&me->startTime, NULL); | ||
55 | strncpy(me->SID, SID, sizeof(me->SID)); | ||
56 | strncpy(me->fileName, file, sizeof(me->fileName)); | ||
57 | eina_hash_add(game->scripts, me->SID, me); | ||
40 | sendBack(game, ev->client, SID, "compiled(true)"); | 58 | sendBack(game, ev->client, SID, "compiled(true)"); |
59 | } | ||
41 | else | 60 | else |
42 | sendBack(game, ev->client, SID, "compiled(false)"); | 61 | sendBack(game, ev->client, SID, "compiled(false)"); |
43 | } | 62 | } |
44 | else if (0 == strcmp(command, "run()")) | 63 | else if (0 == strcmp(command, "run()")) |
45 | { | 64 | { |
65 | script *me; | ||
46 | char buf[PATH_MAX]; | 66 | char buf[PATH_MAX]; |
47 | 67 | ||
48 | sprintf(buf, "%s.lua.out", SID); | 68 | me = eina_hash_find(game->scripts, SID); |
49 | newProc(buf, TRUE); | 69 | if (me) |
70 | { | ||
71 | sprintf(buf, "%s.lua.out", me->fileName); | ||
72 | newProc(buf, TRUE); | ||
73 | } | ||
50 | } | 74 | } |
51 | else if (0 == strcmp(command, "exit()")) | 75 | else if (0 == strcmp(command, "exit()")) |
52 | { | 76 | { |
@@ -95,6 +119,7 @@ int main(int argc, char **argv) | |||
95 | if (eina_init()) | 119 | if (eina_init()) |
96 | { | 120 | { |
97 | loggingStartup(&game); | 121 | loggingStartup(&game); |
122 | game.scripts = eina_hash_string_superfast_new(NULL); | ||
98 | if (ecore_con_init()) | 123 | if (ecore_con_init()) |
99 | { | 124 | { |
100 | if ((game.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, game.address, game.port, &game))) | 125 | if ((game.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, game.address, game.port, &game))) |
diff --git a/LuaSL/src/LuaSL_test.c b/LuaSL/src/LuaSL_test.c index ec7824a..19f6bcd 100644 --- a/LuaSL/src/LuaSL_test.c +++ b/LuaSL/src/LuaSL_test.c | |||
@@ -2,18 +2,6 @@ | |||
2 | #include "LuaSL.h" | 2 | #include "LuaSL.h" |
3 | 3 | ||
4 | 4 | ||
5 | typedef struct | ||
6 | { | ||
7 | char SID[PATH_MAX]; | ||
8 | char fileName[PATH_MAX]; | ||
9 | struct timeval startTime; | ||
10 | float compileTime; | ||
11 | int bugs, warnings; | ||
12 | boolean running; | ||
13 | |||
14 | } script; | ||
15 | |||
16 | |||
17 | static Eina_Strbuf *clientStream; | 5 | static Eina_Strbuf *clientStream; |
18 | static int scriptCount = 0; | 6 | static int scriptCount = 0; |
19 | static int compiledCount = 0; | 7 | static int compiledCount = 0; |
@@ -99,10 +87,10 @@ static void dirList_compile(const char *name, const char *path, void *data) | |||
99 | 87 | ||
100 | scriptCount++; | 88 | scriptCount++; |
101 | gettimeofday(&me->startTime, NULL); | 89 | gettimeofday(&me->startTime, NULL); |
102 | snprintf(me->SID, sizeof(me->SID), "%s/%s", path, name); | 90 | snprintf(me->SID, sizeof(me->SID), "%08lx-%04lx-%04lx-%04lx-%012lx", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random()); |
103 | snprintf(me->fileName, sizeof(me->fileName), "%s/%s", path, name); | 91 | snprintf(me->fileName, sizeof(me->fileName), "%s/%s", path, name); |
104 | eina_hash_add(game->scripts, me->SID, me); | 92 | eina_hash_add(game->scripts, me->SID, me); |
105 | sendForth(game, me->SID, "compile()"); | 93 | sendForth(game, me->SID, "compile(%s)", me->fileName); |
106 | } | 94 | } |
107 | } | 95 | } |
108 | } | 96 | } |
@@ -158,7 +146,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D | |||
158 | strncpy(SID, command, length + 1); | 146 | strncpy(SID, command, length + 1); |
159 | SID[length] = '\0'; | 147 | SID[length] = '\0'; |
160 | eina_strbuf_remove(clientStream, 0, length + 1); | 148 | eina_strbuf_remove(clientStream, 0, length + 1); |
161 | ext = rindex(SID, '.'); | 149 | ext = index(SID, '.'); |
162 | if (ext) | 150 | if (ext) |
163 | { | 151 | { |
164 | script *me; | 152 | script *me; |