aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-02-05 22:53:08 +1000
committerDavid Walter Seikel2016-02-05 22:53:08 +1000
commit476abb937a7eb49e6a197b0f889a925ad78293fe (patch)
tree15bf2b6ca6e1792ca5d0cca6c610690dab339bf2 /lib
parentMore Lua network messages clean ups. (diff)
downloadSledjHamr-476abb937a7eb49e6a197b0f889a925ad78293fe.zip
SledjHamr-476abb937a7eb49e6a197b0f889a925ad78293fe.tar.gz
SledjHamr-476abb937a7eb49e6a197b0f889a925ad78293fe.tar.bz2
SledjHamr-476abb937a7eb49e6a197b0f889a925ad78293fe.tar.xz
Convert either to LSL or to Lua style values as needed.
Diffstat (limited to 'lib')
-rw-r--r--lib/LSL.lua47
1 files changed, 31 insertions, 16 deletions
diff --git a/lib/LSL.lua b/lib/LSL.lua
index 434113d..ffd18de 100644
--- a/lib/LSL.lua
+++ b/lib/LSL.lua
@@ -165,32 +165,43 @@ local args2string -- Pre declare this.
165local functions = {} 165local functions = {}
166local mt = {} 166local mt = {}
167 167
168local function value2string(value, Type) 168local function value2string(doLua, value, Type)
169 local temp = "" 169 local temp = ""
170 170
171 if "float" == Type then temp = temp .. value 171-- TODO - Might be better to convert FROM both in each branch?
172-- elseif "boolean" == Type then if value then temp = '"true"' else temp = '"false"' end 172 if doLua then
173 elseif "integer" == Type then temp = temp .. value 173 -- "nil", "number", "string", "boolean", "table", "function", "thread", and "userdata".
174 elseif "key" == Type then temp = "\"" .. value .. "\"" 174 if "number" == Type then temp = temp .. value
175 elseif "list" == Type then temp = "[" .. args2string(true, unpack(value)) .. "]" 175 elseif "string" == Type then temp = "\"" .. value .. "\""
176 elseif "table" == Type then temp = "[" .. args2string(true, unpack(value)) .. "]" 176 elseif "boolean" == Type then if value then temp = '"true"' else temp = '"false"' end
177 elseif "string" == Type then temp = "\"" .. value .. "\"" 177 elseif "table" == Type then temp = "{" .. args2string(doLua, true, unpack(value)) .. "}"
178 elseif "rotation" == Type then temp = "<" .. value.x .. ", " .. value.y .. ", " .. value.z .. ", " .. value.s .. ">" 178 else
179 elseif "vector" == Type then temp = "<" .. value.x .. ", " .. value.y .. ", " .. value.z .. ">" 179 temp = temp .. value
180 end
180 else 181 else
181 temp = temp .. value 182 if "float" == Type then temp = temp .. value
183 elseif "integer" == Type then temp = temp .. value
184 elseif "key" == Type then temp = "\"" .. value .. "\""
185 elseif "list" == Type then temp = "[" .. args2string(doLua, true, unpack(value)) .. "]"
186 elseif "string" == Type then temp = "\"" .. value .. "\""
187 elseif "rotation" == Type then temp = "<" .. value.x .. ", " .. value.y .. ", " .. value.z .. ", " .. value.s .. ">"
188 elseif "vector" == Type then temp = "<" .. value.x .. ", " .. value.y .. ", " .. value.z .. ">"
189 else
190 temp = temp .. value
191 end
182 end 192 end
193
183 return temp 194 return temp
184end 195end
185 196
186function args2string(doType, ...) 197function args2string(doLua, doType, ...)
187 local temp = "" 198 local temp = ""
188 local first = true 199 local first = true
189 200
190 for j,w in ipairs( {...} ) do 201 for j,w in ipairs( {...} ) do
191 if first then first = false else temp = temp .. ", " end 202 if first then first = false else temp = temp .. ", " end
192 if doType then 203 if doType then
193 temp = temp .. value2string(w, type(w)) 204 temp = temp .. value2string(doLua, w, type(w))
194 else 205 else
195 temp = temp .. w 206 temp = temp .. w
196 end 207 end
@@ -199,12 +210,14 @@ function args2string(doType, ...)
199end 210end
200 211
201function mt.callAndReturn(name, ...) 212function mt.callAndReturn(name, ...)
202 Runnr.send(nil, name .. "(" .. args2string(true, ...) .. ")") 213 -- This converts LSL to Lua.
214 Runnr.send(nil, name .. "(" .. args2string(true, true, ...) .. ")")
203end 215end
204 216
205function mt.callAndWait(name, ...) 217function mt.callAndWait(name, ...)
206 mt.callAndReturn(name, ...); 218 mt.callAndReturn(name, ...);
207 -- Eventually a sendForth() is called, which should end up passing through SendToChannel(). 219 -- Eventually a sendForth() is called, which should end up passing through SendToChannel().
220 -- Except I've changed all those names now. lol
208 -- Wait for the result, which should be a Lua value as a string. 221 -- Wait for the result, which should be a Lua value as a string.
209 return waitAndProcess(true, name, ...) 222 return waitAndProcess(true, name, ...)
210end 223end
@@ -2092,7 +2105,8 @@ function LSL.gimmeLSL()
2092 for i, v in ipairs(constants) do 2105 for i, v in ipairs(constants) do
2093 local value = LSL[v.name] 2106 local value = LSL[v.name]
2094 2107
2095 print(v.Type .. " " .. v.name .. " = " .. value2string(value, v.Type) .. ";") 2108 -- This converts Lua to LSL.
2109 print(v.Type .. " " .. v.name .. " = " .. value2string(false, value, v.Type) .. ";")
2096 end 2110 end
2097 2111
2098 for k in pairs(functions) do 2112 for k in pairs(functions) do
@@ -2100,7 +2114,8 @@ function LSL.gimmeLSL()
2100 if nil == v.args then 2114 if nil == v.args then
2101 print(v.Type .. " " .. k .. "(){}") 2115 print(v.Type .. " " .. k .. "(){}")
2102 else 2116 else
2103 print(v.Type .. " " .. k .. "(" .. args2string(false, unpack(v.args)) .. "){}") 2117 -- This converts Lua to LSL.
2118 print(v.Type .. " " .. k .. "(" .. args2string(false, false, unpack(v.args)) .. "){}")
2104 end 2119 end
2105 end 2120 end
2106end 2121end