From 47c86b21aea0ccc823f10abd9403c1e00cfd8a1e Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 19 Feb 2012 04:53:36 +1000 Subject: Change over to referring to scripts by SID. --- LuaSL/src/LuaSL.h | 11 +++++++++++ LuaSL/src/LuaSL_LSL_tree.h | 3 ++- LuaSL/src/LuaSL_compile.c | 19 ++++++++++--------- LuaSL/src/LuaSL_main.c | 37 +++++++++++++++++++++++++++++++------ LuaSL/src/LuaSL_test.c | 18 +++--------------- 5 files changed, 57 insertions(+), 31 deletions(-) (limited to 'LuaSL') 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 typedef struct { + char SID[PATH_MAX]; + char fileName[PATH_MAX]; + struct timeval startTime; + float compileTime; + int bugs, warnings; + boolean running; + +} script; + +typedef struct +{ Ecore_Evas *ee; // Our window. Evas *canvas; // The canvas for drawing directly onto. 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 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. int argc; char **argv; + char SID[37]; char fileName[PATH_MAX]; FILE *file; LSL_Leaf *ast; @@ -416,7 +417,7 @@ typedef struct boolean compilerSetup(gameGlobals *game); -boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, boolean doConstants); +boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *SID, char *script, boolean doConstants); void burnLeaf(void *data); 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 else { compiler->script.bugCount++; - sendBack(game, compiler->client, compiler->fileName, "compilerError(%d,%d,NOT found %s)", identifier->line, identifier->column, identifier->value.stringValue); + sendBack(game, compiler->client, compiler->SID, "compilerError(%d,%d,NOT found %s)", identifier->line, identifier->column, identifier->value.stringValue); } } @@ -402,7 +402,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, if (OT_undeclared == lType) { compiler->script.warningCount++; - sendBack(game, compiler->client, compiler->fileName, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); + sendBack(game, compiler->client, compiler->SID, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); lval->basicType = OT_undeclared; return lval; } @@ -430,7 +430,7 @@ LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, if (OT_undeclared == rType) { compiler->script.warningCount++; - sendBack(game, compiler->client, compiler->fileName, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); + sendBack(game, compiler->client, compiler->SID, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); lval->basicType = OT_undeclared; return lval; } @@ -587,7 +587,7 @@ else } compiler->script.bugCount++; - 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); + 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); } } @@ -2120,7 +2120,7 @@ boolean compilerSetup(gameGlobals *game) // Compile the constants. snprintf(buf, sizeof(buf), "%s/src/constants.lsl", PACKAGE_DATA_DIR); - compileLSL(game, NULL, buf, TRUE); + compileLSL(game, NULL, "FAKE_SID", buf, TRUE); return TRUE; } @@ -2140,7 +2140,7 @@ static int luaWriter(lua_State *L, const void* p, size_t sz, void* ud) return result; } -boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, boolean doConstants) +boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *SID, char *script, boolean doConstants) { boolean result = FALSE; LuaSL_compiler compiler; @@ -2161,6 +2161,8 @@ boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, bo compiler.ignorable = eina_strbuf_new(); #endif + strncpy(compiler.SID, SID, 36); + compiler.SID[36] = '\0'; strncpy(compiler.fileName, script, PATH_MAX - 1); compiler.fileName[PATH_MAX - 1] = '\0'; compiler.file = fopen(compiler.fileName, "r"); @@ -2216,7 +2218,7 @@ boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, bo call->call->basicType = func->basicType; } else - sendBack(game, compiler.client, compiler.fileName, "compilerError(%d,%d,Undeclared function %s called)", call->call->line, call->call->column, call->call->value.stringValue); + sendBack(game, compiler.client, compiler.SID, "compilerError(%d,%d,Undeclared function %s called)", call->call->line, call->call->column, call->call->value.stringValue); } } secondPass(&compiler, compiler.ast); @@ -2275,8 +2277,7 @@ boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *script, bo fprintf(out, "--// Generated code goes here.\n\n"); fprintf(out, "local _bit = require(\"bit\")\n"); fprintf(out, "local _LSL = require(\"LSL\")\n\n"); - // TODO - Use the scripts UUID instead of the file name here, or something. - fprintf(out, "local _SID = [=[%s]=]\n\n", compiler.fileName); + fprintf(out, "local _SID = [=[%s]=]\n\n", compiler.SID); outputLeaf(out, OM_LUA, compiler.ast); fprintf(out, "\n\n_LSL.mainLoop(_SID, _defaultState)\n"); // This actually starts the script running. 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 static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Data *ev) { gameGlobals *game = data; + char buf[PATH_MAX]; char SID[PATH_MAX]; const char *command; char *ext; @@ -28,25 +29,48 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D strncpy(SID, command, length + 1); SID[length] = '\0'; eina_strbuf_remove(clientStream, 0, length + 1); - ext = rindex(SID, '.'); + ext = index(SID, '.'); if (ext) { ext[0] = '\0'; command = ext + 1; - if (0 == strcmp(command, "compile()")) + if (0 == strncmp(command, "compile(", 8)) { - PD("Compiling %s.", SID); - if (compileLSL(game, ev->client, SID, FALSE)) + char *temp; + char *file; + + strcpy(buf, &command[8]); + temp = buf; + file = temp; + while (')' != temp[0]) + temp++; + temp[0] = '\0'; + + PD("Compiling %s, %s.", SID, file); + if (compileLSL(game, ev->client, SID, file, FALSE)) + { + script *me = calloc(1, sizeof(script)); + + gettimeofday(&me->startTime, NULL); + strncpy(me->SID, SID, sizeof(me->SID)); + strncpy(me->fileName, file, sizeof(me->fileName)); + eina_hash_add(game->scripts, me->SID, me); sendBack(game, ev->client, SID, "compiled(true)"); + } else sendBack(game, ev->client, SID, "compiled(false)"); } else if (0 == strcmp(command, "run()")) { + script *me; char buf[PATH_MAX]; - sprintf(buf, "%s.lua.out", SID); - newProc(buf, TRUE); + me = eina_hash_find(game->scripts, SID); + if (me) + { + sprintf(buf, "%s.lua.out", me->fileName); + newProc(buf, TRUE); + } } else if (0 == strcmp(command, "exit()")) { @@ -95,6 +119,7 @@ int main(int argc, char **argv) if (eina_init()) { loggingStartup(&game); + game.scripts = eina_hash_string_superfast_new(NULL); if (ecore_con_init()) { 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 @@ #include "LuaSL.h" -typedef struct -{ - char SID[PATH_MAX]; - char fileName[PATH_MAX]; - struct timeval startTime; - float compileTime; - int bugs, warnings; - boolean running; - -} script; - - static Eina_Strbuf *clientStream; static int scriptCount = 0; static int compiledCount = 0; @@ -99,10 +87,10 @@ static void dirList_compile(const char *name, const char *path, void *data) scriptCount++; gettimeofday(&me->startTime, NULL); - snprintf(me->SID, sizeof(me->SID), "%s/%s", path, name); + snprintf(me->SID, sizeof(me->SID), "%08lx-%04lx-%04lx-%04lx-%012lx", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random()); snprintf(me->fileName, sizeof(me->fileName), "%s/%s", path, name); eina_hash_add(game->scripts, me->SID, me); - sendForth(game, me->SID, "compile()"); + sendForth(game, me->SID, "compile(%s)", me->fileName); } } } @@ -158,7 +146,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D strncpy(SID, command, length + 1); SID[length] = '\0'; eina_strbuf_remove(clientStream, 0, length + 1); - ext = rindex(SID, '.'); + ext = index(SID, '.'); if (ext) { script *me; -- cgit v1.1