lmfilament reference

Every signature on this page was read from the output of lmfilament --lmcode-signatures and --lmcode-schema --json of the released lmfilament 0.3.21, which embeds Filament 1.78.1. Notes describe only what the repository README and examples state.

Context objects

NameTypeRole
filFilamentThe only context object: factory for materials, meshes, textures and scenes

Host types

TypeMethodsCreated by
Filament19The fil context object
Material7fil.material, fil.material_file
Mesh6fil.box, sphere, icosphere, cylinder, cone, capsule, plane, ring, triangle, text, tube_between, mesh_obj
Texture7fil.texture, texture_checker, texture_file
Scene14fil.scene
Part5Scene.add_part
Node4Scene.node
Total62The schema declares no host functions; everything is a method

Filament methods

MethodSignatureNotes
box(float, float, float) -> MeshProcedural box mesh
capsule(float, float, int) -> MeshProcedural capsule mesh
cone(float, float, int) -> MeshProcedural cone mesh
cylinder(float, float, int) -> MeshProcedural cylinder mesh
icosphere(float, int) -> MeshProcedural icosphere mesh
material(string, string) -> MaterialCompile Filament material source given as a string; the examples pass a name and the source text
material_file(string) -> MaterialCompile a Filament material source file
mesh_obj(string) -> MeshImport an OBJ file; vt is flipped so v = 0 is the top image row
plane(float, float) -> MeshProcedural plane mesh
ring(float, float, int) -> MeshProcedural ring mesh
scene() -> SceneCreate a scene on the Filament engine (noop backend)
sphere(float, int) -> MeshProcedural sphere mesh; examples pass radius and segment count
text(string, float) -> MeshVoxel text mesh from a 5x7 font
texture(int, int) -> TextureCreate an image of the given width and height
texture_checker(int, int, float, float, float, float, float, float) -> TextureCreate a generated checker image
texture_file(string) -> TextureLoad a PNG, JPEG, BMP or TGA image
triangle() -> MeshThe vertex-colored triangle of the upstream hellotriangle sample
tube_between(float, float, float, float, float, float, float) -> MeshTube mesh between two points; examples pass start x y z, end x y z and a radius
version() -> stringEmbedded Filament version string; 1.78.1 in lmfilament 0.3.21

Material methods

MethodSignatureNotes
name() -> stringMaterial name
package_size() -> intSize of the compiled filamat package in bytes
save(string) -> voidWrite the compiled package to a file
set_float(string, float) -> MaterialSet a float parameter by name; returns the material
set_float3(string, float, float, float) -> MaterialSet a float3 parameter such as baseColor
set_float4(string, float, float, float, float) -> MaterialSet a float4 parameter
set_texture(string, Texture) -> MaterialBind a texture to a sampler2d parameter such as albedo

Mesh methods

MethodSignatureNotes
compute_tangents() -> MeshCompute tangent frames; returns the mesh
has_colors() -> boolWhether the mesh has vertex colors
has_tangents() -> boolWhether the mesh has tangent frames
save_obj(string) -> voidExport the mesh as an OBJ file
triangle_count() -> intNumber of triangles
vertex_count() -> intNumber of vertices

Texture methods

MethodSignatureNotes
filter(string) -> TextureSampling filter; the examples use linear and nearest
height() -> intHeight in pixels
pixel(int, int, float, float, float) -> TextureSet one pixel: x, y and a color of three floats
repeat(float, float) -> TextureUV repeat factors
save_png(string) -> voidWrite the image as PNG
width() -> intWidth in pixels
wrap(string) -> TextureWrap mode; the examples use repeat, clamp and mirror

Scene methods

MethodSignatureNotes
add(Mesh, Material) -> SceneAdd a renderable from a mesh and a material; returns the scene
add_at(Mesh, Material, float, float, float) -> SceneAdd a renderable at a position x y z
add_part(Mesh, Material) -> PartAdd a renderable and return a Part that can be transformed, parented and hidden
camera(float, float, float, float, float, float, float) -> SceneSet the camera; the examples pass a field of view, an eye position and a target position
directional_light(float, float, float, float, float, float, float) -> SceneAdd a directional light; the examples pass color r g b, intensity 110000.0 and a direction x y z
light_count() -> intNumber of lights in the scene
node() -> NodeCreate a scene-graph node (Filament TransformManager)
point_light(float, float, float, float, float) -> SceneAdd a point light
render_frames(int) -> intDrive the Filament render loop for the given number of frames; no pixels are produced
render_png(string, int, int) -> voidWrite a CPU preview picture: path, width, height
renderable_count() -> intNumber of renderables in the scene
shadows(bool) -> SceneTurn the preview shadow map on or off
skybox(float, float, float) -> SceneSolid skybox color r g b
sun(float) -> SceneAdd a sun light

Part methods

MethodSignatureNotes
parent(Node) -> PartParent the part to a node
rotate(float, float, float) -> PartRotate the part; three floats
scale(float, float, float) -> PartScale the part
translate(float, float, float) -> PartMove the part; returns the part
visible(bool) -> PartShow or hide the part

Node methods

MethodSignatureNotes
parent(Node) -> NodeParent the node to another node
rotate(float, float, float) -> NodeRotate the node; three floats
scale(float, float, float) -> NodeScale the node
translate(float, float, float) -> NodeMove the node; returns the node

Enumerated string values

ParameterValues used in the repository examples
Texture.filterlinear, nearest
Texture.wraprepeat, clamp, mirror
Material.set_texture sampler name used by the previewalbedo, baseColor, color or emissive, else the first sampler
fil.texture_file formatsPNG, JPEG, BMP, TGA

CLI flags

usage: lmfilament --version | --lmcode-schema [--json] | --lmcode-signatures | --lmcode FILE [FILE ...]
FlagBehavior
--versionPrint lmfilament and the version
--lmcode-schemaPrint all signatures as text
--lmcode-schema --jsonPrint the embedded schema JSON with the keys dsl.schema (2), name, types, functions and context
--lmcode-signaturesPrint all signatures as text: 1 context line, 206 standard signatures and 62 host methods
--lmcode FILE [FILE ...]Run the compiled programs; this is the protocol that run_lmcode drives

Exit codes and result frame

ExitPhaseMeaning
0noneSuccess, also for --version and the schema flags
2cliUsage error; code CLI_USAGE
3loadA program file could not be read; code LOAD_BAD_BYTECODE

Only the exit codes observed with lmfilament 0.3.21 are listed. A failed invocation ends with one result frame on stdout:

lmfilament
usage: lmfilament --version | --lmcode-schema [--json] | --lmcode-signatures | --lmcode FILE [FILE ...]
LMCODE_RETURN_BEGIN
{"ok":false,"phase":"cli","code":"CLI_USAGE","message":"expected --lmcode FILE [FILE ...]"}
LMCODE_RETURN_END
lmfilament --lmcode missing.dslb
LMCODE_RETURN_BEGIN
{"ok":false,"phase":"load","code":"LOAD_BAD_BYTECODE","message":"cannot read missing.dslb"}
LMCODE_RETURN_END

Standard library (lmcode_std_v3)

lmfilament 0.3.21 ships 206 standard signatures: 83 function signatures and 123 method signatures on 16 standard types. They need no import and are callable in any lmfilament block next to the fil 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

FloatList

MethodSignature
add(float) -> FloatList
at(int) -> float
clear() -> FloatList
contains(float) -> bool
index_of(float) -> int
len() -> int
set(int, float) -> FloatList

FloatMap

MethodSignature
clear() -> FloatMap
get(string) -> float
get_or(string, float) -> float
has(string) -> bool
key_at(int) -> string
keys() -> StrList
len() -> int
remove(string) -> bool
set(string, float) -> FloatMap
values() -> FloatList

FloatPQ

MethodSignature
clear() -> FloatPQ
empty() -> bool
len() -> int
peek() -> float
pop() -> float
push(float, float) -> FloatPQ

FloatQueue

MethodSignature
at(int) -> float
clear() -> FloatQueue
empty() -> bool
len() -> int
peek() -> float
pop() -> float
push(float) -> FloatQueue

FloatStack

MethodSignature
at(int) -> float
clear() -> FloatStack
empty() -> bool
len() -> int
peek() -> float
pop() -> float
push(float) -> FloatStack

IntList

MethodSignature
add(int) -> IntList
at(int) -> int
clear() -> IntList
contains(int) -> bool
index_of(int) -> int
len() -> int
set(int, int) -> IntList

IntMap

MethodSignature
clear() -> IntMap
get(string) -> int
get_or(string, int) -> int
has(string) -> bool
key_at(int) -> string
keys() -> StrList
len() -> int
remove(string) -> bool
set(string, int) -> IntMap
values() -> IntList

IntPQ

MethodSignature
clear() -> IntPQ
empty() -> bool
len() -> int
peek() -> int
pop() -> int
push(int, float) -> IntPQ

IntQueue

MethodSignature
at(int) -> int
clear() -> IntQueue
empty() -> bool
len() -> int
peek() -> int
pop() -> int
push(int) -> IntQueue

IntStack

MethodSignature
at(int) -> int
clear() -> IntStack
empty() -> bool
len() -> int
peek() -> int
pop() -> int
push(int) -> IntStack

Json

MethodSignature
as_bool() -> bool
as_float() -> float
as_int() -> int
as_string() -> string
at(int) -> Json
get(string) -> Json
has(string) -> bool
keys() -> StrList
kind() -> string
len() -> int
to_json() -> string

StrList

MethodSignature
add(string) -> StrList
at(int) -> string
clear() -> StrList
contains(string) -> bool
index_of(string) -> int
join(string) -> string
len() -> int
set(int, string) -> StrList

StrMap

MethodSignature
clear() -> StrMap
get(string) -> string
get_or(string, string) -> string
has(string) -> bool
key_at(int) -> string
keys() -> StrList
len() -> int
remove(string) -> bool
set(string, string) -> StrMap
values() -> StrList

StrPQ

MethodSignature
clear() -> StrPQ
empty() -> bool
len() -> int
peek() -> string
pop() -> string
push(string, float) -> StrPQ

StrQueue

MethodSignature
at(int) -> string
clear() -> StrQueue
empty() -> bool
len() -> int
peek() -> string
pop() -> string
push(string) -> StrQueue

StrStack

MethodSignature
at(int) -> string
clear() -> StrStack
empty() -> bool
len() -> int
peek() -> string
pop() -> string
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 lmfilament vendors are the former lmcode_std_rest_v1 module: 5 functions and 15 RestExchange methods, together with 10 standard interfaces. lmfilament does not ship them yet; it picks them up when it syncs its lmcode-cpp SDK and publishes a release. Until then a lmfilament program that calls rest_route or declares a RestGet handler does not compile against the lmfilament 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