diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 5dab399..4644399 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -44,13 +44,24 @@ jobs: python -m pip install --upgrade pip pip install . - - name: Check if syntax generation produces valid output + - name: Check if LSL syntax generation produces valid output run: | # Generate syntax to a temporary file to verify it's valid - gen-lsl-definitions ./lsl_definitions.yaml syntax /tmp/syntax_output.llsd + gen-lsl-definitions ./lsl_definitions.yaml syntax /tmp/lsl_syntax_output.llsd # Check that the output file was created and is not empty - if [ ! -s /tmp/syntax_output.llsd ]; then - echo "Error: Syntax generation produced empty output" + if [ ! -s /tmp/lsl_syntax_output.llsd ]; then + echo "Error: LSL Syntax generation produced empty output" exit 1 fi - echo "✓ Syntax generation successful and produced non-empty output" + echo "✓ LSL Syntax generation successful and produced non-empty output" + + - name: Check if SLua syntax generation produces valid output + run: | + # Generate syntax to a temporary file to verify it's valid + gen-lsl-definitions ./lsl_definitions.yaml slua_syntax ./slua_definitions.yaml /tmp/slua_syntax_output.llsd + # Check that the output file was created and is not empty + if [ ! -s /tmp/slua_syntax_output.llsd ]; then + echo "Error: SLua Syntax generation produced empty output" + exit 1 + fi + echo "✓ SLua Syntax generation successful and produced non-empty output" diff --git a/README.md b/README.md index c773419..29fa35f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # LSL Definitions -This repository contains the canonical `lsl_definitions.yaml` file that serves as the authoritative source of truth for Second Life's LSL (Linden Scripting Language) library. +This repository contains the canonical `lsl_definitions.yaml` and `slua_definitions.yaml` files that serve as the authoritative source of truth for Second Life's LSL (Linden Scripting Language) and SLua (Server Lua) libraries. ## Purpose diff --git a/gen_definitions.py b/gen_definitions.py index 35c03b4..fc6c527 100644 --- a/gen_definitions.py +++ b/gen_definitions.py @@ -3,7 +3,6 @@ # deciding that this script is Python 2. It is not. import ast -import ctypes import dataclasses import enum import itertools @@ -13,7 +12,7 @@ import argparse import uuid import os -from typing import Iterable, NamedTuple, Dict, List, Set, Sequence, TypeVar, Union, Any +from typing import Iterable, NamedTuple, Dict, List, Optional, Set, Sequence, TypeVar, Union, Any import llsd # noqa import yaml @@ -54,6 +53,7 @@ class LSLTypeMeta(NamedTuple): library_abbr: str cs_name: str mono_bind_name: str + slua_name: str _CS_TYPE_MODULE = "[ScriptTypes]LindenLab.SecondLife" @@ -68,6 +68,7 @@ class LSLTypeMeta(NamedTuple): library_abbr="", cs_name="void", mono_bind_name="void", + slua_name="()", ), LSLType.INTEGER: LSLTypeMeta( cil_name="int32", @@ -77,6 +78,7 @@ class LSLTypeMeta(NamedTuple): library_abbr="i", cs_name="int", mono_bind_name="S32", + slua_name="number", ), LSLType.FLOAT: LSLTypeMeta( cil_name="float", @@ -86,6 +88,7 @@ class LSLTypeMeta(NamedTuple): library_abbr="f", cs_name="float", mono_bind_name="F32", + slua_name="number", ), LSLType.STRING: LSLTypeMeta( cil_name="string", @@ -95,6 +98,7 @@ class LSLTypeMeta(NamedTuple): library_abbr="s", cs_name="string", mono_bind_name="MonoStringType", + slua_name="string", ), LSLType.KEY: LSLTypeMeta( cil_name=f"valuetype {_CS_TYPE_MODULE}.Key", @@ -104,6 +108,7 @@ class LSLTypeMeta(NamedTuple): library_abbr="k", cs_name="Key", mono_bind_name="MonoKeyType", + slua_name="uuid", ), LSLType.VECTOR: LSLTypeMeta( cil_name=f"class {_CS_TYPE_MODULE}.Vector", @@ -113,6 +118,7 @@ class LSLTypeMeta(NamedTuple): library_abbr="v", cs_name="Vector", mono_bind_name="MonoVectorType", + slua_name="vector", ), LSLType.ROTATION: LSLTypeMeta( cil_name=f"class {_CS_TYPE_MODULE}.Quaternion", @@ -122,6 +128,7 @@ class LSLTypeMeta(NamedTuple): library_abbr="q", cs_name="Quaternion", mono_bind_name="MonoQuaternionType", + slua_name="quaternion", ), LSLType.LIST: LSLTypeMeta( cil_name="class [mscorlib]System.Collections.ArrayList", @@ -131,6 +138,7 @@ class LSLTypeMeta(NamedTuple): library_abbr="l", cs_name="ArrayList", mono_bind_name="MonoListType", + slua_name="list", ), } @@ -138,6 +146,8 @@ class LSLTypeMeta(NamedTuple): class LSLConstant(NamedTuple): name: str type: LSLType + slua_type: Optional[str] + slua_removed: bool value: str tooltip: str deprecated: bool @@ -147,22 +157,46 @@ class LSLConstant(NamedTuple): def to_dict(self) -> dict: return _remove_worthless( { - "tooltip": self.tooltip, + "deprecated": self.deprecated, # Will always use a node, but that's fine for our purposes. # That's already the case for vector and hex int constants, anyway. - "value": _escape_python(self.value), + "tooltip": self.tooltip, "type": str(self.type), - "deprecated": self.deprecated, + "value": _escape_python(self.value), } ) + def to_slua_dict(self, slua: "SLuaDefinitionParser") -> dict: + try: + return _remove_worthless( + { + "deprecated": self.deprecated, + # Will always use a node, but that's fine for our purposes. + # That's already the case for vector and hex int constants, anyway. + "tooltip": self.tooltip, + "type": slua.validate_type(self.slua_type or self.type.meta.slua_name), + "value": _escape_python(self.value), + } + ) + except Exception as e: + raise ValueError(f"In constant {self.name}: {e}") from e + @dataclasses.dataclass class LSLArgument: name: str type: LSLType + slua_type: Optional[str] tooltip: str index_semantics: bool + bool_semantics: bool + + def compute_slua_type(self) -> str: + if self.slua_type is not None: + return self.slua_type + if self.bool_semantics and self.type == LSLType.INTEGER: + return "boolean | number" + return self.type.meta.slua_name @dataclasses.dataclass @@ -172,24 +206,58 @@ class LSLEvent: tooltip: str private: bool deprecated: bool + slua_deprecated: bool + slua_removed: bool + detected_semantics: bool def to_dict(self) -> dict: return _remove_worthless( { - "tooltip": self.tooltip, "deprecated": self.deprecated, "arguments": [ { a.name: { - "type": str(a.type), "tooltip": a.tooltip, + "type": str(a.type), } } for a in self.arguments ], + "tooltip": self.tooltip, } ) + def to_slua_dict(self, slua: "SLuaDefinitionParser") -> dict: + try: + if self.detected_semantics: + arguments = [ + { + "detected": { + "tooltip": "Array of detected events.", + "type": slua.validate_type("{DetectedEvent}"), + } + } + ] + else: + arguments = [ + { + a.name: { + "tooltip": a.tooltip, + "type": slua.validate_type(a.compute_slua_type()), + } + } + for a in self.arguments + ] + return _remove_worthless( + { + "deprecated": self.deprecated or self.slua_deprecated, + "arguments": arguments, + "tooltip": self.tooltip, + } + ) + except Exception as e: + raise ValueError(f"In event {self.name}: {e}") from e + @dataclasses.dataclass class LSLFunction: @@ -197,9 +265,12 @@ class LSLFunction: energy: float sleep: float ret_type: LSLType + slua_type: Optional[str] god_mode: bool index_semantics: bool bool_semantics: bool + detected_semantics: bool + type_arguments: List[str] arguments: List[LSLArgument] tooltip: str private: bool @@ -210,6 +281,9 @@ class LSLFunction: implementation to Agni and don't want people to use it yet. """ deprecated: bool + slua_deprecated: bool + slua_removed: bool + """Only exists in llcompat""" func_id: int pure: bool """ @@ -239,20 +313,20 @@ class LSLFunction: def to_dict(self, include_internal: bool = False) -> dict: return _remove_worthless( { - "deprecated": self.deprecated, - "god-mode": self.god_mode, - "energy": self.energy, - "sleep": self.sleep, - "return": str(self.ret_type), "arguments": [ { a.name: { - "type": str(a.type), "tooltip": a.tooltip, + "type": str(a.type), } } for a in self.arguments ], + "deprecated": self.deprecated, + "energy": self.energy, + "god-mode": self.god_mode, + "return": str(self.ret_type), + "sleep": self.sleep, "tooltip": self.tooltip, "bool_semantics": self.bool_semantics, **( @@ -269,6 +343,47 @@ def to_dict(self, include_internal: bool = False) -> dict: } ) + def compute_slua_name(self) -> str: + if self.name.startswith("ll"): + return self.name[:2] + "." + self.name[2:] + return self.name + + def compute_slua_type(self) -> str: + if self.slua_type is not None: + return self.slua_type + if self.bool_semantics and self.ret_type == LSLType.INTEGER: + return "boolean" + return self.ret_type.meta.slua_name + + def to_slua_dict(self, slua: "SLuaDefinitionParser") -> dict: + try: + known_types = slua.validate_type_params(self.type_arguments) + return _remove_worthless( + { + "type-arguments": self.type_arguments, + "arguments": [ + { + a.name: { + "tooltip": a.tooltip, + "type": slua.validate_type(a.compute_slua_type(), known_types), + } + } + for a in self.arguments + ], + "deprecated": self.deprecated + or self.slua_deprecated + or self.slua_removed + or self.detected_semantics, + "energy": self.energy, + "god-mode": self.god_mode, + "return": slua.validate_type(self.compute_slua_type(), known_types), + "sleep": self.sleep, + "tooltip": self.tooltip, + } + ) + except Exception as e: + raise ValueError(f"In function {self.name}: {e}") from e + class LSLDefinitions(NamedTuple): events: Dict[str, LSLEvent] @@ -300,6 +415,170 @@ class LSLFunctionRanges(enum.IntEnum): SCRIPT_ID_LIST_ADDITIONS = 800 +@dataclasses.dataclass +class SLuaProperty: + """Property definition""" + + name: str + type: str + value: str | None = None + comment: str = "" + slua_removed: bool = False + + def to_keywords_dict(self) -> dict: + return { + "tooltip": self.comment, + "type": self.type, + **({"value": _escape_python(self.value)} if self.value is not None else {}), + } + + +@dataclasses.dataclass +class SLuaParameter: + """ + Function/method parameter + - Regular parameters require both name and type + - Self parameters only need name (type is implicit) + - Variadic parameters need name "..." and type + """ + + name: str + type: Optional[str] = None + comment: str = "" + + +@dataclasses.dataclass +class SLuaFunctionAnon: + """Annonymous function signature""" + + parameters: List[SLuaParameter] + returnType: str + comment: Optional[str] = None + + +@dataclasses.dataclass +class SLuaFunction: + """Full function or method signature with optional overloads""" + + name: str + parameters: List[SLuaParameter] + returnType: str + typeParameters: Optional[List[str]] = None + comment: str = "" + private: bool = False + deprecated: bool = False + overloads: Optional[List[SLuaFunctionAnon]] = None + + def to_keywords_dict(self) -> dict: + return _remove_worthless( + { + "type-arguments": self.typeParameters, + "arguments": [ + { + a.name: { + "tooltip": a.comment, + "type": a.type, + } + } + for a in self.parameters + ], + "deprecated": self.deprecated, + "energy": 10.0, + "return": self.returnType, + "sleep": 0.0, + "tooltip": self.comment, + } + ) + + +@dataclasses.dataclass +class SLuaTypeAlias: + """Type alias definition""" + + name: str + definition: str + comment: str = "" + export: bool = False + """Whether this type is available to users""" + + def to_keywords_dict(self) -> dict: + definition = self.to_luau_def() + if len(definition) > 200: + definition = "" + return { + "tooltip": f"{self.comment}\n{definition}".strip(), + } + + def to_luau_def(self) -> str: + export_str = "export " if self.export else "" + return f"{export_str}type {self.name} = {self.definition}" + + +@dataclasses.dataclass +class SLuaClassDeclaration: + """Class declaration with properties and methods""" + + name: str + properties: List[SLuaProperty] + methods: List[SLuaFunction] + comment: str = "" + + def to_keywords_dict(self) -> dict: + return {"tooltip": self.comment} + + +@dataclasses.dataclass +class SLuaModule: + """Module declaration with constants and functions""" + + name: str + callable: Optional[SLuaFunction] + constants: List[SLuaProperty] + functions: List[SLuaFunction] + comment: str = "" + + def to_keywords_functions_dict(self) -> dict: + functions = {} + if self.callable: + functions[self.name] = self.callable.to_keywords_dict() + else: + functions[self.name] = {"energy": -1.0, "tooltip": self.comment} + functions.update( + { + f"{self.name}.{func.name}": func.to_keywords_dict() + for func in sorted(self.functions, key=lambda x: x.name) + if not func.private + } + ) + return functions + + def to_keywords_constants_dict(self) -> dict: + return { + f"{self.name}.{prop.name}": prop.to_keywords_dict() + for prop in sorted(self.constants, key=lambda x: x.name) + } + + +class SLuaDefinitions(NamedTuple): + # for best results, load/generate in the same order defined here + + # 1. Luau builtins. Typecheckers already know about these + controls: dict # same structure as LSLDefinitions.controls + builtinTypes: dict # same structure as LSLDefinitions.types + builtinConstants: List[SLuaProperty] + builtinFunctions: List[SLuaFunction] + + # 2. SLua base classes. These only depend on Luau builtins + baseClasses: List[SLuaClassDeclaration] + typeAliases: List[SLuaTypeAlias] + + # 3. SLua standard library. Depends on base classes + classes: List[SLuaClassDeclaration] + globalFunctions: List[SLuaFunction] + modules: List[SLuaModule] + globalVariables: List[SLuaProperty] + + def _escape_python(val: str) -> str: """Encode a string with escapes according to repr() rules""" # Syntax files have double-encoded values :( @@ -376,6 +655,9 @@ def _handle_event(self, event_name: str, event_data: dict) -> LSLEvent: ], private=event_data.get("private", False), deprecated=event_data.get("deprecated", False), + slua_deprecated=event_data.get("slua-deprecated", False), + slua_removed=event_data.get("slua-removed", False), + detected_semantics=event_data.get("detected-semantics", False), ) if event.name in self._definitions.events: @@ -396,17 +678,22 @@ def _handle_function(self, func_name: str, func_data: dict) -> LSLFunction: # 99.9% of the time this won't be specified, if it isn't, just use `sleep`'s value. mono_sleep=float(func_data.get("mono-sleep", func_data.get("sleep")) or "0.0"), ret_type=LSLType(func_data["return"]), + slua_type=func_data.get("slua-return", None), + type_arguments=func_data.get("type-arguments", []), arguments=[ self._handle_argument(func_name, arg) for arg in (func_data.get("arguments") or []) ], private=func_data.get("private", False), god_mode=func_data.get("god-mode", False), deprecated=func_data.get("deprecated", False), + slua_deprecated=func_data.get("slua-deprecated", False), + slua_removed=func_data.get("slua-removed", False), func_id=func_data["func-id"], pure=func_data.get("pure", False), native=func_data.get("native", False), index_semantics=bool(func_data.get("index-semantics", False)), bool_semantics=bool(func_data.get("bool-semantics", False)), + detected_semantics=bool(func_data.get("detected-semantics", False)), ) if func.name in self._definitions.functions: @@ -439,7 +726,9 @@ def _handle_argument(func_name: str, arg_dict: dict) -> LSLArgument: arg = LSLArgument( name=arg_name, type=LSLType(arg_data["type"]), + slua_type=arg_data.get("slua-type", None), index_semantics=bool(arg_data.get("index-semantics", False)), + bool_semantics=bool(arg_data.get("bool-semantics", False)), tooltip=arg_data.get("tooltip", ""), ) if arg.index_semantics and arg.type != LSLType.INTEGER: @@ -467,10 +756,11 @@ def _validate_identifier(self, name: str) -> None: raise KeyError(f"{name!r} is a reserved name") def _handle_constant(self, const_name: str, const_data: dict) -> LSLConstant: - self._validate_identifier(const_name) const = LSLConstant( name=const_name, type=LSLType(const_data["type"]), + slua_type=const_data.get("slua-type", None), + slua_removed=const_data.get("slua-removed", False), value=str(self._massage_const_value(const_data["value"])), tooltip=const_data.get("tooltip", ""), private=const_data.get("private", False), @@ -491,8 +781,212 @@ def _massage_const_value(val: Any) -> Any: return _unescape_python(val) -def _to_f32(val: float) -> float: - return ctypes.c_float(val).value +class SLuaDefinitionParser: + def __init__(self): + self.definitions = SLuaDefinitions({}, {}, [], [], [], [], [], [], [], []) + self.type_names: Set[str] = set() + self.global_scope: Set[str] = set() + + def parse_file(self, name: str) -> SLuaDefinitions: + if name.endswith(".llsd"): + return self.parse_llsd_file(name) + return self.parse_yaml_file(name) + + def parse_yaml_file(self, name: str): + with open(name, "rb") as f: + return self._parse_dict(yaml.safe_load(f.read())) + + def parse_llsd_file(self, name: str) -> SLuaDefinitions: + with open(name, "rb") as f: + return self.parse_llsd_blob(f.read()) + + def parse_llsd_blob(self, llsd_blob: bytes) -> SLuaDefinitions: + return self._parse_dict(llsd.parse_xml(llsd_blob)) + + def _parse_dict(self, def_dict: dict) -> SLuaDefinitions: + if any(x for x in self.definitions): + raise RuntimeError("Already parsed!") + + # 1. Luau builtins. Typecheckers already know about these + # nil is hardcoded because it should highlight as a constant, not a type + self.type_names.add("nil") + self.definitions.builtinTypes.update(def_dict["builtinTypes"]) + self.type_names.update(self.definitions.builtinTypes.keys()) + self.definitions.controls.update(def_dict["controls"]) + self.global_scope.update(self.definitions.controls.keys()) + self.definitions.builtinConstants.extend( + self._validate_property(const, self.global_scope, const=True) + for const in def_dict["builtinConstants"] + ) + self.definitions.builtinFunctions.extend( + self._validate_function(func, self.global_scope) + for func in def_dict["builtinFunctions"] + ) + # 2. SLua base classes. These only depend on Luau builtins + self.definitions.baseClasses.extend( + self._validate_class(class_) for class_ in def_dict["baseClasses"] + ) + self.definitions.typeAliases.extend( + self._validate_type_alias(alias) for alias in def_dict["typeAliases"] + ) + + # 3. SLua standard library. Depends on base classes + self.definitions.classes.extend( + self._validate_class(class_) for class_ in def_dict["classes"] + ) + self.definitions.globalFunctions.extend( + self._validate_function(func, self.global_scope) for func in def_dict["globalFunctions"] + ) + self.definitions.modules.extend( + self._validate_module(module) for module in def_dict["modules"] + ) + self.definitions.globalVariables.extend( + self._validate_property(const, self.global_scope) + for const in def_dict["globalVariables"] + ) + + return self.definitions + + def _validate_module(self, data: any) -> SLuaModule: + module = SLuaModule( + name=data["name"], + comment=data.get("comment", ""), + callable=None, + constants=[], + functions=[], + ) + try: + self._validate_identifier(module.name) + self._validate_scope(module.name, self.global_scope) + module_scope: Set[str] = set() + callable = data.get("callable") + if callable is not None: + module.callable = self._validate_function(callable, module_scope) + if module.callable.name != module.name: + raise ValueError("module.callable.name must match module.name") + module_scope.clear() + module.constants = [ + self._validate_property(prop, module_scope, const=True) + for prop in data.get("constants", []) + ] + module.functions = [ + self._validate_function(function, module_scope) + for function in data.get("functions", []) + ] + except Exception as e: + raise ValueError(f"In module {module.name}: {e}") from e + return module + + def _validate_class(self, data: any) -> SLuaClassDeclaration: + class_ = SLuaClassDeclaration( + name=data["name"], + comment=data.get("comment", ""), + properties=[], + methods=[], + ) + try: + self._validate_identifier(class_.name) + self._validate_scope(class_.name, self.type_names) + class_scope: Set[str] = set() + class_.properties = [ + self._validate_property(prop, class_scope) for prop in data.get("properties", []) + ] + class_.methods = [ + self._validate_function(method, class_scope, method=True) + for method in data.get("methods", []) + ] + except Exception as e: + raise ValueError(f"In class {class_.name}: {e}") from e + return class_ + + def _validate_function(self, data: any, scope: Set[str], method: bool = False) -> SLuaFunction: + try: + func = SLuaFunction( + name=data["name"], + typeParameters=data.get("typeParameters", []), + parameters=[SLuaParameter(**p) for p in data.get("parameters", [])], + returnType=data.get("returnType", LSLType.VOID.meta.slua_name), + comment=data.get("comment", ""), + deprecated=data.get("deprecated", False), + private=data.get("private", False), + ) + self._validate_identifier(func.name) + self._validate_scope(func.name, scope) + known_types = self.validate_type_params(func.typeParameters) + self.validate_type(func.returnType, known_types) + params = func.parameters + params_scope = set() + if method: + if not params or params[0].name != "self" or params[0].type is not None: + raise ValueError(f"Method {func.name} missing self parameter") + params_scope.add("self") + params = params[1:] + if params and params[-1].name == "...": + self.validate_type(params[-1].type, known_types) + params = params[:-1] + for param in params: + self._validate_identifier(param.name) + self._validate_scope(param.name, params_scope) + self.validate_type(param.type, known_types) + return func + except Exception as e: + raise ValueError(f"In function {data['name']}: {e}") from e + + def _validate_type_alias(self, data: any) -> SLuaTypeAlias: + alias = SLuaTypeAlias(**data) + try: + self._validate_identifier(alias.name) + self.validate_type(alias.definition) + # add it to scope only after validating type, to ensure it isn't recursive + self._validate_scope(alias.name, self.type_names) + except Exception as e: + raise ValueError(f"In type alias {alias.name}: {e}") from e + return alias + + def _validate_property(self, data: any, scope: Set[str], const: bool = False) -> SLuaProperty: + prop = SLuaProperty(slua_removed=data.pop("slua-removed", False), **data) + self._validate_identifier(prop.name) + self._validate_scope(prop.name, scope) + if const and prop.type != "any" and prop.value is None: + raise ValueError(f"Constant {prop.name} must have a value") + self.validate_type(prop.type) + return prop + + def validate_type_params(self, type_params: List[str]) -> set[str]: + known_types = set(self.type_names) + for type_param in type_params: + type_param = type_param.replace("...", "", 1) + self._validate_identifier(type_param) + self._validate_scope(type_param, known_types) + return known_types + + _TYPE_SEPERATORS_RE = re.compile( + r"[ \n?&|,{}\[\]()]|\.\.\.|typeof|->|[a-zA-Z0-9_]*:|\"[a-zA-Z0-9_]*\"" + ) + + def validate_type(self, type: str, known_type_names: set[str] | None = None) -> str: + if not type: + raise ValueError("Type may not be empty") + if known_type_names is None: + known_type_names = self.type_names + if type in known_type_names: + return type + subtypes = self._TYPE_SEPERATORS_RE.split(type) + unknown_subtypes = set(subtypes) - known_type_names - {""} + if not unknown_subtypes: + return type + raise ValueError(f"Unknown types {unknown_subtypes} in definition {type!r}") + + def _validate_scope(self, name: str, scope: Set[str]) -> None: + if name in scope: + raise ValueError(f"{name!r} is already defined in this scope") + scope.add(name) + + _IDENTIFIER_RE = re.compile(r"\A[_a-zA-Z][_a-zA-Z0-9]*\Z") + + def _validate_identifier(self, name: str) -> None: + if not re.match(self._IDENTIFIER_RE, name): + raise ValueError(f"{name!r} is not a valid identifier") def _remove_worthless(val: dict) -> dict: @@ -507,22 +1001,26 @@ def _remove_worthless(val: dict) -> dict: val.pop("pure", None) if not val.get("native"): val.pop("native", None) + if not val.get("bool_semantics"): + val.pop("bool_semantics", None) if not val.get("bool-semantics"): val.pop("bool-semantics", None) if not val.get("index-semantics"): val.pop("index-semantics", None) + if not val.get("type-arguments"): + val.pop("type-arguments", None) return val -def dump_syntax(definitions: LSLDefinitions) -> bytes: +def dump_syntax(definitions: LSLDefinitions, pretty: bool = False) -> bytes: """Write a syntax file for use by viewers""" syntax = { - "llsd-lsl-syntax-version": 2, "controls": definitions.controls.copy(), "types": definitions.types.copy(), "constants": {}, "events": {}, "functions": {}, + "llsd-lsl-syntax-version": 2, } for event in sorted(definitions.events.values(), key=lambda x: x.name): if event.private: @@ -534,6 +1032,11 @@ def dump_syntax(definitions: LSLDefinitions) -> bytes: continue syntax["functions"][func.name] = func.to_dict() + for const in sorted(definitions.constants.values(), key=lambda x: x.name): + if const.private: + continue + syntax["constants"][const.name] = const.to_dict() + # This one's a little weird because it's not a "real" constant, but it's expected to be in the # constants section even though it has no value or type. It allows default to have a tooltip # and a distinct color. @@ -542,12 +1045,69 @@ def dump_syntax(definitions: LSLDefinitions) -> bytes: "If another state is defined before the default state, the compiler will report a syntax error." } - for const in sorted(definitions.constants.values(), key=lambda x: x.name): - if const.private: - continue - syntax["constants"][const.name] = const.to_dict() + if pretty: + return llsd.LLSDXMLPrettyFormatter(indent_atom=b" ").format(syntax) + else: + return llsd.format_xml(syntax) - return llsd.format_xml(syntax) + +def dump_slua_syntax( + lsl_definitions: LSLDefinitions, slua_definitions_file: str, pretty: bool = False +) -> bytes: + """Write a syntax file for use by viewers""" + parser = SLuaDefinitionParser() + slua_definitions = parser.parse_file(slua_definitions_file) + ll_module = [m for m in slua_definitions.modules if m.name == "ll"][0] + syntax = { + "controls": slua_definitions.controls.copy(), + "types": slua_definitions.builtinTypes.copy(), + "constants": {}, + "events": {}, + "functions": {}, + "llsd-lsl-syntax-version": 2, + } + + # types + for class_ in sorted(slua_definitions.baseClasses, key=lambda x: x.name): + syntax["types"][class_.name] = class_.to_keywords_dict() + for alias in sorted(slua_definitions.typeAliases, key=lambda x: x.name): + if alias.export: + syntax["types"][alias.name] = alias.to_keywords_dict() + for class_ in sorted(slua_definitions.classes, key=lambda x: x.name): + syntax["types"][class_.name] = class_.to_keywords_dict() + + # events + for event in sorted(lsl_definitions.events.values(), key=lambda x: x.name): + if event.slua_removed: + continue + syntax["events"][event.name] = event.to_slua_dict(parser) + + # functions + for func in slua_definitions.builtinFunctions: + syntax["functions"][func.name] = func.to_keywords_dict() + for func in sorted(slua_definitions.globalFunctions, key=lambda x: x.name): + syntax["functions"][func.name] = func.to_keywords_dict() + for module in sorted(slua_definitions.modules, key=lambda x: x.name): + if module.name not in {"ll", "llcompat"}: + syntax["functions"].update(module.to_keywords_functions_dict()) + syntax["functions"].update(ll_module.to_keywords_functions_dict()) + for func in sorted(lsl_definitions.functions.values(), key=lambda x: x.name): + if not func.private: + syntax["functions"][func.compute_slua_name()] = func.to_slua_dict(parser) + + # constants + for const in slua_definitions.builtinConstants: + syntax["constants"][const.name] = const.to_keywords_dict() + for module in sorted(slua_definitions.modules, key=lambda x: x.name): + syntax["constants"].update(module.to_keywords_constants_dict()) + for const in sorted(lsl_definitions.constants.values(), key=lambda x: x.name): + if not const.private and not const.slua_removed: + syntax["constants"][const.name] = const.to_slua_dict(parser) + + if pretty: + return llsd.LLSDXMLPrettyFormatter(indent_atom=b" ").format(syntax) + else: + return llsd.format_xml(syntax) def _write_if_different(filename: str, data: Union[bytes, str]): @@ -1972,7 +2532,20 @@ def main(): sub = subparsers.add_parser("syntax") sub.add_argument("filename") - sub.set_defaults(func=lambda args, defs: _write_if_different(args.filename, dump_syntax(defs))) + sub.add_argument("--pretty", action="store_true", help="Pretty-print the XML output") + sub.set_defaults( + func=lambda args, defs: _write_if_different(args.filename, dump_syntax(defs, args.pretty)) + ) + + sub = subparsers.add_parser("slua_syntax") + sub.add_argument("slua_definitions", help="Path to the SLua definition yaml") + sub.add_argument("filename") + sub.add_argument("--pretty", action="store_true", help="Pretty-print the XML output") + sub.set_defaults( + func=lambda args, defs: _write_if_different( + args.filename, dump_slua_syntax(defs, args.slua_definitions, args.pretty) + ) + ) sub = subparsers.add_parser("gen_constant_lsl_script") sub.set_defaults(func=lambda args, defs: gen_constant_lsl_script(defs)) diff --git a/lsl_definitions.schema.json b/lsl_definitions.schema.json index f061882..7567c20 100644 --- a/lsl_definitions.schema.json +++ b/lsl_definitions.schema.json @@ -1,15 +1,15 @@ { - "$schema": "http://json-schema.org/draft-07/schema#", + "$schema": "http://json-schema.org/draft/2020-12/schema", "$id": "http://raw.githubusercontent.com/secondlife/lsl-definitions/refs/heads/main/lsl_definitions.schema.json", "$comment": "This schema defines keywords for the Linden Scripting Language (LSL) of Second Life.", - "definitions": { + "$defs": { "nonNegativeInteger": { "minimum": 0, "type": "integer" }, "nonNegativeIntegerDefault0": { "allOf": [ - { "$ref": "#/definitions/nonNegativeInteger" }, + { "$ref": "#/$defs/nonNegativeInteger" }, { "default": 0 } ] }, @@ -33,11 +33,17 @@ "patternProperties": { "^(?:[A-Z]+[0-9]*(?:_(?:[0-9]+|[A-Z]+[0-9]*))*)$": { "properties": { + "additionalProperties": false, "deprecated": { "const": true, "markdownDescription": "This constant has been deprecated.", "type": "boolean" }, + "slua-removed": { + "const": true, + "markdownDescription": "This constant is only present in LSL, not SLua.", + "type": "boolean" + }, "private": { "const": true, "markdownDescription": "This constant should be omitted from the generated documentation.", @@ -134,92 +140,112 @@ "type": "object" }, "events": { - "properties": { - "arguments": { - "items": { - "additionalProperties": false, - "patternProperties": { - "^(?:[a-z]+(?:_[a-z]+)*)$": { - "properties": { - "tooltip": { - "markdownDescription": "A brief description of this event argument.", - "type": "string" - }, - "type": { - "defaultSnippets": [ - { - "label": "float", - "body": "float" - }, - { - "label": "integer", - "body": "integer" - }, - { - "label": "key", - "body": "key" - }, - { - "label": "list", - "body": "list" - }, - { - "label": "quaternion", - "body": "quaternion" - }, - { - "label": "rotation", - "body": "rotation" - }, - { - "label": "string", - "body": "string" + "additionalProperties": false, + "patternProperties": { + "^[a-z_]+$": { + "additionalProperties": false, + "properties": { + "arguments": { + "items": { + "additionalProperties": false, + "patternProperties": { + "^(?:[A-Za-z]+(?:_[A-Za-z]+)*)$": { + "properties": { + "tooltip": { + "markdownDescription": "A brief description of this event argument.", + "type": "string" }, - { - "label": "vector", - "body": "vector" + "type": { + "defaultSnippets": [ + { + "label": "float", + "body": "float" + }, + { + "label": "integer", + "body": "integer" + }, + { + "label": "key", + "body": "key" + }, + { + "label": "list", + "body": "list" + }, + { + "label": "quaternion", + "body": "quaternion" + }, + { + "label": "rotation", + "body": "rotation" + }, + { + "label": "string", + "body": "string" + }, + { + "label": "vector", + "body": "vector" + } + ], + "markdownDescription": "One of the valid types for this event argument: [float, integer, key, list, rotation, string, vector].", + "oneOf": [ + { "const": "float" }, + { "const": "integer" }, + { "const": "key" }, + { "const": "list" }, + { + "$comment": "quaternion is an alias for rotation", + "const": "quaternion" + }, + { "const": "rotation" }, + { "const": "string" }, + { "const": "vector" } + ] } + }, + "required": [ + "type" ], - "markdownDescription": "One of the valid types for this event argument: [float, integer, key, list, rotation, string, vector].", - "oneOf": [ - { "const": "float" }, - { "const": "integer" }, - { "const": "key" }, - { "const": "list" }, - { - "$comment": "quaternion is an alias for rotation", - "const": "quaternion" - }, - { "const": "rotation" }, - { "const": "string" }, - { "const": "vector" } - ] + "type": "object" } }, - "required": [ - "type" - ], "type": "object" - } + }, + "markdownDescription": "An array of event arguments.", + "minItems": 0, + "type": "array", + "uniqueItems": true }, - "type": "object" - }, - "markdownDescription": "An array of event arguments.", - "minItems": 1, - "type": "array", - "uniqueItems": true - }, - "deprecated": { - "const": true, - "markdownDescription": "This event has been deprecated.", - "type": "boolean" - }, - "tooltip": { - "markdownDescription": "A brief description of this event.", - "type": "string" + "detected-semantics": { + "const": true, + "markdownDescription": "Uses llDetected* in LSL and {DetectedEvent} in SLua.", + "type": "boolean" + }, + "deprecated": { + "const": true, + "markdownDescription": "This event has been deprecated.", + "type": "boolean" + }, + "slua-deprecated": { + "const": true, + "markdownDescription": "This event has been deprecated in SLua.", + "type": "boolean" + }, + "slua-removed": { + "const": true, + "markdownDescription": "This event has been removed in SLua.", + "type": "boolean" + }, + "tooltip": { + "markdownDescription": "A brief description of this event.", + "type": "string" + } + } } }, - "required": [], "type": "object" }, "functions": { @@ -228,15 +254,35 @@ "^ll[A-Zs](?:[A-Z0-9]*[a-z]*)+$": { "additionalProperties": false, "properties": { + "type-arguments": { + "items": { + "additionalProperties": false, + "patternProperties": { + "^(?:[A-Za-z]+)$": { + "markdownDescription": "A type variable name for slua typechecking." + } + }, + "type": "string" + }, + "markdownDescription": "An array of type variable names for slua typechecking.", + "type": "array", + "uniqueItems": true + }, "arguments": { "items": { "additionalProperties": false, "patternProperties": { "^(?:[A-Za-z]+(?:[A-z0-9-_]+)*)$": { + "additionalProperties": false, "properties": { "bool-semantics": { "const": true, - "markdownDescription": "The function arguments integer value represents a boolean value.", + "markdownDescription": "This function argument's integer value represents a boolean value.", + "type": "boolean" + }, + "index-semantics": { + "const": true, + "markdownDescription": "This function argument's integer value represents a zero-based index.", "type": "boolean" }, "tooltip": { @@ -292,6 +338,10 @@ { "const": "string" }, { "const": "vector" } ] + }, + "slua-type": { + "markdownDescription": "A more specific argument type for slua type-checking.", + "type": "string" } }, "required": [ @@ -316,8 +366,13 @@ "markdownDescription": "This function has been deprecated.", "type": "boolean" }, + "detected-semantics": { + "const": true, + "markdownDescription": "This function is wrapped in the DetectedEvent class.", + "type": "boolean" + }, "energy": { - "$ref": "#/definitions/nonNegativeNumber", + "$ref": "#/$defs/nonNegativeNumber", "markdownDescription": "The script energy consumed by this function." }, "experience": { @@ -327,7 +382,7 @@ }, "func-id": { "$comment": "llSin has 'func-id: 0', so we must include zero", - "$ref": "#/definitions/nonNegativeInteger", + "$ref": "#/$defs/nonNegativeInteger", "markdownDescription": "The LSO function identifier." }, "god-mode": { @@ -346,7 +401,7 @@ "type": "boolean" }, "mono-sleep": { - "$ref": "#/definitions/nonNegativeNumber", + "$ref": "#/$defs/nonNegativeNumber", "markdownDescription": "Sleep in the mono-script runtime." }, "must-use": { @@ -425,8 +480,22 @@ { "const": "void" } ] }, + "slua-deprecated": { + "const": true, + "markdownDescription": "This function is deprecated in SLua.", + "type": "boolean" + }, + "slua-removed": { + "const": true, + "markdownDescription": "In SLua, this function has been removed from ll module and only exists in llcompat.", + "type": "boolean" + }, + "slua-return": { + "markdownDescription": "A more specific return type for slua type-checking.", + "type": "string" + }, "sleep": { - "$ref": "#/definitions/nonNegativeNumber", + "$ref": "#/$defs/nonNegativeNumber", "markdownDescription": "Additional sleep time imposed by the script after this function completes." }, "tooltip": { @@ -442,7 +511,7 @@ "type": "object" }, "llsd-lsl-syntax-version": { - "$ref": "#/definitions/positiveInteger", + "$ref": "#/$defs/positiveInteger", "markdownDescription": "Only increment with file format changes." }, "types": { diff --git a/lsl_definitions.yaml b/lsl_definitions.yaml index b7ab35f..a90f9a1 100644 --- a/lsl_definitions.yaml +++ b/lsl_definitions.yaml @@ -632,6 +632,7 @@ constants: tooltip: Messages from the region to the COMBAT_CHANNEL will all be from this ID.\n Scripts may filter llListen calls on this ID to receive only system generated combat log messages. type: string + slua-type: uuid value: "45e0fcfa-2268-4490-a51c-3e51bdfe80d1" CONTENT_TYPE_ATOM: tooltip: '"application/atom+xml"' @@ -932,6 +933,7 @@ constants: 'FALSE': tooltip: An integer constant for boolean comparisons. Has the value '0'. type: integer + slua-removed: true value: 0 FILTER_FLAGS: tooltip: Flags to control returned attachments. @@ -1141,46 +1143,57 @@ constants: IMG_USE_BAKED_AUX1: tooltip: '' type: string + slua-type: uuid value: "9742065b-19b5-297c-858a-29711d539043" IMG_USE_BAKED_AUX2: tooltip: '' type: string + slua-type: uuid value: "03642e83-2bd1-4eb9-34b4-4c47ed586d2d" IMG_USE_BAKED_AUX3: tooltip: '' type: string + slua-type: uuid value: "edd51b77-fc10-ce7a-4b3d-011dfc349e4f" IMG_USE_BAKED_EYES: tooltip: '' type: string + slua-type: uuid value: "52cc6bb6-2ee5-e632-d3ad-50197b1dcb8a" IMG_USE_BAKED_HAIR: tooltip: '' type: string + slua-type: uuid value: "09aac1fb-6bce-0bee-7d44-caac6dbb6c63" IMG_USE_BAKED_HEAD: tooltip: '' type: string + slua-type: uuid value: "5a9f4a74-30f2-821c-b88d-70499d3e7183" IMG_USE_BAKED_LEFTARM: tooltip: '' type: string + slua-type: uuid value: "ff62763f-d60a-9855-890b-0c96f8f8cd98" IMG_USE_BAKED_LEFTLEG: tooltip: '' type: string + slua-type: uuid value: "8e915e25-31d1-cc95-ae08-d58a47488251" IMG_USE_BAKED_LOWER: tooltip: '' type: string + slua-type: uuid value: "24daea5f-0539-cfcf-047f-fbc40b2786ba" IMG_USE_BAKED_SKIRT: tooltip: '' type: string + slua-type: uuid value: "43529ce8-7faa-ad92-165a-bc4078371687" IMG_USE_BAKED_UPPER: tooltip: '' type: string + slua-type: uuid value: "ae2de45c-d252-50b8-5c6e-19f39ce79317" INVENTORY_ALL: tooltip: '' @@ -1514,6 +1527,7 @@ constants: NULL_KEY: tooltip: '' type: string + slua-type: uuid value: "00000000-0000-0000-0000-000000000000" OBJECT_ACCOUNT_LEVEL: tooltip: Retrieves the account level of an avatar.\nReturns 0 when the avatar @@ -3900,22 +3914,27 @@ constants: TEXTURE_BLANK: tooltip: '' type: string + slua-type: uuid value: "5748decc-f629-461c-9a36-a35a221fe21f" TEXTURE_DEFAULT: tooltip: '' type: string + slua-type: uuid value: "89556747-24cb-43ed-920b-47caed15465f" TEXTURE_MEDIA: tooltip: '' type: string + slua-type: uuid value: "8b5fec65-8d8d-9dc5-cda8-8fdf2716e361" TEXTURE_PLYWOOD: tooltip: '' type: string + slua-type: uuid value: "89556747-24cb-43ed-920b-47caed15465f" TEXTURE_TRANSPARENT: tooltip: '' type: string + slua-type: uuid value: "8dcd4a48-2d37-4909-9f78-f7a9eb4ef903" TOUCH_INVALID_FACE: tooltip: '' @@ -4013,6 +4032,7 @@ constants: 'TRUE': tooltip: An integer constant for boolean comparisons. Has the value '1'. type: integer + slua-removed: true value: 1 TWO_PI: tooltip: 6.28318530 - The radians of a circle. @@ -4428,6 +4448,7 @@ events: - NumberOfCollisions: tooltip: '' type: integer + detected-semantics: true tooltip: "This event is raised while another object, or avatar, is colliding with\ \ the object the script is attached to.\n\t\t\tThe number of detected objects\ \ is passed to the script. Information on those objects may be gathered via\ @@ -4437,6 +4458,7 @@ events: - NumberOfCollisions: tooltip: '' type: integer + detected-semantics: true tooltip: "This event is raised when another object, or avatar, stops colliding\ \ with the object the script is attached to.\n\t\t\tThe number of detected objects\ \ is passed to the script. Information on those objects may be gathered via\ @@ -4446,6 +4468,7 @@ events: - NumberOfCollisions: tooltip: '' type: integer + detected-semantics: true tooltip: "This event is raised when another object, or avatar, starts colliding\ \ with the object the script is attached to.\n\t\t\tThe number of detected objects\ \ is passed to the script. Information on those objects may be gathered via\ @@ -4516,6 +4539,7 @@ events: - count: tooltip: The number of damage events queued. type: integer + detected-semantics: true tooltip: Triggered as damage is applied to an avatar or task, after all on_damage events have been processed. game_control: @@ -4593,6 +4617,7 @@ events: - ID: tooltip: '' type: key + slua-type: string tooltip: Triggered when object receives a link message via llMessageLinked function call. linkset_data: @@ -4638,21 +4663,21 @@ events: tooltip: This event is triggered when a resident has given an amount of Linden dollars to the object. moving_end: - arguments: null + arguments: [] tooltip: Triggered whenever an object with this script stops moving. moving_start: - arguments: null + arguments: [] tooltip: Triggered whenever an object with this script starts moving. no_sensor: - arguments: null + arguments: [] tooltip: This event is raised when sensors are active, via the llSensor function call, but are not sensing anything. not_at_rot_target: - arguments: null + arguments: [] tooltip: When a target is set via the llRotTarget function call, but the script is outside the specified angle this event is raised. not_at_target: - arguments: null + arguments: [] tooltip: When a target is set via the llTarget library call, but the script is outside the specified range this event is raised. object_rez: @@ -4668,6 +4693,7 @@ events: - count: tooltip: The number of damage events queued. type: integer + detected-semantics: true tooltip: Triggered when an avatar or object receives damage. on_death: arguments: [] @@ -4729,20 +4755,24 @@ events: - NumberDetected: tooltip: '' type: integer + detected-semantics: true tooltip: "This event is raised whenever objects matching the constraints of the\ \ llSensor command are detected.\n\t\t\tThe number of detected objects is passed\ \ to the script in the parameter. Information on those objects may be gathered\ \ via the llDetected* functions." state_entry: - arguments: null + arguments: [] tooltip: The state_entry event occurs whenever a new state is entered, including at program start, and is always the first event handled. + slua-removed: true state_exit: - arguments: null + arguments: [] + slua-removed: true tooltip: The state_exit event occurs whenever the state command is used to transition to another state. It is handled before the new states state_entry event. timer: - arguments: null + arguments: [] + slua-deprecated: true tooltip: This event is raised at regular intervals set by the llSetTimerEvent library function. touch: @@ -4750,6 +4780,7 @@ events: - NumberOfTouches: tooltip: '' type: integer + detected-semantics: true tooltip: "This event is raised while a user is touching the object the script\ \ is attached to.\n\t\t\tThe number of touching objects is passed to the script\ \ in the parameter.\n\t\t\tInformation on those objects may be gathered via\ @@ -4759,6 +4790,7 @@ events: - NumberOfTouches: tooltip: '' type: integer + detected-semantics: true tooltip: "This event is raised when a user stops touching the object the script\ \ is attached to. The number of touches is passed to the script in the parameter.\n\ \t\t\tInformation on those objects may be gathered via the llDetected* library\ @@ -4768,6 +4800,7 @@ events: - NumberOfTouches: tooltip: '' type: integer + detected-semantics: true tooltip: "This event is raised when a user first touches the object the script\ \ is attached to. The number of touches is passed to the script in the parameter.\n\ \t\t\tInformation on those objects may be gathered via the llDetected() library\ @@ -4791,11 +4824,16 @@ functions: # sleep: Additional sleep time imposed by the script after this function completes. # mono-sleep: Sleep in the mono script runtime # return: Return type of the function. +# slua-return: More specific return type for slua type-checking. +# slua-type: More specific argument type for slua type-checking. +# type-arguments: An array of strings naming the type variables used for generic type-checking this slua function. # arguments: An array of maps of maps describing the parameters to this function. # tooltip: A brief description of this function. Map of maps is used to retain ordering. # func-id: The LSO function identifier, (See comment at the top of this file.) # private: Should this function be omitted from the generated documentation. # deprecated: Has this function been deprecated. +# slua-deprecated: Has this function or event been deprecated in SLua. +# slua-removed: Has this function or event been removed in SLua. # pure: Is the function guaranteed to have no side effects. # must-use: If true or `pure` is true, then the functions return value should not be discarded, as it serves no other purpose # native: If true, this function must use a native implementation for non-LSO VMs. @@ -4804,6 +4842,7 @@ functions: # linden-experience: If true, this function requires a linden-owned experience. # index-semantics: If true then the returned integer from this function represents 0 based index # bool-semantics: If true then the returned integer represents a boolean 1 or 0 +# detected-semantics: If true, the event or function is involved in the DetectedEvent wrapper in SLua llAbs: arguments: - Value: @@ -4864,15 +4903,16 @@ functions: llAdjustDamage: arguments: - Number: - index-semantics: true tooltip: Damage event index to modify. type: integer + index-semantics: true - Damage: tooltip: New damage amount to apply on this event. type: float energy: 10.0 func-id: 555 return: void + detected-semantics: true sleep: 0.0 tooltip: Changes the amount of damage to be delivered by this damage event. llAdjustSoundVolume: @@ -4891,11 +4931,11 @@ functions: - AgentID: tooltip: '' type: key - bool-semantics: true energy: 10.0 experience: true func-id: 392 return: integer + bool-semantics: true sleep: 0.0 tooltip: "\n Returns TRUE if the agent is in the Experience\ \ and the Experience can run in the current location.\n " @@ -5118,6 +5158,7 @@ functions: func-id: 196 pure: true return: list + slua-return: '{string}' sleep: 0.0 tooltip: Create a list from a string of comma separated values specified in Text. llCastRay: @@ -5431,23 +5472,26 @@ functions: \ case the second item will be the value associated with the key.\n \ \ " llDeleteSubList: + type-arguments: [T] arguments: - Source: tooltip: '' type: list + slua-type: '{T}' - Start: - index-semantics: true tooltip: '' type: integer - - End: index-semantics: true + - End: tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 193 native: true pure: true return: list + slua-return: '{T}' sleep: 0.0 tooltip: Removes the slice from start to end and returns the remainder of the list.\nRemove a slice from the list and return the remainder, start and end @@ -5461,13 +5505,13 @@ functions: tooltip: '' type: string - Start: - index-semantics: true tooltip: '' type: integer - - End: index-semantics: true + - End: tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 95 pure: true @@ -5486,10 +5530,10 @@ functions: - flags: tooltip: Flags for derez behavior. type: integer - bool-semantics: true energy: 10.0 func-id: 509 return: integer + bool-semantics: true sleep: 0.0 tooltip: Derezzes an object previously rezzed by a script in this region. Returns TRUE on success or FALSE if the object could not be derezzed. @@ -5503,12 +5547,13 @@ functions: llDetectedDamage: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 554 return: list + detected-semantics: true sleep: 0.0 tooltip: Returns a list containing the current damage for the event, the damage type and the original damage delivered. @@ -5516,12 +5561,13 @@ functions: llDetectedGrab: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 37 return: vector + detected-semantics: true sleep: 0.0 tooltip: Returns the grab offset of a user touching the object.\nReturns <0.0, 0.0, 0.0> if Number is not a valid object. @@ -5529,13 +5575,14 @@ functions: llDetectedGroup: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 39 return: integer bool-semantics: true + detected-semantics: true sleep: 0.0 tooltip: Returns TRUE if detected object or agent Number has the same user group active as this object.\nIt will return FALSE if the object or agent is in the @@ -5544,12 +5591,13 @@ functions: llDetectedKey: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 32 return: key + detected-semantics: true sleep: 0.0 tooltip: Returns the key of detected object or avatar number.\nReturns NULL_KEY if Number is not a valid index. @@ -5557,13 +5605,14 @@ functions: llDetectedLinkNumber: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 40 # Note that the return does NOT have index semantics, link numbers are already one-indexed (sort of) return: integer + detected-semantics: true sleep: 0.0 tooltip: Returns the link position of the triggered event for touches and collisions only.\n0 for a non-linked object, 1 for the root of a linked object, 2 for the @@ -5572,12 +5621,13 @@ functions: llDetectedName: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 31 return: string + detected-semantics: true sleep: 0.0 tooltip: Returns the name of detected object or avatar number.\nReturns the name of detected object number.\nReturns empty string if Number is not a valid index. @@ -5585,12 +5635,13 @@ functions: llDetectedOwner: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 33 return: key + detected-semantics: true sleep: 0.0 tooltip: Returns the key of detected object's owner.\nReturns invalid key if Number is not a valid index. @@ -5598,12 +5649,13 @@ functions: llDetectedPos: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 35 return: vector + detected-semantics: true sleep: 0.0 tooltip: Returns the position of detected object or avatar number.\nReturns <0.0, 0.0, 0.0> if Number is not a valid index. @@ -5611,24 +5663,26 @@ functions: llDetectedRezzer: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 553 return: key + detected-semantics: true sleep: 0.0 tooltip: Returns the key for the rezzer of the detected object. must-use: true llDetectedRot: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 38 return: rotation + detected-semantics: true sleep: 0.0 tooltip: Returns the rotation of detected object or avatar number.\nReturns <0.0, 0.0, 0.0, 1.0> if Number is not a valid offset. @@ -5636,12 +5690,13 @@ functions: llDetectedTouchBinormal: arguments: - Index: - index-semantics: true tooltip: Index of detection information type: integer + index-semantics: true energy: 10.0 func-id: 341 return: vector + detected-semantics: true sleep: 0.0 tooltip: Returns the surface bi-normal for a triggered touch event.\nReturns a vector that is the surface bi-normal (tangent to the surface) where the touch @@ -5650,13 +5705,14 @@ functions: llDetectedTouchFace: arguments: - Index: - index-semantics: true tooltip: Index of detection information type: integer + index-semantics: true energy: 10.0 func-id: 338 # NOTE: We can't change face number indexing easily because it's part of the viewer, so no index semantics for ret... return: integer + detected-semantics: true sleep: 0.0 tooltip: Returns the index of the face where the avatar clicked in a triggered touch event. @@ -5664,12 +5720,13 @@ functions: llDetectedTouchNormal: arguments: - Index: - index-semantics: true tooltip: Index of detection information type: integer + index-semantics: true energy: 10.0 func-id: 340 return: vector + detected-semantics: true sleep: 0.0 tooltip: Returns the surface normal for a triggered touch event.\nReturns a vector that is the surface normal (perpendicular to the surface) where the touch event @@ -5678,12 +5735,13 @@ functions: llDetectedTouchPos: arguments: - Index: - index-semantics: true tooltip: Index of detected information type: integer + index-semantics: true energy: 10.0 func-id: 339 return: vector + detected-semantics: true sleep: 0.0 tooltip: Returns the position, in region coordinates, where the object was touched in a triggered touch event.\nUnless it is a HUD, in which case it returns the @@ -5692,12 +5750,13 @@ functions: llDetectedTouchST: arguments: - Index: - index-semantics: true tooltip: Index of detection information type: integer + index-semantics: true energy: 10.0 func-id: 342 return: vector + detected-semantics: true sleep: 0.0 tooltip: Returns a vector that is the surface coordinates where the prim was touched.\nThe X and Y vector positions contain the horizontal (S) and vertical (T) face coordinates @@ -5708,12 +5767,13 @@ functions: llDetectedTouchUV: arguments: - Index: - index-semantics: true tooltip: Index of detection information type: integer + index-semantics: true energy: 10.0 func-id: 337 return: vector + detected-semantics: true sleep: 0.0 tooltip: Returns a vector that is the texture coordinates for where the prim was touched.\nThe X and Y vector positions contain the U and V face coordinates @@ -5723,12 +5783,13 @@ functions: llDetectedType: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 34 return: integer + detected-semantics: true sleep: 0.0 tooltip: "Returns the type (AGENT, ACTIVE, PASSIVE, SCRIPTED) of detected object.\\\ nReturns 0 if number is not a valid index.\\nNote that number is a bit-field,\ @@ -5738,12 +5799,13 @@ functions: llDetectedVel: arguments: - Number: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 36 return: vector + detected-semantics: true sleep: 0.0 tooltip: Returns the velocity of the detected object Number.\nReturns<0.0, 0.0, 0.0> if Number is not a valid offset. @@ -5812,10 +5874,10 @@ functions: - Direction: tooltip: '' type: vector - bool-semantics: true energy: 10.0 func-id: 205 return: integer + bool-semantics: true sleep: 0.0 tooltip: Checks to see whether the border hit by Direction from Position is the edge of the world (has no neighboring region).\nReturns TRUE if the line along @@ -6125,6 +6187,7 @@ functions: energy: 10.0 func-id: 84 return: float + slua-removed: true sleep: 0.0 tooltip: Returns the script time in seconds and then resets the script timer to zero.\nGets the time in seconds since starting and resets the time to zero. @@ -6183,6 +6246,7 @@ functions: energy: 10.0 func-id: 523 return: list + slua-return: '{uuid}' sleep: 0.0 tooltip: Returns a list of keys of all visible (not HUD) attachments on the avatar identified by the ID argument @@ -6198,6 +6262,7 @@ functions: energy: 10.0 func-id: 518 return: list + slua-return: '{uuid}' sleep: 0.0 tooltip: Retrieves a list of attachments on an avatar. must-use: true @@ -6209,6 +6274,7 @@ functions: energy: 10.0 func-id: 277 return: list + slua-return: '{vector}' sleep: 0.0 tooltip: Returns the bounding box around the object (including any linked prims) relative to its root prim, as a list in the format [ (vector) min_corner, (vector) @@ -6418,6 +6484,7 @@ functions: func-id: 410 private: true return: list + slua-return: '{uuid}' sleep: 0.0 tooltip: '' must-use: true @@ -6548,9 +6615,9 @@ functions: tooltip: Inventory item type type: integer - Index: - index-semantics: true tooltip: Index number of inventory item. type: integer + index-semantics: true energy: 10.0 func-id: 147 return: string @@ -6729,9 +6796,9 @@ functions: tooltip: '' type: list - Index: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 194 native: true @@ -6859,9 +6926,9 @@ functions: tooltip: '' type: string - LineNumber: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 217 return: key @@ -6877,9 +6944,9 @@ functions: tooltip: '' type: string - LineNumber: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 549 return: string @@ -7406,10 +7473,10 @@ functions: - ScriptName: tooltip: '' type: string - bool-semantics: true energy: 10.0 func-id: 250 return: integer + bool-semantics: true sleep: 0.0 tooltip: Returns TRUE if the script named is running.\nReturns TRUE if ScriptName is running. @@ -7483,8 +7550,8 @@ functions: type: integer energy: 10.0 func-id: 46 - bool-semantics: true return: integer + bool-semantics: true sleep: 0.0 tooltip: Returns boolean value of the specified status (e.g. STATUS_PHANTOM) of the object the script is attached to. @@ -7495,13 +7562,13 @@ functions: tooltip: '' type: string - Start: - index-semantics: true tooltip: '' type: integer - - End: index-semantics: true + - End: tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 94 pure: true @@ -7899,9 +7966,9 @@ functions: tooltip: '' type: string - Position: - index-semantics: true tooltip: '' type: integer + index-semantics: true - SourceVariable: tooltip: '' type: string @@ -7944,10 +8011,10 @@ functions: - agent_id: tooltip: Agent ID of another agent in the region. type: key - bool-semantics: true energy: 10.0 func-id: 542 return: integer + bool-semantics: true sleep: 0.0 tooltip: Returns TRUE if avatar ID is a friend of the script owner. must-use: true @@ -8064,9 +8131,9 @@ functions: llKeysKeyValue: arguments: - First: - index-semantics: true tooltip: Index of the first key to return. type: integer + index-semantics: true - Count: tooltip: The number of keys to return. type: integer @@ -8398,9 +8465,9 @@ functions: tooltip: '' type: list - Index: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 187 native: true @@ -8416,9 +8483,9 @@ functions: tooltip: '' type: list - Index: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 186 native: true @@ -8449,9 +8516,9 @@ functions: tooltip: '' type: list - Index: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 189 native: true @@ -8462,23 +8529,26 @@ functions: specified list. If Index describes a location not in the list, or the value cannot be type-cast to a key, then null string is returned. llList2List: + type-arguments: [T] arguments: - ListVariable: tooltip: '' type: list + slua-type: '{T}' - Start: - index-semantics: true tooltip: '' type: integer - - End: index-semantics: true + - End: tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 192 native: true pure: true return: list + slua-return: '{T}' sleep: 0.0 tooltip: Returns a subset of entries from ListVariable, in a range specified by the Start and End indicies (inclusive).\nUsing negative numbers for Start and/or @@ -8486,28 +8556,31 @@ functions: -1 would capture the entire string.\nIf Start is greater than End, the sub string is the exclusion of the entries. llList2ListSlice: + type-arguments: [T] arguments: - ListVariable: tooltip: '' type: list + slua-type: '{T}' - Start: - index-semantics: true tooltip: '' type: integer - - End: index-semantics: true + - End: tooltip: '' type: integer + index-semantics: true - Stride: tooltip: '' type: integer - slice_index: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 801 return: list + slua-return: '{T}' sleep: 0.0 tooltip: Returns a subset of entries from ListVariable, in a range specified by Start and End indices (inclusive) return the slice_index element of each stride.\n @@ -8519,24 +8592,27 @@ functions: (e.g. A stride of 2 has valid indices 0,1) must-use: true llList2ListStrided: + type-arguments: [T] arguments: - ListVariable: tooltip: '' type: list + slua-type: '{T}' - Start: - index-semantics: true tooltip: '' type: integer - - End: index-semantics: true + - End: tooltip: '' type: integer + index-semantics: true - Stride: tooltip: '' type: integer energy: 10.0 func-id: 198 return: list + slua-return: '{T}' sleep: 0.0 tooltip: Copies the strided slice of the list from Start to End.\nReturns a copy of the strided slice of the specified list from Start to End. @@ -8547,9 +8623,9 @@ functions: tooltip: '' type: list - Index: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 191 native: true @@ -8565,9 +8641,9 @@ functions: tooltip: '' type: list - Index: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 188 native: true @@ -8583,9 +8659,9 @@ functions: tooltip: '' type: list - Index: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 190 native: true @@ -8605,8 +8681,8 @@ functions: type: list energy: 10.0 func-id: 201 - index-semantics: true return: integer + index-semantics: true sleep: 0.0 tooltip: Returns the index of the first instance of Find in ListVariable. Returns -1 if not found.\nReturns the position of the first instance of the Find list @@ -8621,13 +8697,13 @@ functions: tooltip: '' type: list - Instance: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 803 - index-semantics: true return: integer + index-semantics: true sleep: 0.0 tooltip: Returns the index of the nth instance of Find in ListVariable. Returns -1 if not found. @@ -8641,20 +8717,20 @@ functions: tooltip: '' type: list - Start: - index-semantics: true tooltip: '' type: integer - - End: index-semantics: true + - End: tooltip: '' type: integer + index-semantics: true - Stride: tooltip: '' type: integer energy: 10.0 func-id: 800 - index-semantics: true return: integer + index-semantics: true sleep: 0.0 tooltip: Returns the index of the first instance of Find in ListVariable. Returns -1 if not found.\nReturns the position of the first instance of the Find list @@ -8662,51 +8738,61 @@ functions: ListVariable by stride. Returns -1 if not found. must-use: true llListInsertList: + type-arguments: [T] arguments: - Target: tooltip: '' type: list + slua-type: '{T}' - ListVariable: tooltip: '' type: list + slua-type: '{T}' - Position: - index-semantics: true tooltip: '' type: integer + index-semantics: true energy: 10.0 func-id: 200 native: true pure: true return: list + slua-return: '{T}' sleep: 0.0 tooltip: Returns a list that contains all the elements from Target but with the elements from ListVariable inserted at Position start.\nReturns a new list, created by inserting ListVariable into the Target list at Position. Note this does not alter the Target. llListRandomize: + type-arguments: [T] arguments: - ListVariable: tooltip: '' type: list + slua-type: '{T}' - Stride: tooltip: '' type: integer energy: 10.0 func-id: 197 return: list + slua-return: '{T}' sleep: 0.0 tooltip: Returns a version of the input ListVariable which has been randomized by blocks of size Stride.\nIf the remainder from the length of the list, divided by the stride is non-zero, this function does not randomize the list. must-use: true llListReplaceList: + type-arguments: [T] arguments: - Target: tooltip: '' type: list + slua-type: '{T}' - ListVariable: tooltip: '' type: list + slua-type: '{T}' - Start: tooltip: '' type: integer @@ -8720,6 +8806,7 @@ functions: native: true pure: true return: list + slua-return: '{T}' sleep: 0.0 tooltip: Returns a list that is Target with Start through End removed and ListVariable inserted at Start.\nReturns a list replacing the slice of the Target list from @@ -8727,10 +8814,12 @@ functions: 0, 1 would replace the first two entries and 0, 0 would replace only the first list entry. llListSort: + type-arguments: [T] arguments: - ListVariable: tooltip: List to sort. type: list + slua-type: '{T}' - Stride: tooltip: Stride length. type: integer @@ -8742,16 +8831,19 @@ functions: energy: 10.0 func-id: 184 return: list + slua-return: '{T}' sleep: 0.0 tooltip: Returns the specified list, sorted into blocks of stride in ascending order (if Ascending is TRUE, otherwise descending). Note that sort only works if the first entry of each block is the same datatype. must-use: true llListSortStrided: + type-arguments: [T] arguments: - ListVariable: tooltip: List to sort. type: list + slua-type: '{T}' - Stride: tooltip: Stride length. type: integer @@ -8767,6 +8859,7 @@ functions: energy: 10.0 func-id: 802 return: list + slua-return: '{T}' sleep: 0.0 tooltip: Returns the specified list, sorted by the specified element into blocks of stride in ascending order (if Ascending is TRUE, otherwise descending). Note @@ -9175,9 +9268,11 @@ functions: - Text: tooltip: '' type: string + slua-type: string | uuid - ID: tooltip: '' type: key + slua-type: string | uuid energy: 10.0 func-id: 164 return: void @@ -9333,10 +9428,10 @@ functions: - ID: tooltip: '' type: key - bool-semantics: true energy: 10.0 func-id: 215 return: integer + bool-semantics: true sleep: 0.0 tooltip: Returns TRUE if id ID over land owned by the script owner, otherwise FALSE.\nReturns TRUE if key ID is over land owned by the object owner, FALSE @@ -9388,13 +9483,16 @@ functions: - Separators: tooltip: '' type: list + slua-type: '{string}' - Spacers: tooltip: '' type: list + slua-type: '{string}' energy: 10.0 func-id: 214 pure: true return: list + slua-return: '{string}' sleep: 0.0 tooltip: Converts Text into a list, discarding Separators, keeping Spacers (Separators and Spacers must be lists of strings, maximum of 8 each).\nSeparators and Spacers @@ -9407,13 +9505,16 @@ functions: - Separators: tooltip: '' type: list + slua-type: '{string}' - Spacers: tooltip: '' type: list + slua-type: '{string}' energy: 10.0 func-id: 285 pure: true return: list + slua-return: '{string}' sleep: 0.0 tooltip: Breaks Text into a list, discarding separators, keeping spacers, keeping any null values generated. (separators and spacers must be lists of strings, @@ -10052,6 +10153,7 @@ functions: energy: 10.0 func-id: 83 return: void + slua-removed: true sleep: 0.0 tooltip: Sets the time to zero.\nSets the internal timer to zero. llReturnObjectsByID: @@ -10333,10 +10435,10 @@ functions: - ID: tooltip: '' type: key - bool-semantics: true energy: 10.0 func-id: 219 return: integer + bool-semantics: true sleep: 0.0 tooltip: Returns TRUE if avatar ID is in the same region and has the same active group, otherwise FALSE.\nReturns TRUE if the object or agent identified is in @@ -10398,10 +10500,10 @@ functions: - Position: tooltip: '' type: vector - bool-semantics: true energy: 10.0 func-id: 246 return: integer + bool-semantics: true sleep: 0.0 tooltip: Returns TRUE if Position is over public land, sandbox land, land that doesn't allow everyone to edit and build, or land that doesn't allow outside @@ -11033,10 +11135,11 @@ functions: tooltip: The amount to reserve, which must be less than the allowed maximum (currently 64KB) and not already have been exceeded. type: integer - bool-semantics: true energy: 10.0 func-id: 369 return: integer + bool-semantics: true + slua-removed: true sleep: 0.0 tooltip: Requests Limit bytes to be reserved for this script.\nReturns TRUE or FALSE indicating whether the limit was set successfully.\nThis function has @@ -11079,13 +11182,13 @@ functions: PermissionMask on the object the script is attached to. llSetParcelForSale: arguments: - - ForSale: - tooltip: If TRUE, the parcel is put up for sale. - type: integer - bool-semantics: true - - Options: - tooltip: A list of options to set for the sale. - type: list + - ForSale: + tooltip: If TRUE, the parcel is put up for sale. + type: integer + bool-semantics: true + - Options: + tooltip: A list of options to set for the sale. + type: list energy: 10.0 func-id: 561 return: integer @@ -11401,6 +11504,7 @@ functions: energy: 10.0 func-id: 107 return: void + slua-removed: true sleep: 0.0 tooltip: Causes the timer event to be triggered every Rate seconds.\n Passing in 0.0 stops further timer events. @@ -11778,9 +11882,9 @@ functions: type: string energy: 10.0 func-id: 181 - index-semantics: true pure: true return: integer + index-semantics: true sleep: 0.0 tooltip: Returns an integer that is the index in Text where string pattern Sequence first appears. Returns -1 if not found. @@ -12181,10 +12285,10 @@ functions: - Algorithm: tooltip: 'The digest algorithm: sha1, sha224, sha256, sha384, sha512.' type: string - bool-semantics: true energy: 10.0 func-id: 540 return: integer + bool-semantics: true sleep: 0.0 tooltip: Returns TRUE if PublicKey, Message, and Algorithm produce the same base64-formatted Signature. diff --git a/pyproject.toml b/pyproject.toml index d02e92a..b23794d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ keywords = ["Linden Scripting Language", "Second Life"] [project.scripts] gen-lsl-definitions = "gen_definitions:main" -validate-lsl-definitions-via-jsonschema = "validate:validate_lsl_definitions_via_jsonschema" +validate-lsl-definitions-via-jsonschema = "validate:main" [project.urls] Homepage = "https://github.com/secondlife/lsl-definitions" diff --git a/slua_definitions.schema.json b/slua_definitions.schema.json new file mode 100644 index 0000000..d16a892 --- /dev/null +++ b/slua_definitions.schema.json @@ -0,0 +1,276 @@ +{ + "$schema": "http://json-schema.org/draft/2019-09/schema", + "$id": "http://raw.githubusercontent.com/secondlife/lsl-definitions/refs/heads/main/slua_definitions.schema.json", + "$comment": "This schema defines keywords for the Server Lua Language (SLua) of Second Life.", + "$defs": { + "identifier": { + "pattern": "^[_a-zA-Z][_a-zA-Z0-9]*$", + "type": "string" + }, + "type": { + "markdownDescription": "A luau-format type definition.", + "pattern": "^([ \n?&|,{}\\[\\]()\":a-zA-Z0-9_]|\\.\\.\\.|->)*$", + "type": "string" + }, + "property": { + "markdownDescription": "A property or constant.", + "additionalProperties": false, + "properties": { + "name": { "$ref": "#/$defs/identifier" }, + "type": { "$ref": "#/$defs/type" }, + "value": { + "markdownDescription": "The value of the constant.", + "type": ["number", "string"] + }, + "comment": { + "markdownDescription": "A brief description of this constant.", + "type": "string" + }, + "slua-removed": { + "const": true, + "markdownDescription": "This property is only present in Luau, not SLua.", + "type": "boolean" + } + }, + "required": ["name", "type"], + "type": "object" + }, + "type-alias": { + "markdownDescription": "A type alias.", + "additionalProperties": false, + "properties": { + "name": { "$ref": "#/$defs/identifier" }, + "definition": { "$ref": "#/$defs/type" }, + "comment": { + "markdownDescription": "A brief description of this alias.", + "type": "string" + }, + "export": { + "const": true, + "markdownDescription": "Whether this type is available to users.", + "type": "boolean" + } + }, + "required": ["name", "definition"], + "type": "object" + }, + "function-parameter": { + "markdownDescription": "A function parameter.", + "additionalProperties": false, + "properties": { + "name": { "oneOf": [ + { "$ref": "#/$defs/identifier" }, + { "const": "...", "type": "string" } + ]}, + "type": { "$ref": "#/$defs/type" }, + "comment": { + "markdownDescription": "A brief description of this parameter.", + "type": "string" + } + }, + "required": ["name"], + "type": "object" + }, + "function-anon": { + "markdownDescription": "A plain function signature; no name or overloads.", + "additionalProperties": false, + "properties": { + "typeParameters": { + "items": { + "pattern": "^(\\.\\.\\.)?[_a-zA-Z][_a-zA-Z0-9]*(\\.\\.\\.)?$", + "type": "string" + }, + "type": "array" + }, + "parameters": { + "items": { "$ref": "#/$defs/function-parameter" }, + "type": "array" + }, + "returnType": { "$ref": "#/$defs/type" }, + "comment": { + "markdownDescription": "A brief description of this function.", + "type": "string" + } + }, + "required": [], + "type": "object" + }, + "function": { + "markdownDescription": "A full function signature.", + "additionalProperties": false, + "properties": { + "name": { "$ref": "#/$defs/identifier" }, + "typeParameters": { + "items": { + "pattern": "^(\\.\\.\\.)?[_a-zA-Z][_a-zA-Z0-9]*(\\.\\.\\.)?$", + "type": "string" + }, + "type": "array" + }, + "parameters": { + "items": { "$ref": "#/$defs/function-parameter" }, + "type": "array" + }, + "returnType": { "$ref": "#/$defs/type" }, + "overloads": { + "items": { "$ref": "#/$defs/function-anon" }, + "type": "array" + }, + "deprecated": { + "const": true, + "markdownDescription": "Function is deprecated.", + "type": "boolean" + }, + "private": { + "const": true, + "markdownDescription": "Don't include in documentation.", + "type": "boolean" + }, + "comment": { + "markdownDescription": "A brief description of this function.", + "type": "string" + } + }, + "required": ["name"], + "type": "object" + }, + "class": { + "markdownDescription": "A type with properties and methods.", + "additionalProperties": false, + "properties": { + "name": { "$ref": "#/$defs/identifier" }, + "properties": { + "items": { "$ref": "#/$defs/property" }, + "type": "array" + }, + "methods": { + "items": { "$ref": "#/$defs/function" }, + "type": "array" + }, + "comment": { + "markdownDescription": "A brief description of this type.", + "type": "string" + } + }, + "required": ["name"], + "type": "object" + }, + "module": { + "markdownDescription": "A table with constants and functions.", + "additionalProperties": false, + "properties": { + "name": { "$ref": "#/$defs/identifier" }, + "callable": { "$ref": "#/$defs/function" }, + "constants": { + "items": { "$ref": "#/$defs/property" }, + "type": "array" + }, + "functions": { + "items": { "$ref": "#/$defs/function" }, + "type": "array" + }, + "comment": { + "markdownDescription": "A brief description of this type.", + "type": "string" + } + }, + "required": ["name", "comment"], + "type": "object" + } + }, + "additionalProperties": false, + "properties": { + "version": { + "markdownDescription": "Only increment with file format changes.", + "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$", + "type": "string" + }, + "baseClasses": { + "items": { "$ref": "#/$defs/class" }, + "type": "array" + }, + "typeAliases": { + "items": { "$ref": "#/$defs/type-alias" }, + "type": "array" + }, + "classes": { + "items": { "$ref": "#/$defs/class" }, + "type": "array" + }, + "globalVariables": { + "items": { "$ref": "#/$defs/property" }, + "type": "array" + }, + "globalFunctions": { + "items": { "$ref": "#/$defs/function" }, + "type": "array" + }, + "modules": { + "items": { "$ref": "#/$defs/module" }, + "type": "array" + }, + "constants": { + "items": { "$ref": "#/$defs/property" }, + "type": "array" + }, + "builtinConstants": { + "items": { "$ref": "#/$defs/property" }, + "type": "array" + }, + "builtinFunctions": { + "items": { "$ref": "#/$defs/function" }, + "type": "array" + }, + "controls": { + "markdownDescription": "The Luau keywords.", + "additionalProperties": false, + "patternProperties": { + "^(?:[a-z]+)$": { + "properties": { + "tooltip": { + "markdownDescription": "A brief description of this keyword.", + "type": "string" + } + }, + "required": ["tooltip"], + "type": "object" + } + }, + "type": "object" + }, + "builtinTypes": { + "markdownDescription": "The Luau builtin types.", + "additionalProperties": false, + "patternProperties": { + "^[a-z]*": { + "properties": { + "tooltip": { + "markdownDescription": "A brief description of this type.", + "type": "string" + } + }, + "required": [ + "tooltip" + ], + "type": "object" + } + }, + "type": "object" + } + }, + "required": [ + "version", + "baseClasses", + "typeAliases", + "classes", + "globalFunctions", + "modules", + "constants", + "controls", + "builtinTypes", + "builtinConstants", + "builtinFunctions" + ], + "title": "Second Life SLua Definitions", + "type": "object" +} diff --git a/slua_definitions.yaml b/slua_definitions.yaml new file mode 100644 index 0000000..f0da3e0 --- /dev/null +++ b/slua_definitions.yaml @@ -0,0 +1,2418 @@ +%YAML 1.2 +--- +# yaml-language-server: $schema=http://raw.githubusercontent.com/secondlife/lsl-definitions/refs/heads/main/slua_definitions.schema.json +# +# increment only when the file format changes, not just the content +version: 1.0.0 +# baseClasses must not depend on anything else in this file (not typeAliases, not classes) +baseClasses: +- name: quaternion + comment: A set of four float values. Used to represent rotations and orientations. + methods: + - name: __add + parameters: + - name: self + - name: other + type: quaternion + returnType: quaternion + - name: __sub + parameters: + - name: self + - name: other + type: quaternion + returnType: quaternion + - name: __mul + parameters: + - name: self + - name: other + type: quaternion + returnType: quaternion + - name: __div + parameters: + - name: self + - name: other + type: quaternion + returnType: quaternion + - name: __unm + parameters: + - name: self + returnType: quaternion + - name: __eq + parameters: + - name: self + - name: other + type: quaternion + returnType: boolean + - name: __tostring + parameters: + - name: self + returnType: string + properties: + - name: x + type: number + - name: "y" + type: number + - name: z + type: number + - name: s + type: number +- name: uuid + comment: A 128‑bit unique identifier formatted as 36 hexadecimal characters (8‑4‑4‑4‑12), e.g. "A822FF2B-FF02-461D-B45D-DCD10A2DE0C2". + methods: + - name: __tostring + parameters: + - name: self + returnType: string + properties: + - name: istruthy + comment: Returns true if the UUID is not the null UUID (all zeros) + type: boolean + - name: bytes + comment: Returns the raw 16-byte binary string of the UUID, or nil if the UUID + is not in a compressed state + type: string? +- name: vector + comment: A set of three float values. Used to represent colors (RGB), positions, directions, and velocities. + methods: + - name: __add + comment: Native component-wise addition + parameters: + - name: self + - name: other + type: vector + returnType: vector + - name: __sub + comment: Native component-wise subtraction + parameters: + - name: self + - name: other + type: vector + returnType: vector + - name: __unm + comment: Unary negation + parameters: + - name: self + returnType: vector + - name: __mul + comment: 'Multiplication: vector * vector / number -> vector (Scale), vector + * quaternion -> vector (Rotation)' + parameters: + - name: self + - name: other + type: number | vector | quaternion + returnType: vector + - name: __div + comment: 'Division: vector / number -> vector (Scale), vector / quaternion -> + vector (Rotation by inverse)' + parameters: + - name: self + - name: other + type: number | vector | quaternion + returnType: vector + - name: __mod + comment: 'LSL-style modulo: vector % vector -> vector (Cross Product)' + parameters: + - name: self + - name: other + type: vector + returnType: vector + - name: __tostring + parameters: + - name: self + returnType: string + properties: + - name: x + type: number + - name: "y" + type: number + - name: z + type: number +- name: DetectedEvent + comment: Event detection class providing access to detected object/avatar information + # auto-generated from lsl_definitions.yaml + methods: [] + properties: + - name: index + type: number + - name: valid + type: boolean + - name: canAdjustDamage + type: boolean +typeAliases: +- name: rotation + comment: '''rotation'' is an alias for ''quaternion''' + export: true + definition: quaternion +- name: list + export: true + definition: "{string | number | vector | uuid | quaternion | boolean}" +- name: LLDetectedEventName + # auto-generated from lsl_definitions.yaml + definition: "{}" +- name: LLNonDetectedEventName + # auto-generated from lsl_definitions.yaml + definition: "{}" +- name: LLEventName + definition: LLDetectedEventName | LLNonDetectedEventName +- name: LLEventHandler + # auto-generated from lsl_definitions.yaml + definition: (...any) -> () +- name: LLDetectedEventHandler + definition: "(detected: {DetectedEvent}) -> ()" +- name: LLTimerEveryCallback + comment: Callback type for LLTimers.every() - receives scheduled time and interval + definition: "(scheduled: number, interval: number) -> ()" +- name: LLTimerOnceCallback + comment: Callback type for LLTimers.once() - receives scheduled time + definition: "(scheduled: number) -> ()" +- name: LLTimerCallback + comment: Union of timer callback types + definition: LLTimerEveryCallback | LLTimerOnceCallback +- name: OsDateTime + comment: Date/time table structure used by os.date and os.time + export: true + definition: |- + { + year: number, + month: number, + day: number, + hour: number?, + min: number?, + sec: number?, + wday: number?, + yday: number?, + isdst: boolean?, + } +classes: +- name: LLEvents + comment: Event registration and management class for Second Life events + methods: + - name: 'on' + comment: Registers a callback for an event. Returns the callback. + parameters: + - name: self + - name: event + type: LLEventName + - name: callback + type: LLEventHandler + returnType: LLEventHandler + - name: 'off' + comment: Unregisters a callback. Returns true if found and removed. + parameters: + - name: self + - name: event + type: LLEventName + - name: callback + type: LLEventHandler + returnType: boolean + - name: once + comment: Registers a one-time callback. Returns the wrapper function. + parameters: + - name: self + - name: event + type: LLEventName + - name: callback + type: LLEventHandler + returnType: LLEventHandler + - name: listeners + comment: Returns a list of all listeners for a specific event. + parameters: + - name: self + - name: event + type: LLEventName + returnType: '{LLEventHandler}' + - name: eventNames + comment: Returns a list of all event names that have listeners. + parameters: + - name: self + returnType: '{string}' +- name: LLTimers + comment: Timer management class for scheduling periodic and one-time callbacks + methods: + - name: every + comment: Registers a callback to be called every N seconds. Returns the callback. + parameters: + - name: self + - name: seconds + type: number + - name: callback + type: LLTimerEveryCallback + returnType: LLTimerCallback + - name: once + comment: Registers a callback to be called once after N seconds. Returns the + callback. + parameters: + - name: self + - name: seconds + type: number + - name: callback + type: LLTimerOnceCallback + returnType: LLTimerCallback + - name: 'off' + comment: Unregisters a timer callback. Returns true if found and removed. + parameters: + - name: self + - name: callback + type: LLTimerCallback + returnType: boolean +globalVariables: +- name: rotation + comment: rotation is an alias for quaternion + type: typeof(quaternion) +- name: loadstring + comment: loadstring is removed in SLua + slua-removed: true + type: nil +- name: getfenv + comment: getfenv is removed in SLua + slua-removed: true + type: nil +- name: setfenv + comment: setfenv is removed in SLua + slua-removed: true + type: nil +globalFunctions: +- name: dangerouslyexecuterequiredmodule + comment: Dangerously executes a required module function + parameters: + - name: f + type: (...any) -> ...any + returnType: '...any' +- name: touuid + comment: Converts a string, buffer, or uuid to a uuid, returns nil if invalid + parameters: + - name: val + type: string | buffer | uuid + returnType: uuid? +- name: tovector + comment: Converts a value to a vector, returns nil if invalid + parameters: + - name: val + type: any + returnType: vector? +- name: toquaternion + comment: Converts a value to a quaternion, returns nil if invalid + parameters: + - name: val + type: any + returnType: quaternion? +- name: torotation + comment: Converts a value to a rotation (quaternion), returns nil if invalid + parameters: + - name: val + type: any + returnType: quaternion? +modules: +- name: bit32 + comment: Bitwise operations library. + functions: + - name: arshift + comment: |- + Shifts n by i bits to the right. If i is negative, a left shift is performed. + Does an arithmetic shift: The most significant bit of n is propagated during the shift. + parameters: + - name: "n" + comment: Number to shift. + type: number + - name: i + comment: Number of bits to shift. + type: number + returnType: number + - name: band + comment: Performs a bitwise AND operation on input numbers. + parameters: + - name: ... + comment: Numbers to perform bitwise AND on. + type: ...number + returnType: number + - name: bnot + comment: Returns the bitwise negation of the input number. + parameters: + - name: "n" + comment: Number to negate. + type: number + returnType: number + - name: bor + comment: Performs a bitwise OR operation on input numbers. + parameters: + - name: ... + comment: Numbers to perform bitwise OR on. + type: ...number + returnType: number + - name: bxor + comment: Performs a bitwise XOR operation on input numbers. + parameters: + - name: ... + comment: Numbers to perform bitwise XOR on. + type: ...number + returnType: number + - name: btest + comment: |- + Performs a bitwise AND operation on input numbers. + Returns true if result is non-zero. + parameters: + - name: ... + comment: Numbers to perform bitwise AND on. + type: ...number + returnType: boolean + - name: extract + comment: Extracts bits from n at position field with width + parameters: + - name: "n" + type: number + - name: field + type: number + - name: width + type: number? + returnType: number + - name: lrotate + comment: Rotates n by i bits to the left. If i is negative, a right rotate is performed. + parameters: + - name: "n" + comment: Number to rotate. + type: number + - name: i + comment: Number of bits to rotate. + type: number + returnType: number + - name: lshift + comment: Shifts n by i bits to the left. If i is negative, a right shift is performed. + parameters: + - name: "n" + comment: Number to shift. + type: number + - name: i + comment: Number of bits to shift. + type: number + returnType: number + - name: replace + comment: Replaces bits in n at position field with width using value v + parameters: + - name: "n" + type: number + - name: v + type: number + - name: field + type: number + - name: width + type: number? + returnType: number + - name: rrotate + comment: Rotates n by i bits to the right. If i is negative, a left rotate is performed. + parameters: + - name: "n" + comment: Number to rotate. + type: number + - name: i + comment: Number of bits to rotate. + type: number + returnType: number + - name: rshift + comment: Shifts n by i bits to the right. If i is negative, a left shift is performed. + parameters: + - name: "n" + comment: Number to shift. + type: number + - name: i + comment: Number of bits to shift. + type: number + returnType: number + - name: countlz + comment: Count leading zeros + parameters: + - name: "n" + type: number + returnType: number + - name: countrz + comment: Count trailing zeros + parameters: + - name: "n" + type: number + returnType: number + - name: byteswap + comment: Swap byte order + parameters: + - name: "n" + type: number + returnType: number +- name: buffer + comment: Buffer manipulation library for binary data. + functions: + - name: create + comment: Creates a buffer of the requested size with all bytes initialized to 0. + parameters: + - name: size + comment: Size of the buffer to create. + type: number + returnType: buffer + - name: fromstring + comment: Creates a buffer initialized to the contents of the string. + parameters: + - name: str + comment: String to initialize the buffer with. + type: string + returnType: buffer + - name: tostring + comment: Returns the buffer data as a string. + parameters: + - name: b + comment: Buffer to convert to a string. + type: buffer + returnType: string + - name: readi8 + comment: Reads a signed 8-bit integer from the buffer at the given offset. + parameters: + - name: b + comment: Buffer to read from. + type: buffer + - name: offset + comment: Byte offset to read from. + type: number + returnType: number + - name: readu8 + comment: Reads an unsigned 8-bit integer from the buffer at the given offset. + parameters: + - name: b + comment: Buffer to read from. + type: buffer + - name: offset + comment: Byte offset to read from. + type: number + returnType: number + - name: readi16 + comment: Reads a signed 16-bit integer from the buffer at the given offset. + parameters: + - name: b + comment: Buffer to read from. + type: buffer + - name: offset + comment: Byte offset to read from. + type: number + returnType: number + - name: readu16 + comment: Reads an unsigned 16-bit integer from the buffer at the given offset. + parameters: + - name: b + comment: Buffer to read from. + type: buffer + - name: offset + comment: Byte offset to read from. + type: number + returnType: number + - name: readi32 + comment: Reads a signed 32-bit integer from the buffer at the given offset. + parameters: + - name: b + comment: Buffer to read from. + type: buffer + - name: offset + comment: Byte offset to read from. + type: number + returnType: number + - name: readu32 + comment: Reads an unsigned 32-bit integer from the buffer at the given offset. + parameters: + - name: b + comment: Buffer to read from. + type: buffer + - name: offset + comment: Byte offset to read from. + type: number + returnType: number + - name: readf32 + comment: Reads a 32-bit floating-point number from the buffer at the given offset. + parameters: + - name: b + comment: Buffer to read from. + type: buffer + - name: offset + comment: Byte offset to read from. + type: number + returnType: number + - name: readf64 + comment: Reads a 64-bit floating-point number from the buffer at the given offset. + parameters: + - name: b + comment: Buffer to read from. + type: buffer + - name: offset + comment: Byte offset to read from. + type: number + returnType: number + - name: writei8 + comment: Writes a signed 8-bit integer to the buffer at the given offset. + parameters: + - name: b + comment: Buffer to write to. + type: buffer + - name: offset + comment: Byte offset to write at. + type: number + - name: value + comment: Value to write. + type: number + returnType: () + - name: writeu8 + comment: Writes an unsigned 8-bit integer to the buffer at the given offset. + parameters: + - name: b + comment: Buffer to write to. + type: buffer + - name: offset + comment: Byte offset to write at. + type: number + - name: value + comment: Value to write. + type: number + returnType: () + - name: writei16 + comment: Writes a signed 16-bit integer to the buffer at the given offset. + parameters: + - name: b + comment: Buffer to write to. + type: buffer + - name: offset + comment: Byte offset to write at. + type: number + - name: value + comment: Value to write. + type: number + returnType: () + - name: writeu16 + comment: Writes an unsigned 16-bit integer to the buffer at the given offset. + parameters: + - name: b + comment: Buffer to write to. + type: buffer + - name: offset + comment: Byte offset to write at. + type: number + - name: value + comment: Value to write. + type: number + returnType: () + - name: writei32 + comment: Writes a signed 32-bit integer to the buffer at the given offset. + parameters: + - name: b + comment: Buffer to write to. + type: buffer + - name: offset + comment: Byte offset to write at. + type: number + - name: value + comment: Value to write. + type: number + returnType: () + - name: writeu32 + comment: Writes an unsigned 32-bit integer to the buffer at the given offset. + parameters: + - name: b + comment: Buffer to write to. + type: buffer + - name: offset + comment: Byte offset to write at. + type: number + - name: value + comment: Value to write. + type: number + returnType: () + - name: writef32 + comment: Writes a 32-bit floating-point number to the buffer at the given offset. + parameters: + - name: b + comment: Buffer to write to. + type: buffer + - name: offset + comment: Byte offset to write at. + type: number + - name: value + comment: Value to write. + type: number + returnType: () + - name: writef64 + comment: Writes a 64-bit floating-point number to the buffer at the given offset. + parameters: + - name: b + comment: Buffer to write to. + type: buffer + - name: offset + comment: Byte offset to write at. + type: number + - name: value + comment: Value to write. + type: number + returnType: () + - name: readstring + comment: Reads a string of the given length from the buffer at the specified offset. + parameters: + - name: b + comment: Buffer to read from. + type: buffer + - name: offset + comment: Byte offset to start reading. + type: number + - name: count + comment: Number of bytes to read. + type: number + returnType: string + - name: writestring + comment: Writes data from a string into the buffer at the specified offset. + parameters: + - name: b + comment: Buffer to write to. + type: buffer + - name: offset + comment: Byte offset to write at. + type: number + - name: value + comment: String to write. + type: string + - name: count + comment: Number of bytes to write (optional). + type: number? + returnType: () + - name: len + comment: Returns the size of the buffer in bytes. + parameters: + - name: b + comment: Buffer to get the size of. + type: buffer + returnType: number + - name: copy + comment: Copies bytes from the source buffer into the target buffer. + parameters: + - name: target + comment: Target buffer to copy into. + type: buffer + - name: targetOffset + comment: Offset in target buffer. + type: number + - name: source + comment: Source buffer to copy from. + type: buffer + - name: sourceOffset + comment: Offset in source buffer (optional). + type: number? + - name: count + comment: Number of bytes to copy (optional). + type: number? + returnType: () + - name: fill + comment: Fills the buffer with the specified value starting at the given offset. + parameters: + - name: b + comment: Buffer to fill. + type: buffer + - name: offset + comment: Byte offset to start filling. + type: number + - name: value + comment: Value to fill with. + type: number + - name: count + comment: Number of bytes to fill (optional). + type: number? + returnType: () + - name: readbits + comment: Reads up to 32 bits from the buffer at the given offset. + parameters: + - name: b + comment: Buffer to read from. + type: buffer + - name: bitOffset + comment: Bit offset to read at. + type: number + - name: bitCount + comment: Number of bits to read. Must be in [0, 32] range. + type: number + returnType: number + - name: writebits + comment: Writes up to 32 bits to the buffer at the given offset. + parameters: + - name: b + comment: Buffer to write to. + type: buffer + - name: bitOffset + comment: Bit offset to write at. + type: number + - name: bitCount + comment: Number of bits to write. Must be in [0, 32] range. + type: number + - name: value + comment: Source of bits to write. + type: number + returnType: () +- name: coroutine + comment: Coroutine manipulation library. + functions: + - name: create + comment: Returns a new coroutine that, when resumed, will run function f. + parameters: + - name: f + comment: A function to be executed by the new coroutine. + type: (...any) -> ...any + returnType: thread + - name: resume + comment: Resumes a coroutine, returning true and results if successful, or false and an error. + parameters: + - name: co + comment: The coroutine to resume. + type: thread + - name: ... + comment: Arguments to pass to the coroutine. + type: ...any + returnType: (boolean, ...any) + - name: running + comment: Returns the currently running coroutine, or nil if called from in the main coroutine. + parameters: [] + returnType: thread? + - name: status + comment: 'Returns the status of the coroutine: "running", "suspended", "normal", or "dead".' + parameters: + - name: co + comment: The coroutine to check status of. + type: thread + returnType: '"running" | "suspended" | "normal" | "dead"' + - name: wrap + comment: Creates a coroutine and returns a function that resumes it. + parameters: + - name: f + comment: A function to execute in a coroutine. + type: (...any) -> ...any + returnType: (...any) -> ...any + - name: yield + comment: Yields the current coroutine, passing arguments to the resuming code. + parameters: + - name: ... + comment: Values to pass to the resuming code. + type: ...any + returnType: '...any' + - name: isyieldable + comment: Returns true if the currently running coroutine can yield. + parameters: [] + returnType: boolean + - name: close + comment: Closes a coroutine, returning true if successful or false and an error. + parameters: + - name: co + comment: The coroutine to close. + type: thread + returnType: (boolean, string?) +- name: debug + comment: Debug library for introspection. + functions: + - name: info + comment: Returns information about a stack frame or function based on specified format. + overloads: + - comment: Returns information about a stack level + parameters: + - name: level + comment: Stack level or function reference for inspection. + type: number + - name: s + comment: String specifying requested information. + type: string + returnType: '...any' + - comment: Returns information about a function + parameters: + - name: func + comment: Function reference. + type: (...any) -> ...any + - name: s + comment: String specifying requested information. + type: string + returnType: '...any' + parameters: + - name: co + comment: Optional thread or function reference. + type: thread | ((...any) -> ...any) | number + - name: level + comment: Stack level or function reference for inspection. + type: number + - name: s + comment: String specifying requested information. + type: string + returnType: '...any' + - name: traceback + comment: Returns a human-readable call stack starting from the specified level. + overloads: + - comment: Returns a string with a traceback of the current call stack + parameters: + - name: message + comment: Optional message prepended to the traceback. + type: string? + - name: level + comment: Optional stack level to start traceback. + type: number? + returnType: string + parameters: + - name: co + comment: Optional thread reference for traceback. + type: thread + - name: msg + comment: Optional message prepended to the traceback. + type: string? + - name: level + comment: Optional stack level to start traceback. + type: number? + returnType: string + - name: getinfo + comment: Returns a table containing debug information about a function or stack frame. + parameters: + - name: thread + comment: Optional thread whose stack frame is being inspected. + type: thread + - name: function + comment: Function reference or stack level number. + type: ((...any) -> ...any) | number + - name: what + comment: String specifying which fields to retrieve. + type: string + private: true + returnType: "{[any]: any}" + - name: getlocal + comment: Returns the name and value of a local variable at the specified stack level. + parameters: + - name: level + comment: Stack level number. + type: number + - name: index + comment: Index of the local variable. + type: number + private: true + returnType: string | any + - name: setlocal + comment: Sets the value of a local variable at the specified stack level. + parameters: + - name: level + comment: Stack level number. + type: number + - name: index + comment: Index of the local variable. + type: number + - name: value + comment: New value for the local variable. + type: any + private: true + returnType: boolean + - name: getupvalue + comment: Returns the name and value of an upvalue for a given function. + parameters: + - name: function + comment: Function whose upvalues are being retrieved. + type: (...any) -> ...any + - name: index + comment: Index of the upvalue. + type: number + private: true + returnType: string | any + - name: setupvalue + comment: Sets the value of an upvalue for a given function. + parameters: + - name: function + comment: Function whose upvalues are being modified. + type: (...any) -> ...any + - name: index + comment: Index of the upvalue. + type: number + - name: value + comment: New value for the upvalue. + type: any + private: true + returnType: string + - name: getmetatable + comment: Returns the metatable of the given value, if any. + parameters: + - name: value + comment: Value whose metatable is retrieved. + type: any + private: true + returnType: "{[any]: any}?" + - name: setmetatable + comment: Sets the metatable for a given value. + parameters: + - name: value + comment: Value whose metatable is to be set. + type: any + - name: metatable + comment: Table to be set as the new metatable. + type: "{[any]: any}?" + private: true + returnType: any +- name: llbase64 + comment: Base64 encoding/decoding library. + functions: + - name: encode + comment: Encodes a string or buffer to base64 + parameters: + - name: data + type: string | buffer + returnType: string + - name: decode + comment: Decodes a base64 string to a string + overloads: + - comment: Decodes a base64 string to a string or buffer + parameters: + - name: data + type: string + - name: asBuffer + type: boolean? + returnType: string | buffer + parameters: + - name: data + type: string + returnType: string +- name: lljson + comment: JSON encoding/decoding library for Second Life. + functions: + - name: encode + comment: Encodes a Lua value as JSON + parameters: + - name: value + type: any + returnType: string + - name: decode + comment: Decodes a JSON string to a Lua value + parameters: + - name: json + type: string + returnType: any + - name: slencode + comment: Encodes a Lua value as JSON preserving SL types. Use tight to encode + more compactly. + parameters: + - name: value + type: any + - name: tight + type: boolean? + returnType: string + - name: sldecode + comment: Decodes a JSON string to a Lua value preserving SL types + parameters: + - name: json + type: string + returnType: any + constants: + - name: 'null' + comment: A constant to pass for null to json encode + type: any + - name: empty_array_mt + comment: Metatable for declaring table as an empty array for json encode + type: '{ [any]: any }' + value: '{}' + - name: array_mt + comment: Metatable for declaring table as an array for json encode + type: '{ [any]: any }' + value: '{}' + - name: empty_array + comment: A constant to pass for an empty array to json encode + type: any + - name: _NAME + comment: Name of the lljson library + type: string + value: lljson + - name: _VERSION + comment: Version of the lljson library + type: string + value: "2.1.0.11" +- name: math + comment: Mathematical functions library. + functions: + - name: abs + comment: Returns the absolute value of n. + parameters: + - name: "n" + comment: A number. + type: number + returnType: number + - name: acos + comment: Returns the arc cosine of n in radians. + parameters: + - name: "n" + comment: A number in the range [-1, 1]. + type: number + returnType: number + - name: asin + comment: Returns the arc sine of n in radians. + parameters: + - name: "n" + comment: A number in the range [-1, 1]. + type: number + returnType: number + - name: atan + comment: Returns the arc tangent of n in radians. + parameters: + - name: "n" + comment: A number. + type: number + returnType: number + - name: atan2 + comment: Returns the arc tangent of y/x in radians, using the signs to determine + the quadrant. + parameters: + - name: "y" + comment: The y-coordinate. + type: number + - name: x + comment: The x-coordinate. + type: number + returnType: number + - name: ceil + comment: Returns the smallest integer larger than or equal to n. + parameters: + - name: "n" + comment: A number to round up. + type: number + returnType: number + - name: clamp + comment: Returns n clamped between min and max. + parameters: + - name: "n" + comment: The value to be clamped. + type: number + - name: min + comment: Minimum allowable value. + type: number + - name: max + comment: Maximum allowable value. + type: number + returnType: number + - name: cos + comment: Returns the cosine of n (n is in radians). + parameters: + - name: "n" + comment: An angle in radians. + type: number + returnType: number + - name: cosh + comment: Returns the hyperbolic cosine of n. + parameters: + - name: "n" + comment: A number to compute the hyperbolic cosine of. + type: number + returnType: number + - name: deg + comment: Converts n from radians to degrees. + parameters: + - name: "n" + comment: A value in radians. + type: number + returnType: number + - name: exp + comment: Returns the base-e exponent of n. + parameters: + - name: "n" + comment: A number to compute e^n. + type: number + returnType: number + - name: floor + comment: Returns the largest integer smaller than or equal to n. + parameters: + - name: "n" + comment: A number to round down. + type: number + returnType: number + - name: fmod + comment: Returns the remainder of x modulo y, rounded towards zero. + parameters: + - name: x + comment: The dividend. + type: number + - name: "y" + comment: The divisor. + type: number + returnType: number + - name: frexp + comment: Returns m and e such that n = m * 2^e. + parameters: + - name: "n" + comment: A number to split into significand and exponent. + type: number + returnType: (number, number) + - name: ldexp + comment: Returns s * 2^e. + parameters: + - name: s + comment: The significand. + type: number + - name: e + comment: The exponent. + type: number + returnType: number + - name: lerp + comment: Linearly interpolates between a and b using factor t. + parameters: + - name: a + comment: Start value. + type: number + - name: b + comment: End value. + type: number + - name: t + comment: Interpolation factor. + type: number + returnType: number + - name: log + comment: Returns the logarithm of n in the given base (default e). + parameters: + - name: "n" + comment: A number to compute logarithm. + type: number + - name: base + comment: Base of the logarithm (default is e). + type: number? + returnType: number + - name: log10 + comment: Returns the base-10 logarithm of n. + parameters: + - name: "n" + comment: A number to compute base-10 logarithm. + type: number + returnType: number + - name: map + comment: Maps n from input range to output range. + parameters: + - name: "n" + comment: A number. + type: number + - name: inMin + comment: A number. + type: number + - name: inMax + comment: A number. + type: number + - name: outMin + comment: A number. + type: number + - name: outMax + comment: A number. + type: number + returnType: number + - name: max + comment: Returns the maximum value from the given numbers. + parameters: + - name: "n" + comment: A number. + type: number + - name: ... + comment: Numbers to find the maximum from. + type: ...number + returnType: number + - name: min + comment: Returns the minimum value from the given numbers. + parameters: + - name: "n" + comment: A number. + type: number + - name: ... + comment: Numbers to find the minimum from. + type: ...number + returnType: number + - name: modf + comment: Returns the integer and fractional parts of n. + parameters: + - name: "n" + comment: A number to split into integer and fractional parts. + type: number + returnType: (number, number) + - name: noise + comment: Returns Perlin noise value for the point (x, y, z). + parameters: + - name: x + comment: X coordinate for the noise function. + type: number + - name: "y" + comment: Y coordinate for the noise function (default is 0). + type: number? + - name: z + comment: Z coordinate for the noise function (default is 0). + type: number? + returnType: number + - name: pow + comment: Returns base to the power of exponent. + parameters: + - name: base + comment: Base value. + type: number + - name: exponent + comment: Exponent value. + type: number + returnType: number + - name: rad + comment: Converts n from degrees to radians. + parameters: + - name: "n" + comment: A value in degrees. + type: number + returnType: number + - name: random + comment: Returns a random number within the given range. + parameters: + - name: min + comment: Minimum value of the range (optional). + type: number? + - name: max + comment: Maximum value of the range (optional). + type: number? + returnType: number + - name: randomseed + comment: Sets the seed for the random number generator. + parameters: + - name: seed + comment: Seed for the random number generator. + type: number + returnType: () + - name: round + comment: Rounds n to the nearest integer. + parameters: + - name: "n" + comment: A number to round to the nearest integer. + type: number + returnType: number + - name: sign + comment: Returns -1 if n is negative, 1 if positive, and 0 if zero. + parameters: + - name: "n" + comment: A number to get the sign of. + type: number + returnType: number + - name: sin + comment: Returns the sine of n (n is in radians). + parameters: + - name: "n" + comment: An angle in radians. + type: number + returnType: number + - name: sinh + comment: Returns the hyperbolic sine of n. + parameters: + - name: "n" + comment: A number to compute the hyperbolic sine of. + type: number + returnType: number + - name: sqrt + comment: Returns the square root of n. + parameters: + - name: "n" + comment: A number to compute the square root of. + type: number + returnType: number + - name: tan + comment: Returns the tangent of n (n is in radians). + parameters: + - name: "n" + comment: An angle in radians. + type: number + returnType: number + - name: tanh + comment: Returns the hyperbolic tangent of n. + parameters: + - name: "n" + comment: A number to compute the hyperbolic tangent of. + type: number + returnType: number + - name: isnan + comment: Returns true if n is NaN. + parameters: + - name: "n" + comment: A number. + type: number + returnType: boolean + - name: isinf + comment: Returns true if n is infinite. + parameters: + - name: "n" + comment: A number. + type: number + returnType: boolean + - name: isfinite + comment: Returns true if n is finite. + parameters: + - name: "n" + comment: A number. + type: number + returnType: boolean + constants: + - name: pi + comment: The value of pi + type: number + value: 3.141592653589793 + - name: huge + comment: A value larger than any other numeric value (infinity) + type: number + value: inf +- name: os + comment: Operating system facilities library. + functions: + - name: clock + comment: Returns a high-precision timestamp in seconds for measuring durations. + parameters: [] + returnType: number + - name: date + comment: Returns a table or string representation of the time based on the provided format. + parameters: + - name: s + comment: Optional format string for the date representation. + type: string? + - name: t + comment: Optional timestamp to format; defaults to the current time. + type: number? + returnType: (string | OsDateTime)? + - name: difftime + comment: Returns the difference in seconds between two timestamps. + parameters: + - name: a + comment: First timestamp value. + type: number + - name: b + comment: Second timestamp value. + type: number? + returnType: number + - name: time + comment: Returns the current Unix timestamp or the timestamp of the given date. + parameters: + - name: t + comment: Optional table with date/time fields; returns the corresponding Unix timestamp. + type: OsDateTime? + returnType: number? +- name: quaternion + comment: Quaternion manipulation library. + callable: + name: quaternion + comment: Creates a new quaternion with the given component values. + Alias of quaternion.create. + parameters: + - name: x + comment: X component of the quaternion. + type: number + - name: "y" + comment: Y component of the quaternion. + type: number + - name: z + comment: Z component of the quaternion. + type: number + - name: s + comment: S component of the quaternion. + type: number + returnType: quaternion + functions: + - name: create + comment: Creates a new quaternion with the given component values. + parameters: + - name: x + comment: X component of the quaternion. + type: number + - name: "y" + comment: Y component of the quaternion. + type: number + - name: z + comment: Z component of the quaternion. + type: number + - name: s + comment: S component of the quaternion. + type: number + returnType: quaternion + - name: normalize + comment: Computes the normalized version (unit quaternion) of the quaternion. + parameters: + - name: q + comment: Input quaternion. + type: quaternion + returnType: quaternion + - name: magnitude + comment: Computes the magnitude of the quaternion. + parameters: + - name: q + comment: Input quaternion. + type: quaternion + returnType: number + - name: dot + comment: Computes the dot product of two quaternions. + parameters: + - name: a + comment: Left input quaternion. + type: quaternion + - name: b + comment: Right input quaternion. + type: quaternion + returnType: number + - name: slerp + comment: Spherical linear interpolation from a to b using factor t. + parameters: + - name: a + comment: Start quaternion. + type: quaternion + - name: b + comment: End quaternion. + type: quaternion + - name: t + comment: Interpolation factor. + type: number + returnType: quaternion + - name: conjugate + comment: Computes the conjugate of the quaternion. + parameters: + - name: q + comment: Input quaternion. + type: quaternion + returnType: quaternion + - name: tofwd + comment: Computes the forward vector from the quaternion. + parameters: + - name: q + comment: Input quaternion. + type: quaternion + returnType: vector + - name: toleft + comment: Computes the left vector from the quaternion. + parameters: + - name: q + comment: Input quaternion. + type: quaternion + returnType: vector + - name: toup + comment: Computes the up vector from the quaternion. + parameters: + - name: q + comment: Input quaternion. + type: quaternion + returnType: vector + constants: + - name: identity + comment: Identity quaternion constant. + type: quaternion + value: <0, 0, 0, 1> +- name: string + comment: String manipulation library. + functions: + - name: byte + comment: Returns the numeric code of every byte in the input string within the given range. + parameters: + - name: s + comment: Input string. + type: string + - name: i + comment: Starting index (optional). + type: number? + - name: j + comment: Ending index (optional). + type: number? + returnType: '...number' + - name: char + comment: Returns a string containing characters for the given byte values. + parameters: + - name: ... + comment: Byte values to convert to string. + type: ...number + returnType: string + - name: find + comment: Finds the first instance of the pattern in the string. + parameters: + - name: s + comment: Input string. + type: string + - name: pattern + comment: Pattern to search for. + type: string + - name: init + comment: Starting index (optional). + type: number? + - name: plain + comment: Perform raw search (optional). + type: boolean? + returnType: (number?, number?, ...string) + - name: format + comment: Formats input values into a string using printf-style format specifiers. + parameters: + - name: formatstring + comment: Format string. + type: string + - name: ... + comment: Values to format. + type: ...any + returnType: string + - name: gmatch + comment: Returns an iterator function for pattern matches + parameters: + - name: s + comment: Input string. + type: string + - name: pattern + comment: Pattern to search for. + type: string + returnType: () -> ...string + - name: gsub + comment: Performs pattern-based substitution in a string. + parameters: + - name: s + comment: Input string. + type: string + - name: pattern + comment: Pattern to replace. + type: string + - name: repl + comment: Replacement string, function, or table. + type: 'string | { [string]: string } | (...string) -> string' + - name: maxn + comment: Maximum replacements (optional). + type: number? + returnType: (string, number) + - name: len + comment: "Returns the number of bytes in the string. Identical to #s" + parameters: + - name: s + comment: Input string. + type: string + returnType: number + - name: lower + comment: Returns a lowercase version of the input string. + parameters: + - name: s + comment: Input string. + type: string + returnType: string + - name: match + comment: Finds and returns matches for a pattern in the input string. + parameters: + - name: s + comment: Input string. + type: string + - name: pattern + comment: Pattern to match. + type: string + - name: init + comment: Starting index (optional). + type: number? + returnType: '...string' + - name: pack + comment: Packs values into a binary string. + parameters: + - name: fmt + comment: Pack format string. + type: string + - name: ... + comment: Values to encode. + type: ...any + returnType: string + - name: packsize + comment: Returns the size of a packed string for the given format. + parameters: + - name: fmt + comment: Pack format string. + type: string + returnType: number + - name: rep + comment: Returns the input string repeated a given number of times. + parameters: + - name: s + comment: Input string. + type: string + - name: "n" + comment: Number of times to repeat the string. + type: number + returnType: string + - name: reverse + comment: Returns the input string with bytes in reverse order. + parameters: + - name: s + comment: Input string. + type: string + returnType: string + - name: split + comment: Splits a string by separator. Returns a list of substrings. + parameters: + - name: s + comment: Input string. + type: string + - name: separator + comment: Separator to split on. Default is "," + type: string? + returnType: '{string}' + - name: sub + comment: Returns a substring from the given range. + parameters: + - name: s + comment: Input string. + type: string + - name: i + comment: Starting index. + type: number + - name: j + comment: Ending index (optional). + type: number? + returnType: string + - name: unpack + comment: Decodes a binary string using a pack format. + parameters: + - name: fmt + comment: Pack format string. + type: string + - name: s + comment: Encoded string. + type: string + - name: init + comment: Starting index (optional). + type: number? + returnType: '...any' + - name: upper + comment: Returns an uppercase version of the input string. + parameters: + - name: s + comment: Input string. + type: string + returnType: string +- name: table + comment: Table manipulation library. Tables are collections of key-value pairs. + functions: + - name: concat + comment: Joins an array of strings into one string, with an optional separator. + parameters: + - name: a + comment: Array of strings. + type: '{string | number}' + - name: sep + comment: Separator string (optional). + type: string? + - name: i + comment: Starting index (optional). + type: number? + - name: j + comment: Ending index (optional). + type: number? + returnType: string + - name: foreach + comment: Iterates over all key-value pairs in the table (deprecated). + deprecated: true + typeParameters: [K, V, R] + parameters: + - name: t + comment: Table to iterate over. + type: '{[K]: V}' + - name: f + comment: Function applied to each key-value pair. + type: '(key: K, value: V) -> R?' + returnType: R? + - name: foreachi + comment: Iterates over all index-value pairs in the array (deprecated). + deprecated: true + typeParameters: [V, R] + parameters: + - name: a + comment: Array to iterate over. + type: '{V}' + - name: f + comment: Function applied to each index-value pair. + type: '(index: number, value: V) -> R?' + returnType: R? + - name: getn + comment: 'Returns the length of an array (deprecated; use # instead).' + deprecated: true + parameters: + - name: a + comment: Array to check. + type: '{any}' + returnType: number + - name: maxn + comment: Returns the highest numeric key in the table. + parameters: + - name: t + comment: Table to check. + type: '{any}' + returnType: number + - name: insert + comment: Inserts an element at the specified index, + or at the end of the array. + overloads: + - comment: Inserts an element at the end of a list + typeParameters: [V] + parameters: + - name: a + comment: Array to insert into. + type: '{V}' + - name: value + comment: Value to insert. + type: V + returnType: () + typeParameters: [V] + parameters: + - name: a + comment: Array to insert into. + type: '{V}' + - name: i + comment: "Index to insert at (default: at the end)." + type: number + - name: v + comment: Value to insert. + type: V + returnType: () + - name: remove + comment: Removes and returns the element at the specified index from the array, + or from the end of the array. + typeParameters: [V] + parameters: + - name: a + comment: Array to remove from. + type: '{V}' + - name: i + comment: "Index to remove (default: the last one)." + type: number? + returnType: V? + - name: sort + comment: Sorts an array in place. + typeParameters: [V] + parameters: + - name: a + comment: Array to be sorted. + type: '{V}' + - name: f + comment: Comparison function. + type: '((a: V, b: V) -> boolean)?' + returnType: () + - name: pack + comment: Packs multiple arguments into a new array with length field n. + typeParameters: [V] + parameters: + - name: ... + comment: Array elements. + type: ...V + returnType: '{ n: number, [number]: V }' + - name: unpack + comment: Unpacks array elements into multiple return values. + typeParameters: [V] + parameters: + - name: a + comment: Array to unpack. + type: '{V}' + - name: i + comment: Starting index (optional). + type: number? + - name: j + comment: Ending index (optional). + type: number? + returnType: '...V' + - name: move + comment: Inserts elements [i..j] from src array into dest array at [d]. + typeParameters: [V] + parameters: + - name: src + comment: Source array. + type: '{V}' + - name: i + comment: Starting index. + type: number + - name: j + comment: Ending index. + type: number + - name: d + comment: Destination index. + type: number + - name: dest + comment: Destination array (optional). + type: '{V}?' + returnType: '{V}' + - name: create + comment: Creates a new table with pre-allocated array capacity, optionally filled. + typeParameters: [V] + parameters: + - name: "n" + comment: Number of elements to allocate. + type: number + - name: v + comment: Value to prefill elements with (optional). + type: V? + returnType: '{V}' + - name: find + comment: Finds the first occurrence of a value in the array and returns its index. + typeParameters: [V] + parameters: + - name: t + comment: Table to search in. + type: '{V}' + - name: v + comment: Value to search for. + type: V + - name: i + comment: Starting index (optional). + type: number? + returnType: number? + - name: clear + comment: Clears all elements from a table while keeping its capacity. + parameters: + - name: t + comment: Table to clear. + type: '{[any]: any}' + returnType: () + - name: shrink + comment: Reduces the memory usage of the table to the minimum necessary. + typeParameters: [K, V] + parameters: + - name: t + comment: Table to shrink. + type: '{[K]: V}' + - name: reorder + comment: Allow moving sparse array elements to hash table storage. + type: boolean? + returnType: '{[K]: V}' + - name: freeze + comment: Freezes a table, making it read-only. + typeParameters: [K, V] + parameters: + - name: t + comment: Table to freeze. + type: '{[K]: V}' + returnType: '{[K]: V}' + - name: isfrozen + comment: Returns true if a table is frozen. + parameters: + - name: t + comment: Table to check. + type: '{[any]: any}' + returnType: boolean + - name: clone + comment: Creates a shallow copy of the table. + typeParameters: [K, V] + parameters: + - name: t + comment: Table to clone. + type: '{[K]: V}' + returnType: '{[K]: V}' +- name: utf8 + comment: UTF-8 support library. + functions: + - name: char + comment: Creates a string from Unicode codepoints. + parameters: + - name: ... + comment: Unicode codepoints. + type: ...number + returnType: string + - name: codes + comment: Returns an iterator that produces + the byte offset and Unicode codepoint for each character in the string. + parameters: + - name: s + comment: Input string. + type: string + returnType: ((string, number) -> (number, number), string, number) + - name: codepoint + comment: Returns the Unicode codepoints in the specified range of the string. + parameters: + - name: s + comment: Input string. + type: string + - name: i + comment: Starting index (optional). + type: number? + - name: j + comment: Ending index (optional). + type: number? + returnType: '...number' + - name: len + comment: Returns the number of Unicode codepoints in the specified range of the string, + or nil and error index. + parameters: + - name: s + comment: Input string. + type: string + - name: i + comment: Starting index (optional). + type: number? + - name: j + comment: Ending index (optional). + type: number? + returnType: (number?, number?) + - name: offset + comment: Returns the byte offset of the nth Unicode codepoint in the string. + parameters: + - name: s + comment: Input string. + type: string + - name: n + comment: Character position. + type: number + - name: i + comment: Starting index (optional). + type: number? + returnType: number? + constants: + - name: charpattern + comment: Pattern that matches exactly one UTF-8 byte sequence + type: string + value: "[\\x00-\\x7F\\xC2-\\xF4][\\x80-\\xBF]*" +- name: uuid + comment: UUID library. + callable: + name: uuid + comment: Creates a new uuid from a string, buffer, or existing uuid. Returns + nil if the string is not a valid UUID. Throws an error if the buffer is + shorter than 16 bytes. Alias of uuid.create + parameters: + - name: value + type: string | buffer | uuid + returnType: uuid? + functions: + - name: create + comment: Creates a new uuid from a string, buffer, or existing uuid. Returns + nil if the string is not a valid UUID. Throws an error if the buffer is + shorter than 16 bytes. + parameters: + - name: value + type: string | buffer | uuid + returnType: uuid? +- name: vector + comment: Vector manipuluation library. + callable: + name: vector + comment: Creates a new vector with the given component values. + Alias of vector.create. + parameters: + - name: x + comment: X component of the vector. + type: number + - name: "y" + comment: Y component of the vector. + type: number + - name: z + comment: Z component of the vector (optional). + type: number? + returnType: vector + functions: + - name: create + comment: Creates a new vector with the given component values. + parameters: + - name: x + comment: X component of the vector. + type: number + - name: "y" + comment: Y component of the vector. + type: number + - name: z + comment: Z component of the vector (optional). + type: number? + returnType: vector + - name: magnitude + comment: Computes the magnitude of the vector. + parameters: + - name: v + comment: Input vector. + type: vector + returnType: number + - name: normalize + comment: Computes the normalized version (unit vector) of the vector. + parameters: + - name: v + comment: Input vector. + type: vector + returnType: vector + - name: cross + comment: Computes the cross product of two vectors. + parameters: + - name: a + comment: Left input vector. + type: vector + - name: b + comment: Right input vector. + type: vector + returnType: vector + - name: dot + comment: Computes the dot product of two vectors. + parameters: + - name: a + comment: Left input vector. + type: vector + - name: b + comment: Right input vector. + type: vector + returnType: number + - name: angle + comment: Computes the angle between two vectors in radians. + The axis, if specified, is used to determine the sign of the angle. + parameters: + - name: a + type: vector + comment: Left input vector. + - name: b + comment: Right input vector. + type: vector + - name: axis + comment: Axis to determine the sign of the angle (optional). + type: vector? + returnType: number + - name: floor + comment: Applies math.floor to each component of the vector. + parameters: + - name: v + comment: Input vector. + type: vector + returnType: vector + - name: ceil + comment: Applies math.ceil to each component of the vector. + parameters: + - name: v + comment: Input vector. + type: vector + returnType: vector + - name: abs + comment: Applies math.abs to each component of the vector. + parameters: + - name: v + comment: Input vector. + type: vector + returnType: vector + - name: sign + comment: Applies math.sign to each component of the vector. + parameters: + - name: v + comment: Input vector. + type: vector + returnType: vector + - name: clamp + comment: Clamps each component of the vector between min and max values. + parameters: + - name: v + comment: Input vector to be clamped. + type: vector + - name: min + comment: Minimum vector value. + type: vector + - name: max + comment: Maximum vector value. + type: vector + returnType: vector + - name: max + comment: Applies math.max to each component of the vectors. + parameters: + - name: v + comment: Input vector. + type: vector + - name: ... + comment: Vectors to find the maximum from. + type: ...vector + returnType: vector + - name: min + comment: Applies math.max to each component of the vectors. + parameters: + - name: v + comment: Input vector. + type: vector + - name: ... + comment: Vectors to find the minimum from. + type: ...vector + returnType: vector + - name: lerp + comment: Linearly interpolates between a and b using factor t. + parameters: + - name: a + comment: Start vector. + type: vector + - name: b + comment: End vector. + type: vector + - name: t + comment: Interpolation factor. + type: number + returnType: vector + constants: + - name: zero + comment: Constant vector with all components set to 0. + type: vector + value: <0,0,0> + - name: one + comment: Constant vector with all components set to 1. + type: vector + value: <1,1,1> +- name: ll + # auto-generated from lsl_definitions.yaml + comment: Library for functions shared between LSL and SLua. +- name: llcompat + # auto-generated from lsl_definitions.yaml + comment: Like ll, but exactly matches LSL semantics. +# auto-generated from lsl_definitions.yaml +constants: [] + +# Everything below here is only for keywords.xml generation, not typechecking +controls: + do: + tooltip: "Lua do block: do ... end" + if: + tooltip: "Lua if statement: if condition then ... end" + then: + tooltip: "Lua then keyword: introduces the block executed when an if condition is true." + else: + tooltip: "Lua else keyword: specifies the alternative block in an if/else statement." + elseif: + tooltip: "Lua elseif keyword: provides an additional conditional branch in an if statement." + end: + tooltip: "Lua end keyword: closes control structures like if, do, while, for, and function." + for: + tooltip: "Lua for loop: for var = start, end, step do ... end" + return: + tooltip: "Lua return statement: returns a value from a function." + while: + tooltip: "Lua while loop: while condition do ... end" + repeat: + tooltip: "Lua repeat loop: repeat ... until condition" + until: + tooltip: "Lua until keyword: ends a repeat loop by testing a condition." + function: + tooltip: "Lua function keyword: begins a function definition." + break: + tooltip: "Lua break statement: exits the nearest loop." + continue: + tooltip: "Luau continue statement: skip to the next loop iteration." + local: + tooltip: "Lua local keyword: declares a local variable or function." + export: + tooltip: "Luau export keyword: declares a type that can be used in outside this module." + in: + tooltip: "Lua in keyword: used in generic for loops to iterate over elements." + not: + tooltip: "Lua not operator: performs logical negation." + and: + tooltip: "Lua and operator: performs logical conjunction." + or: + tooltip: "Lua or operator: performs logical disjunction." +builtinTypes: + any: + tooltip: The unspecified type. Disables type-checking. Use unknown instead to use type-checking. + boolean: + tooltip: "Boolean: represents a true or false value." + buffer: + tooltip: Read-write binary data. + never: + tooltip: The empty type that contains no values. + number: + tooltip: Double‑precision floating point number. + string: + tooltip: Read-only binary data. Usually UTF-8-encoded text. + thread: + tooltip: Represents a coroutine. + unknown: + tooltip: The union of every type. Similar to any without disabling type-checking. +builtinConstants: + - name: nil + comment: "Lua nil: represents the absence of a useful value." + type: nil + value: nil + - name: 'true' + comment: "Lua true: Boolean true value." + type: boolean + value: 'true' + - name: 'false' + comment: "Lua false: Boolean false value." + type: boolean + value: 'false' +builtinFunctions: +- name: assert + comment: Checks if the value is truthy; if not, raises an error with the optional message. + typeParameters: [T] + parameters: + - name: value + comment: The value to check for truthiness. + type: T? + - name: message + comment: Optional error message to display if the value is not truthy. + type: string? + returnType: T +- name: error + comment: Raises an error with the specified object and optional call stack level. + parameters: + - name: obj + comment: The error object to raise. + type: any + - name: level + comment: Optional level to attribute the error to in the call stack. + type: number? + returnType: never +- name: gcinfo + comment: Returns the total heap size in kilobytes. + returnType: number +- name: getmetatable + comment: Returns the metatable for the specified object. + parameters: + - name: obj + comment: The object to get the metatable for. + type: any + returnType: "{[any]: any}?" +- name: next + comment: Returns the next key-value pair in the table traversal order. + typeParameters: [K, V] + parameters: + - name: t + comment: The table to traverse. + type: "{[K]: V}" + - name: i + comment: Optional key to start traversal after. + type: K? + returnType: (K, V)? +- name: newproxy + comment: Creates a new untyped userdata object with an optional metatable. + parameters: + - name: mt + comment: Optional boolean to create a modifiable metatable. + type: boolean? + returnType: any +- name: print + comment: Prints all arguments to standard output using Tab as a separator. + parameters: + - name: ... + comment: Arguments to print to standard output. + type: ...any + returnType: () +- name: rawequal + comment: Returns true if a and b have the same type and value. + parameters: + - name: a + comment: First object to compare. + type: any + - name: b + comment: Second object to compare. + type: any + returnType: boolean +- name: rawget + comment: Performs a table lookup bypassing metatables. + typeParameters: [K, V] + parameters: + - name: t + comment: The table to perform the lookup on. + type: "{[K]: V}" + - name: k + comment: The key to look up in the table. + type: K + returnType: V? +- name: rawset + comment: Assigns a value to a table field bypassing metatables. + typeParameters: [K, V] + parameters: + - name: t + comment: The table to assign the value to. + type: "{[K]: V}" + - name: k + comment: The key to assign the value to. + type: K + - name: v + comment: The value to assign. + type: V + returnType: "{[K]: V}" +- name: rawlen + comment: Returns the length of a table or string bypassing metatables. + typeParameters: [K, V] + parameters: + - name: t + comment: The table to assign the value to. + type: "{[any]: any} | string" + returnType: number +- name: select + comment: Returns a subset of arguments or the number of arguments. + parameters: + - name: i + comment: The index or '#' to count arguments. + type: string | number + - name: ... + comment: The arguments to select from. + type: ...any + returnType: any +- name: setmetatable + comment: Changes the metatable for the given table. + parameters: + - name: t + comment: The table to set the metatable for. + type: "{ [any]: any }" + - name: mt + comment: The metatable to set. + type: "{ [any]: any }?" + returnType: () +- name: tonumber + comment: Converts the input string to a number in the specified base. + parameters: + - name: s + comment: The string to convert to a number. + type: string + - name: base + comment: Optional base for the conversion. + type: number? + returnType: number? +- name: tostring + comment: Converts the input object to a string. + parameters: + - name: obj + comment: The object to convert to a string. + type: any + returnType: string +- name: type + comment: Returns the type of the object as a string. + parameters: + - name: obj + comment: The object to get the type of. + type: any + returnType: string +- name: typeof + comment: Returns the type of the object, including custom userdata types. + parameters: + - name: obj + comment: The object to get the type of. + type: any + returnType: string +- name: ipairs + comment: Returns an iterator for numeric key-value pairs in the table. + typeParameters: [V] + parameters: + - name: t + comment: The table to iterate over. + type: "{V}" + returnType: "(({V}, number) -> (number?, V), {V}, number)" +- name: pairs + comment: Returns an iterator for all key-value pairs in the table. + typeParameters: [K, V] + parameters: + - name: t + comment: The table to iterate over. + type: "{[K]: V}" + returnType: "(({[K], V}, K) -> (K?, V), {[K], V}, K)" +- name: pcall + comment: Calls function f with parameters args, returning success and function results or an error. + typeParameters: [A..., R...] + parameters: + - name: f + comment: A function to be called. + type: (A...) -> R... + - name: ... + comment: Arguments to pass to the function. + type: A... + returnType: (boolean, R...) +- name: xpcall + comment: Calls function f with parameters args, handling errors with e if they occur. + typeParameters: [E, A..., R1..., R2...] + parameters: + - name: f + comment: A function to be called. + type: (A...) -> R1... + - name: e + comment: Error handler function. + type: (E) -> R2... + - name: ... + comment: Arguments to pass to the function. + type: A... + returnType: (boolean, R1...) +- name: require + comment: Execute the named external module. + parameters: + - name: target + comment: The name of the external module. + type: string + returnType: any +- name: unpack + comment: Returns values from an array in the specified index range. + typeParameters: [V] + parameters: + - name: a + comment: Array from which to extract values. + type: "{V}" + - name: f + comment: Starting index (optional, defaults to 1). + type: number? + - name: t + comment: "Ending index (optional, defaults to #a)." + type: number? + returnType: ...V diff --git a/validate.py b/validate.py index 26cf10d..476c160 100644 --- a/validate.py +++ b/validate.py @@ -9,25 +9,34 @@ import jsonschema -def validate_lsl_definitions_via_jsonschema() -> None: - with open("lsl_definitions.schema.json", "r", encoding="utf-8") as schema_file: +def validate_definitions_via_jsonschema(schema_filename, yaml_filename) -> None: + with open(schema_filename, "r", encoding="utf-8") as schema_file: schemadata = json.load(schema_file) - with open("lsl_definitions.yaml", "r", encoding="utf-8") as yaml_file: + with open(yaml_filename, "r", encoding="utf-8") as yaml_file: yamldata = yaml.safe_load(yaml_file) try: jsonschema.validate(instance=yamldata, schema=schemadata) - print("\nSUCCESS: Valid against the schema") + print(f"\nSUCCESS: Validated {yaml_filename} against the schema") except jsonschema.exceptions.ValidationError as e: - print("\nVALIDATION ERROR: INVALID", file=sys.stderr) + print(f"\nVALIDATION ERROR: INVALID {yaml_filename}", file=sys.stderr) print(f" Message: {e.message}", file=sys.stderr) print(f" Path: {' -> '.join(map(str, e.path))}", file=sys.stderr) print(f" Schema Path: {' -> '.join(map(str, e.schema_path))}", file=sys.stderr) raise e except jsonschema.exceptions.SchemaError as e: - print("\nSCHEMA ERROR: The schema is invalid", file=sys.stderr) + print(f"\nSCHEMA ERROR: The schema {schema_filename} is invalid", file=sys.stderr) print(f" Message: {e.message}", file=sys.stderr) raise e except Exception as e: - print(f"\nOh no ...: {e}", file=sys.stderr) + print(f"\nOh no ...: {e} processing {yaml_filename}", file=sys.stderr) raise e + + +def main(): + validate_definitions_via_jsonschema("lsl_definitions.schema.json", "lsl_definitions.yaml") + validate_definitions_via_jsonschema("slua_definitions.schema.json", "slua_definitions.yaml") + + +if __name__ == "__main__": + main()