Skip to content

Commit e018cdb

Browse files
authored
Merge def changes from SLua branch (#15)
Merges some changes to the definitions that've been done on the server SLua branch
1 parent cf6df98 commit e018cdb

File tree

2 files changed

+113
-34
lines changed

2 files changed

+113
-34
lines changed

gen_definitions.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
import yaml
2020

2121

22+
def quoted_presenter(dumper, data):
23+
return dumper.represent_scalar("tag:yaml.org,2002:str", str(data), style='"')
24+
25+
26+
yaml.add_representer(uuid.UUID, quoted_presenter)
27+
28+
2229
class StringEnum(str, enum.Enum):
2330
def __str__(self):
2431
return self.value
@@ -1892,7 +1899,7 @@ def gen_lua_registrations(definitions: LSLDefinitions, pure_only: bool, output_p
18921899
const LSCRIPTType types[] = {%(arg_types)s};
18931900
// Convert the arguments to LLScriptLibData, throwing if not possible.
18941901
extract_lua_args(L, %(num_args)d, types, args);
1895-
return call_lib_func_lua(%(func_id)d, %(num_args)d, args, %(ret_type)s);
1902+
return call_lib_func_lua(L, %(func_id)d, %(num_args)d, args, %(ret_type)s);
18961903
}}
18971904
""" % {
18981905
"num_args": len(func.arguments),
@@ -1905,6 +1912,40 @@ def gen_lua_registrations(definitions: LSLDefinitions, pure_only: bool, output_p
19051912
_write_if_different(output_path, ",".join(bindings))
19061913

19071914

1915+
def _is_uuid(val: str) -> bool:
1916+
return bool(re.match(r"\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\Z", val))
1917+
1918+
1919+
def gen_lua_constant_definitions(definitions: LSLDefinitions, output_path: str) -> None:
1920+
"""Generate lambdas to handle incoming Lua calls that wrap ll*() lscript functions"""
1921+
# TODO: This would be much better as a constant folding pass in the compiler.
1922+
# there are a ton of constants and putting them all in the runtime environment
1923+
# is not free.
1924+
bindings = []
1925+
for const in definitions.constants.values():
1926+
binding = " "
1927+
if const.type == LSLType.KEY or _is_uuid(const.value):
1928+
# This is a bit weird. UUID constants don't exist in LSL, but they do in Lua.
1929+
# Make these an actual UUID if we can to make comparison easier.
1930+
binding += f'luaSL_pushuuidstring(L, "{_to_c_str(const.value)}");'
1931+
elif const.type == LSLType.STRING:
1932+
binding += f'lua_pushstring(L, "{_to_c_str(const.value)}");'
1933+
elif const.type == LSLType.INTEGER:
1934+
binding += f"luaSL_pushnativeinteger(L, {const.value});"
1935+
elif const.type == LSLType.FLOAT:
1936+
binding += f"lua_pushnumber(L, {const.value});"
1937+
elif const.type == LSLType.VECTOR:
1938+
binding += f"lua_pushvector(L, {const.value[1:-1]});"
1939+
elif const.type == LSLType.ROTATION:
1940+
binding += f"luaSL_pushquaternion(L, {const.value[1:-1]});"
1941+
else:
1942+
raise ValueError(f"Can't generate Lua constant for {const.name} of type {const.type}")
1943+
1944+
binding += f'\n lua_setglobal(L, "{_to_c_str(const.name)}");\n'
1945+
bindings.append(binding)
1946+
_write_if_different(output_path, "\n".join(bindings))
1947+
1948+
19081949
def gen_lscript_library_bind_pure(definitions: LSLDefinitions, output_path: str) -> None:
19091950
"""
19101951
Bind lscript functions for all pure functions, useful for test harnesses
@@ -1922,13 +1963,6 @@ def gen_lscript_library_bind_pure(definitions: LSLDefinitions, output_path: str)
19221963
_write_if_different(output_path, "".join(assign_execs))
19231964

19241965

1925-
def quoted_presenter(dumper, data):
1926-
return dumper.represent_scalar("tag:yaml.org,2002:str", str(data), style='"')
1927-
1928-
1929-
yaml.add_representer(uuid.UUID, quoted_presenter)
1930-
1931-
19321966
def main():
19331967
argparser = argparse.ArgumentParser(description="Process LSL definitions.")
19341968
argparser.add_argument("definitions", help="Path to the LSL definition yaml")
@@ -2012,6 +2046,10 @@ def main():
20122046
func=lambda args, defs: gen_lua_registrations(defs, bool(args.pure_only), args.output_path)
20132047
)
20142048

2049+
sub = subparsers.add_parser("gen_lua_constant_definitions")
2050+
sub.add_argument("output_path")
2051+
sub.set_defaults(func=lambda args, defs: gen_lua_constant_definitions(defs, args.output_path))
2052+
20152053
args = argparser.parse_args()
20162054

20172055
parser = LSLDefinitionParser()

lsl_definitions.yaml

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,35 +2287,47 @@ constants:
22872287
type: integer
22882288
value: 24
22892289
PRIM_CLICK_ACTION:
2290-
tooltip: ''
2290+
tooltip: '[PRIM_CLICK_ACTION, integer CLICK_ACTION_*]'
22912291
type: integer
22922292
value: 43
22932293
PRIM_COLLISION_SOUND:
22942294
tooltip: Collision sound uuid and volume for this prim
22952295
type: integer
22962296
value: 53
22972297
PRIM_COLOR:
2298-
tooltip: ''
2298+
tooltip: '[PRIM_COLOR, integer face, vector color, float alpha]
2299+
2300+
integer face – face number or ALL_SIDES
2301+
vector color – color in RGB <R, G, B> (<0.0, 0.0, 0.0> = black, <1.0, 1.0, 1.0> = white)
2302+
float alpha – from 0.0 (clear) to 1.0 (solid) (0.0 <= alpha <= 1.0)'
22992303
type: integer
23002304
value: 18
23012305
PRIM_DAMAGE:
23022306
tooltip: Damage and damage type assigned to this prim.
23032307
type: integer
23042308
value: 51
23052309
PRIM_DESC:
2306-
tooltip: ''
2310+
tooltip: '[PRIM_DESC, string description]'
23072311
type: integer
23082312
value: 28
23092313
PRIM_FLEXIBLE:
2310-
tooltip: ''
2314+
tooltip: '[ PRIM_FLEXIBLE, integer boolean, integer softness, float gravity, float friction, float wind, float tension, vector force ]
2315+
+
2316+
+integer boolean – TRUE enables, FALSE disables
2317+
+integer softness – ranges from 0 to 3
2318+
+float gravity – ranges from -10.0 to 10.0
2319+
+float friction – ranges from 0.0 to 10.0
2320+
+float wind – ranges from 0.0 to 10.0
2321+
+float tension – ranges from 0.0 to 10.0
2322+
+vector force'
23112323
type: integer
23122324
value: 21
23132325
PRIM_FULLBRIGHT:
2314-
tooltip: ''
2326+
tooltip: '[ PRIM_FULLBRIGHT, integer face, integer boolean ]'
23152327
type: integer
23162328
value: 20
23172329
PRIM_GLOW:
2318-
tooltip: PRIM_GLOW is used to get or set the glow status of the face.
2330+
tooltip: 'PRIM_GLOW is used to get or set the glow status of the face.\n[ PRIM_GLOW, integer face, float intensity ]'
23192331
type: integer
23202332
value: 25
23212333
PRIM_GLTF_ALPHA_MODE_BLEND:
@@ -2374,11 +2386,13 @@ constants:
23742386
type: integer
23752387
value: '0x30'
23762388
PRIM_LINK_TARGET:
2377-
tooltip: ''
2389+
tooltip: '[ PRIM_LINK_TARGET, integer link_target ]
2390+
2391+
Used to get or set multiple links with a single PrimParameters call.'
23782392
type: integer
23792393
value: 34
23802394
PRIM_MATERIAL:
2381-
tooltip: ''
2395+
tooltip: '[ PRIM_MATERIAL, integer PRIM_MATERIAL_* ]'
23822396
type: integer
23832397
value: 2
23842398
PRIM_MATERIAL_DENSITY:
@@ -2555,7 +2569,7 @@ constants:
25552569
type: integer
25562570
value: 9
25572571
PRIM_NAME:
2558-
tooltip: ''
2572+
tooltip: '[ PRIM_NAME, string name ]'
25592573
type: integer
25602574
value: 27
25612575
PRIM_NORMAL:
@@ -2564,15 +2578,19 @@ constants:
25642578
type: integer
25652579
value: 37
25662580
PRIM_OMEGA:
2567-
tooltip: ''
2581+
tooltip: '[ PRIM_OMEGA, vector axis, float spinrate, float gain ]
2582+
2583+
vector axis – arbitrary axis to rotate the object around
2584+
float spinrate – rate of rotation in radians per second
2585+
float gain – also modulates the final spinrate and disables the rotation behavior if zero'
25682586
type: integer
25692587
value: 32
25702588
PRIM_PHANTOM:
2571-
tooltip: ''
2589+
tooltip: '[ PRIM_PHANTOM, integer boolean ]'
25722590
type: integer
25732591
value: 5
25742592
PRIM_PHYSICS:
2575-
tooltip: ''
2593+
tooltip: '[ PRIM_PHYSICS, integer boolean ]'
25762594
type: integer
25772595
value: 3
25782596
PRIM_PHYSICS_SHAPE_CONVEX:
@@ -2596,19 +2614,29 @@ constants:
25962614
type: integer
25972615
value: 30
25982616
PRIM_POINT_LIGHT:
2599-
tooltip: ''
2617+
tooltip: '[ PRIM_POINT_LIGHT, integer boolean, vector linear_color, float intensity, float radius, float falloff ]
2618+
2619+
integer boolean – TRUE enables, FALSE disables
2620+
vector linear_color – linear color in RGB <R, G, B&> (<0.0, 0.0, 0.0> = black, <1.0, 1.0, 1.0> = white)
2621+
float intensity – ranges from 0.0 to 1.0
2622+
float radius – ranges from 0.1 to 20.0
2623+
float falloff – ranges from 0.01 to 2.0'
26002624
type: integer
26012625
value: 23
26022626
PRIM_POSITION:
2603-
tooltip: ''
2627+
tooltip: '[ PRIM_POSITION, vector position ]
2628+
2629+
vector position – position in region or local coordinates depending upon the situation'
26042630
type: integer
26052631
value: 6
26062632
PRIM_POS_LOCAL:
2607-
tooltip: ''
2633+
tooltip: 'PRIM_POS_LOCAL, vector position ]
2634+
2635+
vector position - position in local coordinates'
26082636
type: integer
26092637
value: 33
26102638
PRIM_PROJECTOR:
2611-
tooltip: ''
2639+
tooltip: '[ PRIM_PROJECTOR, string texture, float fov, float focus, float ambiance ]'
26122640
type: integer
26132641
value: 42
26142642
PRIM_REFLECTION_PROBE:
@@ -2636,15 +2664,15 @@ constants:
26362664
type: integer
26372665
value: 4
26382666
PRIM_RENDER_MATERIAL:
2639-
tooltip: ''
2667+
tooltip: '[ PRIM_RENDER_MATERIAL, integer face, string material ]'
26402668
type: integer
26412669
value: 49
26422670
PRIM_ROTATION:
2643-
tooltip: ''
2671+
tooltip: '[ PRIM_ROT_LOCAL, rotation global_rot ]'
26442672
type: integer
26452673
value: 8
26462674
PRIM_ROT_LOCAL:
2647-
tooltip: ''
2675+
tooltip: '[ PRIM_ROT_LOCAL, rotation local_rot ]'
26482676
type: integer
26492677
value: 29
26502678
PRIM_SCRIPTED_SIT_ONLY:
@@ -2709,15 +2737,15 @@ constants:
27092737
type: integer
27102738
value: 50
27112739
PRIM_SIT_TARGET:
2712-
tooltip: ''
2740+
tooltip: '[ PRIM_SIT_TARGET, integer boolean, vector offset, rotation rot ]'
27132741
type: integer
27142742
value: 41
27152743
PRIM_SIZE:
2716-
tooltip: ''
2744+
tooltip: '[ PRIM_SIZE, vector size ]'
27172745
type: integer
27182746
value: 7
27192747
PRIM_SLICE:
2720-
tooltip: ''
2748+
tooltip: '[ PRIM_SLICE, vector slice ]'
27212749
type: integer
27222750
value: 35
27232751
PRIM_SPECULAR:
@@ -2731,7 +2759,7 @@ constants:
27312759
type: integer
27322760
value: 4
27332761
PRIM_TEXGEN:
2734-
tooltip: ''
2762+
tooltip: '[ PRIM_TEXGEN, integer face, PRIM_TEXGEN_* ]'
27352763
type: integer
27362764
value: 22
27372765
PRIM_TEXGEN_DEFAULT:
@@ -2743,11 +2771,11 @@ constants:
27432771
type: integer
27442772
value: 1
27452773
PRIM_TEXT:
2746-
tooltip: ''
2774+
tooltip: '[ PRIM_TEXT, string text, vector color, float alpha ]'
27472775
type: integer
27482776
value: 26
27492777
PRIM_TEXTURE:
2750-
tooltip: ''
2778+
tooltip: '[ PRIM_TEXTURE, integer face, string texture, vector repeats, vector offsets, float rotation_in_radians ]'
27512779
type: integer
27522780
value: 17
27532781
PRIM_TYPE:
@@ -5437,6 +5465,7 @@ functions:
54375465
energy: 10.0
54385466
func-id: 39
54395467
return: integer
5468+
bool_semantics: true
54405469
sleep: 0.0
54415470
tooltip: Returns TRUE if detected object or agent Number has the same user group
54425471
active as this object.\nIt will return FALSE if the object or agent is in the
@@ -7231,6 +7260,7 @@ functions:
72317260
type: integer
72327261
energy: 10.0
72337262
func-id: 46
7263+
bool_semantics: true
72347264
return: integer
72357265
sleep: 0.0
72367266
tooltip: Returns boolean value of the specified status (e.g. STATUS_PHANTOM) of
@@ -7622,6 +7652,7 @@ functions:
76227652
tooltip: ''
76237653
type: string
76247654
- Position:
7655+
index_semantics: true
76257656
tooltip: ''
76267657
type: integer
76277658
- SourceVariable:
@@ -7683,6 +7714,7 @@ functions:
76837714
energy: 10.0
76847715
func-id: 559
76857716
return: integer
7717+
bool_semantics: true
76867718
sleep: 0.0
76877719
tooltip: Checks the face for a PBR render material.
76887720
llJson2List:
@@ -7997,6 +8029,7 @@ functions:
79978029
- start:
79988030
tooltip: First entry to return. 0 for start of list.
79998031
type: integer
8032+
index_semantics: true
80008033
- count:
80018034
tooltip: Number of entries to return. Less than 1 for all keys.
80028035
type: integer
@@ -8011,6 +8044,7 @@ functions:
80118044
- start:
80128045
tooltip: First entry to return. 0 for start of list.
80138046
type: integer
8047+
index_semantics: true
80148048
- count:
80158049
tooltip: Number of entries to return. Less than 1 for all keys.
80168050
type: integer
@@ -8363,6 +8397,7 @@ functions:
83638397
tooltip: ''
83648398
type: list
83658399
- Position:
8400+
index_semantics: true
83668401
tooltip: ''
83678402
type: integer
83688403
energy: 10.0
@@ -8401,9 +8436,11 @@ functions:
84018436
- Start:
84028437
tooltip: ''
84038438
type: integer
8439+
index_semantics: true
84048440
- End:
84058441
tooltip: ''
84068442
type: integer
8443+
index_semantics: true
84078444
energy: 10.0
84088445
func-id: 296
84098446
native: true
@@ -8445,6 +8482,7 @@ functions:
84458482
- Sortkey:
84468483
tooltip: The zero based element within the stride to use as the sort key
84478484
type: integer
8485+
index_semantics: true
84488486
- Ascending:
84498487
tooltip: Boolean. TRUE = result in ascending order, FALSE = result in descending
84508488
order.
@@ -8799,6 +8837,7 @@ functions:
87998837
energy: 10.0
88008838
func-id: 393
88018839
return: integer
8840+
bool_semantics: true
88028841
sleep: 0.0
88038842
tooltip: Adds or removes agents from the estate's agent access or ban lists, or
88048843
groups to the estate's group access list. Action is one of the ESTATE_ACCESS_ALLOWED_*
@@ -8998,9 +9037,9 @@ functions:
89989037
tooltip: The string to convert to Unicode.
89999038
type: string
90009039
- index:
9001-
# note: This does _not_ have index semantics, this is a Unicode codepoint!
90029040
tooltip: Index of character to convert to unicode.
90039041
type: integer
9042+
index_semantics: true
90049043
energy: 10.0
90059044
func-id: 527
90069045
pure: true
@@ -10036,6 +10075,7 @@ functions:
1003610075
energy: 10.0
1003710076
func-id: 592
1003810077
return: integer
10078+
bool_semantics: true
1003910079
sleep: 0.0
1004010080
tooltip: Attempts to resize the entire object by ScalingFactor, maintaining the
1004110081
size-position ratios of the prims.\n\nResizing is subject to prim scale limits
@@ -10855,6 +10895,7 @@ functions:
1085510895
energy: 10.0
1085610896
func-id: 397
1085710897
return: integer
10898+
bool_semantics: true
1085810899
sleep: 0.0
1085910900
tooltip: Attempts to move the object so that the root prim is within 0.1m of Position.\nReturns
1086010901
an integer boolean, TRUE if the object is successfully placed within 0.1 m of

0 commit comments

Comments
 (0)