X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/521aa2e579bdf76e25487fb6b9019e78ec75ad32..460bf13957aee18682f280a06910bd4032342fe4:/src/bindings/lua/simgrid_lua.c?ds=sidebyside diff --git a/src/bindings/lua/simgrid_lua.c b/src/bindings/lua/simgrid_lua.c index 7c395d2ff4..67328c6c2c 100644 --- a/src/bindings/lua/simgrid_lua.c +++ b/src/bindings/lua/simgrid_lua.c @@ -55,7 +55,7 @@ static void stackDump (lua_State *L) { } p+=sprintf(p," "); /* put a separator */ } - INFO1("%s",buff); + DEBUG1("%s",buff); } /** @brief ensures that a userdata on the stack is a task and returns the pointer inside the userdata */ @@ -92,7 +92,7 @@ static int Task_new(lua_State* L) { int msg_size = luaL_checkint(L,3); // FIXME: data shouldn't be NULL I guess pushTask(L,MSG_task_create(name,comp_size,msg_size,NULL)); - INFO0("Created task"); + DEBUG0("Created task"); return 1; } @@ -124,21 +124,18 @@ static int Task_destroy(lua_State *L) { static int Task_send(lua_State *L) { m_task_t tk = checkTask(L,1); const char *mailbox = luaL_checkstring(L,2); - stackDump(L);fflush(stdout);fflush(stderr); int res = MSG_task_send(tk,mailbox); res++;//FIXME: check it instead of avoiding the warning - stackDump(L); return 0; } static int Task_recv(lua_State *L) { m_task_t tk = NULL; - //stackDump(L); const char *mailbox = luaL_checkstring(L,1); int res = MSG_task_receive(&tk,mailbox); + MSG_task_ref(tk); res++;//FIXME: check it instead of avoiding the warning - INFO1("Task Name : >>>%s",MSG_task_get_name(tk)); + DEBUG1("Task Name : >>>%s",MSG_task_get_name(tk)); pushTask(L,tk); - // stackDump(L); return 1; } @@ -174,20 +171,55 @@ static const luaL_reg Task_meta[] = { /* * Environment related */ +extern lua_State *simgrid_lua_state; + +static int run_lua_code(int argc,char **argv) { + DEBUG1("Run lua code %s",argv[0]); +// fprintf(stderr,"Run lua code %s\n", (argv ? argv[0] : "(null)")); + lua_State *L = lua_newthread(simgrid_lua_state); + int ref = luaL_ref(simgrid_lua_state, LUA_REGISTRYINDEX); // protect the thread from being garbage collected + int res = 1; + + /* Start the co-routine */ + lua_getglobal(L,argv[0]); + xbt_assert1(lua_isfunction(L,-1), + "The lua function %s does not seem to exist",argv[0]); + + // push arguments onto the stack + int i; + for(i=1;i