aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LSL.lua
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/src/LSL.lua')
-rw-r--r--LuaSL/src/LSL.lua685
1 files changed, 365 insertions, 320 deletions
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 @@
1-- A module of LSL stuffs. 1-- A module of LSL stuffs.
2-- TODO - currently there is a constants.lsl file. Move it into here.
3-- It contains LSL constants and ll*() functions stubs.
4-- The compiler compiles that into a LSL_Scripts structure at startup,
5-- then uses that for function and variable lookups, as well as looking up in the current script.
6-- I can run this at compiler startup time, then iterate through the LSL table from C to generate that LSL_Script structure.
7--[[
8Have an array of functions and argument types.
9Compiler startup writes a short script that loads this module as normal, then calls the special "gimme the LSL" function.
10 The function runs through the array, calling back to C, passing each function definition.
11 It also runs through the constants, calling back to C, passing each constant type, name, and value.
12 In both cases, it could just combine them all (variables and functions together) into one big string blob to pass to the lexer+parser.
13Hook up the metatable _call method to check if the function is in the array, then pass it to OpenSim.
14 The array includes any return type, so _call knows if it has to wait for the reply.
15 So the function array should have some structure, to be able to tell the function name, and the various types.
16]]
17 2
18-- Using a module means it gets compiled each time? Maybe not if I can use bytecode files. Perhaps LuaJIT caches these? 3-- Using a module means it gets compiled each time? Maybe not if I can use bytecode files. Perhaps LuaJIT caches these?
19-- Does not seem to be slowing it down noticably, but that might change once the stubs are filled out. 4-- 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.
41local LSL = {}; 26local LSL = {};
42local SID = ""; 27local SID = "";
43 28
44
45-- Debugging aids 29-- Debugging aids
46 30
47-- Functions to print tables. 31-- Functions to print tables.
@@ -70,6 +54,7 @@ function msg(...)
70 print(SID, ...) -- The comma adds a tab, fancy that. B-) 54 print(SID, ...) -- The comma adds a tab, fancy that. B-)
71end 55end
72 56
57
73-- LSL function and constant creation stuff. 58-- LSL function and constant creation stuff.
74 59
75local function newConst(Type, name, value) 60local function newConst(Type, name, value)
@@ -77,261 +62,302 @@ local function newConst(Type, name, value)
77 return { Type = Type, name = name } 62 return { Type = Type, name = name }
78end 63end
79 64
80local function newFunc(Type, name, ... ) 65local function newFunc(Type, ... )
81 return { Type = Type, name = name, args = ... } 66 return { Type = Type, args = {...} }
82end 67end
83 68
84local functions = 69
85{ 70-- LSL constants.
86 newFunc("key", "llAvatarOnSitTarget"),
87 newFunc("list", "llGetAnimationList", "key"),
88}
89 71
90local constants = 72local constants =
91{ 73{
92 newConst("float", "PI", 3.14159265358979323846264338327950), 74 newConst("float", "PI", 3.14159265358979323846264338327950),
75 newConst("float", "PI_BY_TWO", LSL.PI / 2), -- 1.57079632679489661923132169163975
76 newConst("float", "TWO_PI", LSL.PI * 2), -- 6.28318530717958647692528676655900
77 newConst("float", "DEG_TO_RAD", LSL.PI / 180.0), -- 0.01745329252
78 newConst("float", "RAD_TO_DEG", 180.0 / LSL.PI), -- 57.2957795131
79 newConst("float", "SQRT2", 1.4142135623730950488016887242097),
80
81 newConst("integer", "CHANGED_INVENTORY", 0x001),
82 newConst("integer", "CHANGED_COLOR", 0x002),
83 newConst("integer", "CHANGED_SHAPE", 0x004),
84 newConst("integer", "CHANGED_SCALE", 0x008),
85 newConst("integer", "CHANGED_TEXTURE", 0x010),
86 newConst("integer", "CHANGED_LINK", 0x020),
87 newConst("integer", "CHANGED_ALLOWED_DROP", 0x040),
88 newConst("integer", "CHANGED_OWNER", 0x080),
89 newConst("integer", "CHANGED_REGION", 0x100),
90 newConst("integer", "CHANGED_TELEPORT", 0x200),
91 newConst("integer", "CHANGED_REGION_START", 0x400),
92 newConst("integer", "CHANGED_MEDIA", 0x800),
93
94 newConst("integer", "DEBUG_CHANNEL", 2147483647),
95 newConst("integer", "PUBLIC_CHANNEL", 0),
96
97 newConst("integer", "INVENTORY_ALL", -1),
98 newConst("integer", "INVENTORY_NONE", -1),
99 newConst("integer", "INVENTORY_TEXTURE", 0),
100 newConst("integer", "INVENTORY_SOUND", 1),
101 newConst("integer", "INVENTORY_LANDMARK", 3),
102 newConst("integer", "INVENTORY_CLOTHING", 5),
103 newConst("integer", "INVENTORY_OBJECT", 6),
104 newConst("integer", "INVENTORY_NOTECARD", 7),
105 newConst("integer", "INVENTORY_SCRIPT", 10),
106 newConst("integer", "INVENTORY_BODYPART", 13),
107 newConst("integer", "INVENTORY_ANIMATION", 20),
108 newConst("integer", "INVENTORY_GESTURE", 21),
109
110 newConst("integer", "ALL_SIDES", -1),
111 newConst("integer", "LINK_SET", -1),
112 newConst("integer", "LINK_ROOT", 1),
113 newConst("integer", "LINK_ALL_OTHERS", -2),
114 newConst("integer", "LINK_ALL_CHILDREN", -3),
115 newConst("integer", "LINK_THIS", -4),
116
117 newConst("integer", "PERM_ALL", 0x7FFFFFFF),
118 newConst("integer", "PERM_COPY", 0x00008000),
119 newConst("integer", "PERM_MODIFY", 0x00004000),
120 newConst("integer", "PERM_MOVE", 0x00080000),
121 newConst("integer", "PERM_TRANSFER", 0x00002000),
122 newConst("integer", "MASK_BASE", 0),
123 newConst("integer", "MASK_OWNER", 1),
124 newConst("integer", "MASK_GROUP", 2),
125 newConst("integer", "MASK_EVERYONE", 3),
126 newConst("integer", "MASK_NEXT", 4),
127 newConst("integer", "PERMISSION_DEBIT", 0x0002),
128 newConst("integer", "PERMISSION_TAKE_CONTROLS", 0x0004),
129 newConst("integer", "PERMISSION_TRIGGER_ANIMATION", 0x0010),
130 newConst("integer", "PERMISSION_ATTACH", 0x0020),
131 newConst("integer", "PERMISSION_CHANGE_LINKS", 0x0080),
132 newConst("integer", "PERMISSION_TRACK_CAMERA", 0x0400),
133 newConst("integer", "PERMISSION_CONTRAL_CAMERA", 0x0800),
134
135 newConst("integer", "AGENT", 0x01),
136 newConst("integer", "ACTIVE", 0x02),
137 newConst("integer", "PASSIVE", 0x04),
138 newConst("integer", "SCRIPTED", 0x08),
139
140 newConst("integer", "OBJECT_UNKNOWN_DETAIL", -1),
141
142 newConst("integer", "PRIM_BUMP_SHINY", 19),
143 newConst("integer", "PRIM_COLOR", 18),
144 newConst("integer", "PRIM_FLEXIBLE", 21),
145 newConst("integer", "PRIM_FULLBRIGHT", 20),
146 newConst("integer", "PRIM_GLOW", 25),
147 newConst("integer", "PRIM_MATERIAL", 2),
148 newConst("integer", "PRIM_PHANTOM", 5),
149 newConst("integer", "PRIM_PHYSICS", 3),
150 newConst("integer", "PRIM_POINT_LIGHT", 23),
151 newConst("integer", "PRIM_POSITION", 6),
152 newConst("integer", "PRIM_ROTATION", 8),
153 newConst("integer", "PRIM_SIZE", 7),
154 newConst("integer", "PRIM_TEMP_ON_REZ", 4),
155 newConst("integer", "PRIM_TYPE", 9),
156 newConst("integer", "PRIM_TYPE_OLD", 1),
157 newConst("integer", "PRIM_TEXGEN", 22),
158 newConst("integer", "PRIM_TEXTURE", 17),
159 newConst("integer", "PRIM_TEXT", 26),
160
161 newConst("integer", "PRIM_BUMP_NONE", 0),
162 newConst("integer", "PRIM_BUMP_BRIGHT", 1),
163 newConst("integer", "PRIM_BUMP_DARK", 2),
164 newConst("integer", "PRIM_BUMP_WOOD", 3),
165 newConst("integer", "PRIM_BUMP_BARK", 4),
166 newConst("integer", "PRIM_BUMP_BRICKS", 5),
167 newConst("integer", "PRIM_BUMP_CHECKER", 6),
168 newConst("integer", "PRIM_BUMP_CONCRETE", 7),
169 newConst("integer", "PRIM_BUMP_TILE", 8),
170 newConst("integer", "PRIM_BUMP_STONE", 9),
171 newConst("integer", "PRIM_BUMP_DISKS", 10),
172 newConst("integer", "PRIM_BUMP_GRAVEL", 11),
173 newConst("integer", "PRIM_BUMP_BLOBS", 12),
174 newConst("integer", "PRIM_BUMP_SIDING", 13),
175 newConst("integer", "PRIM_BUMP_LARGETILE", 14),
176 newConst("integer", "PRIM_BUMP_STUCCO", 15),
177 newConst("integer", "PRIM_BUMP_SUCTION", 16),
178 newConst("integer", "PRIM_BUMP_WEAVE", 17),
179
180 newConst("integer", "PRIM_HOLE_DEFAULT", 0),
181 newConst("integer", "PRIM_HOLE_CIRCLE", 16),
182 newConst("integer", "PRIM_HOLE_SQUARE", 32),
183 newConst("integer", "PRIM_HOLE_TRIANGLE", 48),
184
185 newConst("integer", "PRIM_MATERIAL_STONE", 0),
186 newConst("integer", "PRIM_MATERIAL_METAL", 1),
187 newConst("integer", "PRIM_MATERIAL_GLASS", 2),
188 newConst("integer", "PRIM_MATERIAL_WOOD", 3),
189 newConst("integer", "PRIM_MATERIAL_FLESH", 4),
190 newConst("integer", "PRIM_MATERIAL_PLASTIC", 5),
191 newConst("integer", "PRIM_MATERIAL_RUBBER", 6),
192 newConst("integer", "PRIM_MATERIAL_LIGHT", 7),
193
194 newConst("integer", "PRIM_SCULPT_TYPE_SPHERE", 1),
195 newConst("integer", "PRIM_SCULPT_TYPE_TORUS", 2),
196 newConst("integer", "PRIM_SCULPT_TYPE_PLANE", 3),
197 newConst("integer", "PRIM_SCULPT_TYPE_CYLINDER", 4),
198 newConst("integer", "PRIM_SCULPT_TYPE_MESH", 5),
199 newConst("integer", "PRIM_SCULPT_TYPE_MIMESH", 6),
200
201 newConst("integer", "PRIM_SHINY_NONE", 0),
202 newConst("integer", "PRIM_SHINY_LOW", 1),
203 newConst("integer", "PRIM_SHINY_MEDIUM", 2),
204 newConst("integer", "PRIM_SHINY_HIGH", 3),
205
206 newConst("integer", "PRIM_TYPE_BOX", 0),
207 newConst("integer", "PRIM_TYPE_CYLINDER", 1),
208 newConst("integer", "PRIM_TYPE_PRISM", 2),
209 newConst("integer", "PRIM_TYPE_SPHERE", 3),
210 newConst("integer", "PRIM_TYPE_TORUS", 4),
211 newConst("integer", "PRIM_TYPE_TUBE", 5),
212 newConst("integer", "PRIM_TYPE_RING", 6),
213 newConst("integer", "PRIM_TYPE_SCULPT", 7),
214
215 newConst("integer", "STRING_TRIM", 3),
216 newConst("integer", "STRING_TRIM_HEAD", 1),
217 newConst("integer", "STRING_TRIM_TAIL", 2),
218
219 newConst("integer", "TRUE", 1),
220 newConst("integer", "FALSE", 0),
221
222 newConst("integer", "TYPE_INTEGER", 1),
223 newConst("integer", "TYPE_FLOAT", 2),
224 newConst("integer", "TYPE_STRING", 3),
225 newConst("integer", "TYPE_KEY", 4),
226 newConst("integer", "TYPE_VECTOR", 5),
227 newConst("integer", "TYPE_ROTATION", 6),
228 newConst("integer", "TYPE_INVALID", 0),
229
230 newConst("string", "NULL_KEY", "00000000-0000-0000-0000-000000000000"),
231 newConst("string", "EOF", "\\n\\n\\n"), -- Corner case, dealt with later.
232
233 newConst("rotation", "ZERO_ROTATION", {x=0.0, y=0.0, z=0.0, s=1.0}),
234 newConst("vector", "ZERO_VECTOR", {x=0.0, y=0.0, z=0.0}),
235
236-- TODO - Temporary dummy variables to get vector and rotation thingies to work for now.
237
238 newConst("float", "s", 1.0),
239 newConst("float", "x", 0.0),
240 newConst("float", "y", 0.0),
241 newConst("float", "z", 0.0),
93} 242}
94 243
244-- ll*() function definitions
95 245
96-- LSL constants. 246local functions =
247{
248-- LSL avatar functions
249 llAvatarOnSitTarget = newFunc("key"),
250 llGetAnimationList = newFunc("list", "key id"),
251 llGetPermissions = newFunc("integer"),
252 llGetPermissionsKey = newFunc("key"),
253 llKey2Name = newFunc("string", "key avatar"),
254 llRequestPermissions = newFunc("", "key avatar", "integer perms"),
255 llSameGroup = newFunc("integer", "key avatar"),
256 llStartAnimation = newFunc("", "string anim"),
257 llStopAnimation = newFunc("", "string anim"),
258 llUnSit = newFunc("", "key avatar"),
97 259
98LSL.PI = 3.14159265358979323846264338327950; 260-- LSL collision / detect / sensor functions
99LSL.PI_BY_TWO = LSL.PI / 2; -- 1.57079632679489661923132169163975 261 llDetectedGroup = newFunc("key", "integer index"),
100LSL.TWO_PI = LSL.PI * 2; -- 6.28318530717958647692528676655900 262 llDetectedKey = newFunc("key", "integer index"),
101LSL.DEG_TO_RAD = LSL.PI / 180.0; -- 0.01745329252
102LSL.RAD_TO_DEG = 180.0 / LSL.PI; -- 57.2957795131
103LSL.SQRT2 = 1.4142135623730950488016887242097;
104
105LSL.CHANGED_INVENTORY = 0x001;
106LSL.CHANGED_COLOR = 0x002;
107LSL.CHANGED_SHAPE = 0x004;
108LSL.CHANGED_SCALE = 0x008;
109LSL.CHANGED_TEXTURE = 0x010;
110LSL.CHANGED_LINK = 0x020;
111LSL.CHANGED_ALLOWED_DROP = 0x040;
112LSL.CHANGED_OWNER = 0x080;
113LSL.CHANGED_REGION = 0x100;
114LSL.CHANGED_TELEPORT = 0x200;
115LSL.CHANGED_REGION_START = 0x400;
116LSL.CHANGED_MEDIA = 0x800;
117
118LSL.DEBUG_CHANNEL = 2147483647;
119LSL.PUBLIC_CHANNEL = 0;
120
121LSL.INVENTORY_ALL = -1;
122LSL.INVENTORY_NONE = -1;
123LSL.INVENTORY_TEXTURE = 0;
124LSL.INVENTORY_SOUND = 1;
125LSL.INVENTORY_LANDMARK = 3;
126LSL.INVENTORY_CLOTHING = 5;
127LSL.INVENTORY_OBJECT = 6;
128LSL.INVENTORY_NOTECARD = 7;
129LSL.INVENTORY_SCRIPT = 10;
130LSL.INVENTORY_BODYPART = 13;
131LSL.INVENTORY_ANIMATION = 20;
132LSL.INVENTORY_GESTURE = 21;
133
134LSL.ALL_SIDES = -1;
135LSL.LINK_SET = -1;
136LSL.LINK_ROOT = 1;
137LSL.LINK_ALL_OTHERS = -2;
138LSL.LINK_ALL_CHILDREN = -3;
139LSL.LINK_THIS = -4;
140
141LSL.PERM_ALL = 0x7FFFFFFF;
142LSL.PERM_COPY = 0x00008000;
143LSL.PERM_MODIFY = 0x00004000;
144LSL.PERM_MOVE = 0x00080000;
145LSL.PERM_TRANSFER = 0x00002000;
146LSL.MASK_BASE = 0;
147LSL.MASK_OWNER = 1;
148LSL.MASK_GROUP = 2;
149LSL.MASK_EVERYONE = 3;
150LSL.MASK_NEXT = 4;
151LSL.PERMISSION_DEBIT = 0x0002;
152LSL.PERMISSION_TAKE_CONTROLS = 0x0004;
153LSL.PERMISSION_TRIGGER_ANIMATION = 0x0010;
154LSL.PERMISSION_ATTACH = 0x0020;
155LSL.PERMISSION_CHANGE_LINKS = 0x0080;
156LSL.PERMISSION_TRACK_CAMERA = 0x0400;
157LSL.PERMISSION_CONTRAL_CAMERA = 0x0800;
158
159LSL.AGENT = 0x01;
160LSL.ACTIVE = 0x02;
161LSL.PASSIVE = 0x04;
162LSL.SCRIPTED = 0x08;
163
164LSL.OBJECT_UNKNOWN_DETAIL = -1;
165
166LSL.PRIM_BUMP_SHINY = 19;
167LSL.PRIM_COLOR = 18;
168LSL.PRIM_FLEXIBLE = 21;
169LSL.PRIM_FULLBRIGHT = 20;
170LSL.PRIM_GLOW = 25;
171LSL.PRIM_MATERIAL = 2;
172LSL.PRIM_PHANTOM = 5;
173LSL.PRIM_PHYSICS = 3;
174LSL.PRIM_POINT_LIGHT = 23;
175LSL.PRIM_POSITION = 6;
176LSL.PRIM_ROTATION = 8;
177LSL.PRIM_SIZE = 7;
178LSL.PRIM_TEMP_ON_REZ = 4;
179LSL.PRIM_TYPE = 9;
180LSL.PRIM_TYPE_OLD = 1;
181LSL.PRIM_TEXGEN = 22;
182LSL.PRIM_TEXTURE = 17;
183LSL.PRIM_TEXT = 26;
184
185LSL.PRIM_BUMP_NONE = 0;
186LSL.PRIM_BUMP_BRIGHT = 1;
187LSL.PRIM_BUMP_DARK = 2;
188LSL.PRIM_BUMP_WOOD = 3;
189LSL.PRIM_BUMP_BARK = 4;
190LSL.PRIM_BUMP_BRICKS = 5;
191LSL.PRIM_BUMP_CHECKER = 6;
192LSL.PRIM_BUMP_CONCRETE = 7;
193LSL.PRIM_BUMP_TILE = 8;
194LSL.PRIM_BUMP_STONE = 9;
195LSL.PRIM_BUMP_DISKS = 10;
196LSL.PRIM_BUMP_GRAVEL = 11;
197LSL.PRIM_BUMP_BLOBS = 12;
198LSL.PRIM_BUMP_SIDING = 13;
199LSL.PRIM_BUMP_LARGETILE = 14;
200LSL.PRIM_BUMP_STUCCO = 15;
201LSL.PRIM_BUMP_SUCTION = 16;
202LSL.PRIM_BUMP_WEAVE = 17;
203
204LSL.PRIM_HOLE_DEFAULT = 0;
205LSL.PRIM_HOLE_CIRCLE = 16;
206LSL.PRIM_HOLE_SQUARE = 32;
207LSL.PRIM_HOLE_TRIANGLE = 48;
208
209LSL.PRIM_MATERIAL_STONE = 0;
210LSL.PRIM_MATERIAL_METAL = 1;
211LSL.PRIM_MATERIAL_GLASS = 2;
212LSL.PRIM_MATERIAL_WOOD = 3;
213LSL.PRIM_MATERIAL_FLESH = 4;
214LSL.PRIM_MATERIAL_PLASTIC = 5;
215LSL.PRIM_MATERIAL_RUBBER = 6;
216LSL.PRIM_MATERIAL_LIGHT = 7;
217
218LSL.PRIM_SCULPT_TYPE_SPHERE = 1;
219LSL.PRIM_SCULPT_TYPE_TORUS = 2;
220LSL.PRIM_SCULPT_TYPE_PLANE = 3;
221LSL.PRIM_SCULPT_TYPE_CYLINDER = 4;
222LSL.PRIM_SCULPT_TYPE_MESH = 5;
223LSL.PRIM_SCULPT_TYPE_MIMESH = 6;
224
225LSL.PRIM_SHINY_NONE = 0;
226LSL.PRIM_SHINY_LOW = 1;
227LSL.PRIM_SHINY_MEDIUM = 2;
228LSL.PRIM_SHINY_HIGH = 3;
229
230LSL.PRIM_TYPE_BOX = 0;
231LSL.PRIM_TYPE_CYLINDER = 1;
232LSL.PRIM_TYPE_PRISM = 2;
233LSL.PRIM_TYPE_SPHERE = 3;
234LSL.PRIM_TYPE_TORUS = 4;
235LSL.PRIM_TYPE_TUBE = 5;
236LSL.PRIM_TYPE_RING = 6;
237LSL.PRIM_TYPE_SCULPT = 7;
238
239LSL_RC_GET_NORMAL = 1;
240LSL_RC_GET_ROOT_KEY = 2;
241LSL_RC_GET_LINK_NUM = 4;
242LSL_RC_REJECT_AGENTS = 1;
243LSL_RC_REJECT_PHYSICAL = 2;
244LSL_RC_REJECT_NONPHYSICAL = 4;
245LSL_RC_REJECT_LAND = 8;
246LSL.RC_REJECT_TYPES = 0;
247LSL.RC_DETECT_PHANTOM = 1;
248LSL.RC_DATA_FLAGS = 2;
249LSL.RC_MAX_HITS = 3;
250LSL.RCERR_UNKNOWN = -1;
251LSL.RCERR_SIM_PERF_LOW = -2;
252LSL.RCERR_CAST_TIME_EXCEEDED = -3;
253
254LSL.STATUS_OK = 0;
255LSL.STATUS_MALFORMED_PARAMS = 1000;
256LSL.STATUS_TYPE_MISMATCH = 1001;
257LSL.STATUS_BOUNDS_ERROR = 1002;
258LSL.STATUS_NOT_FOUND = 1003;
259LSL.STATUS_NOT_SUPPORTED = 1004;
260LSL.STATUS_INTERNAL_ERROR = 1999;
261LSL.STATUS_WHITELIST_FAILED = 2001;
262
263LSL.STRING_TRIM = 3;
264LSL.STRING_TRIM_HEAD = 1;
265LSL.STRING_TRIM_TAIL = 2;
266
267LSL.TRUE = 1;
268LSL.FALSE = 0;
269
270LSL.TYPE_INTEGER = 1;
271LSL.TYPE_FLOAT = 2;
272LSL.TYPE_STRING = 3;
273LSL.TYPE_KEY = 4;
274LSL.TYPE_VECTOR = 5;
275LSL.TYPE_ROTATION = 6;
276LSL.TYPE_INVALID = 0;
277
278LSL.NULL_KEY = "00000000-0000-0000-0000-000000000000";
279LSL.EOF = "\n\n\n";
280
281LSL.ZERO_ROTATION = {x=0.0, y=0.0, z=0.0, s=1.0};
282LSL.ZERO_VECTOR = {x=0.0, y=0.0, z=0.0};
283
284-- TODO - Temporary dummy variables to got vector and rotation thingies to work for now.
285
286LSL.s = 1.0;
287LSL.x = 0.0;
288LSL.y = 0.0;
289LSL.z = 0.0;
290
291-- ll*() function stubs.
292 263
264-- LSL communications functions
265 llDialog = newFunc("", "key avatar", "string caption", "list arseBackwardsMenu", "integer channel"),
266 llListen = newFunc("integer", "integer channel", "string name", "key id", "string msg"),
267 llListenRemove = newFunc("", "integer handle"),
268 llOwnerSay = newFunc("", "string text"),
269 llSay = newFunc("", "integer channel", "string text"),
270 llShout = newFunc("", "integer channel", "string text"),
271 llWhisper = newFunc("", "integer channel", "string text"),
272 llMessageLinked = newFunc("", "integer link", "integer num", "string text", "key aKey"),
293 273
294-- LSL avatar functions 274-- LSL inventory functions.
275 llGetInventoryName = newFunc("string", "integer Type", "integer index"),
276 llGetInventoryNumber = newFunc("integer", "integer Type"),
277 llGetInventoryType = newFunc("integer", "string name"),
278 llGetNotecardLine = newFunc("key", "string name", "integer index"),
279 llRezAtRoot = newFunc("", "string name", "vector position", "vector velocity", "rotation rot", "integer channel"),
280 llRezObject = newFunc("", "string name", "vector position", "vector velocity", "rotation rot", "integer channel"),
295 281
296function --[[key]] LSL.llAvatarOnSitTarget() return LSL.NULL_KEY end; 282-- LSL list functions.
297function --[[list]] LSL.llGetAnimationList(--[[key]] id) return {} end; 283 llCSV2List = newFunc("list", "string text"),
298function --[[integer]] LSL.llGetPermissions() return 0 end; 284 llDeleteSubList = newFunc("list", "list l", "integer start", "integer End"),
299function --[[key]] LSL.llGetPermissionsKey() return LSL.NULL_KEY end; 285 llDumpList2String = newFunc("string", "list l", "string separator"),
300function --[[string]] LSL.llKey2Name(--[[key]] avatar) return "" end; 286 llGetListLength = newFunc("integer", "list l"),
301function LSL.llRequestPermissions(--[[key]] avatar,--[[integer]] perms) end; 287 llList2CSV = newFunc("string", "list l"),
302function --[[integer]] LSL.llSameGroup(--[[key]] avatar) return 0 end; 288 llList2Float = newFunc("float", "list l", "integer index"),
303function LSL.llStartAnimation(--[[string]] anim) end; 289 llList2Integer = newFunc("integer", "list l", "integer index"),
304function LSL.llStopAnimation(--[[string]] anim) end; 290 llList2Key = newFunc("key", "list l", "integer index"),
305function LSL.llUnSit(--[[key]] avatar) end; 291 llList2List = newFunc("list", "list l", "integer start", "integer End"),
292 llList2String = newFunc("string", "list l", "integer index"),
293 llList2Rotation = newFunc("rotation", "list l", "integer index"),
294 llList2Vector = newFunc("vector", "list l", "integer index"),
295 llListFindList = newFunc("integer", "list l", "list l1"),
296 llListInsertList = newFunc("list", "list l", "list l1", "integer index"),
297 llListReplaceList = newFunc("list", "list l", "list part", "integer start", "integer End"),
298 llListSort = newFunc("list", "list l", "integer stride", "integer ascending"),
299 llParseString2List = newFunc("list", "string In", "list l", "list l1"),
300 llParseStringKeepNulls = newFunc("list", "string In", "list l", "list l1"),
306 301
302-- LSL math functions
303 llEuler2Rot = newFunc("rotation", "vector vec"),
304 llFrand = newFunc("float", "float max"),
305 llPow = newFunc("float", "float number", "float places"),
306 llRot2Euler = newFunc("vector", "rotation rot"),
307 llRound = newFunc("integer", "float number"),
307 308
308-- LSL collision / detect / sensor functions 309-- LSL media functions
310 llPlaySound = newFunc("", "string name", "float volume"),
309 311
310function --[[key]] LSL.llDetectedGroup(--[[integer]] index) return LSL.NULL_KEY end; 312-- LSL object / prim functions
311function --[[key]] LSL.llDetectedKey(--[[integer]] index) return LSL.NULL_KEY end; 313 llDie = newFunc(""),
314 llGetKey = newFunc("key"),
315 llGetLinkNumber = newFunc("integer"),
316 llGetObjectDesc = newFunc("string"),
317 llGetObjectName = newFunc("string"),
318 llGetOwner = newFunc("key"),
319 llSetObjectDesc = newFunc("", "string text"),
320 llSetObjectName = newFunc("", "string text"),
321 llSetPrimitiveParams = newFunc("", "list params"),
322 llSetSitText = newFunc("", "string text"),
323 llSetText = newFunc("", "string text", "vector colour", "float alpha"),
324 llSitTarget = newFunc("", "vector pos", "rotation rot"),
312 325
326-- LSL rotation / scaling / translation functions
327 llGetPos = newFunc("vector", ""),
328 llGetRot = newFunc("rotation", ""),
329 llSetPos = newFunc("", "vector pos"),
330 llSetRot = newFunc("", "rotation rot"),
331 llSetScale = newFunc("", "vector scale"),
313 332
314-- LSL communications functions 333-- LSL script functions
334 llGetFreeMemory = newFunc("integer", ""),
335 llGetScriptName = newFunc("string", ""),
336 llResetOtherScript = newFunc("", "string name"),
337 llResetScript = newFunc("", ""),
338 llSetScriptState = newFunc("", "string name", "integer running"),
315 339
316function LSL.llDialog(--[[key]] avatar, --[[string]] caption, --[[list]] arseBackwardsMenu,--[[integer]] channel) end; 340-- LSL string functions
317function --[[integer]] LSL.llListen(--[[integer]] channel, --[[string]] name, --[[key]] id, --[[string]] msg) return 0 end; 341 llGetSubString = newFunc("string", "string text", "integer start", "integer End"),
318function LSL.llListenRemove(--[[integer]] handle) end; 342 llStringLength = newFunc("integer", "string text"),
319function LSL.llOwnerSay(--[[string]] text) msg("Owner say: " .. text); end; 343 llStringTrim = newFunc("string", "string text", "integer type"),
320function LSL.llSay(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " say: " .. text); end; 344 llSubStringIndex = newFunc("integer", "string text", "string sub"),
321function LSL.llShout(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " shout: " .. text); end;
322function LSL.llWhisper(--[[integer]] channel, --[[string]] text) msg("Channel " .. channel .. " whisper: " .. text); end;
323 345
324function LSL.llMessageLinked(--[[integer]] link,--[[integer]] num, --[[string]] text, --[[key]] aKey) end; 346-- LSL texture functions
347 llGetAlpha = newFunc("float", "integer side"),
348 llSetAlpha = newFunc("", "float alpha", "integer side"),
349 llSetColor = newFunc("", "vector colour", "integer side"),
325 350
351-- LSL time functions
352 llGetTime = newFunc("float", ""),
353 llResetTime = newFunc("", ""),
354 llSetTimerEvent = newFunc("", "float seconds"),
355 llSleep = newFunc("", "float seconds"),
356}
326 357
327-- LSL inventory functions.
328 358
329function --[[string]] LSL.llGetInventoryName(--[[integer]] tyPe,--[[integer]] index) return "" end; 359-- TODO - fake this for now.
330function --[[integer]] LSL.llGetInventoryNumber(--[[integer]] tyPe) return 0 end;
331function --[[integer]] LSL.llGetInventoryType(--[[string]] name) return LSL.INVENTORY_SCRIPT end; 360function --[[integer]] LSL.llGetInventoryType(--[[string]] name) return LSL.INVENTORY_SCRIPT end;
332function --[[key]] LSL.llGetNotecardLine(--[[string]] name,--[[integer]] index) return LSL.NULL_KEY end;
333function LSL.llRezAtRoot(--[[string]] name, --[[vector]] position, --[[vector]] velocity, --[[rotation]] rot,--[[integer]] channel) end;
334function LSL.llRezObject(--[[string]] name, --[[vector]] position, --[[vector]] velocity, --[[rotation]] rot,--[[integer]] channel) end;
335 361
336 362
337-- LSL list functions. 363-- LSL list functions.
@@ -483,78 +509,6 @@ function --[[list]] LSL.llParseString2List(--[[string]] In, --[[list]] l, --[[li
483function --[[list]] LSL.llParseStringKeepNulls(--[[string]] In, --[[list]] l, --[[list]] l1) return {} end; 509function --[[list]] LSL.llParseStringKeepNulls(--[[string]] In, --[[list]] l, --[[list]] l1) return {} end;
484 510
485 511
486-- LSL math functions
487
488function --[[rotation]] LSL.llEuler2Rot(--[[vector]] vec) return LSL.ZERO_ROTATION end;
489function --[[float]] LSL.llFrand(--[[float]] max) return 0.0 end;
490function --[[float]] LSL.llPow(--[[float]] number,--[[float]] places) return 0.0 end;
491function --[[vector]] LSL.llRot2Euler(--[[rotation]] rot) return LSL.ZERO_VECTOR end;
492function --[[integer]] LSL.llRound(--[[float]] number) return 0 end;
493
494
495-- LSL media functions
496
497function LSL.llPlaySound(--[[string]] name,--[[float]] volume) end;
498
499
500-- LSL object / prim functions
501
502function LSL.llDie() end;
503function --[[key]] LSL.llGetKey() return LSL.NULL_KEY end;
504function --[[integer]] LSL.llGetLinkNumber() return 0 end;
505function --[[string]] LSL.llGetObjectDesc() return "" end;
506function --[[string]] LSL.llGetObjectName() return "" end;
507function --[[key]] LSL.llGetOwner() return LSL.NULL_KEY end;
508function LSL.llSetObjectDesc(--[[string]] text) end;
509function LSL.llSetObjectName(--[[string]] text) end;
510function LSL.llSetPrimitiveParams(--[[list]] params) end;
511function LSL.llSetSitText(--[[string]] text) end;
512function LSL.llSetText(--[[string]] text, --[[vector]] colour,--[[float]] alpha) end;
513function LSL.llSitTarget(--[[vector]] pos, --[[rotation]] rot) end;
514
515
516-- LSL rotation / scaling / translation functions
517
518function --[[vector]] LSL.llGetPos() return LSL.ZERO_VECTOR end;
519function --[[rotation]] LSL.llGetRot() return LSL.ZERO_ROTATION end;
520function LSL.llSetPos(--[[vector]] pos) end;
521function LSL.llSetRot(--[[rotation]] rot) end;
522function LSL.llSetScale(--[[vector]] scale) end;
523
524
525-- LSL script functions
526
527function --[[integer]] LSL.llGetFreeMemory() return 0 end;
528function --[[string]] LSL.llGetScriptName() return "" end;
529function LSL.llResetOtherScript(--[[string]] name) msg("llResetOtherScript(" .. name .. ")") end;
530function LSL.llResetScript() end;
531function LSL.llSetScriptState(--[[string]] name,--[[integer]] running) msg("llSetScriptState(" .. name .. "," .. running .. ")") end;
532
533
534-- LSL string functions
535
536function --[[string]] LSL.llGetSubString(--[[string]] text,--[[integer]] start,--[[integer]] eNd) return "" end;
537function --[[integer]] LSL.llStringLength(--[[string]] text) return 0 end;
538function --[[string]] LSL.llStringTrim(--[[string]] text,--[[integer]] tyPe) return "" end;
539function --[[integer]] LSL.llSubStringIndex(--[[string]] text, --[[string]] sub) return 0 end;
540
541
542-- LSL texture functions
543
544function --[[float]] LSL.llGetAlpha(--[[integer]] side) return 0.0 end;
545function LSL.llSetAlpha(--[[float]] alpha,--[[integer]] side) end;
546function LSL.llSetColor(--[[vector]] colour,--[[integer]] side) end;
547
548
549-- LSL time functions
550
551function --[[float]] LSL.llGetTime() return 0.0 end;
552function LSL.llResetTime() end;
553function LSL.llSetTimerEvent(--[[float]] seconds) end;
554function LSL.llSleep(--[[float]] seconds) msg("llSleep(" .. seconds .. ")") end;
555
556
557
558-- Crements stuff. 512-- Crements stuff.
559 513
560function LSL.preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end; 514function LSL.preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end;
@@ -682,4 +636,95 @@ function LSL.vectorTypecast(x)
682end 636end
683 637
684 638
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()
677 for i,v in ipairs(constants) do
678 local value = LSL[v.name]
679
680 print(v.Type .. " " .. v.name .. " = " .. value2string(value, v.Type) .. ";")
681 end
682
683 for k in pairs(functions) do
684 local v = functions[k]
685 if nil == v.args then
686 print(v.Type .. " " .. k .. "(){}")
687 else
688 print(v.Type .. " " .. k .. "(" .. args2string(false, unpack(v.args)) .. "){}")
689 end
690 end
691 LSL.EOF = "\n\n\n" -- Fix this up now.
692end
693
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
685return LSL; 730return LSL;