Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,786 changes: 2,570 additions & 216 deletions generated/cpp/EmbeddedBuiltinDefinitions.cpp

Large diffs are not rendered by default.

46 changes: 33 additions & 13 deletions generated/lua_keywords_pretty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ export type DateTypeArg = {
export type DateTypeResult = {
year: number,
month: number,
wday: number,
yday: number,
day: number,
hour: number?,
min: number?,
sec: number?,
wday: number?,
yday: number?,
isdst: boolean?,
hour: number,
min: number,
sec: number,
isdst: boolean,
}</string>
</map>
<key>HttpRequestParams</key>
Expand Down Expand Up @@ -12941,6 +12941,11 @@ Returns 0 if i &lt; -31, or all sign bits if i &gt; 31.</string>
</map>
<key>coroutine.create</key>
<map>
<key>type-arguments</key>
<array>
<string>A...</string>
<string>R...</string>
</array>
<key>arguments</key>
<array>
<map>
Expand All @@ -12949,7 +12954,7 @@ Returns 0 if i &lt; -31, or all sign bits if i &gt; 31.</string>
<key>tooltip</key>
<string>A function to be executed by the new coroutine.</string>
<key>type</key>
<string>(...any) -&gt; ...any</string>
<string>(A...) -&gt; R...</string>
</map>
</map>
</array>
Expand Down Expand Up @@ -12978,6 +12983,11 @@ Returns 0 if i &lt; -31, or all sign bits if i &gt; 31.</string>
</map>
<key>coroutine.resume</key>
<map>
<key>type-arguments</key>
<array>
<string>A...</string>
<string>R...</string>
</array>
<key>arguments</key>
<array>
<map>
Expand All @@ -12995,14 +13005,14 @@ Returns 0 if i &lt; -31, or all sign bits if i &gt; 31.</string>
<key>tooltip</key>
<string>Arguments to pass to the coroutine.</string>
<key>type</key>
<string>...any</string>
<string>A...</string>
</map>
</map>
</array>
<key>energy</key>
<real>10.0</real>
<key>return</key>
<string>(boolean, ...any)</string>
<string>(boolean, R...)</string>
<key>sleep</key>
<real>0.0</real>
<key>tooltip</key>
Expand Down Expand Up @@ -13047,6 +13057,11 @@ Returns 0 if i &lt; -31, or all sign bits if i &gt; 31.</string>
</map>
<key>coroutine.wrap</key>
<map>
<key>type-arguments</key>
<array>
<string>A...</string>
<string>R...</string>
</array>
<key>arguments</key>
<array>
<map>
Expand All @@ -13055,21 +13070,26 @@ Returns 0 if i &lt; -31, or all sign bits if i &gt; 31.</string>
<key>tooltip</key>
<string>A function to execute in a coroutine.</string>
<key>type</key>
<string>(...any) -&gt; ...any</string>
<string>(A...) -&gt; R...</string>
</map>
</map>
</array>
<key>energy</key>
<real>10.0</real>
<key>return</key>
<string>(...any) -&gt; ...any</string>
<string>(A...) -&gt; R...</string>
<key>sleep</key>
<real>0.0</real>
<key>tooltip</key>
<string>Creates a coroutine and returns a function that resumes it.</string>
</map>
<key>coroutine.yield</key>
<map>
<key>type-arguments</key>
<array>
<string>A...</string>
<string>R...</string>
</array>
<key>arguments</key>
<array>
<map>
Expand All @@ -13078,14 +13098,14 @@ Returns 0 if i &lt; -31, or all sign bits if i &gt; 31.</string>
<key>tooltip</key>
<string>Values to pass to the resuming code.</string>
<key>type</key>
<string>...any</string>
<string>A...</string>
</map>
</map>
</array>
<key>energy</key>
<real>10.0</real>
<key>return</key>
<string>...any</string>
<string>R...</string>
<key>sleep</key>
<real>0.0</real>
<key>tooltip</key>
Expand Down
24 changes: 12 additions & 12 deletions generated/secondlife.d.luau
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ export type DateTypeArg = {
export type DateTypeResult = {
year: number,
month: number,
wday: number,
yday: number,
day: number,
hour: number?,
min: number?,
sec: number?,
wday: number?,
yday: number?,
isdst: boolean?,
hour: number,
min: number,
sec: number,
isdst: boolean,
}
type LLJsonEncodeOptions = {
tight: boolean?,
Expand Down Expand Up @@ -394,12 +394,12 @@ declare buffer: {
---------------------------

declare coroutine: {
create: (f: (...any) -> ...any) -> thread,
resume: (co: thread, ...any) -> (boolean, ...any),
create: <A..., R...>(f: (A...) -> R...) -> thread,
resume: <A..., R...>(co: thread, A...) -> (boolean, R...),
running: () -> thread?,
status: @checked (co: thread) -> "running" | "suspended" | "normal" | "dead",
wrap: (f: (...any) -> ...any) -> (...any) -> ...any,
yield: (...any) -> ...any,
wrap: <A..., R...>(f: (A...) -> R...) -> (A...) -> R...,
yield: <A..., R...>(A...) -> R...,
isyieldable: () -> boolean,
close: @checked (co: thread) -> (boolean, string?),
}
Expand Down Expand Up @@ -536,12 +536,12 @@ declare quaternion: ((x: number, y: number, z: number, s: number) -> quaternion)
toup: (q: quaternion) -> vector,
}

--[[ commented out to avoid shadowing magic type functions find, format, gmatch, and match

---------------------------
-- Global Table: string
---------------------------

--[[ commented out to avoid shadowing magic type functions find, format, gmatch, and match
declare string: {
byte: @checked (src: string, start_index: number?, end_index: number?) -> ...number, -- builtin
char: @checked (...number) -> string, -- builtin
Expand All @@ -561,9 +561,9 @@ declare string: {
unpack: @checked (format_string: string, src: string, start: number?) -> ...any, -- builtin
upper: @checked (src: string) -> string, -- builtin
}

--]]


---------------------------
-- Global Table: table
---------------------------
Expand Down
21 changes: 21 additions & 0 deletions lsl_definitions/generators/slua.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,40 @@ def gen_luau_lsp_defs(definitions: LSLDefinitions, slua_definitions: SLuaDefinit
for module in sorted(slua_definitions.modules.values(), key=lambda x: x.name):
if module.name in {"ll", "llcompat"}:
continue
defs.write(f"""
---------------------------
-- Global Table: {module.name}
---------------------------

""")
if module.name == "string":
defs.write(
"--[[ commented out to avoid shadowing magic type functions find, format, gmatch, and match\n"
)
module.write_luau_def(defs)
if module.name == "string":
defs.write("--]]\n")
defs.write("\n")
for var in slua_definitions.global_variables.values():
defs.write("declare ")
defs.write(var.to_luau_def())
defs.write("\n")
defs.write("""
---------------------------
-- Global Table: ll
---------------------------

""")
ll_module.write_luau_def(defs)
defs.write("""

---------------------------
-- Global Table: llcompat
---------------------------

""")
llcompat_module.write_luau_def(defs)
defs.write("\n")
for const in sorted(slua_definitions.global_constants.values(), key=lambda x: x.name):
if const.private:
continue
Expand Down
122 changes: 99 additions & 23 deletions lsl_definitions/generators/slua_embedded.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import io
from string import Template

from lsl_definitions.generators.base import register
Expand All @@ -13,29 +14,104 @@ def gen_slua_embedded_defs(
) -> str:
"""Generate SLua Embedded Definitions File."""

# quaternion_module = slua_definitions.get_module("quaternion")
# rotation_module = SLuaModule(
# name="rotation",
# comment=quaternion_module.comment,
# callable=quaternion_module.callable,
# constants=quaternion_module.constants,
# functions=quaternion_module.functions,
# )
# slua_definitions.modules.append(rotation_module)

inserts = {
# SLUA_GLOBAL_FUNCTIONS_REGEX=get_slua_global_functions(slua_definitions),
# SLUA_GLOBAL_MODULES_REGEX=get_slua_modules(slua_definitions),
# SLUA_GLOBAL_CONSTANTS_REGEX=get_slua_global_constants(slua_definitions),
# SLUA_GLOBAL_LSL_CONSTANTS_REGEX=get_LL_constants(slua_definitions),
# SLUA_GLOBAL_LL_MODULE_REGEX=get_LL_module_functions(slua_definitions),
# SLUA_GLOBAL_LL_MODULE_DEPRECATED_REGEX=get_LL_module_deprecated_functions(slua_definitions),
# # nil|string|number|boolean|thread|userdata|symbol|vector|buffer|unknown|never|any
# SLUA_GLOBAL_TYPES_REGEX=get_slua_global_types(slua_definitions),
# SLUA_METAMETHODS_REGEX=get_slua_metamethods(slua_definitions),
# SLUA_GLOBAL_LL_VARIABLE_FUNCTIONS_REGEX=get_LL_variable_functions(slua_definitions),
# SLUA_GLOBAL_LL_VARIABLES_REGEX=get_LL_variables(slua_definitions),
}
inserts = {}
# Global functions
with io.StringIO() as defs:
defs.write("declare ")
defs.write(slua_definitions.global_constants.pop("_G").to_luau_def())
defs.write("\ndeclare ")
defs.write(slua_definitions.global_constants.pop("_VERSION").to_luau_def())
defs.write("\n")
for func in slua_definitions.functions.values():
if func.private or func.local_only:
continue
if func.slua_removed:
continue
if func.typechecker_flags.builtin:
defs.write("-- ")
func.write_luau_global_def(defs)
inserts["GLOBAL_FUNCTIONS"] = defs.getvalue()

# Luau standard library modules
with io.StringIO() as defs:
slua_definitions.modules.pop("bit32").write_luau_def(defs)
inserts["BIT32_TABLE"] = defs.getvalue()
with io.StringIO() as defs:
slua_definitions.modules.pop("math").write_luau_def(defs)
inserts["MATH_TABLE"] = defs.getvalue()
with io.StringIO() as defs:
alias = slua_definitions.type_aliases.pop("DateTypeArg")
alias.export = False
defs.write(alias.to_luau_def())
defs.write("\n")
alias = slua_definitions.type_aliases.pop("DateTypeResult")
alias.export = False
defs.write(alias.to_luau_def())
defs.write("\n")
slua_definitions.modules.pop("os").write_luau_def(defs)
inserts["OS_TABLE"] = defs.getvalue()
with io.StringIO() as defs:
slua_definitions.modules.pop("coroutine").write_luau_def(defs)
inserts["COROUTINE_TABLE"] = defs.getvalue()
with io.StringIO() as defs:
slua_definitions.modules.pop("table").write_luau_def(defs)
inserts["TABLE_TABLE"] = defs.getvalue()
with io.StringIO() as defs:
slua_definitions.modules.pop("debug").write_luau_def(defs)
inserts["DEBUG_TABLE"] = defs.getvalue()
with io.StringIO() as defs:
slua_definitions.modules.pop("utf8").write_luau_def(defs)
inserts["UTF8_TABLE"] = defs.getvalue()
with io.StringIO() as defs:
slua_definitions.modules.pop("buffer").write_luau_def(defs)
inserts["BUFFER_TABLE"] = defs.getvalue()
# string is not in the EmbeddedBuiltinDefinitions, only the BuiltinDefinitions
slua_definitions.modules.pop("string")

# base classes
with io.StringIO() as defs:
slua_definitions.base_classes.pop("vector").write_luau_def(defs)
slua_definitions.modules.pop("vector").write_luau_def(defs)
inserts["VECTOR_TABLE"] = defs.getvalue()
with io.StringIO() as defs:
slua_definitions.base_classes.pop("quaternion").write_luau_def(defs)
slua_definitions.modules.pop("quaternion").write_luau_def(defs)
var = slua_definitions.global_variables.pop("rotation")
defs.write("declare ")
defs.write(var.to_luau_def())
defs.write("\n")
inserts["QUATERNION_TABLE"] = defs.getvalue()
with io.StringIO() as defs:
slua_definitions.base_classes.pop("uuid").write_luau_def(defs)
slua_definitions.modules.pop("uuid").write_luau_def(defs)
inserts["UUID_TABLE"] = defs.getvalue()

# LL libraries
with io.StringIO() as defs:
for class_ in slua_definitions.base_classes.values():
class_.write_luau_def(defs)
defs.write("\n")
for alias in slua_definitions.type_aliases.values():
defs.write(alias.to_luau_def())
defs.write("\n")
defs.write("\n")
for class_ in slua_definitions.classes.values():
class_.write_luau_def(defs)
for var in slua_definitions.global_variables.values():
defs.write("declare ")
defs.write(var.to_luau_def())
defs.write("\n")
defs.write("\n")
for module in sorted(slua_definitions.modules.values(), key=lambda x: x.name):
module.write_luau_def(defs)
defs.write("\n")
for const in sorted(slua_definitions.global_constants.values(), key=lambda x: x.name):
if const.private:
continue
defs.write("declare ")
defs.write(const.to_luau_def())
defs.write("\n")
inserts["LL_TABLE"] = defs.getvalue()

with open(template_path) as f:
template = Template(f.read())
Expand Down
9 changes: 2 additions & 7 deletions lsl_definitions/slua.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,7 @@ def _workaround_annotated_callable_bug(self) -> None:

def write_luau_def(self, f: TextIO) -> None:
self._workaround_annotated_callable_bug()
f.write(f"""
---------------------------
-- Global Table: {self.name}
---------------------------

declare {self.name}: """)
f.write(f"declare {self.name}: ")
if self.callable:
f.write("(")
f.write(self.callable.annotation_string)
Expand All @@ -406,7 +401,7 @@ def write_luau_def(self, f: TextIO) -> None:
if func.private or func.local_only:
continue
func.write_luau_table_def(f, indent=1)
f.write("}\n\n")
f.write("}\n")


@dataclasses.dataclass
Expand Down
Loading
Loading