From 26df7205616dbcf80b60c1ed3c04ebea26975fe9 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 21 Apr 2014 18:28:19 +1000 Subject: Convert LuaSL to use LumbrJack. --- LuaSL/src/LuaSL.h | 31 +------- LuaSL/src/LuaSL_LSL_tree.h | 4 +- LuaSL/src/LuaSL_compile.c | 24 +++--- LuaSL/src/LuaSL_lemon_yaccer.y | 8 +- LuaSL/src/LuaSL_main.c | 80 ++++++++++---------- LuaSL/src/LuaSL_test.c | 162 ++++++++++++++++++++--------------------- LuaSL/src/LuaSL_threads.c | 4 +- LuaSL/src/LuaSL_threads.h | 2 +- LuaSL/src/LuaSL_utilities.c | 84 +-------------------- test.sh | 6 +- 10 files changed, 151 insertions(+), 254 deletions(-) diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h index 086d1b7..5dfa0eb 100644 --- a/LuaSL/src/LuaSL.h +++ b/LuaSL/src/LuaSL.h @@ -23,39 +23,16 @@ typedef struct _script script; // Define this here, so LuaSL_threads.h can use typedef struct _gameGlobals gameGlobals; // Define this here, so LuaSL_threads.h can use it. #include "LuaSL_threads.h" +#include "LumbrJack.h" #define WIDTH (1024) #define HEIGHT (768) -#define PC(...) EINA_LOG_DOM_CRIT(game->logDom, __VA_ARGS__) -#define PE(...) EINA_LOG_DOM_ERR(game->logDom, __VA_ARGS__) -#define PW(...) EINA_LOG_DOM_WARN(game->logDom, __VA_ARGS__) -#define PD(...) EINA_LOG_DOM_DBG(game->logDom, __VA_ARGS__) -#define PI(...) EINA_LOG_DOM_INFO(game->logDom, __VA_ARGS__) - -#define PCm(...) EINA_LOG_DOM_CRIT(game.logDom, __VA_ARGS__) -#define PEm(...) EINA_LOG_DOM_ERR(game.logDom, __VA_ARGS__) -#define PWm(...) EINA_LOG_DOM_WARN(game.logDom, __VA_ARGS__) -#define PDm(...) EINA_LOG_DOM_DBG(game.logDom, __VA_ARGS__) -#define PIm(...) EINA_LOG_DOM_INFO(game.logDom, __VA_ARGS__) - -#define D() PD("DEBUG") - -// "01:03:52 01-01-1973\n\0" -#define DATE_TIME_LEN 21 #define TABLE_WIDTH 7 #define TABLE_HEIGHT 42 -#ifndef FALSE -// NEVER change this -typedef enum -{ - FALSE = 0, - TRUE = 1 -} boolean; -#endif struct _gameGlobals { @@ -97,11 +74,9 @@ typedef struct } scriptMessage; -void loggingStartup(gameGlobals *game); -char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); void scriptSendBack(void * data); -void sendBack(gameGlobals *game, Ecore_Con_Client *client, const char *SID, const char *message, ...); -void sendForth(gameGlobals *game, const char *SID, const char *message, ...); +void sendBack(gameGlobals *ourGlobals, Ecore_Con_Client *client, const char *SID, const char *message, ...); +void sendForth(gameGlobals *ourGlobals, const char *SID, const char *message, ...); float timeDiff(struct timeval *now, struct timeval *then); #include "LuaSL_LSL_tree.h" diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index f172110..5415228 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h @@ -406,8 +406,8 @@ typedef struct -boolean compilerSetup(gameGlobals *game); -boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *SID, char *script, boolean doConstants); +boolean compilerSetup(gameGlobals *ourGlobals); +boolean compileLSL(gameGlobals *ourGlobals, 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 2a4c503..afff67f 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -316,7 +316,7 @@ static LSL_Leaf *findVariable(LuaSL_compiler *compiler, const char *name) LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf *dot, LSL_Leaf *sub) { - gameGlobals *game = compiler->game; + gameGlobals *ourGlobals = compiler->game; const char *search; if (dot) @@ -358,7 +358,7 @@ LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf else { compiler->script.bugCount++; - sendBack(game, compiler->client, compiler->SID, "compilerError(%d,%d,NOT found %s)", identifier->line, identifier->column, identifier->value.stringValue); + sendBack(ourGlobals, compiler->client, compiler->SID, "compilerError(%d,%d,NOT found %s)", identifier->line, identifier->column, identifier->value.stringValue); } } @@ -367,7 +367,7 @@ LSL_Leaf *checkVariable(LuaSL_compiler *compiler, LSL_Leaf *identifier, LSL_Leaf LSL_Leaf *addOperation(LuaSL_compiler *compiler, LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) { - gameGlobals *game = compiler->game; + gameGlobals *ourGlobals = compiler->game; if (lval) { @@ -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->SID, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); + sendBack(ourGlobals, 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->SID, "compilerWarning(%d,%d,Undeclared identifier issue, deferring this until the second pass)", lval->line, lval->column); + sendBack(ourGlobals, 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->SID, "compilerError(%d,%d,Invalid operation [%s(%s) %s %s(%s)])", lval->line, lval->column, leftType, leftToken, lval->toKen->toKen, rightType, rightToken); + sendBack(ourGlobals, 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); } } @@ -991,7 +991,7 @@ LSL_Leaf *addFor(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Leaf *flow, LSL_L LSL_Leaf *addStatement(LuaSL_compiler *compiler, LSL_Leaf *lval, LSL_Leaf *flow, LSL_Leaf *left, LSL_Leaf *expr, LSL_Leaf *right, LSL_Leaf *block, LSL_Leaf *identifier) { - gameGlobals *game = compiler->game; + gameGlobals *ourGlobals = compiler->game; LSL_Statement *stat = calloc(1, sizeof(LSL_Statement)); boolean justOne = FALSE; @@ -2095,7 +2095,7 @@ static void outputStringToken(FILE *file, outputMode mode, LSL_Leaf *content) fprintf(file, "%s", content->value.stringValue); // The quotes are part of the string value already. } -boolean compilerSetup(gameGlobals *game) +boolean compilerSetup(gameGlobals *ourGlobals) { int i; @@ -2122,7 +2122,7 @@ boolean compilerSetup(gameGlobals *game) snprintf(buf, sizeof(buf), "lua -e 'require(\"LSL\").gimmeLSL()' > %s/constants.lsl", PACKAGE_DATA_DIR); system(buf); snprintf(buf, sizeof(buf), "%s/constants.lsl", PACKAGE_DATA_DIR); - compileLSL(game, NULL, "FAKE_SID", buf, TRUE); + compileLSL(ourGlobals, NULL, "FAKE_SID", buf, TRUE); return TRUE; } @@ -2142,7 +2142,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 *SID, char *script, boolean doConstants) +boolean compileLSL(gameGlobals *ourGlobals, Ecore_Con_Client *client, char *SID, char *script, boolean doConstants) { boolean result = FALSE; LuaSL_compiler compiler; @@ -2153,7 +2153,7 @@ boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *SID, char // Just pass all LSL constants and ll*() )function names through to Lua, assume they are globals there. memset(&compiler, 0, sizeof(LuaSL_compiler)); - compiler.game = game; + compiler.game = ourGlobals; compiler.client = client; compiler.script.functions = eina_hash_stringshared_new(burnLeaf); compiler.script.states = eina_hash_stringshared_new(burnLeaf); @@ -2220,7 +2220,7 @@ boolean compileLSL(gameGlobals *game, Ecore_Con_Client *client, char *SID, char call->call->basicType = func->basicType; } else - sendBack(game, compiler.client, compiler.SID, "compilerError(%d,%d,Undeclared function %s called)", call->call->line, call->call->column, call->call->value.stringValue); + sendBack(ourGlobals, 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); diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 1ac3cc8..182789f 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y @@ -222,14 +222,14 @@ expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; } %parse_accept { -// gameGlobals *game = compiler->game; +// gameGlobals *ourGlobals = compiler->game; // PI("Parsing complete."); } %parse_failure { - gameGlobals *game = compiler->game; + gameGlobals *ourGlobals = compiler->game; compiler->script.bugCount++; PE("Giving up. Parser is hopelessly lost!"); @@ -237,7 +237,7 @@ expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; } %stack_overflow { - gameGlobals *game = compiler->game; + gameGlobals *ourGlobals = compiler->game; compiler->script.bugCount++; PE("Giving up. Parser stack overflow @ line %d, column %d!", yypMinor->yy0->line, yypMinor->yy0->column); // Gotta love consistancy, if it ever happens. @@ -245,7 +245,7 @@ expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; } %syntax_error { - gameGlobals *game = compiler->game; + gameGlobals *ourGlobals = compiler->game; compiler->script.bugCount++; PE("Syntax error @ line %d, column %d!", yyminor.yy0->line, yyminor.yy0->column); diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index ac0b0c9..0a40712 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c @@ -9,24 +9,24 @@ static Eina_Strbuf *clientStream; static Eina_Bool _sleep_timer_cb(void *data) { script *script = data; - gameGlobals *game = script->game; + gameGlobals *ourGlobals = script->game; PD("Waking up %s", script->SID); - sendToChannel(game, script->SID, "return 0.0"); + sendToChannel(ourGlobals, script->SID, "return 0.0"); return ECORE_CALLBACK_CANCEL; } static Eina_Bool _timer_timer_cb(void *data) { script *script = data; - gameGlobals *game = script->game; + gameGlobals *ourGlobals = script->game; PD("Timer for %s", script->SID); - sendToChannel(game, script->SID, "events.timer()"); + sendToChannel(ourGlobals, script->SID, "events.timer()"); return ECORE_CALLBACK_RENEW; } -static script *findThem(gameGlobals *game, const char *base, const char *text) +static script *findThem(gameGlobals *ourGlobals, const char *base, const char *text) { char name[PATH_MAX]; char *temp; @@ -38,12 +38,12 @@ static script *findThem(gameGlobals *game, const char *base, const char *text) if ((temp = rindex(name, '"'))) temp[0] = '\0'; strcat(name, ".lsl"); - return eina_hash_find(game->names, name); + return eina_hash_find(ourGlobals->names, name); } static void resetScript(script *victim) { - gameGlobals *game = victim->game; + gameGlobals *ourGlobals = victim->game; PD("Resetting %s", victim->fileName); // TODO - now what? @@ -52,7 +52,7 @@ static void resetScript(script *victim) void scriptSendBack(void * data) { scriptMessage *message = data; - gameGlobals *game = message->script->game; + gameGlobals *ourGlobals = message->script->game; if (0 == strncmp(message->message, "llSleep(", 8)) ecore_timer_add(atof(&(message->message)[8]), _sleep_timer_cb, message->script); @@ -72,7 +72,7 @@ void scriptSendBack(void * data) { script *them; - if ((them = findThem(game, message->script->fileName, &(message->message[18])))) + if ((them = findThem(ourGlobals, message->script->fileName, &(message->message[18])))) { char *temp = rindex(&(message->message[18]), ','); @@ -82,9 +82,9 @@ void scriptSendBack(void * data) while (isspace(*temp)) temp++; if ('1' == *temp) - sendToChannel(game, them->SID, "start()"); + sendToChannel(ourGlobals, them->SID, "start()"); else - sendToChannel(game, them->SID, "stop()"); + sendToChannel(ourGlobals, them->SID, "stop()"); PD("Stopped %s", them->fileName); } else @@ -103,13 +103,13 @@ void scriptSendBack(void * data) { script *them; - if ((them = findThem(game, message->script->fileName, &(message->message[20])))) + if ((them = findThem(ourGlobals, message->script->fileName, &(message->message[20])))) resetScript(them); } else if (0 == strncmp(message->message, "llResetScript(", 14)) resetScript(message->script); else - sendBack(game, message->script->client, message->script->SID, message->message); + sendBack(ourGlobals, message->script->client, message->script->SID, message->message); free(message); } @@ -121,7 +121,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; + gameGlobals *ourGlobals = data; char buf[PATH_MAX]; char SID[PATH_MAX]; const char *command; @@ -154,28 +154,28 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D temp[0] = '\0'; PD("Compiling %s, %s.", SID, file); - if (compileLSL(game, ev->client, SID, file, FALSE)) + if (compileLSL(ourGlobals, 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)); - me->game = game; + me->game = ourGlobals; me->client = ev->client; - eina_hash_add(game->scripts, me->SID, me); - eina_hash_add(game->names, me->fileName, me); - sendBack(game, ev->client, SID, "compiled(true)"); + eina_hash_add(ourGlobals->scripts, me->SID, me); + eina_hash_add(ourGlobals->names, me->fileName, me); + sendBack(ourGlobals, ev->client, SID, "compiled(true)"); } else - sendBack(game, ev->client, SID, "compiled(false)"); + sendBack(ourGlobals, ev->client, SID, "compiled(false)"); } else if (0 == strcmp(command, "run()")) { script *me; char buf[PATH_MAX]; - me = eina_hash_find(game->scripts, SID); + me = eina_hash_find(ourGlobals->scripts, SID); if (me) { sprintf(buf, "%s.lua.out", me->fileName); @@ -191,7 +191,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D { const char *status = NULL; - status = sendToChannel(game, SID, command); + status = sendToChannel(ourGlobals, SID, command); if (status) PE("Error sending command %s to script %s : %s", command, SID, status); } @@ -206,7 +206,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D static Eina_Bool _del(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Del *ev) { - gameGlobals *game = data; + gameGlobals *ourGlobals = data; if (ev->client) { @@ -219,31 +219,31 @@ static Eina_Bool _del(void *data, int type __UNUSED__, Ecore_Con_Event_Client_De int main(int argc, char **argv) { - gameGlobals game; + gameGlobals ourGlobals; int result = EXIT_FAILURE; - memset(&game, 0, sizeof(gameGlobals)); - game.address = "127.0.0.1"; - game.port = 8211; + memset(&ourGlobals, 0, sizeof(gameGlobals)); + ourGlobals.address = "127.0.0.1"; + ourGlobals.port = 8211; if (eina_init()) { - loggingStartup(&game); - game.scripts = eina_hash_string_superfast_new(NULL); - game.names = eina_hash_string_superfast_new(NULL); + ourGlobals.logDom = loggingStartup("LuaSL", ourGlobals.logDom); + ourGlobals.scripts = eina_hash_string_superfast_new(NULL); + ourGlobals.names = eina_hash_string_superfast_new(NULL); if (ecore_con_init()) { if (ecore_con_init()) { - if ((game.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, game.address, game.port, &game))) + if ((ourGlobals.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port, &ourGlobals))) { - ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb) _add, &game); - ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb) _data, &game); - ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb) _del, &game); - ecore_con_server_timeout_set(game.server, 0); - ecore_con_server_client_limit_set(game.server, -1, 0); - ecore_con_server_timeout_set(game.server, 10); - ecore_con_server_client_limit_set(game.server, 3, 0); + ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb) _add, &ourGlobals); + ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb) _data, &ourGlobals); + ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb) _del, &ourGlobals); + ecore_con_server_timeout_set(ourGlobals.server, 0); + ecore_con_server_client_limit_set(ourGlobals.server, -1, 0); + ecore_con_server_timeout_set(ourGlobals.server, 10); + ecore_con_server_client_limit_set(ourGlobals.server, 3, 0); clientStream = eina_strbuf_new(); if (edje_init()) @@ -251,7 +251,7 @@ int main(int argc, char **argv) int i; result = 0; - compilerSetup(&game); + compilerSetup(&ourGlobals); luaprocInit(); for (i = 0; i < CPUs; i++) { @@ -402,7 +402,7 @@ static int errFunc(lua_State *L) return 0; } -void runLuaFile(gameGlobals *game, const char *filename) +void runLuaFile(gameGlobals *ourGlobals, const char *filename) { PD("Starting %s", filename); newProc(filename, TRUE); diff --git a/LuaSL/src/LuaSL_test.c b/LuaSL/src/LuaSL_test.c index 69cbf2c..51fd902 100644 --- a/LuaSL/src/LuaSL_test.c +++ b/LuaSL/src/LuaSL_test.c @@ -22,31 +22,31 @@ static const char *names[] = static void _edje_signal_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source) { -// gameGlobals *game = data; +// gameGlobals *ourGlobals = data; } static Eina_Bool anim(void *data) { - gameGlobals *game = data; + gameGlobals *ourGlobals = data; Evas_Object *bub, *sh; Evas_Coord x, y, w, h, vw, vh; double t, xx, yy, zz, r, fac; double lx, ly; unsigned int i; - evas_output_viewport_get(game->canvas, 0, 0, &vw, &vh); + evas_output_viewport_get(ourGlobals->canvas, 0, 0, &vw, &vh); r = 48; t = ecore_loop_time_get(); fac = 2.0 / (double)((sizeof(names) / sizeof(char *) / 2)); - evas_pointer_canvas_xy_get(game->canvas, &x, &y); + evas_pointer_canvas_xy_get(ourGlobals->canvas, &x, &y); lx = x; ly = y; for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) { - bub = evas_object_data_get(game->bg, names[i * 2]); - sh = evas_object_data_get(game->bg, names[(i * 2) + 1]); + bub = evas_object_data_get(ourGlobals->bg, names[i * 2]); + sh = evas_object_data_get(ourGlobals->bg, names[(i * 2) + 1]); zz = (((2 + sin(t * 6 + (M_PI * (i * fac)))) / 3) * 64) * 2; xx = (cos(t * 4 + (M_PI * (i * fac))) * r) * 2; yy = (sin(t * 6 + (M_PI * (i * fac))) * r) * 2; @@ -78,7 +78,7 @@ _on_delete(Ecore_Evas *ee __UNUSED__) static void dirList_compile(const char *name, const char *path, void *data) { - gameGlobals *game = data; + gameGlobals *ourGlobals = data; char *ext = rindex(name, '.'); @@ -92,34 +92,34 @@ static void dirList_compile(const char *name, const char *path, void *data) gettimeofday(&me->startTime, NULL); 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(%s)", me->fileName); + eina_hash_add(ourGlobals->scripts, me->SID, me); + sendForth(ourGlobals, me->SID, "compile(%s)", me->fileName); } } } static Eina_Bool _timer_cb(void *data) { - gameGlobals *game = data; + gameGlobals *ourGlobals = data; Eina_Iterator *scripts; script *me; boolean exit = FALSE; - scripts = eina_hash_iterator_data_new(game->scripts); + scripts = eina_hash_iterator_data_new(ourGlobals->scripts); while(eina_iterator_next(scripts, (void **) &me)) { switch (timedEvent) { case 5 : { - sendForth(game, me->SID, "events.detectedKeys({\"%s\"})", ownerKey); - sendForth(game, me->SID, "events.detectedNames({\"%s\"})", ownerName); - sendForth(game, me->SID, "events.touch_start(1)"); + sendForth(ourGlobals, me->SID, "events.detectedKeys({\"%s\"})", ownerKey); + sendForth(ourGlobals, me->SID, "events.detectedNames({\"%s\"})", ownerName); + sendForth(ourGlobals, me->SID, "events.touch_start(1)"); break; } case 9 : { - sendForth(game, me->SID, "quit()"); + sendForth(ourGlobals, me->SID, "quit()"); break; } case 11 : @@ -133,7 +133,7 @@ static Eina_Bool _timer_cb(void *data) if (exit) { - sendForth(game, ownerKey, "exit()"); + sendForth(ourGlobals, ownerKey, "exit()"); ecore_main_loop_quit(); return ECORE_CALLBACK_CANCEL; } @@ -142,21 +142,21 @@ static Eina_Bool _timer_cb(void *data) static Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Server_Add *ev) { - gameGlobals *game = data; + gameGlobals *ourGlobals = data; char buf[PATH_MAX]; - game->server = ev->server; + ourGlobals->server = ev->server; gettimeofday(&startTime, NULL); snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR); - eina_file_dir_list(buf, EINA_TRUE, dirList_compile, game); + eina_file_dir_list(buf, EINA_TRUE, dirList_compile, ourGlobals); // Wait awhile, then start sending events for testing. - ecore_timer_add(0.5, _timer_cb, game); + ecore_timer_add(0.5, _timer_cb, ourGlobals); return ECORE_CALLBACK_RENEW; } static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_Data *ev) { - gameGlobals *game = data; + gameGlobals *ourGlobals = data; char buf[PATH_MAX]; char SID[PATH_MAX]; @@ -179,7 +179,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D ext[0] = '\0'; command = ext + 1; - me = eina_hash_find(game->scripts, SID); + me = eina_hash_find(ourGlobals->scripts, SID); if (0 == strncmp(command, "compilerWarning(", 16)) { char *temp; @@ -247,31 +247,31 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D PD("TOTAL compile speed is %f scripts per second", compiledCount / timeDiff(&now, &startTime)); } // PD("The compile of %s worked, running it now.", SID); - sendForth(game, SID, "run()"); + sendForth(ourGlobals, SID, "run()"); } else { // Send back some random or fixed values for testing. if (0 == strcmp(command, "llGetKey()")) - sendForth(game, SID, "return \"%08lx-%04lx-%04lx-%04lx-%012lx\"", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random()); + sendForth(ourGlobals, SID, "return \"%08lx-%04lx-%04lx-%04lx-%012lx\"", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random()); else if (0 == strcmp(command, "llGetOwner()")) - sendForth(game, SID, "return \"%s\"", ownerKey); + sendForth(ourGlobals, SID, "return \"%s\"", ownerKey); else if (0 == strcmp(command, "llGetPos()")) - sendForth(game, SID, "return {x=128.0, y=128.0, z=128.0}"); + sendForth(ourGlobals, SID, "return {x=128.0, y=128.0, z=128.0}"); else if (0 == strcmp(command, "llGetRot()")) - sendForth(game, SID, "return {x=0.0, y=0.0, z=0.0, s=1.0}"); + sendForth(ourGlobals, SID, "return {x=0.0, y=0.0, z=0.0, s=1.0}"); else if (0 == strcmp(command, "llGetObjectDesc()")) - sendForth(game, SID, "return \"\""); + sendForth(ourGlobals, SID, "return \"\""); else if (0 == strncmp(command, "llGetAlpha(", 11)) - sendForth(game, SID, "return 1.0"); + sendForth(ourGlobals, SID, "return 1.0"); else if (0 == strcmp(command, "llGetInventoryNumber(7)")) - sendForth(game, SID, "return 3"); + sendForth(ourGlobals, SID, "return 3"); else if (0 == strcmp(command, "llGetInventoryName(7, 2)")) - sendForth(game, SID, "return \".readme\""); + sendForth(ourGlobals, SID, "return \".readme\""); else if (0 == strcmp(command, "llGetInventoryName(7, 1)")) - sendForth(game, SID, "return \".POSITIONS\""); + sendForth(ourGlobals, SID, "return \".POSITIONS\""); else if (0 == strcmp(command, "llGetInventoryName(7, 0)")) - sendForth(game, SID, "return \".MENUITEMS\""); + sendForth(ourGlobals, SID, "return \".MENUITEMS\""); else PI("Script %s sent command %s", SID, command); } @@ -286,11 +286,11 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Server_D static Eina_Bool _del(void *data, int type __UNUSED__, Ecore_Con_Event_Server_Del *ev) { - gameGlobals *game = data; + gameGlobals *ourGlobals = data; if (ev->server) { - game->server = NULL; + ourGlobals->server = NULL; ecore_con_server_del(ev->server); ecore_main_loop_quit(); } @@ -301,27 +301,27 @@ static Eina_Bool _del(void *data, int type __UNUSED__, Ecore_Con_Event_Server_De int main(int argc, char **argv) { /* put here any init specific to this app like parsing args etc. */ - gameGlobals game; + gameGlobals ourGlobals; char *programName = argv[0]; boolean badArgs = FALSE; int result = EXIT_FAILURE; - memset(&game, 0, sizeof(gameGlobals)); - game.address = "127.0.0.1"; - game.port = 8211; + memset(&ourGlobals, 0, sizeof(gameGlobals)); + ourGlobals.address = "127.0.0.1"; + ourGlobals.port = 8211; if (eina_init()) { - loggingStartup(&game); - game.scripts = eina_hash_string_superfast_new(NULL); + ourGlobals.logDom = loggingStartup("LuaSL_test", ourGlobals.logDom); + ourGlobals.scripts = eina_hash_string_superfast_new(NULL); if (ecore_con_init()) { - if ((game.server = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, game.address, game.port, &game))) + if ((ourGlobals.server = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port, &ourGlobals))) { - ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb) _add, &game); - ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb) _data, &game); - ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb) _del, &game); + ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb) _add, &ourGlobals); + ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb) _data, &ourGlobals); + ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb) _del, &ourGlobals); clientStream = eina_strbuf_new(); if (ecore_evas_init()) @@ -340,7 +340,7 @@ int main(int argc, char **argv) { case 'u': { - game.ui = TRUE; + ourGlobals.ui = TRUE; break; } default: @@ -358,7 +358,7 @@ int main(int argc, char **argv) printf(" -u: Show the test UI.\n"); } else - // else if ((game.config) && (game.data)) + // else if ((ourGlobals.config) && (ourGlobals.data)) { unsigned int i; Evas_Object *bub, *sh; @@ -366,80 +366,80 @@ int main(int argc, char **argv) char *group = "main"; char buf[PATH_MAX]; - if (game.ui) + if (ourGlobals.ui) { /* this will give you a window with an Evas canvas under the first engine available */ - game.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); - if (!game.ee) + ourGlobals.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); + if (!ourGlobals.ee) { PEm("You got to have at least one evas engine built and linked up to ecore-evas for this example to run properly."); edje_shutdown(); ecore_evas_shutdown(); return -1; } - game.canvas = ecore_evas_get(game.ee); - ecore_evas_title_set(game.ee, "LuaSL test harness"); - ecore_evas_show(game.ee); - - game.bg = evas_object_rectangle_add(game.canvas); - evas_object_color_set(game.bg, 255, 255, 255, 255); /* white bg */ - evas_object_move(game.bg, 0, 0); /* at canvas' origin */ - evas_object_size_hint_weight_set(game.bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_resize(game.bg, WIDTH, HEIGHT); /* covers full canvas */ - evas_object_show(game.bg); - ecore_evas_object_associate(game.ee, game.bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); - evas_object_focus_set(game.bg, EINA_TRUE); - - game.edje = edje_object_add(game.canvas); + ourGlobals.canvas = ecore_evas_get(ourGlobals.ee); + ecore_evas_title_set(ourGlobals.ee, "LuaSL test harness"); + ecore_evas_show(ourGlobals.ee); + + ourGlobals.bg = evas_object_rectangle_add(ourGlobals.canvas); + evas_object_color_set(ourGlobals.bg, 255, 255, 255, 255); /* white bg */ + evas_object_move(ourGlobals.bg, 0, 0); /* at canvas' origin */ + evas_object_size_hint_weight_set(ourGlobals.bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_resize(ourGlobals.bg, WIDTH, HEIGHT); /* covers full canvas */ + evas_object_show(ourGlobals.bg); + ecore_evas_object_associate(ourGlobals.ee, ourGlobals.bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); + evas_object_focus_set(ourGlobals.bg, EINA_TRUE); + + ourGlobals.edje = edje_object_add(ourGlobals.canvas); snprintf(buf, sizeof(buf), "%s/%s.edj", PACKAGE_DATA_DIR, "LuaSL"); - if (!edje_object_file_set(game.edje, buf, group)) + if (!edje_object_file_set(ourGlobals.edje, buf, group)) { - int err = edje_object_load_error_get(game.edje); + int err = edje_object_load_error_get(ourGlobals.edje); const char *errmsg = edje_load_error_str(err); PEm("Could not load '%s' from %s: %s\n", group, buf, errmsg); - evas_object_del(game.edje); - ecore_evas_free(game.ee); + evas_object_del(ourGlobals.edje); + ecore_evas_free(ourGlobals.ee); edje_shutdown(); ecore_evas_shutdown(); return -2; } - evas_object_move(game.edje, 0, 0); - evas_object_resize(game.edje, WIDTH, HEIGHT); - evas_object_show(game.edje); + evas_object_move(ourGlobals.edje, 0, 0); + evas_object_resize(ourGlobals.edje, WIDTH, HEIGHT); + evas_object_show(ourGlobals.edje); snprintf(buf, sizeof(buf), "%s/images/bubble_sh.png", PACKAGE_DATA_DIR); for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) { - sh = evas_object_image_filled_add(game.canvas); + sh = evas_object_image_filled_add(ourGlobals.canvas); evas_object_image_file_set(sh, buf, NULL); evas_object_resize(sh, 64, 64); evas_object_show(sh); - evas_object_data_set(game.bg, names[(i * 2) + 1], sh); + evas_object_data_set(ourGlobals.bg, names[(i * 2) + 1], sh); } snprintf(buf, sizeof(buf), "%s/images/bubble.png", PACKAGE_DATA_DIR); for (i = 0; i < (sizeof(names) / sizeof(char *) / 2); i++) { - bub = evas_object_image_filled_add(game.canvas); + bub = evas_object_image_filled_add(ourGlobals.canvas); evas_object_image_file_set(bub, buf, NULL); evas_object_resize(bub, 64, 64); evas_object_show(bub); - evas_object_data_set(game.bg, names[(i * 2)], bub); + evas_object_data_set(ourGlobals.bg, names[(i * 2)], bub); } - ani = ecore_animator_add(anim, &game); - evas_object_data_set(game.bg, "animator", ani); + ani = ecore_animator_add(anim, &ourGlobals); + evas_object_data_set(ourGlobals.bg, "animator", ani); // Setup our callbacks. - ecore_evas_callback_delete_request_set(game.ee, _on_delete); - edje_object_signal_callback_add(game.edje, "*", "game_*", _edje_signal_cb, &game); + ecore_evas_callback_delete_request_set(ourGlobals.ee, _on_delete); + edje_object_signal_callback_add(ourGlobals.edje, "*", "game_*", _edje_signal_cb, &ourGlobals); } ecore_main_loop_begin(); - if (game.ui) + if (ourGlobals.ui) { ecore_animator_del(ani); - ecore_evas_free(game.ee); + ecore_evas_free(ourGlobals.ee); } } diff --git a/LuaSL/src/LuaSL_threads.c b/LuaSL/src/LuaSL_threads.c index aec5ed6..234a7c5 100644 --- a/LuaSL/src/LuaSL_threads.c +++ b/LuaSL/src/LuaSL_threads.c @@ -392,7 +392,7 @@ const char *sendToChannelErrors[] = }; /* send a message to a lua process */ -const char *sendToChannel(gameGlobals *game, const char *SID, const char *message) +const char *sendToChannel(gameGlobals *ourGlobals, const char *SID, const char *message) { const char *result = NULL; script *dstlp; @@ -401,7 +401,7 @@ const char *sendToChannel(gameGlobals *game, const char *SID, const char *messag pthread_mutex_lock(&mutex_channel); // Add the message to the queue. - if ((dstlp = eina_hash_find(game->scripts, SID))) + if ((dstlp = eina_hash_find(ourGlobals->scripts, SID))) { scriptMessage *sm = NULL; diff --git a/LuaSL/src/LuaSL_threads.h b/LuaSL/src/LuaSL_threads.h index 78c6639..9a11b5c 100644 --- a/LuaSL/src/LuaSL_threads.h +++ b/LuaSL/src/LuaSL_threads.h @@ -46,7 +46,7 @@ THE SOFTWARE. void luaprocInit(void); int sched_create_worker(void); void newProc(const char *code, int file, script *lp); -const char *sendToChannel(gameGlobals *game, const char *SID, const char *message); +const char *sendToChannel(gameGlobals *ourGlobals, const char *SID, const char *message); /* join all worker threads and exit */ void sched_join_workerthreads(void); diff --git a/LuaSL/src/LuaSL_utilities.c b/LuaSL/src/LuaSL_utilities.c index e25b46c..40263df 100644 --- a/LuaSL/src/LuaSL_utilities.c +++ b/LuaSL/src/LuaSL_utilities.c @@ -1,83 +1,7 @@ #include "LuaSL.h" -// "01:03:52 01-01-1973\n\0" -# define DATE_TIME_LEN 21 - - -char dateTime[DATE_TIME_LEN]; - - -static -void _ggg_log_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args) -{ - FILE *f = data; - char dt[DATE_TIME_LEN + 1]; - char fileTab[256], funcTab[256]; - - getDateTime(NULL, dt, NULL); - dt[19] = '\0'; - if (12 > strlen(file)) - snprintf(fileTab, sizeof(fileTab), "%s\t\t", file); - else - snprintf(fileTab, sizeof(fileTab), "%s\t", file); - snprintf(funcTab, sizeof(funcTab), "\t%s", fnc); - fprintf(f, "%s ", dt); - if (f == stderr) - eina_log_print_cb_stderr(d, level, fileTab, funcTab, line, fmt, data, args); - else if (f == stdout) - eina_log_print_cb_stdout(d, level, fileTab, funcTab, line, fmt, data, args); - fflush(f); -} - -void loggingStartup(gameGlobals *game) -{ - game->logDom = eina_log_domain_register("LuaSL", NULL); - if (game->logDom < 0) - { - EINA_LOG_CRIT("could not register log domain 'LuaSL'"); - } - // TODO - should unregister this later. - eina_log_level_set(EINA_LOG_LEVEL_DBG); - eina_log_domain_level_set("LuaSL", EINA_LOG_LEVEL_DBG); - eina_log_print_cb_set(_ggg_log_print_cb, stderr); - - // Shut up the excess debugging shit from EFL. - eina_log_domain_level_set("eo", EINA_LOG_LEVEL_WARN); - eina_log_domain_level_set("eldbus", EINA_LOG_LEVEL_WARN); - eina_log_domain_level_set("eet", EINA_LOG_LEVEL_WARN); - eina_log_domain_level_set("ecore", EINA_LOG_LEVEL_WARN); - eina_log_domain_level_set("ecore_audio", EINA_LOG_LEVEL_WARN); - eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_WARN); - eina_log_domain_level_set("ecore_input_evas", EINA_LOG_LEVEL_WARN); - eina_log_domain_level_set("ecore_input_evas", EINA_LOG_LEVEL_WARN); - eina_log_domain_level_set("ecore_system_upower", EINA_LOG_LEVEL_WARN); -} - -char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) -{ - struct tm *newTime; - time_t szClock; - char *date = dateTime; - - // Get time in seconds - time(&szClock); - // Convert time to struct tm form - newTime = localtime(&szClock); - - if (nowOut) - *nowOut = newTime; - if (dateOut) - date = dateOut; - if (timeOut) - *timeOut = szClock; - - // format - strftime(date, DATE_TIME_LEN, "%d/%m/%Y %H:%M:%S\r", newTime); - return (dateTime); -} - -void sendBack(gameGlobals *game, Ecore_Con_Client *client, const char *SID, const char *message, ...) +void sendBack(gameGlobals *ourGlobals, Ecore_Con_Client *client, const char *SID, const char *message, ...) { va_list args; char buf[PATH_MAX]; @@ -94,7 +18,7 @@ void sendBack(gameGlobals *game, Ecore_Con_Client *client, const char *SID, cons ecore_con_client_flush(client); } -void sendForth(gameGlobals *game, const char *SID, const char *message, ...) +void sendForth(gameGlobals *ourGlobals, const char *SID, const char *message, ...) { va_list args; char buf[PATH_MAX]; @@ -107,8 +31,8 @@ void sendForth(gameGlobals *game, const char *SID, const char *message, ...) va_end(args); buf[length++] = '\n'; buf[length++] = '\0'; - ecore_con_server_send(game->server, buf, strlen(buf)); - ecore_con_server_flush(game->server); + ecore_con_server_send(ourGlobals->server, buf, strlen(buf)); + ecore_con_server_flush(ourGlobals->server); } float timeDiff(struct timeval *now, struct timeval *then) diff --git a/test.sh b/test.sh index 1b77b42..7d2ab31 100755 --- a/test.sh +++ b/test.sh @@ -4,7 +4,7 @@ reset wd=$(pwd) -./build.sh || exit +./build.lua || exit echo "_______________ TESTING extantz _______________" cd $wd/ClientHamr/extantz @@ -21,9 +21,7 @@ echo "_______________ TESTING LuaSL _______________" killall -KILL LuaSL cd $wd/LuaSL/testLua export LUA_PATH="$wd/LuaSL/src/?.lua" -export LUA_SOPATH='../../libraries/luaproc/' -export LD_LIBRARY_PATH="../../libraries/luajit-2.0/src:$LD_LIBRARY_PATH" -export EINA_LOG_LEVELS="eo:2,ecore:2,ecore_con:2" +export LD_LIBRARY_PATH="../../libraries:$LD_LIBRARY_PATH" case $@ in -- cgit v1.1