aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-05 18:19:39 +1000
committerDavid Walter Seikel2012-02-05 18:19:39 +1000
commit5fc1d9cce112bd0df3604be3a9efbc43ff5170a8 (patch)
tree7f3adb04e6b71cdbc841c8cde641b39b151e6d65 /LuaSL
parentTell the scripts to quit after a short delay. (diff)
downloadSledjHamr-5fc1d9cce112bd0df3604be3a9efbc43ff5170a8.zip
SledjHamr-5fc1d9cce112bd0df3604be3a9efbc43ff5170a8.tar.gz
SledjHamr-5fc1d9cce112bd0df3604be3a9efbc43ff5170a8.tar.bz2
SledjHamr-5fc1d9cce112bd0df3604be3a9efbc43ff5170a8.tar.xz
Do script quitting differently, using the wire protocol method, which means I got to debug that.
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LSL.lua19
-rw-r--r--LuaSL/src/LuaSL_compile.c2
-rw-r--r--LuaSL/src/LuaSL_main.c2
3 files changed, 15 insertions, 8 deletions
diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua
index 59f706d..6473cc2 100644
--- a/LuaSL/src/LSL.lua
+++ b/LuaSL/src/LSL.lua
@@ -307,6 +307,13 @@ function LSL.postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1;
307-- State stuff 307-- State stuff
308 308
309local currentState = {} 309local currentState = {}
310local running = true;
311
312-- Damn, looks like these sorts of functions have to be part of the table.
313-- Coz pcall() runs in the context of the script, not this module, so needs to call _LSL.quit().
314function LSL.quit()
315 running = false
316end
310 317
311function LSL.stateChange(x) 318function LSL.stateChange(x)
312 if currentState ~= x then -- Changing to the same state is a NOP. 319 if currentState ~= x then -- Changing to the same state is a NOP.
@@ -347,18 +354,18 @@ function LSL.mainLoop(SID, x)
347 354
348 LSL.stateChange(x); 355 LSL.stateChange(x);
349 356
350 -- TODO - Need a FIFO stack of incoming events. Which will be in the C main thread, coz that's listening on the socket for us. 357 -- TODO - Need a FIFO queue of incoming events. Which will be in the C main thread, coz that's listening on the socket for us.
358 -- Actually, I think the luaproc message system manages such a queue for us anyway.
359 -- C should strip off the "SID." part and replace it with "_LSL.", so might be better to restrict the wire protocol to single function calls.
351 360
352 while true do 361 while running do
353 local message = luaproc.receive(sid) 362 local message = luaproc.receive(sid)
354 if "quit()" == message then 363 if message then
355 return
356 elseif message then
357 result, errorMsg = loadstring(message) 364 result, errorMsg = loadstring(message)
358 if nil == result then 365 if nil == result then
359 print("Not a valid event: " .. message .. " ERROR MESSAGE: " .. errorMsg) 366 print("Not a valid event: " .. message .. " ERROR MESSAGE: " .. errorMsg)
360 else 367 else
361 status, result = pcall(result()) 368 status, result = pcall(result)
362 if not status then 369 if not status then
363 print("Error from event: " .. message .. " ERROR MESSAGE: " .. result) 370 print("Error from event: " .. message .. " ERROR MESSAGE: " .. result)
364 elseif result then 371 elseif result then
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 72d94b9..f840b69 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -2275,7 +2275,7 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
2275 2275
2276 fprintf(out, "--// Generated code goes here.\n\n"); 2276 fprintf(out, "--// Generated code goes here.\n\n");
2277 fprintf(out, "local _bit = require(\"bit\")\n"); 2277 fprintf(out, "local _bit = require(\"bit\")\n");
2278 fprintf(out, "local _LSL = require(\"LSL\")\n\n"); 2278 fprintf(out, "_LSL = require(\"LSL\")\n\n"); // Local might be quicker, but looks like we need global for pcall(), it has it's own local stack I think.
2279 // TODO - Use the scripts UUID instead of the file name here. 2279 // TODO - Use the scripts UUID instead of the file name here.
2280 fprintf(out, "local _SID = [=[%s.lua.out]=]\n\n", compiler.fileName); 2280 fprintf(out, "local _SID = [=[%s.lua.out]=]\n\n", compiler.fileName);
2281 outputLeaf(out, OM_LUA, compiler.ast); 2281 outputLeaf(out, OM_LUA, compiler.ast);
diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c
index 5f48c5e..c441bc5 100644
--- a/LuaSL/src/LuaSL_main.c
+++ b/LuaSL/src/LuaSL_main.c
@@ -123,7 +123,7 @@ static void dirList_quit(const char *name, const char *path, void *data)
123 123
124 snprintf(buf, sizeof(buf), "%s/%s.events", path, name); 124 snprintf(buf, sizeof(buf), "%s/%s.events", path, name);
125// PD("Quitting Lua script %s", buf); 125// PD("Quitting Lua script %s", buf);
126 status = sendToChannel(buf, "quit()"); 126 status = sendToChannel(buf, "_LSL.quit()");
127 if (status) 127 if (status)
128 PE("Error trying to kill script %s : %s", buf, status); 128 PE("Error trying to kill script %s : %s", buf, status);
129 } 129 }