Skip to main content

Module lua_runtime

Module lua_runtime 

Source
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 Context into a Lua table with request, response, and message sub-tables. Header and query-param values become 1-indexed arrays of strings; bodies become Lua strings; message values are converted from JSON. errors is not exposed to scripts.
failure_code 🔒
The error code for a failed Lua call: LUA_TIMEOUT when 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 Context from the table returned by the script’s execute.
setup_module_loader 🔒
Registers a custom require() loader that reads .lua files 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.