From 53fe89764f8f679f3f4cbaa39c2393918898815f Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 5 Feb 2012 16:38:50 +1000 Subject: Implement the script main loop, and the script UUID, which we call SID, though for now it's only the file name. --- LuaSL/src/LSL.lua | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'LuaSL/src/LSL.lua') diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua index 0b02077..975f219 100644 --- a/LuaSL/src/LSL.lua +++ b/LuaSL/src/LSL.lua @@ -335,16 +335,40 @@ function LSL.stateChange(x) end end; -function LSL.mainLoop(x) +function LSL.mainLoop(SID, x) + -- TODO - disabled the stuff that waits until I implement the stuff that makes it stop waiting. lol + local sid = SID .. ".events" + local status, errorMsg = "disabled" -- = luaproc.newchannel(sid) + local result + + if not status then + print("Can't open the luaproc channel " .. sid .. " ERROR MESSAGE: " .. errorMsg) + return + end + LSL.stateChange(x); - --[[ TODO - - Sits around waiting for events. This should be "wait for a message" in luaproc. - Incoming events can be the same format as the OpenSim SID.event.* protocol on the wiki. - When we get an event, run it, then go back to waiting. - - 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 stack of incoming events. Which will be in the C main thread, coz that's listening on the socket for us. + +-- while true do + local message = luaproc.receive(sid) + 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()) + if not status then + print("Error from event: " .. message .. " ERROR MESSAGE: " .. result) + elseif result then + status, errorMsg = luaproc.send(sid, result) + if not status then + print("Error sending results from event: " .. message .. " ERROR MESSAGE: " .. errorMsg) + end + end + end + end +-- end end -- Typecasting stuff. -- cgit v1.1