Skip to content
Draft
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
1 change: 1 addition & 0 deletions gen_all_definitions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ $CMD $DEFS gen_tree_source_file "$outdir/cpp/lscript_tree.cpp"
$CMD $DEFS gen_lexer_file ./templates/indra.in.l "$outdir/templated/indra.l"
$CMD $DEFS gen_parser_file ./templates/indra.in.y "$outdir/templated/indra.y"
$CMD $DEFS gen_mono_library_defs ./templates/LslLibrary.cs "$outdir/templated/LslLibrary.cs"
$CMD $DEFS gen_slua_embedded_defs ./templates/EmbeddedBuiltinDefinitions.in.cpp $SLUA "$outdir/cpp/EmbeddedBuiltinDefinitions.cpp"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


# Experimental generators
$CMD $DEFS gen_enums_txt "$outdir/experimental/enums.txt"
Expand Down
3,068 changes: 3,068 additions & 0 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
2 changes: 2 additions & 0 deletions lsl_definitions/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
lscript_compiler,
lsl,
slua,
slua_embedded,
slua_lsp_docs,
textmate,
)
Expand All @@ -24,6 +25,7 @@
"lscript_compiler",
"lsl",
"slua",
"slua_embedded",
"slua_lsp_docs",
"textmate",
]
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
118 changes: 118 additions & 0 deletions lsl_definitions/generators/slua_embedded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from __future__ import annotations

import io
from string import Template

from lsl_definitions.generators.base import register
from lsl_definitions.lsl import LSLDefinitions
from lsl_definitions.slua import SLuaDefinitions


@register("gen_slua_embedded_defs")
def gen_slua_embedded_defs(
definitions: LSLDefinitions, template_path: str, slua_definitions: SLuaDefinitions
) -> str:
"""Generate SLua Embedded Definitions File."""

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()
Comment on lines +65 to +67

@tapple tapple Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yunno, it's not really sustainable trying to generate 2 different versions of a definition for different FFlags.

I think a better idea would be to:

  1. Only generate the parts of EmbeddedBuiltinDefinitions.cpp that SLua actually enables with it's released FFlag set
  2. Leave the FFlag-disabled parts of EmbeddedBuiltinDefinitions.cpp in the template, to be synced upstream from Luau

In practice, for Luau 0.729, this would mean:

  1. generating kBuiltinDefinitionBufferSrc_NOINTEGER
  2. NOT generating kBuiltinDefinitionBufferSrc
  3. NOT generating kBuiltinDefinitionIntegerSrc
  4. NOT generating kBuiltinDefinitionClassSrc
  5. Removing Luau 0.715 integer library #176, Luau 0.724 class library #179, and Exclude integer and class from generated files #180 as dependencies on this PR
  6. Closing Exclude integer and class from generated files #180 because it's no longer needed (it's what implements enable_fflags in the commented code)
  7. Leaving Luau 0.715 integer library #176 and Luau 0.724 class library #179 unmerged until they are actually enabled via FFlags in SLua, and not just present and disabled in the code

This would also mean that I don't need to ask Harold not to base SLua on a particular Luau version just because of what FFlags Luau happened to put in EmbeddedBuiltinDefinitions.cpp that week (see above comment #181 (comment))

# 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())
return template.substitute(inserts)
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