lmdraw

lmdraw is a native host for retained 2D scenes written in lmscript: an _lmcode_ block builds a scene from shapes, text, diagram blocks and imported SVG, and the host renders deterministic PNG files or numbered frames. This page is the quick reference for lmdraw 0.2.7; the linked pages hold the details.

Install and run
Install lmctl, which provides the lmscript compiler and runner. A script that declares the lmdraw host downloads the release binary into the lmscript tool cache on first use. Release binaries are built for Linux x86-64 and arm64 with glibc 2.35 or newer.
npm install -g @lmctl-ai/lmctl
lmscript install github:lmctl-ai/lmdraw@latest
lmscript --check scene.lms
lmscript scene.lms
lmctl autorun https://raw.githubusercontent.com/lmctl-ai/lmdraw/main/examples/hohmann-transfer.lms
Minimal example
Save this as scene.lms and run it with lmscript scene.lms. It writes images/card.png at 1280 by 720 pixels and prints the result envelope returned by run_lmcode.
mkdir("images");
title = "Quarterly review";
p = _lmcode_ cli="lmdraw" install="github:lmctl-ai/lmdraw@latest";
scene.canvas(640, 360, "#152438");
let card = scene.rect(36.0, 36.0, 568.0, 288.0, "#1f344b");
card.set_attr("stroke", "#6fbdb4");
card.set_attr("stroke-width", "2");
let w = scene.measure_text(${title}, 38.0, true);
let heading = scene.text(320.0, 170.0, 38.0, ${title}, "#f5f8fb");
heading.set_attr("text-anchor", "middle");
heading.set_attr("font-weight", "700");
scene.line(320.0 - w / 2.0, 190.0, 320.0 + w / 2.0, 190.0, "#f5c16c", 3.0);
scene.render_png("images/card.png", 640, 360, 2);
lmcode_return_set(w);
end _lmcode_
r = run_lmcode(p);
require(r.ok, json_stringify(r));
println(json_stringify(r));
lmscript scene.lms
{"ok":true,"result":321.5179748535156}
Host protocol and CLI flags
Scripts normally reach the host through run_lmcode. The flags below are the protocol the compiler and runner use, and they are useful for inspection.
| Command | Effect |
|---|---|
| lmdraw --version | Prints the version, for example lmdraw 0.2.7. |
| lmdraw --lmcode-schema --json | Prints the embedded schema JSON the compiler checks blocks against: dsl.schema 2, name lmdraw, context scene of type Scene, six host types. |
| lmdraw --lmcode-schema | Prints the compact per-type summary of host members. |
| lmdraw --schema and lmdraw --schema --json | Earlier spellings of the same two outputs; still accepted. |
| lmdraw --lmcode-signatures | Prints every registered signature, one per line: 1 context, 46 host methods and 206 standard signatures in 0.2.7. |
| lmdraw --lmcode FILE.dslb [FILE.dslb ...] | Verifies every compiled program file, then runs them in order in one process. run_lmcode calls this for you. |
| Exit code | Meaning |
|---|---|
| 0 | Success. |
| 2 | Invalid command line (code CLI_USAGE). |
| 3 | Program file load or verification failed, or a host call failed while running. |
| 4 | Another application failure. |
Scene API at a glance
The block has one context object, scene, of type Scene. Coordinates are float CSS pixels with the origin at the upper left and y growing down; text y is the baseline. Write float arguments with a decimal point.
| Type | Members | Use |
|---|---|---|
| Scene (context scene) | canvas, load_svg, render_png | Start a scene with a size and background or from an SVG file under assets/, and write a PNG under images/ or build/rendered/. |
| Scene | rect, circle, ellipse, line, arrow, polyline, path, text, image | Primitive constructors; each returns a Node. |
| Scene | box, diamond, cylinder, note, cluster, grid, connector | Labeled diagram shapes (Shape), an invisible layout grid (Grid) and routed edges between coordinates or shape anchors. |
| Scene | lifeline, message, activation, self_message | Sequence-diagram notation; each returns a Group. |
| Scene | axes, log_axes, legend | Linear and logarithmic plot axes and a multi-series legend; each returns a Group. |
| Scene | group, linear_gradient, load_font, measure_text | Grouping, gradient paint, TrueType fonts from assets/fonts/, and text width in pixels. |
| Node | set_attr(name, value) | Update an SVG-style attribute such as fill, stroke, opacity, transform, font-weight, text-anchor, marker-end or stroke-dasharray. Values are strings. |
| Shape | set_attr, cx, cy | Style the shape body and read its center. Anchors are n, s, e, w, ne, nw, se, sw and c. |
| Grid | cell(col, row) | Returns the cell as a Shape for placing boxes and connectors. |
| Group | add(Node), add(Group), set_attr | Collect children and style them together. |
| Gradient | stop(offset, color) | Add color stops; paint with a fill or stroke of the form url(#id). |
| Limit | Value |
|---|---|
| Canvas | 1 to 4096 pixels per side and at most 8,000,000 pixels. |
| Render scale | Integer 1 to 4; scaled output at most 8,000,000 pixels. |
| Output | A .png file directly under images/ or build/rendered/. |
| Inputs | SVG directly under assets/ (at most 2 MiB); TrueType fonts directly under assets/fonts/ (at most 8 MiB); images only as embedded PNG data URIs. |
| Scene size | At most 10,000 nodes, 1,024 gradients and 128 stops per gradient. |
Standard library
lmdraw 0.2.7 registers 206 lmcode_std_v3 signatures: strings, encoding, math, collections, queues, stacks, priority queues, Json, templates, files and the lmcode_return functions. The current lmcode_std_v3 catalog has 226 signatures; the 20 added REST and CLI signatures are not in the 0.2.7 binary and arrive when lmdraw next syncs the standard library and releases. The reference page lists both sets.