From 5fc1d9cce112bd0df3604be3a9efbc43ff5170a8 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 5 Feb 2012 18:19:39 +1000 Subject: Do script quitting differently, using the wire protocol method, which means I got to debug that. --- LuaSL/src/LSL.lua | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'LuaSL/src/LSL.lua') 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; -- State stuff local currentState = {} +local running = true; + +-- Damn, looks like these sorts of functions have to be part of the table. +-- Coz pcall() runs in the context of the script, not this module, so needs to call _LSL.quit(). +function LSL.quit() + running = false +end function LSL.stateChange(x) if currentState ~= x then -- Changing to the same state is a NOP. @@ -347,18 +354,18 @@ function LSL.mainLoop(SID, x) LSL.stateChange(x); - -- 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. + -- 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. + -- Actually, I think the luaproc message system manages such a queue for us anyway. + -- 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. - while true do + while running do local message = luaproc.receive(sid) - if "quit()" == message then - return - elseif message then + if message then result, errorMsg = loadstring(message) if nil == result then print("Not a valid event: " .. message .. " ERROR MESSAGE: " .. errorMsg) else - status, result = pcall(result()) + status, result = pcall(result) if not status then print("Error from event: " .. message .. " ERROR MESSAGE: " .. result) elseif result then -- cgit v1.1