aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-05 21:50:25 +1000
committerDavid Walter Seikel2012-02-05 21:50:25 +1000
commitc15b2124ea5e399e40abf0e043bdce885214aa8b (patch)
tree847fa79f4a35bbba974fffb93703acddee8e1790
parentWrite most of the rest of the list functions, some are only half arsed. (diff)
downloadSledjHamr-c15b2124ea5e399e40abf0e043bdce885214aa8b.zip
SledjHamr-c15b2124ea5e399e40abf0e043bdce885214aa8b.tar.gz
SledjHamr-c15b2124ea5e399e40abf0e043bdce885214aa8b.tar.bz2
SledjHamr-c15b2124ea5e399e40abf0e043bdce885214aa8b.tar.xz
Half of starting and stopping scripts.
-rw-r--r--LuaSL/src/LSL.lua34
1 files changed, 19 insertions, 15 deletions
diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua
index ca92380..c8c2c6d 100644
--- a/LuaSL/src/LSL.lua
+++ b/LuaSL/src/LSL.lua
@@ -467,11 +467,11 @@ function LSL.postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1;
467 467
468local currentState = {} 468local currentState = {}
469local running = true 469local running = true
470local paused = false
470 471
471-- Stuff called from the wire protocol has to be global, but I think this means just global to this file. 472-- Stuff called from the wire protocol has to be global, but I think this means just global to this file.
472function quit() 473function pause() paused = true end
473 running = false 474function quit() running = false end
474end
475 475
476function LSL.stateChange(x) 476function LSL.stateChange(x)
477 if currentState ~= x then -- Changing to the same state is a NOP. 477 if currentState ~= x then -- Changing to the same state is a NOP.
@@ -519,20 +519,24 @@ function LSL.mainLoop(SID, x)
519 while running do 519 while running do
520 local message = luaproc.receive(sid) 520 local message = luaproc.receive(sid)
521 if message then 521 if message then
522 result, errorMsg = loadstring(message) -- "The environment of the returned function is the global environment." Though normally, a function inherits it's environment from the function creating it. Which is what we want. lol 522 if paused then
523 if nil == result then 523 if "resume()" == message then paused = false end
524 print("Not a valid event: " .. message .. " ERROR MESSAGE: " .. errorMsg)
525 else 524 else
526 -- Set the functions environment to ours, for the protection of the script, coz loadstring sets it to the global environment instead. 525 result, errorMsg = loadstring(message) -- "The environment of the returned function is the global environment." Though normally, a function inherits it's environment from the function creating it. Which is what we want. lol
527 -- TODO - On the other hand, we will need the global environment when we call event handlers. So we should probably stash it around here somewhere. 526 if nil == result then
528 setfenv(result, getfenv(1)) 527 print("Not a valid event: " .. message .. " ERROR MESSAGE: " .. errorMsg)
529 status, result = pcall(result) 528 else
530 if not status then 529 -- Set the functions environment to ours, for the protection of the script, coz loadstring sets it to the global environment instead.
531 print("Error from event: " .. message .. " ERROR MESSAGE: " .. result) 530 -- TODO - On the other hand, we will need the global environment when we call event handlers. So we should probably stash it around here somewhere.
532 elseif result then 531 setfenv(result, getfenv(1))
533 status, errorMsg = luaproc.send(sid, result) 532 status, result = pcall(result)
534 if not status then 533 if not status then
535 print("Error sending results from event: " .. message .. " ERROR MESSAGE: " .. errorMsg) 534 print("Error from event: " .. message .. " ERROR MESSAGE: " .. result)
535 elseif result then
536 status, errorMsg = luaproc.send(sid, result)
537 if not status then
538 print("Error sending results from event: " .. message .. " ERROR MESSAGE: " .. errorMsg)
539 end
536 end 540 end
537 end 541 end
538 end 542 end