diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/src/LSL.lua | 19 |
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 | ||
309 | local currentState = {} | 309 | local currentState = {} |
310 | local 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(). | ||
314 | function LSL.quit() | ||
315 | running = false | ||
316 | end | ||
310 | 317 | ||
311 | function LSL.stateChange(x) | 318 | function 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 |