fix(luals-meta): generate globals in c2 and echo @lua commands (#5385)

Co-authored-by: Mm2PL <miau@mail.kotmisia.pl>
This commit is contained in:
nerix
2024-05-22 15:23:33 +02:00
committed by GitHub
parent da526b379b
commit ec6b1ef24d
6 changed files with 78 additions and 72 deletions
+24 -19
View File
@@ -134,11 +134,13 @@ class Reader:
def read_class_body(self) -> list[list[str]]:
"""The reader must be at the first line of the class/struct body. All comments inside the class are returned."""
items = []
nesting = -1 # for the opening brace
while (line := self.peek_line()) is not None:
if line.startswith("};"):
if line.startswith("};") and nesting == 0:
self.next_line()
break
if not is_comment_start(line):
nesting += line.count("{") - line.count("}")
self.next_line()
continue
doc = self.next_doc_comment()
@@ -231,21 +233,6 @@ def read_file(path: Path, out: TextIOWrapper):
else:
header = doc_comment
# include block
if header[0].startswith("@includefile "):
for comment in header:
if not comment.startswith("@includefile "):
panic(
path,
reader.line_no(),
f"Invalid include block - got line '{comment}'",
)
filename = comment.split(" ", 1)[1]
out.write(f"-- Begin src/{filename}\n\n")
read_file(repo_root / "src" / filename, out)
out.write(f"-- End src/{filename}\n\n")
continue
# enum
if header[0].startswith("@exposeenum "):
if len(header) > 1:
@@ -270,7 +257,7 @@ def read_file(path: Path, out: TextIOWrapper):
continue
# class
if header[0].startswith("@lua@class "):
elif header[0].startswith("@lua@class "):
name = header[0].split(" ", 1)[1]
classname = name.split(":")[0].strip()
printmsg(path, reader.line_no(), f"class {classname}")
@@ -311,11 +298,29 @@ def read_file(path: Path, out: TextIOWrapper):
for func in funcs:
write_func(path, reader.line_no(), func, out)
continue
# global function
if header[-1].startswith("@exposed "):
elif header[-1].startswith("@exposed "):
write_func(path, reader.line_no(), doc_comment, out)
continue
else:
for comment in header:
inline_command(path, reader.line_no(), comment, out)
def inline_command(path: Path, line: int, comment: str, out: TextIOWrapper):
if comment.startswith("@includefile "):
filename = comment.split(" ", 1)[1]
out.write(f"-- Begin src/{filename}\n\n")
read_file(repo_root / "src" / filename, out)
out.write(f"-- End src/{filename}\n\n")
elif comment.startswith("@lua@class"):
panic(
path,
line,
"Unexpected @lua@class command. @lua@class must be placed at the start of the comment block!",
)
elif comment.startswith("@lua@"):
out.write(f'---{comment.replace("@lua", "", 1)}\n')
if __name__ == "__main__":