diff options
author | David Walter Seikel | 2012-02-22 23:46:56 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-02-22 23:46:56 +1000 |
commit | f93cf73e01e9cf4b0a6be43d61ebc24b9fa64b0d (patch) | |
tree | a291eb5bf596aad17791b37a2a2826d9271742f3 | |
parent | Implement llGetScriptName(). (diff) | |
download | SledjHamr-f93cf73e01e9cf4b0a6be43d61ebc24b9fa64b0d.zip SledjHamr-f93cf73e01e9cf4b0a6be43d61ebc24b9fa64b0d.tar.gz SledjHamr-f93cf73e01e9cf4b0a6be43d61ebc24b9fa64b0d.tar.bz2 SledjHamr-f93cf73e01e9cf4b0a6be43d61ebc24b9fa64b0d.tar.xz |
Implement callAndReturn(), use it from callAndWait(). That's most of LuaSL's side of "use OpenSim to deal with in world stuff".
Diffstat (limited to '')
-rw-r--r-- | LuaSL/src/LSL.lua | 13 | ||||
-rw-r--r-- | LuaSL/src/LuaSL.h | 29 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_main.c | 12 | ||||
-rw-r--r-- | libraries/luaproc/Makefile | 3 | ||||
-rw-r--r-- | libraries/luaproc/luaproc.c | 45 | ||||
-rw-r--r-- | libraries/luaproc/luaproc.h | 3 |
6 files changed, 85 insertions, 20 deletions
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, ...) | |||
94 | return temp | 94 | return temp |
95 | end | 95 | end |
96 | 96 | ||
97 | function mt.callAndReturn(name, ... ) | 97 | function mt.callAndReturn(name, ...) |
98 | print("mt.callAndReturn(" .. name .. "(" .. args2string(true, ...) .. "))") | 98 | luaproc.sendback(name .. "(" .. args2string(true, ...) .. ")") |
99 | end | 99 | end |
100 | 100 | ||
101 | function mt.callAndWait(name, ... ) | 101 | function mt.callAndWait(name, ...) |
102 | local func = functions[name] | 102 | local func = functions[name] |
103 | 103 | ||
104 | print("mt.callAndWait(" .. name .. "(" .. args2string(true, ...) .. "))") | 104 | mt.callAndReturn(name, ...); |
105 | |||
106 | --[[ TODO - do a luaproc sync receive() waiting for the result. | ||
107 | Eventually a sendForth() is called, which should end up passing through SendToChannel(). | ||
108 | The format of the result should be something like - SID.result({x=0.45, y=0.6, z=1.8}) | ||
109 | ]] | ||
105 | 110 | ||
106 | if "float" == func.Type then return 0.0 | 111 | if "float" == func.Type then return 0.0 |
107 | elseif "integer" == func.Type then return 0 | 112 | 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 | |||
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 | { | ||
63 | Ecore_Evas *ee; // Our window. | 52 | Ecore_Evas *ee; // Our window. |
64 | Evas *canvas; // The canvas for drawing directly onto. | 53 | Evas *canvas; // The canvas for drawing directly onto. |
65 | Evas_Object *bg; // Our background edje, also the game specific stuff. | 54 | Evas_Object *bg; // Our background edje, also the game specific stuff. |
@@ -72,6 +61,24 @@ typedef struct | |||
72 | boolean ui; // Wether we actually start up the UI. | 61 | boolean ui; // Wether we actually start up the UI. |
73 | } gameGlobals; | 62 | } gameGlobals; |
74 | 63 | ||
64 | typedef struct | ||
65 | { | ||
66 | char SID[PATH_MAX]; | ||
67 | char fileName[PATH_MAX]; | ||
68 | struct timeval startTime; | ||
69 | float compileTime; | ||
70 | int bugs, warnings; | ||
71 | boolean running; | ||
72 | gameGlobals *game; | ||
73 | Ecore_Con_Client *client; | ||
74 | } script; | ||
75 | |||
76 | typedef struct | ||
77 | { | ||
78 | script *script; | ||
79 | const char message[PATH_MAX]; | ||
80 | } scriptMessage; | ||
81 | |||
75 | 82 | ||
76 | void loggingStartup(gameGlobals *game); | 83 | void loggingStartup(gameGlobals *game); |
77 | char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); | 84 | 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; | |||
6 | static Eina_Strbuf *clientStream; | 6 | static Eina_Strbuf *clientStream; |
7 | 7 | ||
8 | 8 | ||
9 | static void _sendBack(void * data) | ||
10 | { | ||
11 | scriptMessage *message = data; | ||
12 | |||
13 | sendBack(message->script->game, message->script->client, message->script->SID, message->message); | ||
14 | free(message); | ||
15 | } | ||
16 | |||
9 | static Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev) | 17 | static Eina_Bool _add(void *data, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev) |
10 | { | 18 | { |
11 | ecore_con_client_timeout_set(ev->client, 0); | 19 | 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 | |||
54 | gettimeofday(&me->startTime, NULL); | 62 | gettimeofday(&me->startTime, NULL); |
55 | strncpy(me->SID, SID, sizeof(me->SID)); | 63 | strncpy(me->SID, SID, sizeof(me->SID)); |
56 | strncpy(me->fileName, file, sizeof(me->fileName)); | 64 | strncpy(me->fileName, file, sizeof(me->fileName)); |
65 | me->game = game; | ||
66 | me->client = ev->client; | ||
57 | eina_hash_add(game->scripts, me->SID, me); | 67 | eina_hash_add(game->scripts, me->SID, me); |
58 | sendBack(game, ev->client, SID, "compiled(true)"); | 68 | sendBack(game, ev->client, SID, "compiled(true)"); |
59 | } | 69 | } |
@@ -69,7 +79,7 @@ static Eina_Bool _data(void *data, int type __UNUSED__, Ecore_Con_Event_Client_D | |||
69 | if (me) | 79 | if (me) |
70 | { | 80 | { |
71 | sprintf(buf, "%s.lua.out", me->fileName); | 81 | sprintf(buf, "%s.lua.out", me->fileName); |
72 | newProc(buf, TRUE); | 82 | newProc(buf, TRUE, (Ecore_Cb) _sendBack, me); |
73 | } | 83 | } |
74 | } | 84 | } |
75 | else if (0 == strcmp(command, "exit()")) | 85 | else if (0 == strcmp(command, "exit()")) |
diff --git a/libraries/luaproc/Makefile b/libraries/luaproc/Makefile index 1efc2d5..3ab61bf 100644 --- a/libraries/luaproc/Makefile +++ b/libraries/luaproc/Makefile | |||
@@ -33,7 +33,8 @@ LUA_LIB_PATH=/usr/lib/lua5.1 | |||
33 | 33 | ||
34 | # standard makefile variables | 34 | # standard makefile variables |
35 | CC=gcc | 35 | CC=gcc |
36 | CFLAGS=-c -Wall -fPIC -I${LUA_INC_PATH} | 36 | # TODO - hack, hard coded EFL include paths for now. |
37 | CFLAGS=-c -Wall -fPIC -I${LUA_INC_PATH} -I/opt/e17/include/eina-1 -I/opt/e17/include/eina-1/eina -I/opt/e17/include/ecore-1 | ||
37 | LDFLAGS=-shared -L${LUA_LIB_PATH} -lpthread | 38 | LDFLAGS=-shared -L${LUA_LIB_PATH} -lpthread |
38 | SOURCES=sched.c list.c luaproc.c channel.c | 39 | SOURCES=sched.c list.c luaproc.c channel.c |
39 | OBJECTS=${SOURCES:.c=.o} | 40 | OBJECTS=${SOURCES:.c=.o} |
diff --git a/libraries/luaproc/luaproc.c b/libraries/luaproc/luaproc.c index ee0764a..7f4b2bb 100644 --- a/libraries/luaproc/luaproc.c +++ b/libraries/luaproc/luaproc.c | |||
@@ -41,6 +41,7 @@ THE SOFTWARE. | |||
41 | #include "sched.h" | 41 | #include "sched.h" |
42 | #include "channel.h" | 42 | #include "channel.h" |
43 | 43 | ||
44 | |||
44 | #define FALSE 0 | 45 | #define FALSE 0 |
45 | #define TRUE 1 | 46 | #define TRUE 1 |
46 | 47 | ||
@@ -67,8 +68,18 @@ struct stluaproc { | |||
67 | int args; | 68 | int args; |
68 | channel chan; | 69 | channel chan; |
69 | int destroyworker; | 70 | int destroyworker; |
71 | void *data; | ||
72 | Ecore_Cb callback; | ||
70 | }; | 73 | }; |
71 | 74 | ||
75 | /* TODO - hack, duplicating something from LuaSL for now. */ | ||
76 | typedef struct | ||
77 | { | ||
78 | void *script; | ||
79 | char message[PATH_MAX]; | ||
80 | } scriptMessage; | ||
81 | |||
82 | |||
72 | /****************************** | 83 | /****************************** |
73 | * library functions prototypes | 84 | * library functions prototypes |
74 | ******************************/ | 85 | ******************************/ |
@@ -90,6 +101,8 @@ static int luaproc_create_worker( lua_State *L ); | |||
90 | static int luaproc_destroy_worker( lua_State *L ); | 101 | static int luaproc_destroy_worker( lua_State *L ); |
91 | /* set amount of lua processes that should be recycled (ie, reused) */ | 102 | /* set amount of lua processes that should be recycled (ie, reused) */ |
92 | static int luaproc_recycle_set( lua_State *L ); | 103 | static int luaproc_recycle_set( lua_State *L ); |
104 | /* send a message back to the main loop */ | ||
105 | static int luaproc_send_back( lua_State *L ); | ||
93 | 106 | ||
94 | /* luaproc function registration array - main (parent) functions */ | 107 | /* luaproc function registration array - main (parent) functions */ |
95 | static const struct luaL_reg luaproc_funcs_parent[] = { | 108 | static const struct luaL_reg luaproc_funcs_parent[] = { |
@@ -98,6 +111,7 @@ static const struct luaL_reg luaproc_funcs_parent[] = { | |||
98 | { "createworker", luaproc_create_worker }, | 111 | { "createworker", luaproc_create_worker }, |
99 | { "destroyworker", luaproc_destroy_worker }, | 112 | { "destroyworker", luaproc_destroy_worker }, |
100 | { "recycle", luaproc_recycle_set }, | 113 | { "recycle", luaproc_recycle_set }, |
114 | { "sendback", luaproc_send_back }, | ||
101 | { NULL, NULL } | 115 | { NULL, NULL } |
102 | }; | 116 | }; |
103 | 117 | ||
@@ -111,6 +125,7 @@ static const struct luaL_reg luaproc_funcs_child[] = { | |||
111 | { "createworker", luaproc_create_worker }, | 125 | { "createworker", luaproc_create_worker }, |
112 | { "destroyworker", luaproc_destroy_worker }, | 126 | { "destroyworker", luaproc_destroy_worker }, |
113 | { "recycle", luaproc_recycle_set }, | 127 | { "recycle", luaproc_recycle_set }, |
128 | { "sendback", luaproc_send_back }, | ||
114 | { NULL, NULL } | 129 | { NULL, NULL } |
115 | }; | 130 | }; |
116 | 131 | ||
@@ -359,7 +374,7 @@ static luaproc luaproc_recycle( luaproc lp, const char *code, int file ) { | |||
359 | } | 374 | } |
360 | 375 | ||
361 | 376 | ||
362 | int newProc(const char *code, int file) | 377 | int newProc(const char *code, int file, Ecore_Cb callback, void *data) |
363 | { | 378 | { |
364 | /* new lua process pointer */ | 379 | /* new lua process pointer */ |
365 | luaproc lp; | 380 | luaproc lp; |
@@ -383,6 +398,10 @@ int newProc(const char *code, int file) | |||
383 | return 1; | 398 | return 1; |
384 | } | 399 | } |
385 | 400 | ||
401 | /* Stash any data and callback given to us. */ | ||
402 | lp->data = data; | ||
403 | lp->callback = callback; | ||
404 | |||
386 | /* increase active luaproc count */ | 405 | /* increase active luaproc count */ |
387 | sched_lpcount_inc(); | 406 | sched_lpcount_inc(); |
388 | 407 | ||
@@ -405,7 +424,7 @@ static int luaproc_create_newproc( lua_State *L ) { | |||
405 | /* check if first argument is a string (lua code) */ | 424 | /* check if first argument is a string (lua code) */ |
406 | const char *code = luaL_checkstring( L, 1 ); | 425 | const char *code = luaL_checkstring( L, 1 ); |
407 | 426 | ||
408 | switch (newProc(code, FALSE)) | 427 | switch (newProc(code, FALSE, NULL, NULL)) |
409 | { | 428 | { |
410 | case 1 : | 429 | case 1 : |
411 | /* in case of errors return nil + error msg */ | 430 | /* in case of errors return nil + error msg */ |
@@ -496,6 +515,28 @@ luaproc luaproc_getself( lua_State *L ) { | |||
496 | return lp; | 515 | return lp; |
497 | } | 516 | } |
498 | 517 | ||
518 | /* send a message to a lua process */ | ||
519 | static int luaproc_send_back( lua_State *L ) { | ||
520 | |||
521 | luaproc self; | ||
522 | const char *message = luaL_checkstring( L, 1 ); | ||
523 | |||
524 | self = luaproc_getself( L ); | ||
525 | if (self && self->callback && self->data) | ||
526 | { | ||
527 | scriptMessage *sm = calloc(1, sizeof(scriptMessage)); | ||
528 | |||
529 | if (sm) | ||
530 | { | ||
531 | sm->script = self->data; | ||
532 | strcpy(sm->message, message); | ||
533 | ecore_main_loop_thread_safe_call_async(self->callback, sm); | ||
534 | } | ||
535 | } | ||
536 | |||
537 | return 0; | ||
538 | } | ||
539 | |||
499 | /* error messages for the sendToChannel function */ | 540 | /* error messages for the sendToChannel function */ |
500 | const char *sendToChannelErrors[] = | 541 | const char *sendToChannelErrors[] = |
501 | { | 542 | { |
diff --git a/libraries/luaproc/luaproc.h b/libraries/luaproc/luaproc.h index a5dde0d..1286107 100644 --- a/libraries/luaproc/luaproc.h +++ b/libraries/luaproc/luaproc.h | |||
@@ -29,6 +29,7 @@ THE SOFTWARE. | |||
29 | #define _LUAPROC_H_ | 29 | #define _LUAPROC_H_ |
30 | 30 | ||
31 | #include "channel.h" | 31 | #include "channel.h" |
32 | #include <Ecore.h> | ||
32 | 33 | ||
33 | /* process is idle */ | 34 | /* process is idle */ |
34 | #define LUAPROC_STAT_IDLE 0 | 35 | #define LUAPROC_STAT_IDLE 0 |
@@ -46,7 +47,7 @@ typedef struct stluaproc *luaproc; | |||
46 | 47 | ||
47 | void luaprocInit(void); | 48 | void luaprocInit(void); |
48 | void luaprocRegister(lua_State *L); | 49 | void luaprocRegister(lua_State *L); |
49 | int newProc(const char *code, int file); | 50 | int newProc(const char *code, int file, Ecore_Cb callback, void *data); |
50 | 51 | ||
51 | 52 | ||
52 | /* return a process' status */ | 53 | /* return a process' status */ |