Expand description
Lumen C-ABI surface.
Opaque LumenApp plus a tagged LumenValue union let any language
with C interop embed Lumen. The app’s script reaches across the ABI
through callbacks the embedder registers via lumen_app_expose.
No Rust panic escapes any lumen_* fn - every entry point wraps its
body in catch_unwind and stashes a UTF-8 message that
C callers read through lumen_last_error.
§W6.12 hardening
user_datano longer uses theusizestash trick. It now lives inUserData, aNonNull<c_void>newtype with an explicitunsafe impl Send + Syncwhose SAFETY comment names the embedder’s contract.LumenStatussplit from 5 variants into a richer error surface so C callers can branch onErrParsevsErrCssvsErrWindowinstead of one opaqueErrRuntime.LUMEN_ABI_VERSION+lumen_abi_versionexport a runtime ABI version(major << 16) | (minor << 8) | patch.lumen_last_errorkeeps its thread-local primary store but now falls back to a globalMutex<Option<CString>>when the thread has no error recorded. This trades a cheap lock for the common case where embedders calllumen_app_runon thread A and check the error on thread B.
Structs§
- Lumen
App - Builder + handle for one embedded Lumen application. Construct
with
lumen_app_new, populate withlumen_app_expose/lumen_app_set_*, run withlumen_app_run(which consumes the handle). If you decide not to run,lumen_app_freedrops it. - Lumen
Array View - Borrowed view of an array of
LumenValue. Pointer must stay valid for the duration of the call returning it. - Lumen
Event - Scalar snapshot of the event delivered to a
LumenEventFn. The string fields (type / key / value) are read separately vialumen_event_type/lumen_event_key/lumen_event_value.#[repr(C)](never packed): the fields are naturally aligned. - Lumen
Frame Info - Per-frame counters (
frame_info()). - LumenKV
- One
(key, value)pair in aLumenKVList. Both are owned, UTF-8, NUL-terminated strings freed bylumen_kvlist_free. - LumenKV
List - Owned key-value buffer returned by the string-map introspection reads.
Free with
lumen_kvlist_free. - Lumen
MapEntry - One entry in a
LumenMapView.keyis UTF-8, NUL-terminated. - Lumen
MapView - Borrowed view of a map of
LumenMapEntry. Pointer must stay valid for the duration of the call returning it. - Lumen
Node List - Owned list of node handles returned by a query / children call. Free
with
lumen_nodelist_free; index withlumen_nodelist_get. - Lumen
Pointer State - Pointer state snapshot (
pointer_state()). - Lumen
Rect - Post-layout box (design 4.7
rect()/content_rect()). Localx/yare relative to the parent;client_*are window coordinates. - Lumen
Scroll - Scroll offsets + travel limits (
scroll()). - Lumen
StrList - Owned string buffer returned by
classes/components. Free withlumen_strlist_free. - Lumen
Value - One scalar / container value crossing the C ABI in either
direction. Always pass
kindconsistently with the populated union field. Pointers are borrowed for the duration of the call; Lumen copies before returning to the script. - User
Data - Embedder-supplied opaque pointer carried across the FFI to native
callbacks. A script host moves the wrapping closure across
threads, which requires
Send + Sync- that bound is impossible to satisfy generically for*mut c_void, so this newtype carries an explicit unsafe impl with the contract spelled out in SAFETY.
Enums§
- Lumen
Kind - Discriminant for
LumenValue. - Lumen
Status - Return code for every
lumen_*C function.
Constants§
- LUMEN_
ABI_ MAJOR - Major ABI version. Bump on breaking layout/signature changes.
- LUMEN_
ABI_ MINOR - Minor ABI version. Bump on additive changes (new exports, new variants at the end of enums).
- LUMEN_
ABI_ PATCH - Patch ABI version. Bump on non-API metadata changes (docs, code, etc.).
- LUMEN_
ABI_ VERSION - Packed runtime ABI version
(major << 16) | (minor << 8) | patch. Mirrored inlumen.hasLUMEN_API_VERSION. Embedders compare at runtime to refuse a header / shared-library mismatch.
Functions§
- lumen_
abi_ version - Returns the packed ABI version this library was compiled with.
Compare against
LUMEN_API_VERSIONfromlumen.hat startup. - lumen_
app_ ⚠expose - Expose a native callback to the app’s script under
name.arg_countis the arity (0..=8 sensible); Rhai dispatches on it, Lua and candela bind the call variadically. Pointers are stored by value; the embedder ownsuser_dataand must keep it valid untillumen_app_runreturns. - lumen_
app_ ⚠expose_ v2 - Expose a native callback to the app’s script under
name, using the out-parameter callback convention (ABI 0.3). - lumen_
app_ ⚠free - Drop the app handle without running. Safe to call on null.
- lumen_
app_ ⚠new - Allocate a new app rooted at
dir(UTF-8, NUL-terminated). The directory must exist and containmain.lmnand/orlumen.toml. Returns null on error; calllumen_last_errorfor details. - lumen_
app_ ⚠new_ from_ lmna - Allocate a new app from prebuilt LMNA artifact bytes (ABI 0.7).
datapoints tolenbytes of alumenc-compiled artifact (magicLMNA); Lumen copies them in immediately, so the caller may freedataas soon as this returns.base_dir(UTF-8, NUL-terminated, or null) is the directory relative asset paths in the artifact resolve against; null means the current directory. - lumen_
app_ ⚠on_ click - Register an id-scoped native click handler (ABI 0.3).
- lumen_
app_ ⚠on_ close - Register an app-level close hook (ABI 0.5).
- lumen_
app_ ⚠run - Consume the app handle and enter the Lumen event loop. Blocks
until the window closes. After this returns,
appis freed - do not calllumen_app_freeon the same pointer. - lumen_
app_ ⚠run_ headless - Consume the app handle and drive
ticksmain-schedule ticks without opening a window or GPU surface (ABI 0.3). After this returns,appis freed - do not calllumen_app_freeon the same pointer. - lumen_
app_ ⚠set_ size - Override the initial window size in logical pixels.
- lumen_
app_ ⚠set_ title - Override the window title (default: derived from
lumen.tomlor the directory name). - lumen_
current_ ⚠page - Read the current active page key into
buf(UTF-8 + trailing NUL), following the shared string-out convention: on success*out_len(when non-null) is the byte length excluding the NUL; whenbufis null or too small,*out_lenis set to the required capacity andLumenStatus::ErrBufferTooSmallis returned. Empty before the first page mounts. Thread-safe (reads thelumen_core::navcurrent-page mirror, which lags a resolved navigation by at most one tick). - lumen_
document ⚠ - Write the document root node to
*out(0before the first tick). Thread-safe. - lumen_
document_ ⚠spawn document.spawn(tag): document-scoped create verb; writes the new handle to*out. Thread-safe.- lumen_
dump_ ⚠tree - Whole-tree structural dump. Owned C string, free with
lumen_string_free. An inspection call. - lumen_
event_ current_ target - The current event’s
current_targetnode (packed handle). Thread-safe. - lumen_
event_ ⚠key - Copy the current event’s
key(keyboard events) intobuf. Seelumen_event_typefor the convention. Thread-safe. - lumen_
event_ prevent_ default - Cancel the current event’s default action (link navigation for
click, form submission forsubmit). Thread-safe. - lumen_
event_ stop_ immediate_ propagation - Stop the current event immediately: no further handlers run, on this node or any other. Thread-safe.
- lumen_
event_ stop_ propagation - Stop the current event propagating to further nodes. Thread-safe.
- lumen_
event_ target - The current event’s target node (packed handle), or
0outside a callback. Thread-safe. - lumen_
event_ ⚠type - Copy the current event’s type name into
buf(string-out convention:*out_lenexcludes the NUL; too-small returnsLumenStatus::ErrBufferTooSmallwith the required capacity). Valid only inside aLumenEventFncallback. Thread-safe. - lumen_
event_ ⚠value - Copy the current event’s
value(input / change events) intobuf. Seelumen_event_typefor the convention. Thread-safe. - lumen_
frame_ ⚠info - Current frame counters, written to
*out. Thread-safe. - lumen_
get_ ⚠by_ id - Fast id lookup. Writes the matching node to
*out, or0when no element carriesid. Thread-safe. - lumen_
history_ ⚠go history.go(delta): stepdeltaentries (negative back, positive forward) through the in-memory history stack. Thread-safe.- lumen_
kvlist_ ⚠free - Release a
LumenKVListreturned by an introspection read. - lumen_
last_ ⚠error - Last error message set by any
lumen_*call on this thread. Returns null if no error has been recorded on this thread AND no error has been recorded globally. The pointer is valid until the nextlumen_*call on this thread that produces an error. - lumen_
last_ error_ global - Returns the most recent error message recorded by any thread.
May return null if no error has ever been recorded. The returned
pointer is valid until the next
lumen_*call anywhere in the process that produces an error. - lumen_
navigate ⚠ - Navigate the active page to
path(UTF-8, NUL-terminated).pathis a page path ("settings","/user/7","/"), resolved by longest existing.lmnprefix - not a URL scheme. Equivalent to the scriptpage("...")command and the Rust SDKSignals::navigate. Thread-safe. - lumen_
navigate_ ⚠back - Step one entry back in the in-memory history stack (desktop). No-op at the start of history. Thread-safe.
- lumen_
navigate_ ⚠forward - Step one entry forward in the in-memory history stack (desktop). No-op at the end of history. Thread-safe.
- lumen_
node_ ⚠append - Append
childunderparent(appendChild). Thread-safe. - lumen_
node_ ⚠attrs - Full attribute map of
node. Free withlumen_kvlist_free. - lumen_
node_ ⚠children - Children of
nodein document order, written to*out_list(own + free withlumen_nodelist_free). Thread-safe. - lumen_
node_ ⚠class_ add - Add one class to
node’s class list. Thread-safe. - lumen_
node_ ⚠class_ remove - Remove one class from
node’s class list. Thread-safe. - lumen_
node_ ⚠class_ toggle - Toggle one class on
node’s class list. Thread-safe. - lumen_
node_ ⚠classes - Class list of
node. Free withlumen_strlist_free. - lumen_
node_ ⚠clone - Deep-clone
source’s subtree into a fresh detached node, writing its handle to*out. Thread-safe. - lumen_
node_ ⚠closest - Nearest ancestor-or-self of
nodematchingselector, written to*out(0when none). Bad selector returnsLumenStatus::ErrCss. Thread-safe. - lumen_
node_ ⚠component - Field map of
node’snamecomponent. Free withlumen_kvlist_free. A non-whitelisted component name returnsLumenStatus::ErrBadArg. - lumen_
node_ ⚠components - Names of the whitelisted components present on
node. Free withlumen_strlist_free. - lumen_
node_ ⚠computed_ style - Full computed style of
nodeas an owned key-value buffer. Free withlumen_kvlist_free. An inspection call. Thread-safe. - lumen_
node_ ⚠content_ rect - Content-box (inner box minus padding + border) of
node. Thread-safe. - lumen_
node_ ⚠entity_ id - Raw
(index, generation)ofnode, written to*out_index/*out_gen. - lumen_
node_ ⚠first_ child - First child of
node(0when none). Thread-safe. - lumen_
node_ ⚠inline_ style - Inline-style override map of
node. Free withlumen_kvlist_free. - lumen_
node_ ⚠inner_ markup - Serialize
node’s children (not the node itself) to.lmn-ish text – the read half oflumen_node_set_inner_markup. Owned C string, free withlumen_string_free. - lumen_
node_ ⚠insert_ before - Insert
childunderparentbeforereference(insertBefore). Areferenceof0appends. Thread-safe. - lumen_
node_ ⚠is_ visible - Effective visibility of
node(1/0), written to*out. - lumen_
node_ ⚠last_ child - Last child of
node(0when none). Thread-safe. - lumen_
node_ ⚠next - Next sibling of
node(0when none). Thread-safe. - lumen_
node_ ⚠outer_ markup - Serialize
node’s subtree to.lmn-ish text. Owned C string, free withlumen_string_free. - lumen_
node_ ⚠parent - Parent of
node(0for a root or unknown handle). Thread-safe. - lumen_
node_ ⚠prev - Previous sibling of
node(0when none). Thread-safe. - lumen_
node_ ⚠rect - Post-layout border-box of
node, written to*out. Thread-safe. - lumen_
node_ ⚠remove - Detach and despawn
nodeand its subtree (node.remove). Thread-safe. - lumen_
node_ ⚠remove_ attr - Remove an attribute from
node. Thread-safe. - lumen_
node_ ⚠remove_ style - Remove an inline style property from
node. Thread-safe. - lumen_
node_ ⚠replace_ with - Replace
oldwithnewinold’s parent, despawningold’s subtree. Thread-safe. - lumen_
node_ ⚠scroll - Scroll offsets + limits of
node, written to*out. Thread-safe. - lumen_
node_ ⚠set_ attr - Set an attribute on
node. KNOWN attrs (id/class/text/disabled) route to their typed component; others land in the generic attribute map. Thread-safe. - lumen_
node_ ⚠set_ inner_ markup - Replace
node’s children with the subtree parsed frommarkup(element.innerHTML = ...). Parsed by the injected front-end and spawned through the same path the<for>reconciler uses; a no-op on the precompiled-artifact path (no parser linked). Guarded: do not feed untrusted content; this injects live markup. Thread-safe. - lumen_
node_ ⚠set_ parent - Attach
nodeunderparent(node.set_parent/ reparent). Thread-safe. - lumen_
node_ ⚠set_ style - Set an inline style property on
node(element.style). Thread-safe. - lumen_
node_ ⚠set_ text - Replace
node’s text content. Thread-safe. - lumen_
node_ ⚠spawn - Create a fresh detached element with markup tag
tag, writing its handle to*out. The handle is valid for the rest of the tick; attach it withlumen_node_append/lumen_node_set_parent. Thread-safe. - lumen_
node_ ⚠valid - Whether
nodeis present in the current snapshot (1) or not (0), written to*out. The snapshot rebuilds each tick, so a despawned node reads0. Thread-safe. - lumen_
node_ ⚠z_ index - Resolved stacking order of
node, written to*out. - lumen_
nodelist_ ⚠free - Release a
LumenNodeListreturned by a query / children call. Double-free / freeing a non-Lumen list is undefined; call once. - lumen_
nodelist_ ⚠get - Read the handle at
indexinlist, written to*out. Out-of-range (or null list) returnsLumenStatus::ErrBadArg. The iteration primitive: walk0..list.len. Thread-safe. - lumen_
off - Unbind a callback previously registered with
lumen_on. No-op for an unknown token. Thread-safe. - lumen_
on ⚠ - Bind
callbacktonodeforevent_type.capture(non-zero) makes it a capture-phase listener. Returns an off token (0on a bad argument); unbind withlumen_off. Thread-safe. - lumen_
pointer_ ⚠state - Current pointer state, written to
*out. Thread-safe. - lumen_
query ⚠ - Run a CSS selector against the current DOM snapshot, writing the
matches (document order) into
*out_list. On success the caller owns the list and must release it withlumen_nodelist_free. A bad selector returnsLumenStatus::ErrCss. Thread-safe. - lumen_
query_ ⚠len - Number of matches for
selector, written to*out_len. Thread-safe. - lumen_
query_ ⚠single - Bevy
single()contract: succeed only whenselectormatches exactly one node, writing it to*out. Zero or many matches returnsLumenStatus::ErrBadArg(and sets*outto0). Thread-safe. - lumen_
signal_ ⚠array_ get_ field - Read one field of one row of an array signal as a UTF-8 string (ABI 0.3).
- lumen_
signal_ ⚠array_ len - Report the row count of an array signal (ABI 0.3).
- lumen_
signal_ ⚠clear - Clear a signal (scalar => empty string, array => empty vec).
- lumen_
signal_ ⚠get_ bool - Read a scalar signal as a boolean, typed.
- lumen_
signal_ ⚠get_ color - Read a scalar signal as a 4-byte RGBA color.
outmust point to at least 4 writable bytes. - lumen_
signal_ ⚠get_ float64 - Read a scalar signal as an IEEE-754 double, typed.
- lumen_
signal_ ⚠get_ int64 - Read a scalar signal as a 64-bit signed integer, typed. Returns
LumenStatus::ErrBadArgwhen the signal holds no number. - lumen_
signal_ ⚠get_ str - Read a scalar signal as a UTF-8 string into a caller-provided buffer.
- lumen_
signal_ ⚠set_ array - Replace the contents of an array signal.
valuemust be aLUMEN_ARRAYofLUMEN_MAPentries - each map becomes one row (string->string after stringification) consumed by<for>markup. Pointer is borrowed for the duration of the call; Lumen copies immediately. Embedder may free buffers as soon as this returns. - lumen_
signal_ ⚠set_ bool - Set a scalar signal to a boolean, typed.
- lumen_
signal_ ⚠set_ color - Set a scalar signal to a 4-byte RGBA color (each channel in 0..=255).
rgbamust point to at least 4 bytes (R,G,B,A). - lumen_
signal_ ⚠set_ float64 - Set a scalar signal to an IEEE-754 double, typed.
- lumen_
signal_ ⚠set_ int64 - Set a scalar signal to a 64-bit signed integer, typed.
- lumen_
signal_ ⚠set_ str - Set a scalar signal to a UTF-8 string. A null
valuewrites an empty string. Thread-safe. - lumen_
signal_ ⚠watch - Subscribe to changes of the global signal
name(ABI 0.4). - lumen_
signals_ ⚠all - The whole signal set as an owned key-value buffer. Free with
lumen_kvlist_free. An inspection call. Thread-safe. - lumen_
status_ message - Returns a static, NUL-terminated UTF-8 description of
status. Useful for log messages on a non-OK return without anlumen_last_errorround-trip (which carries the thread-local context message instead of the status enum’s canonical name). The returned pointer lives for the program’s lifetime; callers must not free it. - lumen_
string_ ⚠free - Release an owned C string returned by
dump_tree/outer_markup. - lumen_
strlist_ ⚠free - Release a
LumenStrListreturned byclasses/components. - lumen_
window_ ⚠dpr window.dpr: current device-pixel ratio, written to*out. Thread-safe.- lumen_
window_ ⚠reload window.reload: re-navigate to the current page. Thread-safe.- lumen_
window_ ⚠set_ href window.set_href: navigate to a page path. Binds onto the samelumen_core::navbus aslumen_navigate. Thread-safe.- lumen_
window_ ⚠set_ size window.set_sizein logical pixels. Thread-safe.- lumen_
window_ ⚠set_ title window.set_title. Thread-safe.
Type Aliases§
- Lumen
Click Fn - Id-scoped native click callback (ABI 0.3). Registered with
lumen_app_on_click; invoked once per [ClickEvent] whose target element carries the matchingLumenId.idis the element id (UTF-8, NUL-terminated), borrowed for the duration of the call. - Lumen
Close Fn - App-level close callback (ABI 0.5). Registered with
lumen_app_on_close; invoked once per OS close request - the window close button, or (Unix) the first SIGINT/SIGTERM - before the runtime tears anything down, so embedders get a last chance to persist state. - Lumen
Event Fn - C callback invoked when a bound event fires.
eventis borrowed for the duration of the call; copy anything retained.user_datais the pointer passed tolumen_on. - Lumen
Event Token - Off token returned by
lumen_on; pass tolumen_offto unbind. - LumenFn
- Signature of an exposed callback.
argvis borrowed for the duration of the call; the returnedLumenValue(and any pointers it carries) must stay valid until this function returns - Lumen copies into aDynamicbefore unwinding. - Lumen
FnV2 - Out-parameter callback variant of
LumenFn(ABI 0.3). - Lumen
Node - Opaque packed node handle.
0means “no node”. - Lumen
Watch Fn - Signal-change subscription callback (ABI 0.4). Registered with
lumen_signal_watch; fires once per tick in which the watched global signal’s committed value changed (plus once on the first tick the value is observed after the watch is registered).
Unions§
- Lumen
Value Data - Payload union for
LumenValue. Read the field matchingLumenValue::kind.