aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LSL.lua
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/src/LSL.lua
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 '')
-rw-r--r--LuaSL/src/LSL.lua19
1 files changed, 13 insertions, 6 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