aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-22 23:46:56 +1000
committerDavid Walter Seikel2012-02-22 23:46:56 +1000
commitf93cf73e01e9cf4b0a6be43d61ebc24b9fa64b0d (patch)
treea291eb5bf596aad17791b37a2a2826d9271742f3 /libraries
parentImplement llGetScriptName(). (diff)
downloadSledjHamr-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 'libraries')
-rw-r--r--libraries/luaproc/Makefile3
-rw-r--r--libraries/luaproc/luaproc.c45
-rw-r--r--libraries/luaproc/luaproc.h3
3 files changed, 47 insertions, 4 deletions
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
35CC=gcc 35CC=gcc
36CFLAGS=-c -Wall -fPIC -I${LUA_INC_PATH} 36# TODO - hack, hard coded EFL include paths for now.
37CFLAGS=-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
37LDFLAGS=-shared -L${LUA_LIB_PATH} -lpthread 38LDFLAGS=-shared -L${LUA_LIB_PATH} -lpthread
38SOURCES=sched.c list.c luaproc.c channel.c 39SOURCES=sched.c list.c luaproc.c channel.c
39OBJECTS=${SOURCES:.c=.o} 40OBJECTS=${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. */
76typedef 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 );
90static int luaproc_destroy_worker( lua_State *L ); 101static 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) */
92static int luaproc_recycle_set( lua_State *L ); 103static int luaproc_recycle_set( lua_State *L );
104/* send a message back to the main loop */
105static 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 */
95static const struct luaL_reg luaproc_funcs_parent[] = { 108static 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
362int newProc(const char *code, int file) 377int 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 */
519static 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 */
500const char *sendToChannelErrors[] = 541const 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
47void luaprocInit(void); 48void luaprocInit(void);
48void luaprocRegister(lua_State *L); 49void luaprocRegister(lua_State *L);
49int newProc(const char *code, int file); 50int 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 */