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

NameTypePurpose
sceneSceneThe one scene of the host process: shapes, groups, textures, camera, lights, render and export

Host functions

FunctionSignaturePurpose
material() -> MaterialCreate a new material to configure by chaining
magnum_version() -> stringIdentifier of the embedded Magnum build; 0.2.15 returns 369e9620ab22

Host types

TypeMethodsObtained fromRole
Scene31Context object sceneScene settings, primitive constructors, textures, render, accumulation, export, counts
Shape9Scene primitive constructorsOne mesh instance with transform, colour, texture, name, visibility and parent
Material5material()Colour, specular, shininess, roughness and texture
Texture7scene.texture, scene.texture_checker, scene.texture_fileImage sampled by materials and shapes
Group4scene.group()Scene graph node that shapes and other groups are parented to
Camera1scene.cameraThe view
Light1scene.directional_lightA directional light

Host methods

All 58 host method signatures, as printed by the host.

TypeMethodSignature
Cameralook_at(float, float, float, float, float, float) -> Camera
Groupparent(Group) -> Group
Grouprotate(float, float, float) -> Group
Groupscale(float, float, float) -> Group
Grouptranslate(float, float, float) -> Group
Lightintensity(float) -> Light
Materialcolor(float, float, float) -> Material
Materialroughness(float) -> Material
Materialshininess(float) -> Material
Materialspecular(float) -> Material
Materialtexture(Texture) -> Material
Sceneaccumulate(int, int) -> void
Sceneambient(float) -> Scene
Scenebackground(float, float, float) -> Scene
Scenebox(float, float, float, Material) -> Shape
Scenecamera(float, float, float, float, float, float, float) -> Camera
Scenecapsule(float, float, Material) -> Shape
Scenecone(float, float, Material) -> Shape
Scenecube(float, Material) -> Shape
Scenecylinder(float, float, Material) -> Shape
Scenedirectional_light(float, float, float, float) -> Light
Sceneexport_obj(string) -> void
Sceneexport_ply(string) -> void
Sceneexport_stl(string) -> void
Scenegroup() -> Group
Sceneicosphere(float, int, Material) -> Shape
Sceneplane(float, Material) -> Shape
Scenerender_png(string, int, int) -> void
Scenerender_ppm(string, int, int) -> void
Scenereset_accumulation() -> void
Scenering(float, float, Material) -> Shape
Scenesave_accumulated_png(string) -> void
Sceneshadows(bool) -> Scene
Sceneshape_count() -> int
Scenesphere(float, Material) -> Shape
Scenetext(string, float, Material) -> Shape
Scenetexture(int, int) -> Texture
Scenetexture_checker(int, int, float, float, float, float, float, float) -> Texture
Scenetexture_file(string) -> Texture
Scenetriangle(float, float, float, float, float, float, float, float, float, Material) -> Shape
Scenetriangle_count() -> int
Scenetube_between(float, float, float, float, float, float, float, Material) -> Shape
Shapecolor(float, float, float) -> Shape
Shapename(string) -> Shape
Shapeparent(Group) -> Shape
Shaperotate(float, float, float) -> Shape
Shapescale(float, float, float) -> Shape
Shapetexture(Texture) -> Shape
Shapetranslate(float, float, float) -> Shape
Shapetriangle_count() -> int
Shapevisible(bool) -> Shape
Texturefilter(string) -> Texture
Textureheight() -> int
Texturepixel(int, int, float, float, float) -> Texture
Texturerepeat(float, float) -> Texture
Texturesave_png(string) -> void
Texturewidth() -> int
Texturewrap(string) -> Texture

Notes on arguments

CallUsage in the repository examples
Scene.background, Material.color, Shape.color, Texture.pixelColour components are floats in the range 0 to 1
Scene.cameraSeven floats; the primitives example calls scene.camera(40.0, 0.0, 1.5, 9.0, 0.0, -0.5, 0.0)
Scene.directional_lightThree direction floats and an intensity, for example (-0.5, -1.0, -0.4, 0.9)
Scene.render_png, Scene.render_ppmPath, width in pixels, height in pixels
Scene.tube_betweenStart point, end point, radius, material
Scene.triangleNine floats (three points) and a material
Shape.rotateThree angles in degrees, for example rotate(-90.0, 0.0, 0.0) to lay a plane flat
Scene.texture_filePath to a PNG, JPEG, BMP or TGA image
Material.texture, Shape.textureThe texture multiplies the colour; use white for the image as is

Enumerated string values

MethodValues used in the repository examplesMeaning
Texture.filterlinear, nearestTrilinear mip filtering by default; nearest on request
Texture.wraprepeat, clamp, mirrorAddressing outside the 0 to 1 UV range

File formats

DirectionFormatsMethods
Image outputPNG, PPMScene.render_png, Scene.render_ppm, Scene.save_accumulated_png, Texture.save_png
Mesh outputOBJ, STL, PLYScene.export_obj, Scene.export_stl, Scene.export_ply
Texture inputPNG, JPEG, BMP, TGAScene.texture_file

CLI flags

FlagEffectExit
--versionPrint lmmagnum and the version0
--lmcode-schema --jsonPrint the embedded schema JSON with the keys dsl.schema (2), name (lmmagnum), types, functions and context0
--lmcode-signaturesPrint every signature, one per line0
--lmcode FILE [FILE ...]Run compiled bytecode; each file must be readable and no larger than 16 MiB0 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

ExitPhaseCodeMeaning
0Success
2cliCLI_USAGEMissing or unknown arguments
3loadRUN_HOSTBytecode 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

GroupSignaturesPurpose
String17Byte-string search, slicing, case, split, replace, numeric parsing and glob match
Encoding4Base64 and hexadecimal encode and decode
Math16Integer and float overloads of abs, ceil, floor, max, min, pow, round and sqrt
File5Whole-file read, write, append, existence test and line split
Collection constructors15Create empty lists, maps, queues, stacks and priority queues of int, float and string
JSON and templates2Parse JSON text into a Json value; render a text template from a Json value
Result sink24Set the value that run_lmcode returns as result: one value, or named fields
Collection and Json methods123Methods of the 16 standard types listed below
Total20683 function signatures plus 123 method signatures

Standard functions

FunctionSignature
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

TypeMethodSignature
FloatListadd(float) -> FloatList
FloatListat(int) -> float
FloatListclear() -> FloatList
FloatListcontains(float) -> bool
FloatListindex_of(float) -> int
FloatListlen() -> int
FloatListset(int, float) -> FloatList
FloatMapclear() -> FloatMap
FloatMapget(string) -> float
FloatMapget_or(string, float) -> float
FloatMaphas(string) -> bool
FloatMapkey_at(int) -> string
FloatMapkeys() -> StrList
FloatMaplen() -> int
FloatMapremove(string) -> bool
FloatMapset(string, float) -> FloatMap
FloatMapvalues() -> FloatList
FloatPQclear() -> FloatPQ
FloatPQempty() -> bool
FloatPQlen() -> int
FloatPQpeek() -> float
FloatPQpop() -> float
FloatPQpush(float, float) -> FloatPQ
FloatQueueat(int) -> float
FloatQueueclear() -> FloatQueue
FloatQueueempty() -> bool
FloatQueuelen() -> int
FloatQueuepeek() -> float
FloatQueuepop() -> float
FloatQueuepush(float) -> FloatQueue
FloatStackat(int) -> float
FloatStackclear() -> FloatStack
FloatStackempty() -> bool
FloatStacklen() -> int
FloatStackpeek() -> float
FloatStackpop() -> float
FloatStackpush(float) -> FloatStack
IntListadd(int) -> IntList
IntListat(int) -> int
IntListclear() -> IntList
IntListcontains(int) -> bool
IntListindex_of(int) -> int
IntListlen() -> int
IntListset(int, int) -> IntList
IntMapclear() -> IntMap
IntMapget(string) -> int
IntMapget_or(string, int) -> int
IntMaphas(string) -> bool
IntMapkey_at(int) -> string
IntMapkeys() -> StrList
IntMaplen() -> int
IntMapremove(string) -> bool
IntMapset(string, int) -> IntMap
IntMapvalues() -> IntList
IntPQclear() -> IntPQ
IntPQempty() -> bool
IntPQlen() -> int
IntPQpeek() -> int
IntPQpop() -> int
IntPQpush(int, float) -> IntPQ
IntQueueat(int) -> int
IntQueueclear() -> IntQueue
IntQueueempty() -> bool
IntQueuelen() -> int
IntQueuepeek() -> int
IntQueuepop() -> int
IntQueuepush(int) -> IntQueue
IntStackat(int) -> int
IntStackclear() -> IntStack
IntStackempty() -> bool
IntStacklen() -> int
IntStackpeek() -> int
IntStackpop() -> int
IntStackpush(int) -> IntStack
Jsonas_bool() -> bool
Jsonas_float() -> float
Jsonas_int() -> int
Jsonas_string() -> string
Jsonat(int) -> Json
Jsonget(string) -> Json
Jsonhas(string) -> bool
Jsonkeys() -> StrList
Jsonkind() -> string
Jsonlen() -> int
Jsonto_json() -> string
StrListadd(string) -> StrList
StrListat(int) -> string
StrListclear() -> StrList
StrListcontains(string) -> bool
StrListindex_of(string) -> int
StrListjoin(string) -> string
StrListlen() -> int
StrListset(int, string) -> StrList
StrMapclear() -> StrMap
StrMapget(string) -> string
StrMapget_or(string, string) -> string
StrMaphas(string) -> bool
StrMapkey_at(int) -> string
StrMapkeys() -> StrList
StrMaplen() -> int
StrMapremove(string) -> bool
StrMapset(string, string) -> StrMap
StrMapvalues() -> StrList
StrPQclear() -> StrPQ
StrPQempty() -> bool
StrPQlen() -> int
StrPQpeek() -> string
StrPQpop() -> string
StrPQpush(string, float) -> StrPQ
StrQueueat(int) -> string
StrQueueclear() -> StrQueue
StrQueueempty() -> bool
StrQueuelen() -> int
StrQueuepeek() -> string
StrQueuepop() -> string
StrQueuepush(string) -> StrQueue
StrStackat(int) -> string
StrStackclear() -> StrStack
StrStackempty() -> bool
StrStacklen() -> int
StrStackpeek() -> string
StrStackpop() -> string
StrStackpush(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.

InterfaceSignatureRole
RestGet(RestExchange exchange) -> voidHandler for GET routes
RestPost(RestExchange exchange) -> voidHandler for POST routes
RestPut(RestExchange exchange) -> voidHandler for PUT routes
RestDelete(RestExchange exchange) -> voidHandler for DELETE routes
RestPatch(RestExchange exchange) -> voidHandler for PATCH routes
RestHead(RestExchange exchange) -> voidHandler for HEAD routes
RestOptions(RestExchange exchange) -> voidHandler for OPTIONS routes
RestHandler(RestExchange exchange) -> voidGeneric handler bound by rest_route to an annotation name
CliCommand(RestExchange exchange) -> voidHandler for a command dispatched by rest_cli
CliOption(RestExchange exchange) -> voidHandler for an option dispatched by rest_cli
FunctionSignatureBehavior
rest_config(string, string) -> voidStore 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) -> voidRegister method, path template and handler annotation; templates accept {param} and {rest...} or :param and :rest... placeholders
rest_serve() -> voidRequest serving after the program body; routes are frozen from this call on
rest_stop() -> voidStop serving
rest_cli(StrList) -> stringStateless CLI mode: dispatch an argument vector to options, commands and REST routes and return the response text
RestExchange methodSignatureBehavior
method() -> stringRequest method
path() -> stringRequest path
query(string) -> stringQuery parameter value, empty when absent
has_query(string) -> boolWhether a query parameter is present
param(string) -> stringRoute template parameter value, empty when absent
header(string) -> stringRequest header value; repeated headers are joined with a comma and a space
has_header(string) -> boolWhether a request header is present
body() -> stringRequest body bytes
status(int) -> voidSet the response status; values outside 200..599 are a host error
set_header(string, string) -> voidSet a response header; Content-Length, Connection and Transfer-Encoding are managed by the server
send(string) -> voidSet the response body
json(string) -> voidSet the response body and the Content-Type application/json
get(string) -> stringRead a shared state value, empty when absent
set(string, string) -> voidWrite a shared state value
increment(string) -> intIncrement a shared named counter and return it

See also