aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-14 14:33:50 +1000
committerDavid Walter Seikel2014-05-14 14:33:50 +1000
commitd06706b346854cd73631aeb6297418ff82cabdf9 (patch)
tree1628f237c47b833c1f4e1e59dd5d8d5944256950 /src/LuaSL
parentDisplay LSL script names instead of lengthy paths and UUIDs. (diff)
downloadSledjHamr-d06706b346854cd73631aeb6297418ff82cabdf9.zip
SledjHamr-d06706b346854cd73631aeb6297418ff82cabdf9.tar.gz
SledjHamr-d06706b346854cd73631aeb6297418ff82cabdf9.tar.bz2
SledjHamr-d06706b346854cd73631aeb6297418ff82cabdf9.tar.xz
Actually implement LSL script resetting, and some associated fixes.
Diffstat (limited to 'src/LuaSL')
-rw-r--r--src/LuaSL/LuaSL_main.c25
-rw-r--r--src/LuaSL/LuaSL_threads.c10
2 files changed, 28 insertions, 7 deletions
diff --git a/src/LuaSL/LuaSL_main.c b/src/LuaSL/LuaSL_main.c
index 33b15c6..cb2726e 100644
--- a/src/LuaSL/LuaSL_main.c
+++ b/src/LuaSL/LuaSL_main.c
@@ -45,10 +45,27 @@ static script *findThem(gameGlobals *ourGlobals, const char *base, const char *t
45 45
46static void resetScript(script *victim) 46static void resetScript(script *victim)
47{ 47{
48// gameGlobals *ourGlobals = victim->game; 48 gameGlobals *ourGlobals = victim->game;
49 49 script *me;
50 PD("Resetting %s", victim->fileName); 50 char buf[PATH_MAX];
51 // TODO - now what? 51
52 PD("RESETTING %s", victim->name);
53 sendToChannel(ourGlobals, victim->SID, "quit()");
54 eina_hash_del(ourGlobals->scripts, victim->SID, NULL);
55 eina_hash_del(ourGlobals->names, victim->fileName, NULL);
56
57 // The old one will eventually die, create a new one.
58 me = calloc(1, sizeof(script));
59 gettimeofday(&me->startTime, NULL);
60 strncpy(me->SID, victim->SID, sizeof(me->SID));
61 strncpy(me->fileName, victim->fileName, sizeof(me->fileName));
62 me->name = &me->fileName[sizeof(PACKAGE_DATA_DIR)];
63 me->game = ourGlobals;
64 me->client = victim->client;
65 eina_hash_add(ourGlobals->scripts, me->SID, me);
66 eina_hash_add(ourGlobals->names, me->fileName, me);
67 sprintf(buf, "%s.lua.out", me->fileName);
68 newProc(buf, TRUE, me);
52} 69}
53 70
54void scriptSendBack(void * data) 71void scriptSendBack(void * data)
diff --git a/src/LuaSL/LuaSL_threads.c b/src/LuaSL/LuaSL_threads.c
index 234a7c5..e326e14 100644
--- a/src/LuaSL/LuaSL_threads.c
+++ b/src/LuaSL/LuaSL_threads.c
@@ -298,27 +298,31 @@ void newProc(const char *code, int file, script *lp)
298 recycled *trash; 298 recycled *trash;
299 299
300 // Try to recycle a Lua state, otherwise create one from scratch. 300 // Try to recycle a Lua state, otherwise create one from scratch.
301#if 0 // TODO - something about this causes a crash.
301 pthread_mutex_lock(&mutex_recycle_list); 302 pthread_mutex_lock(&mutex_recycle_list);
302 /* pop list head */ 303 /* pop list head */
303 if ((trash = (recycled *) eina_clist_head(&recyclelp))) 304 if ((trash = (recycled *) eina_clist_head(&recyclelp)))
304 { 305 {
306 printf(" Reusing Lua trash.\n");
305 eina_clist_remove(&(trash->node)); 307 eina_clist_remove(&(trash->node));
306 lp->L = trash->L; 308 lp->L = trash->L;
307 free(trash); 309 free(trash);
308 } 310 }
309 pthread_mutex_unlock(&mutex_recycle_list); 311 pthread_mutex_unlock(&mutex_recycle_list);
312#endif
310 313
311 if (NULL == lp->L) 314 if (NULL == lp->L)
312 { 315 {
313 lp->L = luaL_newstate(); 316 lp->L = luaL_newstate();
314 317
315 /* store the script struct in its own Lua state */
316 lua_pushlightuserdata(lp->L, lp);
317 lua_setfield(lp->L, LUA_REGISTRYINDEX, "_SELF");
318 luaL_openlibs(lp->L); 318 luaL_openlibs(lp->L);
319 luaL_register(lp->L, "luaproc", luaproc_funcs_child); 319 luaL_register(lp->L, "luaproc", luaproc_funcs_child);
320 } 320 }
321 321
322 /* store the script struct in its own Lua state */
323 lua_pushlightuserdata(lp->L, lp);
324 lua_setfield(lp->L, LUA_REGISTRYINDEX, "_SELF");
325
322 lp->status = LUAPROC_STAT_IDLE; 326 lp->status = LUAPROC_STAT_IDLE;
323 lp->args = 0; 327 lp->args = 0;
324 eina_clist_element_init(&(lp->node)); 328 eina_clist_element_init(&(lp->node));