Expand description
Lua scripting runtime for the script plugin, built on mlua’s Luau VM.
Marshals the gateway Context into a Lua table, calls the script’s
global execute(ctx) function, and marshals the returned table back into
a Context. Also installs a sandboxed require restricted to a
configured modules directory.
Structs§
- LuaRuntime
- Holds a validated Lua script and executes it against a
Context.
Constants§
- RESPOND_
PORT 🔒 - The one outcome port a script may name:
return ctx, "respond".
Functions§
- context_
to_ 🔒lua - Marshals a
Contextinto a Lua table withrequest,response, andmessagesub-tables. Header and query-param values become 1-indexed arrays of strings; bodies become Lua strings;messagevalues are converted from JSON.errorsis not exposed to scripts. - failure_
code 🔒 - The error code for a failed Lua call:
LUA_TIMEOUTwhen the deadline tripped, otherwise the caller’s code for that failure site. - field_
body 🔒 - A body field: a string, a scalar, or nil for “no body”.
- field_
string 🔒 - A required string field, named in the error so the script author knows which one to fix.
- field_
string_ 🔒lists - A header or query-parameter map. The canonical shape is a list of strings
per key (that is what the script is handed), but
headers["x-user"] = "alice"is the natural thing to write, so a bare scalar is accepted as a one-element list. Anything else names the offending key. - install_
deadline 🔒 - Installs a wall-clock deadline on
lua, returning the flag its interrupt sets when the budget runs out. - json_
to_ 🔒lua - Converts a JSON value to the corresponding Lua value (arrays become 1-indexed tables, objects become string-keyed tables).
- lua_
to_ 🔒context - The context table a script returned, field by field. Every failure names the field: an opaque “error converting Lua string to table” left script authors (and agents) guessing at the shape.
- lua_
to_ 🔒json - Converts a Lua value back to JSON. Tables with a non-zero sequence length become JSON arrays, other tables become objects with string keys; unconvertible values (functions, userdata, non-UTF-8 strings) degrade to null or empty strings rather than erroring.
- scalar_
text 🔒 - Rebuilds a
Contextfrom the table returned by the script’sexecute. - setup_
module_ 🔒loader - Registers a custom
require()loader that reads.luafiles from the modules directory. - shown_
lua_ 🔒value - Renders a Lua value for an error message: a string quoted (lossily, so a non-UTF-8 second return value renders instead of panicking), anything else by its Lua type name.