aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--LuaSL/src/LSL.lua306
1 files changed, 146 insertions, 160 deletions
diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua
index 2f337a5..53b5d72 100644
--- a/LuaSL/src/LSL.lua
+++ b/LuaSL/src/LSL.lua
@@ -57,13 +57,74 @@ end
57 57
58-- LSL function and constant creation stuff. 58-- LSL function and constant creation stuff.
59 59
60local args2string -- Pre declare this.
61local functions = {}
62local mt = {}
63
64local function value2string(value, Type)
65 local temp = ""
66
67 if "float" == Type then temp = temp .. value
68 elseif "integer" == Type then temp = temp .. value
69 elseif "key" == Type then temp = "\"" .. value .. "\""
70 elseif "list" == Type then temp = "[" .. args2string(true, unpack(value)) .. "]"
71 elseif "table" == Type then temp = "[" .. args2string(true, unpack(value)) .. "]"
72 elseif "string" == Type then temp = "\"" .. value .. "\""
73 elseif "rotation" == Type then temp = "<" .. value.x .. ", " .. value.y .. ", " .. value.z .. ", " .. value.s .. ">"
74 elseif "vector" == Type then temp = "<" .. value.x .. ", " .. value.y .. ", " .. value.z .. ">"
75 else
76 temp = temp .. value
77 end
78 return temp
79end
80
81function args2string(doType, ...)
82 local temp = ""
83 local first = true
84
85 for j,w in ipairs( {...} ) do
86 if first then first = false else temp = temp .. ", " end
87 if doType then
88 temp = temp .. value2string(w, type(w))
89 else
90 temp = temp .. w
91 end
92 end
93 return temp
94end
95
96function mt.callAndReturn(name, ... )
97 print("mt.callAndReturn(" .. name .. "(" .. args2string(true, ...) .. "))")
98end
99
100function mt.callAndWait(name, ... )
101 local func = functions[name]
102
103 print("mt.callAndWait(" .. name .. "(" .. args2string(true, ...) .. "))")
104
105 if "float" == func.Type then return 0.0
106 elseif "integer" == func.Type then return 0
107 elseif "key" == func.Type then return LSL.NULL_KEY
108 elseif "list" == func.Type then return {}
109 elseif "string" == func.Type then return ""
110 elseif "rotation" == func.Type then return LSL.ZERO_ROTATION
111 elseif "vector" == func.Type then return LSL.ZERO_VECTOR
112 end
113 return nil
114end
115
60local function newConst(Type, name, value) 116local function newConst(Type, name, value)
61 LSL[name] = value 117 LSL[name] = value
62 return { Type = Type, name = name } 118 return { Type = Type, name = name }
63end 119end
64 120
65local function newFunc(Type, ... ) 121local function newFunc(Type, name, ... )
66 return { Type = Type, args = {...} } 122 functions[name] = { Type = Type, args = {...} }
123 if "" == Type then
124 LSL[name] = function(...) mt.callAndReturn(name, ... ) end
125 else
126 LSL[name] = function(...) return mt.callAndWait(name, ... ) end
127 end
67end 128end
68 129
69 130
@@ -243,117 +304,114 @@ local constants =
243 304
244-- ll*() function definitions 305-- ll*() function definitions
245 306
246local functions =
247{
248-- LSL avatar functions 307-- LSL avatar functions
249 llAvatarOnSitTarget = newFunc("key"), 308newFunc("key", "llAvatarOnSitTarget")
250 llGetAnimationList = newFunc("list", "key id"), 309newFunc("list", "llGetAnimationList", "key id")
251 llGetPermissions = newFunc("integer"), 310newFunc("integer", "llGetPermissions")
252 llGetPermissionsKey = newFunc("key"), 311newFunc("key", "llGetPermissionsKey")
253 llKey2Name = newFunc("string", "key avatar"), 312newFunc("string", "llKey2Name", "key avatar")
254 llRequestPermissions = newFunc("", "key avatar", "integer perms"), 313newFunc("", "llRequestPermissions", "key avatar", "integer perms")
255 llSameGroup = newFunc("integer", "key avatar"), 314newFunc("integer", "llSameGroup", "key avatar")
256 llStartAnimation = newFunc("", "string anim"), 315newFunc("", "llStartAnimation", "string anim")
257 llStopAnimation = newFunc("", "string anim"), 316newFunc("", "llStopAnimation", "string anim")
258 llUnSit = newFunc("", "key avatar"), 317newFunc("", "llUnSit", "key avatar")
259 318
260-- LSL collision / detect / sensor functions 319-- LSL collision / detect / sensor functions
261 llDetectedGroup = newFunc("key", "integer index"), 320newFunc("key", "llDetectedGroup", "integer index")
262 llDetectedKey = newFunc("key", "integer index"), 321newFunc("key", "llDetectedKey", "integer index")
263 322
264-- LSL communications functions 323-- LSL communications functions
265 llDialog = newFunc("", "key avatar", "string caption", "list arseBackwardsMenu", "integer channel"), 324newFunc("", "llDialog", "key avatar", "string caption", "list arseBackwardsMenu", "integer channel")
266 llListen = newFunc("integer", "integer channel", "string name", "key id", "string msg"), 325newFunc("integer", "llListen", "integer channel", "string name", "key id", "string msg")
267 llListenRemove = newFunc("", "integer handle"), 326newFunc("", "llListenRemove", "integer handle")
268 llOwnerSay = newFunc("", "string text"), 327newFunc("", "llOwnerSay", "string text")
269 llSay = newFunc("", "integer channel", "string text"), 328newFunc("", "llSay", "integer channel", "string text")
270 llShout = newFunc("", "integer channel", "string text"), 329newFunc("", "llShout", "integer channel", "string text")
271 llWhisper = newFunc("", "integer channel", "string text"), 330newFunc("", "llWhisper", "integer channel", "string text")
272 llMessageLinked = newFunc("", "integer link", "integer num", "string text", "key aKey"), 331newFunc("", "llMessageLinked", "integer link", "integer num", "string text", "key aKey")
273 332
274-- LSL inventory functions. 333-- LSL inventory functions.
275 llGetInventoryName = newFunc("string", "integer Type", "integer index"), 334newFunc("string", "llGetInventoryName", "integer Type", "integer index")
276 llGetInventoryNumber = newFunc("integer", "integer Type"), 335newFunc("integer", "llGetInventoryNumber", "integer Type")
277 llGetInventoryType = newFunc("integer", "string name"), 336newFunc("integer", "llGetInventoryType", "string name")
278 llGetNotecardLine = newFunc("key", "string name", "integer index"), 337newFunc("key", "llGetNotecardLine", "string name", "integer index")
279 llRezAtRoot = newFunc("", "string name", "vector position", "vector velocity", "rotation rot", "integer channel"), 338newFunc("", "llRezAtRoot", "string name", "vector position", "vector velocity", "rotation rot", "integer channel")
280 llRezObject = newFunc("", "string name", "vector position", "vector velocity", "rotation rot", "integer channel"), 339newFunc("", "llRezObject", "string name", "vector position", "vector velocity", "rotation rot", "integer channel")
281 340
282-- LSL list functions. 341-- LSL list functions.
283 llCSV2List = newFunc("list", "string text"), 342newFunc("list", "llCSV2List", "string text")
284 llDeleteSubList = newFunc("list", "list l", "integer start", "integer End"), 343newFunc("list", "llDeleteSubList", "list l", "integer start", "integer End")
285 llDumpList2String = newFunc("string", "list l", "string separator"), 344newFunc("string", "llDumpList2String", "list l", "string separator")
286 llGetListLength = newFunc("integer", "list l"), 345newFunc("integer", "llGetListLength", "list l")
287 llList2CSV = newFunc("string", "list l"), 346newFunc("string", "llList2CSV", "list l")
288 llList2Float = newFunc("float", "list l", "integer index"), 347newFunc("float", "llList2Float", "list l", "integer index")
289 llList2Integer = newFunc("integer", "list l", "integer index"), 348newFunc("integer", "llList2Integer", "list l", "integer index")
290 llList2Key = newFunc("key", "list l", "integer index"), 349newFunc("key", "llList2Key", "list l", "integer index")
291 llList2List = newFunc("list", "list l", "integer start", "integer End"), 350newFunc("list", "llList2List", "list l", "integer start", "integer End")
292 llList2String = newFunc("string", "list l", "integer index"), 351newFunc("string", "llList2String", "list l", "integer index")
293 llList2Rotation = newFunc("rotation", "list l", "integer index"), 352newFunc("rotation", "llList2Rotation", "list l", "integer index")
294 llList2Vector = newFunc("vector", "list l", "integer index"), 353newFunc("vector", "llList2Vector", "list l", "integer index")
295 llListFindList = newFunc("integer", "list l", "list l1"), 354newFunc("integer", "llListFindList", "list l", "list l1")
296 llListInsertList = newFunc("list", "list l", "list l1", "integer index"), 355newFunc("list", "llListInsertList", "list l", "list l1", "integer index")
297 llListReplaceList = newFunc("list", "list l", "list part", "integer start", "integer End"), 356newFunc("list", "llListReplaceList", "list l", "list part", "integer start", "integer End")
298 llListSort = newFunc("list", "list l", "integer stride", "integer ascending"), 357newFunc("list", "llListSort", "list l", "integer stride", "integer ascending")
299 llParseString2List = newFunc("list", "string In", "list l", "list l1"), 358newFunc("list", "llParseString2List", "string In", "list l", "list l1")
300 llParseStringKeepNulls = newFunc("list", "string In", "list l", "list l1"), 359newFunc("list", "llParseStringKeepNulls", "string In", "list l", "list l1")
301 360
302-- LSL math functions 361-- LSL math functions
303 llEuler2Rot = newFunc("rotation", "vector vec"), 362newFunc("rotation", "llEuler2Rot", "vector vec")
304 llFrand = newFunc("float", "float max"), 363newFunc("float", "llFrand", "float max")
305 llPow = newFunc("float", "float number", "float places"), 364newFunc("float", "llPow", "float number", "float places")
306 llRot2Euler = newFunc("vector", "rotation rot"), 365newFunc("vector", "llRot2Euler", "rotation rot")
307 llRound = newFunc("integer", "float number"), 366newFunc("integer", "llRound", "float number")
308 367
309-- LSL media functions 368-- LSL media functions
310 llPlaySound = newFunc("", "string name", "float volume"), 369newFunc("", "llPlaySound", "string name", "float volume")
311 370
312-- LSL object / prim functions 371-- LSL object / prim functions
313 llDie = newFunc(""), 372newFunc("", "llDie")
314 llGetKey = newFunc("key"), 373newFunc("key", "llGetKey")
315 llGetLinkNumber = newFunc("integer"), 374newFunc("integer", "llGetLinkNumber")
316 llGetObjectDesc = newFunc("string"), 375newFunc("string", "llGetObjectDesc")
317 llGetObjectName = newFunc("string"), 376newFunc("string", "llGetObjectName")
318 llGetOwner = newFunc("key"), 377newFunc("key", "llGetOwner")
319 llSetObjectDesc = newFunc("", "string text"), 378newFunc("", "llSetObjectDesc", "string text")
320 llSetObjectName = newFunc("", "string text"), 379newFunc("", "llSetObjectName", "string text")
321 llSetPrimitiveParams = newFunc("", "list params"), 380newFunc("", "llSetPrimitiveParams", "list params")
322 llSetSitText = newFunc("", "string text"), 381newFunc("", "llSetSitText", "string text")
323 llSetText = newFunc("", "string text", "vector colour", "float alpha"), 382newFunc("", "llSetText", "string text", "vector colour", "float alpha")
324 llSitTarget = newFunc("", "vector pos", "rotation rot"), 383newFunc("", "llSitTarget", "vector pos", "rotation rot")
325 384
326-- LSL rotation / scaling / translation functions 385-- LSL rotation / scaling / translation functions
327 llGetPos = newFunc("vector", ""), 386newFunc("vector", "llGetPos")
328 llGetRot = newFunc("rotation", ""), 387newFunc("rotation", "llGetRot")
329 llSetPos = newFunc("", "vector pos"), 388newFunc("", "llSetPos", "vector pos")
330 llSetRot = newFunc("", "rotation rot"), 389newFunc("", "llSetRot", "rotation rot")
331 llSetScale = newFunc("", "vector scale"), 390newFunc("", "llSetScale", "vector scale")
332 391
333-- LSL script functions 392-- LSL script functions
334 llGetFreeMemory = newFunc("integer", ""), 393newFunc("integer", "llGetFreeMemory")
335 llGetScriptName = newFunc("string", ""), 394newFunc("string", "llGetScriptName")
336 llResetOtherScript = newFunc("", "string name"), 395newFunc("", "llResetOtherScript", "string name")
337 llResetScript = newFunc("", ""), 396newFunc("", "llResetScript")
338 llSetScriptState = newFunc("", "string name", "integer running"), 397newFunc("", "llSetScriptState", "string name", "integer running")
339 398
340-- LSL string functions 399-- LSL string functions
341 llGetSubString = newFunc("string", "string text", "integer start", "integer End"), 400newFunc("string", "llGetSubString", "string text", "integer start", "integer End")
342 llStringLength = newFunc("integer", "string text"), 401newFunc("integer", "llStringLength", "string text")
343 llStringTrim = newFunc("string", "string text", "integer type"), 402newFunc("string", "llStringTrim", "string text", "integer type")
344 llSubStringIndex = newFunc("integer", "string text", "string sub"), 403newFunc("integer", "llSubStringIndex", "string text", "string sub")
345 404
346-- LSL texture functions 405-- LSL texture functions
347 llGetAlpha = newFunc("float", "integer side"), 406newFunc("float", "llGetAlpha", "integer side")
348 llSetAlpha = newFunc("", "float alpha", "integer side"), 407newFunc("", "llSetAlpha", "float alpha", "integer side")
349 llSetColor = newFunc("", "vector colour", "integer side"), 408newFunc("", "llSetColor", "vector colour", "integer side")
350 409
351-- LSL time functions 410-- LSL time functions
352 llGetTime = newFunc("float", ""), 411newFunc("float", "llGetTime")
353 llResetTime = newFunc("", ""), 412newFunc("", "llResetTime")
354 llSetTimerEvent = newFunc("", "float seconds"), 413newFunc("", "llSetTimerEvent", "float seconds")
355 llSleep = newFunc("", "float seconds"), 414newFunc("", "llSleep", "float seconds")
356}
357 415
358 416
359-- TODO - fake this for now. 417-- TODO - fake this for now.
@@ -636,43 +694,6 @@ function LSL.vectorTypecast(x)
636end 694end
637 695
638 696
639-- glue stuff
640
641local args2string -- Pre declare this.
642local mt = {}
643
644local function value2string(value, Type)
645 local temp = ""
646
647 if "float" == Type then temp = temp .. value
648 elseif "integer" == Type then temp = temp .. value
649 elseif "key" == Type then temp = "\"" .. value .. "\""
650 elseif "list" == Type then temp = "[" .. args2string(true, unpack(value)) .. "]"
651 elseif "table" == Type then temp = "[" .. args2string(true, unpack(value)) .. "]"
652 elseif "string" == Type then temp = "\"" .. value .. "\""
653 elseif "rotation" == Type then temp = "<" .. value.x .. ", " .. value.y .. ", " .. value.z .. ", " .. value.s .. ">"
654 elseif "vector" == Type then temp = "<" .. value.x .. ", " .. value.y .. ", " .. value.z .. ">"
655 else
656 temp = temp .. value
657 end
658 return temp
659end
660
661function args2string(doType, ...)
662 local temp = ""
663 local first = true
664
665 for j,w in ipairs( {...} ) do
666 if first then first = false else temp = temp .. ", " end
667 if doType then
668 temp = temp .. value2string(w, type(w))
669 else
670 temp = temp .. w
671 end
672 end
673 return temp
674end
675
676function LSL.gimmeLSL() 697function LSL.gimmeLSL()
677 for i,v in ipairs(constants) do 698 for i,v in ipairs(constants) do
678 local value = LSL[v.name] 699 local value = LSL[v.name]
@@ -691,40 +712,5 @@ function LSL.gimmeLSL()
691 LSL.EOF = "\n\n\n" -- Fix this up now. 712 LSL.EOF = "\n\n\n" -- Fix this up now.
692end 713end
693 714
694function mt.callAndReturn( ... )
695 print("mt.callAndReturn(" .. mt.name .. "(" .. args2string(true, ...) .. "))")
696end
697
698function mt.callAndWait( ... )
699 local func = functions[mt.name]
700
701 print("mt.callAndWait(" .. mt.name .. "(" .. args2string(true, ...) .. "))")
702
703 if "float" == func.Type then return 0.0
704 elseif "integer" == func.Type then return 0
705 elseif "key" == func.Type then return LSL.NULL_KEY
706 elseif "list" == func.Type then return {}
707 elseif "string" == func.Type then return ""
708 elseif "rotation" == func.Type then return LSL.ZERO_ROTATION
709 elseif "vector" == func.Type then return LSL.ZERO_VECTOR
710 end
711 return nil
712end
713
714function mt.__index(Table, key)
715 local func = functions[key]
716
717 -- This is hacky, but we should only be running one at a time.
718 mt.name = key
719
720 if "" == func.Type then
721 return mt.callAndReturn
722 else
723 return mt.callAndWait
724 end
725end
726
727setmetatable(LSL, mt)
728
729 715
730return LSL; 716return LSL;