diff options
-rw-r--r-- | lib/LSL.lua | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/LSL.lua b/lib/LSL.lua index ffd18de..7022fea 100644 --- a/lib/LSL.lua +++ b/lib/LSL.lua | |||
@@ -170,7 +170,7 @@ local function value2string(doLua, value, Type) | |||
170 | 170 | ||
171 | -- TODO - Might be better to convert FROM both in each branch? | 171 | -- TODO - Might be better to convert FROM both in each branch? |
172 | if doLua then | 172 | if doLua then |
173 | -- "nil", "number", "string", "boolean", "table", "function", "thread", and "userdata". | 173 | -- "nil", "function", "thread", and "userdata". |
174 | if "number" == Type then temp = temp .. value | 174 | if "number" == Type then temp = temp .. value |
175 | elseif "string" == Type then temp = "\"" .. value .. "\"" | 175 | elseif "string" == Type then temp = "\"" .. value .. "\"" |
176 | elseif "boolean" == Type then if value then temp = '"true"' else temp = '"false"' end | 176 | elseif "boolean" == Type then if value then temp = '"true"' else temp = '"false"' end |
@@ -210,14 +210,12 @@ function args2string(doLua, doType, ...) | |||
210 | end | 210 | end |
211 | 211 | ||
212 | function mt.callAndReturn(name, ...) | 212 | function mt.callAndReturn(name, ...) |
213 | -- This converts LSL to Lua. | 213 | -- This converts LSL to Lua, then sends it to the LuaSL client (the nil at the start, otherwise it's sending to an SID). |
214 | Runnr.send(nil, name .. "(" .. args2string(true, true, ...) .. ")") | 214 | Runnr.send(nil, name .. "(" .. args2string(true, true, ...) .. ")") |
215 | end | 215 | end |
216 | 216 | ||
217 | function mt.callAndWait(name, ...) | 217 | function mt.callAndWait(name, ...) |
218 | mt.callAndReturn(name, ...); | 218 | mt.callAndReturn(name, ...); |
219 | -- Eventually a sendForth() is called, which should end up passing through SendToChannel(). | ||
220 | -- Except I've changed all those names now. lol | ||
221 | -- Wait for the result, which should be a Lua value as a string. | 219 | -- Wait for the result, which should be a Lua value as a string. |
222 | return waitAndProcess(true, name, ...) | 220 | return waitAndProcess(true, name, ...) |
223 | end | 221 | end |
@@ -2021,9 +2019,12 @@ function waitAndProcess(returnWanted, name, ...) | |||
2021 | if paused then | 2019 | if paused then |
2022 | if "start()" == message then paused = false end | 2020 | if "start()" == message then paused = false end |
2023 | else | 2021 | else |
2024 | 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 | 2022 | local temp = message |
2023 | local value = "" | ||
2024 | if returnWanted and string.match(message, "^return%(") then temp = "return " .. string.sub(message, 8, -2) end | ||
2025 | local result, errorMsg = loadstring(temp) -- "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 | ||
2025 | if nil == result then | 2026 | if nil == result then |
2026 | local text = "Not a valid " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. errorMsg | 2027 | local text = "Not a valid " .. Type .. ": " .. temp .. " ERROR MESSAGE: " .. errorMsg |
2027 | msg(text) | 2028 | msg(text) |
2028 | print(text) | 2029 | print(text) |
2029 | else | 2030 | else |
@@ -2035,7 +2036,7 @@ function waitAndProcess(returnWanted, name, ...) | |||
2035 | 2036 | ||
2036 | local status, result1 = pcall(result) | 2037 | local status, result1 = pcall(result) |
2037 | if not status then | 2038 | if not status then |
2038 | local text = "Error from " .. Type .. ": " .. message .. " ERROR MESSAGE: " .. result1 | 2039 | local text = "Error from " .. Type .. ": " .. temp .. " ERROR MESSAGE: " .. result1 |
2039 | msg(text) | 2040 | msg(text) |
2040 | print(text) | 2041 | print(text) |
2041 | elseif result1 then | 2042 | elseif result1 then |
@@ -2054,7 +2055,9 @@ function waitAndProcess(returnWanted, name, ...) | |||
2054 | -- end | 2055 | -- end |
2055 | else | 2056 | else |
2056 | if string.match(message, "^return%(") then | 2057 | if string.match(message, "^return%(") then |
2057 | print("!" .. SID .. "_" .. scriptName, " - IN AN ODD PLACE!!!!!" .. message) | 2058 | print("!" .. SID .. "_" .. scriptName, " - IN AN ODD PLACE!!!!! " .. message) |
2059 | print(type(value)) | ||
2060 | print(value) | ||
2058 | else | 2061 | else |
2059 | -- print("!" .. SID .. "_" .. scriptName, " - " .. message) | 2062 | -- print("!" .. SID .. "_" .. scriptName, " - " .. message) |
2060 | end | 2063 | end |