lmfinance reference
Complete reference for lmfinance 0.1.4: command-line flags, exit codes, environment, the seven context objects, every host type and method of the embedded schema, and the standard lmcode_std_v3 library the host vendors. Signatures are taken from schema/lmfinance.dsl.json in the repository.
Command line
| Flag | Behavior |
| --version | Print lmfinance X.Y.Z |
| --notices | Print the embedded third-party notices |
| --lmcode-schema --json | Print the embedded effective schema as JSON (host declarations merged with the standard library) |
| --lmcode-schema | Print the registry signatures as text |
| --lmcode-signatures | Print the registry signatures as text: context, method and function lines |
| --lmcode FILE [FILE ...] | Load and verify every compiled program, run them in order, stop at the first failure, write one result frame to standard output |
| --dry-run --lmcode FILE [FILE ...] | Load and verify every program without running any; must come first; contradicting real-mode invocation metadata is a usage error |
Exit codes
| Code | Meaning |
| 0 | Success |
| 2 | Command-line or invocation metadata error (failure phase cli, code CLI_USAGE); usage text on stderr |
| 3 | Program load error (phase load) or run error (phase run), including failed assertions, QuantLib errors and an exceeded memory budget |
| 4 | Application failure (phase app, code APP_FAIL) or failure writing output |
Environment
| Variable | Meaning |
| LMFINANCE_MAX_MEMORY_MB | Total memory budget in MiB, a positive whole number; default 4096. An invalid value is a usage error (exit 2) |
| LMCODE_INVOCATION_FILE | Set by run_lmcode to pass invocation metadata, including dry mode; not set by hand |
Result envelope
| Field | Present | Meaning |
| ok | always | true on success, false on failure |
| result | success | Value set with lmcode_return_set or lmcode_return_put, else null |
| phase | failure | cli, load, run or app |
| code | failure | Error code such as CLI_USAGE, LOAD_BAD_BYTECODE or RUN_HOST |
| message | failure | Diagnostic text; run errors start with the block line and column |
| line, column | run failure | Position in the block |
Context objects
| Name | Type | Purpose |
| market | MarketApi | evaluation date and yield curves. |
| instrument | InstrumentApi | payoffs and fixed-income instruments. |
| model | ModelApi | equity market models. |
| pricing | PricingApi | engines and valuations. |
| risk | RiskApi | bumped Greeks, rate risk, value at risk. |
| calibration | CalibrationApi | implied volatility and Heston fitting. |
| lmf | LmfApi | checks and output. |
Host types and methods
The host schema declares 19 types with 107 method signatures and no free functions. Float parameters must be finite. Objects live until the host exits; at most 4000000 objects of each kind can be created.
MarketApi
Context object market: evaluation date and yield curves.
| Method | Signature | Description |
| set_date | (string) -> void | Set the evaluation date from a YYYY-MM-DD string (years 1901 to 2199). Set it before building curves |
| date | () -> string | Current evaluation date as YYYY-MM-DD; default 2024-01-02 |
| flat_curve | (float) -> Curve | Flat continuously compounded curve at the given rate |
| zero_curve | () -> CurveBuilder | Builder for a curve from zero-rate nodes; add nodes with zero |
| bootstrap_curve | () -> CurveBuilder | Builder for a curve bootstrapped from deposit and swap quotes |
CurveBuilder
Returned by market.zero_curve and market.bootstrap_curve; methods chain.
| Method | Signature | Description |
| zero | (float, float) -> CurveBuilder | Add a node (years, zero rate); zero_curve builders only; nodes must be at distinct maturities |
| deposit | (string, float) -> CurveBuilder | Add a deposit quote (tenor such as 3M, rate); bootstrap builders only |
| swap | (string, float) -> CurveBuilder | Add a swap quote (tenor such as 5Y, rate); bootstrap builders only |
| build | () -> Curve | Build the Curve; needs at least one node or quote |
Curve
An immutable yield curve anchored to the evaluation date at which it was built.
| Method | Signature | Description |
| discount | (float) -> float | Discount factor at t years |
| zero | (float) -> float | Continuously compounded zero rate at t years; t must be positive |
| forward | (float, float) -> float | Continuously compounded forward rate between t1 and t2 years; needs 0 <= t1 < t2 |
| bumped | (float) -> Curve | New curve with dr added to every continuously compounded zero rate |
| save_csv | (string, float, int) -> void | Write (path, max years, points): space-separated rows of time, zero rate, discount factor, forward rate; 2 to 1000000 points |
InstrumentApi
Context object instrument: payoffs and fixed-income instruments.
| Method | Signature | Description |
| european_call | (float, float) -> Option | (strike, years) European call |
| european_put | (float, float) -> Option | (strike, years) European put |
| american_call | (float, float) -> Option | (strike, years) American call |
| american_put | (float, float) -> Option | (strike, years) American put |
| barrier_call | (float, float, float, string) -> Option | (strike, years, barrier, type) barrier call; type is up-in, up-out, down-in or down-out |
| barrier_put | (float, float, float, string) -> Option | (strike, years, barrier, type) barrier put; same types |
| asian_call | (float, float, string, int) -> Option | (strike, years, averaging, fixings) Asian call; averaging is geometric or arithmetic; 1 to 10000 equally spaced fixings ending at expiry |
| asian_put | (float, float, string, int) -> Option | (strike, years, averaging, fixings) Asian put |
| cap | (float, float, float) -> CapFloor | (notional, strike, years) cap on Euribor 6M; maturity in whole half years, 1 to 100 years |
| floor | (float, float, float) -> CapFloor | (notional, strike, years) floor on Euribor 6M |
| swaption | (Swap, float) -> Swaption | (swap, expiry years) option to enter the swap; expiry a whole number of months up to 50 years |
| bond | (float, float, float, int) -> Bond | (face, coupon, years, frequency) fixed-rate bond; frequency 1, 2, 4 or 12; maturity a whole number of coupon periods, at most 100 years |
| zero_bond | (float, float) -> Bond | (face, years) zero-coupon bond |
| swap | (float, float, float) -> Swap | (notional, fixed rate, years) payer swap; maturity in whole years, 1 to 100 |
CapFloor
A cap or floor.
| Method | Signature | Description |
| strike | () -> float | Strike rate |
| years | () -> float | Maturity in years |
Swaption
A swaption.
| Method | Signature | Description |
| expiry | () -> float | Expiry in years |
Option
An option payoff and exercise style.
| Method | Signature | Description |
| strike | () -> float | Strike |
| years | () -> float | Maturity in years |
Bond
A fixed-rate or zero-coupon bond.
| Method | Signature | Description |
| years | () -> float | Maturity in years |
Swap
A fixed-for-floating swap; the methods modify the swap and return it.
| Method | Signature | Description |
| receiver | () -> Swap | Make it a receiver swap (receives fixed) |
| payer | () -> Swap | Make it a payer swap (pays fixed); the default |
| spread | (float) -> Swap | Set the floating-leg spread; ignored inside a swaption |
ModelApi
Context object model: equity market models.
| Method | Signature | Description |
| black_scholes | (float, float, float, float) -> Model | (spot, rate, dividend yield, volatility) Black-Scholes-Merton model; spot and volatility positive |
| heston | (float, float, float, float, float, float, float, float) -> Model | (spot, rate, dividend yield, v0, kappa, theta, sigma, rho) Heston model; v0, kappa, theta, sigma positive, rho inside (-1, 1) |
Model
A Black-Scholes-Merton or Heston market.
| Method | Signature | Description |
| spot | () -> float | Spot price |
| param | (string) -> float | Parameter by name: spot, rate, dividend; vol for Black-Scholes; v0, kappa, theta, sigma, rho for Heston |
| with_spot | (float) -> Model | Copy with another spot |
| with_rate | (float) -> Model | Copy with another rate |
| with_vol | (float) -> Model | Copy with another volatility; Black-Scholes models only |
PricingApi
Context object pricing: engines and valuations.
| Method | Signature | Description |
| analytic | () -> Engine | Closed-form engine: European options under Black-Scholes or Heston, barrier and geometric Asian options |
| baw | () -> Engine | Barone-Adesi-Whaley approximation engine |
| binomial | (int) -> Engine | Binomial tree engine (Cox-Ross-Rubinstein) with 2 to 20000 steps |
| binomial_tree | (string, int) -> Engine | (tree, steps) binomial engine; tree is crr, jr, tian or lr |
| finite_diff | (int, int) -> Engine | (time steps, grid points) finite-difference engine; 2 to 100000 time steps, 10 to 100000 grid points |
| monte_carlo | (int, int) -> Engine | (paths, seed) Monte Carlo engine; 16 to 100000000 paths, seed at least 1 |
| price | (Option, Model, Engine) -> Result | Price an option under a model with an engine |
| bond_clean_price | (Bond, Curve) -> float | Clean price per 100 face on the curve |
| bond_npv | (Bond, Curve) -> float | Dirty value in currency on the curve |
| bond_accrued | (Bond) -> float | Accrued amount |
| bond_price_from_yield | (Bond, float) -> float | (bond, yield) clean price per 100 face |
| bond_yield | (Bond, float) -> float | (bond, clean price) yield compounded at the coupon frequency |
| bond_duration | (Bond, float) -> float | (bond, yield) modified duration |
| bond_macaulay_duration | (Bond, float) -> float | (bond, yield) Macaulay duration |
| bond_convexity | (Bond, float) -> float | (bond, yield) convexity |
| swap_npv | (Swap, Curve) -> float | Net present value on the curve |
| swap_par_rate | (Swap, Curve) -> float | Fair fixed rate on the curve |
| swap_annuity | (Swap, Curve) -> float | Fixed-leg annuity on the curve |
| capfloor_npv | (CapFloor, Curve, float) -> float | (cap or floor, curve, volatility) Black value with a flat lognormal volatility |
| capfloor_implied_vol | (CapFloor, Curve, float) -> float | (cap or floor, curve, price) Black implied volatility |
| capfloor_atm_rate | (CapFloor, Curve) -> float | At-the-money strike rate, where cap and floor have equal value |
| swaption_npv | (Swaption, Curve, float) -> float | (swaption, curve, volatility) Black value with a flat lognormal volatility |
| swaption_implied_vol | (Swaption, Curve, float) -> float | (swaption, curve, price) Black implied volatility |
| swaption_forward_rate | (Swaption, Curve) -> float | Fair rate of the forward-starting underlying swap |
Engine
A numerical method.
| Method | Signature | Description |
| name | () -> string | One of analytic, binomial, finite_diff, monte_carlo, baw |
Result
Returned by pricing.price. A Greek the engine does not provide is a run error.
| Method | Signature | Description |
| price | () -> float | Price |
| stderr | () -> float | Monte Carlo standard error |
| delta | () -> float | Delta |
| gamma | () -> float | Gamma |
| vega | () -> float | Vega per 1.00 of volatility |
| theta | () -> float | Theta per year |
| rho | () -> float | Rho per 1.00 of rate |
RiskApi
Context object risk: bumped Greeks, rate risk, value at risk.
| Method | Signature | Description |
| delta | (Option, Model, Engine) -> float | Central-difference delta (1% spot bump) with any engine; Black-Scholes model |
| gamma | (Option, Model, Engine) -> float | Central-difference gamma |
| vega | (Option, Model, Engine) -> float | Central-difference vega (volatility bump 0.001) |
| rho | (Option, Model, Engine) -> float | Central-difference rho (rate bump 0.0001) |
| theta | (Option, Model, Engine) -> float | Finite-difference theta over one day; needs more than two days to expiry |
| save_profile | (Option, Model, Engine, float, float, int, string) -> void | (option, model, engine, low spot, high spot, points, path) write space-separated rows of spot, price, delta, gamma; 2 to 100000 points |
| bond_dv01 | (Bond, Curve) -> float | Fall in bond value for +1 basis point of continuous zero rate |
| swap_dv01 | (Swap, Curve) -> float | Signed NPV change for +1 basis point; positive for a payer swap |
| var_normal | (float, float, float, float) -> float | (value, annual volatility, confidence, horizon days) parametric normal value at risk; 252 days per year |
| es_normal | (float, float, float, float) -> float | (value, annual volatility, confidence, horizon days) parametric normal expected shortfall |
| series | (string) -> Series | Read numbers from a file (whitespace or comma separated, one header line allowed) into a Series |
Series
A set of samples read by risk.series; up to 100000000 values.
| Method | Signature | Description |
| size | () -> int | Number of samples |
| get | (int) -> float | Sample at a zero-based index, in file order |
| mean | () -> float | Mean |
| std | () -> float | Sample standard deviation; needs at least 2 values |
| min | () -> float | Minimum |
| max | () -> float | Maximum |
| quantile | (float) -> float | Quantile for p in [0, 1], linear interpolation between order statistics |
| var | (float) -> float | Empirical value at risk: minus the quantile at 1 - confidence; confidence inside (0.5, 1) |
| es | (float) -> float | Empirical expected shortfall: minus the mean of the samples at or below that quantile |
CalibrationApi
Context object calibration: implied volatility and Heston fitting.
| Method | Signature | Description |
| implied_vol | (Option, Model, Engine, float) -> float | (option, model, engine, price) Black-Scholes implied volatility by Brent search in 0.0001 to 5 |
| heston | (float, float, float) -> HestonFit | (spot, rate, dividend yield) start a Heston fit |
HestonFit
A Heston calibration job; quote and guess chain.
| Method | Signature | Description |
| quote | (float, float, float) -> HestonFit | (strike, years, implied volatility) add a quote; at least 5 are needed |
| guess | (float, float, float, float, float) -> HestonFit | (v0, kappa, theta, sigma, rho) starting point; the default is 0.04, 1.5, 0.04, 0.5, -0.5 |
| fit | () -> Model | Run Levenberg-Marquardt and return the fitted Heston Model; non-convergence is a run error |
| error | () -> float | Calibration error after fit |
LmfApi
Context object lmf: checks and output.
| Method | Signature | Description |
| assert_close | (float, float, float) -> void | (a, b, tolerance) run error unless the absolute difference is within the tolerance |
| check | (bool, string) -> void | (condition, message) run error with the message when the condition is false |
| save_text | (string, string) -> void | (path, text) write a text file |
| print | (string) -> void | Write a line to standard output |
| version | () -> string | The string lmfinance X.Y.Z |
String enumerations
| Used by | Accepted values |
| instrument.barrier_call, barrier_put (type) | up-in, up-out, down-in, down-out |
| instrument.asian_call, asian_put (averaging) | geometric, arithmetic |
| pricing.binomial_tree (tree) | crr, jr, tian, lr |
| Model.param (name) | spot, rate, dividend, vol (Black-Scholes); spot, rate, dividend, v0, kappa, theta, sigma, rho (Heston) |
| Engine.name (return value) | analytic, binomial, finite_diff, monte_carlo, baw |
| CurveBuilder.deposit, swap (tenor) | Period strings such as 3M, 6M, 2Y, 30Y |
| market.set_date (date) | YYYY-MM-DD |
Standard library (lmcode_std_v3)
lmfinance 0.1.4 vendors the lmcode_std_v3 schema from lmcode-cpp at the commit pinned in sdk.lock. That vendored catalog has 206 canonical signatures: 83 function signatures and 123 method signatures on 16 standard types. They are available in every lmfinance block without declaration, next to the host types above. The file functions are unrestricted byte operations relative to the working directory.
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 lmfinance vendors are the former lmcode_std_rest_v1 module: 5 functions and 15 RestExchange methods, together with 10 standard interfaces. lmfinance does not ship them yet; it picks them up when it syncs its pinned lmcode-cpp SDK and publishes a release. Until then a lmfinance program that calls rest_route or declares a RestGet handler does not compile against the lmfinance 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 |