The complete, source-generated Lua API. Signatures, types, and
option keys are extracted from src-tauri/src/plugins/lua_api/; prose is
authored against the real implementation and validated to cover every call with no
invented symbols. For concepts, packaging, and tutorials see the
plugin development guide.
mud
mud.alias(pattern: string, fn_: function, opts: table?)
Register an input alias that runs a callback when the user's typed line matches a pattern.
Registers an alias on the host: when an input line matches the regex pattern, the provided function is invoked with the captured match. An optional opts table refines registration.
| Param | Type | Notes |
|---|---|---|
pattern | string | Regex pattern matched against typed input; capture groups are passed to the callback. |
fn_ | function | Callback invoked on a match, receiving the match/captures. |
opts | table? | Optional table of registration options. (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
flags | string | "" | Regex compile flags string (e.g. case-insensitivity), passed to compile_regex. Only a string value is read. |
priority | number | 0 | Integer match priority; only an integer value is read, cast to i32. |
enabled | boolean | true | Whether the alias starts enabled; only a boolean is read. A stored per-rule override for this world/plugin/rule_key takes precedence over this value. |
name | string | nil | Stable name used as the rule_key for replace/override semantics; only a string is read. When omitted, a key is hashed from pattern + flags + callback bytecode. |
Note: Patterns are regexes; bracket-string literals like [[^g (\w+)$]] are convenient for backslash-heavy patterns.
mud.alias("^note (.+)$", function(m)
-- handle m
end)
source: mud.rs:568
mud.capture(n: number, opts: table?) -> LuaSpan
Create a span that captures a numbered regex group, optionally styled.
Builds a LuaSpan whose source is capture group n, applying any style options (fg, bg, bold, italic, etc.) from opts. The span's text is cleared so only the styling and the capture index are retained.
| Param | Type | Notes |
|---|---|---|
n | number | The capture group index to bind this span to. |
opts | table? | Optional table of style overlay options such as fg, bg, bold, and italic. (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
fg | string | — | Foreground color applied to the captured text. "#rrggbb" hex literal or palette name (parse_color); nil leaves it unset. |
bg | string | — | Background color applied to the captured text. Same accepted values as fg; nil leaves it unset. |
bold | boolean | false | When true, renders the captured overlay bold. Only Boolean values are read. |
italic | boolean | false | When true, renders the captured overlay italic. Only Boolean values are read. |
underline | boolean | false | When true, underlines the captured overlay. Only Boolean values are read. |
reverse | boolean | false | When true, swaps fg/bg (reverse video). Only Boolean values are read. |
strike | boolean | false | When true, applies strikethrough. Only Boolean values are read. |
send | string | — | Makes the span clickable to send this text to the MUD. Must be a string; at most one of send/url/on_click may be set or build_span_from_opts errors. |
url | string | — | Makes the span clickable to open this URL. Must be a string; at most one of send/url/on_click may be set. |
on_click | function | — | Callback invoked when the span is clicked. Mutually exclusive with send/url (at most one allowed). Requires a plugin context to wire the click callback. |
Returns LuaSpan — A LuaSpan bound to capture group n with the given style overlay.
Note: Only style fields from opts and the capture index matter; any text in opts is discarded.
local span = mud.capture(1, { fg = "cyan", bold = true })
source: span.rs:323
mud.command(name: string, fn_: function, opts: any)
Register a named command that runs a callback when invoked.
Registers a command with the given name on the host, invoking the supplied function when the command is run. The opts argument refines registration.
| Param | Type | Notes |
|---|---|---|
name | string | The command name to register. |
fn_ | function | Callback invoked when the command runs. |
opts | any | Registration options passed through to the host. |
| Option | Type | Default | Meaning |
|---|---|---|---|
description | string | nil | Human-readable description of the command, shown in help/command listings. Passed through normalize_metadata (trimmed/normalized); nil or absent means no description. Must be a string or an error is raised. |
usage | string | nil | Usage/syntax hint for the command, shown in help. Passed through normalize_metadata; nil or absent means no usage. Must be a string or an error is raised. |
hidden | boolean | false | When true, hides the command from help/command listings while still registering it. nil or absent defaults to false; must be a boolean or an error is raised. |
aliases | string | string[] | nil | Alternative names for the command: a single string (aliases = "v") or an array of strings (aliases = { "v", "vlt" }). Each alias is validated like a command name (a malformed alias raises an error), lowercased, and de-duplicated with order preserved. A valid alias that collides with an existing command name or alias is dropped quietly at registration (first-wins). Aliases dispatch exactly like the command name and are shown in /commands. |
mud.command("greet", function()
-- run command
end)
source: mud.rs:584
mud.command_prefix() -> string
Return the host's configured command prefix string.
Returns the current command prefix used by the host to recognize commands.
Returns string — The command prefix as a string.
local prefix = mud.command_prefix()
source: mud.rs:313
mud.delay(ms: number, fn_: function)
Schedule a callback to run once after a delay in milliseconds.
Registers a one-shot scheduled callback that fires once after ms milliseconds.
| Param | Type | Notes |
|---|---|---|
ms | number | Delay in milliseconds before the callback fires. |
fn_ | function | Callback invoked once after the delay. |
Note: Fires only once; use mud.every for a repeating timer.
mud.delay(2000, function()
-- runs once after 2s
end)
source: mud.rs:733
mud.every(ms: number, fn_: function)
Schedule a callback to run repeatedly on a fixed interval in milliseconds.
Registers a repeating scheduled callback that fires every ms milliseconds.
| Param | Type | Notes |
|---|---|---|
ms | number | Interval in milliseconds between callback invocations. |
fn_ | function | Callback invoked on each interval. |
Note: Repeats indefinitely; use mud.delay for a one-shot timer.
mud.every(10000, function()
-- runs every 10s
end)
source: mud.rs:741
mud.execute(text: string, opts: table?) -> ()
Run a string through the input pipeline exactly as if the user had typed it.
Feeds text into the same input pipeline that handles typed input: alias expansion, slash-commands, and triggers all apply, and any resulting send goes out to the world. A recursion guard caps nesting depth (EXECUTE_DEPTH_CAP), so triggers or send observers that call mud.execute cannot loop back on themselves indefinitely. Returns nothing.
| Param | Type | Notes |
|---|---|---|
text | string | The line to run through the input pipeline, as if typed at the input line. |
opts | table? | Optional table refining the call. Unknown keys are rejected. (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
silent | boolean | false | When true, the resulting send suppresses its local echo (the command still goes to the world, it just isn't echoed to the output pane). Must be a boolean or a runtime error is raised. |
Note: A plain line that matches no alias, command, or trigger is sent with origin kind "execute" (distinct from a user's "typed" send and from mud.send's "plugin" send). Nesting past the depth cap raises a runtime error.
mud.trigger("^You are hungry\\.$", function()
mud.execute("eat bread")
end)
source: mud.rs:112, mud.rs:522
mud.gag(pattern: string, opts: table?)
Registers a trigger that gags (hides) lines matching a pattern.
Registers a trigger on `pattern` whose action is to gag the matched line, suppressing it from output. If `opts` is omitted, an empty options table is used before registration.
| Param | Type | Notes |
|---|---|---|
pattern | string | Trigger pattern to match against incoming lines. |
opts | table? | Optional trigger options table; defaults to an empty table when nil. (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
flags | string | "" | Regex flag string passed to the regex compiler (e.g. case-insensitivity flags). |
priority | number | 0 | Integer trigger priority; higher fires earlier relative to other triggers. |
fires_remaining | number | nil (unlimited) | Integer cap on remaining fires; only applied when >= 0, otherwise unlimited. |
enabled | boolean | true | Whether the trigger starts enabled. A stored plugin rule override for this rule key takes precedence over this value. |
name | string | nil | Stable trigger name. Used as the rule key (disambiguating otherwise-identical anonymous gags) and lets a later same-named registration replace this one. |
Note: Delegates to the shared trigger registration path with a single Gag action.
mud.gag("^You feel hungry%.$")
source: mud.rs:706
mud.gag_substring(text: string, opts: table?)
Gags a specific substring of text rather than a whole line.
Registers a substring gag for the given `text`, removing matching text from output while leaving the rest of the line intact.
| Param | Type | Notes |
|---|---|---|
text | string | The substring to gag from matching output. |
opts | table? | Optional options table passed through to substring-gag registration. (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
flags | string | "" | Regex compile flags string applied to all three generated triggers; only a string value is read. |
priority | number | 0 | Integer match priority for the generated triggers; only an integer is read, cast to i32. |
fires_remaining | number | nil | Number of times the trigger may fire before auto-disabling; only a non-negative integer is read (negative values are ignored, leaving it unlimited). |
enabled | boolean | true | Whether the triggers start enabled; only a boolean is read. A stored per-rule override takes precedence. |
name | string | nil | Stable base name; only a string is read. When set, the two strip-variant triggers are suffixed with __strip_front / __strip_back. When omitted, a rule_key is hashed. |
mud.gag_substring("(secret)")
source: mud.rs:720
mud.note(args: ...any) -> ()
Prints a local note line to the client, optionally styled.
Emits a client-side note that is not sent to the MUD. Supports a legacy single-string form, a string-plus-style-table form, and a span form built from one or more spans/strings/tables. Empty span input produces no output.
| Param | Type | Notes |
|---|---|---|
args | ...any | Either (text), (text, style_table), or one or more span/string/table arguments. |
| Option | Type | Default | Meaning |
|---|---|---|---|
fg | string | — | Foreground color of the note text. "#rrggbb" hex literal or palette name (parse_style_table -> parse_color); nil leaves it unset. Only applied in the legacy mud.note(string, style_table) two-argument form. |
bg | string | — | Background color of the note text. Same accepted values as fg; nil leaves it unset. |
bold | boolean | — | When true, renders the note bold. Only Boolean values are read. |
italic | boolean | — | When true, renders the note italic. Only Boolean values are read. |
underline | boolean | — | When true, underlines the note text. Only Boolean values are read. |
reverse | boolean | — | When true, swaps fg/bg (reverse video). Only Boolean values are read. |
strike | boolean | — | When true, applies strikethrough. Only Boolean values are read. |
Note: The two-argument string+table form is parsed as a style table; a span-form call with no resolvable spans is a no-op.
mud.note("[demo] saw 'ping', replied 'pong'", { fg = "#88ccff" })
source: mud.rs:140
mud.on_send(args: ...any)
Register an observe-only callback that watches every outbound command as it is sent.
Registers a send observer that runs its callback for each outbound command, without altering or blocking it. Call it as mud.on_send(pattern, fn, opts?) to watch only sends matching a regex, or mud.on_send(fn, opts?) with no pattern to watch every send. The callback receives a match object m: capture groups are available as m[1], m[2], ...; m.origin is a table { kind, plugin_id? } describing where the send came from, and m.silent is a boolean telling you whether the send suppressed its local echo. Registered observers appear in the plugin rules browser and can be enabled, disabled, or removed through the returned handle.
| Param | Type | Notes |
|---|---|---|
args | ...any | Either (pattern, fn, opts?) — a regex string, the observer function, and an optional options table — or (fn, opts?) to observe every send. The first argument must be a pattern string or the observer function; the callback must be a function; opts, if given, must be a table. |
| Option | Type | Default | Meaning |
|---|---|---|---|
flags | string | "" (empty) | Regex flags string (e.g. case-insensitivity) passed to compile_regex via parse_match_opts. Applies to the optional pattern. |
priority | number | 0 | Integer observer priority; higher fires earlier relative to other observers. Only Integer values are read. |
enabled | boolean | true | Whether the observer is active when registered. Only Boolean values are read. May be overridden by a persisted plugin rule override for this rule key. |
name | string | nil | Optional stable name for the observer; used as the rule key (for overrides / dedup) instead of an auto-computed hash. Only String values are read. |
Note: Observe-only: the callback cannot change or cancel the send. m.origin.kind is one of "typed", "alias", "command", "trigger", "keymap", "plugin", "execute", or "script". Unlike mud.trigger, the fires_remaining option has no effect on observers.
mud.on_send([[^(n|s|e|w|u|d)$]], function(m)
mud.note("moved: " .. m[1] .. " (origin: " .. m.origin.kind .. ")")
end, { name = "movement-observer" })
source: mud.rs:576
mud.panel(panel_id: string) -> table
Get a handle to one of the plugin's declared panels.
Returns a handle for the panel with the given id, used to push messages to the panel's webview (:post) and to receive messages from it (:on_message). The panel id must be declared in the plugin manifest; calling :post or :on_message on an undeclared panel logs a warning and is ignored.
| Param | Type | Notes |
|---|---|---|
panel_id | string | Id of a panel declared in the plugin manifest. |
Returns table — a panel handle table with :post(name, data) and :on_message(name, fn).
Note: Posting to an undeclared panel returns false; a :post payload over 1 MB is dropped with a warning.
local p = mud.panel("vitals")
p:post("update", { hp = 42 })
p:on_message("click", function(data)
mud.note("panel clicked")
end)
source: panel.rs:96
mud.play_sound(name: string, opts: table?) -> ()
Plays a named sound with optional volume and tag.
Plays the sound identified by `name`, which must be non-empty. Accepts an options table whose only honored keys in v1 are `volume` (integer 0-100) and `tag` (string); the remaining reserved keys are accepted but currently dropped.
| Param | Type | Notes |
|---|---|---|
name | string | Sound name; must be non-empty or an error is raised. |
opts | table? | Optional options table. Unknown keys are rejected. `volume` must be an integer in 0-100; `tag` must be a string. `loops`, `fadein`, `fadeout`, `start`, `finish`, `key`, `priority`, and `kind` are accepted but ignored in v1. (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
volume | number | nil | Playback volume as an integer 0-100. nil/absent leaves volume unset (host default). Non-integer raises "volume must be an integer"; out of range raises "volume out of range 0-100". |
tag | string | nil | String tag/group label for the sound, used so it can be stopped later (e.g. via mud.stop_sounds by tag). Must be a string; nil/absent means no tag. |
loops | number | nil | Reserved key: accepted (does not raise) but currently dropped/ignored in v1; intended to set the number of times the sound repeats. Not yet forwarded to the SoundManager. |
fadein | number | nil | Reserved key: accepted but currently dropped/ignored in v1; intended fade-in duration. Not yet forwarded to the SoundManager. |
fadeout | number | nil | Reserved key: accepted but currently dropped/ignored in v1; intended fade-out duration. Not yet forwarded to the SoundManager. |
start | number | nil | Reserved key: accepted but currently dropped/ignored in v1; intended playback start offset. Not yet forwarded to the SoundManager. |
finish | number | nil | Reserved key: accepted but currently dropped/ignored in v1; intended playback end/finish offset. Not yet forwarded to the SoundManager. |
key | string | nil | Reserved key: accepted but currently dropped/ignored in v1; intended identifier key for the sound. Not yet forwarded to the SoundManager. |
priority | number | nil | Reserved key: accepted but currently dropped/ignored in v1; intended playback priority. Not yet forwarded to the SoundManager. |
kind | string | nil | Reserved key: accepted but currently dropped/ignored in v1; intended sound category/kind. Not yet forwarded to the SoundManager. |
Note: Raises an error on empty name, an out-of-range volume, a non-integer volume, a non-string tag, or any unknown option key.
mud.play_sound("alert", { volume = 80, tag = "combat" })
source: mud.rs:176
mud.replace(args: ...any)
Registers a trigger that replaces matched text with a template.
Registers a replacement trigger; requires at least a pattern and template, raising an error otherwise. A table of patterns as the first argument selects the chain form, where the second argument must be a table containing `with` (and optional `capture`) and an optional third trigger-options table; a single pattern uses the single-line replacement path.
| Param | Type | Notes |
|---|---|---|
args | ...any | (pattern, template, opts?) for the single form, or (patterns_table, { capture = N, with = "..." }, opts?) for the chain form. |
| Option | Type | Default | Meaning |
|---|---|---|---|
capture | number | 0 (whole match) | Single-target capture index. 0 or absent targets the whole match/line; 1..=255 targets that capture. Out-of-range errors. (Accepted in both the single-line opts table and the chain replace-opts table.) |
with | string | nil | Chain form only (second-arg replace-opts table). Static string template used as the replacement; required for the chain overload. Function-valued `with` is rejected (chain triggers carry static actions). |
fg | string | nil (unchanged) | Foreground color applied to literal segments of the replacement template: "#rrggbb", an ANSI 16-color name, or tintin aliases pink/orange/light orange. Accepted in the single-line opts table and the chain replace-opts table. |
bg | string | nil (unchanged) | Background color for replacement literal segments, same forms as `fg`. |
bold | boolean | nil (unchanged) | Set/clear bold on replacement literal segments; only a boolean is applied. |
italic | boolean | nil (unchanged) | Set/clear italic on replacement literal segments; only a boolean is applied. |
underline | boolean | nil (unchanged) | Set/clear underline on replacement literal segments; only a boolean is applied. |
reverse | boolean | nil (unchanged) | Set/clear reverse-video on replacement literal segments; only a boolean is applied. |
strike | boolean | nil (unchanged) | Set/clear strikethrough on replacement literal segments; only a boolean is applied. |
within_lines | number | 5 | Chain form only (third-arg trigger-opts table). Positive integer (>= 1) max line span over which the chain rows may match; non-integer/<1 errors. |
flags | string | "" | Regex flag string. Single-line form only: passed to the regex compiler. Explicitly rejected on the chain form (use per-row flags via the table-of-tables pattern form). |
priority | number | 0 | Integer trigger priority; higher fires earlier. Accepted in the single-line opts table and the chain trigger-opts table. |
fires_remaining | number | nil (unlimited) | Integer cap on remaining fires; only applied when >= 0. Accepted in single-line opts and chain trigger-opts. |
enabled | boolean | true | Whether the trigger starts enabled; a stored plugin rule override takes precedence. Accepted in single-line opts and chain trigger-opts. |
name | string | nil | Stable trigger name used as rule key and for same-named replacement. Accepted in single-line opts and chain trigger-opts. |
Note: Fewer than two arguments raises an error. In the chain form the second argument must be a table and the optional trigger opts must be a table or absent.
mud.replace("go (%w+)", "go " .. "%1")
source: mud.rs:605
mud.request_restart() -> ()
Requests a restart of the plugin/client.
Signals a restart request through the settings callbacks. If the settings module has not been installed yet, the call is ignored and a warning is logged instead.
Note: Calling this before the settings module is installed logs a warning and does nothing.
mud.request_restart()
source: mud.rs:323
mud.send(text: string, opts: table?) -> ()
Sends text to the MUD, splitting on line boundaries.
Splits `text` into individual lines and sends each to the MUD. The optional options table accepts a single `silent` boolean that suppresses local echo; unknown keys are rejected.
| Param | Type | Notes |
|---|---|---|
text | string | Text to send; split into multiple lines before sending. |
opts | table? | Optional options table. Only `silent` (boolean) is allowed; a non-boolean `silent` or any unknown key raises an error. (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
silent | boolean | false | When true, the line is sent without echoing it to the output. Must be a boolean (nil is allowed and means false); any other type raises "silent must be a boolean". This is the only accepted key — unknown keys are rejected. |
Note: Multi-line text is split and each resulting line is sent separately.
mud.send("go " .. m[1])
source: mud.rs:54, mud.rs:458
mud.send_raw(bytes: string, opts: table?) -> ()
Sends raw bytes directly to the MUD connection.
Writes the given string's bytes to the host connection unmodified. An optional opts table accepts a single boolean key `silent`; when true the send is performed silently.
| Param | Type | Notes |
|---|---|---|
bytes | string | String whose raw bytes are sent to the host connection. |
opts | table? | Optional table; only the key `silent` (boolean) is accepted. Any other key raises an error, and a non-boolean, non-nil `silent` raises "silent must be a boolean". (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
silent | boolean | false | When true, sends the bytes without echoing them to the output buffer. Must be a boolean (nil is treated as default false; any other type errors). This is the only allowed key — reject_unknown_keys errors on anything else. |
Note: Unknown keys in opts are rejected; `silent` defaults to false.
mud.send_raw("look\r\n")
mud.send_raw("password\r\n", { silent = true })
source: mud.rs:86, mud.rs:493
mud.sounds(_: ...args) -> table
Returns the list of available sound entries.
Re-reads the host sound list on each call (no caching) and returns an array table. Each element is a table with `name` (string) and `source`, which is either "bundled" or "user".
| Param | Type | Notes |
|---|---|---|
_ | ...args | Ignored. The function takes no meaningful arguments; any extra args are silently dropped. |
Returns table — An array table where each entry is { name = string, source = "bundled" | "user" }.
for _, s in ipairs(mud.sounds()) do
print(s.name, s.source)
end
source: mud.rs:241
mud.span(text: string, opts: table?) -> LuaSpan
Builds a styled text span from text and optional style options.
Constructs a LuaSpan with source type Text from the given text and an optional opts table of styling. An `on_click` function in opts is rejected because click handlers require a plugin context.
| Param | Type | Notes |
|---|---|---|
text | string | The text content of the span. |
opts | table? | Optional table of span styling options. Supplying an `on_click` function raises "mud.span: on_click requires a plugin context". (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
fg | string | nil | Foreground color, parsed via parse_color (e.g. named color or hex). nil/absent leaves the span's foreground unchanged. |
bg | string | nil | Background color, parsed via parse_color (e.g. named color or hex). nil/absent leaves the span's background unchanged. |
bold | boolean | false | Renders the text bold when true. Only applied if the value is a boolean; other types are ignored. |
italic | boolean | false | Renders the text italic when true. Only applied if the value is a boolean; other types are ignored. |
underline | boolean | false | Underlines the text when true. Only applied if the value is a boolean; other types are ignored. |
reverse | boolean | false | Swaps foreground/background (reverse video) when true. Only applied if the value is a boolean; other types are ignored. |
strike | boolean | false | Renders the text with strikethrough when true. Only applied if the value is a boolean; other types are ignored. |
send | string | nil | Makes the span clickable to send the given command string to the MUD. Must be a string; mutually exclusive with url and on_click (at most one action may be set). |
url | string | nil | Makes the span clickable to open the given URL. Must be a string; mutually exclusive with send and on_click (at most one action may be set). |
on_click | function | nil | Callback invoked when the span is clicked. Requires a plugin context (the bare mud.span errors with "on_click requires a plugin context"); under a plugin it is wired through the callback registry. Mutually exclusive with send and url. |
Returns LuaSpan — A LuaSpan object with source Text.
Note: on_click handlers are not allowed here; only plugin-context spans support them.
local s = mud.span("hello", { fg = "red" })
source: span.rs:274, span.rs:300
mud.stop_sounds(opts: table?) -> ()
Stops playing sounds, optionally filtered by tag.
Stops currently playing sounds via the host. An optional opts table accepts a `tag` string; when provided, only sounds matching that tag are stopped, otherwise all sounds stop.
| Param | Type | Notes |
|---|---|---|
opts | table? | Optional table; only the key `tag` is accepted. A non-nil `tag` must be a string (otherwise "tag must be a string" is raised); unknown keys are rejected. (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
tag | string | nil (stops all sounds) | Only stop sounds previously started with this tag; omitted/nil stops all. Must be a string when present. Unknown keys in the opts table are rejected (only `tag` is allowed). |
Note: Omitting opts or `tag` stops all sounds.
mud.stop_sounds()
mud.stop_sounds({ tag = "ambient" })
source: mud.rs:220
mud.style(pattern: any, opts: table, trigger_opts: table?)
Registers a restyle rule that reformats matching output.
Classifies the pattern as either a single pattern or a chain. A single pattern registers a restyle; a chain (multiple rows) registers a chain restyle that also accepts trigger_opts.
| Param | Type | Notes |
|---|---|---|
pattern | any | The pattern to match; may be a single pattern or a chain of patterns. |
opts | table | Table describing the restyling to apply to matches. (see options below) |
trigger_opts | table? | Optional table of trigger options; used only for chain patterns. (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
fg | string | nil | Foreground color for the matched target(s): a "#rrggbb" hex literal, an ANSI-16 palette name, or a tintin alias. May also be a function (m -> color string) to use the dynamic-restyle path (single/non-chain only; rejected for chain patterns). |
bg | string | nil | Background color; same accepted forms as fg, including a function value for dynamic restyle (non-chain only). |
bold | boolean | nil | Bold attribute patch; only a boolean is applied. Omitted leaves the attribute unchanged. |
italic | boolean | nil | Italic attribute patch; only a boolean is applied. Omitted leaves it unchanged. |
underline | boolean | nil | Underline attribute patch; only a boolean is applied. Omitted leaves it unchanged. |
reverse | boolean | nil | Reverse-video attribute patch; only a boolean is applied. Omitted leaves it unchanged. |
strike | boolean | nil | Strikethrough attribute patch; only a boolean is applied. Omitted leaves it unchanged. At least one of fg/bg/bold/italic/underline/reverse/strike must be present, or an error is raised. |
capture | number | 0 | Single target: integer capture group to restyle; 0 (or absent) means the whole line. Must be 0 or 1..=255. Mutually exclusive with captures. |
captures | table | nil | Multi-target form, mutually exclusive with capture. Either an array of integer capture indices sharing the top-level style (e.g. {1,2}), or a table keyed by capture index mapping to per-target style sub-tables (e.g. { [1] = {fg=...}, [2] = {fg=...} }). Mixed shapes are rejected. |
flags | string | "" | Regex compile flags. Read from opts on the single-pattern path and from trigger_opts; only a string is read. Not supported on chain patterns (a non-empty flags in trigger_opts raises an error). |
priority | number | 0 | Integer match priority; only an integer is read, cast to i32. Read from opts (single path) or from trigger_opts. |
fires_remaining | number | nil | Times the trigger may fire before auto-disabling; only a non-negative integer is read. Read from opts (single path) or trigger_opts. |
enabled | boolean | true | Whether the trigger starts enabled; only a boolean is read. A stored per-rule override takes precedence. Read from opts (single path) or trigger_opts. |
name | string | nil | Stable rule_key for replace/override semantics; only a string is read. When omitted, a key is hashed from the pattern/chain shape. Read from opts (single path) or trigger_opts. |
within_lines | number | 5 | Chain patterns only (read from trigger_opts): maximum number of lines the chain may span. Must be a positive integer (>= 1); defaults to 5 when omitted. |
Note: trigger_opts is only consulted when the pattern is a chain.
mud.style("^You hit (.+)$", { fg = "green" })
source: mud.rs:592
mud.trigger(pattern: any, fn_: function, opts: table?)
Registers a trigger that runs a callback on matching output.
Classifies the pattern as a single pattern or a chain and registers the callback accordingly. The callback receives match information; for capture patterns it is passed the match object.
| Param | Type | Notes |
|---|---|---|
pattern | any | The pattern to match; may be a single pattern or a chain of patterns. |
fn_ | function | Function invoked when the pattern matches; receives the match object. |
opts | table? | Optional table of trigger options. (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
flags | string | "" (empty) | Regex flags string passed to compile_regex (e.g. case-insensitivity). Parsed by parse_match_opts. NOT supported on chain triggers — a non-empty flags on a chain pattern errors (use per-row flags instead). |
priority | number | 0 | Integer trigger priority; higher fires earlier relative to other triggers. Only Integer values are read (cast to i32). |
fires_remaining | number | nil (unlimited) | Integer cap on how many times the trigger may fire before auto-disabling. Only Integer values >= 0 are accepted; negative values are ignored, leaving it unlimited. |
enabled | boolean | true | Whether the trigger is active when registered. Only Boolean values are read. May be overridden by a persisted plugin rule override for this rule key. |
name | string | nil | Optional stable name for the trigger; used as the rule key (for overrides / dedup) instead of an auto-computed hash. Only String values are read. |
within_lines | number | 5 | Chain triggers only: maximum number of lines within which the chain's sub-patterns must all match. Must be a positive integer (>= 1); other values error. Ignored for single-pattern triggers. |
Note: Single vs. chain patterns are dispatched to different registration paths automatically.
local echo_handle = mud.trigger("^echo (.+)$", function(m)
mud.send_raw(m[1] .. "\r\n")
end)
source: mud.rs:555
mud.viewport() -> table
Returns the current viewport dimensions.
Queries the host for the viewport size and returns a table with `cols` and `rows` fields.
Returns table — A table { cols = number, rows = number }.
local vp = mud.viewport()
print(vp.cols, vp.rows)
source: mud.rs:295
mud.keymap
mud.keymap.activate(name: string)
Pushes a named keymap layer onto the active stack, attributed to the calling plugin.
Applies an Activate operation for the given layer name on behalf of the current plugin, adding that keymap to the layer stack. Ownership is tracked by the plugin id so the host can attribute and manage the layer.
| Param | Type | Notes |
|---|---|---|
name | string | Name of the keymap layer to activate. |
mud.keymap.activate("combat")
source: mud_keymap.rs:134
mud.keymap.clear()
Deactivates all keymap layers, emptying the stack.
Applies a DeactivateAll operation, removing every active keymap layer from the stack regardless of which plugin added it.
mud.keymap.clear()
source: mud_keymap.rs:172
mud.keymap.cycle(direction: string)
Deprecated no-op that only validates its direction argument.
Emits a deprecation note and has no effect in the multi-layer stack model. It accepts only the strings 'next' or 'prev'; any other value raises a runtime error.
| Param | Type | Notes |
|---|---|---|
direction | string | Must be 'next' or 'prev'; other values raise an error. |
Note: Deprecated and does nothing beyond argument validation. Passing anything other than 'next' or 'prev' raises a runtime error.
mud.keymap.cycle("next")
source: mud_keymap.rs:247
mud.keymap.deactivate(name: string)
Removes a named keymap layer from the stack, attributed to the calling plugin.
Applies a Deactivate operation for the given layer name on behalf of the current plugin, removing that keymap from the layer stack.
| Param | Type | Notes |
|---|---|---|
name | string | Name of the keymap layer to deactivate. |
mud.keymap.deactivate("combat")
source: mud_keymap.rs:144
mud.keymap.deactivate_top()
Removes the topmost keymap layer from the stack.
Applies a DeactivateTop operation, popping the most recently activated keymap layer off the stack.
mud.keymap.deactivate_top()
source: mud_keymap.rs:163
mud.keymap.get_active()
Deprecated accessor returning the name of the top active keymap layer, if any.
Emits a deprecation note and returns the first name from the active layer list, or nil when no layers are active. Use mud.keymap.list_active()[1] instead.
Note: Deprecated; prefer mud.keymap.list_active()[1].
local top = mud.keymap.get_active()
source: mud_keymap.rs:235
mud.keymap.is_active(name: string)
Reports whether a named keymap layer is currently active.
Returns whether a layer with the given name exists anywhere in the active layer stack.
| Param | Type | Notes |
|---|---|---|
name | string | Name of the keymap layer to check. |
if mud.keymap.is_active("combat") then
mud.keymap.deactivate("combat")
end
source: mud_keymap.rs:194
mud.keymap.list_active()
Returns the names of all currently active keymaps.
Queries the host for the list of active keymap names and returns them as a Lua array (1-indexed) of strings.
for _, name in ipairs(mud.keymap.list_active()) do
mud.note(name)
end
source: mud_keymap.rs:181
mud.keymap.on_active_change(f: function)
Registers a callback fired when the set of active keymaps changes (deprecated).
Stores the given function in the Lua registry and appends it to the on_active_change callback list. Emits a deprecation note advising the use of mud.keymap.on_change instead.
| Param | Type | Notes |
|---|---|---|
f | function | Function invoked when the active keymap set changes. |
Note: Deprecated; the host emits a note steering callers to mud.keymap.on_change.
mud.keymap.on_active_change(function()
mud.note("keymaps changed")
end)
source: mud_keymap.rs:268
mud.keymap.on_change(f: function)
Registers a callback fired when keymaps change.
Stores the given function in the Lua registry and appends it to the on_change callback list so it is invoked on keymap changes.
| Param | Type | Notes |
|---|---|---|
f | function | Function invoked when keymaps change. |
mud.keymap.on_change(function()
mud.note("active: " .. #mud.keymap.list_active())
end)
source: mud_keymap.rs:202
mud.keymap.set_active(name: any)
Activates a named keymap or deactivates all keymaps (deprecated).
Accepts a string name to activate that keymap, or nil to deactivate all keymaps; any other Lua type raises a runtime error. Emits a deprecation note pointing to mud.keymap.activate / mud.keymap.clear.
| Param | Type | Notes |
|---|---|---|
name | any | A string keymap name to activate, or nil to deactivate all keymaps. |
Note: Deprecated in favor of mud.keymap.activate / mud.keymap.clear. Passing anything other than a string or nil raises a runtime error.
mud.keymap.set_active("combat")
mud.keymap.set_active(nil)
source: mud_keymap.rs:214
mud.keymap.toggle(name: string)
Toggles a named keymap on or off, attributed to the calling plugin.
Applies a Toggle keymap operation for the given name as the current plugin, flipping that keymap's active state.
| Param | Type | Notes |
|---|---|---|
name | string | Name of the keymap to toggle. |
mud.keymap.toggle("combat")
source: mud_keymap.rs:154
mud.timer
mud.timer.after(ms: number, fn_: function)
Schedules a one-shot callback after a delay in milliseconds (deprecated).
Registers a non-repeating scheduled callback to run once after ms milliseconds. On first use it logs a one-time warning that this name is deprecated in favor of mud.delay.
| Param | Type | Notes |
|---|---|---|
ms | number | Delay in milliseconds before the callback runs. |
fn_ | function | Function invoked once after the delay elapses. |
Note: Deprecated; use mud.delay instead. A one-time warning is logged on first use and the old name will be removed in a future release.
mud.timer.after(1000, function()
mud.note("one second later")
end)
source: mud.rs:758
mud.timer.every(ms: number, fn_: function)
Schedules a repeating callback every ms milliseconds (deprecated).
Registers a repeating scheduled callback that runs every ms milliseconds. On first use it logs a one-time warning that this name is deprecated in favor of mud.every.
| Param | Type | Notes |
|---|---|---|
ms | number | Interval in milliseconds between callback invocations. |
fn_ | function | Function invoked on each interval. |
Note: Deprecated; use mud.every instead. A one-time warning is logged on first use and the old name will be removed in a future release.
mud.timer.every(5000, function()
mud.note("tick")
end)
source: mud.rs:779
vars
vars.delete(name: string) -> ()
Deletes a session variable.
Removes the variable named `name` from the host's variable store. No error is raised if it does not exist.
| Param | Type | Notes |
|---|---|---|
name | string | Variable name to delete. |
vars.delete("target")
source: vars.rs:43
vars.get(name: string) -> any
Read a persisted plugin variable by name.
Looks up the named variable in the host's variable store and returns its value as a string. Returns nil when the variable is not set.
| Param | Type | Notes |
|---|---|---|
name | string | Variable name to look up. |
Returns any — The stored value as a string, or nil if the variable does not exist.
Note: Values are always returned as strings; missing keys return nil, so guard with `or` and convert with tonumber as needed.
local count = tonumber(vars.get("demo_count") or "0") + 1
source: vars.rs:14
vars.set(name: string, value: any) -> ()
Set or delete a persisted plugin variable.
Stores the value under the given name in the host's variable store. Strings are stored verbatim; integers, numbers, and booleans ("true"/"false") are stringified before storage; other types fall back to Lua's tostring coercion. Passing nil deletes the variable.
| Param | Type | Notes |
|---|---|---|
name | string | Variable name to write. |
value | any | Value to store; nil deletes the key. |
Note: All values are coerced to strings; passing nil removes the variable rather than storing an empty value.
vars.set("demo_count", tostring(count))
source: vars.rs:23
vars.snapshot() -> table
Return all plugin variables as a table.
Builds and returns a fresh Lua table containing every key/value pair currently in the host's variable store.
Returns table — A table mapping each variable name to its stored value.
for name, value in pairs(vars.snapshot()) do log.info(name .. "=" .. value) end
source: vars.rs:50
storage
storage.byte_size() -> number
Returns the total byte size of the plugin's stored data.
Returns the number of bytes currently used by the calling plugin's storage.
Returns number — The total storage size in bytes as a number.
table.insert(lines, " (total bytes: " .. tostring(storage.byte_size()) .. ")")
source: storage.rs:77
storage.delete(key: string) -> ()
Removes a key from the plugin's persistent storage.
Deletes the value stored under `key` for the current plugin and world. No error is raised if the key does not exist.
| Param | Type | Notes |
|---|---|---|
key | string | Storage key to remove. |
Note: Scoped to the current plugin and world; deleting an absent key is a no-op.
storage.delete("last_echo")
source: storage.rs:58
storage.get(key: string) -> any
Reads a value from the plugin's persistent storage.
Looks up `key` and, if present, parses the stored JSON string back into a Lua value. Returns nil when the key is absent.
| Param | Type | Notes |
|---|---|---|
key | string | Storage key to read. |
Returns any — The decoded Lua value for the key, or nil if it is not set.
Note: Errors if the stored value is not valid JSON. Use `or` to supply a default since a missing key yields nil.
local n = (storage.get(k) or 0) + 1
source: storage.rs:37
storage.has(key: string) -> boolean
Reports whether a storage key exists.
Returns true if `key` is present in the current plugin and world's storage, false otherwise.
| Param | Type | Notes |
|---|---|---|
key | string | Storage key to test. |
Returns boolean — Boolean indicating whether the key is set.
if storage.has("notes") then end
source: storage.rs:51
storage.keys() -> table
Lists all storage keys for the plugin.
Returns a sequence table of every key currently stored for this plugin and world, indexed from 1.
Returns table — An array-style table of key strings.
for _, k in ipairs(storage.keys()) do
print(k)
end
source: storage.rs:66
storage.set(key: string, value: any) -> ()
Writes a value to the plugin's persistent storage.
Encodes `value` as JSON and stores it under `key`. Passing nil for `value` deletes the key instead.
| Param | Type | Notes |
|---|---|---|
key | string | Storage key to write. |
value | any | Lua value to store; nil deletes the key. |
Note: `value` of nil deletes the key as sugar. Errors if the value cannot be JSON-encoded or the underlying store rejects the write (e.g. size limits).
storage.set("last_echo", m[1])
source: storage.rs:21
settings
settings.get(key: string) -> any
Reads a declared setting value for the current plugin and world.
Returns the value of the named setting, converted from JSON to a Lua value. If the key is not declared in the plugin manifest, it logs a warning and returns nil.
| Param | Type | Notes |
|---|---|---|
key | string | Setting key; must be declared in the plugin manifest or the call returns nil with a warning. |
Returns any — The setting value as a Lua value, or nil if the key is not declared.
Note: An undeclared key does not error; it logs a warning and yields nil.
local enabled = settings.get("auto_walk")
if enabled then
print("auto walk on")
end
source: settings.rs:150
settings.on(event: string, f: function) -> ()
Registers a callback for settings change events.
Subscribes a callback to settings events. Only the "change" event is supported; any other event name raises an error.
| Param | Type | Notes |
|---|---|---|
event | string | Event name; must be exactly "change" or the call errors. |
f | function | Callback to invoke when settings change. |
Note: Passing any event other than "change" raises an error.
settings.on("change", function()
print("settings changed")
end)
source: settings.rs:177
settings.snapshot() -> table
Returns a table of all current settings for the plugin and world.
Builds and returns a Lua table mapping each setting key to its current value, converted from JSON.
Returns table — A table mapping setting keys to their current values.
local s = settings.snapshot()
for k, v in pairs(s) do
print(k, v)
end
source: settings.rs:164
events
events.emit(name: string, data: any) -> ()
Emit a named event with a JSON-encodable payload to the world.
Converts data to JSON and emits an event under the given name on the current world. Errors if the payload cannot be JSON-encoded.
| Param | Type | Notes |
|---|---|---|
name | string | Event name to emit. |
data | any | Payload value; must be JSON-encodable. |
Note: Raises an error if data cannot be encoded to JSON.
events.emit("net.mallard.showcase.echo", { text = m[1] })
source: events.rs:42
events.on(name: string, fn_: function) -> userdata
Subscribe a callback to a named event and return a handle.
Registers fn_ as a listener for events named name on the current world and returns a userdata handle that can be used to unsubscribe.
| Param | Type | Notes |
|---|---|---|
name | string | Event name to listen for. |
fn_ | function | Lua callback invoked with the event data. |
Returns userdata — A userdata event handle (supports :remove() to unsubscribe).
local h = events.on("net.mallard.showcase.echo", function(data)
mud.note(data.text)
end)
source: events.rs:54
world
world.on(event: string, f: function) -> ()
Register a callback for a world event.
Registers the given function as a handler for the named world event. Valid events are "connect", "disconnect", and "line"; handlers are appended so multiple callbacks may be registered for the same event.
| Param | Type | Notes |
|---|---|---|
event | string | Event name: one of "connect", "disconnect", or "line". |
f | function | Function invoked when the event fires. |
Note: Any event name other than "connect", "disconnect", or "line" raises an error ("unknown world event").
world.on("line", function(line)
log.info("got: " .. line)
end)
source: world.rs:92
ui
ui.notify(title: string, body: string, opts: table?) -> ()
Shows a desktop notification with a title and body.
Displays a notification with the given `title` and `body`. The optional `opts.icon` selects the icon style; "warning" and "error" map to their respective icons and any other value (or omission) defaults to info.
| Param | Type | Notes |
|---|---|---|
title | string | Notification title text. |
body | string | Notification body text. |
opts | table? | Optional table; supports `icon` of "info", "warning", or "error". |
Note: Requires the Notifications capability; raises an error if the plugin lacks that permission. Unrecognized icon values fall back to info.
ui.notify("Server error", line.text, { icon = "error" })
source: ui.rs:14
log
log.error(args: ...args) -> ()
Log a message at error level.
Stringifies the supplied arguments into a single message and writes it to the host log at error level.
| Param | Type | Notes |
|---|---|---|
args | ...args | One or more values that are concatenated into the logged message. |
log.error("failed to load config")
source: log.rs:13
log.info(args: ...args) -> ()
Log a message at info level.
Stringifies the supplied arguments into a single message and writes it to the host log at info level.
| Param | Type | Notes |
|---|---|---|
args | ...args | One or more values that are concatenated into the logged message. |
log.info("demo plugin loaded for world '" .. mud.world.name .. "'")
source: log.rs:13
log.warn(args: ...args) -> ()
Write a warning-level log message built from the given arguments.
Stringifies all passed arguments into a single message and emits it to the host log at the warn level. Accepts any number of arguments.
| Param | Type | Notes |
|---|---|---|
args | ...args | Zero or more values to stringify and join into the log message. |
Note: The message is assembled by the host's argument stringifier; non-string values are converted automatically.
log.warn("unexpected state", value)
source: log.rs:13
keychain
keychain.delete(name: string) -> boolean
Delete a plugin's stored keychain credential by name.
Requires the Keychain permission. Deletes the OS keychain entry stored under a key namespaced to this plugin and also removes the key name from the plugin's keychain sidecar record. Returns whether an entry existed.
| Param | Type | Notes |
|---|---|---|
name | string | Key name within this plugin's namespace; combined as plugin:<plugin_id>:<name>. |
Returns boolean — boolean: true if a credential existed and was deleted, false if there was no entry.
Note: Requires Keychain permission; errors if the keychain backend is unavailable.
keychain.delete("api_token")
source: keychain.rs:71
keychain.get(name: string) -> string?
Retrieve a plugin's stored keychain credential by name.
Requires the Keychain permission. Reads the OS keychain entry stored under a key namespaced to this plugin and returns its value, or nil if no such entry exists.
| Param | Type | Notes |
|---|---|---|
name | string | Key name within this plugin's namespace; combined as plugin:<plugin_id>:<name>. |
Returns string? — string?: the stored value, or nil if no entry exists.
Note: Requires Keychain permission; errors if the keychain backend is unavailable.
local token = keychain.get("api_token")
source: keychain.rs:53
keychain.set(name: string, value: string) -> boolean
Store a plugin keychain credential under the given name.
Requires the Keychain permission and rejects values larger than the keychain byte limit. Writes the value to the OS keychain under a key namespaced to this plugin and records the key name in the plugin's sidecar so it can be swept on uninstall.
| Param | Type | Notes |
|---|---|---|
name | string | Key name within this plugin's namespace; combined as plugin:<plugin_id>:<name>. |
value | string | Secret string to store; must not exceed the keychain value size limit. |
Returns boolean — boolean: always true on success.
Note: Requires Keychain permission; errors if the value is too large or the keychain backend is unavailable.
keychain.set("api_token", token)
source: keychain.rs:26
gmcp
gmcp.get(path: string) -> string?
Read the current GMCP value at a dotted path.
Returns the cached GMCP value stored at the given path, or nil if none is present. Requires GmcpAccess permission for path; a permission failure raises an error.
| Param | Type | Notes |
|---|---|---|
path | string | Dotted GMCP path, e.g. "Char.Vitals.hp". |
Returns string? — The stored string value at path, or nil if absent.
Note: Errors if the plugin lacks GmcpAccess permission for the path.
local v = gmcp.get("Char.Vitals.hp")
mud.note(tostring(v))
source: gmcp.rs:48
gmcp.on(prefix: string, fn_: function) -> userdata
Subscribe to GMCP packages matching a prefix and return a handle.
Registers fn_ for GMCP packages whose name starts with prefix and returns a userdata handle. The prefix must be non-empty and at most 256 characters; it is lowercased at registration so matching is case-insensitive, while the callback still receives the original-case package name. Requires GmcpAccess permission for the (lowercased) prefix.
| Param | Type | Notes |
|---|---|---|
prefix | string | GMCP package prefix to match; must be 1-256 characters. |
fn_ | function | Lua callback invoked with the package name and decoded data. |
Returns userdata — A userdata GMCP handle.
Note: Empty prefixes and prefixes over 256 chars raise an error; matching is case-insensitive due to lowercasing at registration.
gmcp.on("Char.Vitals", function(pkg, data)
mud.note(data.hp)
end)
source: gmcp.rs:60
gmcp.send(pkg: string, data: any?) -> ()
Send a GMCP message for the given package to the connected world.
Validates that the package name is non-empty and that the plugin holds GmcpAccess permission for that package, then dispatches the message to the current world. When data is nil or omitted no payload is sent; otherwise the value is converted to JSON and sent as the payload.
| Param | Type | Notes |
|---|---|---|
pkg | string | GMCP package name; must not be empty and is permission-checked via GmcpAccess(pkg). |
data | any? | Optional payload; nil or omitted sends no data, otherwise the Lua value is encoded to JSON. |
Note: Errors if pkg is empty, if the plugin lacks GmcpAccess permission for pkg, or if the data fails JSON encoding.
gmcp.send("Char.Login", { name = "hero" })
source: gmcp.rs:98
mxp
mxp.get_entity(name: string) -> string?
Returns the current value of a named MXP entity, or nil if unset.
Looks up the MXP entity by name for the current world and returns its value. Returns nil when no entity with that name exists.
| Param | Type | Notes |
|---|---|---|
name | string | Entity name to look up. |
Returns string? — The entity's string value, or nil if the entity is not set.
local hp = mxp.get_entity("hp")
if hp then
print("HP entity: " .. hp)
end
source: mxp.rs:141
mxp.on(tag: string, fn_: function) -> userdata
Registers a listener for a custom MXP tag, returning a handle.
Subscribes a callback to fire when the named custom MXP tag is received in the current world; the callback receives the tag name, attributes, and text. Returns a userdata handle that supports :remove() to unregister the listener.
| Param | Type | Notes |
|---|---|---|
tag | string | MXP tag name; must be non-empty and at most 256 characters. Matched case-insensitively (uppercased internally). Built-in MXP tags are accepted but the listener will never fire since built-ins do not emit Custom events. |
fn_ | function | Callback invoked as fn(name, attrs, text) when the tag fires. |
Returns userdata — A userdata MXP handle supporting :remove() to unregister.
Note: Passing a built-in tag logs a warning and registers the listener anyway, but it will never fire.
local h = mxp.on("RoomName", function(name, attrs, text)
print("room: " .. text)
end)
source: mxp.rs:81
mxp.on_entity(name: string, fn_: function) -> userdata
Registers a listener for changes to a named MXP entity, returning a handle.
Subscribes a callback to fire when the named MXP entity changes in the current world. The name is matched case-insensitively (lowercased internally). Returns a userdata handle supporting :remove() to unregister.
| Param | Type | Notes |
|---|---|---|
name | string | Entity name; must be non-empty and at most 256 characters. Lowercased internally before matching. |
fn_ | function | Callback invoked when the entity changes. |
Returns userdata — A userdata entity handle supporting :remove() to unregister.
local h = mxp.on_entity("hp", function(value)
print("hp changed: " .. tostring(value))
end)
source: mxp.rs:116
keymap
keymap.bind(combo_str: string, fn_: function) -> userdata
Bind a key combination to a Lua callback.
Registers the given callback to run when the parsed key combination is pressed, returning a userdata handle for the binding. Combination strings use modifier+key syntax such as "Ctrl+Shift+M", "F5", "Mod+Shift+G", or a bare key like "j".
| Param | Type | Notes |
|---|---|---|
combo_str | string | Key combination string; must include a key, not only modifiers. |
fn_ | function | Callback function invoked when the combination is pressed. |
Returns userdata — userdata: a handle representing the registered key binding.
Note: A combination consisting only of modifiers with no key is rejected as a parse error.
keymap.bind("Ctrl+Shift+M", function()
mud.note("pressed")
end)
source: keymap.rs:154
EntityHandle object
handle:remove()
Unsubscribes an entity listener registered with mxp.on_entity().
Removes the entity subscription for this handle's world and listener, then drops the stored Lua callback so it can no longer fire. After calling this the registered callback is fully detached.
Note: Idempotent intent aside, the handle is meant to be removed once; the underlying callback id is dropped.
local echo_handle = mxp.on_entity("echo", function(e) end)
-- later, when no longer needed:
echo_handle:remove()
source: mxp.rs:54
EventHandle object
handle:remove()
Unsubscribes an entity listener registered with mxp.on_entity().
Removes the entity subscription for this handle's world and listener, then drops the stored Lua callback so it can no longer fire. After calling this the registered callback is fully detached.
Note: Idempotent intent aside, the handle is meant to be removed once; the underlying callback id is dropped.
local echo_handle = mxp.on_entity("echo", function(e) end)
-- later, when no longer needed:
echo_handle:remove()
source: events.rs:22
GmcpHandle object
handle:remove()
Unsubscribes an entity listener registered with mxp.on_entity().
Removes the entity subscription for this handle's world and listener, then drops the stored Lua callback so it can no longer fire. After calling this the registered callback is fully detached.
Note: Idempotent intent aside, the handle is meant to be removed once; the underlying callback id is dropped.
local echo_handle = mxp.on_entity("echo", function(e) end)
-- later, when no longer needed:
echo_handle:remove()
source: gmcp.rs:21
KeymapHandle object
handle:remove()
Unsubscribes an entity listener registered with mxp.on_entity().
Removes the entity subscription for this handle's world and listener, then drops the stored Lua callback so it can no longer fire. After calling this the registered callback is fully detached.
Note: Idempotent intent aside, the handle is meant to be removed once; the underlying callback id is dropped.
local echo_handle = mxp.on_entity("echo", function(e) end)
-- later, when no longer needed:
echo_handle:remove()
source: keymap.rs:128
LuaHandle object
handle:disable()
Disables the trigger, alias, scheduled task, or command behind this handle.
Marks the handle's enabled flag false and disables the underlying entity in the engine. Triggers, aliases, and commands are set disabled by id; for scheduled handles the timer is stopped by name if one exists.
Note: For scheduled (delay/every) handles, disabling stops the timer; re-enabling cannot re-arm it (see handle:enable).
local h = mud.trigger("^You are hungry$", function() end)
h:disable()
source: mud.rs:378
handle:enable()
Enables the trigger, alias, or command behind this handle.
Sets the handle's enabled flag true and re-enables the underlying trigger, alias, or command by id in the engine. Scheduled handles are a no-op here because the anonymous scheduled entry is not persisted.
Note: For scheduled work created by mud.delay/mud.every, enable() does nothing; you must call mud.delay/mud.every again to register a new scheduled entry.
local h = mud.alias("^hp$", function() end)
h:disable()
h:enable()
source: mud.rs:394
handle:remove()
Unsubscribes an entity listener registered with mxp.on_entity().
Removes the entity subscription for this handle's world and listener, then drops the stored Lua callback so it can no longer fire. After calling this the registered callback is fully detached.
Note: Idempotent intent aside, the handle is meant to be removed once; the underlying callback id is dropped.
local echo_handle = mxp.on_entity("echo", function(e) end)
-- later, when no longer needed:
echo_handle:remove()
source: mud.rs:413
LuaMatch object
m:capture(n: number, opts: table?)
Builds a span overlay that reuses the text of capture group n.
Constructs a styled span whose text is taken from capture group n, applying any style options from opts. The overlay's own text is cleared so the captured text is used as the content, and the result is returned as a span object for use with span-form effects.
| Param | Type | Notes |
|---|---|---|
n | number | index of the capture group whose text the span will use |
opts | table? | optional style options table applied to the span overlay (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
fg | string | nil | Foreground color: a "#rrggbb" hex literal (0x000000-0xffffff), an ANSI-16 palette name (black, red, green, yellow, blue, magenta, cyan, white, plus their 'light X' variants), or a tintin alias (pink, orange, light orange). nil leaves it unset. |
bg | string | nil | Background color; same accepted forms as fg. nil leaves it unset. |
bold | boolean | false | Bold attribute; only a Lua boolean is applied (non-boolean values are ignored). |
italic | boolean | false | Italic attribute; only a Lua boolean is applied. |
underline | boolean | false | Underline attribute; only a Lua boolean is applied. |
reverse | boolean | false | Reverse-video attribute; only a Lua boolean is applied. |
strike | boolean | false | Strikethrough attribute; only a Lua boolean is applied. |
send | string | nil | Click action that sends this string to the MUD. At most one of send/url/on_click may be set, else an error is raised. |
url | string | nil | Click action that opens this URL. At most one of send/url/on_click may be set. |
on_click | function | nil | Accepted as an option key but not wired up by the capture overlay path (build_span_from_opts leaves on_click for the span-install path); counts toward the at-most-one-action constraint. |
local s = m:capture(1, { fg = "red" })
m:replace(1, s)
source: mud_match.rs:347
m:gag()
Suppresses the matched line from output.
Sets the match's gag effect so the line that triggered the callback is not displayed.
Note: Affects the whole line; there is no way to ungag once set within the callback.
trigger("^spam$", function(m)
m:gag()
end)
source: mud_match.rs:220
m:note(args: ...any)
Appends a note line to the match's effects.
In legacy form, m:note(string) or m:note(string, opts_table) creates a plain span from the string and applies an optional style table to it. Otherwise the arguments are interpreted as spans (or a span list) and pushed as a note only if the resulting span list is non-empty.
| Param | Type | Notes |
|---|---|---|
args | ...any | either a string with an optional style table, or one or more spans / a span list |
| Option | Type | Default | Meaning |
|---|---|---|---|
fg | string | — | Foreground color of the note text. Either a "#rrggbb" hex literal or a palette name (ANSI 16-color names such as black/red/.../white plus "light X" variants, or the aliases pink/orange/light orange). Parsed by parse_style_table -> parse_color; nil leaves it unset. Only applied in the legacy m:note(string, opts_table) form. |
bg | string | — | Background color of the note text. Same accepted values as fg ("#rrggbb" or palette name); nil leaves it unset. |
bold | boolean | — | When true, renders the note bold. Only Boolean values are read; any non-boolean is ignored. |
italic | boolean | — | When true, renders the note italic. Only Boolean values are read. |
underline | boolean | — | When true, underlines the note text. Only Boolean values are read. |
reverse | boolean | — | When true, swaps fg/bg (reverse video). Only Boolean values are read. |
strike | boolean | — | When true, applies strikethrough. Only Boolean values are read. |
Note: With one or two args where the first is a string, the second table is treated as a style; otherwise all args are parsed as spans. Empty span results are dropped.
m:note("connection established", { fg = "green" })
source: mud_match.rs:322
m:raw(key: any)
Looks up the raw (unstyled) text for a capture key.
Returns the raw captured string for the given key, or nil if no such raw value exists.
| Param | Type | Notes |
|---|---|---|
key | any | the capture key to look up (e.g. a capture index or name) |
local who = m:raw(1)
if who then m:send("greet " .. who) end
source: mud_match.rs:213
m:replace(args: ...any)
Replaces a match target with a replacement string, function result, or spans.
Requires at least a target and a replacement. With a single string or function as the replacement it uses the legacy replace path; otherwise the remaining arguments are parsed as spans/captures. Errors if no arguments are given.
| Param | Type | Notes |
|---|---|---|
args | ...any | the target followed by one or more replacement values (string, function, or spans/captures) |
Note: Requires at least (target, replacement) or it errors. For chain matches, an integer target that resolves to an earlier (non-completing) row is silently dropped.
m:replace(1, m:capture(1, { fg = "yellow" }))
source: mud_match.rs:252
m:send(text: string, opts: table?)
Queues a command to be sent to the server.
Pushes a send request with the given text. The optional opts table accepts only a boolean silent key; any other key is rejected and a non-boolean silent value raises an error.
| Param | Type | Notes |
|---|---|---|
text | string | the command text to send |
opts | table? | optional table; only the boolean key silent is allowed (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
silent | boolean | false | When true, the command is sent to the MUD without echoing it to the local output. Must be a boolean (nil is treated as false); any other type raises "silent must be a boolean". |
Note: Unknown option keys are rejected; silent must be a boolean if provided.
m:send("look", { silent = true })
source: mud_match.rs:298
m:style(spec: table)
Applies styling to captures of the match.
Accepts a spec table in single-capture form ({ capture = N, ... }) or multi-capture form ({ captures = {...}, ... }) and pushes the corresponding style effects. For chain matches, flat capture indices are translated to completing-row-local indices and targets on earlier rows are silently dropped.
| Param | Type | Notes |
|---|---|---|
spec | table | style spec table using either a capture index or a captures list plus style attributes (see options below) |
| Option | Type | Default | Meaning |
|---|---|---|---|
capture | number | nil (whole line) | Integer capture index to restyle; omitted/nil targets the whole matched line. Mutually exclusive with `captures`. |
captures | table | nil | Multi-capture form. Either an array of integer capture indices (e.g. {1,2}) sharing the top-level style, or a table keyed by capture index whose values are per-capture style tables (e.g. {[1]={fg=...},[2]={fg=...}}). Mutually exclusive with `capture`; mixed value types error. |
fg | string | nil (unchanged) | Foreground color: "#rrggbb" hex, an ANSI 16-color name (black/red/green/yellow/blue/magenta/cyan/white plus 'light X'), or tintin aliases pink/orange/light orange. nil leaves fg unchanged. |
bg | string | nil (unchanged) | Background color, same accepted forms as `fg`. nil leaves bg unchanged. |
bold | boolean | nil (unchanged) | Set or clear the bold attribute; only a boolean value is applied, otherwise the attribute is left unchanged. |
italic | boolean | nil (unchanged) | Set or clear the italic attribute; non-boolean leaves it unchanged. |
underline | boolean | nil (unchanged) | Set or clear the underline attribute; non-boolean leaves it unchanged. |
reverse | boolean | nil (unchanged) | Set or clear the reverse-video attribute; non-boolean leaves it unchanged. |
strike | boolean | nil (unchanged) | Set or clear the strikethrough attribute; non-boolean leaves it unchanged. |
Note: In chain matches a capture that belongs to an earlier row is silently ignored rather than styled.
m:style({ capture = 1, fg = "cyan", bold = true })
source: mud_match.rs:225
MxpHandle object
handle:remove()
Unsubscribes an entity listener registered with mxp.on_entity().
Removes the entity subscription for this handle's world and listener, then drops the stored Lua callback so it can no longer fire. After calling this the registered callback is fully detached.
Note: Idempotent intent aside, the handle is meant to be removed once; the underlying callback id is dropped.
local echo_handle = mxp.on_entity("echo", function(e) end)
-- later, when no longer needed:
echo_handle:remove()
source: mxp.rs:30
PanelHandle object
panel:on_message(arg2: string, arg3: function)
Register a callback for messages of a given name sent from the panel.
Subscribes a Lua function to messages named arg2 coming from this panel. If the panel id was not declared in the plugin manifest, a warning is logged and the listener is never registered.
| Param | Type | Notes |
|---|---|---|
arg2 | string | Message name to listen for. |
arg3 | function | Lua callback invoked with the message data when a matching message arrives. |
Note: Silently does nothing (only a warning is logged) if the panel id is not declared in the manifest.
local panel = mud.panel("my.panel")
panel:on_message("send", function(data)
mud.note(data.text)
end)
source: panel.rs:76
panel:post(arg2: string, arg3: any)
Send a named message with a JSON payload to the panel.
Serializes arg3 to JSON and dispatches it to this panel under the name arg2. Returns false (logging a warning) if the panel id is not declared in the manifest or if the serialized payload exceeds 1 MB; otherwise dispatches and returns true.
| Param | Type | Notes |
|---|---|---|
arg2 | string | Message name. |
arg3 | any | Payload value; converted to JSON before dispatch. |
Returns boolean — true if the message was dispatched, false if the panel is undeclared or the payload exceeds 1 MB.
Note: Payloads larger than 1 MB when serialized are dropped and return false.
local panel = mud.panel("my.panel")
panel:post("connects", { n = get_or("connects", 0) })
source: panel.rs:49