From 1681bea42dd2f11ba3fe6df05560d0b231de3c76 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Wed, 6 May 2026 13:56:12 +0100 Subject: config/lua: add simple layout API (#14258) Adds a simple layout lua api --- meta/generateLuaStubs.py | 62 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'meta/generateLuaStubs.py') diff --git a/meta/generateLuaStubs.py b/meta/generateLuaStubs.py index 7ef70bab..0e94aa6e 100644 --- a/meta/generateLuaStubs.py +++ b/meta/generateLuaStubs.py @@ -87,18 +87,18 @@ def merge_node(dst: ApiNode, src: ApiNode) -> None: def parse_binding_tree(root: Path) -> tuple[ApiNode, set[str]]: - bindings_dir = root / "src/config/lua/bindings" + lua_dir = root / "src/config/lua" root_node = ApiNode() callable_namespaces: set[str] = set() register_header = re.compile( - r"void\s+Internal::register\w+Bindings\s*\([^)]*\)\s*\{", re.MULTILINE + r"void\s+(?:(?:Config::Lua::Bindings::)?Internal::)?register\w+Bindings\s*\([^)]*\)\s*\{", re.MULTILINE ) - set_fn = re.compile(r'Internal::set(?:Mgr)?Fn\(\s*L\s*,(?:\s*mgr\s*,)?\s*"([^"]+)"\s*,') + set_fn = re.compile(r'(?:Internal::)?set(?:Mgr)?Fn\(\s*L\s*,(?:\s*mgr\s*,)?\s*"([^"]+)"\s*,') set_field = re.compile(r'lua_setfield\(L,\s*-2,\s*"([^"]+)"\s*\);') - for cpp in sorted(bindings_dir.glob("*.cpp")): + for cpp in sorted(lua_dir.rglob("*.cpp")): source = read_text(cpp) for _, body in extract_function_bodies(source, register_header): local_root = ApiNode() @@ -503,6 +503,7 @@ def generate_stub(root: Path) -> str: "hl.get_current_submap": "fun(): string", "hl.notification.create": "fun(opts?: HL.NotificationOptions): HL.Notification", "hl.notification.get": "fun(): HL.Notification[]", + "hl.layout.register": "fun(name: string, provider: HL.LayoutProvider): nil", "hl.exec_cmd": "fun(cmd: string, rules?: table): nil", } api_signatures.update(query_overrides) @@ -539,6 +540,59 @@ def generate_stub(root: Path) -> str: ) lines.append("") + lines.extend( + emit_class_block( + "HL.Box", + [ + ("x", "number", False), + ("y", "number", False), + ("w", "number", False), + ("h", "number", False), + ], + ) + ) + lines.append("") + + lines.extend( + emit_class_block( + "HL.LayoutTarget", + [ + ("index", "integer", False), + ("window", "HL.Window|nil", False), + ("box", "HL.Box", False), + ("place", "fun(self: HL.LayoutTarget, box: HL.Box): nil", False), + ("set_box", "fun(self: HL.LayoutTarget, box: HL.Box): nil", False), + ], + ) + ) + lines.append("") + + lines.extend( + emit_class_block( + "HL.LayoutContext", + [ + ("area", "HL.Box", False), + ("targets", "HL.LayoutTarget[]", False), + ("grid_cell", "fun(self: HL.LayoutContext, i: integer, cols: integer, rows?: integer): HL.Box", False), + ("column", "fun(self: HL.LayoutContext, i: integer, n: integer): HL.Box", False), + ("row", "fun(self: HL.LayoutContext, i: integer, n: integer): HL.Box", False), + ("split", "fun(self: HL.LayoutContext, box: HL.Box, side: 'left'|'right'|'top'|'bottom'|'up'|'down', ratio: number): HL.Box", False), + ], + ) + ) + lines.append("") + + lines.extend( + emit_class_block( + "HL.LayoutProvider", + [ + ("recalculate", "fun(ctx: HL.LayoutContext): nil", False), + ("layout_msg", "fun(ctx: HL.LayoutContext, msg: string): boolean|string|nil", True), + ], + ) + ) + lines.append("") + lines.extend( emit_class_block( "HL.BindOptions", -- cgit v1.2.3