diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2026-05-03 15:41:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-03 15:41:44 +0100 |
| commit | 21fa9b2ee27227c964fdeb8090d98255edb89bec (patch) | |
| tree | 2027ff3bea1c2a9ac55fd8287aaf67526bb9526b /meta/generateLuaStubs.py | |
| parent | c0933bffcf0394f7701ab134f6c308eaa9584bee (diff) | |
config/lua: fix dispatcher shapes to not be callable (#14268)
this would only lead to abuse, explicitly forbid it
Diffstat (limited to 'meta/generateLuaStubs.py')
| -rw-r--r-- | meta/generateLuaStubs.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/meta/generateLuaStubs.py b/meta/generateLuaStubs.py index a523496d..7ef70bab 100644 --- a/meta/generateLuaStubs.py +++ b/meta/generateLuaStubs.py @@ -469,7 +469,8 @@ def generate_stub(root: Path) -> str: api_signatures: dict[str, str] = { "hl.on": "fun(event: HL.EventName, cb: fun(...)): HL.EventSubscription", - "hl.bind": "fun(keys: string, dispatcher: function, opts?: HL.BindOptions): HL.Keybind", + "hl.bind": "fun(keys: string, dispatcher: HL.Dispatcher|function, opts?: HL.BindOptions): HL.Keybind", + "hl.dispatch": "fun(dispatcher: HL.Dispatcher|function): any", "hl.define_submap": "fun(name: string, reset_or_fn: string|function, fn?: function): nil", "hl.timer": "fun(callback: function, opts: HL.TimerOptions): HL.Timer", "hl.config": "fun(config: table): nil", @@ -523,6 +524,9 @@ def generate_stub(root: Path) -> str: lines.append("---@alias HL.CssGap integer|{top?:integer, right?:integer, bottom?:integer, left?:integer}") lines.append("---@alias HL.Gradient string|{colors:string[], angle?:number}") lines.append("") + lines.append("---@class HL.Dispatcher") + lines.append("local __HL_Dispatcher = {}") + lines.append("") lines.extend( emit_class_block( @@ -651,7 +655,8 @@ def generate_stub(root: Path) -> str: for method in sorted(node.methods): full_name = f"{full_prefix}.{method}" - method_type = api_signatures.get(full_name, "fun(...): any") + default_method_type = "fun(...): HL.Dispatcher" if path and path[0] == "dsp" else "fun(...): any" + method_type = api_signatures.get(full_name, default_method_type) fields.append((method, method_type, False)) for child_name in sorted(node.children.keys()): |
