aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/LSL.lua34
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/LSL.lua b/lib/LSL.lua
index 6f627e8..f4c7fd4 100644
--- a/lib/LSL.lua
+++ b/lib/LSL.lua
@@ -206,7 +206,7 @@ function mt.callAndWait(name, ...)
206 mt.callAndReturn(name, ...); 206 mt.callAndReturn(name, ...);
207 -- Eventually a sendForth() is called, which should end up passing through SendToChannel(). 207 -- Eventually a sendForth() is called, which should end up passing through SendToChannel().
208 -- Wait for the result, which should be a Lua value as a string. 208 -- Wait for the result, which should be a Lua value as a string.
209 return waitAndProcess(true) 209 return waitAndProcess(true, name, ...)
210end 210end
211 211
212local function newConst(Type, name, value) 212local function newConst(Type, name, value)
@@ -1982,25 +1982,36 @@ function LSL.mainLoop(sid, name, x)
1982 LSL.EOF = "EndOfFuckingAround" -- Fix this up now. 1982 LSL.EOF = "EndOfFuckingAround" -- Fix this up now.
1983 1983
1984 LSL.stateChange(x); 1984 LSL.stateChange(x);
1985 waitAndProcess(false) 1985 waitAndProcess(false, "LSL.mainLoop")
1986-- msg("LSL.Lua: Script quitting " .. scriptName) 1986-- msg("LSL.Lua: Script quitting " .. scriptName)
1987end 1987end
1988 1988
1989function waitAndProcess(returnWanted) 1989function waitAndProcess(returnWanted, name, ...)
1990 local Type = "event" 1990 local Type = "event"
1991 1991
1992 if returnWanted then Type = "result" end 1992 if returnWanted then
1993 Type = "result"
1994 if running then
1995-- print(">" .. SID .. "_" .. scriptName, " - REQUESTING " .. name)
1996 else
1997-- print("?" .. SID .. "_" .. scriptName, " - STOPPED???? ")
1998 end
1999 else
2000-- print("." .. SID .. "_" .. scriptName, " waitAndProcess(false, " .. name .. ")")
2001 end
2002
1993 while running do 2003 while running do
1994 local message = Runnr.receive() 2004 local message = Runnr.receive()
1995 if message then 2005 if message then
1996--print('GOT MESSAGE for script ' .. scriptName .. ' - "' .. message .. '"') 2006--print(" " .. SID .. "_" .. scriptName .. ' GOT MESSAGE - "' .. message .. '"')
1997 -- TODO - should we be discarding return values while paused? I don't think so, so we need to process those, 2007 -- TODO - should we be discarding return values while paused? I don't think so, so we need to process those,
1998 if paused then 2008 if paused then
1999 if "start()" == message then paused = false end 2009 if "start()" == message then paused = false end
2000 else 2010 else
2001 local 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 2011 local 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
2002 if nil == result then 2012 if nil == result then
2003 msg("Not a valid " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. errorMsg) 2013 msg("Not a valid " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. errorMsg)
2014-- print("Not a valid " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. errorMsg)
2004 else 2015 else
2005 -- Set the functions environment to ours, for the protection of the script, coz loadstring sets it to the global environment instead. 2016 -- Set the functions environment to ours, for the protection of the script, coz loadstring sets it to the global environment instead.
2006 -- 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. 2017 -- 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.
@@ -2009,11 +2020,14 @@ function waitAndProcess(returnWanted)
2009 local status, result1 = pcall(result) 2020 local status, result1 = pcall(result)
2010 if not status then 2021 if not status then
2011 msg("Error from " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. result1) 2022 msg("Error from " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. result1)
2023 print("Error from " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. result1)
2012 elseif result1 then 2024 elseif result1 then
2013 -- Check if we are waiting for a return, and got it. 2025 -- Check if we are waiting for a return, and got it.
2014 if returnWanted and string.match(message, "^return ") then 2026 if returnWanted and string.match(message, "^return ") then
2015-- print("RETURNING " .. result1) 2027-- print("<" .. SID .. "_" .. scriptName, " - RETURNING " .. type(result1) .. " " .. message .. " TO " .. name)
2016 return result1 2028 return result1
2029 else
2030-- print("." .. SID .. "_" .. scriptName, " - IGNORING " .. type(result1) .. " " .. message .. " TO " .. name)
2017 end 2031 end
2018 -- Otherwise, just run it and keep looping. 2032 -- Otherwise, just run it and keep looping.
2019 -- TODO - Not sure why I had this here. "sid" is not set anywhere, and SID would just send it to ourselves. 2033 -- TODO - Not sure why I had this here. "sid" is not set anywhere, and SID would just send it to ourselves.
@@ -2021,6 +2035,12 @@ function waitAndProcess(returnWanted)
2021-- if not status then 2035-- if not status then
2022-- msg("Error sending results from " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. errorMsg) 2036-- msg("Error sending results from " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. errorMsg)
2023-- end 2037-- end
2038 else
2039 if string.match(message, "^return ") then
2040 print("!" .. SID .. "_" .. scriptName, " - IN AN ODD PLACE!!!!!" .. message)
2041 else
2042-- print("!" .. SID .. "_" .. scriptName, " - " .. message)
2043 end
2024 end 2044 end
2025 end 2045 end
2026 end 2046 end