From 536bbf5aa5285e5bbf46046e9bd1b00f9a19c1be Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Mon, 12 Oct 2026 16:23:57 -0700 Subject: [PATCH] RynthLua: run script commands as /lua [args] In a Decal (bridge-mode) client the engine only forwards a fixed list of chat-bar commands to plugins (/rc /ra /rv /rn /rnav /lua), so a script's game.RegisterCommand("/demo") never ran there. When the /lua subcommand is not a built-in verb, try it as a script command via the existing queue, so /lua demo status runs the /demo handler once with args "status". Usage text is shown only when no script owns the name, and lists the registered commands. Built-in verbs always win. Docs: RegisterCommand in rynthlua.d.lua. - "/lua /demo status" works too: one leading slash on the subcommand is stripped, and the usage lists names without the slash, the form the fallback takes ("/lua demo"). - A script command named like a built-in verb (list, exec, start, ...) can never be reached through /lua, so the usage summary leaves it out. One BuiltInLuaVerbs set gates the fallback and filters the summary. Tests (CompatTests luacmd.lua): plain and slash forms, case, spacing and quotes, unknown command usage, summary form and filtering, a script /exec not run by /lua exec, stopped owner gives usage, none-registered branch. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../ScriptManager.cs | 33 +++++ .../Types/rynthlua.d.lua | 4 + Tools/RynthLua.CompatTests/Scripts/luacmd.lua | 135 ++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 Tools/RynthLua.CompatTests/Scripts/luacmd.lua diff --git a/Plugins/RynthCore.Plugin.RynthLua/ScriptManager.cs b/Plugins/RynthCore.Plugin.RynthLua/ScriptManager.cs index 2546ab7..8da878f 100644 --- a/Plugins/RynthCore.Plugin.RynthLua/ScriptManager.cs +++ b/Plugins/RynthCore.Plugin.RynthLua/ScriptManager.cs @@ -255,11 +255,30 @@ public sealed partial class RynthLuaPlugin // ── /lua commands ─────────────────────────────────────────────────────── + /// + /// Every built-in /lua verb. The one list behind both the dispatch gate in HandleLuaChatCommand + /// (a verb never falls back to a script command) and the usage summary (a script command with + /// one of these names is unreachable through /lua). A new verb goes in the switch AND here. + /// + private static readonly HashSet BuiltInLuaVerbs = new(StringComparer.OrdinalIgnoreCase) + { + "run", "start", "restart", "stop", "exec", "execin", "autostart", "list", "hud", + }; + private void HandleLuaChatCommand(string line) { string[] parts = line.Split(' ', 3, StringSplitOptions.RemoveEmptyEntries); string sub = parts.Length > 1 ? parts[1].ToLowerInvariant() : ""; + if (sub.StartsWith('/')) sub = sub[1..]; // "/lua /demo": the usage lists names with a slash, one is accepted string rest = parts.Length > 2 ? parts[2].Trim() : ""; + // Not a built-in verb (those always win): in a Decal (bridge-mode) client the engine only + // forwards /lua, so "/lua demo status" (or "/lua /demo status", as the usage text lists them) is + // the way to reach a script's game.RegisterCommand("/demo"). Same queue as a typed "/demo status": + // the handler runs once on the tick thread with args "status". + if (!BuiltInLuaVerbs.Contains(sub)) + { + if (sub.Length > 0 && TryQueueScriptCommand("/" + sub + (rest.Length > 0 ? " " + rest : ""))) return; + } switch (sub) { case "run": @@ -322,7 +341,21 @@ public sealed partial class RynthLuaPlugin break; default: ChatLine("/lua list | start