From f93cf73e01e9cf4b0a6be43d61ebc24b9fa64b0d Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 22 Feb 2012 23:46:56 +1000 Subject: Implement callAndReturn(), use it from callAndWait(). That's most of LuaSL's side of "use OpenSim to deal with in world stuff". --- LuaSL/src/LSL.lua | 13 +++++++++---- LuaSL/src/LuaSL.h | 29 ++++++++++++++++++----------- LuaSL/src/LuaSL_main.c | 12 +++++++++++- 3 files changed, 38 insertions(+), 16 deletions(-) (limited to 'LuaSL/src') diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua index 8861bf3..b8e2d4b 100644 --- a/LuaSL/src/LSL.lua +++ b/LuaSL/src/LSL.lua @@ -94,14 +94,19 @@ function args2string(doType, ...) return temp end -function mt.callAndReturn(name, ... ) - print("mt.callAndReturn(" .. name .. "(" .. args2string(true, ...) .. "))") +function mt.callAndReturn(name, ...) + luaproc.sendback(name .. "(" .. args2string(true, ...) .. ")") end -function mt.callAndWait(name, ... ) +function mt.callAndWait(name, ...) local func = functions[name] - print("mt.callAndWait(" .. name .. "(" .. args2string(true, ...) .. "))") + mt.callAndReturn(name, ...); + +--[[ TODO - do a luaproc sync receive() waiting for the result. + Eventually a sendForth() is called, which should end up passing through SendToChannel(). + The format of the result should be something like - SID.result({x=0.45, y=0.6, z=1.8}) +]] if "float" == func.Type then return 0.0 elseif "integer" == func.Type then return 0 diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h index f6a5fad..6d495fa 100644 --- a/LuaSL/src/LuaSL.h +++ b/LuaSL/src/LuaSL.h @@ -49,17 +49,6 @@ 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. @@ -72,6 +61,24 @@ typedef struct boolean ui; // Wether we actually start up the UI. } gameGlobals; +typedef struct +{ + char SID[PATH_MAX]; + char fileName[PATH_MAX]; + struct timeval startTime; + float compileTime; + int bugs, warnings; + boolean running; + gameGlobals *game; + Ecore_Con_Client *client; +} script; + +typedef struct +{ + script *script; + const char message[PATH_MAX]; +} scriptMessage; + void loggingStartup(gameGlobals *game); char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index e56aaf3..daee816 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c @@ -6,6 +6,14 @@ static int CPUs = 4; static Eina_Strbuf *clientStream; +static void _sendBack(void * data) +{ + scriptMessage *message = data; + + sendBack(message->script->game, message->script->client, message->script->SID, message->message); + free(message); +} + static Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev) { ecore_con_client_timeout_set(ev->client, 0); @@ -54,6 +62,8 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D gettimeofday(&me->startTime, NULL); strncpy(me->SID, SID, sizeof(me->SID)); strncpy(me->fileName, file, sizeof(me->fileName)); + me->game = game; + me->client = ev->client; eina_hash_add(game->scripts, me->SID, me); sendBack(game, ev->client, SID, "compiled(true)"); } @@ -69,7 +79,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D if (me) { sprintf(buf, "%s.lua.out", me->fileName); - newProc(buf, TRUE); + newProc(buf, TRUE, (Ecore_Cb) _sendBack, me); } } else if (0 == strcmp(command, "exit()")) -- cgit v1.1