From db07db3f6cdec03e9c16142c8e6a9d49801c5ae1 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 22 Feb 2012 02:08:13 +1000 Subject: Create constants.lsl at run time from LSL.lua, and use the same infrastructure to generate calls for OpenSim to deal with. --- LuaSL/src/LSL.lua | 685 +++++++++++++++++++++++++++++------------------------- 1 file changed, 365 insertions(+), 320 deletions(-) (limited to 'LuaSL/src/LSL.lua') diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua index d618e65..2f337a5 100644 --- a/LuaSL/src/LSL.lua +++ b/LuaSL/src/LSL.lua @@ -1,19 +1,4 @@ -- A module of LSL stuffs. --- TODO - currently there is a constants.lsl file. Move it into here. --- It contains LSL constants and ll*() functions stubs. --- The compiler compiles that into a LSL_Scripts structure at startup, --- then uses that for function and variable lookups, as well as looking up in the current script. --- I can run this at compiler startup time, then iterate through the LSL table from C to generate that LSL_Script structure. ---[[ -Have an array of functions and argument types. -Compiler startup writes a short script that loads this module as normal, then calls the special "gimme the LSL" function. - The function runs through the array, calling back to C, passing each function definition. - It also runs through the constants, calling back to C, passing each constant type, name, and value. - In both cases, it could just combine them all (variables and functions together) into one big string blob to pass to the lexer+parser. -Hook up the metatable _call method to check if the function is in the array, then pass it to OpenSim. - The array includes any return type, so _call knows if it has to wait for the reply. - So the function array should have some structure, to be able to tell the function name, and the various types. -]] -- Using a module means it gets compiled each time? Maybe not if I can use bytecode files. Perhaps LuaJIT caches these? -- Does not seem to be slowing it down noticably, but that might change once the stubs are filled out. @@ -41,7 +26,6 @@ upvalue--either way is a bit more efficient and less error prone. local LSL = {}; local SID = ""; - -- Debugging aids -- Functions to print tables. @@ -70,6 +54,7 @@ function msg(...) print(SID, ...) -- The comma adds a tab, fancy that. B-) end + -- LSL function and constant creation stuff. local function newConst(Type, name, value) @@ -77,261 +62,302 @@ local function newConst(Type, name, value) return { Type = Type, name = name } end -local function newFunc(Type, name, ... ) - return { Type = Type, name = name, args = ... } +local function newFunc(Type, ... ) + return { Type = Type, args = {...} } end -local functions = -{ - newFunc("key", "llAvatarOnSitTarget"), - newFunc("list", "llGetAnimationList", "key"), -} + +-- LSL constants. local constants = { - newConst("float", "PI", 3.14159265358979323846264338327950), + newConst("float", "PI", 3.14159265358979323846264338327950), + newConst("float", "PI_BY_TWO", LSL.PI / 2), -- 1.57079632679489661923132169163975 + newConst("float", "TWO_PI", LSL.PI * 2), -- 6.28318530717958647692528676655900 + newConst("float", "DEG_TO_RAD", LSL.PI / 180.0), -- 0.01745329252 + newConst("float", "RAD_TO_DEG", 180.0 / LSL.PI), -- 57.2957795131 + newConst("float", "SQRT2", 1.4142135623730950488016887242097), + + newConst("integer", "CHANGED_INVENTORY", 0x001), + newConst("integer", "CHANGED_COLOR", 0x002), + newConst("integer", "CHANGED_SHAPE", 0x004), + newConst("integer", "CHANGED_SCALE", 0x008), + newConst("integer", "CHANGED_TEXTURE", 0x010), + newConst("integer", "CHANGED_LINK", 0x020), + newConst("integer", "CHANGED_ALLOWED_DROP", 0x040), + newConst("integer", "CHANGED_OWNER", 0x080), + newConst("integer", "CHANGED_REGION", 0x100), + newConst("integer", "CHANGED_TELEPORT", 0x200), + newConst("integer", "CHANGED_REGION_START", 0x400), + newConst("integer", "CHANGED_MEDIA", 0x800), + + newConst("integer", "DEBUG_CHANNEL", 2147483647), + newConst("integer", "PUBLIC_CHANNEL", 0), + + newConst("integer", "INVENTORY_ALL", -1), + newConst("integer", "INVENTORY_NONE", -1), + newConst("integer", "INVENTORY_TEXTURE", 0), + newConst("integer", "INVENTORY_SOUND", 1), + newConst("integer", "INVENTORY_LANDMARK", 3), + newConst("integer", "INVENTORY_CLOTHING", 5), + newConst("integer", "INVENTORY_OBJECT", 6), + newConst("integer", "INVENTORY_NOTECARD", 7), + newConst("integer", "INVENTORY_SCRIPT", 10), + newConst("integer", "INVENTORY_BODYPART", 13), + newConst("integer", "INVENTORY_ANIMATION", 20), + newConst("integer", "INVENTORY_GESTURE", 21), + + newConst("integer", "ALL_SIDES", -1), + newConst("integer", "LINK_SET", -1), + newConst("integer", "LINK_ROOT", 1), + newConst("integer", "LINK_ALL_OTHERS", -2), + newConst("integer", "LINK_ALL_CHILDREN", -3), + newConst("integer", "LINK_THIS", -4), + + newConst("integer", "PERM_ALL", 0x7FFFFFFF), + newConst("integer", "PERM_COPY", 0x00008000), + newConst("integer", "PERM_MODIFY", 0x00004000), + newConst("integer", "PERM_MOVE", 0x00080000), + newConst("integer", "PERM_TRANSFER", 0x00002000), + newConst("integer", "MASK_BASE", 0), + newConst("integer", "MASK_OWNER", 1), + newConst("integer", "MASK_GROUP", 2), + newConst("integer", "MASK_EVERYONE", 3), + newConst("integer", "MASK_NEXT", 4), + newConst("integer", "PERMISSION_DEBIT", 0x0002), + newConst("integer", "PERMISSION_TAKE_CONTROLS", 0x0004), + newConst("integer", "PERMISSION_TRIGGER_ANIMATION", 0x0010), + newConst("integer", "PERMISSION_ATTACH", 0x0020), + newConst("integer", "PERMISSION_CHANGE_LINKS", 0x0080), + newConst("integer", "PERMISSION_TRACK_CAMERA", 0x0400), + newConst("integer", "PERMISSION_CONTRAL_CAMERA", 0x0800), + + newConst("integer", "AGENT", 0x01), + newConst("integer", "ACTIVE", 0x02), + newConst("integer", "PASSIVE", 0x04), + newConst("integer", "SCRIPTED", 0x08), + + newConst("integer", "OBJECT_UNKNOWN_DETAIL", -1), + + newConst("integer", "PRIM_BUMP_SHINY", 19), + newConst("integer", "PRIM_COLOR", 18), + newConst("integer", "PRIM_FLEXIBLE", 21), + newConst("integer", "PRIM_FULLBRIGHT", 20), + newConst("integer", "PRIM_GLOW", 25), + newConst("integer", "PRIM_MATERIAL", 2), + newConst("integer", "PRIM_PHANTOM", 5), + newConst("integer", "PRIM_PHYSICS", 3), + newConst("integer", "PRIM_POINT_LIGHT", 23), + newConst("integer", "PRIM_POSITION", 6), + newConst("integer", "PRIM_ROTATION", 8), + newConst("integer", "PRIM_SIZE", 7), + newConst("integer", "PRIM_TEMP_ON_REZ", 4), + newConst("integer", "PRIM_TYPE", 9), + newConst("integer", "PRIM_TYPE_OLD", 1), + newConst("integer", "PRIM_TEXGEN", 22), + newConst("integer", "PRIM_TEXTURE", 17), + newConst("integer", "PRIM_TEXT", 26), + + newConst("integer", "PRIM_BUMP_NONE", 0), + newConst("integer", "PRIM_BUMP_BRIGHT", 1), + newConst("integer", "PRIM_BUMP_DARK", 2), + newConst("integer", "PRIM_BUMP_WOOD", 3), + newConst("integer", "PRIM_BUMP_BARK", 4), + newConst("integer", "PRIM_BUMP_BRICKS", 5), + newConst("integer", "PRIM_BUMP_CHECKER", 6), + newConst("integer", "PRIM_BUMP_CONCRETE", 7), + newConst("integer", "PRIM_BUMP_TILE", 8), + newConst("integer", "PRIM_BUMP_STONE", 9), + newConst("integer", "PRIM_BUMP_DISKS", 10), + newConst("integer", "PRIM_BUMP_GRAVEL", 11), + newConst("integer", "PRIM_BUMP_BLOBS", 12), + newConst("integer", "PRIM_BUMP_SIDING", 13), + newConst("integer", "PRIM_BUMP_LARGETILE", 14), + newConst("integer", "PRIM_BUMP_STUCCO", 15), + newConst("integer", "PRIM_BUMP_SUCTION", 16), + newConst("integer", "PRIM_BUMP_WEAVE", 17), + + newConst("integer", "PRIM_HOLE_DEFAULT", 0), + newConst("integer", "PRIM_HOLE_CIRCLE", 16), + newConst("integer", "PRIM_HOLE_SQUARE", 32), + newConst("integer", "PRIM_HOLE_TRIANGLE", 48), + + newConst("integer", "PRIM_MATERIAL_STONE", 0), + newConst("integer", "PRIM_MATERIAL_METAL", 1), + newConst("integer", "PRIM_MATERIAL_GLASS", 2), + newConst("integer", "PRIM_MATERIAL_WOOD", 3), + newConst("integer", "PRIM_MATERIAL_FLESH", 4), + newConst("integer", "PRIM_MATERIAL_PLASTIC", 5), + newConst("integer", "PRIM_MATERIAL_RUBBER", 6), + newConst("integer", "PRIM_MATERIAL_LIGHT", 7), + + newConst("integer", "PRIM_SCULPT_TYPE_SPHERE", 1), + newConst("integer", "PRIM_SCULPT_TYPE_TORUS", 2), + newConst("integer", "PRIM_SCULPT_TYPE_PLANE", 3), + newConst("integer", "PRIM_SCULPT_TYPE_CYLINDER", 4), + newConst("integer", "PRIM_SCULPT_TYPE_MESH", 5), + newConst("integer", "PRIM_SCULPT_TYPE_MIMESH", 6), + + newConst("integer", "PRIM_SHINY_NONE", 0), + newConst("integer", "PRIM_SHINY_LOW", 1), + newConst("integer", "PRIM_SHINY_MEDIUM", 2), + newConst("integer", "PRIM_SHINY_HIGH", 3), + + newConst("integer", "PRIM_TYPE_BOX", 0), + newConst("integer", "PRIM_TYPE_CYLINDER", 1), + newConst("integer", "PRIM_TYPE_PRISM", 2), + newConst("integer", "PRIM_TYPE_SPHERE", 3), + newConst("integer", "PRIM_TYPE_TORUS", 4), + newConst("integer", "PRIM_TYPE_TUBE", 5), + newConst("integer", "PRIM_TYPE_RING", 6), + newConst("integer", "PRIM_TYPE_SCULPT", 7), + + newConst("integer", "STRING_TRIM", 3), + newConst("integer", "STRING_TRIM_HEAD", 1), + newConst("integer", "STRING_TRIM_TAIL", 2), + + newConst("integer", "TRUE", 1), + newConst("integer", "FALSE", 0), + + newConst("integer", "TYPE_INTEGER", 1), + newConst("integer", "TYPE_FLOAT", 2), + newConst("integer", "TYPE_STRING", 3), + newConst("integer", "TYPE_KEY", 4), + newConst("integer", "TYPE_VECTOR", 5), + newConst("integer", "TYPE_ROTATION", 6), + newConst("integer", "TYPE_INVALID", 0), + + newConst("string", "NULL_KEY", "00000000-0000-0000-0000-000000000000"), + newConst("string", "EOF", "\\n\\n\\n"), -- Corner case, dealt with later. + + newConst("rotation", "ZERO_ROTATION", {x=0.0, y=0.0, z=0.0, s=1.0}), + newConst("vector", "ZERO_VECTOR", {x=0.0, y=0.0, z=0.0}), + +-- TODO - Temporary dummy variables to get vector and rotation thingies to work for now. + + newConst("float", "s", 1.0), + newConst("float", "x", 0.0), + newConst("float", "y", 0.0), + newConst("float", "z", 0.0), } +-- ll*() function definitions --- LSL constants. +local functions = +{ +-- LSL avatar functions + llAvatarOnSitTarget = newFunc("key"), + llGetAnimationList = newFunc("list", "key id"), + llGetPermissions = newFunc("integer"), + llGetPermissionsKey = newFunc("key"), + llKey2Name = newFunc("string", "key avatar"), + llRequestPermissions = newFunc("", "key avatar", "integer perms"), + llSameGroup = newFunc("integer", "key avatar"), + llStartAnimation = newFunc("", "string anim"), + llStopAnimation = newFunc("", "string anim"), + llUnSit = newFunc("", "key avatar"), -LSL.PI = 3.14159265358979323846264338327950; -LSL.PI_BY_TWO = LSL.PI / 2; -- 1.57079632679489661923132169163975 -LSL.TWO_PI = LSL.PI * 2; -- 6.28318530717958647692528676655900 -LSL.DEG_TO_RAD = LSL.PI / 180.0; -- 0.01745329252 -LSL.RAD_TO_DEG = 180.0 / LSL.PI; -- 57.2957795131 -LSL.SQRT2 = 1.4142135623730950488016887242097; - -LSL.CHANGED_INVENTORY = 0x001; -LSL.CHANGED_COLOR = 0x002; -LSL.CHANGED_SHAPE = 0x004; -LSL.CHANGED_SCALE = 0x008; -LSL.CHANGED_TEXTURE = 0x010; -LSL.CHANGED_LINK = 0x020; -LSL.CHANGED_ALLOWED_DROP = 0x040; -LSL.CHANGED_OWNER = 0x080; -LSL.CHANGED_REGION = 0x100; -LSL.CHANGED_TELEPORT = 0x200; -LSL.CHANGED_REGION_START = 0x400; -LSL.CHANGED_MEDIA = 0x800; - -LSL.DEBUG_CHANNEL = 2147483647; -LSL.PUBLIC_CHANNEL = 0; - -LSL.INVENTORY_ALL = -1; -LSL.INVENTORY_NONE = -1; -LSL.INVENTORY_TEXTURE = 0; -LSL.INVENTORY_SOUND = 1; -LSL.INVENTORY_LANDMARK = 3; -LSL.INVENTORY_CLOTHING = 5; -LSL.INVENTORY_OBJECT = 6; -LSL.INVENTORY_NOTECARD = 7; -LSL.INVENTORY_SCRIPT = 10; -LSL.INVENTORY_BODYPART = 13; -LSL.INVENTORY_ANIMATION = 20; -LSL.INVENTORY_GESTURE = 21; - -LSL.ALL_SIDES = -1; -LSL.LINK_SET = -1; -LSL.LINK_ROOT = 1; -LSL.LINK_ALL_OTHERS = -2; -LSL.LINK_ALL_CHILDREN = -3; -LSL.LINK_THIS = -4; - -LSL.PERM_ALL = 0x7FFFFFFF; -LSL.PERM_COPY = 0x00008000; -LSL.PERM_MODIFY = 0x00004000; -LSL.PERM_MOVE = 0x00080000; -LSL.PERM_TRANSFER = 0x00002000; -LSL.MASK_BASE = 0; -LSL.MASK_OWNER = 1; -LSL.MASK_GROUP = 2; -LSL.MASK_EVERYONE = 3; -LSL.MASK_NEXT = 4; -LSL.PERMISSION_DEBIT = 0x0002; -LSL.PERMISSION_TAKE_CONTROLS = 0x0004; -LSL.PERMISSION_TRIGGER_ANIMATION = 0x0010; -LSL.PERMISSION_ATTACH = 0x0020; -LSL.PERMISSION_CHANGE_LINKS = 0x0080; -LSL.PERMISSION_TRACK_CAMERA = 0x0400; -LSL.PERMISSION_CONTRAL_CAMERA = 0x0800; - -LSL.AGENT = 0x01; -LSL.ACTIVE = 0x02; -LSL.PASSIVE = 0x04; -LSL.SCRIPTED = 0x08; - -LSL.OBJECT_UNKNOWN_DETAIL = -1; - -LSL.PRIM_BUMP_SHINY = 19; -LSL.PRIM_COLOR = 18; -LSL.PRIM_FLEXIBLE = 21; -LSL.PRIM_FULLBRIGHT = 20; -LSL.PRIM_GLOW = 25; -LSL.PRIM_MATERIAL = 2; -LSL.PRIM_PHANTOM = 5; -LSL.PRIM_PHYSICS = 3; -LSL.PRIM_POINT_LIGHT = 23; -LSL.PRIM_POSITION = 6; -LSL.PRIM_ROTATION = 8; -LSL.PRIM_SIZE = 7; -LSL.PRIM_TEMP_ON_REZ = 4; -LSL.PRIM_TYPE = 9; -LSL.PRIM_TYPE_OLD = 1; -LSL.PRIM_TEXGEN = 22; -LSL.PRIM_TEXTURE = 17; -LSL.PRIM_TEXT = 26; - -LSL.PRIM_BUMP_NONE = 0; -LSL.PRIM_BUMP_BRIGHT = 1; -LSL.PRIM_BUMP_DARK = 2; -LSL.PRIM_BUMP_WOOD = 3; -LSL.PRIM_BUMP_BARK = 4; -LSL.PRIM_BUMP_BRICKS = 5; -LSL.PRIM_BUMP_CHECKER = 6; -LSL.PRIM_BUMP_CONCRETE = 7; -LSL.PRIM_BUMP_TILE = 8; -LSL.PRIM_BUMP_STONE = 9; -LSL.PRIM_BUMP_DISKS = 10; -LSL.PRIM_BUMP_GRAVEL = 11; -LSL.PRIM_BUMP_BLOBS = 12; -LSL.PRIM_BUMP_SIDING = 13; -LSL.PRIM_BUMP_LARGETILE = 14; -LSL.PRIM_BUMP_STUCCO = 15; -LSL.PRIM_BUMP_SUCTION = 16; -LSL.PRIM_BUMP_WEAVE = 17; - -LSL.PRIM_HOLE_DEFAULT = 0; -LSL.PRIM_HOLE_CIRCLE = 16; -LSL.PRIM_HOLE_SQUARE = 32; -LSL.PRIM_HOLE_TRIANGLE = 48; - -LSL.PRIM_MATERIAL_STONE = 0; -LSL.PRIM_MATERIAL_METAL = 1; -LSL.PRIM_MATERIAL_GLASS = 2; -LSL.PRIM_MATERIAL_WOOD = 3; -LSL.PRIM_MATERIAL_FLESH = 4; -LSL.PRIM_MATERIAL_PLASTIC = 5; -LSL.PRIM_MATERIAL_RUBBER = 6; -LSL.PRIM_MATERIAL_LIGHT = 7; - -LSL.PRIM_SCULPT_TYPE_SPHERE = 1; -LSL.PRIM_SCULPT_TYPE_TORUS = 2; -LSL.PRIM_SCULPT_TYPE_PLANE = 3; -LSL.PRIM_SCULPT_TYPE_CYLINDER = 4; -LSL.PRIM_SCULPT_TYPE_MESH = 5; -LSL.PRIM_SCULPT_TYPE_MIMESH = 6; - -LSL.PRIM_SHINY_NONE = 0; -LSL.PRIM_SHINY_LOW = 1; -LSL.PRIM_SHINY_MEDIUM = 2; -LSL.PRIM_SHINY_HIGH = 3; - -LSL.PRIM_TYPE_BOX = 0; -LSL.PRIM_TYPE_CYLINDER = 1; -LSL.PRIM_TYPE_PRISM = 2; -LSL.PRIM_TYPE_SPHERE = 3; -LSL.PRIM_TYPE_TORUS = 4; -LSL.PRIM_TYPE_TUBE = 5; -LSL.PRIM_TYPE_RING = 6; -LSL.PRIM_TYPE_SCULPT = 7; - -LSL_RC_GET_NORMAL = 1; -LSL_RC_GET_ROOT_KEY = 2; -LSL_RC_GET_LINK_NUM = 4; -LSL_RC_REJECT_AGENTS = 1; -LSL_RC_REJECT_PHYSICAL = 2; -LSL_RC_REJECT_NONPHYSICAL = 4; -LSL_RC_REJECT_LAND = 8; -LSL.RC_REJECT_TYPES = 0; -LSL.RC_DETECT_PHANTOM = 1; -LSL.RC_DATA_FLAGS = 2; -LSL.RC_MAX_HITS = 3; -LSL.RCERR_UNKNOWN = -1; -LSL.RCERR_SIM_PERF_LOW = -2; -LSL.RCERR_CAST_TIME_EXCEEDED = -3; - -LSL.STATUS_OK = 0; -LSL.STATUS_MALFORMED_PARAMS = 1000; -LSL.STATUS_TYPE_MISMATCH = 1001; -LSL.STATUS_BOUNDS_ERROR = 1002; -LSL.STATUS_NOT_FOUND = 1003; -LSL.STATUS_NOT_SUPPORTED = 1004; -LSL.STATUS_INTERNAL_ERROR = 1999; -LSL.STATUS_WHITELIST_FAILED = 2001; - -LSL.STRING_TRIM = 3; -LSL.STRING_TRIM_HEAD = 1; -LSL.STRING_TRIM_TAIL = 2; - -LSL.TRUE = 1; -LSL.FALSE = 0; - -LSL.TYPE_INTEGER = 1; -LSL.TYPE_FLOAT = 2; -LSL.TYPE_STRING = 3; -LSL.TYPE_KEY = 4; -LSL.TYPE_VECTOR = 5; -LSL.TYPE_ROTATION = 6; -LSL.TYPE_INVALID = 0; - -LSL.NULL_KEY = "00000000-0000-0000-0000-000000000000"; -LSL.EOF = "\n\n\n"; - -LSL.ZERO_ROTATION = {x=0.0, y=0.0, z=0.0, s=1.0}; -LSL.ZERO_VECTOR = {x=0.0, y=0.0, z=0.0}; - --- TODO - Temporary dummy variables to got vector and rotation thingies to work for now. - -LSL.s = 1.0; -LSL.x = 0.0; -LSL.y = 0.0; -LSL.z = 0.0; - --- ll*() function stubs. +-- LSL collision / detect / sensor functions + llDetectedGroup = newFunc("key", "integer index"), + llDetectedKey = newFunc("key", "integer index"), +-- LSL communications functions + llDialog = newFunc("", "key avatar", "string caption", "list arseBackwardsMenu", "integer channel"), + llListen = newFunc("integer", "integer channel", "string name", "key id", "string msg"), + llListenRemove = newFunc("", "integer handle"), + llOwnerSay = newFunc("", "string text"), + llSay = newFunc("", "integer channel", "string text"), + llShout = newFunc("", "integer channel", "string text"), + llWhisper = newFunc("", "integer channel", "string text"), + llMessageLinked = newFunc("", "integer link", "integer num", "string text", "key aKey"), --- LSL avatar functions +-- LSL inventory functions. + llGetInventoryName = newFunc("string", "integer Type", "integer index"), + llGetInventoryNumber = newFunc("integer", "integer Type"), + llGetInventoryType = newFunc("integer", "string name"), + llGetNotecardLine = newFunc("key", "string name", "integer index"), + llRezAtRoot = newFunc("", "string name", "vector position", "vector velocity", "rotation rot", "integer channel"), + llRezObject = newFunc("", "string name", "vector position", "vector velocity", "rotation rot", "integer channel"), -function --[[key]] LSL.llAvatarOnSitTarget() return LSL.NULL_KEY end; -function --[[list]] LSL.llGetAnimationList(--[[key]] id) return {} end; -function --[[integer]] LSL.llGetPermissions() return 0 end; -function --[[key]] LSL.llGetPermissionsKey() return LSL.NULL_KEY end; -function --[[string]] LSL.llKey2Name(--[[key]] avatar) return "" end; -function LSL.llRequestPermissions(--[[key]] avatar,--[[integer]] perms) end; -function --[[integer]] LSL.llSameGroup(--[[key]] avatar) return 0 end; -function LSL.llStartAnimation(--[[string]] anim) end; -function LSL.llStopAnimation(--[[string]] anim) end; -function LSL.llUnSit(--[[key]] avatar) end; +-- LSL list functions. + llCSV2List = newFunc("list", "string text"), + llDeleteSubList = newFunc("list", "list l", "integer start", "integer End"), + llDumpList2String = newFunc("string", "list l", "string separator"), + llGetListLength = newFunc("integer", "list l"), + llList2CSV = newFunc("string", "list l"), + llList2Float = newFunc("float", "list l", "integer index"), + llList2Integer = newFunc("integer", "list l", "integer index"), + llList2Key = newFunc("key", "list l", "integer index"), + llList2List = newFunc("list", "list l", "integer start", "integer End"), + llList2String = newFunc("string", "list l", "integer index"), + llList2Rotation = newFunc("rotation", "list l", "integer index"), + llList2Vector = newFunc("vector", "list l", "integer index"), + llListFindList = newFunc("integer", "list l", "list l1"), + llListInsertList = newFunc("list", "list l", "list l1", "integer index"), + llListReplaceList = newFunc("list", "list l", "list part", "integer start", "integer End"), + llListSort = newFunc("list", "list l", "integer stride", "integer ascending"), + llParseString2List = newFunc("list", "string In", "list l", "list l1"), + llParseStringKeepNulls = newFunc("list", "string In", "list l", "list l1"), +-- LSL math functions + llEuler2Rot = newFunc("rotation", "vector vec"), + llFrand = newFunc("float", "float max"), + llPow = newFunc("float", "float number", "float places"), + llRot2Euler = newFunc("vector", "rotation rot"), + llRound = newFunc("integer", "float number"), --- LSL collision / detect / sensor functions +-- LSL media functions + llPlaySound = newFunc("", "string name", "float volume"), -function --[[key]] LSL.llDetectedGroup(--[[integer]] index) return LSL.NULL_KEY end; -function --[[key]] LSL.llDetectedKey(--[[integer]] index) return LSL.NULL_KEY end; +-- LSL object / prim functions + llDie = newFunc(""), + llGetKey = newFunc("key"), + llGetLinkNumber = newFunc("integer"), + llGetObjectDesc = newFunc("string"), + llGetObjectName = newFunc("string"), + llGetOwner = newFunc("key"), + llSetObjectDesc = newFunc("", "string text"), + llSetObjectName = newFunc("", "string text"), + llSetPrimitiveParams = newFunc("", "list params"), + llSetSitText = newFunc("", "string text"), + llSetText = newFunc("", "string text", "vector colour", "float alpha"), + llSitTarget = newFunc("", "vector pos", "rotation rot"), +-- LSL rotation / scaling / translation functions + llGetPos = newFunc("vector", ""), + llGetRot = newFunc("rotation", ""), + llSetPos = newFunc("", "vector pos"), + llSetRot = newFunc("", "rotation rot"), + llSetScale = newFunc("", "vector scale"), --- LSL communications functions +-- LSL script functions + llGetFreeMemory = newFunc("integer", ""), + llGetScriptName = newFunc("string", ""), + llResetOtherScript = newFunc("", "string name"), + llResetScript = newFunc("", ""), + llSetScriptState = newFunc("", "string name", "integer running"), -function LSL.llDialog(--[[key]] avatar, --[[string]] caption, --[[list]] arseBackwardsMenu,--[[integer]] channel) end; -function --[[integer]] LSL.llListen(--[[integer]] channel, --[[string]] name, --[[key]] id, --[[string]] msg) return 0 end; -function LSL.llListenRemove(--[[integer]] handle) end; -function LSL.llOwnerSay(--[[string]] text) msg("Owner say: " .. text); end; -function LSL.llSay(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " say: " .. text); end; -function LSL.llShout(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " shout: " .. text); end; -function LSL.llWhisper(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " whisper: " .. text); end; +-- LSL string functions + llGetSubString = newFunc("string", "string text", "integer start", "integer End"), + llStringLength = newFunc("integer", "string text"), + llStringTrim = newFunc("string", "string text", "integer type"), + llSubStringIndex = newFunc("integer", "string text", "string sub"), -function LSL.llMessageLinked(--[[integer]] link,--[[integer]] num, --[[string]] text, --[[key]] aKey) end; +-- LSL texture functions + llGetAlpha = newFunc("float", "integer side"), + llSetAlpha = newFunc("", "float alpha", "integer side"), + llSetColor = newFunc("", "vector colour", "integer side"), +-- LSL time functions + llGetTime = newFunc("float", ""), + llResetTime = newFunc("", ""), + llSetTimerEvent = newFunc("", "float seconds"), + llSleep = newFunc("", "float seconds"), +} --- LSL inventory functions. -function --[[string]] LSL.llGetInventoryName(--[[integer]] tyPe,--[[integer]] index) return "" end; -function --[[integer]] LSL.llGetInventoryNumber(--[[integer]] tyPe) return 0 end; +-- TODO - fake this for now. function --[[integer]] LSL.llGetInventoryType(--[[string]] name) return LSL.INVENTORY_SCRIPT end; -function --[[key]] LSL.llGetNotecardLine(--[[string]] name,--[[integer]] index) return LSL.NULL_KEY end; -function LSL.llRezAtRoot(--[[string]] name, --[[vector]] position, --[[vector]] velocity, --[[rotation]] rot,--[[integer]] channel) end; -function LSL.llRezObject(--[[string]] name, --[[vector]] position, --[[vector]] velocity, --[[rotation]] rot,--[[integer]] channel) end; -- LSL list functions. @@ -483,78 +509,6 @@ function --[[list]] LSL.llParseString2List(--[[string]] In, --[[list]] l, --[[li function --[[list]] LSL.llParseStringKeepNulls(--[[string]] In, --[[list]] l, --[[list]] l1) return {} end; --- LSL math functions - -function --[[rotation]] LSL.llEuler2Rot(--[[vector]] vec) return LSL.ZERO_ROTATION end; -function --[[float]] LSL.llFrand(--[[float]] max) return 0.0 end; -function --[[float]] LSL.llPow(--[[float]] number,--[[float]] places) return 0.0 end; -function --[[vector]] LSL.llRot2Euler(--[[rotation]] rot) return LSL.ZERO_VECTOR end; -function --[[integer]] LSL.llRound(--[[float]] number) return 0 end; - - --- LSL media functions - -function LSL.llPlaySound(--[[string]] name,--[[float]] volume) end; - - --- LSL object / prim functions - -function LSL.llDie() end; -function --[[key]] LSL.llGetKey() return LSL.NULL_KEY end; -function --[[integer]] LSL.llGetLinkNumber() return 0 end; -function --[[string]] LSL.llGetObjectDesc() return "" end; -function --[[string]] LSL.llGetObjectName() return "" end; -function --[[key]] LSL.llGetOwner() return LSL.NULL_KEY end; -function LSL.llSetObjectDesc(--[[string]] text) end; -function LSL.llSetObjectName(--[[string]] text) end; -function LSL.llSetPrimitiveParams(--[[list]] params) end; -function LSL.llSetSitText(--[[string]] text) end; -function LSL.llSetText(--[[string]] text, --[[vector]] colour,--[[float]] alpha) end; -function LSL.llSitTarget(--[[vector]] pos, --[[rotation]] rot) end; - - --- LSL rotation / scaling / translation functions - -function --[[vector]] LSL.llGetPos() return LSL.ZERO_VECTOR end; -function --[[rotation]] LSL.llGetRot() return LSL.ZERO_ROTATION end; -function LSL.llSetPos(--[[vector]] pos) end; -function LSL.llSetRot(--[[rotation]] rot) end; -function LSL.llSetScale(--[[vector]] scale) end; - - --- LSL script functions - -function --[[integer]] LSL.llGetFreeMemory() return 0 end; -function --[[string]] LSL.llGetScriptName() return "" end; -function LSL.llResetOtherScript(--[[string]] name) msg("llResetOtherScript(" .. name .. ")") end; -function LSL.llResetScript() end; -function LSL.llSetScriptState(--[[string]] name,--[[integer]] running) msg("llSetScriptState(" .. name .. "," .. running .. ")") end; - - --- LSL string functions - -function --[[string]] LSL.llGetSubString(--[[string]] text,--[[integer]] start,--[[integer]] eNd) return "" end; -function --[[integer]] LSL.llStringLength(--[[string]] text) return 0 end; -function --[[string]] LSL.llStringTrim(--[[string]] text,--[[integer]] tyPe) return "" end; -function --[[integer]] LSL.llSubStringIndex(--[[string]] text, --[[string]] sub) return 0 end; - - --- LSL texture functions - -function --[[float]] LSL.llGetAlpha(--[[integer]] side) return 0.0 end; -function LSL.llSetAlpha(--[[float]] alpha,--[[integer]] side) end; -function LSL.llSetColor(--[[vector]] colour,--[[integer]] side) end; - - --- LSL time functions - -function --[[float]] LSL.llGetTime() return 0.0 end; -function LSL.llResetTime() end; -function LSL.llSetTimerEvent(--[[float]] seconds) end; -function LSL.llSleep(--[[float]] seconds) msg("llSleep(" .. seconds .. ")") end; - - - -- Crements stuff. function LSL.preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end; @@ -682,4 +636,95 @@ function LSL.vectorTypecast(x) end +-- glue stuff + +local args2string -- Pre declare this. +local mt = {} + +local function value2string(value, Type) + local temp = "" + + if "float" == Type then temp = temp .. value + elseif "integer" == Type then temp = temp .. value + elseif "key" == Type then temp = "\"" .. value .. "\"" + elseif "list" == Type then temp = "[" .. args2string(true, unpack(value)) .. "]" + elseif "table" == Type then temp = "[" .. args2string(true, unpack(value)) .. "]" + elseif "string" == Type then temp = "\"" .. value .. "\"" + elseif "rotation" == Type then temp = "<" .. value.x .. ", " .. value.y .. ", " .. value.z .. ", " .. value.s .. ">" + elseif "vector" == Type then temp = "<" .. value.x .. ", " .. value.y .. ", " .. value.z .. ">" + else + temp = temp .. value + end + return temp +end + +function args2string(doType, ...) + local temp = "" + local first = true + + for j,w in ipairs( {...} ) do + if first then first = false else temp = temp .. ", " end + if doType then + temp = temp .. value2string(w, type(w)) + else + temp = temp .. w + end + end + return temp +end + +function LSL.gimmeLSL() + for i,v in ipairs(constants) do + local value = LSL[v.name] + + print(v.Type .. " " .. v.name .. " = " .. value2string(value, v.Type) .. ";") + end + + for k in pairs(functions) do + local v = functions[k] + if nil == v.args then + print(v.Type .. " " .. k .. "(){}") + else + print(v.Type .. " " .. k .. "(" .. args2string(false, unpack(v.args)) .. "){}") + end + end + LSL.EOF = "\n\n\n" -- Fix this up now. +end + +function mt.callAndReturn( ... ) + print("mt.callAndReturn(" .. mt.name .. "(" .. args2string(true, ...) .. "))") +end + +function mt.callAndWait( ... ) + local func = functions[mt.name] + + print("mt.callAndWait(" .. mt.name .. "(" .. args2string(true, ...) .. "))") + + if "float" == func.Type then return 0.0 + elseif "integer" == func.Type then return 0 + elseif "key" == func.Type then return LSL.NULL_KEY + elseif "list" == func.Type then return {} + elseif "string" == func.Type then return "" + elseif "rotation" == func.Type then return LSL.ZERO_ROTATION + elseif "vector" == func.Type then return LSL.ZERO_VECTOR + end + return nil +end + +function mt.__index(Table, key) + local func = functions[key] + + -- This is hacky, but we should only be running one at a time. + mt.name = key + + if "" == func.Type then + return mt.callAndReturn + else + return mt.callAndWait + end +end + +setmetatable(LSL, mt) + + return LSL; -- cgit v1.1