lmmagnum reference
Complete reference for lmmagnum 0.2.15: the context object, 7 host types, 58 host methods, 2 host functions, enumerated strings, CLI flags, exit codes and the vendored standard library. Signatures are taken verbatim from the output of lmmagnum --lmcode-signatures (267 lines: 1 context, 85 functions, 181 methods). Argument meanings are described from the usage in the repository examples; the implementation source is not public.
Context objects
| Name | Type | Purpose |
|---|---|---|
| scene | Scene | The one scene of the host process: shapes, groups, textures, camera, lights, render and export |
Host functions
| Function | Signature | Purpose |
|---|---|---|
| material | () -> Material | Create a new material to configure by chaining |
| magnum_version | () -> string | Identifier of the embedded Magnum build; 0.2.15 returns 369e9620ab22 |
Host types
| Type | Methods | Obtained from | Role |
|---|---|---|---|
| Scene | 31 | Context object scene | Scene settings, primitive constructors, textures, render, accumulation, export, counts |
| Shape | 9 | Scene primitive constructors | One mesh instance with transform, colour, texture, name, visibility and parent |
| Material | 5 | material() | Colour, specular, shininess, roughness and texture |
| Texture | 7 | scene.texture, scene.texture_checker, scene.texture_file | Image sampled by materials and shapes |
| Group | 4 | scene.group() | Scene graph node that shapes and other groups are parented to |
| Camera | 1 | scene.camera | The view |
| Light | 1 | scene.directional_light | A directional light |
Host methods
All 58 host method signatures, as printed by the host.
| Type | Method | Signature |
|---|---|---|
| Camera | look_at | (float, float, float, float, float, float) -> Camera |
| Group | parent | (Group) -> Group |
| Group | rotate | (float, float, float) -> Group |
| Group | scale | (float, float, float) -> Group |
| Group | translate | (float, float, float) -> Group |
| Light | intensity | (float) -> Light |
| Material | color | (float, float, float) -> Material |
| Material | roughness | (float) -> Material |
| Material | shininess | (float) -> Material |
| Material | specular | (float) -> Material |
| Material | texture | (Texture) -> Material |
| Scene | accumulate | (int, int) -> void |
| Scene | ambient | (float) -> Scene |
| Scene | background | (float, float, float) -> Scene |
| Scene | box | (float, float, float, Material) -> Shape |
| Scene | camera | (float, float, float, float, float, float, float) -> Camera |
| Scene | capsule | (float, float, Material) -> Shape |
| Scene | cone | (float, float, Material) -> Shape |
| Scene | cube | (float, Material) -> Shape |
| Scene | cylinder | (float, float, Material) -> Shape |
| Scene | directional_light | (float, float, float, float) -> Light |
| Scene | export_obj | (string) -> void |
| Scene | export_ply | (string) -> void |
| Scene | export_stl | (string) -> void |
| Scene | group | () -> Group |
| Scene | icosphere | (float, int, Material) -> Shape |
| Scene | plane | (float, Material) -> Shape |
| Scene | render_png | (string, int, int) -> void |
| Scene | render_ppm | (string, int, int) -> void |
| Scene | reset_accumulation | () -> void |
| Scene | ring | (float, float, Material) -> Shape |
| Scene | save_accumulated_png | (string) -> void |
| Scene | shadows | (bool) -> Scene |
| Scene | shape_count | () -> int |
| Scene | sphere | (float, Material) -> Shape |
| Scene | text | (string, float, Material) -> Shape |
| Scene | texture | (int, int) -> Texture |
| Scene | texture_checker | (int, int, float, float, float, float, float, float) -> Texture |
| Scene | texture_file | (string) -> Texture |
| Scene | triangle | (float, float, float, float, float, float, float, float, float, Material) -> Shape |
| Scene | triangle_count | () -> int |
| Scene | tube_between | (float, float, float, float, float, float, float, Material) -> Shape |
| Shape | color | (float, float, float) -> Shape |
| Shape | name | (string) -> Shape |
| Shape | parent | (Group) -> Shape |
| Shape | rotate | (float, float, float) -> Shape |
| Shape | scale | (float, float, float) -> Shape |
| Shape | texture | (Texture) -> Shape |
| Shape | translate | (float, float, float) -> Shape |
| Shape | triangle_count | () -> int |
| Shape | visible | (bool) -> Shape |
| Texture | filter | (string) -> Texture |
| Texture | height | () -> int |
| Texture | pixel | (int, int, float, float, float) -> Texture |
| Texture | repeat | (float, float) -> Texture |
| Texture | save_png | (string) -> void |
| Texture | width | () -> int |
| Texture | wrap | (string) -> Texture |
Notes on arguments
| Call | Usage in the repository examples |
|---|---|
| Scene.background, Material.color, Shape.color, Texture.pixel | Colour components are floats in the range 0 to 1 |
| Scene.camera | Seven floats; the primitives example calls scene.camera(40.0, 0.0, 1.5, 9.0, 0.0, -0.5, 0.0) |
| Scene.directional_light | Three direction floats and an intensity, for example (-0.5, -1.0, -0.4, 0.9) |
| Scene.render_png, Scene.render_ppm | Path, width in pixels, height in pixels |
| Scene.tube_between | Start point, end point, radius, material |
| Scene.triangle | Nine floats (three points) and a material |
| Shape.rotate | Three angles in degrees, for example rotate(-90.0, 0.0, 0.0) to lay a plane flat |
| Scene.texture_file | Path to a PNG, JPEG, BMP or TGA image |
| Material.texture, Shape.texture | The texture multiplies the colour; use white for the image as is |
Enumerated string values
| Method | Values used in the repository examples | Meaning |
|---|---|---|
| Texture.filter | linear, nearest | Trilinear mip filtering by default; nearest on request |
| Texture.wrap | repeat, clamp, mirror | Addressing outside the 0 to 1 UV range |
File formats
| Direction | Formats | Methods |
|---|---|---|
| Image output | PNG, PPM | Scene.render_png, Scene.render_ppm, Scene.save_accumulated_png, Texture.save_png |
| Mesh output | OBJ, STL, PLY | Scene.export_obj, Scene.export_stl, Scene.export_ply |
| Texture input | PNG, JPEG, BMP, TGA | Scene.texture_file |
CLI flags
| Flag | Effect | Exit |
|---|---|---|
| --version | Print lmmagnum and the version | 0 |
| --lmcode-schema --json | Print the embedded schema JSON with the keys dsl.schema (2), name (lmmagnum), types, functions and context | 0 |
| --lmcode-signatures | Print every signature, one per line | 0 |
| --lmcode FILE [FILE ...] | Run compiled bytecode; each file must be readable and no larger than 16 MiB | 0 or 3 |
The usage line printed by the host is: usage: lmmagnum --version | --lmcode-schema [--json] | --lmcode-signatures | --lmcode FILE [FILE ...]
Exit codes and result frame
| Exit | Phase | Code | Meaning |
|---|---|---|---|
| 0 | Success | ||
| 2 | cli | CLI_USAGE | Missing or unknown arguments |
| 3 | load | RUN_HOST | Bytecode input missing, unreadable or larger than 16 MiB |
The host prints the result frame as one JSON line between the marker lines LMCODE_RETURN_BEGIN and LMCODE_RETURN_END. run_lmcode turns it into the map it returns: ok and result on success; ok false with phase, code and message on failure.
Standard library (lmcode_std_v3)
lmmagnum 0.2.15 ships the lmcode_std_v3 catalog with 206 canonical signatures: 83 function signatures and 123 method signatures on 16 standard types. The library needs no import and is callable in any lmmagnum block next to the scene context. The result sink functions fill the result field of the run_lmcode envelope.
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 | Whole-file read, write, append, existence test and 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
| Function | Signature |
|---|---|
| file_append | (string, string) -> void |
| file_exists | (string) -> bool |
| file_lines | (string) -> StrList |
| file_read | (string) -> string |
| file_write | (string, string) -> void |
| float_list | () -> FloatList |
| float_map | () -> FloatMap |
| float_pq | () -> FloatPQ |
| float_queue | () -> FloatQueue |
| float_stack | () -> FloatStack |
| int_list | () -> IntList |
| int_map | () -> IntMap |
| int_pq | () -> IntPQ |
| int_queue | () -> IntQueue |
| int_stack | () -> IntStack |
| json_parse | (string) -> Json |
| lmcode_return_null | () -> void |
| lmcode_return_put | (string, FloatList) -> void |
| lmcode_return_put | (string, FloatMap) -> void |
| lmcode_return_put | (string, IntList) -> void |
| lmcode_return_put | (string, IntMap) -> void |
| lmcode_return_put | (string, Json) -> void |
| lmcode_return_put | (string, StrList) -> void |
| lmcode_return_put | (string, StrMap) -> void |
| lmcode_return_put | (string, bool) -> void |
| lmcode_return_put | (string, float) -> void |
| lmcode_return_put | (string, int) -> void |
| lmcode_return_put | (string, string) -> void |
| lmcode_return_put_null | (string) -> void |
| lmcode_return_set | (FloatList) -> void |
| lmcode_return_set | (FloatMap) -> void |
| lmcode_return_set | (IntList) -> void |
| lmcode_return_set | (IntMap) -> void |
| lmcode_return_set | (Json) -> void |
| lmcode_return_set | (StrList) -> void |
| lmcode_return_set | (StrMap) -> void |
| lmcode_return_set | (bool) -> void |
| lmcode_return_set | (float) -> void |
| lmcode_return_set | (int) -> void |
| lmcode_return_set | (string) -> void |
| math_abs | (float) -> float |
| math_abs | (int) -> int |
| math_ceil | (float) -> float |
| math_ceil | (int) -> int |
| math_floor | (float) -> float |
| math_floor | (int) -> int |
| math_max | (float, float) -> float |
| math_max | (int, int) -> int |
| math_min | (float, float) -> float |
| math_min | (int, int) -> int |
| math_pow | (float, float) -> float |
| math_pow | (int, int) -> int |
| math_round | (float) -> float |
| math_round | (int) -> int |
| math_sqrt | (float) -> float |
| math_sqrt | (int) -> int |
| str_base64_decode | (string) -> string |
| str_base64_encode | (string) -> string |
| str_contains | (string, string) -> bool |
| str_ends_with | (string, string) -> bool |
| str_find | (string, string) -> int |
| str_hex_decode | (string) -> string |
| str_hex_encode | (string) -> string |
| str_is_float | (string) -> bool |
| str_is_int | (string) -> bool |
| str_len | (string) -> int |
| str_list | () -> StrList |
| str_lower | (string) -> string |
| str_map | () -> StrMap |
| str_match | (string, string) -> bool |
| str_pq | () -> StrPQ |
| str_queue | () -> StrQueue |
| str_repeat | (string, int) -> string |
| str_replace | (string, string, string) -> string |
| str_split | (string, string) -> StrList |
| str_stack | () -> StrStack |
| str_starts_with | (string, string) -> bool |
| str_substr | (string, int, int) -> string |
| str_to_float | (string) -> float |
| str_to_int | (string) -> int |
| str_trim | (string) -> string |
| str_upper | (string) -> string |
| template_render | (string, Json) -> string |
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 | clear | () -> FloatMap |
| FloatMap | get | (string) -> float |
| FloatMap | get_or | (string, float) -> float |
| FloatMap | has | (string) -> bool |
| FloatMap | key_at | (int) -> string |
| FloatMap | keys | () -> StrList |
| FloatMap | len | () -> int |
| FloatMap | remove | (string) -> bool |
| FloatMap | set | (string, float) -> FloatMap |
| FloatMap | values | () -> FloatList |
| FloatPQ | clear | () -> FloatPQ |
| FloatPQ | empty | () -> bool |
| FloatPQ | len | () -> int |
| FloatPQ | peek | () -> float |
| FloatPQ | pop | () -> float |
| FloatPQ | push | (float, float) -> FloatPQ |
| FloatQueue | at | (int) -> float |
| FloatQueue | clear | () -> FloatQueue |
| FloatQueue | empty | () -> bool |
| FloatQueue | len | () -> int |
| FloatQueue | peek | () -> float |
| FloatQueue | pop | () -> float |
| FloatQueue | push | (float) -> FloatQueue |
| FloatStack | at | (int) -> float |
| FloatStack | clear | () -> FloatStack |
| FloatStack | empty | () -> bool |
| FloatStack | len | () -> int |
| FloatStack | peek | () -> float |
| FloatStack | pop | () -> float |
| FloatStack | push | (float) -> FloatStack |
| 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 | clear | () -> IntMap |
| IntMap | get | (string) -> int |
| IntMap | get_or | (string, int) -> int |
| IntMap | has | (string) -> bool |
| IntMap | key_at | (int) -> string |
| IntMap | keys | () -> StrList |
| IntMap | len | () -> int |
| IntMap | remove | (string) -> bool |
| IntMap | set | (string, int) -> IntMap |
| IntMap | values | () -> IntList |
| IntPQ | clear | () -> IntPQ |
| IntPQ | empty | () -> bool |
| IntPQ | len | () -> int |
| IntPQ | peek | () -> int |
| IntPQ | pop | () -> int |
| IntPQ | push | (int, float) -> IntPQ |
| IntQueue | at | (int) -> int |
| IntQueue | clear | () -> IntQueue |
| IntQueue | empty | () -> bool |
| IntQueue | len | () -> int |
| IntQueue | peek | () -> int |
| IntQueue | pop | () -> int |
| IntQueue | push | (int) -> IntQueue |
| IntStack | at | (int) -> int |
| IntStack | clear | () -> IntStack |
| IntStack | empty | () -> bool |
| IntStack | len | () -> int |
| IntStack | peek | () -> int |
| IntStack | pop | () -> int |
| IntStack | push | (int) -> IntStack |
| Json | as_bool | () -> bool |
| Json | as_float | () -> float |
| Json | as_int | () -> int |
| Json | as_string | () -> string |
| Json | at | (int) -> Json |
| Json | get | (string) -> Json |
| Json | has | (string) -> bool |
| Json | keys | () -> StrList |
| Json | kind | () -> string |
| Json | len | () -> int |
| 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 | keys | () -> StrList |
| StrMap | len | () -> int |
| StrMap | remove | (string) -> bool |
| StrMap | set | (string, string) -> StrMap |
| StrMap | values | () -> StrList |
| StrPQ | clear | () -> StrPQ |
| StrPQ | empty | () -> bool |
| StrPQ | len | () -> int |
| StrPQ | peek | () -> string |
| StrPQ | pop | () -> string |
| StrPQ | push | (string, float) -> StrPQ |
| StrQueue | at | (int) -> string |
| StrQueue | clear | () -> StrQueue |
| StrQueue | empty | () -> bool |
| StrQueue | len | () -> int |
| StrQueue | peek | () -> string |
| StrQueue | pop | () -> string |
| StrQueue | push | (string) -> StrQueue |
| StrStack | at | (int) -> string |
| StrStack | clear | () -> StrStack |
| StrStack | empty | () -> bool |
| StrStack | len | () -> int |
| StrStack | peek | () -> string |
| StrStack | pop | () -> string |
| StrStack | push | (string) -> StrStack |
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 lmmagnum vendors are the former lmcode_std_rest_v1 module: 5 functions and 15 RestExchange methods, together with 10 standard interfaces. lmmagnum does not ship them yet; it picks them up when it syncs its pinned lmcode-cpp SDK and publishes a release. Until then a lmmagnum program that calls rest_route or declares a RestGet handler does not compile against the lmmagnum 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 |