lmfluid reference
Complete reference for lmfluid 0.2.2: the host command line, exit codes and result frame, the context object, all six host types with their 59 method signatures, expression syntax, CSV layouts, limits, and the standard library the host ships.
Command line
| Arguments | Behavior | Exit |
| --version | Print lmfluid and the version on stdout | 0 |
| --notices | Print the embedded third-party notices | 0 |
| --lmcode-schema --json | Print the exact embedded schema bytes (JSON, dsl.schema 2, name lmfluid) | 0 |
| --lmcode-schema | Print the registered signatures, one per line | 0 |
| --lmcode-signatures | Print the registered signatures, one per line: 266 lines in 0.2.2 (1 context, 59 host methods, 206 standard) | 0 |
| --lmcode FILE [FILE ...] | Load and verify every bytecode file, then run each in order, stopping at the first failure; one result frame on stdout | 0, 3, 4 |
| --dry-run --lmcode FILE [FILE ...] | Dry mode: load and verify without numerical work or file effects. --dry-run may also follow the files, but may appear only once | 0, 3 |
| No arguments, unknown flags, an empty file name, a file name starting with two hyphens, or extra arguments after a query flag | Usage text on stderr and a failure frame with code CLI_USAGE | 2 |
The usage text printed by the host is:
usage: lmfluid --version | --notices | --lmcode-schema [--json] | --lmcode-signatures | [--dry-run] --lmcode FILE [FILE ...]
environment: LMFLUID_MAX_MEMORY_MB total memory budget in MiB (default 4096); a program that needs more
stops with a run error (exit 3) instead of allocating
Environment variables
| Variable | Meaning |
| LMFLUID_MAX_MEMORY_MB | Total memory budget in MiB, default 4096. Must be a positive whole number; anything else is a usage error (exit 2) |
| LMCODE_INVOCATION_FILE | Set by run_lmcode to pass invocation metadata (parts, dry mode) to the host; not set by hand. A standalone --dry-run that contradicts real-mode metadata is refused with exit 2 |
| GITHUB_TOKEN | Read by lmscript, not by the host, when install="github:lmctl-ai/lmfluid@latest" resolves the release through the GitHub API |
Exit codes and result frame
| Exit | Phase in the frame | Meaning |
| 0 | | Success |
| 2 | cli | Command-line or invocation metadata error (code CLI_USAGE) |
| 3 | load, run | Bytecode could not be read or verified (for example code LOAD_BAD_BYTECODE), or a program failed while running (for example code RUN_HOST), including the memory budget |
| 4 | app | Application or output contract failure (error code APP_FAIL) |
For --lmcode invocations stdout carries exactly one frame between the marker lines LMCODE_RETURN_BEGIN and LMCODE_RETURN_END. A failure frame produced by a real run:
lmfluid --lmcode missing.dslb
LMCODE_RETURN_BEGIN
{"ok":false,"phase":"load","code":"LOAD_BAD_BYTECODE","message":"cannot read missing.dslb"}
LMCODE_RETURN_END
In dry mode the same frame additionally carries dry true. run_lmcode parses the frame and returns it to the script as a map: ok and result on success; ok, phase, code, message and, for run errors, line and column on failure.
Block declaration
prog = _lmcode_ cli="lmfluid" install="github:lmctl-ai/lmfluid@latest";
# host program: let, arithmetic, for (k in range(a, b)) { ... }, if, method calls on fluid
end _lmcode_
r = run_lmcode(prog);
assert(r.ok);
| Element | Meaning |
| cli="lmfluid" | Host binary that supplies the schema and runs the block |
| install="github:lmctl-ai/lmfluid@latest" | Release that lmscript downloads into its tool cache when the host is missing |
| run_lmcode(prog) | Run the compiled block; returns the result map |
| lmscript --check FILE.lms | Compile blocks without running; needs the host schema cached by an earlier real run |
Context objects
| Name | Type | Description |
| fluid | Fluid | The only context object. The schema declares no free host functions; everything is a method of fluid or of an object it returns |
Host types and methods
Signatures are quoted from the host schema. Parameter names in descriptions follow the repository documentation; the schema itself records only types.
Fluid
Type of the context object fluid: factory for every other type, plus helpers.
| Method | Signatures | Description |
| rect | (int, int, float, float) -> Mesh | Quadrilateral mesh of nx by ny elements on a rectangle lx by ly; boundary attributes 1 bottom, 2 right, 3 top, 4 left |
| box | (int, int, int, float, float, float) -> Mesh | Hexahedral mesh of nx by ny by nz elements on a box lx by ly by lz; attributes 1 bottom, 2 front, 3 right, 4 back, 5 left, 6 top |
| load_mesh | (string) -> Mesh | Read an MFEM mesh v1.0 or v1.2 text file; validated before parsing, other formats rejected |
| poisson | (Mesh, int) -> Problem | Problem -div(k grad u) = f on the mesh with H1 elements of the given order (1 to 3) |
| heat | (Mesh, int) -> Problem | Problem u_t - div(k grad u) = f, integrated by backward Euler; order 1 to 3 |
| elasticity | (Mesh, int) -> Problem | Isotropic linear elasticity problem (plane strain in 2D); order 1 to 3 |
| channel | (int, int, float, float) -> LBM | D2Q9 simulation nx by ny, viscosity nu, body acceleration g along x; periodic in x, walls at bottom and top; g must be finite and within ±0.02 |
| cavity | (int, int, float, float) -> LBM | D2Q9 lid-driven cavity nx by ny, viscosity nu, lid speed; magnitude of the lid speed must be below 0.2 |
| periodic | (int, int, float) -> LBM | D2Q9 simulation nx by ny, viscosity nu, periodic in both directions |
| assert_close | (float, float, float) -> void | Fail the run unless the first two values differ by at most the absolute tolerance; message assert_close failed: a vs b |
| assert_true | (bool) -> void | Fail the run with assert_true failed when the condition is false |
| matrix | (int, int) -> Matrix | Zero matrix of rows by cols for recording results; at most 10 million entries |
| eval | (string) -> float | Evaluate an expression string to a float; the result must be finite |
| print | (string) -> void | Write a line of text to stderr |
Mesh
A quadrilateral or hexahedral mesh.
| Method | Signatures | Description |
| dimension | () -> int | Space dimension of the mesh, 2 or 3 |
| elements | () -> int | Number of elements |
| save | (string) -> void | Write the mesh as an MFEM mesh text file that load_mesh can read |
Problem
A finite-element problem builder. Every builder method returns the problem, so calls chain.
| Method | Signatures | Description |
| diffusion | (string) -> Problem | Scalar coefficient k as an expression; must be finite and positive where evaluated |
| source | (string) -> Problem | Scalar source f as an expression |
| initial | (string) -> Problem | Initial condition for a heat problem at t = 0 |
| dirichlet | (int, string) -> Problem | Scalar essential boundary data on a boundary attribute; attribute 0 selects all boundaries |
| displacement | (int, string, string, string) -> Problem | Vector essential boundary data ux, uy, uz on an attribute (all components); the third expression is unused in 2D |
| force | (string, string, string) -> Problem | Body force expressions fx, fy, fz for elasticity; the third is unused in 2D |
| lame | (float, float) -> Problem | Lamé parameters lambda and mu of the isotropic material |
| tol | (float, int) -> Problem | Relative tolerance and maximum iterations of the iterative linear solver |
| solve | () -> Field | Solve a steady Poisson or elasticity problem and return the field |
| evolve | (float, float) -> Field | Advance a heat problem from t = 0 to end_time with step dt and return the final field |
Field
A computed finite-element solution. It owns its mesh and space.
| Method | Signatures | Description |
| value | (float, float) -> float; (float, float, float, int) -> float | Value at a mesh point: (x, y) reads component 0 in 2D; (x, y, z, component) takes a zero-based component. Points outside the mesh fail |
| gradient | (float, float, int) -> float; (float, float, float, int, int) -> float | Derivative at a point along direction 0 (x), 1 (y) or 2 (z): (x, y, direction), or (x, y, z, component, direction) |
| l2_error | (string) -> float | Integrated L2 error of a scalar field against an exact expression |
| l2_error_vector | (string, string, string) -> float | Integrated L2 error of a vector field against exact expressions ex, ey, ez |
| sample | (int, int) -> Matrix; (int, int, int) -> Matrix | Sample the bounding box on an nx by ny (by nz) grid; columns x, y, z, u or x, y, z, ux, uy and uz when present |
| dofs | () -> int | Number of degrees of freedom of the solution |
| components | () -> int | Number of solution components (1 for scalar problems) |
| time | () -> float | Time of the field; the end time for a heat solution |
LBM
A D2Q9 lattice-Boltzmann simulation in lattice units. Cell indices are zero-based.
| Method | Signatures | Description |
| init | (string, string) -> LBM | Set the velocity field from expressions ux, uy at cell centres; resets density to one, time to zero and the force average |
| run | (int) -> LBM | Advance the given number of lattice steps (0 to 10 million per call) from the current state |
| velocity | (int, int, int) -> float | Velocity component 0 (x) or 1 (y) at cell (ix, iy) |
| density | (int, int) -> float | Density at cell (ix, iy) |
| mass | () -> float | Total mass over fluid cells |
| max_speed | () -> float | Largest speed over fluid cells |
| kinetic_energy | () -> float | Kinetic energy over fluid cells |
| steps | () -> int | Number of steps taken since construction or the last init |
| sample | () -> Matrix | Matrix with one row per cell: x, y, rho, ux, uy, speed at centres ix+0.5, iy+0.5 |
| obstacle | (string) -> LBM | Mark cells whose centre gives expression > 0 as solid (no-slip, halfway bounceback); calls add up; at least one fluid cell must remain |
| is_solid | (int, int) -> bool | Whether cell (ix, iy) is solid |
| solid_cells | () -> int | Number of solid cells |
| solid_force | (int) -> float | Momentum-exchange force component 0 or 1 on all solid cells, averaged over the last run call |
| tau | () -> float | Relaxation time 0.5 + 3 nu |
| mach | () -> float | Mach number of the largest speed |
| vorticity | () -> Matrix | Matrix with columns x, y, omega, solid (central differences, no-slip walls) |
Matrix
A dense table of floats with zero-based indices.
| Method | Signatures | Description |
| rows | () -> int | Number of rows |
| cols | () -> int | Number of columns |
| get | (int, int) -> float | Entry at zero-based (row, col) |
| set | (int, int, float) -> Matrix | Set a finite entry at zero-based (row, col); returns the matrix |
| save_csv | (string) -> void | Write headerless CSV with 17 significant digits; overwrites the path |
Enumerated values
The schema defines no enum types. These integer and string arguments take a fixed set of values.
| Argument | Values |
| Finite-element order | 1, 2 or 3 |
| Boundary attribute | 0 for all boundaries; rect: 1 bottom, 2 right, 3 top, 4 left; box: 1 bottom, 2 front, 3 right, 4 back, 5 left, 6 top; imported meshes: their own attributes, 1 to 100000 |
| Field component | Zero-based: 0 for scalar fields; 0, 1 and, in 3D, 2 for displacement |
| Gradient direction | 0 x, 1 y, 2 z; must be below the mesh dimension |
| LBM velocity and force component | 0 x, 1 y |
| Problem kind | Chosen by the constructor: poisson, heat or elasticity |
Expression strings
| Item | Supported |
| Variables | x, y, z, t (z is 0 in 2D; lattice x and y are cell centres ix+0.5, iy+0.5) |
| Constants | Numbers and pi |
| Operators | Arithmetic and the power operator ^ |
| Functions | sin, cos, exp, log, sqrt, abs, min, max, sign and similar elementary functions |
| Constraints | Results must be finite; diffusion must be positive; an obstacle expression is solid where it is greater than 0 |
CSV layouts
| Source | Columns | Rows |
| Scalar field.sample | x, y, z, u | One per grid point of the bounding box |
| Elasticity field.sample | x, y, z, ux, uy and, in 3D, uz | One per grid point |
| flow.sample | x, y, rho, ux, uy, speed | One per lattice cell |
| flow.vorticity | x, y, omega, solid | One per lattice cell |
| fluid.matrix | Whatever the script set | As created |
Files have no header, deterministic order and 17 significant digits.
Limits and diagnostics
| Limit | Value | Message when exceeded |
| Total memory | 4096 MiB by default (LMFLUID_MAX_MEMORY_MB) | memory budget exceeded, naming the variable; exit 3 |
| Objects per arena | 100000 each for meshes, problems, fields, simulations, matrices | object limit exceeded |
| Finite-element order | 1 to 3 | FEM order outside allowed range |
| Mesh elements | 100000 | mesh element limit exceeded |
| Degrees of freedom | 1 million | |
| Sample points | 5 million | |
| fluid.matrix entries | 10 million | matrix exceeds 10 million entries |
| Lattice size | At least 3 by 3, at most 1 million cells | LBM grid must be at least 3 by 3; LBM grid exceeds 1 million cells |
| Steps per run call | 0 to 10 million | LBM steps must be between 0 and 10000000 |
| Channel acceleration | Finite, within ±0.02 | LBM acceleration must be finite and within +/-0.02 |
| Lid speed | Finite, magnitude below 0.2 | LBM lid speed must be finite and have magnitude below 0.2 |
| Viscosity | Finite and positive | LBM viscosity must be finite, positive, and representable in tau |
| Flow speed | Error at 0.45 or a non-finite value; stderr warning above Mach 0.3; stderr warning when tau is below 0.51 | LBM became numerically unstable |
| Point queries | Inside the mesh | point is outside mesh |
| Matrix access | Indices in range, finite values | Matrix index outside range; Matrix value must be finite |
Standard library (lmcode_std_v3)
lmfluid 0.2.2 vendors the lmcode-cpp SDK at the commit pinned in sdk.lock (93bddf1) and registers its standard library by default. The vendored schema fragment is named lmcode_std_v3 and has 206 canonical signatures: 83 function signatures and 123 method signatures on 16 standard types. They are available in every lmfluid block without a declaration, alongside the fluid context, and appear in lmfluid --lmcode-signatures.
In lmfluid programs the most useful groups are the result sink (return numbers to the outer script without a file), the float and string collections (collect values in a loop), the string functions (build expression strings and file names), and the file functions. The file functions add no sandbox: relative paths resolve against the working directory and writes overwrite.
Function groups
| Group | Signatures | Purpose |
| String | 17 | Byte-string search, slicing, case, split, replace, numeric parsing and glob match |
| Encoding | 4 | Base64 and hexadecimal encode and decode |
| Math | 16 | Integer and float overloads of abs, ceil, floor, max, min, pow, round and sqrt |
| File | 5 | Unrestricted whole-file byte read, write, append, existence test and LF line split |
| Collection constructors | 15 | Create empty lists, maps, queues, stacks and priority queues of int, float and string |
| JSON and templates | 2 | Parse JSON text into a Json value; render a text template from a Json value |
| Result sink | 24 | Set the value that run_lmcode returns as result: one value, or named fields |
| Collection and Json methods | 123 | Methods of the 16 standard types listed below |
| Total | 206 | 83 function signatures plus 123 method signatures |
Standard functions
| Group | Function | Signatures |
| String | str_contains | (string, string) -> bool |
| String | str_ends_with | (string, string) -> bool |
| String | str_find | (string, string) -> int |
| String | str_is_float | (string) -> bool |
| String | str_is_int | (string) -> bool |
| String | str_len | (string) -> int |
| String | str_lower | (string) -> string |
| String | str_match | (string, string) -> bool |
| String | str_repeat | (string, int) -> string |
| String | str_replace | (string, string, string) -> string |
| String | str_split | (string, string) -> StrList |
| String | str_starts_with | (string, string) -> bool |
| String | str_substr | (string, int, int) -> string |
| String | str_to_float | (string) -> float |
| String | str_to_int | (string) -> int |
| String | str_trim | (string) -> string |
| String | str_upper | (string) -> string |
| Encoding | str_base64_encode | (string) -> string |
| Encoding | str_base64_decode | (string) -> string |
| Encoding | str_hex_encode | (string) -> string |
| Encoding | str_hex_decode | (string) -> string |
| Math | math_abs | (int) -> int; (float) -> float |
| Math | math_ceil | (int) -> int; (float) -> float |
| Math | math_floor | (int) -> int; (float) -> float |
| Math | math_max | (int, int) -> int; (float, float) -> float |
| Math | math_min | (int, int) -> int; (float, float) -> float |
| Math | math_pow | (int, int) -> int; (float, float) -> float |
| Math | math_round | (int) -> int; (float) -> float |
| Math | math_sqrt | (int) -> int; (float) -> float |
| File | file_append | (string, string) -> void |
| File | file_exists | (string) -> bool |
| File | file_lines | (string) -> StrList |
| File | file_read | (string) -> string |
| File | file_write | (string, string) -> void |
| Collection constructors | float_list | () -> FloatList |
| Collection constructors | float_map | () -> FloatMap |
| Collection constructors | float_pq | () -> FloatPQ |
| Collection constructors | float_queue | () -> FloatQueue |
| Collection constructors | float_stack | () -> FloatStack |
| Collection constructors | int_list | () -> IntList |
| Collection constructors | int_map | () -> IntMap |
| Collection constructors | int_pq | () -> IntPQ |
| Collection constructors | int_queue | () -> IntQueue |
| Collection constructors | int_stack | () -> IntStack |
| Collection constructors | str_list | () -> StrList |
| Collection constructors | str_map | () -> StrMap |
| Collection constructors | str_pq | () -> StrPQ |
| Collection constructors | str_queue | () -> StrQueue |
| Collection constructors | str_stack | () -> StrStack |
| JSON and templates | json_parse | (string) -> Json |
| JSON and templates | template_render | (string, Json) -> string |
| Result sink | lmcode_return_null | () -> void |
| Result sink | lmcode_return_put | (string, bool) -> void; (string, float) -> void; (string, FloatList) -> void; (string, FloatMap) -> void; (string, int) -> void; (string, IntList) -> void; (string, IntMap) -> void; (string, Json) -> void; (string, StrList) -> void; (string, StrMap) -> void; (string, string) -> void |
| Result sink | lmcode_return_put_null | (string) -> void |
| Result sink | lmcode_return_set | (bool) -> void; (float) -> void; (FloatList) -> void; (FloatMap) -> void; (int) -> void; (IntList) -> void; (IntMap) -> void; (Json) -> void; (StrList) -> void; (StrMap) -> void; (string) -> void |
Standard types and methods
| Type | Method | Signature |
| FloatList | add | (float) -> FloatList |
| FloatList | at | (int) -> float |
| FloatList | clear | () -> FloatList |
| FloatList | contains | (float) -> bool |
| FloatList | index_of | (float) -> int |
| FloatList | len | () -> int |
| FloatList | set | (int, float) -> FloatList |
| FloatMap | len | () -> int |
| FloatMap | has | (string) -> bool |
| FloatMap | get | (string) -> float |
| FloatMap | get_or | (string, float) -> float |
| FloatMap | set | (string, float) -> FloatMap |
| FloatMap | key_at | (int) -> string |
| FloatMap | remove | (string) -> bool |
| FloatMap | clear | () -> FloatMap |
| FloatMap | keys | () -> StrList |
| FloatMap | values | () -> FloatList |
| FloatPQ | push | (float, float) -> FloatPQ |
| FloatPQ | pop | () -> float |
| FloatPQ | peek | () -> float |
| FloatPQ | len | () -> int |
| FloatPQ | empty | () -> bool |
| FloatPQ | clear | () -> FloatPQ |
| FloatQueue | push | (float) -> FloatQueue |
| FloatQueue | pop | () -> float |
| FloatQueue | peek | () -> float |
| FloatQueue | len | () -> int |
| FloatQueue | empty | () -> bool |
| FloatQueue | clear | () -> FloatQueue |
| FloatQueue | at | (int) -> float |
| FloatStack | push | (float) -> FloatStack |
| FloatStack | pop | () -> float |
| FloatStack | peek | () -> float |
| FloatStack | len | () -> int |
| FloatStack | empty | () -> bool |
| FloatStack | clear | () -> FloatStack |
| FloatStack | at | (int) -> float |
| IntList | add | (int) -> IntList |
| IntList | at | (int) -> int |
| IntList | clear | () -> IntList |
| IntList | contains | (int) -> bool |
| IntList | index_of | (int) -> int |
| IntList | len | () -> int |
| IntList | set | (int, int) -> IntList |
| IntMap | len | () -> int |
| IntMap | has | (string) -> bool |
| IntMap | get | (string) -> int |
| IntMap | get_or | (string, int) -> int |
| IntMap | set | (string, int) -> IntMap |
| IntMap | key_at | (int) -> string |
| IntMap | remove | (string) -> bool |
| IntMap | clear | () -> IntMap |
| IntMap | keys | () -> StrList |
| IntMap | values | () -> IntList |
| IntPQ | push | (int, float) -> IntPQ |
| IntPQ | pop | () -> int |
| IntPQ | peek | () -> int |
| IntPQ | len | () -> int |
| IntPQ | empty | () -> bool |
| IntPQ | clear | () -> IntPQ |
| IntQueue | push | (int) -> IntQueue |
| IntQueue | pop | () -> int |
| IntQueue | peek | () -> int |
| IntQueue | len | () -> int |
| IntQueue | empty | () -> bool |
| IntQueue | clear | () -> IntQueue |
| IntQueue | at | (int) -> int |
| IntStack | push | (int) -> IntStack |
| IntStack | pop | () -> int |
| IntStack | peek | () -> int |
| IntStack | len | () -> int |
| IntStack | empty | () -> bool |
| IntStack | clear | () -> IntStack |
| IntStack | at | (int) -> int |
| Json | kind | () -> string |
| Json | len | () -> int |
| Json | at | (int) -> Json |
| Json | get | (string) -> Json |
| Json | has | (string) -> bool |
| Json | keys | () -> StrList |
| Json | as_string | () -> string |
| Json | as_int | () -> int |
| Json | as_float | () -> float |
| Json | as_bool | () -> bool |
| Json | to_json | () -> string |
| StrList | add | (string) -> StrList |
| StrList | at | (int) -> string |
| StrList | clear | () -> StrList |
| StrList | contains | (string) -> bool |
| StrList | index_of | (string) -> int |
| StrList | join | (string) -> string |
| StrList | len | () -> int |
| StrList | set | (int, string) -> StrList |
| StrMap | clear | () -> StrMap |
| StrMap | get | (string) -> string |
| StrMap | get_or | (string, string) -> string |
| StrMap | has | (string) -> bool |
| StrMap | key_at | (int) -> string |
| StrMap | len | () -> int |
| StrMap | remove | (string) -> bool |
| StrMap | set | (string, string) -> StrMap |
| StrMap | keys | () -> StrList |
| StrMap | values | () -> StrList |
| StrPQ | push | (string, float) -> StrPQ |
| StrPQ | pop | () -> string |
| StrPQ | peek | () -> string |
| StrPQ | len | () -> int |
| StrPQ | empty | () -> bool |
| StrPQ | clear | () -> StrPQ |
| StrQueue | push | (string) -> StrQueue |
| StrQueue | pop | () -> string |
| StrQueue | peek | () -> string |
| StrQueue | len | () -> int |
| StrQueue | empty | () -> bool |
| StrQueue | clear | () -> StrQueue |
| StrQueue | at | (int) -> string |
| StrStack | push | (string) -> StrStack |
| StrStack | pop | () -> string |
| StrStack | peek | () -> string |
| StrStack | len | () -> int |
| StrStack | empty | () -> bool |
| StrStack | clear | () -> StrStack |
| StrStack | at | (int) -> string |
Standard REST and CLI interfaces (current catalog, not yet in this host)
The current lmcode_std_v3 catalog in lmcode-cpp has 226 canonical signatures. The 20 signatures beyond the 206 that lmfluid vendors are the former lmcode_std_rest_v1 module: 5 functions and 15 RestExchange methods, together with 10 standard interfaces. lmfluid does not ship them yet; it picks them up when it syncs its pinned lmcode-cpp SDK and publishes a release. Until then a lmfluid program that calls rest_route or declares a RestGet handler does not compile against the lmfluid schema.
| Interface | Signature | Role |
| RestGet | (RestExchange exchange) -> void | Handler for GET routes |
| RestPost | (RestExchange exchange) -> void | Handler for POST routes |
| RestPut | (RestExchange exchange) -> void | Handler for PUT routes |
| RestDelete | (RestExchange exchange) -> void | Handler for DELETE routes |
| RestPatch | (RestExchange exchange) -> void | Handler for PATCH routes |
| RestHead | (RestExchange exchange) -> void | Handler for HEAD routes |
| RestOptions | (RestExchange exchange) -> void | Handler for OPTIONS routes |
| RestHandler | (RestExchange exchange) -> void | Generic handler bound by rest_route to an annotation name |
| CliCommand | (RestExchange exchange) -> void | Handler for a command dispatched by rest_cli |
| CliOption | (RestExchange exchange) -> void | Handler for an option dispatched by rest_cli |
| Function | Signature | Behavior |
| rest_config | (string, string) -> void | Store a configuration key and value; the keys prefix and base_path set the route prefix and max_body_bytes sets the request body limit |
| rest_route | (string, string, string) -> void | Register method, path template and handler annotation; templates accept {param} and {rest...} or :param and :rest... placeholders |
| rest_serve | () -> void | Request serving after the program body; routes are frozen from this call on |
| rest_stop | () -> void | Stop serving |
| rest_cli | (StrList) -> string | Stateless CLI mode: dispatch an argument vector to options, commands and REST routes and return the response text |
| RestExchange method | Signature | Behavior |
| method | () -> string | Request method |
| path | () -> string | Request path |
| query | (string) -> string | Query parameter value, empty when absent |
| has_query | (string) -> bool | Whether a query parameter is present |
| param | (string) -> string | Route template parameter value, empty when absent |
| header | (string) -> string | Request header value; repeated headers are joined with a comma and a space |
| has_header | (string) -> bool | Whether a request header is present |
| body | () -> string | Request body bytes |
| status | (int) -> void | Set the response status; values outside 200..599 are a host error |
| set_header | (string, string) -> void | Set a response header; Content-Length, Connection and Transfer-Encoding are managed by the server |
| send | (string) -> void | Set the response body |
| json | (string) -> void | Set the response body and the Content-Type application/json |
| get | (string) -> string | Read a shared state value, empty when absent |
| set | (string, string) -> void | Write a shared state value |
| increment | (string) -> int | Increment a shared named counter and return it |