typed
The typed namespace: 3441 functions.
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/lightMobility
public.lightMobility() -> string
How GI baking should treat this light, resolved to "static",
"mixed" or "dynamic". Every component that puts a light in the
scene answers this, which is how a bake finds the lights it has to
account for without knowing what component authored them.
Returns string — The resolved mobility.
if light:lightMobility() == "dynamic" then ... end
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/resolveMobility
public.resolveMobility() -> string
Resolve this light's mobility to "static", "mixed" or
"dynamic" — how GI baking treats it. An explicit mobility field
wins; "auto" resolves to "dynamic" for a light something carries
(non-world participation, an animated or physics-driven entity, or
one the running world moves: entity.inMotion) and
"mixed" for the rest.
"static" bakes the light whole — direct light and bounce — and
withholds its live contribution, so it costs nothing per frame and
lights nothing that was not there at bake time.
"mixed" bakes only its bounce and keeps its direct light and shadows
live, so it still lights and shadows anything that moves. This is what
"auto" picks, because a light that stands still still shines on
characters walking under it.
"dynamic" keeps the light out of the bake entirely.
Returns string
local mob = light:resolveMobility()
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/setAngle
public.setAngle(deg: number)
Set a spot's outer cone half-angle in degrees. Nothing past it is
lit; set below innerAngle, the cone is fully bright out to it with a
hard edge there.
Parameters
degnumber— Outer cone half-angle (0..90).
light:setAngle(45)
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/setCastsShadows
public.setCastsShadows(b: boolean)
Enable or disable shadow casting. Point lights cast omnidirectional (cube) shadows; spot lights cast a single projected shadow. Capacity is capped per kind — past the cap the light stays lit but unshadowed.
Parameters
bboolean—trueto cast shadows,falseto disable.
light:setCastsShadows(true)
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/setColor
public.setColor(color: table)
Set the light color. Values >1 are auto-scaled from 0..255.
Parameters
colortable—{r, g, b}array or{r=, g=, b=}map.
light:setColor({1, 0.8, 0.5})
light:setColor({r = 255, g = 200, b = 128})
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/setDirection
public.setDirection(dirOrX: table | number, y: number?, z: number?)
Set the direction a directional or distant light travels along.
Accepts three numbers or a single {x, y, z} / {x=, y=, z=} vector.
A spot aims by face and its entity's rotation, so this raises on a
spot, naming face.
Parameters
dirOrXtable | number— Either the x component, or a{x, y, z}array /{x=, y=, z=}map.ynumber(optional) — The y component when the first argument is a number.znumber(optional) — The z component when the first argument is a number.
light:setDirection(-0.5, -1, -0.3)
light:setDirection({-0.5, -1, -0.3})
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/setFace
public.setFace(face: string)
Set the entity-local axis a spot's cone points along. One of Front,
Back, Left, Right, Top, Bottom — the world-space cone axis is
transform.rotation * face, and "Front" is the entity's own forward, so
a cone left on it follows wherever the entity is aimed.
Parameters
facestring— Face name string.
light:setFace("Bottom")
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/setInnerAngle
public.setInnerAngle(deg: number)
Set a spot's inner cone half-angle in degrees. Anything inside the
inner cone is at full intensity; the light smoothsteps to nothing between
it and angle. An inner angle at or past angle makes the cone fully
bright out to angle with a hard edge there.
Parameters
degnumber— Inner cone half-angle (0..angle).
light:setInnerAngle(15)
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/setIntensity
public.setIntensity(i: number)
Set the light intensity (0..N).
Parameters
inumber— Intensity scalar.
light:setIntensity(2.5)
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/setKind
public.setKind(lightKind: string)
Switch the light kind ("point" / "spot" / "directional" /
"ambient" / "distant"). "directional" aims the scene's sun, which is a single
field: setting it replaces whatever the sun was. "distant" is parallel
light held as a row of the scene's light buffer, so several coexist —
DirectionalLight is the component that authors one.
Parameters
lightKindstring— One of"point","spot","directional","ambient","distant".
light:setKind("directional")
typed//zero/source/libs/@builtin/components/Light/component/init/luau/public/setRadius
public.setRadius(r: number)
Set the radius (point lights only).
Parameters
rnumber— Radius in world units.
light:setRadius(15)
typed//zero/source/libs/@builtin/systems/characterController/package/Locomotion/component/init/luau/public/bodyChanged
public.bodyChanged()
State that a body was composed under this entity in place of the one
it carried (an avatar swapped to another body, even one that took the old
body's id): the next update drops the graph built for the body it drove and
builds one for the body the entity carries then. A body that leaves the
world is dropped the same way without a call. An avatar's setCharacter
calls this when it seats a body under a root that carries a Locomotion.
entity(id).component.get("Locomotion"):bodyChanged()
typed//zero/source/libs/@builtin/systems/characterController/package/Locomotion/component/init/luau/public/footingChanged
public.footingChanged()
Read the body's footing again: the footprint and ground gap the air
states sweep with come from its CharacterController's radius and
skinWidth, and the engine runs the graph with them as they were when it
took it, so this takes the graph back and the next frame hands it over
with them as they stand now. The CharacterController calls it when either
field changes.
entity(id).component.get("Locomotion"):footingChanged()
typed//zero/source/libs/@builtin/systems/characterController/package/Locomotion/component/init/luau/public/moversChanged
public.moversChanged()
Read the body's movers again: whether its entity carries a MovementState or a CharacterController decides what its velocity is measured from (against its parent, or in the world when it carries neither) and whether the engine runs its graph, and the engine runs the graph with the movers as they were when it took it, so this takes the graph back and the next frame reads them as they stand now. A MovementState and a CharacterController call it as they are added to the entity and removed from it.
entity(id).component.get("Locomotion"):moversChanged()
typed//zero/source/libs/@builtin/systems/characterController/package/Locomotion/component/init/luau/public/stats
public.stats() -> any
Where the component's graph runs and what its velocity is read from:
native true while the engine runs it in place of update, with its
program handle and frames; otherwise refusal names why it runs in
script (nil while it is still building). motion is "stated" while the
velocity is the walk the character's mover states, "measured" while it is
measured from the body's motion; space is "local" while a measured
velocity is the body's motion against its parent (it carries a
MovementState or a CharacterController), "world" while it is its motion in
the world (it carries neither, and its ancestors move it).
Returns any — { native, handle?, frames?, refusal?, motion, space }.
local where = entity(id).component.get("Locomotion"):stats()
typed/builtin//assetTypes/assetType/shared/instantiable/M/composeRecords
M.composeRecords(source: any?, records: {any}, target: EntityRef, opts: {[string]: any}?) -> (EntityRef, {[string]: string})
Compose generated entity records onto an existing owner with stable child mappings and instance overrides.
Parameters
sourceany(optional) — The asset whose type generated these records.records{any}— Flat entity records with original_id, parent_id, transforms and components.targetEntityRef— Existing owning entity.opts{[string]: any}(optional) — Instantiation options including idMap, diff and temporary.
Returns (EntityRef, {[string]: string}) — Composed owner and original-id to runtime-id map.
typed/builtin//assetTypes/assetType/shared/ref/M/build
M.build(envelope: any?) -> any
Attach the AssetRef method metatable to an envelope table. Invoked
by the Rust factory (push_asset_ref_handle →
_G.__build_asset_ref_proxy) immediately after the six envelope
fields (__ref, type, name, guid, identity, path) have
been set, so the metatable's __index only ever fires for method /
property lookups, never for the literal envelope fields.
Parameters
envelopeany(optional) — The freshly-built envelope table.
Returns any — The same table with AssetRefMT attached. Returning the table rather than relying on side-effects makes the Rust factory's pcall-then-replace flow simpler.
local r = require("@builtin::assetTypes.assetType.shared.ref").build({ type = "material", path = "/zero/source/Gold.material", ... })
typed/builtin//assetTypes/assetType/shared/ref/M/flushPendingPersists
M.flushPendingPersists()
Write out every asset whose edit-mode persistence is still coalesced, spending no allowance and waiting on no refill. The runtime-state wipe on a mode flip calls this first, so a change made in the last window before the flip reaches the asset instead of being cleared with the overlay it lives in. Call it before reading an asset's file for a value a runtime write may have just changed.
require("@builtin::assetTypes.assetType.shared.ref").flushPendingPersists()
typed/builtin//assetTypes/assetType/shared/ref/M/forgetRuntime
M.forgetRuntime(guid: string) -> boolean
Forget everything a type derived from ONE asset's content — the values
it cached in ref.runtime off the bytes that asset used to hold. Called
when an asset is removed and no asset answers for its guid any more, and
when an asset's content is REPLACED under a guid live consumers already
hold: a type memoizes its parse, its GPU handle, its settings against the
content it read, and each of those describes the previous bytes the moment
the new ones land. Emptying the table in place rather than replacing it is
what makes the clear reach every holder — the runtime table is shared by
every resolver of the copy the world holds under the guid, and a type may
be holding it directly. A recorded version's copy, held in that version's
folder, keeps a runtime table of its own and is left as it is.
Parameters
guidstring— The asset's stable guid; the copy the world holds under it is the one forgotten.
Returns boolean — True when there was runtime state to forget.
require("@builtin::assetTypes.assetType.shared.ref").forgetRuntime(ref.guid)
typed/builtin//assetTypes/assetType/shared/ref/M/loadTypeBehavior
M.loadTypeBehavior(asset_type: string) -> ({ [string]: any }?, string?)
Load an asset type's behavior.luau module table, reporting a
behavior that raised while loading. The first return is the module (nil
when the type ships no behavior.luau); the second is set when the type
HAS a behavior.luau that raised, and carries the require key plus the
error it raised.
A caller that runs the type's hooks — asset.create runs onCreate —
reads the second return to tell "this type declares no behavior" from
"this type's behavior is broken", which are opposite situations for the
asset it is about to write.
Parameters
asset_typestring— The type name (e.g."dynamicAsset","material").
Returns ({ [string]: any }?, string?) — The type module table, or nil. The load error, or nil.
local mod, err = require("@builtin::assetTypes.assetType.shared.ref").loadTypeBehavior("dialogue")
typed/builtin//assetTypes/assetType/shared/ref/M/loadTypeBehaviorOf
M.loadTypeBehaviorOf(type_ref: any?) -> ({ [string]: any }?, string?)
Load the behavior.luau module table of the asset type type_ref
names, from the folder the type asset lies in, the way
loadTypeBehavior loads it once the name has resolved. For a caller that
already holds the type asset, such as a row of asset.list("assetType").
Parameters
type_refany(optional) — The type asset: a ref or a listing row holding itsidentityandpath.
Returns ({ [string]: any }?, string?) — The type module table, or nil when the type ships no behavior.luau. The load error, or nil.
for _, t in ipairs(asset.list("assetType")) do local mod = require("@builtin::assetTypes.assetType.shared.ref").loadTypeBehaviorOf(t) end
typed/builtin//assetTypes/assetType/shared/ref/M/loadTypeModule
M.loadTypeModule(asset_type: string) -> { [string]: any }?
Load the full behavior.luau module table for an asset type
(every key the type declares), or nil when the type ships no
behavior.luau. Registry-driven resolution — same path the per-type
ref dispatch uses. Exposed so the asset-change dispatcher
(@builtin::assetTypes.assetType.shared.changeDispatch) can reach a type's onChange
hook without duplicating the resolution logic.
Parameters
asset_typestring— The type name (e.g."dynamicAsset","material").
Returns { [string]: any }? — The type module table, or nil.
local m = require("@builtin::assetTypes.assetType.shared.ref").loadTypeModule("dynamicAsset")
typed/builtin//assetTypes/assetType/shared/ref/M/onRuntimeWiped
M.onRuntimeWiped(name: string, fn: (string?) -> ())
Be told when runtime state is gone: fn(nil) after every asset's
runtime state was wiped (an edit/play flip, a render-device rebuild), and
fn(guid) after one asset's was forgotten (its content replaced in place,
or the asset removed). Called after the wipe, so fn reads the empty
state; a listener that raises is logged and the others still run. A second
subscription under the same name replaces the first. The engine
subscriptions behind it are made the first time a ref is built.
Parameters
namestring— The subscriber's name, such as its module's identity.fn(string?) -> ()— The listener.
AssetRef.onRuntimeWiped("@builtin::interfaces.applicable.contract", function(guid) restate(guid) end)
typed/builtin//assetTypes/assetType/shared/ref/M/persistInEditMode
M.persistInEditMode(self: any?)
Generic edit-mode persistence hook an assetType calls when a change of
its own is meant to reach the file. In EDIT mode, flush a ref's transient
runtime overlay (ref.runtime) to its backing asset file by invoking the
type's own saveDefinition(self), so the change syncs to peers and is
saved. Works for any assetType that defines a saveDefinition; whether a
given type's runtime writes route through here is that type's own
contract. The write-through is
rate-limited per asset: an asset carries an allowance of 8 writes that
refills at one per 250ms. Changes made in one frame are coalesced onto a
single re-emit, and a caller that changes a value and moves on has it on
disk a frame or two later. A caller that keeps changing the same asset
runs the allowance down to its refill rate, so over any span the asset
costs at most that allowance plus one write per 250ms, whatever cadence
the changes arrive at.
In PLAY mode this is a deliberate no-op: runtime overlays stay transient
(frame-fast) and are persisted back to the source asset on demand. An
assetType opts in simply by exposing ref.saveDefinition; no per-type
branching lives here.
Parameters
selfany(optional) — Any AssetRef.
require("@builtin::assetTypes.assetType.shared.ref").persistInEditMode(matRef)
typed/builtin//assetTypes/assetType/shared/ref/M/requireKeyOf
M.requireKeyOf(ref: any?) -> string?
The key an asset's own code is required by from a type's behavior: its path, which the module loader answers with the module the asset's identity names, for a world asset and a library one alike. A ref that holds no path is required by the path its guid resolves to, and only a ref with neither by its identity.
Parameters
refany(optional) — The asset ref.
Returns string? — The require key, or nil when the ref names nothing.
local ok, mod = pcall(require, AssetRef.requireKeyOf(moduleRef))
typed/builtin//assetTypes/assetType/shared/ref/M/requireTypeModule
M.requireTypeModule(identity: string?, path: string?, stem: string?, accept: ((any) -> boolean)?) -> (any?, string?)
Require a module inside an asset folder — a type's <stem>.luau
("behavior", a settings schema file's own stem, or any other module a
type.yaml names), or, with no stem, the asset's own entry module (its
init.luau, as an importer or a component ships) — from wherever the
asset lives (the builtin library, a world-authored folder, a vendored
library), through the ONE resolution that works for all of them: see
the comment above for the routes it tries in order.
Parameters
identitystring(optional) — The asset's own resolved identity (ref.identity), or nil.pathstring(optional) — The asset's own resolved folder path (ref.path), or nil.stemstring(optional) — The module's file stem (its filename with.luaustripped), or nil for the asset's entry module.accept((any) -> boolean)(optional) — Optional acceptance check a loaded module must satisfy to count as a hit — distinguishing "declares none" from "failed to load" for a module whose shape this caller knows. Omit to accept any table.
Returns (any?, string?) — The loaded module, or nil. The load error, when a module existed at some route but failed to load — the require key and what it raised.
local schema, err = require("@builtin::assetTypes.assetType.shared.ref").requireTypeModule(identity, path, "settings")
typed/builtin//assetTypes/assetType/shared/ref/M/typeModuleKeys
M.typeModuleKeys(identity: string?, path: string?, stem: string?) -> { string }
The require keys requireTypeModule tries, in order, for a module
inside an asset folder: the asset's identity with the stem appended, then
the folder path under @local/. A key reads true from library.has once
the module source is registered under it.
Parameters
identitystring(optional) — The asset's own resolved identity (ref.identity), or nil.pathstring(optional) — The asset's own resolved folder path (ref.path), or nil.stemstring(optional) — The module's file stem, or nil for the asset's entry module.
Returns { string } — The keys.
for _, key in ipairs(AssetRef.typeModuleKeys(ref.identity, ref.path, "schema")) do print(library.has(key)) end
typed/builtin//assetTypes/assetType/shared/ref/assetRef/as
assetRef.as(self, interface: string) -> any
A view of this asset through an interface its type implements: the interface's members are methods and its properties are fields. Raises when the type does not implement it.
Parameters
selfinterfacestring
Returns any
typed/builtin//assetTypes/assetType/shared/ref/assetRef/canInstantiate
assetRef.canInstantiate(self) -> boolean
Whether this asset can be instantiated into a scene, which is true exactly when its type implements sceneInstantiable.
Parameters
self
Returns boolean
typed/builtin//assetTypes/assetType/shared/ref/assetRef/canPreview
assetRef.canPreview(self) -> boolean
Whether this asset can render a preview, which is true when its type declares a preview recipe in its type.yaml, defines its own preview, or defines an instantiate method.
Parameters
self
Returns boolean
typed/builtin//assetTypes/assetType/shared/ref/assetRef/cpu_resident
assetRef.cpu_resident -> boolean
Whether this asset's bytes are warm in memory for a live script-component context.
Returns boolean
typed/builtin//assetTypes/assetType/shared/ref/assetRef/deps
assetRef.deps(self) -> { deps: { any }, unresolved_deps: { any }, problems: { any } }
This asset's outbound references, the literals nothing answered, and the problems attached to it.
Parameters
self
Returns { deps: { any }, unresolved_deps: { any }, problems: { any } }
typed/builtin//assetTypes/assetType/shared/ref/assetRef/events
assetRef.events -> { [string]: any }?
The subscribe-only view over the events this asset's type declares, each entry carrying connect / once / wait.
Returns { [string]: any }?
typed/builtin//assetTypes/assetType/shared/ref/assetRef/exists
assetRef.exists(self) -> boolean
Whether the VFS holds this asset at its path: a folder asset's folder or a loose asset's file.
Parameters
self
Returns boolean
typed/builtin//assetTypes/assetType/shared/ref/assetRef/getBytes
assetRef.getBytes(self, filename: string?) -> string?
This asset's content bytes, or the bytes of one named file inside a composite asset.
Parameters
selffilenamestring(optional)
Returns string?
typed/builtin//assetTypes/assetType/shared/ref/assetRef/getSource
assetRef.getSource(self, filename: string?) -> string?
This asset's content bytes, or the bytes of one named file inside a composite asset.
Parameters
selffilenamestring(optional)
Returns string?
typed/builtin//assetTypes/assetType/shared/ref/assetRef/getText
assetRef.getText(self, filename: string?) -> string?
This asset's content bytes, or the bytes of one named file inside a composite asset.
Parameters
selffilenamestring(optional)
Returns string?
typed/builtin//assetTypes/assetType/shared/ref/assetRef/gpu_resident
assetRef.gpu_resident -> boolean
Whether the device holds a texture or mesh under this asset's guid.
Returns boolean
typed/builtin//assetTypes/assetType/shared/ref/assetRef/has_backing_asset
assetRef.has_backing_asset -> boolean
Whether a /zero/source/ asset backs this ref.
Returns boolean
typed/builtin//assetTypes/assetType/shared/ref/assetRef/has_runtime_changes
assetRef.has_runtime_changes -> boolean
Whether a runtime copy of this asset exists under /zero/runtime/assets/.
Returns boolean
typed/builtin//assetTypes/assetType/shared/ref/assetRef/implements
assetRef.implements(self, interface: string | { string }) -> boolean
Whether this asset's type implements an interface, or any of a list of them: its type lists it under interfaces in its type.yaml and keeps it.
Parameters
selfinterfacestring | { string }
Returns boolean
typed/builtin//assetTypes/assetType/shared/ref/assetRef/meta
assetRef.meta -> { [string]: any }?
This asset's .meta sidecar, parsed.
Returns { [string]: any }?
typed/builtin//assetTypes/assetType/shared/ref/assetRef/modules
assetRef.modules -> { [string]: any }?
The shared modules this asset's type ships, reached as ref.modules.<name>.
Returns { [string]: any }?
typed/builtin//assetTypes/assetType/shared/ref/assetRef/preview
assetRef.preview(self, opts: { [string]: any }?) -> { [string]: any }
Render this asset's preview in the preview studio, by the recipe its type declares under preview: in its type.yaml.
Parameters
selfopts{ [string]: any }(optional)
Returns { [string]: any }
typed/builtin//assetTypes/assetType/shared/ref/assetRef/runtime
assetRef.runtime -> { [string]: any }
The live per-asset table every resolver of this asset shares, for values that do not round-trip through the asset's bytes.
Returns { [string]: any }
typed/builtin//assetTypes/assetType/shared/ref/assetRef/typeRef
assetRef.typeRef -> string?
The guid of the asset type this asset was authored against, read from its .refs sidecar.
Returns string?
typed/builtin//assetTypes/avatar/behavior/M/onCreate
M.onCreate(name: string, opts: CreateOpts?) -> { [string]: string }
Generic-creation hook for asset.create("avatar", name, opts). Composes
the avatar from a body plus an independent movement controller and
animation system, written as avatar.json. The body is a .bundle
(skinned mesh + bones), a plain .mesh (a simple visual), or omitted (a
body-less avatar — a controller / first-person camera with no mesh).
Defaults: the standard humanoid controller and, for a humanoid body, the
shared Locomotion (clips from the locomotion preset, default "synty").
Override animation to author your own locomotion without touching movement;
pass controller = false for a body the engine doesn't move; pass clip for
a single-clip ClipPlayer. Humanoid-ness drives the default animation only
and is auto-derived from a rigged body; pass humanoid to set it explicitly
(e.g. a body-less first-person avatar that still carries Humanoid).
Parameters
namestringoptsCreateOpts(optional)
Returns { [string]: string } — { ["avatar.json"] = <json> }.
asset.create("avatar", "my_hero", { body = heroBundle }) -- standard controller + locomotion
asset.create("avatar", "fp_player", { humanoid = true }) -- body-less first-person player
typed/builtin//assetTypes/avatarType/behavior/M/onChange
M.onChange(self: any?, _change: any?)
Drop the cached module and advance the generation when the type's content
changes, so the next :module() loads the edited init.luau and every rig
qualified under the old one is qualified again.
Parameters
selfany(optional) — The avatarType AssetRef that changed._changeany(optional) — What happened to it; the cache is dropped whatever it was.
typed/builtin//assetTypes/bundle/behavior/M/onCreate
M.onCreate(name: string, opts: CreateOpts?) -> { [string]: string }
Generic-creation hook for asset.create("bundle", name, opts).
With opts.entity, composes that LIVE entity's hierarchy into the new
bundle's entity_template in the same call — one step, capturing live
component state (serialized component snapshots) + transforms of the root and
every non-temporary descendant. With no opts, the bundle starts from
the template skeleton's entity_template.
Parameters
namestringoptsCreateOpts(optional)
Returns { [string]: string } — { entity_template = <JSON> } when opts.entity is given, else {}.
asset.create("bundle", "tree_prefab", { entity = rootRef })
typed/builtin//assetTypes/computeShader/behavior/TextureHandleMethods/destroy
TextureHandleMethods.destroy(self: any?) -> boolean
Destroy this texture or sampler and free its GPU memory.
Parameters
selfany(optional)
Returns boolean — True on success.
typed/builtin//assetTypes/computeShader/behavior/TextureHandleMethods/read
TextureHandleMethods.read(self: any?) -> Readback
Start a GPU→CPU read-back of this 3D texture's voxels. The read takes
frames to arrive — ask the returned Readback whether it is :ready(),
then drain it.
Parameters
selfany(optional)
Returns Readback — The Readback in flight.
local pending = density:read()
if pending:ready() then local voxels = pending:result() end
typed/builtin//assetTypes/computeShader/behavior/TextureHandleMethods/write
TextureHandleMethods.write(self: any?, data: buffer | string | { number }) -> boolean
Upload voxels into this 3D texture: a buffer or a binary string
carrying the texture's byte layout verbatim, or one number per channel in
the texture's format.
Parameters
selfany(optional)databuffer | string | { number }— Voxel bytes, or voxel values in texel order.
Returns boolean — True on success.
typed/builtin//assetTypes/computeShader/behavior/TextureHandleMethods/writeFloats
TextureHandleMethods.writeFloats(self: any?, floats: { number }, formatOrOpts: (string | { [string]: any })?) -> boolean
Upload float voxels into this 3D texture, converting to the texture's format.
Parameters
selfany(optional)floats{ number }— Voxel values in texel order.formatOrOpts(string | { [string]: any })(optional) — Source format name, or an options table.
Returns boolean — True on success.
typed/builtin//assetTypes/font/behavior/M/onChange
M.onChange(self: any?, change: any?)
Install the instance again when a file its registration reads is
written: face.json, data.zfnt, a raw font file, or the font or
coverage file an on-demand entry names. The font is then
selected by the names the descriptor now gives it and no longer by a name
it dropped, on every text surface, and text drawn in it is drawn again.
A folder that arrives whole installs once, unless onRegister already
installed it.
Parameters
selfany(optional) — The.fontinstance's AssetRef.changeany(optional) —{ path, asset, kind, ... }: the written file and how it arrived.
typed/builtin//assetTypes/font/behavior/M/onRegister
M.onRegister(self: any?)
Install this .font instance into the engine's text systems. A baked
instance is declared (font.declare) by its name, its face.json group,
role and aliases, and the coverage file face.json names; its data.zfnt
is read and registered with font.register(name, zfnt) the first time a
text names the face or needs a character it covers, which loads it into
the runtime store (for font.glyph / font.textMesh) and feeds the
embedded font bytes to the 2D text and egui UI systems. A face.json
carrying boot = true registers the face in this call. Falls back to a
raw font file, registered in this call, for instances authored before the
baked layout. An instance whose face.json lists onDemand entries is
declared by their coverage (font.declare), and each entry's file is read
the first time text needs a character it covers.
Fired once per instance by the asset system (live on asset.create, and in
the world-load sweep). Guarded so a single bad font never errors the sweep.
Parameters
selfany(optional)
typed/builtin//assetTypes/inputMap/behavior/M/onChange
M.onChange(self: any?, change: any?)
Re-activate this map after a write inside the instance, so an edit to its bindings takes hold in the running session. Only the map that is currently active is re-activated; a removal is ignored.
Parameters
selfany(optional) — The changed.inputMapasset's reference.changeany(optional) — The change record the asset dispatcher raised for the write.
typed/builtin//assetTypes/menuTab/behavior/M/onChange
M.onChange(self: any?, change: any?)
Parameters
selfany(optional)changeany(optional)
typed/builtin//assetTypes/menuTab/behavior/M/onDelete
M.onDelete(self: any?)
Parameters
selfany(optional)
typed/builtin//assetTypes/menuTab/behavior/M/onRegister
M.onRegister(self: any?)
Parameters
selfany(optional)
typed/builtin//assetTypes/mesh/behavior/M/onCreate
M.onCreate(name: string, opts: CreateOpts) -> { [string]: string }
Generic-creation hook for asset.create("mesh", name, opts). Pure:
returns the content-file map; asset.create writes it to the authored
destination, registering the .mesh asset under its minted guid. Disk-only —
nothing is uploaded to the GPU here (the GPU mesh is a separate, explicit
renderer.mesh.create step keyed by this asset's guid).
opts is raw geometry { positions, indices, normals?, uvs?, colors?, tangents?, skinning?, skins?, morphTargets? } (flat float / u32 arrays, the
per-vertex skin binding and skeleton a skinned mesh carries, and the shapes a
mesh blends towards, encoded to data.zmsh via renderer.mesh.encode), or a
pre-encoded { bytes } payload (stored verbatim).
Parameters
namestring— Mesh identity (the instance name).optsCreateOpts
Returns { [string]: string } — { ["data.zmsh"] = <ZMSH> } — the container's primary content file.
asset.create("mesh", "tree", { positions = {...}, indices = {...} })
typed/builtin//assetTypes/plugin/behavior/M/onChange
M.onChange(self: any?, change: any?)
Load the plugin again when its component or its manifest changes.
Parameters
selfany(optional) — TheAssetRef<plugin>whose files changed.changeany(optional) —{ path, kind, origin }describing the write.
typed/builtin//assetTypes/plugin/behavior/M/onDelete
M.onDelete(self: any?)
Stop the plugin this asset loaded, because the asset is gone.
Parameters
selfany(optional) — TheAssetRef<plugin>that was removed.
typed/builtin//assetTypes/plugin/behavior/M/onRegister
M.onRegister(self: any?)
Load the plugin this asset carries.
Parameters
selfany(optional) — TheAssetRef<plugin>registering.
typed/builtin//assetTypes/rig/behavior/M/onChange
M.onChange(self: any?, _change: any?)
Drop the cached decode and every qualification made from it when the rig's
content changes — a hot-reload, a re-import or an override edit — so the next read
re-derives from the new rig.json.
Parameters
selfany(optional) — The rig AssetRef that changed._changeany(optional) — What happened to it; the caches are dropped whatever it was.
typed/builtin//assetTypes/rig/behavior/M/onCreate
M.onCreate(name: string, opts: CreateOpts) -> { [string]: string }
Generic-creation hook for asset.create("rig", name, opts). Returns the
content-file map; asset.create writes it to the authored destination,
registering the .rig asset under its minted guid. A profile or humanoid
section in the incoming document is dropped: how a rig maps onto an avatar type
is derived from its bones.
Parameters
namestring— Rig identity (the instance name).optsCreateOpts
Returns { [string]: string } — { ["rig.json"] = <json> }.
asset.create("rig", "PolygonSyntyCharacter", { json = rigJson })
typed/builtin//assetTypes/rig/behavior/M/onReplace
M.onReplace(dest: string, files: { [string]: string }) -> { [string]: string }
Replacement hook: when asset.create writes a rig over one already at
dest (a re-import re-deriving the rig from its source file), the replaced
rig's overrides are carried into the new document, so what an author set by
hand survives. Overrides the new document states itself win for their type.
Parameters
deststring— The folder of the rig being replaced.files{ [string]: string }— The filesonCreateproduced for the new rig.
Returns { [string]: string } — The files to write.
typed/builtin//assetTypes/scene/shared/build/M/attribute
M.attribute(refusals: { Refusal }) -> { Refusal }
Read a refusal's traceback for the one frame that belongs to the code being built. A build composed from several contributors reports this so an author reads which contributor was refused rather than which build ran.
Parameters
refusals{ Refusal }— The refusal arrayentity.capturehands back.
Returns { Refusal } — The same entries with source filled in where a frame names one.
local named = SceneBuild.attribute(select(4, entity.capture(fn)))
typed/builtin//assetTypes/scene/shared/build/M/buildSurface
M.buildSurface(folder: string, sourceDigest: string, sourceSnapshot: any?) -> BuildSurface
The build surface a build script reads: the operations that belong to
the build itself rather than to the scene it states. build.asset(kind, name, produce) is the asset a build makes — produce runs when the build
script changed and its result is authored at <folder>/<name>.<kind>,
and every other run hands back that same asset, guid and all, without
running produce at all. The returned AssetRef is what a component field
names, so the reference survives the save and the reload.
build.key(entity, identity) gives a placement a stable identity within its
build owner and target. Names, parents and emission order can then change
while the placement keeps its entity id.
Parameters
folderstring— The build's own folder, which the assets it produces are authored inside.sourceDigeststring— The digest of the build script running now, asM.digestreports it — what decides whether an asset it produced is still the asset the code states. build.source() returns the exact source snapshot being evaluated. build.bindSource(target) records a SourceEditing target and the entities it produced.sourceSnapshotany(optional)
Returns BuildSurface — The table bound as the build global for that build.
local surface = SceneBuild.buildSurface(dir, SceneBuild.digest(src))
typed/builtin//assetTypes/scene/shared/build/M/composedRecords
M.composedRecords(document: any?, owner: string) -> ({any}, {[string]: string})
Convert composed saved entities for one build owner into reconciliation records with retained placement identities.
Parameters
documentany(optional) — A validated composed scene document, ordered parents before children.ownerstring— Build owner whose records are being activated.
Returns ({any}, {[string]: string}) — Captured-format records and their exact persistent placement assignments.
local records, placements = SceneBuild.composedRecords(composed.document, "build")
typed/builtin//assetTypes/scene/shared/build/M/digest
M.digest(source: string) -> string
A short, stable digest of a script's source. Two different scripts give different digests, and the same script gives the same one on every machine and every run — which is what makes it the answer to "did the code that produced this change?".
Parameters
sourcestring— The script body to digest.
Returns string — The digest, as a hex string.
local key = SceneBuild.digest(vfs.read(path))
typed/builtin//assetTypes/scene/shared/build/M/drift
M.drift(owner: string?) -> { Drift }
Where the live scene disagrees with the build that states it. Every entity a build placed records what that build last said about each of its properties, so anything an author has changed since reads back differently — and this is that list: the entity, the property, what the build said, and what the scene holds now.
These are values a rebuild KEEPS: a plain rebuild leaves each one as the
scene holds it, and layers.active.asset:build({ restate = true }) lands
build.luau's value instead. This list reads the entity's own values
alone: its name, internal flag, transform, active flag, lifecycle mode,
replication scope, whether its live state replicates, and its attributes.
The build's own report is the whole
answer: layers.active.asset:build({ save = false }) answers kept (these
and every component field, each with the value build.luau states),
driven (fields another component writes at runtime), handAdded and
handPlaced, and its message opens with one line counting all four.
Read that report to know where a scene and its build.luau disagree
before deciding which should win.
Numbers compare within the precision a saved record keeps, the tolerance
the build reads kept with, so a value the report keeps nothing of is
never listed here.
Property names are the ones the build records: n name, i internal,
p position, r rotation, s scale, o active, m lifecycle mode
(participation), w replication scope (network scope), y whether the
live state replicates (synced), and a:<name> for an attribute.
Parameters
ownerstring(optional) — Optional build name, asM.ownerOfreports it, to read just that build. Omitted, every build-owned entity in the scene is read.
Returns { Drift } — Array of { entity, name, owner, property, baked, live }, one per drifted property, sorted by entity then property.
for _, d in ipairs(SceneBuild.drift()) do print(d.name, d.property) end
typed/builtin//assetTypes/scene/shared/build/M/handPlaced
M.handPlaced(target: EntityRef | string | { guid: string }) -> { HandPlaced }
The entities under target that no build placed: each one an author, a
tool or a script put in the scene, with everything under it. They carry
no build's owner attribute, so build.luau states nothing about them and
a rebuild leaves them exactly where they are. Only entities the scene file
holds count: what a component produces, a spawner puts back or a peer
replicates in is left out. An entity under another one listed here comes
with it and is not listed again.
Parameters
targetEntityRef | string | { guid: string }— Entity ref, entity id, or scene layer, asM.reconciletakes it.
Returns { HandPlaced } — One { entity, name, property, components, builtTwin? } per entity: property is e, the code for the whole entity, beside the codes a kept, driven or hand-added entry carries, so one reader walks all four lists alike; components the short names of the components it carries, in the order the scene lists them; builtTwin the id of an entity a build placed under the same name, when there is one: build.luau now states the entity, so the hand-made one is a second copy beside the build's. The four lists are the build's answer: layers.active.asset:build({ save = false }) returns kept, driven, handAdded and this list as handPlaced, with a message whose first line counts all four.
local loose = SceneBuild.handPlaced(layers.active)
typed/builtin//assetTypes/scene/shared/build/M/identityOf
M.identityOf(entityId: string) -> string?
The explicit build identity of an entity, scoped to its build owner and target.
Parameters
entityIdstring— Runtime entity id.
Returns string? — The key declared by build.key, or nil.
local key = SceneBuild.identityOf(entityId)
typed/builtin//assetTypes/scene/shared/build/M/notePreview
M.notePreview(entityId: string, values: { [string]: any }, componentType: string?) -> nil
Record the values an author left on entityId, an entity a build owns.
The build states that entity from its own source, so the values hold until
it runs again — and M.takePreview is what the next run reads to say which
of them it replaced and with what. Each record REPLACES the one before it:
what it states is everything the entity carries now, so a name dropped
between two records is dropped here too.
Parameters
entityIdstring— Runtime entity id of the owned entity.values{ [string]: any }— The values the entity carries now, by name.componentTypestring(optional) — The component that states them, so a rebuild knows to state that type again instead of leaving it to the scene.
Returns nil
SceneBuild.notePreview(id, { count = 9 }, "SceneModule")
typed/builtin//assetTypes/scene/shared/build/M/noteSourceWrite
M.noteSourceWrite(guid: string, origin: string?) -> nil
Record that a file of the asset guid, which a build is stated from
(a .sceneModule a placement builds), was written, and by which session.
Every session holding a build stated from it rebuilds; the session that
made the write records what its rebuild lands, and every other session
lands it in its live scene alone.
Parameters
guidstring— The asset's guid.originstring(optional) —"local"for a write this session made (the default),"remote"for one another session sharing the world made.
Returns nil
SceneBuild.noteSourceWrite(ref.guid, change.origin)
typed/builtin//assetTypes/scene/shared/build/M/ownerOf
M.ownerOf(entityId: string) -> string?
The build that placed entityId, or nil when no build placed it. A
reconcile writes the name of the build onto every entity it places, as an
attribute the scene records beside the entity's name and transform, so the
answer holds across a reload — and an entity an author spawned carries no
owner at all.
Parameters
entityIdstring— Runtime entity id.
Returns string? — The owner the reconcile that placed it was called with, or nil.
if SceneBuild.ownerOf(id) ~= nil then print("a build states this") end
typed/builtin//assetTypes/scene/shared/build/M/plan
M.plan(records: { any }, target: EntityRef | string | { guid: string }, owner: string, identityMap: { [string]: string }?) -> PlacementPlan
Assign persistent ids to captured records before composing or applying their scene. Reads the target without changing live entities.
Parameters
records{ any }— Captured records returned by run; every record carries original_id.targetEntityRef | string | { guid: string }— The entity or layer whose build is being planned.ownerstring— The build owner scoped to this target.identityMap{ [string]: string }(optional) — Previously retained explicit placement identities.
Returns PlacementPlan — Captured-id placement map, retained explicit identities, hierarchy-key map and ids the build would remove.
local plan = SceneBuild.plan(records, layer, "build", identities)
typed/builtin//assetTypes/scene/shared/build/M/previewedComponentType
M.previewedComponentType(entityId: string) -> string?
The component type that recorded a preview for entityId, or nil when
none is waiting. A component that records one is SAYING that a build states
its fields and that it announces the replacement itself — so a rebuild
states that type again rather than leaving it to the scene, which is what
lets the announcement happen. Every other component is merged.
Parameters
entityIdstring— Runtime entity id of the owned entity.
Returns string? — The component type name, or nil.
if SceneBuild.previewedComponentType(id) == "SceneModule" then end
typed/builtin//assetTypes/scene/shared/build/M/project
M.project(records: { any }, plan: PlacementPlan, owner: string, componentGuid: SceneRecords.ComponentIdentity, componentName: SceneRecords.ComponentIdentity, rootParent: string?) -> { any }
Project a planned build into persisted scene records before changing live entities.
Parameters
records{ any }— The capture used to compute the placement plan.planPlacementPlan— The complete persistent placement plan.ownerstring— Build owner written into reconstruction metadata.componentGuidSceneRecords.ComponentIdentity— Resolve a recorded component type to its stable identity.componentNameSceneRecords.ComponentIdentity— Resolve a stable component identity to its persisted spelling.rootParentstring(optional) — Persistent parent for roots of an entity-scoped build; nil for scene roots.
Returns { any } — Persisted entity records with planned ids, remapped references and build metadata.
local generated = SceneBuild.project(records, plan, owner, componentGuid, componentName)
typed/builtin//assetTypes/scene/shared/build/M/reconcile
M.reconcile(records: { any }, target: EntityRef | string | { guid: string }, owner: string, opts: {
participation: string?,
source: string?,
frameBudget: number?,
handBack: (() -> boolean)?,
record: boolean?,
identityMap: { [string]: string }?,
placements: { [string]: string }?,
restate: boolean?,
}?) -> ({ [string]: string }, number, { Kept }, { Driven }, { HandAdded }, { [string]: string })
Apply records to the scene under target, reusing the entities a
previous reconcile left behind. A record that maps to a live entity
updates THAT entity — same runtime id, so every reference to it survives
the rebuild — and only a record with no live entity spawns one. The
entity it spawns takes an id derived from owner, target and the
record's identity, so every session sharing the world that runs the same
build creates it under the same id, and the records one session's build
writes land on the entity another session's build created. Entities
the previous build held that this one no longer emits are despawned. A
SceneModule placement the previous build stated on an entity and this
one does not goes together with the entities it built beneath it.
Name, transform, hidden, active, attributes, lifecycle mode, network scope,
whether the entity's live state replicates, and components are all made to
match the record, so a rebuild that drops a component or an attribute drops
it from the scene. Each of them is a diff:
what already matches the record is left exactly as it is, so a rebuild that
changed nothing changes nothing — a running component keeps running and the
scene stays clean. Only entities the build owns are touched: anything else
under target is left exactly as it was.
A component field holding an entity reference is resolved as the records
are applied: a reference to an entity of the SAME build points at the
entity this reconcile landed it on, and a reference to any other entity
keeps pointing where it did.
owner names the build. Every entity it places carries that name and the
record's identity as attributes of its own, which is what lets a rebuild
find the entities the last one placed without anything being remembered
between them — the pair is in the scene, and a reload brings it back with
the entity. Two builds sharing a target stay out of each other's way by
using different owners.
A record's identity is its place in the hierarchy — the chain of names
from the build root down to it — so dropping, inserting or reordering a
sibling leaves every other entity where it was. Several children of
one parent sharing a name are told apart by their rank among those,
counted in the order the builder created them.
Parameters
records{ any }— Flat record array, parents before children — whatM.runreturns.targetEntityRef | string | { guid: string }— Entity ref, entity id, or scene layer every root record lands in.ownerstring— Name of the build, unique among the builds sharing this target.opts{ participation: string?, source: string?, frameBudget: number?, handBack: (() -> boolean)?, record: boolean?, identityMap: { [string]: string }?, placements: { [string]: string }?, restate: boolean?, }(optional) —participationsets the lifecycle mode every placed entity takes, ahead of the mode any record carries.sourcenames the file the build is written in, whichM.sourceOfreports for every entity the build places.frameBudgetspreads the reconcile over frames: each frame applies at most that many records' worth of work (a record placed, its components, its active flag, an entity despawned each count one) and the rest waits for the frames after. It takes effect where the caller can yield, the scheduler task a build runs in; elsewhere the reconcile lands in the one frame.handBackspreads it by time instead, for a caller that owns when its frames are handed back: the reconcile applies records until this frame's slice (FrameBudget) is spent, then callshandBack, which hands the frame back and answers true, or answers false when the caller cannot, and the reconcile then lands the rest in the frame it is in. A scene load passesSceneLoader.handBackHere.frameBudgettakes precedence. Across each frame a spread reconcile hands back, other code runs: a reconcile of the sameownerat the sametargetstarted in those frames lands what the build states, and the earlier one returns at its next frame boundary with what it had landed; an entitytargettaken away in them stops the reconcile there with an error naming it. A reconcile that states no records while a scene loads, over entities the build placed before, raises and leaves them: a build that stated nothing during a load did not run to the end, and a rebuild after the load applies an empty statement.record(default true) states to the scene saver every entity the reconcile creates, changes or takes away, so the scene's unsaved edits carry them;record = falselands them in the live scene alone, for a caller that decides itself what the scene's files hold: nothing the reconcile spawns, writes or removes reaches the scene's unsaved edits, and a save this session makes of the scene afterwards writes what the live scene then holds, the removals included. On an entity the build placed before, a property the code states the way the last build stated it is left as the scene holds it, so an author's change to it survives the rebuild.restate = truelands every value the build states instead, over whatever the scene holds. A component field another component drives (the sky orienting the scene's sun light) is left to that component in every case, restated or not, the way a load of the scene leaves it: the instance comes back holding what that component wrote, and driven by it.identityMapmaps explicit build keys to persistent entity ids for this target and owner. Retain the returned map in the caller's authoring state and supply it on subsequent builds to restore removed placements by id. The supplied map is copied and validated before scene mutation.placementssupplies the captured-id map returned byplan; every assignment is revalidated against the live target before application. An explicit placement map applies its planned composition during a load, including an empty composition after authored removals.
Returns ({ [string]: string }, number, { Kept }, { Driven }, { HandAdded }, { [string]: string }) — The ids this reconcile landed on, keyed by record identity, how many of them it had to create, every value it left as the scene holds it where the build states another (Kept: the entity, its name, the property as the build records it, the component instance and field for a component, the value the build states and the value kept), and every component field it left to the component driving it where the build states another (Driven: the same, and drivenBy, the driving component and the entity it is on), every component or attribute an author added to an entity the build placed (HandAdded), and the updated explicit identity map, which retains entries for keys this build does not emit. A reconcile that created nothing landed on entities the saved scene already holds; one that created something is why the saved scene is now behind the live one.
local ids = SceneBuild.reconcile(records, root, "chairs")
local ids, created = SceneBuild.reconcile(records, layer, "build")
SceneBuild.reconcile(SceneBuild.run(build), layers.active, "build")
typed/builtin//assetTypes/scene/shared/build/M/recordDrift
M.recordDrift(rec: any?) -> { string }
Where an entity RECORD disagrees with what the build that placed it
last stated: the question M.drift asks of the live scene, asked of a
record the way scene.json and a scene's unsaved edits hold it. A record
carries the build's statement in its own attributes, so a property that
reads differently from that statement is one changed since the build ran,
and an attribute the record holds that the build never stated is one added
since. The record's name, transform, lifecycle mode, replication scope,
synced flag and attributes are compared, numbers within the precision a
saved record keeps.
Parameters
recany(optional) — An entity record:name,transform = { position, rotation, scale }andattributes.
Returns { string } — The drifted property names, sorted (n name, p position, r rotation, s scale, m lifecycle mode, w replication scope, y synced, a:<name> an attribute). Empty for a record that holds what its build stated, and for a record no build placed.
local drifted = SceneBuild.recordDrift(record)
typed/builtin//assetTypes/scene/shared/build/M/run
M.run(builder: () -> (), opts: {isolated: boolean?}?) -> ({ any }, { Refusal }, { any })
Run builder inside an entity capture scope and return the records for
every entity it created. The builder writes ordinary spawn code — real
entity.spawn, real component.add, real loops — and the entities it
creates are real for the duration of the call. They are composed into
records and then despawned, so run leaves the scene untouched and hands
back data. Reconciling that data into a scene is M.reconcile.
The builder's entities are despawned even when it raises, so a failed
build never leaks a half-built hierarchy into the scene.
What a component the builder attached created while running its own
lifecycle belongs to that component: the record names the COMPONENT, and
the same lifecycle runs again wherever the record is put back, so the
entities come from there rather than from records of their own. That covers
a nested build — a placement the builder makes runs its own module and owns
what it lands — and every other component that expands into entities.
An operation the scope refused is refused BEFORE it lands, so the records
describe the live world exactly as the builder left it, and a builder that
ran to its end around a refusal somebody caught for it composes what it
did make. Every such refusal comes back as the second return, naming the
contributor it stopped, for the caller to report alongside what it baked.
Parameters
builder() -> ()— Function taking no arguments; spawns whatever it wants.opts{isolated: boolean?}(optional) —isolatedkeeps candidate evaluation and entity cleanup inside a persistent-effect restriction.
Returns ({ any }, { Refusal }, { any }) — Flat array of records, parents before children, siblings in the order the builder created them; and the array of refusals the scope issued, each with message, at and the source frame naming who was refused. The third return holds source bindings attached during the build.
local records, refused = SceneBuild.run(function() entity.spawn("chair") end)
typed/builtin//assetTypes/scene/shared/build/M/sourceOf
M.sourceOf(owner: string) -> string?
The file that states the build named owner — what the reconcile
running that build passed as opts.source. Nil for a build that has not
run in this session and for one that named no source.
Parameters
ownerstring— Build name, asM.ownerOfreports it.
Returns string? — Path of the file the build is written in, or nil.
local file = SceneBuild.sourceOf(SceneBuild.ownerOf(id))
typed/builtin//assetTypes/scene/shared/build/M/sourceWrittenHere
M.sourceWrittenHere(guid: string) -> boolean
Whether the latest write to the asset guid this session saw was its
own, so a rebuild stated from it records what it lands. True for a write
this session made and for an asset it has seen no write to; false when
another session wrote it last, whose own rebuild records the change, and
whose records reach this session.
Parameters
guidstring— The asset's guid.
Returns boolean — True when this session records the rebuild of the change.
local record = SceneBuild.sourceWrittenHere(ref.guid)
typed/builtin//assetTypes/scene/shared/build/M/states
M.states(owner: string, key: string) -> boolean?
Whether the build named owner placed an entity for the record
identity key the last time it ran in this session. An entity carrying
that pair that is gone from the scene was taken away by the build when the
build no longer states it, and by an author when the build still does: the
build's next run would put it back.
Parameters
ownerstring— Build name, asM.ownerOfreports it.keystring— The record identity, as the entity'sbuildKeyattribute holds it.
Returns boolean? — True when the build's last run placed an entity for key; false when it ran and placed none, or another build has since taken the build's placement out of the scene; nil when the build has not run in this session.
local stillStated = SceneBuild.states(owner, key)
typed/builtin//assetTypes/scene/shared/build/M/takePreview
M.takePreview(entityId: string) -> { [string]: any }?
Take the values M.notePreview recorded for entityId and clear them.
Each set of values is read once — by whichever run of the build states that
entity next.
Parameters
entityIdstring— Runtime entity id of the owned entity.
Returns { [string]: any }? — The recorded values by name, or nil when none are waiting.
local set = SceneBuild.takePreview(id)
typed/builtin//assetTypes/scene/shared/records/M/captured
M.captured(record: any?, ids: { [string]: string }, resolve: ComponentIdentity) -> Projection
Normalize a builder capture using its assigned persistent entity identities.
Parameters
recordany(optional) — An entity_records capture.ids{ [string]: string }— Captured entity ids mapped to persistent placement ids.resolveComponentIdentity— Returns the stable component identity for each recorded type.
Returns Projection — Field-addressable value and reconstruction bookkeeping.
local projected = SceneRecords.captured(record, ids, componentGuid)
typed/builtin//assetTypes/scene/shared/records/M/componentGuid
M.componentGuid(value: string) -> string
The stable identity of a component type, whether or not the type still resolves. A type that resolves is its asset guid; one that does not is its own name behind an unresolved: prefix, so a record that names a removed component still projects, composes and restores under the name it was saved with.
Parameters
valuestring— A component type name or asset guid as a scene record states it.
Returns string — The component's guid, or the unresolved: identity of a type no asset answers to.
local key = SceneRecords.componentGuid("survivalKit.GatherSpot")
typed/builtin//assetTypes/scene/shared/records/M/componentName
M.componentName(value: string) -> string
The component type name a stable identity from componentGuid stands for: the asset's identity while it resolves, and the name it was saved with while it does not.
Parameters
valuestring— A keycomponentGuidreturned, or a component name or guid.
Returns string — The component type name to write into a scene record; a key no component answers to comes back behind the unresolved: prefix.
local name = SceneRecords.componentName(key)
typed/builtin//assetTypes/scene/shared/records/M/diff
M.diff(before: any?, after: any?) -> { Fields.Edit }
Compare scene values, a rotation by the orientation it states, so quaternion normalization and float rounding noise are the same orientation.
Parameters
beforeany(optional) — The previous scene entity value, or nil.afterany(optional) — The current scene entity value, or nil.
Returns { Fields.Edit } — Field edits; every value other than a rotation compares exactly.
local changes = SceneRecords.diff(previous.value, current.value)
typed/builtin//assetTypes/scene/shared/records/M/isBookkeepingAttribute
M.isBookkeepingAttribute(name: string) -> boolean
Whether an entity attribute is build or bundle bookkeeping rather than authored state.
Parameters
namestring— The attribute's name.
Returns boolean — True for an attribute a build or bundle placement writes about its own output.
if SceneRecords.isBookkeepingAttribute("buildBaked") then print("bookkeeping") end
typed/builtin//assetTypes/scene/shared/records/M/restore
M.restore(projection: Projection, resolve: ComponentIdentity) -> any
Restore a projected value to a persisted entity, retaining component order where its instances survive.
Parameters
projectionProjection— The composed value and current build bookkeeping.resolveComponentIdentity— Returns the current component type spelling for a stable identity.
Returns any — A persisted entity record with a component list.
local saved = SceneRecords.restore(projected, componentName)
typed/builtin//assetTypes/scene/shared/records/M/saved
M.saved(record: any?, resolve: ComponentIdentity) -> Projection
Normalize a saved entity, separating build bookkeeping from editable fields.
Parameters
recordany(optional) — A persisted entity with an id and component list.resolveComponentIdentity— Returns the stable component identity for each recorded type.
Returns Projection — Field-addressable value and reconstruction bookkeeping.
local projected = SceneRecords.saved(record, componentGuid)
typed/builtin//components/Asset/public/bakeIntoScene
public.bakeIntoScene()
Promote the bundle's spawned children from temporary to permanent scene state and remove the Asset component, "baking" the bundle's contents directly into the owning scene. Subsequent saves persist the baked entities verbatim and stop replaying the bundle template.
Returns true once the bake completes.
assetComp:bakeIntoScene()
typed/builtin//components/Asset/public/overrides
public.overrides() -> { [string]: any }
How this instance stands against its asset, measured now: every part
the asset composed (linked — as the asset has it, modified — edited in
the scene, removed — deleted from the scene), and every entity added
under the instance that the asset does not have (added). A modified
part lists what was changed. The same measurement a scene save records
as this component's diff, taken against the asset the parts were built
from.
Returns { [string]: any } — { source, parts = { { id?, templateId?, name, state, changes } }, linked, modified, added, removed }.
local o = entity("lamp_east").component.get("Asset"):overrides()
typed/builtin//components/Asset/public/revert
public.revert(part: string?) -> boolean
Put a part back the way the asset has it — or, with no argument, the whole instance. A modified part loses its edits, a removed part comes back, and an entity added under the instance is taken away. The rebuilt parts keep their entity ids, so references to them stay valid.
Parameters
partstring(optional) — The part's entity id or its id in the asset (a part'sidortemplateIdfromoverrides()); omit for every part.
Returns boolean — true once the instance is rebuilt.
entity("lamp_east").component.get("Asset"):revert("ent_3fa2c1")
entity("lamp_east").component.get("Asset"):revert()
typed/builtin//components/BoxCollider/public/setHalf
public.setHalf(size: vec3)
Set the box's half-extents. Recreates the collision shape.
Parameters
sizevec3— Half-extents as { x, y, z } or { x = , y = , z = }.
collider:setHalf({ 1, 2, 0.5 })
typed/builtin//components/BoxCollider/public/setTrigger
public.setTrigger(trigger: boolean)
Toggle trigger mode. A trigger reports overlaps without blocking.
Parameters
triggerboolean— true to detect overlaps only, false to collide solidly.
collider:setTrigger(true)
typed/builtin//components/Camera/public/capture
public.capture()
Capture a frame from this camera to its current render target. Alias of render() — kept so the verb matches the agent-facing capture toolbox.
cam:capture()
typed/builtin//components/Camera/public/lookAt
public.lookAt(target: string | table) -> (boolean, string?)
Aim this camera at a world position or another entity. Returns whether the camera was rotated, so a target naming an entity the scene does not carry is reported rather than leaving the camera on its previous aim.
Parameters
targetstring | table— An entity id string, an entity name, an entity proxy, or a position table ({x, y, z} array form or {x=, y=, z=} map form).
Returns (boolean, string?) — True when the camera was rotated, and nil for the second value. False plus the reason otherwise — "unresolved" when the target names no entity, "no-transform" when one of the two carries no transform, "degenerate" when the camera already sits on the point it was asked to face.
cam:lookAt(playerId)
cam:lookAt("player")
cam:lookAt({0, 1, 0})
cam:lookAt({x = 0, y = 1, z = 0})
typed/builtin//components/Camera/public/render
public.render(rtGuid: string?) -> { frame: number? }
Schedule a single-frame render for this camera. Works whether the component is enabled or disabled. Uses the camera's current transform, fov, near/far, and render layers. Pass a render-target guid to render this frame into THAT texture instead of the camera's configured output — the one-shot-target form the capture path uses to read a camera's exact view back without disturbing where it normally renders.
Parameters
rtGuidstring(optional) — Optional render-target guid (fromrenderer.texture.create) to render into this frame; omit to use the camera's configured target.
Returns { frame: number? } — The request's record: frame is the engine frame the render was scheduled on. It is filled at once when the camera's ECS row stands, and later — on the frame the row lands — when the camera was spawned and asked to render in one step, so a reader that binds the render to its frame reads the field once the render is in.
cam:render()
local request = cam:render(tex.guid)
typed/builtin//components/Camera/public/setTargetTexture
public.setTargetTexture(tex: renderer.TextureHandle?)
Point the camera at a GPU texture to render into, or back to the main
viewport. Create the texture first with
renderer.texture.create({ width, height }) (it owns its own size); the
camera only references it — free it with renderer.destroy(handle) when done.
Parameters
texrenderer.TextureHandle(optional) — ATextureHandleto render into, or nil for the main viewport.
local tex = renderer.texture.create({ width = 512, height = 512 })
cam:setTargetTexture(tex) -- render into the texture
cam:setTargetTexture(nil) -- back to the main viewport
typed/builtin//components/Humanoid/public/attach
public.attach(point: string, childId: string, opts: { position: any?, rotation: any?, scale: any? }?)
Seat an existing entity on the bone at point (see socket): it becomes
a child of that bone, so it rides the bone's animation, and stands at the
socket's frame moved by opts. A standard attachment point ("hat",
"rightGrip", …) or "viewpoint" (the eyes, for a first-person camera)
seats the item at that point's frame: its place on the
body, with +Y up, +Z forward and +X the body's left as the body stands in a
T-pose with its palms down, so an item authored once sits the same way on
every conforming body; a role, a VRM bone name or a bone name seats it at the
bone's origin, turned as the bone is. opts.position and opts.scale are in
metres in that frame: the rig's bone units (a rig authored in centimetres
carries a bone scale of 0.01) are taken out, so the same numbers seat an item
the same way on every humanoid body. opts.rotation is relative to that
frame, in either form localRotation takes: a quaternion { x, y, z, w },
or Euler degrees { pitch, yaw, roll }. The item records its point and
transform, so attachments() lists it and an avatar body swap re-seats it on
the new body's socket.
Parameters
pointstring— string — a standard point,viewpoint, a VRM bone name, a canonical role, or an exact bone name.childIdstring— string — the entity to attach.opts{ position: any?, rotation: any?, scale: any? }(optional) —{ position, rotation, scale }?: the item's transform in the socket's frame. Defaults: no offset, the bone's orientation, scale 1.
Returns entity (the socket bone) | nil when the point doesn't resolve.
h:attach("rightGrip", sword.id)
h:attach("hat", hat.id, { position = { 0, 0.02, 0 }, scale = 1.1 })
typed/builtin//components/Humanoid/public/attachments
public.attachments()
Every item seated on this body with attach, each as
{ id, point, position, rotation, scale }: the item's entity id, the point
it is seated on, and its transform in that socket's frame in metres, the
values attach takes. An item an avatar body swap holds on the avatar
root until the new body has a socket for its point is listed too. Items
seated on items are carried by the item they sit on and are not listed.
Returns { { id: string, point: string, position: vec3, rotation: quat, scale: vec3 } }
for _, a in ipairs(h:attachments()) do print(a.id, a.point) end
typed/builtin//components/Humanoid/public/bone
public.bone(name: string)
Lookup a single bone entity by canonical name ("Head", "Hand_R", etc).
Returns nil when the bone isn't present (e.g. a skeleton missing the finger sub-tree).
Parameters
namestring— string — canonical bone name from the humanoid table
Returns entity | nil
typed/builtin//components/Humanoid/public/descriptor
public.descriptor()
This body's descriptor under the humanoid avatar standard
(modules.avatarStandard), read from the body it wears now: every VRM 1.0
bone it fills, its optional chains (hair, tail, ears, …), the 19 attachment
points and the viewpoint (eye position) with their frames, its expressions by
tier, its height and bounds, and every rule it breaks. Positions are metres
in the avatar's space (+Y up, +Z its facing, +X its left, from the ground
beneath its hips), the space attach takes them in; scale is the avatar
root's world scale, so the body stands height * scale tall in the world.
Nil while the body has not set up its skeleton.
Returns descriptor | nil
local d = h:descriptor(); print(d.height, d.viewpoint.position.y)
typed/builtin//components/Humanoid/public/socket
public.socket(point: string)
Resolve an attachment point to the live bone entity for THIS body, so
content attaches a prop to a known point WITHOUT knowing the per-mesh bone
name. point is one of the standard attachment points ("hat",
"rightGrip", "bodyBack", … — modules.avatarStandard lists all 19),
"viewpoint" (the eyes),
a VRM 1.0 bone name ("rightHand", "head", "leftUpperLeg"), or a
canonical ROLE ("righthand", "head", "hips"), each resolved
mesh-independently from the body's skeleton; a VRM bone name the body does
not fill, or a name that is none of these, falls back to an exact bone NAME
(per-rig custom attachment). A standard
point resolves to the bone that carries it (the avatar root for origin).
Returns the entity, or nil when the body has none.
Parameters
pointstring— string — a standard point,viewpoint, a VRM bone name, a canonical role, or an exact bone name.
Returns entity | nil
typed/builtin//components/Humanoid/public/validate
public.validate(opts: { rules: { string }? }?)
Every rule of the humanoid avatar standard this body breaks, each named:
{ ok, problems }, each problem { rule, name, message } with rule one of
type, bone, point, expression, height, or body while the body has
not set up its skeleton. opts.rules names the rules a game holds the body to
(default: all; a game with no faces leaves out expression).
Parameters
opts{ rules: { string }? }(optional) —{ rules: { string }? }?summarysays the problems in one line per broken rule, for showing a player. The height rule holds the height the body stands in the world.
Returns { ok: boolean, problems: { { rule: string, name: string, message: string } }, summary: { string } }
local v = h:validate({ rules = { "type", "bone", "point", "height" } })
typed/builtin//components/Light/public/lightMobility
public.lightMobility() -> string
How GI baking should treat this light, resolved to "static",
"mixed" or "dynamic". Every component that puts a light in the
scene answers this, which is how a bake finds the lights it has to
account for without knowing what component authored them.
Returns string — The resolved mobility.
if light:lightMobility() == "dynamic" then ... end
typed/builtin//components/Light/public/resolveMobility
public.resolveMobility() -> string
Resolve this light's mobility to "static", "mixed" or
"dynamic" — how GI baking treats it. An explicit mobility field
wins; "auto" resolves to "dynamic" for a light something carries
(non-world participation, an animated or physics-driven entity, or
one the running world moves: entity.inMotion) and
"mixed" for the rest.
"static" bakes the light whole — direct light and bounce — and
withholds its live contribution, so it costs nothing per frame and
lights nothing that was not there at bake time.
"mixed" bakes only its bounce and keeps its direct light and shadows
live, so it still lights and shadows anything that moves. This is what
"auto" picks, because a light that stands still still shines on
characters walking under it.
"dynamic" keeps the light out of the bake entirely.
Returns string
local mob = light:resolveMobility()
typed/builtin//components/Light/public/setAngle
public.setAngle(deg: number)
Set a spot's outer cone half-angle in degrees. Nothing past it is
lit; set below innerAngle, the cone is fully bright out to it with a
hard edge there.
Parameters
degnumber— Outer cone half-angle (0..90).
light:setAngle(45)
typed/builtin//components/Light/public/setCastsShadows
public.setCastsShadows(b: boolean)
Enable or disable shadow casting. Point lights cast omnidirectional (cube) shadows; spot lights cast a single projected shadow. Capacity is capped per kind — past the cap the light stays lit but unshadowed.
Parameters
bboolean—trueto cast shadows,falseto disable.
light:setCastsShadows(true)
typed/builtin//components/Light/public/setColor
public.setColor(color: table)
Set the light color. Values >1 are auto-scaled from 0..255.
Parameters
colortable—{r, g, b}array or{r=, g=, b=}map.
light:setColor({1, 0.8, 0.5})
light:setColor({r = 255, g = 200, b = 128})
typed/builtin//components/Light/public/setDirection
public.setDirection(dirOrX: table | number, y: number?, z: number?)
Set the direction a directional or distant light travels along.
Accepts three numbers or a single {x, y, z} / {x=, y=, z=} vector.
A spot aims by face and its entity's rotation, so this raises on a
spot, naming face.
Parameters
dirOrXtable | number— Either the x component, or a{x, y, z}array /{x=, y=, z=}map.ynumber(optional) — The y component when the first argument is a number.znumber(optional) — The z component when the first argument is a number.
light:setDirection(-0.5, -1, -0.3)
light:setDirection({-0.5, -1, -0.3})
typed/builtin//components/Light/public/setFace
public.setFace(face: string)
Set the entity-local axis a spot's cone points along. One of Front,
Back, Left, Right, Top, Bottom — the world-space cone axis is
transform.rotation * face, and "Front" is the entity's own forward, so
a cone left on it follows wherever the entity is aimed.
Parameters
facestring— Face name string.
light:setFace("Bottom")
typed/builtin//components/Light/public/setInnerAngle
public.setInnerAngle(deg: number)
Set a spot's inner cone half-angle in degrees. Anything inside the
inner cone is at full intensity; the light smoothsteps to nothing between
it and angle. An inner angle at or past angle makes the cone fully
bright out to angle with a hard edge there.
Parameters
degnumber— Inner cone half-angle (0..angle).
light:setInnerAngle(15)
typed/builtin//components/Light/public/setIntensity
public.setIntensity(i: number)
Set the light intensity (0..N).
Parameters
inumber— Intensity scalar.
light:setIntensity(2.5)
typed/builtin//components/Light/public/setKind
public.setKind(lightKind: string)
Switch the light kind ("point" / "spot" / "directional" /
"ambient" / "distant"). "directional" aims the scene's sun, which is a single
field: setting it replaces whatever the sun was. "distant" is parallel
light held as a row of the scene's light buffer, so several coexist —
DirectionalLight is the component that authors one.
Parameters
lightKindstring— One of"point","spot","directional","ambient","distant".
light:setKind("directional")
typed/builtin//components/Light/public/setRadius
public.setRadius(r: number)
Set the radius (point lights only).
Parameters
rnumber— Radius in world units.
light:setRadius(15)
typed/builtin//components/Model/public/applySessionMaterial
public.applySessionMaterial(handle: any?)
Show a session-created runtime material on this Model in place of
its authored material. The authored material field is never touched —
persisted state always carries the authored ref, so nothing broken can
be saved. The handle is kept in the session store under
renderer.material.sessionKeyFor(entityId), so awake re-adopts it
across VM reloads; on a fresh boot (runtime materials gone) the Model
renders its authored material again automatically.
Called with no handle, it copies this Model's current material into a fresh
session material keyed to this entity, so later setMaterialProperty edits
land on the copy instead of the shared authored material.
A copy per entity is what a DIFFERENT LOOK per entity costs — its own
pipeline binding and its own row in the material table. When entities want
the same look and differ only in a VALUE, renderer.instanceData.set writes
one of the four vec4 lanes every drawn object already carries, which the
shader reads as input.shader_data[lane], and one material serves them all.
Parameters
handleany(optional) — The runtime material handle OBJECT, asrenderer.material.createandrenderer.material.animatedTexturereturn it. Itsguidfield is the material's registry key, which is whatrenderer.material.setProperty/describe/destroytake; this call takes the handle itself. Omit to copy this Model's current material into a new session material.
model:applySessionMaterial(handle)
model:applySessionMaterial() -- copy the current material for per-entity edits
typed/builtin//components/Model/public/clearOutline
public.clearOutline()
Remove the outline from this mesh.
model:clearOutline()
typed/builtin//components/Model/public/clearTint
public.clearTint()
Reset the tint so the mesh renders with its original material colour.
model:clearTint()
typed/builtin//components/Model/public/getMaterialProperty
public.getMaterialProperty(property: string)
Read a property from this Model's material — the session material when one is active, else the authored material.
Parameters
propertystring— Property name (string).
Returns The current value of the property, or nil when no material is assigned.
local color = model:getMaterialProperty("baseColor")
typed/builtin//components/Model/public/getMaterialPropertyNames
public.getMaterialPropertyNames()
List all property names available on this Model's material — the session material when one is active, else the authored material.
Returns Array of property name strings (empty when no material is assigned).
for _, name in ipairs(model:getMaterialPropertyNames()) do print(name) end
typed/builtin//components/Model/public/resolveMobility
public.resolveMobility() -> string
Resolve this entity's effective mobility: "static" (stands still —
receives lightmaps, occludes baked light) or "movable" (moves — samples
probe volumes for indirect light). An explicit mobility field value wins;
"auto" derives it from the entity AND everything carrying it: anything
that animates, simulates, or is driven (a non-static Physics body, a
SkinnedModel, a ClipPlayer, a Mover/FreeMover — on this entity or
any ancestor — or a non-world runtime participation) is movable, and so is
anything the running world moves (entity.inMotion: a script's update in
play, or an engine system, has placed it or an ancestor on more than one
frame); everything else is static. A component that places a prop once
leaves it static.
Returns string — "static" or "movable".
local Lightmap = require("@builtin::systems.globalIllumination.lightmap")
if model:resolveMobility() == "static" then Lightmap.bake(id) end
typed/builtin//components/Model/public/restoreSessionMaterial
public.restoreSessionMaterial() -> boolean
End the session-material swap: the Model renders its authored material again.
Returns boolean — true when a session material was active, else false.
model:restoreSessionMaterial()
typed/builtin//components/Model/public/setMaterialProperties
public.setMaterialProperties(props: { [string]: any }) -> number
Set many properties on this Model's material in one call, the plural of
setMaterialProperty and with the same target: this entity's session copy
when one is active, else the authored material every entity sharing it
takes. Each key resolves against the material's declared vocabulary the way
the singular resolves it; a property the material's shader does not expose
is skipped, so one patch table serves models on different shaders.
Parameters
props{ [string]: any }— Table of{ [propertyName] = value }pairs.
Returns number — Number of properties applied.
model:setMaterialProperties({ roughness = 0.2, metallic = 0.9 })
typed/builtin//components/Model/public/setMaterialProperty
public.setMaterialProperty(property: string, value: any?)
Set a property on this Model's material. With a session material active
(see applySessionMaterial), the write lands on this entity's session copy
alone; otherwise it changes the shared material at runtime, which every
entity sharing it takes since material properties are registry-wide. Either
way the change reaches the GPU and not the material's mat.yaml — call
material:saveDefinition() to write the current values into the asset. The
key resolves against the material's declared vocabulary on both targets, so
the same name reaches the same uniform.
Parameters
propertystring— Property name (string).valueany(optional) — New value for the property. Type depends on the property.
model:setMaterialProperty("baseColor", {1, 0, 0, 1})
model:setMaterialProperty("roughness", 0.5)
typed/builtin//components/Model/public/setOutline
public.setOutline(color: table, intensity: number?)
Set the outline colour and intensity for this mesh.
Parameters
colortable— Outline color as {r, g, b} array or {r=, g=, b=} map. Channel values are 0-1.intensitynumber(optional) — Outline intensity (0 = none, 1 = full). Defaults to 1.
model:setOutline({0, 1, 0})
model:setOutline({r = 1, g = 1, b = 0}, 0.8)
typed/builtin//components/Model/public/setTint
public.setTint(color: table, blend: number?)
Set the mesh tint colour and blend amount. The tint fields are synced,
so every participant sees it. A colour rewritten every frame on many
entities (stress colour, heat map, damage flash) is cheaper as an
instance-data lane: @builtin::materials.instance_color reads one, written
with renderer.instanceData.set(id, 2, r, g, b, coverage).
Parameters
colortable— Tint color as {r, g, b} array or {r=, g=, b=} map. Channel values are 0-1.blendnumber(optional) — Blend amount (0 = no tint, 1 = full tint). Defaults to 1.
model:setTint({1, 0, 0})
model:setTint({r = 1, g = 0, b = 0}, 0.5)
typed/builtin//components/Physics/public/addVelocity
public.addVelocity(dx: number, dy: number, dz: number)
Add to the body's current linear velocity.
Parameters
dxnumber— Velocity delta along world X.dynumber— Velocity delta along world Y.dznumber— Velocity delta along world Z.
body:addVelocity(0, 2, 0)
typed/builtin//components/Physics/public/applyForce
public.applyForce(x: number, y: number, z: number)
Apply a force to this body (Newtons), over the span
Physics.applyForce states: from Physics.onBeforeStep or fixedUpdate
on the next physics step alone (call once per step for a steady push),
from anywhere else over the simulated time of the next frame (call once
per frame).
Parameters
xnumber— Force component along world X.ynumber— Force component along world Y.znumber— Force component along world Z.
body:applyForce(0, 100, 0)
typed/builtin//components/Physics/public/applyImpulse
public.applyImpulse(x: number, y: number, z: number)
Apply an instantaneous impulse to this body (kg·m/s).
Parameters
xnumber— Impulse component along world X.ynumber— Impulse component along world Y.znumber— Impulse component along world Z.
body:applyImpulse(5, 0, 0)
typed/builtin//components/Physics/public/applyTorque
public.applyTorque(x: number, y: number, z: number)
Apply a torque to this body (rotational force), over the span
Physics.applyForce states for a force.
Parameters
xnumber— Torque around world X.ynumber— Torque around world Y.znumber— Torque around world Z.
body:applyTorque(0, 5, 0)
typed/builtin//components/Physics/public/setVelocity
public.setVelocity(x: number, y: number, z: number)
Set the body's linear velocity directly.
Parameters
xnumber— Velocity component along world X.ynumber— Velocity component along world Y.znumber— Velocity component along world Z.
body:setVelocity(0, 10, 0)
typed/builtin//components/PlayerNameLabel/public/refresh
public.refresh()
Re-read the owner and rasterise the label. Called by PlayerAvatar when
the owning identity or its display name changes.
typed/builtin//components/SceneSetup/public/apply
public.apply()
Apply the setup the placement's Asset links now, with its overrides.
The setup's instantiate calls it when it composes onto a root that
already holds this component: a placement restored from the scene file
wakes before its Asset resolves a source that arrives later. An instance
that has not woken yet applies the setup when it wakes.
setup:apply()
typed/builtin//components/SceneSetup/public/audition
public.audition(setupRef: any?)
Audition another setup in this placement's place for the session: the
placement applies setupRef instead of its own setup, with the overrides
that address its parameters, and records nothing, so the scene and its
authored edits stay as they are. endAudition, a flip between edit and
play, and a reload of the scene each put the placement's own setup back.
members, get and the Inspector read the auditioned setup meanwhile;
set is refused, since an override is the placement's own.
Parameters
setupRefany(optional) — The setup to audition (any asset implementingapplicable).
entity.find("lighting").component.get("SceneSetup"):audition(asset.resolve("lighting.harbour_night", "sceneSetup"))
typed/builtin//components/SceneSetup/public/auditioning
public.auditioning() -> any?
The setup this placement auditions in place of its own, or nil.
Returns any? — The auditioned setup, or nil.
if setup:auditioning() then setup:endAudition() end
typed/builtin//components/SceneSetup/public/endAudition
public.endAudition() -> any?
End an audition: the placement applies its own setup again.
Returns any? — The setup that was auditioned, or nil when none was.
setup:endAudition()
typed/builtin//components/SceneSetup/public/get
public.get(path: string) -> { [string]: any }
A parameter of the placed setup: the value its member receives, where
that value comes from (override, definition with the identity of the
composition that states it and definedAt, the path it states it at in
that setup, live, or saved), and its Field descriptor. An override that
is relative carries relative ({ scale } or { offset }) and supplied,
the value the setup supplies under it, with suppliedFrom naming where
that comes from. For a parameter another system drives (the intensity of a
sun that follows the sky), landed is what it lands at now beside the
stated value.
Parameters
pathstring— A parameter path (fog/density,ao/@enabled,@lit).
Returns { [string]: any } — { value, origin, definedBy?, definedAt?, relative?, supplied?, suppliedFrom?, desc, landed? }.
print(setup:get("fog/density").origin)
typed/builtin//components/SceneSetup/public/members
public.members() -> { [string]: any }
Every member of the placed setup at every depth (sky, sky/backdrop),
by member path, each with its source and the state its application has on
this frame (inForce, off or held, with heldBy and notice when it
states them): a member whose light, feature or effect another application
holds reads held by that application. A member whose
parameters another system drives (a light that follows the sky) also
carries landed, what those parameters land at now, beside stated, the
values it states for them. values holds each of the member's own
parameters with the value it receives and where that value comes from:
{ value, origin, definedBy?, definedAt?, relative?, supplied? }, as get
answers it. order is the member's place in the setup's definition order,
nested members following the member that holds them.
Returns { [string]: any } — { [path] = { source, state, order, values, landed?, stated? } }.
for path, m in pairs(setup:members()) do print(path, m.state.status) end
typed/builtin//components/SceneSetup/public/orphans
public.orphans() -> { [string]: any }
The overrides that address no parameter of the setup: kept byte for byte, and applied again when their path returns.
Returns { [string]: any } — { [path] = value }.
for path in pairs(setup:orphans()) do print(path) end
typed/builtin//components/SceneSetup/public/reset
public.reset(path: string)
Remove overrides: one parameter path, every path under a member path,
or an orphan. The member returns to what the setup says. In edit mode on
a world scene, a reset that leaves no override records no authored edit,
and releases the one an earlier set recorded on this placement.
Parameters
pathstring— A parameter path, a member path or an orphaned key.
setup:reset("fog/density")
typed/builtin//components/SceneSetup/public/set
public.set(path: string, value: any?) -> { [string]: any }
Set a parameter of this placement: an override, saved with the scene
and synced like any edit, checked against the parameter's descriptor.
<member>/@enabled turns a member on or off. A numeric parameter also
takes a relative override, { scale = n } or { offset = n }: it lands at
the value the setup supplies times scale or plus offset, checked
against the descriptor, and follows that value when the setup changes. In
edit mode on a world scene, a set is an authored scene edit: it is
recorded and holds over what build.luau states until it is reset or
released (sceneAuthoring releaseAuthored). Returns what get(path)
answers once the override is applied: the stated value, and for a
parameter another system drives (the intensity of a light that follows
the sky), landed, what it lands at now.
Parameters
pathstring— A parameter path.valueany(optional) — The value, or{ scale = n }/{ offset = n }for a numeric parameter.
Returns { [string]: any } — The parameter as get(path) reads it: { value, origin, landed?, ... }.
setup:set("fog/density", 0.05)
setup:set("fog/density", { scale = 3.75 })
local read = setup:set("fill/intensity", 0.9); print(read.value, read.landed)
typed/builtin//components/SkinnedModel/public/applySessionMaterial
public.applySessionMaterial(handle: any?)
Show a session-created runtime material on this SkinnedModel in
place of its authored material. The authored material field is never
touched — persisted state always carries the authored ref. The handle
is kept in the session store under
renderer.material.sessionKeyFor(entityId), so awake re-adopts it
across VM reloads; on a fresh boot (runtime materials gone) the
SkinnedModel renders its authored material again automatically.
Called with no handle, it copies this SkinnedModel's current material into
a fresh session material keyed to this entity, so later
setMaterialProperty edits land on the copy instead of the shared
authored material.
Parameters
handleany(optional) — The runtime material handle OBJECT, asrenderer.material.createreturns it. Omit to copy this SkinnedModel's current material into a new session material.
skinned:applySessionMaterial(handle)
skinned:applySessionMaterial() -- copy the current material for per-entity edits
typed/builtin//components/SkinnedModel/public/clearOutline
public.clearOutline()
Remove the outline from this mesh.
sm:clearOutline()
typed/builtin//components/SkinnedModel/public/clearTint
public.clearTint()
Reset the tint so the mesh renders with its original material colour.
sm:clearTint()
typed/builtin//components/SkinnedModel/public/getMaterialProperty
public.getMaterialProperty(property: string)
Read a property from this model's material — the session material when one is active, else the authored material.
Parameters
propertystring— Property name (string).
Returns The current value of the property, or nil when no material is assigned.
local color = sm:getMaterialProperty("baseColor")
typed/builtin//components/SkinnedModel/public/getMaterialPropertyNames
public.getMaterialPropertyNames()
List all property names available on this model's material — the session material when one is active, else the authored material.
Returns Array of property name strings (empty when no material is assigned).
for _, name in ipairs(sm:getMaterialPropertyNames()) do print(name) end
typed/builtin//components/SkinnedModel/public/renderCheck
public.renderCheck() -> { state: string, reason: string? }
The render self-check's verdict on the mesh model names. A few frames
after the mesh attaches, the SkinnedModel checks that it reached the GPU and
that the pose it is drawn in has not collapsed it below its own bind-pose
extent; a mesh that fails is swapped for the ERROR marker. Setting model
again takes the marker down and checks the new mesh.
Returns { state: string, reason: string? } — { state, reason? } — state is "pending" while the check runs, then "passed", "failed" (with reason, the cause the marker was shown for) or "skipped" (no model, or skinningEnabled off).
local v = sm:renderCheck(); if v.state == "failed" then print(v.reason) end
typed/builtin//components/SkinnedModel/public/restoreSessionMaterial
public.restoreSessionMaterial() -> boolean
End the session-material swap: the SkinnedModel renders its authored material again.
Returns boolean — true when a session material was active, else false.
skinned:restoreSessionMaterial()
typed/builtin//components/SkinnedModel/public/setMaterialProperties
public.setMaterialProperties(props: { [string]: any }) -> number
Set many properties on this model's material in one call, the plural of
setMaterialProperty and with the same target: this entity's session copy
when one is active, else the authored material every entity sharing it
takes. Each key resolves against the material's declared vocabulary the way
the singular resolves it; a property the material's shader does not expose
is skipped, so one patch table serves models on different shaders.
Parameters
props{ [string]: any }— Table of{ [propertyName] = value }pairs.
Returns number — Number of properties applied.
sm:setMaterialProperties({ roughness = 0.5, metallic = 0.2 })
typed/builtin//components/SkinnedModel/public/setMaterialProperty
public.setMaterialProperty(property: string, value: any?)
Set a property on this model's material. With a session material active
(see applySessionMaterial), the write lands on this entity's session copy
alone; otherwise it changes the shared material at runtime, which every
entity sharing it takes since material properties are registry-wide. Either
way the change reaches the GPU and not the material's mat.yaml — call
material:saveDefinition() to write the current values into the asset. The
key resolves against the material's declared vocabulary on both targets, so
the same name reaches the same uniform.
Parameters
propertystring— Property name (string).valueany(optional) — New value for the property. Type depends on the property.
sm:setMaterialProperty("roughness", 0.5)
typed/builtin//components/SkinnedModel/public/setOutline
public.setOutline(color: table, intensity: number?)
Set the outline colour and intensity for this mesh.
Parameters
colortable— Outline color as {r, g, b} array or {r=, g=, b=} map. Channel values are 0-1.intensitynumber(optional) — Outline intensity (0 = none, 1 = full). Defaults to 1.
sm:setOutline({0, 1, 0})
sm:setOutline({r = 1, g = 1, b = 0}, 0.8)
typed/builtin//components/SkinnedModel/public/setTint
public.setTint(color: table, blend: number?)
Set the mesh tint colour and blend amount. The tint fields are synced,
so every participant sees it. A colour rewritten every frame on many
characters (damage flash, team colour, heat map) is cheaper as an
instance-data lane: @builtin::materials.instance_color reads one, written
with renderer.instanceData.set(id, 2, r, g, b, coverage).
Parameters
colortable— Tint color as {r, g, b} array or {r=, g=, b=} map. Channel values are 0-1.blendnumber(optional) — Blend amount (0 = no tint, 1 = full tint). Defaults to 1.
sm:setTint({1, 0, 0})
sm:setTint({r = 1, g = 0, b = 0}, 0.5)
typed/builtin//components/Text3D/public/getSize
public.getSize()
Measure the rasterised text in pixels.
Returns Table with width and height in pixels (zero when not yet rasterised).
typed/builtin//components/Text3D/public/getText
public.getText()
Read the current text content.
Returns Current text string.
typed/builtin//components/Text3D/public/getWorldSize
public.getWorldSize()
Read the world-space size the text quad is drawn at. This is
worldHeight and the width its aspect gives wherever the hierarchy leaves
the label's local axes their own length, and the smaller extent an axis a
scaled ancestor has flattened draws where it does not.
Returns Table with width and height in world units.
typed/builtin//components/Text3D/public/refresh
public.refresh()
Force the text to re-rasterise now.
t:refresh()
typed/builtin//components/Text3D/public/setStyle
public.setStyle(options: table)
Update one or more style fields in a single call. Unknown keys are ignored. Each changed field fires the reactive rebuild (position-only for offset/pivot keys, a re-rasterise for styling keys).
Parameters
optionstable— Table of style overrides keyed by public-field name.
t:setStyle({fontSize = 64, color = "yellow"})
typed/builtin//components/Text3D/public/setText
public.setText(content: string)
Replace the displayed text content.
Parameters
contentstring— New text string.
t:setText("Hello World")
typed/builtin//controller/camera_rig/R/airborne
R.airborne(subjectId: string) -> boolean
Whether a subject is off the ground this frame, as the mover that
carries it states: its CharacterController's grounded, or its
MovementState's where it carries no controller. track holds the
framed height through a jump on it.
Parameters
subjectIdstring— The subject a rig follows.
Returns boolean — True while the subject's mover reads it off the ground; false on the ground and for a subject no mover states it for (a vehicle, a prop).
local fx, fy, fz = CameraRig.track(tracking, tx, ty, tz, frame, limits, dt, CameraRig.airborne(subjectId))
typed/builtin//controller/camera_rig/R/applyFacing
R.applyFacing(selfId: string, fromX: number, fromY: number, fromZ: number, lookX: number, lookY: number, lookZ: number, frame: Frame.Frame?)
Turn a camera to face from one point toward another, leaving where it
stands as it is: the rotation applyPose writes for the same two points.
A rig's look(dt) turns the camera with this, before anything that steers
by the camera's facing reads it, and its update places the camera once
its subject has moved. Both points are in the camera entity's own
transform frame, as for applyPose.
Parameters
selfIdstring— The camera entity id.fromXnumber— The point the camera looks from, X.fromYnumber— Look-from Y.fromZnumber— Look-from Z.lookXnumber— Aim point X.lookYnumber— Aim point Y.lookZnumber— Aim point Z.frameFrame.Frame(optional) — The frame whose up is the view's up; defaults to the world's.
CameraRig.applyFacing(id, cx, cy, cz, tx, ty, tz, Frame.at(tx, ty, tz))
typed/builtin//controller/camera_rig/R/applyPose
R.applyPose(selfId: string, camX: number, camY: number, camZ: number, lookX: number, lookY: number, lookZ: number, frame: Frame.Frame?)
Write a camera pose onto an entity, aiming at a point. Both the pose
and the aim point are expressed in the camera entity's own transform
frame — parent-relative when the camera is parented, world space when it
is not. The view's up is the up of frame (Frame.at of the
modules.up_frame module: up against the gravity where the subject
stands, so a camera on the side of a planet keeps level with it), +Y
when it is left out.
Parameters
selfIdstring— The camera entity id.camXnumber— Camera X.camYnumber— Camera Y.camZnumber— Camera Z.lookXnumber— Aim point X.lookYnumber— Aim point Y.lookZnumber— Aim point Z.frameFrame.Frame(optional) — The frame whose up is the view's up; defaults to the world's.
CameraRig.applyPose(id, cx, cy, cz, tx, ty, tz)
CameraRig.applyPose(id, cx, cy, cz, tx, ty, tz, Frame.at(tx, ty, tz))
typed/builtin//controller/camera_rig/R/carryTrail
R.carryTrail(state: Trail, frame: Frame.Frame, fromX: number, fromY: number, fromZ: number, toX: number, toY: number, toZ: number)
Carry a change of a rig's framing into its trail on this frame, so
the camera stands where the new framing puts it at once instead of
easing there. What the trail was still closing keeps its place against
the framing: it turns about up as far as the framing's heading turned.
A rig carries the turn a mouse makes this way (lookIsDirect) and leaves
every other change of its framing to trail's easing.
Parameters
stateTrail— The rig's trail, fromnewTrail.frameFrame.Frame— The frame the subject stands in, whose up the heading turns about.fromXnumber— The framing's offset from the subject before the change, X.fromYnumber— Offset before, Y.fromZnumber— Offset before, Z.toXnumber— The framing's offset from the subject after the change, X.toYnumber— Offset after, Y.toZnumber— Offset after, Z.
CameraRig.carryTrail(follow, frame, beforeX, beforeY, beforeZ, afterX, afterY, afterZ)
typed/builtin//controller/camera_rig/R/componentIsLive
R.componentIsLive(entityId: string, enabled: boolean?) -> boolean
Whether a component instance is live: enabled itself, and on an
entity that is active in the hierarchy. A component's awake runs when
it is attached whatever its state, so a rig reads this in awake to know
whether it starts live, and states it from onEnable through
setDriveEnabled: one attached disabled, or to an entity that is
inactive or under an inactive parent, takes nothing up until it is live.
Parameters
entityIdstring— The entity the component is on (public.entityId).enabledboolean(optional) — The component's ownenabledfield (public.enabled).
Returns boolean — True when the component is enabled and its entity is active in the hierarchy, or the entity's state cannot be read.
local live = CameraRig.componentIsLive(public.entityId, public.enabled)
typed/builtin//controller/camera_rig/R/damp
R.damp(current: number, goal: number, tau: number, dt: number) -> number
Frame-rate independent damping toward a goal.
Parameters
currentnumber— Current value.goalnumber— Target value.taunumber— Time constant in seconds; 0 snaps.dtnumber— Frame delta in seconds.
Returns number — The damped value, which never overshoots the goal.
pos.x = CameraRig.damp(pos.x, goal.x, 0.2, dt)
typed/builtin//controller/camera_rig/R/drawnForward
R.drawnForward(targetId: string) -> (number, number, number)
The direction a subject faces where it is drawn this frame: its
local -Z carried into world space by its drawn rotation, the same axis
entity.transform.forward reads from its transform.
Parameters
targetIdstring— The subject to read.
Returns (number, number, number) — Unit world-space forward as three numbers; world -Z when nothing in the scene answers to that id.
local fx, fy, fz = CameraRig.drawnForward(bodyId)
typed/builtin//controller/camera_rig/R/drawnPose
R.drawnPose(targetId: string) -> (number?, number?, number?, number?, number?, number?, number?)
Where a subject is drawn this frame and how it is turned there, in
world space: the position drawnPosition reads and the rotation the frame
draws it with. A rig that rides a body (a seat, a hood, a turret) places
itself in the body's frame from this pose, so it moves with the body as
smoothly as the body is drawn, whatever the physics tick and the frame
rate.
Parameters
targetIdstring— The subject to read.
Returns (number?, number?, number?, number?, number?, number?, number?) — Position as three numbers and rotation as four (qx, qy, qz, qw), or nil when nothing in the scene answers to that id. A VM that holds no render state answers with the transform's pose.
local px, py, pz, qx, qy, qz, qw = CameraRig.drawnPose(carId)
typed/builtin//controller/camera_rig/R/drawnPosition
R.drawnPosition(targetId: string) -> (number?, number?, number?)
Where a subject is drawn this frame, in world space. A body the
simulation moves is drawn blended between physics ticks, and so is
everything parented under it, while its transform (entity.position)
moves only when a tick runs; a rig placed from the drawn pose keeps the
subject steady on screen. Any other entity is drawn where its transform
puts it.
Parameters
targetIdstring— The subject to read.
Returns (number?, number?, number?) — The drawn world position as three numbers, or nil when nothing in the scene answers to that id. A VM that holds no render state answers with the transform's position.
local x, y, z = CameraRig.drawnPosition(bodyId)
typed/builtin//controller/camera_rig/R/facingSource
R.facingSource(targetId: string) -> string?
What visibleForward reads a subject's facing from, as one key: the
character's facing component, the anchor it turns and the direction it
declares along that anchor (BodyFacing.source), or nil while the
subject answers its own transform. The key changes when the facing
becomes known (a Locomotion or LocomotionFull arrives, a body stands
up under the character) or is declared anew (Locomotion.forward or
LocomotionFull.faceSign changes), and holds while the body turns. A
follow rig aims behind its subject when it binds it and again when this
key changes, so a character whose facing arrives after the camera bound
is framed from behind.
Parameters
targetIdstring— The subject to read.
Returns string? — The key, or nil when the subject's own transform is its facing.
if CameraRig.facingSource(bodyId) ~= alignedSource then alignBehind(bodyId) end
typed/builtin//controller/camera_rig/R/firstLookThisFrame
R.firstLookThisFrame(state: { frame: number? }) -> boolean
Whether a rig's look has already run in the frame now running, and
marks it run. A rig's look(dt) runs once a frame however many times it
is called: the Camera calls it in the look phase, and the rig's own
update calls it for a frame the Camera did not.
Parameters
state{ frame: number? }— The rig's look state, fromnewLookFrame.
Returns boolean — True the first time it is asked in a frame.
if not CameraRig.firstLookThisFrame(looked) then return end
typed/builtin//controller/camera_rig/R/headingOf
R.headingOf(frame: Frame.Frame, wx: number, wy: number, wz: number) -> number?
The heading a direction points along, measured the way the follow
rigs hold theirs: radians about the frame's up from its +Z, in
[0, 2pi). A rig looking along this heading stands behind something
facing that direction.
Parameters
frameFrame.Frame— The frame the heading is measured in.wxnumber— World-space direction X.wynumber— Direction Y.wznumber— Direction Z.
Returns number? — The heading, or nil when the direction runs along up.
local yaw = CameraRig.headingOf(frame, CameraRig.visibleForward(bodyId))
typed/builtin//controller/camera_rig/R/lookAround
R.lookAround(state: Look, dx: number, dy: number, limits: LookLimits, dt: number) -> (number, number)
Turn a look-around by one frame of look input, held within its
limits, and bring it back to rest once the input stops. Yaw is positive
to the right, pitch positive up; a look delta reports what the pointer
did, so pushing the mouse or stick forward (negative dy) looks up
unless invertY is set. A look moves state and answers the turn.
Parameters
stateLook— The rig's look, fromnewLook.dxnumber— This frame's horizontal look input.dynumber— This frame's vertical look input.limitsLookLimits— TheLookLimitsthe look answers to.dtnumber— Frame delta in seconds.
Returns (number, number) — Yaw and pitch in radians.
local yaw, pitch = CameraRig.lookAround(look, dx, dy, limits, dt)
typed/builtin//controller/camera_rig/R/lookIsDirect
R.lookIsDirect(class: string?) -> boolean
Whether a look from this device class turns the view on the frame
it arrives. A mouse reports the hand's own movement, so the view
follows it one to one ("kbm"). A stick reports a held position the
look control integrates into a turn rate, and a finger's drag arrives in
uneven steps, so those turns, and a script's drive, ease through the
rig's damping like any other change of its framing.
Parameters
classstring(optional) — The device class the look control reported (onInput's fourth argument).
Returns boolean — true for a look the rig carries on the frame it arrives.
local direct = CameraRig.lookIsDirect(class)
typed/builtin//controller/camera_rig/R/mapGuid
R.mapGuid(ref: any?) -> string?
Which input map an inputMap field names: its guid. asset.resolve
hands back a fresh table for every call, so the guid is what says whether
two refs name the same scheme, which is how a rig tells a repointed
inputMap from a write of the map it already holds.
Parameters
refany(optional) — An input map ref, or nil.
Returns string? — The map's guid, or nil when ref names none.
if CameraRig.mapGuid(public.inputMap) ~= CameraRig.mapGuid(activeMap) then retake() end
typed/builtin//controller/camera_rig/R/newLook
R.newLook() -> Look
A fresh look-around state for lookAround, at rest.
Returns Look — A look turned by nothing.
local look = CameraRig.newLook()
typed/builtin//controller/camera_rig/R/newLookFrame
R.newLookFrame() -> { frame: number? }
A fresh look state for firstLookThisFrame: no frame looked yet.
Returns { frame: number? } — The state a rig holds between frames.
local looked = CameraRig.newLookFrame()
typed/builtin//controller/camera_rig/R/newPullIn
R.newPullIn() -> PullIn
A fresh pull-in state for pullInEased.
Returns PullIn — A pull-in holding the camera at its framing, with no motion measured yet.
local hold = CameraRig.newPullIn()
typed/builtin//controller/camera_rig/R/newRecenter
R.newRecenter() -> Recenter
A fresh recentre state for recenter.
Returns Recenter — A recentre that has seen no input and was not asked for.
local recentring = CameraRig.newRecenter()
typed/builtin//controller/camera_rig/R/newTracking
R.newTracking() -> Tracking
A fresh tracking state for track, holding no point yet.
Returns Tracking — An empty tracking state: the first track call places the tracked point on the subject.
local tracking = CameraRig.newTracking()
typed/builtin//controller/camera_rig/R/newTrail
R.newTrail() -> Trail
A fresh trail state for trail, holding no offset yet.
Returns Trail — An empty trail: the first trail call places the camera at its goal.
local follow = CameraRig.newTrail()
typed/builtin//controller/camera_rig/R/playRunning
R.playRunning() -> boolean
Whether play is running: play mode with its clock going. A rig's field written while play runs is a steer, which the rig's next tick takes through its damping and its pull-in the way look input is taken; a field written in edit mode, or while play is paused, is an authoring edit that re-poses the rig at once.
Returns boolean — true in play mode with the clock going.
if not CameraRig.playRunning() then poseImmediate() end
typed/builtin//controller/camera_rig/R/pullIn
R.pullIn(pivotX: number, pivotY: number, pivotZ: number, camX: number, camY: number, camZ: number, radius: number, exclude: (string | { string })?) -> (number, number, number)
Pull a camera position in toward the pivot when a collider intervenes.
A sphere of radius is swept from the pivot to the camera, and the
camera stops where the sphere first meets a collider. Every collider in
the world blocks the sweep, whether or not anything draws it: an
invisible walk bound, a trigger volume and a wall all pull the camera in
alike. The entities named in exclude are the ones the sweep passes
through. A pivot standing against a collider, so that the sphere starts
touching it, is swept again with a sphere of half the radius, then a
quarter, which slides along that collider, and a pivot nearer it than
that is answered by a ray. A pivot inside a collider has no line out to
the camera, and the camera position comes back untouched.
Parameters
pivotXnumber— Pivot X.pivotYnumber— Pivot Y.pivotZnumber— Pivot Z.camXnumber— Desired camera X.camYnumber— Desired camera Y.camZnumber— Desired camera Z.radiusnumber— Sphere radius used for the cast; 0 turns the pull-in off and returns the camera position untouched.exclude(string | { string })(optional) — The entity, or list of entities, whose colliders never block the camera: the subject, plus any collider the camera should see through.
Returns (number, number, number) — The corrected camera position.
local x, y, z = CameraRig.pullIn(px, py, pz, cx, cy, cz, 0.3, bodyId)
local x, y, z = CameraRig.pullIn(px, py, pz, cx, cy, cz, 0.3, { bodyId, boundsId })
typed/builtin//controller/camera_rig/R/pullInAim
R.pullInAim(fromX: number, fromY: number, fromZ: number, framedX: number, framedY: number, framedZ: number, heldX: number, heldY: number, heldZ: number, aimX: number, aimY: number, aimZ: number) -> (number, number, number)
The point a camera pullInEased placed looks at: the rig's aim,
brought toward the point the sweep started from in step with how far
along its framing line the camera came in, and moved with the camera
where it stands off that line. The camera then looks along the line its
framing looks along, so a camera pulled in past the point a lagging rig
frames still faces its subject, and a camera turned round its pivot
keeps the heading its framing has. A camera standing at its framing
looks at the aim itself.
Parameters
fromXnumber— Where the sweep started, X: the pivot passed topullInEased.fromYnumber— Sweep start Y.fromZnumber— Sweep start Z.framedXnumber— Where the framing put the camera, X: the camera passed topullInEased.framedYnumber— Framed camera Y.framedZnumber— Framed camera Z.heldXnumber— WherepullInEasedstood the camera, X.heldYnumber— Held camera Y.heldZnumber— Held camera Z.aimXnumber— The point the framing looks at, X.aimYnumber— Aim Y.aimZnumber— Aim Z.
Returns (number, number, number) — The point the camera looks at, as three numbers.
local ax, ay, az = CameraRig.pullInAim(px, py, pz, fx, fy, fz, cx, cy, cz, lookX, lookY, lookZ)
typed/builtin//controller/camera_rig/R/pullInEased
R.pullInEased(state: PullIn, pivotX: number, pivotY: number, pivotZ: number, camX: number, camY: number, camZ: number, radius: number, exclude: (string | { string })?, outTime: number, dt: number, frame: Frame.Frame?) -> (number, number, number)
pullIn that never cuts: each frame the sphere sweep finds where
the camera may stand, and sweeps of the line ahead (from where the pivot
is moving to, as far as its own path is clear, along where the line is
turning) find what is about to
come between the camera and its subject, so the camera comes in ahead of
it, at the speed that has it clear by the time the line gets there.
Something the sweeps ahead could not see coming (a wall that appears)
brings the camera in to it on the frame it blocks the view, so no frame
draws from behind geometry. What the sweeps ahead found stays held for
the time ahead they last found it at, so frames of uneven length (a long
frame the subject's motion comes late to, then the short one it comes
in) neither ease the camera back out from it nor cut it in to it, and
one such frame that reads slower motion than the measured moves the
measured motion no more than halfway to it, while one that reads faster
moves it as far as the time constant has it, so a walk that starts in a
long frame is swept ahead at once. Once the way is clear the camera eases back
out to its framing over a time constant of outTime. A camera standing
at its framing moves with that framing, nearer or farther, on the frame
it moves.
The camera stands no nearer its pivot than 0.4 m while there is room round it: a framing line with less room than that, now or ahead (the subject stands against a wall or a pillar the camera is behind), turns the camera round the pivot about the up, by the smallest turn that has the room, and the camera turns back onto the line once the line has the room again. It keeps looking the way its framing looks, so the controls that follow the camera's heading hold steady while it is turned. Within 0.4 m of the pivot the camera is held clear of geometry by a 0.16 m sphere, which holds its near plane. A pivot that starts touching a collider is swept with a thinner sphere, which slides along it, and a pivot nearer it than the thinnest sphere has room for by a ray; a pivot inside a collider holds the camera as far out as it stood.
Parameters
statePullIn— The rig's pull-in, fromnewPullIn.pivotXnumber— Pivot X: the point on or over the subject the sweep starts from, which the camera stands out from.pivotYnumber— Pivot Y.pivotZnumber— Pivot Z.camXnumber— Where the framing puts the camera, X.camYnumber— Camera Y.camZnumber— Camera Z.radiusnumber— Sphere radius used for the cast; 0 turns the pull-in off.exclude(string | { string })(optional) — The entities whose colliders the sweep passes, aspullIntakes them.outTimenumber— Time constant in seconds of the ease back out; 0 snaps out.dtnumber— Frame delta in seconds; 0 places the camera where the sweep lets it stand, with no motion carried.frameFrame.Frame(optional) — The frame whose up the camera turns round its pivot about (modules.up_frame); the world's when left out.
Returns (number, number, number) — The camera position as three numbers.
cx, cy, cz = CameraRig.pullInEased(hold, px, py, pz, cx, cy, cz, 0.3, exclude, 0.4, dt)
cx, cy, cz = CameraRig.pullInEased(hold, px, py, pz, cx, cy, cz, 0.3, exclude, 0.4, dt, Frame.at(px, py, pz))
typed/builtin//controller/camera_rig/R/pullInExclude
R.pullInExclude(subjectId: string?, ignore: { any }?) -> { string }
The exclude list a rig hands pullIn: its subject, followed by every
entity in its cameraIgnore field. Each entry of ignore is an entity
id or an entity proxy; an empty slot is skipped.
Parameters
subjectIdstring(optional) — The entity the rig frames, or nil when it frames none.ignore{ any }(optional) — The rig'scameraIgnorelist, or nil.
Returns { string } — The entity ids the pull-in sweep passes through.
local exclude = CameraRig.pullInExclude(targetId, public.cameraIgnore)
typed/builtin//controller/camera_rig/R/recenter
R.recenter(state: Recenter, heading: number, goal: number?, looked: boolean, weight: number, delay: number, time: number, dt: number, moving: boolean?) -> number
Turn a heading back toward its goal by one frame once look input has
stopped. Look input this frame holds the heading and starts the wait
over; once delay seconds pass with none (or at once after
requestRecenter), the heading turns the short way round toward goal
over a time constant of time seconds, its rate scaled by weight
(1 is the full rate; a requested recentre turns at the full rate). A
frame whose weight is 0 holds the heading and starts the wait over as
well, so a subject that stops after running toward the camera is turned
behind only once it has stood for delay. A negative delay turns only
on request. Told whether the subject moves (moving), a look the player
made holds the heading for as long as the subject stands, however long
that is: the player aimed the camera there. The wait starts once the
subject moves off, and a subject that stops again with no look since is
turned behind once it has stood for delay.
Parameters
stateRecenter— The rig's recentre, fromnewRecenter.headingnumber— The heading now, in radians.goalnumber(optional) — The heading to turn to, or nil when there is none this frame.lookedboolean— Whether look input turned the heading this frame.weightnumber— Share of the full rate this frame, 0 to 1.delaynumber— Seconds without look input before the heading turns; negative turns only on request.timenumber— Time constant in seconds of the turn; 0 snaps.dtnumber— Frame delta in seconds.movingboolean(optional) — Whether the subject moves this frame (subjectMoving); nil leaves a look's hold out.
Returns number — The heading in [0, 2pi).
yaw = CameraRig.recenter(recentring, yaw, goal, looked, 1, 2, 1, dt, CameraRig.subjectMoving(frame, vx, vy, vz))
typed/builtin//controller/camera_rig/R/recenterGoal
R.recenterGoal(frame: Frame.Frame, subjectId: string, to: string, state: Tracking) -> number?
The heading a follow rig turns back to: behind what to names.
"facing" is the way the subject visibly faces (visibleForward);
"motion" is the way it moves across the ground as track measured it,
and its facing while it moves slower than 0.5 m/s.
Parameters
frameFrame.Frame— The frame the subject stands in.subjectIdstring— The subject.tostring—"facing"or"motion".stateTracking— The rig's tracking, fromnewTracking.
Returns number? — The heading, or nil when the direction runs along up.
local goal = CameraRig.recenterGoal(frame, bodyId, public.recenterTo, tracking)
typed/builtin//controller/camera_rig/R/recenterWeight
R.recenterWeight(frame: Frame.Frame, heading: number, goal: number, vx: number, vy: number, vz: number) -> number
How much of a recentre's rate applies while the subject moves: the square of the share of the subject's facing that points along the view (0 for a subject running across the view or toward the camera, 0.5 at 45 degrees off it, 1 running straight away). A camera turning behind a subject that turns to face its motion, which the player steers by the camera, would otherwise turn the subject with it and circle forever. A subject moving slower than 0.5 m/s across the ground answers 1.
Parameters
frameFrame.Frame— The frame the subject stands in.headingnumber— The heading the camera looks along.goalnumber— The heading behind the subject's facing.vxnumber— Subject velocity X, world space.vynumber— Subject velocity Y.vznumber— Subject velocity Z.
Returns number — The share of the full rate, 0 to 1.
local w = CameraRig.recenterWeight(frame, yaw, goal, CameraRig.trackingVelocity(tracking))
typed/builtin//controller/camera_rig/R/requestRecenter
R.requestRecenter(state: Recenter)
Ask a recentre to turn the heading behind its goal now, without waiting out its delay. The request holds until the heading arrives or look input turns it, and it ends the hold of a look made while the subject stood: once behind, the heading recentres as it does after no look at all.
Parameters
stateRecenter— The rig's recentre, fromnewRecenter.
CameraRig.requestRecenter(recentring)
typed/builtin//controller/camera_rig/R/resolveFollow
R.resolveFollow(selfId: string, followField: any?) -> string?
Resolve the entity this rig follows: the explicit field, else the
standard Camera.follow slot.
Parameters
selfIdstring— This rig's entity id.followFieldany(optional) — The rig's ownfollowfield value.
Returns string? — Entity id, or nil when nothing resolvable is set.
local target = CameraRig.resolveFollow(public.entity.id, public.follow)
typed/builtin//controller/camera_rig/R/ringAt
R.ringAt(rings: Rings, t: number) -> (number, number)
Height and radius of the orbit at a point along the path through the three rings. The path passes through each ring and turns no corner at the centre ring: it heads there halfway between the directions of its two stretches.
Parameters
ringsRings— The bottom / center / top rings.tnumber— Position along the path, 0 at the bottom ring, 0.5 at the centre ring and 1 at the top.
Returns (number, number) — Height and radius at t.
local h, rad = CameraRig.ringAt(rings, 0.5)
typed/builtin//controller/camera_rig/R/ringLook
R.ringLook(rings: Rings, aimHeight: number, radiusScale: number, t: number, angle: number) -> number
Where along the path through the three rings a vertical look of
angle radians puts the camera. Where the path runs within about 78
degrees of round the aim point, the view pitches by the look's angle,
the rate a look turns the heading. Where it heads more steeply toward or
away from the aim point, the look moves the camera along it by five
times the angle times the camera's distance from the aim point, the
farthest it moves anywhere on the rings; so a stretch with little or no
pitch to turn takes a look the way any other stretch does, and a camera
moves the same way along rings authored a fraction of a degree apart.
The look carries on through a ring into the next stretch; a stretch
between two rings that stand in one place takes none of it.
Parameters
ringsRings— The bottom / center / top rings.aimHeightnumber— Height of the point the camera aims at, on the rings' axis.radiusScalenumber— What the ring radii are multiplied by.tnumber— Position along the path, 0 at the bottom ring and 1 at the top.anglenumber— Radians of look; positive moves toward the top ring.
Returns number — The position along the path, 0..1, the look arrives at.
rig.verticalAxis = CameraRig.ringLook(rings, 1.4, 1, rig.verticalAxis, dy * 0.005)
typed/builtin//controller/camera_rig/R/setDriveEnabled
R.setDriveEnabled(handle: number?, enabled: boolean) -> boolean
State whether a rig is live, from its onEnable (as
componentIsLive reads it) and its onDisable (false).
Disabling it releases its controls; enabling it arms them again, in edit
mode and while play runs. Enabled while play is paused, it arms on the
resume. A rig that is disabled stays released across a pause and its
resume. A statement of the state the rig is already in calls neither
callback.
Parameters
handlenumber(optional) — The handledriveWhileRunningreturned.enabledboolean— Whether the rig is live.
Returns boolean — True when a live registration carried that handle.
function onEnable() CameraRig.setDriveEnabled(driving, CameraRig.componentIsLive(public.entityId, public.enabled)) end
function onDisable() CameraRig.setDriveEnabled(driving, false) end
typed/builtin//controller/camera_rig/R/snapTracking
R.snapTracking(state: Tracking, subjectX: number, subjectY: number, subjectZ: number)
Put a tracking state on its subject, at rest: no lag, no lead and no velocity. A rig calls it where it frames a subject with no easing (a new subject, an authored framing write).
Parameters
stateTracking— The rig's tracking, fromnewTracking.subjectXnumber— Subject X, where it is drawn this frame.subjectYnumber— Subject Y.subjectZnumber— Subject Z.
CameraRig.snapTracking(tracking, tx, ty, tz)
typed/builtin//controller/camera_rig/R/subjectMoving
R.subjectMoving(frame: Frame.Frame, vx: number, vy: number, vz: number) -> boolean
Whether a subject moves across the ground, as a follow rig's recentre reads it: faster than 0.5 m/s across the frame it stands in.
Parameters
frameFrame.Frame— The frame the subject stands in.vxnumber— Subject velocity X, world space.vynumber— Subject velocity Y.vznumber— Subject velocity Z.
Returns boolean — true while it moves.
local moving = CameraRig.subjectMoving(frame, CameraRig.trackingVelocity(tracking))
typed/builtin//controller/camera_rig/R/tauOf
R.tauOf(remaining: number) -> number
The time constant of a per-second blend: a rig field stating what
share of the gap is left after one second (0 closes it at once, 1 never
closes it) as the seconds damp and trail take.
Parameters
remainingnumber— The share of the gap left after one second, 0 to 1.
Returns number — The time constant in seconds; 0 for a blend that snaps, math.huge for one that never moves.
local tau = CameraRig.tauOf(public.positionSmoothing)
typed/builtin//controller/camera_rig/R/track
R.track(state: Tracking, subjectX: number, subjectY: number, subjectZ: number, frame: Frame.Frame, limits: TrackingLimits, dt: number, airborne: boolean?) -> (number, number, number)
Follow a subject's motion by one frame: the tracked point closes on
the subject over the lags limits states, across the ground and along
up separately, so a step, a stair or a landing is eased rather than
copied, and it is held within the bounds limits states however fast
the subject goes. A rig frames the tracked point, so the subject moves
off the frame centre by at most those bounds. The same call measures the
subject's velocity and eases the lead toward it (trackingLead). Up and
across are those of frame, the frame the subject stands in.
Parameters
stateTracking— The rig's tracking, fromnewTracking.subjectXnumber— Subject X, where it is drawn this frame.subjectYnumber— Subject Y.subjectZnumber— Subject Z.frameFrame.Frame— The frame the subject stands in (Frame.follow).limitsTrackingLimits— TheTrackingLimitsthe rig states.dtnumber— Frame delta in seconds.airborneboolean(optional) — Whether the subject is off the ground this frame (airborne): while it is, the tracked point holds its height withinlimits.jumpBand.
Returns (number, number, number) — The tracked point as three numbers.
local fx, fy, fz = CameraRig.track(tracking, tx, ty, tz, frame, limits, dt, CameraRig.airborne(subjectId))
typed/builtin//controller/camera_rig/R/trackingLead
R.trackingLead(state: Tracking) -> (number, number, number)
Where a rig's aim runs ahead of its subject this frame, as track
last eased it: a world-space offset along the subject's motion across
the ground, scaled by its speed.
Parameters
stateTracking— The rig's tracking, fromnewTracking.
Returns (number, number, number) — The lead as three numbers.
local ax, ay, az = CameraRig.trackingLead(tracking)
typed/builtin//controller/camera_rig/R/trackingReport
R.trackingReport(state: Tracking, recentring: Recenter) -> TrackingReport
How a follow rig is following its subject, as its tracking()
answers it.
Parameters
stateTracking— The rig's tracking, fromnewTracking.recentringRecenter— The rig's recentre, fromnewRecenter.
Returns TrackingReport — lag: how far the subject stands from the point the rig frames, in metres, world space; lead: how far the aim runs ahead of that point; velocity: the subject's velocity as the rig measures it; recentering: whether the heading turned back toward the subject this frame; idle: seconds since look input last turned it; lookHeld: whether a look the player made holds the heading while the subject stands.
local t = CameraRig.trackingReport(tracking, recentring)
typed/builtin//controller/camera_rig/R/trackingVelocity
R.trackingVelocity(state: Tracking) -> (number, number, number)
The subject's velocity as track last measured it, in world space.
Parameters
stateTracking— The rig's tracking, fromnewTracking.
Returns (number, number, number) — The velocity as three numbers, in metres per second.
local vx, vy, vz = CameraRig.trackingVelocity(tracking)
typed/builtin//controller/camera_rig/R/trail
R.trail(state: Trail, subjectX: number, subjectY: number, subjectZ: number, goalX: number, goalY: number, goalZ: number, tauX: number, tauY: number, tauZ: number, dt: number) -> (number, number, number)
Ease a camera toward the place its framing puts it, measured from its
subject. The camera's OFFSET from the subject is what eases, so the
subject's own motion carries the camera with it at any speed: a camera
framed 6 m behind a car stands 6 m behind it at 5 m/s and at 200 m/s, and
what the time constants soften is a change of the framing itself (a
turn of the subject, a zoom, a look, a pull-in). state keeps the offset
between frames.
Parameters
stateTrail— The rig's trail, fromnewTrail.subjectXnumber— Subject X, where it is drawn this frame.subjectYnumber— Subject Y.subjectZnumber— Subject Z.goalXnumber— Where the framing puts the camera this frame, X.goalYnumber— Goal Y.goalZnumber— Goal Z.tauXnumber— Time constant in seconds for the offset's X; 0 snaps.tauYnumber— Time constant for Y.tauZnumber— Time constant for Z.dtnumber— Frame delta in seconds.
Returns (number, number, number) — The camera position as three numbers.
local cx, cy, cz = CameraRig.trail(follow, tx, ty, tz, gx, gy, gz, 0.3, 0.3, 0.3, dt)
typed/builtin//controller/camera_rig/R/visibleForward
R.visibleForward(targetId: string) -> (number, number, number)
The direction a subject visibly faces, in world space.
A character's facing is the body its Locomotion or LocomotionFull
turns: the direction that component declares (Locomotion.forward, or
LocomotionFull.faceSign along the anchor's Z) carried through the turned
body's rotation anchor, the one the component itself turns, so the answer
follows the body as it turns to walk and after setCharacter swaps it.
A subject with neither component answers its own transform.forward.
Parameters
targetIdstring— The subject to read: a character, or any entity under one.
Returns (number, number, number) — Unit world-space forward as three numbers.
local fx, fy, fz = CameraRig.visibleForward(bodyId)
typed/builtin//controller/orbital_follow/public/look
public.look(dt: number)
Turn the camera for this frame: take the look and zoom controls,
recentre, and face the camera along its framing from where the subject
stands. The Camera calls it in the look phase, ahead of everything that
steers by the camera's facing, so a walk relative to the camera moves
along the facing the frame is drawn with. It runs once a frame; update
then places the camera around the subject where it has moved to.
Parameters
dtnumber— Frame delta in seconds.
entity.find("PlayerCamera").component.get("controller.orbital_follow"):look(1 / 60)
typed/builtin//controller/orbital_follow/public/onFollowChanged
public.onFollowChanged(newFollow: any?, oldFollow: any?)
Re-pose after the Camera's follow slot changed. follow lives on the
Camera, so this rig receives no property notification of its own for it and
the Camera calls this instead. A target assigned after the rig attached is
picked up here, in edit mode as well as play.
Parameters
newFollowany(optional) — The entity the camera now follows.oldFollowany(optional) — The entity it followed before.
-- called by Camera.onPropertyChanged, not usually by hand
typed/builtin//controller/orbital_follow/public/recenter
public.recenter()
Turn the camera back behind its subject now, at the recenterTime
rate, without waiting out recenterDelay. It turns until it is behind
what recenterTo names, or until look input turns it, and it ends
the hold of a look the player made while the subject stood.
entity.find("PlayerCamera").component.get("controller.orbital_follow"):recenter()
typed/builtin//controller/orbital_follow/public/tracking
public.tracking() -> CameraRig.TrackingReport
How the camera is following its subject this frame.
Returns CameraRig.TrackingReport — lag: how far the subject stands from the point the camera frames, in metres (world space); lead: how far the aim runs ahead of that point; velocity: the subject's velocity as the rig measures it; recentering: whether the heading is turning back behind the subject this frame; idle: seconds since look input last turned it; lookHeld: whether a look the player made holds the heading while the subject stands.
local t = rig:tracking(); print(t.lag.y, t.recentering)
typed/builtin//editor/edui/editorPanel/behavior/M/onChange
M.onChange(self: any?, change: any?)
Parameters
selfany(optional)changeany(optional)
typed/builtin//editor/edui/editorPanel/behavior/M/onDelete
M.onDelete(self: any?)
Parameters
selfany(optional)
typed/builtin//editor/edui/editorPanel/behavior/M/onRegister
M.onRegister(self: any?)
Parameters
selfany(optional)
typed/builtin//modules/api/editor/agents/_ended
_ended(slot: number, termId: number) -> boolean
Deliver the ending a drain would have delivered for a slot whose program was closed in its pane — the one ending that brings nothing back and spawns no process. Served only by an engine that booted offline.
Parameters
slotnumber— Slot index.termIdnumber— The slot's terminal.
Returns boolean — Whether the ending was delivered.
typed/builtin//modules/api/editor/agents/_spawnPending
_spawnPending(pending: boolean) -> boolean
Hold a spawn as being on its way up, or release it — the window a slot spends waiting on the agent host before it can spawn. The scheduled watch reads it, so this is how a test asks what the watch does during it. Served only by an engine that booted offline.
Parameters
pendingboolean— True to hold a spawn in flight, false to release it.
Returns boolean — Whether the state was taken.
typed/builtin//modules/api/editor/agents/_spawned
_spawned(slot: number, termId: number) -> boolean
Leave the record a successful spawn leaves — the slot registered, the claim reported, the watch armed — for a terminal the caller supplies, without launching a process. Served only by an engine that booted offline.
Parameters
slotnumber— Slot index.termIdnumber— Terminal the slot's run would have been in.
Returns boolean — Whether the record was left.
typed/builtin//modules/api/editor/agents/chooseEffort
chooseEffort(agent: string, effort: string, offered: { any }, suggested: string?) -> any
Keep effort as the person's choice for agent, on the model the
agent runs on. An effort that model does not take is refused with the
efforts it does take.
Parameters
agentstring— The agent's id.effortstring— The effort to run at (low,medium,high,xhigh,max, or any other the model lists).offered{ any }— The models the agent offers, asmodelChoicetakes them.suggestedstring(optional) — The model the agent itself would run on.
Returns any — { ok = true, choice } or { ok = false, reason, efforts? }.
typed/builtin//modules/api/editor/agents/chooseModel
chooseModel(agent: string, model: string, offered: { any }, suggested: string?) -> any
Keep model as the person's choice for agent. A model the offer
does not list is refused with the models it does list; it is never
replaced by another. A kept effort the new model does not take is dropped
and named in effortDropped.
Parameters
agentstring— The agent's id.modelstring— The model to run on.offered{ any }— The models the agent offers, asmodelChoicetakes them.suggestedstring(optional) — The model the agent itself would run on.
Returns any — { ok = true, choice, effortDropped? }, choice being what modelChoice now answers, or { ok = false, reason, offered? }.
typed/builtin//modules/api/editor/agents/deliver
deliver(i: number, message: any?) -> any
Queue a current-world event for a slot: { text, id?, actionable? }. An actionable event (the default) wakes an idle agent once it can act, and a busy agent receives it when its CLI accepts another prompt; with actionable false it joins the agent's context without starting a turn. A stable id makes retries idempotent. Check ok before considering a message queued.
Parameters
inumbermessageany(optional)
Returns any
typed/builtin//modules/api/editor/agents/deliveryStatus
deliveryStatus(i: number) -> any
Delivery state for this slot: event phase, pending count, whether a pending event wakes the agent (wakes), whether a Codex slot's engine tools have connected (toolsReady), reactive toggle, watched tasks and errors. contextActive reports request-time snapshots; contextRequests counts injected requests and contextError describes provider availability.
Parameters
inumber
Returns any
typed/builtin//modules/api/editor/agents/ensureSlot
ensureSlot(i: number)
Ensure slot i's agent process is running, spawning it (and waiting on
the agent host's boot dependency) when it is not. Opening a slot's panel
calls this; calling it again on a running slot is a no-op, so it is also
how a panel relaunches an exited agent.
Parameters
inumber
typed/builtin//modules/api/editor/agents/label
label(i: number) -> string
The name slot i carries: its harness's own name — "Claude Code",
"Codex CLI", "Cursor CLI" — numbered only where another slot seats the
same harness. This is what an agent tab and the Agents menu are titled by.
Parameters
inumber— The slot number, from 1 toslotCount().
Returns string — The slot's label.
print(agents.slotLabel(2)) -- the title of the panel "agent2"
typed/builtin//modules/api/editor/agents/modelChoice
modelChoice(agent: string, offered: { any }, suggested: string?) -> any
The model and the effort the engine runs agent on, judged against
what the agent offers right now. The person's own choice comes first, then
the engine's default for the agent (DotBot on Claude: claude-sonnet-5-5),
then the model the agent suggests, then the first it offers; the effort is
the person's choice when the model takes it, else high when it takes
that. The choice is kept for the person's account on this device, across
conversations and restarts.
Parameters
agentstring— The agent's id, as its host names it (dotbot-claude,dotbot-chatgpt,dotbot). An agent on a further account of its provider (dotbot-claude~2) shares the agent's default and choice.offered{ any }— The models the agent offers: a list of{ id, efforts?, defaultEffort? },effortsnaming the efforts that model takes anddefaultEffortthe one the model states for itself.suggestedstring(optional) — The model the agent itself would run on, used when neither the person nor the engine names one the offer holds.
Returns any — { ok, agent, model, effort, modelFrom, effortFrom, efforts, kept, notOffered?, effortNotTaken?, storeError? }. modelFrom is person, engine or offer; effortFrom is person, engine or model; kept is the person's stored { model?, effort? }, whether or not the offer holds it. notOffered / effortNotTaken name a kept choice the offer no longer holds, with the reason. storeError says why the kept choice could not be read, and the engine's default answers in its place. { ok = false, reason } for an agent id or an offer of the wrong shape. An empty offer answers no model.
typed/builtin//modules/api/editor/agents/resetModelChoice
resetModelChoice(agent: string) -> any
Forget the person's choice of model and effort for agent, so the
engine's default applies again.
Parameters
agentstring— The agent's id.
Returns any — { ok = true } or { ok = false, reason }.
typed/builtin//modules/api/editor/agents/setReactive
setReactive(i: number, enabled: boolean) -> any
Enable automatic engine-event delivery, or pause it. Paused, the slot's notices reach it on its tool results, and its own messages and task completions stay queued until delivery resumes.
Parameters
inumberenabledboolean
Returns any
typed/builtin//modules/api/editor/agents/slotCount
slotCount() -> number
How many concurrent agent slots the editor offers.
Returns number — The slot count.
typed/builtin//modules/api/editor/agents/slotStatus
slotStatus(i: number) -> any
Slot i's terminal and live state, for a panel to render: drains the
slot lifecycle events, then reports the backing terminal id (created on
first ask), whether its process is running, the slot's display label, how
many automatic relaunches it has spent, whether this host has the slot's
harness, and the step and the site that install it.
Parameters
inumber
Returns any — {termId, running, label, relaunches, installed, install, site}.
typed/builtin//modules/api/editor/agents/spec
spec(kickoffPrompt: string?, slot: number?) -> any
The process spec the launcher runs for a slot's harness — the command,
its flags, its working directory, and the environment it inherits, with
the agent's bearer replaced by <redacted> wherever the spec carries it.
Parameters
kickoffPromptstring(optional) — Text submitted as the agent's first message.slotnumber(optional) — Which slot to build for: its harness, and the caller id that slot's agent presents to the engine on every call. The first slot when omitted; a number the dock has no slot for is refused.
Returns any — A terminal.spawn spec: {cmd, args, cwd, env, envRemove}, plus files for an agent whose configuration is read from its working directory rather than from its flags.
typed/builtin//modules/api/editor/agents/watchSlotExits
watchSlotExits() -> boolean
Watch every slot's ending on a schedule, so an agent that ends while its tab is not the drawn one is still noticed — brought back if that is what its ending calls for (the same relaunch a drawn pane would have run), and reported as no longer working either way. A spawn starts this and every later spawn starts it again; it ends on a tick with no slot registered and no spawn on its way up, and one chain holds it at a time.
Returns boolean — True when this call took the watch, false when this module already held it.
typed/builtin//modules/api/engine/agentContext/M/clearWorld
M.clearWorld(name: string, world: string, branch: string, scene: string?) -> (boolean, string?)
Clear a named block when its stored scope is the one given.
Parameters
namestring— Block name.worldstring— The world GUID it was published for.branchstring— The branch it was published for.scenestring(optional) — The scene GUID it was published for, or nil.
Returns (boolean, string?) — True once removed, or false and an optional reason.
agentContext.clearWorld("sceneAuthoring", world.guid(), world.branch(), sceneGuid)
typed/builtin//modules/api/engine/agentContext/M/publishWorld
M.publishWorld(name: string, world: string, branch: string, scene: string?, json: string) -> (boolean, string?)
Publish a named block of world data for agents. The scope must name the bound world and branch, and a scene scope the active root scene. Up to 32 names and 8192 JSON bytes per value are kept.
Parameters
namestring— Block name.worldstring— The world GUID the data was observed in.branchstring— The branch the data was observed on.scenestring(optional) — The root scene GUID the data describes, or nil for world-wide data.jsonstring— The value, as JSON.
Returns (boolean, string?) — True once published, or false and the reason.
local ok, why = agentContext.publishWorld("sceneAuthoring", world.guid(), world.branch(), sceneGuid, body)
typed/builtin//modules/api/engine/animation/animation/animating
animation.animating() -> { AnimationBody }
The bodies the engine measured a changing pose on — what is animating right now.
Returns { AnimationBody } — An array of AnimationBody.
for _, b in animation.animating() do for _, c in b.clips do print(b.entity, c.name, c.weight) end end
typed/builtin//modules/api/engine/animation/animation/bodies
animation.bodies() -> { AnimationBody }
Every body the engine holds animation state for.
Returns { AnimationBody } — An array of AnimationBody.
for _, b in animation.bodies() do print(b.entity, b.matched .. "/" .. b.total) end
typed/builtin//modules/api/engine/animation/animation/body
animation.body(entityId: string | EntityRef) -> AnimationBody?
The report for one body, or nil when the engine holds no animation state for it. Accepts the body itself or any ancestor of it, so a character root answers for the skinned body underneath it.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns AnimationBody? — An AnimationBody, or nil.
local b = animation.body(hero.id); print(b and b.reason)
typed/builtin//modules/api/engine/animation/animation/clips
animation.clips(entityId: string | EntityRef) -> { AnimationClip }
The clips contributing to a body's pose right now, with their playheads and their retarget coverage.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns { AnimationClip } — An array of AnimationClip.
for _, c in animation.clips(hero.id) do print(c.name, c.time, c.matched) end
typed/builtin//modules/api/engine/animation/animation/coverage
animation.coverage(entityId: string | EntityRef) -> (number, number)
How many of a body's bones the clips driving it actually reach.
Returns (matched, total). A clip that retargets onto nothing reads
(0, 50) while its playhead advances; a partial retarget reads its own
count, so 3 of 50 is as visible as none.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns (number, number) — (matched, total).
local m, t = animation.coverage(hero.id); print(m .. "/" .. t)
typed/builtin//modules/api/engine/animation/animation/declare
animation.declare(entityId: string, facts: { [string]: any })
Publish what an animator is running on a body, so the observation names
its clips, playheads and retarget coverage beside the pose the engine
measures. The shipped animators declare through AnimGraph:publish; a
custom animator calls this itself whenever what it runs changes. A clip
that names its sampler (the handle skeleton.bindClip returned) reports
the playhead that sampler last sampled at, and each sample keeps the
declaration current; an animator declaring a clip without its sampler
declares on every frame it runs, since nothing else shows it is still
running. A declaration stands until the animator declares again or calls
animation.forget.
Parameters
entityIdstring— The body the animator drives.facts{ [string]: any }—{ driver, bound, playing, outputKind, failure, clips }, where each clip is{ name, nodeKind, sampler, time, duration, playing, finished, looping, weight, matched, total, unmatched };unmatchedlists the bones the clip leaves at rest that fill a role of the body's retarget profile first.
animation.declare(body.id, { driver = "MyAnimator", playing = true, clips = {} })
typed/builtin//modules/api/engine/animation/animation/forget
animation.forget(entityId: string)
Drop the declaration and the pose evidence the engine holds for one body. An animator calls this when it releases a body, so the observation reports the body as undriven from the next frame.
Parameters
entityIdstring— The body to drop.
animation.forget(body.id)
typed/builtin//modules/api/engine/animation/animation/observe
animation.observe() -> AnimationObservation
Report what the engine is posing right now and why a body is not moving. One read covering every body the engine holds animation state for, each with the pose evidence the engine measured on its armature beside the clips the animator driving it declared. Answers in edit mode as well as play mode.
Returns AnimationObservation — An AnimationObservation.
local a = animation.observe(); print(a.animatingCount, a.riggedBodyCount)
for _, b in animation.observe().bodies do print(b.entity, b.animating, b.reason) end
typed/builtin//modules/api/engine/animation/animation/poseDue
animation.poseDue(entityId: string | EntityRef) -> boolean
Whether the engine evaluates this body's pose this frame. The engine
decides each rigged body's interval once a frame from what the views see
of it, and every shipped animator (AnimGraph:tick, the graphs the engine
runs, AvatarAnimator) evaluates only on the frames this answers true,
carrying the time of the frames between into the next evaluation. A custom
animator does the same: skip the evaluation and keep the delta when this
is false. A body the engine does not schedule answers true.
Parameters
entityIdstring | EntityRef— The skinned body's id, or an EntityRef.
Returns boolean — true on a frame the body is evaluated on.
if animation.poseDue(body.id) then print("evaluated this frame") end
typed/builtin//modules/api/engine/animation/animation/poseRate
animation.poseRate(entityId: string | EntityRef) -> AnimationPoseRate?
How often the engine evaluates a body's pose and why, as an
AnimationPoseRate. Accepts the body or an entity above it, answering for
the first scheduled body beneath. nil when no body there is scheduled.
Parameters
entityIdstring | EntityRef— The body's id, an entity above it, or an EntityRef.
Returns AnimationPoseRate? — An AnimationPoseRate, or nil.
local r = animation.poseRate(hero.id); print(r and r.interval, r and r.reason)
typed/builtin//modules/api/engine/animation/animation/poseRates
animation.poseRates() -> AnimationPoseRates
Every scheduled body's rate in total, with the settings the intervals
are chosen by, as an AnimationPoseRates: how many bodies are evaluated
every frame, how many for each reason, and the share of full-rate
evaluations a frame makes.
Returns AnimationPoseRates — An AnimationPoseRates.
local t = animation.poseRates(); print(t.bodies, t.evaluationShare, t.byReason.offscreen)
typed/builtin//modules/api/engine/animation/animation/ragdoll
animation.ragdoll(entityId: string | EntityRef, opts: (boolean | RagdollOptions)?) -> string
Ragdoll a skinned body: its skeleton is carried by physics bodies that
fall, tumble and pose the mesh, for a death, a knockout, a hit reaction, a
stunt fall or a limp limb. Works on any rigged skeleton: a humanoid (the
built-in avatar and any imported humanoid rig) gets bodies sized for each
body part and anatomical joints (hinged knees and elbows, cones at the
shoulders, hips and neck); any other rig (a quadruped, a bird, a tail, a
robot arm) gets a capsule along every bone and ball joints. The first call
builds the ragdoll on the next frame, false included (its bodies follow
the animation until it is switched on, so its bones can be read and
jointed first); animation.ragdollState reads it back. false hands the
body back to its animation: every bone moves from where the ragdoll left
it to the pose its animation holds over blend seconds (play a get-up
clip on the body as you call it, and the body rises into it; a body
nothing animates goes back to the pose it held when it fell), and the
entity this call names (or the nearest one above it that also holds the
skeleton's bones) is moved to stand the body up where it lies (over the
place the hips lie, turned the way the body lies). true ragdolls it
again. A ragdoll poses the body whatever animates it: a clip player, an
animation graph or a locomotion program.
The options table takes active (default true), limp (bone names: only
those bones and the bones below them go limp while the rest keep
animating), blend (the seconds a bone handed back to its animation takes
to reach it, default 0.5; 0 hands it back in one frame), standUp
(default true; false leaves the entity this call names where it is when
the body is handed back), mass (the whole body's mass in kilograms; by default bodies
weigh 1000 kg per cubic metre of collider, about 120 kg for the built-in
avatar, so pass a person's 60 to 90 kg for a lifelike one) and bones (bone
name -> { shape = "capsule" | "box" | "sphere" | "none", radius, length, size = {x, y, z}, mass, joint = "ball" | "hinge" | "fixed", swing, twist, hinge = {min, max}, strength, damping }, sizes in metres and angles in
degrees). A description different from the last one rebuilds the ragdoll.
On a humanoid a bone is also named by its humanoid role (hips, spine,
chest, neck, head, leftshoulder, leftarm, leftforearm,
lefthand, leftupleg, leftleg, leftfoot and the right ones), so
one description fits every humanoid rig.
Each bone body is the body of that bone's armature entity (its id in
ragdollState), so every Physics call takes it: Physics.addJoint to
hold a hand to a ledge (breakable with breakForce), Physics.applyImpulseAtPoint
for a hit, Physics.getVelocity, Physics.bodyState and Physics.contacts
to measure a fall.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it (a character root).opts(boolean | RagdollOptions)(optional) —true/false, or aRagdollOptionstable.
Returns string — The id of the skinned entity the ragdoll is built on.
animation.ragdoll(enemy.id) -- collapse it
animation.ragdoll(enemy.id, false) -- back to its animation, standing up where it lies
animation.ragdoll(enemy.id, { active = false, blend = 1.2 }) -- a slower rise
animation.ragdoll(hero.id, { limp = { "leftarm" } }) -- one limp arm
animation.ragdoll(dummy.id, { mass = 75, bones = { head = { mass = 5, swing = 30 }, leftleg = { hinge = { -140, 0 } } } })
local hand = animation.ragdollBone(hero.id, "righthand"); Physics.addJoint(hand, ledge, { kind = "ball", breakForce = 3000 })
typed/builtin//modules/api/engine/animation/animation/ragdollBone
animation.ragdollBone(entityId: string | EntityRef, bone: string) -> string?
The entity a ragdoll's bone body answers to, by bone name or, on a
humanoid, by humanoid role (head, righthand, ...): the id to
pass Physics.addJoint, Physics.applyImpulseAtPoint,
Physics.getVelocity, Physics.bodyState, Physics.contacts and every
other Physics call. nil until the ragdoll is built, or when that bone
has no body of its own.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it.bonestring— The bone's name in the skeleton.
Returns string? — The bone body's entity id, or nil.
local head = animation.ragdollBone(dummy.id, "head"); print(Physics.getVelocity(head))
typed/builtin//modules/api/engine/animation/animation/ragdollState
animation.ragdollState(entityId: string | EntityRef) -> RagdollState?
The ragdoll built on a skinned body: whether the simulation drives
it, its total mass, and every bone body with the entity it answers to (the
bone's armature entity), its shape and size in metres, its mass read off
the solver, whether it is simulated, and its joint. built reads false
until the engine has built it (the frame after animation.ragdoll), and
problems names anything the description asked for that the skeleton
could not give. Under multiplayer replication reads which peer simulates
the ragdoll (the owner of the synced entity at or above the body; every
other peer shows it from that peer's bone poses) and what it costs on the
wire.
Parameters
entityIdstring | EntityRef— The skinned entity, or any entity above it.
Returns RagdollState? — A RagdollState, or nil when the body carries no ragdoll.
local r = animation.ragdollState(hero.id); for _, b in r.bones do print(b.bone, b.mass, b.joint and b.joint.kind) end
typed/builtin//modules/api/engine/animation/animation/setPoseRate
animation.setPoseRate(entityId: string | EntityRef, mode: string | number)
Pin how often a body's pose is evaluated, wherever it stands: "exact"
(every frame, for a character whose bones drive gameplay, attachments or
physics off screen as well as on), a number of frames (1 to 120), or
"auto" to return it to the interval the views decide. Applies to every
skinned body at or below the entity, from the next frame. Raises when no
entity at or below it carries a Skeleton, as a character whose model
has not loaded yet: pin it once its body is there.
Parameters
entityIdstring | EntityRef— The body, an entity above it, or an EntityRef.modestring | number—"exact","auto", or frames between two evaluations.
animation.setPoseRate(boss.id, "exact")
typed/builtin//modules/api/engine/animation/animation/setPoseRateSettings
animation.setPoseRateSettings(settings: { [string]: any })
Change how the engine chooses each body's interval, replacing the
fields named (see PoseRateSettings): steps from the largest share of a
view's height down (a visible body takes the first step it spans, and the
last step's interval below them all), offscreenInterval for a body no
view holds, nearDistance in metres within which a body is evaluated
every frame, viewMarginDeg by which each view is widened, and enabled.
Raises naming the field when one cannot apply, and changes nothing then.
Parameters
settings{ [string]: any }— The fields to replace.
animation.setPoseRateSettings({ offscreenInterval = 30 })
typed/builtin//modules/api/engine/animation/animation/whyStill
animation.whyStill(entityId: string | EntityRef) -> (string?, string?)
Why the body on an entity is not animating. Returns nil when it IS
animating, and otherwise one of deactivated, noRiggedSkeleton,
noGraph, clipUnreadable, noOutputNode, retargetPending, retargetMatchedNoRoles,
stopped, finished, paused, poseNotApplied, poseUnchanged — the
nearest cause, so the answer names the thing to change. A second return
carries the animator's own words when it could not build a graph.
An entity the engine holds no animation state for is answered from the
entity itself, in the same order the engine resolves a body it does hold:
one carrying no rigged Skeleton is noRiggedSkeleton, and a rigged one
nothing drives is noGraph. An id no entity carries is neither — the
reason is nil and the detail says so.
Parameters
entityIdstring | EntityRef— The entity's stable id, or an EntityRef.
Returns (string?, string?) — (reason, detail).
local why, detail = animation.whyStill(hero.id); if why then print(why, detail) end
typed/builtin//modules/api/engine/app_menu/appMenu/activeTab
appMenu.activeTab() -> string?
The tab the menu shows, or would show when opened.
Returns string?
typed/builtin//modules/api/engine/app_menu/appMenu/close
appMenu.close(opts: { force: boolean? }?) -> boolean
Close the menu and go back to the world it was opened over. A menu
with no world behind it stays, unless force takes it down regardless,
as opening a world from it does.
Parameters
opts{ force: boolean? }(optional) —{ force? }.
Returns boolean — Whether it closed.
typed/builtin//modules/api/engine/app_menu/appMenu/isOpen
appMenu.isOpen() -> boolean
Whether the menu is open.
Returns boolean
typed/builtin//modules/api/engine/app_menu/appMenu/open
appMenu.open(tab: string?)
Open the menu, on the tab named or the one shown last.
Parameters
tabstring(optional) — The tab's id ("world","zeromind","system"), or nil.
typed/builtin//modules/api/engine/app_menu/appMenu/presentation
appMenu.presentation() -> Presentation
The presentation the menu is drawn in on this client now: "vr"
while a headset session holds focus, "phone" on Android and on a
screen narrower than a tablet or standing in portrait, "desktop"
otherwise.
Returns Presentation — The presentation.
typed/builtin//modules/api/engine/app_menu/appMenu/redraw
appMenu.redraw()
Draw the open menu again, its frame and the shown tab's body built
from their state now. A tab calls it after its own state changes, in
its onCallback or from a task or a timer, for the change to show; a
closed menu builds the tab it shows afresh when it next opens.
typed/builtin//modules/api/engine/app_menu/appMenu/select
appMenu.select(tab: string)
Show the tab named in the open menu.
Parameters
tabstring— The tab's id.
typed/builtin//modules/api/engine/app_menu/appMenu/tabs
appMenu.tabs() -> { { id: string, title: string, visible: boolean } }
The tabs registered, in their order, and whether each shows now.
Returns { { id: string, title: string, visible: boolean } } — { { id, title, visible } }.
typed/builtin//modules/api/engine/app_menu/appMenu/toggle
appMenu.toggle()
What the pause action does: open the menu, or, while it is open, go back one step in its tab, and close it from the tab's first step.
typed/builtin//modules/api/engine/asset/asset/add_tag
asset.add_tag(ref: RefArg, tag: string)
Add a tag to the asset's .metadata.tags. Idempotent.
Creates the sidecar and the tags array if missing.
Parameters
refRefArg— Any name the asset has.tagstring— Tag to add.
asset.add_tag("brick", "wip")
typed/builtin//modules/api/engine/asset/asset/alias
asset.alias(ref: RefArg, alias: string) -> boolean
Add a name the asset answers to. asset.resolve, leaf
shorthand, and the typed-argument coercion that content refs
travel through all reach the asset by the alias from here on,
exactly as they do by its identity — so a material naming a
shader by its alias resolves, and content written against an
older name keeps working after a rename. The name survives
writes to the asset's own files.
Raises when the name already resolves to a DIFFERENT asset — an
alias extends the identity namespace and never takes a name out
of another asset's hands — and when it is shaped like a guid or
a VFS path, forms that resolve before identity lookup, so an
alias in that shape could never answer.
Parameters
refRefArg— The asset gaining the name.aliasstring— The additional name. Any identity form: a bare leaf (standard) or a scope-qualified path (@builtin::shaders.legacy).
Returns boolean — True when newly added, false when the asset already answered to it.
asset.alias("@builtin::shaders.pbr", "standard")
typed/builtin//modules/api/engine/asset/asset/aliases
asset.aliases(ref: RefArg) -> { string }
The additional names this asset answers to, beyond its own
identity — what asset.alias registered, plus the
package-relative ~pkg.tail form when the asset lives inside a
package.
Parameters
refRefArg— Any name the asset has.
Returns { string } — Array of alias names in canonical identity form.
for _, n in asset.aliases("pbr") do print(n) end
typed/builtin//modules/api/engine/asset/asset/canCreate
asset.canCreate(typeName: string) -> boolean
Whether asset.create can instance typeName: the type declares
creation logic (a behavior.luau onCreate hook) or ships a
template/ skeleton the hookless fallback clones. A type with neither
— one whose instances only arrive by import — answers false. The query
a creation UI derives its offering from, so what it offers is what
asset.create accepts.
Parameters
typeNamestring— Registered asset type (e.g. "material", "scene").
Returns boolean — true when asset.create(typeName, …) can produce one.
if asset.canCreate(kind) then asset.create(kind, name) end
typed/builtin//modules/api/engine/asset/asset/categories
asset.categories(opts: CategoriesOpts?) -> { string }
List every asset category the engine currently recognises.
Use to discover valid type argument values for the rest of
asset.*. With implements, only the types that implement that
interface (a name, identity or guid), or any of a list of them: the
types whose type.yaml lists it under interfaces: and keeps it.
Parameters
optsCategoriesOpts(optional) — Optional{ implements }.
Returns { string } — Array of category names.
for _, c in asset.categories() do print(c) end
local placeable = asset.categories({ implements = "sceneInstantiable" })
typed/builtin//modules/api/engine/asset/asset/containing
asset.containing(path: string) -> AssetRef?
Walk path and its ancestors and return an AssetRef handle for
the INNERMOST registered category-folder containing it — the typed asset
that directly owns the path (e.g. main.scene for
"/source/scenes/main.scene/scene.json"; for a folder that is itself a
registered asset, that asset). Returns nil for paths outside any
registered asset.
Parameters
pathstring— VFS path to inspect.
Returns AssetRef? — AssetRef handle, or nil.
local a = asset.containing("/source/scenes/main.scene/scene.json")
typed/builtin//modules/api/engine/asset/asset/context
asset.context(path: string) -> AssetContext?
The context the engine loads the file at path into: the one the
contexts: block of the type.yaml of the type owning the file declares
(a scene's build.luau runs in sceneBuild, a .sceneModule's
init.luau in sceneModule). globals are the names its loader binds
into each chunk, each with a note on where it lives; hooks the functions
the engine calls by name; modules the source paths of the modules whose
leading block joins the context with a --!context <name> line, whose
exports are globals in the file. A module joins a context to hand its
exports to every file of it, and the language server declares the same
names. Nil for a file no type declares a context for.
Parameters
pathstring— The file's VFS path.
Returns AssetContext? — The context, or nil.
local context = asset.context("/zero/source/scenes/park.scene/build.luau")
typed/builtin//modules/api/engine/asset/asset/cpuResident
asset.cpuResident(ref: RefArg, typeName: string?) -> boolean
True when the asset is CPU-resident — a live script-component context
holds it (a component's assetRef field, or an imperative
asset.resolve/ref made while a component is the caller), which is what
warms its bytes into memory. The CPU pool is a different pool from the
device's: asset.observe().cpu lists it, asset.observe().textures /
.meshes list what the device holds, and an asset can be in one and not
the other.
Parameters
refRefArg— Any name the asset has — handle, identity, guid, name or path.typeNamestring(optional) — Category to restrict the match to. Omit to search every category.
Returns boolean — true when a live context holds it.
if asset.cpuResident(ref) then print("bytes are warm") end
typed/builtin//modules/api/engine/asset/asset/create
asset.create(typeName: string, name: string, opts: { [string]: any }?) -> (AssetRef, { durable: boolean, survivesRestart: boolean?, warning: string?, playShadow: string?, shadowed: { string }?, scratch: { string }? })
Instance a new asset of an existing type. Runs the type's
behavior.luau onCreate(name, opts) hook to produce the asset's
files, then writes them under /source/<folder>/<name>.<type>/
(/source/<name>.<type>/ when no folder is given). This is the
single generic asset-creation API. Refuses to clobber an existing
edit-mode asset unless opts.overwrite = true, which re-authors it in
place and keeps the existing guid (only the checksum changes). Pairs with
asset.exists for content generators that re-run over the same names.
A create made from a script component's callback or a scene entrypoint is
output the world reproduces on every load, so it is filed in the ephemeral
/runtime/assets/ store instead, where the saved manifest never carries a
second copy of it. name and folder spell the same IDENTITY in either
store, so a reference written against that identity resolves the asset
wherever the call filed it, and one generator run from an execute and
from a component names one asset.
Parameters
typeNamestring— Registered asset type to instance (e.g. "material", "texture").namestring— Destination asset name (becomes/source/<name>.<typeName>). A bare identity — passopts.folderto place it in a subfolder rather than spelling a path here. The accepted shape is the type's to declare:^[A-Za-z][A-Za-z0-9_]*$unless itsbehavior.luauexports anamePattern, asguidedoes to takegetting-startedand01-overview. This call names the category FIRST and the asset second. Every otherasset.*call taking both names them the other way round —asset.exists(name, category),asset.tryResolve(ref, category)— so a create-then-check pair readsif not asset.exists(n, t) then asset.create(t, n, opts) end. A call whose two arguments are read into each other, at either end of that pair, is refused and told which way round the call reads.opts{ [string]: any }(optional) — Optional table forwarded to the type'sonCreatehook, minus five framework keys consumed here and never seen by the hook:folder(a relative subfolder path under/sourceto author the asset in, with/between its folders as ingame/materials, so generated content groups instead of accumulating at the source root; those folders joined by dots prefix the asset's identity,game.materials.<name>),into(author INSIDE a resolved container ref),dest(an absolute destination path),overwrite(re-author in place, keeping the guid), anddurable(file every content file this create writes on canonical/sourcewith play still running, in place of the play shadow, and raise with the reason when they cannot become source, the same key, meaning the same thing, thatvfs.writetakes). Every type accepts all five whatever its own contract declares;asset.describe(typeName).frameworkParamsnames them, and a rejection prints them under the type's own parameters.
Returns (AssetRef, { durable: boolean, survivesRestart: boolean?, warning: string?, playShadow: string?, shadowed: { string }?, scratch: { string }? }) — The created asset's AssetRef, the SAME interned instance asset.resolve returns. ref.path is the VFS path the asset was written to (its folder: /zero/source/<folder>/<name>.<type>, the dest or into destination when one is given, /zero/runtime/assets/<identity>.<type> for a create filed in the ephemeral store), ref.primary the content file inside it (a shader's shader.wgsl, a module's init.luau), and both read and write with vfs.read / vfs.write or the read_file / write_file tools as they stand. ref.identity is the dotted name references use (<folder>.<name>, folder separators spelled .) and is what tostring(ref) prints. ref.guid is the stable id, and the type's ref methods (:getBytes, :ensureHandle, :serialize, ...) ride on it. Returned from execute, the ref reads back with all of these fields. Disk-only: nothing is uploaded to CPU/GPU. Where the bytes this call landed went, as a SECOND return value: { durable = true } when the files are where the call filed them, and { durable = false, survivesRestart = …, warning = …, playShadow = …, shadowed = { … } } when the play shadow took them: live in this session and undone by a guarded play-exit unless kept, with survivesRestart saying whether a restart of this engine keeps them, playShadow naming the routes that keep them and shadowed the paths. A create under /source/tmp/ answers durable = false with survivesRestart = false, a warning opening SCRATCH and scratch naming the paths: scratch reads back while the engine runs and is gone when it stops or restarts. durable is present whatever the answer is, so its absence is never a reading, and one call answers once for every file it wrote. It is the same answer, off the same shadow set and in the same words, that the MCP write_file / edit_file / capture tools attach to their own results — ask vfs.durability for it directly at any other write site.
local m = asset.create("material", "brick", { shader = "pbr" })
local s = asset.create("shader", "glow", { folder = "fx" }) -- s.path: /zero/source/fx/glow.shader, s.primary: /zero/source/fx/glow.shader/shader.wgsl
local wgsl = vfs.read(s.primary) -- the created asset's content file, read by the path the ref names
local mesh = asset.create("mesh", "tree", { positions = {...}, indices = {...} })
local mesh = asset.create("mesh", "rock", { positions = {...}, indices = {...}, folder = "terrain/props" })
local mesh = asset.create("mesh", name, { positions = p, indices = i, overwrite = true }) -- idempotent rebuild
local clip, d = asset.create("soundClip", "hit", { pcm = buf, sampleRate = 48000, channels = 1 })
if not d.durable then log.warn(d.warning) end
local c = asset.create("soundClip", "step", { pcm = buf, sampleRate = 48000, channels = 1, durable = true }) -- lands on source during play
typed/builtin//modules/api/engine/asset/asset/declareReferenceArg
asset.declareReferenceArg(call: string, position: number, assetType: string)
Declare that call's argument at 1-based position names an
asset of type, so a string literal written there is recorded as a
reference. The positional counterpart of
asset.declareReferenceField, for a call that takes its asset as a
plain argument — including a world's own spawn helper, which is
where a name most often stops being visible to the reference graph.
A lookup whose asset is its FIRST argument (asset.resolve and its
siblings) is already read and needs no declaration. Only a literal —
or a name the file holds in a top-level string constant — is
recorded; anything computed is reported as a dynamic resolve.
An asset type states the same declaration as content, in the
references.args of its type.yaml, which every reference table
reads from the moment the type registers.
Parameters
callstring— The callee as it is written at a call site.positionnumber— Which argument holds the name, counting from 1.assetTypestring
asset.declareReferenceArg("spawnModel", 3, "mesh")
typed/builtin//modules/api/engine/asset/asset/declareReferenceField
asset.declareReferenceField(call: string, field: string, assetType: string)
Declare that call's options table names an asset of type in
its field, so a string literal written there is recorded as a
reference by whatever writes the file. This is what puts an API
that takes an asset BY NAME into the reference graph: the named
asset becomes a dependency, travels with the content that names it
into a pack or a pull, and a name nothing answers to becomes an
unresolved dependency worldValidation reports and the push gate
refuses. A field holding a TABLE of names — a material's textures
— records every name in it. Declare once, beside the API; a call
taking its asset as the FIRST positional argument is already read
and needs no declaration. Only a literal is recorded; a computed
name resolves at runtime and is reported as a dynamic resolve.
An asset type states the same declaration as content, in the
references.fields of its type.yaml, which every reference table
reads from the moment the type registers.
Parameters
callstring— The callee as it is written at a call site.fieldstring— The options-table field holding the name, read at the table's own level.assetTypestring
asset.declareReferenceField("fx.beam", "material", "material")
typed/builtin//modules/api/engine/asset/asset/declareReferenceKey
asset.declareReferenceKey(assetType: string, key: string, refType: string | { string }, via: ("asset_ref" | "settings_of")?, field: string?)
Declare that, in a data file belonging to an assetType asset,
the top-level key names an asset of type ("*" for any type) — a
.material's mat.yaml naming the shader it draws with and the
textures it binds. The names a format holds are references as surely
as ones written in code: recording them carries a material's shader
along with the material into a pack or a pull, and turns a name nothing
answers to into an unresolved dependency instead of a surface that
renders as the magenta error material. A key holding a table of
names records one per entry; a { __ref = <guid> } envelope names its
guid. via is the provenance the file's .refs records: "asset_ref"
(default) for an asset the file uses, "settings_of" for the declarer
whose settings schema the file's values follow. A type states the keys
of its own files as content, in the references.keys of its
type.yaml, which every reference table reads from the moment the type
registers.
Parameters
assetTypestring— The category owning the file, e.g. "material".keystring— The top-level key holding the name(s).refTypestring | { string }via("asset_ref" | "settings_of")(optional) — "asset_ref" or "settings_of".fieldstring(optional) — The field at which each mapping entry the key holds names its asset; the entry's other fields name nothing.
asset.declareReferenceKey("material", "shader", "shader")
asset.declareReferenceKey("preset", "target", "*", "settings_of")
asset.declareReferenceKey("playlist", "tracks", { "audio", "midi" }, "asset_ref", "source")
typed/builtin//modules/api/engine/asset/asset/deprecation
asset.deprecation(ref: RefArg) -> Deprecation.Deprecation?
Whether an asset is deprecated, why, and what replaces it. An asset is
deprecated when its own .metadata carries "deprecated": { "reason": "<one line why>", "replacedBy": "<identity>" }, when a container holding
it at any depth does (a package, a toolbox, a folder asset), or when its
asset type does. A deprecated asset still resolves and loads by identity
and guid; search surfaces do not offer it, and resolving it warns once per
session.
Parameters
refRefArg— Asset handle, identity, guid or VFS path.
Returns Deprecation.Deprecation? — { reason, replacedBy, via, source }, where via is "asset", "container" or "type" and source is the folder holding the marker; nil when the asset is not deprecated.
local d = asset.deprecation("/zero/source/legacyFx.package/OldEmitter.component")
typed/builtin//modules/api/engine/asset/asset/deps
asset.deps(ref: RefArg, type: string?) -> DepsResult
Return the asset's outbound dependency graph — every other asset recorded as a content dependency of it.
Parameters
refRefArg— Any name the asset has.typestring(optional) — Category hint (optional).
Returns DepsResult — { deps = { { asset_guid, origin, literal, via, ... } }, worlds = { { world, name, commit, sites } }, unresolved_deps, problems }.
for _, d in asset.deps("main.scene").deps do print(d.asset_guid) end
typed/builtin//modules/api/engine/asset/asset/describe
asset.describe(typeName: string) -> DescribeResult
The creation contract for an asset type: the parameters its
onCreate(name, opts) hook accepts, as data. kind is "schema"
(typed contract), "legacy" (untyped opts — anything passes), "none"
(template scaffold — takes no opts), or "error" (the type's schema
failed to parse; error says why). contract is the human-readable
rendering validation errors print. frameworkParams and
frameworkContract carry the options asset.create consumes itself:
folder, into, dest, overwrite, durable, which every type
accepts and none declares.
Parameters
typeNamestring— Registered asset type to describe (e.g. "texture").
Returns DescribeResult — the creation contract.
local contract = asset.describe("texture").contract
typed/builtin//modules/api/engine/asset/asset/diagnose
asset.diagnose(ref: RefArg) -> any
Why one asset can or cannot be used, read from the engine rather than
from what the caller asked for. Always carries usable; when false,
reason is one of asset.unusableReasons() and detail is the engine's
own message. primary names the file the type's declared primary list
resolved to, the file a load of the asset reads. The
payload's bytes are read by the engine's own decoder wherever it has one
for that container, so usable is the verdict a load would reach and the
call costs that decode.
Parameters
refRefArg— Any name the asset has — handle, identity, guid, name or path.
Returns any — DiagnoseRecord
local d = asset.diagnose("myTex") if not d.usable then print(d.reason, d.detail) end
typed/builtin//modules/api/engine/asset/asset/exists
asset.exists(name: string, typeName: string) -> boolean
Parameters
namestringtypeNamestring
Returns boolean
typed/builtin//modules/api/engine/asset/asset/get_field
asset.get_field(ref: RefArg, key: string) -> any
Read one top-level field from the asset's .metadata.
Parameters
refRefArg— Any name the asset has.keystring— Field name.
Returns any — Field value or nil.
local author = asset.get_field("brick", "author")
local tags = asset.get_field("tree", "tags") -- → a Luau table
typed/builtin//modules/api/engine/asset/asset/gpuResident
asset.gpuResident(ref: RefArg) -> boolean
True when the device holds a texture or mesh under this asset's guid, read off the inventory the renderer publishes.
Parameters
refRefArg— Any name the asset has — handle, identity, guid, name or path.
Returns boolean — true when the device holds it.
print(asset.gpuResident("@builtin::models.Sample.DamagedHelmet"))
typed/builtin//modules/api/engine/asset/asset/guid
asset.guid(ref: RefArg, type: string?) -> string
Return the guid for an asset.
Parameters
refRefArg— Any name the asset has.typestring(optional) — Category hint (optional).
Returns string — Guid.
local g = asset.guid("@builtin::components.Camera")
typed/builtin//modules/api/engine/asset/asset/has_field
asset.has_field(ref: RefArg, key: string) -> boolean
True when the asset's .metadata carries the named field.
Parameters
refRefArg— Any name the asset has.keystring— Field name.
Returns boolean — True when present.
if asset.has_field("brick", "author") then end
typed/builtin//modules/api/engine/asset/asset/has_tag
asset.has_tag(ref: RefArg, tag: string) -> boolean
True when the asset's .metadata.tags contains tag.
Parameters
refRefArg— Any name the asset has.tagstring— Tag to check for.
Returns boolean — True when present.
if asset.has_tag("brick", "wip") then end
typed/builtin//modules/api/engine/asset/asset/identity
asset.identity(ref: RefArg, type: string?) -> string
Return the canonical identity for an asset.
Parameters
refRefArg— Any name the asset has.typestring(optional) — Category hint (optional).
Returns string — Canonical identity.
local id = asset.identity("brick")
typed/builtin//modules/api/engine/asset/asset/import
asset.import(path: string, opts: { importerSettings: { [string]: { [string]: any } }? }?) -> string?
Import a raw source file NOW and return the produced asset path
(a .bundle for a model, .texture for an image, .audio for a
sound, …), or nil if no importer claims it. While play runs and holds the
source where it stands (vfs.playHoldsInPlace), the import is owed: this
returns nil, the source's job in tools.use("importers", "status") reads
owed, and the import runs when play ends or pauses. This is the deterministic,
on-demand counterpart to the engine's automatic import-on-write: it runs
in the calling task and returns only when the import is complete. Pair it
with a quiet write — vfs.write(path, bytes, { quiet = true }) lands the
raw bytes without firing the automatic importer, then asset.import(path)
imports them under your control, so you can act on the result instead of
polling for the import to appear.
Parameters
pathstring— The raw source VFS path to import (e.g. a just-written.glb).opts{ importerSettings: { [string]: { [string]: any } }? }(optional) — Optional{ importerSettings = { <importer name> = { <setting> = value } } }: settings for this import only, laid over the claiming importer's own. A setting that importer does not declare is an error.
Returns string? — The produced asset path, or nil when nothing claimed it.
local bundle = asset.import("/zero/source/generated/chest.glb")
local bundle = asset.import("/zero/source/generated/chest.glb", { importerSettings = { model = { keepSource = false } } })
typed/builtin//modules/api/engine/asset/asset/inspect
asset.inspect(ref: RefArg, type: string?) -> InspectRecord
Everything known about one asset in a single record: identity, guid,
source, type, scope and origin, its description and tags, the ref methods
its type exposes, and the type's own inspect detail when it declares one.
The read-everything counterpart to asset.resolve, which hands back a ref.
Parameters
refRefArg— AnAssetRef, an identity string, or a path.typestring(optional) — Narrow the resolve to one asset type when assets of several categories answer to the same bare name.
Returns InspectRecord — The inspect record.
local rec = asset.inspect("@builtin::materials.default")
local rec = asset.inspect(name, "mesh"); print(rec.guid, #rec.tags)
typed/builtin//modules/api/engine/asset/asset/interface
asset.interface(ref: RefArg, category: string?) -> AssetInterface?
What the asset declares it takes and gives, read from its source
without running it: the interface its type's interface: block says its
sources declare (a .procNode declares one). description is what it
does; each of inputs carries its name, type, default, min, max,
options, optional and description as the declaration states them (a
vector default reads as { ["$vector"] = { x, y, z } }); each of
outputs its name and from, what makes it. program is the identity
a g:program("path") call at the top of a graph's builder names. problems lists each part
of the declaration that is not written as literals, which a push refuses.
The same data travels with the source's reference table to ZeroMind.
Parameters
refRefArg— Any name the asset has.categorystring(optional) — Category hint (optional).
Returns AssetInterface? — { form, id?, description?, program?, inputs, outputs, problems }, or nil when the asset's type declares no interface or its source hands no builder.
local iface = asset.interface("@builtin::systems.procgen.nodes.points.disc", "procNode")
typed/builtin//modules/api/engine/asset/asset/isPrivateSubasset
asset.isPrivateSubasset(path: string) -> boolean
Whether the asset at path is a private subasset: nested inside
another asset whose type does not broadcast its subassets — a .bundle's
interior meshes, materials and textures, an effect's own materials. A
private subasset is part of its parent: it is not listed, searched or
installed on its own, and it is excused from the files that describe an
asset. Whether nested assets are private is the enclosing asset's type's
to say: broadcasts_subassets: true in its type.yaml (a .package)
makes its members public, and an asset nested in no other asset is never
private. The same rule asset.list applies, where subassets = true is
what reaches private subassets.
Parameters
pathstring— The asset's VFS folder path.
Returns boolean — True for a private subasset; false for any other asset, and for a path that names no asset.
asset.isPrivateSubasset("/zero/source/models/tree.bundle/material/Bark.material") -- true
typed/builtin//modules/api/engine/asset/asset/list
asset.list(type_or_opts: (AssetCategory | ListOpts)?, scope: string?, opts: ListOpts?) -> ListResult
Query registered assets, returning each match as a resolved
AssetRef handle. Every filter narrows the same enumeration and
they compose: path selects a VFS subtree (the folder and
everything under it), type keeps only those asset types within
it, scope keeps only that scope, and fields keeps only assets
whose .metadata matches. type and path each take one value or
a list matching any of its entries, and all / any / none
group whole filters — none excludes what it matches. order,
limit, and offset shape the result: matches come back ordered
by identity unless order names another field
(name / path / type / guid).
subassets decides how deep the enumeration reaches into composite
assets. An enumeration returns the assets each container broadcasts,
which its type declares: a .package and a .toolbox broadcast
theirs, so their members are listed on their own, and a .bundle
keeps its interior meshes, materials and rigs to itself, so they are
reached through the bundle and a list of the folder holding it comes
back without them. subassets = true enumerates those private
interiors as well — what an asset is built out of, beside what the
world offers.
Each entry is the same envelope asset.resolve returns (__ref /
type / name / guid / identity / path), so it can be passed
anywhere an AssetRef is accepted, and the result carries
:first() / :random() / :filter() / :sort() and friends.
type takes the same values asset.categories() lists. The first
positional argument is a path when it is absolute, a type
otherwise. A type naming none of those values raises, naming it
and any near spelling, so an empty result means a type the engine
has. A type-group name stands for a family of those types rather
than naming one (model for glb/gltf/fbx/obj, and image,
text, config and script for theirs), so it lists whichever
members the engine carries, and raises naming them when it carries
none. An unknown key raises,
as does a table setting both type and its older spelling
category.
A static (literal) type or path makes the enumeration part of the
calling file's content dependencies when it is saved — the set
travels with published content, so consumers get at-least the
authoring world's assets.
Parameters
type_or_opts(AssetCategory | ListOpts)(optional) — Type or VFS path filter (a static literal so the enumeration can be captured for publish), or the full query table.scopestring(optional) — Scope filter (when first arg is a type).optsListOpts(optional) — The query table — seeListOpts.
Returns ListResult — The matched AssetRef handles, as a result carrying query methods.
local hero = asset.list({ path = "/zero/source/props", type = "mesh", fields = { tags = "hero" } }):first()
local parts = asset.list({ path = "/zero/source/models", type = "mesh", subassets = true }) -- a bundle's interior meshes too
local placeable = asset.list({ implements = "sceneInstantiable", path = "/zero/source/props" })
typed/builtin//modules/api/engine/asset/asset/listRevision
asset.listRevision() -> (number, number)
Two numbers that together move whenever what asset.list could answer
changes: an asset made, removed, moved or renamed, a name it answers to
added, a file created in or removed from an asset's folder (a new entity
in the open scene writes one), or the index rebuilt. Rewriting a file
that already exists leaves them still, and so does a write to a path no
asset can sit at. The copies play makes resident in the runtime-asset
layer move neither number. Hold the pair beside something derived from a
listing and list again only when either differs, so a per-frame reader
lists only on the frames where the answer can have changed.
Returns (number, number) — The index epoch and the generation within it.
local e, g = asset.listRevision() if e ~= held.e or g ~= held.g then held.list = asset.list("texture") end
typed/builtin//modules/api/engine/asset/asset/list_field_values
asset.list_field_values(key: string) -> { any }
Distinct values seen for the named field across every
asset's .metadata.
Parameters
keystring— Field name.
Returns { any } — Array of distinct values.
local authors = asset.list_field_values("author")
typed/builtin//modules/api/engine/asset/asset/list_fields
asset.list_fields() -> { string }
Distinct top-level field keys observed across every asset's
.metadata. Useful for tooling discovering custom keys in use.
Returns { string } — Array of field names.
for _, k in asset.list_fields() do print(k) end
typed/builtin//modules/api/engine/asset/asset/meta
asset.meta(ref: RefArg, type: string?) -> AssetMeta
Read the asset's engine-owned identity record (guid /
checksum). Distinct from .metadata (agent-editable);
for that use asset.metadata. An asset in the runtime asset store
(/zero/runtime/assets/, where a create made from a component or a
scene entrypoint lands) has a version too: its checksum is derived from
its bytes, and every edit is a new one.
Parameters
refRefArg— Any name the asset has.typestring(optional) — Category hint (optional).
Returns AssetMeta — Metadata table.
local m = asset.meta("brick") -- { guid = ..., checksum = ... }
typed/builtin//modules/api/engine/asset/asset/metadata
asset.metadata(ref: RefArg, type: string?) -> AssetMeta
Read the asset's agent-editable .metadata sidecar as a
Lua table. Missing sidecar returns {}. Distinct from
asset.meta (engine-owned).
Parameters
refRefArg— Any name the asset has.typestring(optional) — Category hint (optional).
Returns AssetMeta — JSON-shaped table; empty when no sidecar exists.
local md = asset.metadata("brick")
typed/builtin//modules/api/engine/asset/asset/observe
asset.observe() -> any
What the engine is holding for content right now, in one reading:
textures and meshes (one row per resource the device holds, each with
the bytes it costs, its dimensions or buffer split, and where it came
from), cpu (one row per asset a live script-component context holds),
offDevice (one row per mesh nothing displays, whose GPU buffers were
given back: held is "definition" when the engine keeps the mesh's
whole CPU definition and "source" when it keeps only the stored file
source it reads the mesh from again, and bytes is the CPU memory that
costs), and totals: the aggregates those rows sum to, so the listing
reconciles against renderer.textureMemory() and renderer.gpuMemory()
(offDeviceBytes sums the offDevice rows).
Each pool is named because they are different pools: an asset can be on
the device and not CPU-resident, or the reverse. devicePublished is
false when no renderer has published an inventory and cpuPublished when
the scripting VM has not published its pool — an engine that cannot answer
reads differently from one answering with nothing resident.
Returns any — ResidencyReading
local r = asset.observe() print(#r.textures, r.totals.textureBytes)
typed/builtin//modules/api/engine/asset/asset/pathHolding
asset.pathHolding(guid: string, checksum: string) -> string?
The VFS path holding the asset guid at exactly the version whose
content checksum is checksum (the pair asset.meta reports): the guid's
home when its bytes are that version, else a copy of that version held
beside it, such as an installed dependency's. Returns nil when this world
holds that asset at no such version.
Parameters
guidstring— The asset's guid.checksumstring— The content checksum of the version wanted.
Returns string? — The path holding that version, or nil.
local m = asset.meta(asset.resolve("@builtin::shaders.pbr", "shader")); local path = asset.pathHolding(m.guid, m.checksum)
typed/builtin//modules/api/engine/asset/asset/pending
asset.pending() -> { count: number, entries: { PendingReference } }
Every asset reference a component on this engine holds that no asset
answers yet. A reference arrives ahead of its bytes when a peer delivers a
component whose asset has not synced here, when the carried mount it
names is still filling, or when a scene applies before the content it
names. Each one applies by itself the moment its asset resolves: a
component waiting on it runs its awake() then, and a write held for a
component already running (held) lands then and reaches its
onPropertyChanged. state is pending, or refused when the carried
mount the reference names settled without its content; reason and
detail say why. A refused reference applies if a later mount of that
key brings the content. A reference inside a list or struct field waits
the same way at its place in the field (path, such as skins[2] or
look.skin), the field keeps every other value it holds, and the
reference applies in place. Every peer of a world holds and applies the
references it was delivered the same way.
Returns { count: number, entries: { PendingReference } } — { count, entries }: how many references wait, and one entry per reference naming the entity, the component (type, instance, instanceId), the field, where the reference sits in it (path: the field's name for its own value), the spec of the slot holding it, the reference, held, state, reason and detail.
local waiting = asset.pending()
if waiting.count > 0 then print(waiting.entries[1].reference, waiting.entries[1].state) end
repeat task.wait() until asset.pending().count == 0
typed/builtin//modules/api/engine/asset/asset/preview
asset.preview(ref: RefArg, opts: { [string]: any }?, type: string?) -> { [string]: any }
Render a preview of an asset. Resolves the ref and dispatches to its
type's preview ref-method when present; otherwise returns the
{ available = false } sentinel ("no preview available for this type").
Parameters
refRefArg— Any name the asset has.opts{ [string]: any }(optional) — Optional{ size = { width, height }, angle = { yaw, pitch } }.typestring(optional) — Category hint (optional).
Returns { [string]: any } — { available, imageBase64?, width?, height?, bounds?, stats?, reason? }.
local p = asset.preview("@builtin::materials.gold", { size = { width = 512, height = 512 } })
typed/builtin//modules/api/engine/asset/asset/primaryFile
asset.primaryFile(ref: RefArg) -> any
The file the asset type's declared primary list resolves to inside
this asset, as the loader itself resolves it. A *.<ext> entry resolves
the lowest-named file with that extension, and never the asset's
preview.png, the picture rendered from it. resolved is false when no
declaration matched and path is then absent; declared is the type's
own primary list in match order.
Parameters
refRefArg— Any name the asset has — handle, identity, guid, name or path.
Returns any — { path: string?, resolved: boolean, isFolder: boolean, declared: { string } }
print(asset.primaryFile("myTex").path)
typed/builtin//modules/api/engine/asset/asset/ref
asset.ref(ref: RefArg, type: string?) -> AssetRef
Build a reference handle for an asset — the canonical ref
envelope constructor. Identical shape to asset.resolve;
preferred name for the author-side use case (embedding refs in
YAML / JSON / Luau output).
Naming the asset here reads exactly as naming it in asset.resolve,
down to raising on a miss: a literal is recorded as this source's
dependency, a computed name is a dynamic resolve — free in a tool,
refused on the gameplay path. asset.exists(name, type) is the probe a
computed name can ask.
Parameters
refRefArg— The asset to reference — an identity, a guid, a VFS path, or a handle.typestring(optional) — Category hint (optional).
Returns AssetRef — Ref handle. Raises on a miss or ambiguity, as asset.resolve does.
local r = asset.ref("animations.idle", "animation")
typed/builtin//modules/api/engine/asset/asset/reloadPending
asset.reloadPending(ref: RefArg, typeName: string?) -> boolean
True while a write to this asset still owes it a reload — the write is inside the settle window that collects one authoring step's writes, or its reload is queued and the engine has not run it yet. False means every content change written so far has reached its subscribers, so a consumer bound to the asset now cannot be interrupted by a reload the earlier writes already earned. The recording is synchronous with the write, so a call made right after one already reads true.
Parameters
refRefArg— Any name the asset has — handle, identity, guid, name or path.typeNamestring(optional) — Category to restrict the match to. Omit to search every category.
Returns boolean — true while a content-change reload is still owed.
repeat task.wait() until not asset.reloadPending(ref)
typed/builtin//modules/api/engine/asset/asset/reloadSeq
asset.reloadSeq(ref: RefArg, typeName: string?) -> number
How many content-change reloads this asset has been through — the
count of onAssetReload dispatches the engine has RUN for it. A write to
a file inside an asset does not reload it on the spot: the writes of one
authoring step are collected for a settle window and the reload runs on a
later frame. Read this, write, then poll for a larger number to learn the
write's reload has actually reached subscribers. Monotonic per asset and
session-scoped; 0 for an asset whose content has not changed since boot.
Parameters
refRefArg— Any name the asset has — handle, identity, guid, name or path.typeNamestring(optional) — Category to restrict the match to. Omit to search every category.
Returns number — content-change reloads dispatched for this asset.
local at = asset.reloadSeq(ref)
vfs.write(asset.source(ref) .. "/graph.json", encoded)
repeat task.wait() until asset.reloadSeq(ref) > at
typed/builtin//modules/api/engine/asset/asset/remove_field
asset.remove_field(ref: RefArg, key: string)
Remove one top-level field from the asset's .metadata.
No-op when the field isn't present.
Parameters
refRefArg— Any name the asset has.keystring— Field name.
asset.remove_field("brick", "author")
typed/builtin//modules/api/engine/asset/asset/remove_tag
asset.remove_tag(ref: RefArg, tag: string)
Remove a tag from the asset's .metadata.tags. No-op when
the tag isn't present.
Parameters
refRefArg— Any name the asset has.tagstring— Tag to remove.
asset.remove_tag("brick", "wip")
typed/builtin//modules/api/engine/asset/asset/resolve
asset.resolve(ref: RefArg, type: (C & string)?) -> AssetRef<C>
Find an asset. The returned handle carries every name form
the asset has (guid, identity, path, type) so
downstream code can read any one of them without calling
resolve again. Raises when ref resolves to no asset — or, with a
type, to no asset of that type — and when ref reaches more than one
asset, where it names the candidates for you to pick from instead of
picking one of them. A <scope>::-qualified identity reaches exactly one:
@root::name for the asset this world holds at its source root, the
library identity (@builtin::…) for a library's. For the same lookup
answering a miss with nil, use asset.tryResolve(ref, type).
A name written as a string LITERAL is recorded as this source's
dependency on that asset, so the asset travels with the content and
still resolves once someone installs it in another world. A COMPUTED
name cannot be written down, so nothing pins what it reaches: that is a
dynamic resolve — free in a tool, refused on the gameplay path (a
component or scene entrypoint). asset.tryResolve, asset.ref and
asset.source read the name they are given exactly this way too, so
which of the four you reach for changes neither answer. To ask whether a
computed name has files without reaching a handle, use
asset.exists(name, type).
Parameters
refRefArg— The asset to find — an identity, a guid, a VFS path, or a handle.type(C & string)(optional) — Category to restrict the match to (optional). Separates a bare name that assets of different categories share (asset.resolve("cube", "mesh")); where several assets of the SAME category answer to it, the scope-qualified identity is what separates them. A reference naming a file an importer has since promoted (wall.pngafter the texture importer turned it intowall.texture) resolves to the promoted asset, and says so in the log once per reference.
Returns AssetRef<C> — Asset handle, carrying the category when one was named — so the methods that category defines are checked on the result. Raises (rather than returning nil) on a miss, and on a name that reaches more than one asset.
local a = asset.resolve("@builtin::components.Camera")
typed/builtin//modules/api/engine/asset/asset/rootKinds
asset.rootKinds() -> { string }
The kind of every asset folder that is a root of its contents (its category declares root: true; a package is
one too): a ~ written in a file inside such a folder names that folder. The same answer in every VM, the engine
thread's and each worker's.
Returns { string } — The kinds, without their leading dot.
local roots = asset.rootKinds() -- { "effect", ... }
typed/builtin//modules/api/engine/asset/asset/schema
asset.schema(ref: RefArg, values: { [string]: any }?) -> any?
The typed settings schema governing this asset — the Field
descriptors its type declares for every asset of that type, or the ones
the asset declares for itself. Each descriptor carries its kind, default,
constraint and description, so an editor renders it and an agent reads
what a setting takes without guessing. With values, the parameters the
asset takes for those values: an asset whose parameters follow from
content its values name adds those, and a composition hands each member
the values stated for it.
Parameters
refRefArg— The asset (ref, identity, guid or path).values{ [string]: any }(optional) — Optional values the parameters are read for.
Returns any? — The schema table, or nil when this asset carries no settings.
local schema = asset.schema(texRef); print(schema.filter.constraint.values)
typed/builtin//modules/api/engine/asset/asset/setSettings
asset.setSettings(ref: RefArg, patch: { [string]: any })
Write a partial settings patch. The patch is merged over the asset's
current values, the type's cross-field constraints are applied — a field
the patch does not name moves to the only value the rest allows (a
texture given a high-precision compression stops generating mipmaps), and a
field the patch names that cannot hold refuses the write, saying why —
and the result is checked against its schema; a violation refuses the
whole write, naming every problem, and leaves the asset on its last
valid settings. A valid write re-runs the type's onChange, which is
where the type re-cooks whatever the settings describe. Older field
names are accepted and stored under the current ones, and a field whose
default follows another moves with it when the write does not name it.
Parameters
refRefArg— The asset (ref, identity, guid or path).patch{ [string]: any }— Any subset of the schema's fields.
asset.setSettings(texRef, { filter = "nearest" })
typed/builtin//modules/api/engine/asset/asset/set_field
asset.set_field(ref: RefArg, key: string, value: any?)
Set one field in the asset's .metadata, creating the sidecar if missing.
Sibling fields are preserved. When the new value AND the existing value are
both maps (objects), the new value DEEP-MERGES into the existing one, so
writing one sub-key never drops the others — set_field(ref, "provenance", { bakedBy = "agent" }) keeps every other provenance key. Arrays and
scalars replace. Clear a whole field with asset.remove_field; replace
the entire sidecar with asset.set_metadata.
Parameters
refRefArg— Any name the asset has.keystring— Field name.valueany(optional) — Field value (any JSON-serialisable Lua value).
asset.set_field("brick", "author", "me")
asset.set_field("tree", "provenance", { bakedBy = "agent" }) -- merges; sibling keys kept
typed/builtin//modules/api/engine/asset/asset/set_metadata
asset.set_metadata(ref: RefArg, data: AssetMeta)
Replace the asset's .metadata sidecar with the given
table. Pass an empty table to clear all fields. A table that holds
itself, and one past what one read carries (16,384 values and 4 MiB
of text, a table held by several entries counted at each), is refused
and nothing is written.
Parameters
refRefArg— Any name the asset has.dataAssetMeta— Full JSON-shaped contents for the sidecar.
asset.set_metadata("brick", { author = "me", tags = { "wip" } })
typed/builtin//modules/api/engine/asset/asset/settings
asset.settings(ref: RefArg) -> any?
This asset's settings values, with every declared default filled in.
Parameters
refRefArg— The asset (ref, identity, guid or path).
Returns any? — The values table, or nil when this asset carries no settings.
if asset.settings(texRef).filter == "nearest" then ... end
typed/builtin//modules/api/engine/asset/asset/source
asset.source(ref: RefArg, type: string?) -> string
Return the VFS source path for an asset.
It reaches the asset, so the name carries the same reference contract
asset.resolve's does: a literal is recorded as this source's
dependency, a computed name is a dynamic resolve — free in a tool,
refused on the gameplay path. asset.exists(name, type) is the probe a
computed name can ask.
Parameters
refRefArg— Any name the asset has.typestring(optional) — Category hint (optional).
Returns string — VFS source path.
local p = asset.source("brick") -- "/source/brick.material"
typed/builtin//modules/api/engine/asset/asset/tags
asset.tags(ref: RefArg) -> { string }
Convenience read of the .metadata.tags array.
Parameters
refRefArg— Any name the asset has.
Returns { string } — Array of tag strings.
for _, t in asset.tags("brick") do print(t) end
typed/builtin//modules/api/engine/asset/asset/tryResolve
asset.tryResolve(ref: RefArg, type: string?, base: string?) -> AssetRef?
The same lookup asset.resolve performs, answering a miss with nil
instead of raising. Every name form, the same type narrowing, and the
same handle on success — so "use it if it is there" needs no pcall
around a call whose failure would otherwise be indistinguishable from a
real error.
This consults the asset REGISTRY, so it sees registered assets wherever
their files live, @builtin:: ones included. asset.exists(name, type)
answers the narrower question of whether an asset's files are present in
the current mode's store.
A name that reaches more than one asset of type (or more than one asset,
with no type) still raises: that is a question about the reference, and
a nil there would report absence for content that is present twice. A
name that only assets of other types answer to reaches no asset of type,
and answers nil.
It reaches the asset, so the name carries the same reference contract
asset.resolve's does: a literal is recorded as this source's
dependency, a computed name is a dynamic resolve — free in a tool,
refused on the gameplay path. asset.exists(name, type) is the probe a
computed name can ask.
Parameters
refRefArg— The asset to look up — an identity, a guid, a VFS path, or a handle.typestring(optional) — Category to restrict the match to (optional). A reference naming a file an importer has since promoted resolves to the promoted asset, the same asasset.resolve.basestring(optional) — Optional VFS path of the asset the reference is written in, or of its file: a data asset resolving the references it holds, such as a material resolving itsmat.yaml. A~/~.tailref expands against the root enclosing it, and a ref its.refsrecorded reaches the asset recorded there. Without it, both are read at the calling Luau source, asasset.resolvereads them.
Returns AssetRef? — Asset handle, or nil when the reference resolves to no asset.
local mat = asset.tryResolve(name, "material")
typed/builtin//modules/api/engine/asset/asset/typeRef
asset.typeRef(target: RefArg) -> string?
Return the pinned asset_type reference (the type's guid)
that the asset is an instance of. Resolve the full type with
asset.resolve(asset.typeRef(target)). Returns nil for loose
files / assets with no pinned type.
Parameters
targetRefArg— Asset handle / identity / guid / VFS path.
Returns string? — Pinned type's guid, or nil.
local t = asset.resolve(assert(asset.typeRef("brick")))
typed/builtin//modules/api/engine/asset/asset/unusableReasons
asset.unusableReasons() -> { string }
Every reason asset.diagnose can report an asset unusable for, sorted.
Returns { string } — Array of reason names.
for _, r in ipairs(asset.unusableReasons()) do print(r) end
typed/builtin//modules/api/engine/asset/asset/validate
asset.validate(ref: RefArg, type: string?) -> ValidateResult
Validate an asset folder against its type's type.yaml, plus
the type's own semantic validation. Structural problems come from
type.yaml — missing required files, unsatisfied one_of_group
alternatives, and (when allow_unlisted: false) unexpected
children. validated = false when no type.yaml is registered
— nothing structural to check. On top of that, when the asset's
type ships a behavior.luau exporting a top-level
validate(assetRef) -> { { code, message, severity?, remedy?, publishRequirement? } }, its
reported problems (severity defaults to "error"; remedy names the
action that resolves the problem) are appended to
problems; error-severity problems flip ok to false, warnings
leave it untouched. A hook that raises or returns a non-table is
itself reported as a validate.hook_failed error problem — a
broken hook blocks. A type with no validate export behaves
exactly as the structural check alone.
world.push calls this per user asset, so a type's semantic
validation is enforced at publish time with no further wiring.
Parameters
refRefArg— Any name the asset has.typestring(optional) — Category hint (optional).
Returns ValidateResult — { ok, typeName, validated, problems }.
local v = asset.validate("@builtin::components.Camera")
typed/builtin//modules/api/engine/asset/asset/warmup
asset.warmup(ref: RefArg, opts: WarmupOpts?) -> WarmupResult
Warm an asset's bytes into CPU memory and follow its declared
content dependencies to each referenced asset, deduped by
guid. Type-agnostic (reads the generic ref graph) and CPU-only —
never touches the GPU. Side-effect-free name resolution (uses
asset.guid/asset.deps, not asset.resolve).
Parameters
refRefArg— Any name the root asset has — handle, identity, guid, or path.optsWarmupOpts(optional) — Optional{ vias, max }— restrict ref-edge kinds / cap closure size.
Returns WarmupResult — { closure, count } — the deduped guid closure warmed and its size.
local w = asset.warmup("@builtin::scenes.test_arena")
typed/builtin//modules/api/engine/audio/AudioStream/close
AudioStream.close(self) -> boolean
Close the stream and take its audio source off the entity.
Parameters
self
Returns boolean
typed/builtin//modules/api/engine/audio/AudioStream/entity
AudioStream.entity -> string
The entity whose voice plays the stream.
Returns string
typed/builtin//modules/api/engine/audio/AudioStream/flush
AudioStream.flush(self) -> boolean
Drop every queued frame.
Parameters
self
Returns boolean
typed/builtin//modules/api/engine/audio/AudioStream/id
AudioStream.id -> number
The stream's id, which its entity's audio source names in stream.
Returns number
typed/builtin//modules/api/engine/audio/AudioStream/pause
AudioStream.pause(self) -> ()
Pause the stream's voice.
Parameters
self
Returns ()
typed/builtin//modules/api/engine/audio/AudioStream/play
AudioStream.play(self) -> ()
Start or resume the stream's voice.
Parameters
self
Returns ()
typed/builtin//modules/api/engine/audio/AudioStream/push
AudioStream.push(self, pcm: any, frames: number?) -> (number?, string?)
Queue interleaved samples; returns the frames taken.
Parameters
selfpcmanyframesnumber(optional)
Returns (number?, string?)
typed/builtin//modules/api/engine/audio/AudioStream/set
AudioStream.set(self, settings: { [string]: any }) -> ()
Change the stream's voice settings.
Parameters
selfsettings{ [string]: any }
Returns ()
typed/builtin//modules/api/engine/audio/AudioStream/status
AudioStream.status(self) -> AudioStreamStatus?
Where the stream stands, or nil once it is closed.
Parameters
self
Returns AudioStreamStatus?
typed/builtin//modules/api/engine/audio/AudioStream/wanted
AudioStream.wanted(self) -> number
Frames that bring the queue up to the stream's latency.
Parameters
self
Returns number
typed/builtin//modules/api/engine/audio/audio/decode
audio.decode(zaud: buffer | string) -> (string?, number?, number?)
Decode a ZAUD payload into interleaved f32 PCM. A PCM payload comes
back as the frames its header accounts for, held to the whole frames the
bytes behind it fill, so the sample count is always a whole number of
channels and a consumer walking it channels at a time ends on a frame.
Parameters
zaudbuffer | string— A ZAUD payload — a buffer or a binary string.
Returns (string?, number?, number?) — (pcm, sampleRate, channels), or (nil, err).
typed/builtin//modules/api/engine/audio/audio/device
audio.device() -> AudioDeviceStatus
What the engine's audio output is doing: state is "open" while a
stream is running on an output device and "silent" while none is, and
device names the device an open stream runs on. The counters record
what the engine has been through keeping one open — faults a live
stream reported, changes of the host's default output, reopens the
engine made, failedOpens the platform refused, and the glitches a
listener heard as dropouts, with lastError carrying what the platform
said. A device that goes away leaves the mixer running and the engine
opening a stream again as soon as one is there. parked is true while
nothing plays: the output stream is paused and the mixer renders nothing,
so the device rests, and the first sound started resumes it, reading
false once its first period plays; parks counts the times it parked and
resumeLatencyMs is how long the last resume took to play its first
period. held names what the platform holds the output quiet for while
the mixer still has sound: "background" while nothing of the app is on
screen, "focusLost" while another app holds the platform's audio focus
(a call, a voice assistant, another player). A held output is parked and
every voice waits where it is, going on from there once nothing holds it.
outputLatencyMs is how long after the mixer renders a period it is
heard, as the platform's timestamps state it, and performanceMode the
latency mode the platform runs the stream in where it states one
("lowLatency", "powerSaving" or "none", on Android).
Returns AudioDeviceStatus — An AudioDeviceStatus.
local d = audio.device(); print(d.state, d.device, d.reopens)
typed/builtin//modules/api/engine/audio/audio/encode
audio.encode(sourceBytes: buffer | string, opts: { [string]: any }?) -> (string?, string?)
Encode container audio bytes (ogg / mp3 / wav / flac) into a ZAUD
payload. Every decoded sample must be finite; a source whose samples carry
a NaN or an infinity comes back as (nil, err) naming how many fail and
where the first one sits.
Parameters
sourceBytesbuffer | string— Encoded source audio bytes — a buffer or a binary string.opts{ [string]: any }(optional) —{ codec: "opus"|"pcm"?, bitrateKbps: number?, vbr: boolean?, sampleRate: number?, forceMono: boolean?, loopStart: number?, loopEnd: number? }
Returns (string?, string?) — The ZAUD bytes, or (nil, err).
local zaud = audio.encode(oggBytes, { bitrateKbps = 96 })
typed/builtin//modules/api/engine/audio/audio/encodePcm
audio.encodePcm(pcm: any?, sampleRate: number, channels: number, opts: { [string]: any }?) -> (string?, string?)
Encode raw interleaved f32 PCM into a ZAUD payload. Every sample must
be finite; a buffer carrying a NaN or an infinity comes back as
(nil, err) naming how many fail and where the first one sits, so a
filter that diverged over part of a bake is caught before it is written.
The sample count is a whole number of channels: a buffer with a tail
over comes back as (nil, err) naming the whole frames it holds and the
samples past them.
Parameters
pcmany(optional) — Interleaved f32 samples — a buffer or a binary string of little-endian f32, the shapemicrophone.samplesandaudio.decodehand back, or a flat number array. A byte payload's samples are its 4-byte lanes, and a length that stops partway through one comes back as(nil, err)naming the whole samples it holds and the bytes past them.sampleRatenumber— Source sample rate in Hz.channelsnumber— 1 or 2, and a divisor of the sample count.opts{ [string]: any }(optional) — Same shape asaudio.encode.
Returns (string?, string?) — The ZAUD bytes, or (nil, err).
local s = microphone.status(); local zaud = audio.encodePcm(microphone.samples(), s.sampleRate, 1)
typed/builtin//modules/api/engine/audio/audio/encodeWav
audio.encodeWav(pcm: any?, sampleRate: number, channels: number, opts: { [string]: any }?) -> (string?, string?)
Write raw interleaved f32 PCM as a 16-bit PCM WAV file: the container
speech-to-text and other audio services upstream read. Samples are
clamped to [-1, 1]. Every sample must be finite and the sample count a
whole number of channels, or it comes back as (nil, err) naming what
is wrong.
Parameters
pcmany(optional) — Interleaved f32 samples, in the formsaudio.encodePcmtakes — the buffermicrophone.sampleshands back included.sampleRatenumber— Source sample rate in Hz.channelsnumber— 1 or 2.opts{ [string]: any }(optional) —{ sampleRate?, forceMono? }:sampleRateresamples first (16000 is what speech recognisers read);forceMonodownmixes stereo.
Returns (string?, string?) — The WAV file's bytes, or (nil, err).
local s = microphone.status(); local wav = audio.encodeWav(microphone.samples(), s.sampleRate, 1, { sampleRate = 16000 })
typed/builtin//modules/api/engine/audio/audio/info
audio.info(zaud: buffer | string) -> (AudioInfo?, string?)
Read a ZAUD payload's header. A PCM payload's samples are its bytes, and
the header is read against them: a sample count differing from
frames * channels comes back as (nil, err) naming both counts, and a
sample carrying a NaN or an infinity comes back as (nil, err) naming how
many fail and where the first one sits, so the header handed back describes
a clip that is as long as it says and can sound. The header describes the
clip's shape — rate, channels, frames, duration, codec, loop points. What
the samples do where a whole-clip loop wraps is a reading of its own,
audio.loopSeam, which is the call that answers whether a bed cycles
without a click.
Parameters
zaudbuffer | string— A ZAUD payload — a buffer or a binary string.
Returns (AudioInfo?, string?) — An AudioInfo table, or (nil, err).
local info = audio.info(zaud); print(info.durationMs)
typed/builtin//modules/api/engine/audio/audio/levels
audio.levels() -> AudioLevels
The master mix's peak and RMS over the meter's most recent closed window, measured without recording anything.
Returns AudioLevels — An AudioLevels.
local l = audio.levels(); print(l.peak, l.rms, l.windowMs)
typed/builtin//modules/api/engine/audio/audio/listener
audio.listener() -> AudioListenerState
Where the scene is heard from, how many active listeners exist, and which entity's listener drives the ears.
Returns AudioListenerState — An AudioListenerState.
local l = audio.listener(); print(l.present, l.count, l.entity)
typed/builtin//modules/api/engine/audio/audio/loopSeam
audio.loopSeam(zaud: buffer | string) -> (AudioLoopSeam?, string?)
Measure what a clip's samples do where a whole-clip loop wraps, so a bed
can be judged before anyone hears it tick. The wrap's own step
(|x[1] - x[frames]|) is reported against the step the signal ordinarily
makes between neighbouring samples, as ratio = step / meanStep — a figure
in the units the signal itself moves in, so a quiet ambience and a loud
drone are read the same way. A bed whose partials wrap reads near 1; one
carrying a strike at its head and silence at its tail reads in the tens.
ratio and the step / meanStep / maxStep beside it belong to the
worst channel, channel names it, and channels carries every channel's
own reading. seamless is ratio <= threshold, the same threshold
asset.create("soundClip", ...) warns past. The reading is taken on the
DECODED samples, so it answers for what the codec left behind and for a
clip that arrived already encoded and whose source buffer nobody holds.
Costs a decode of the whole payload; audio.info reads a header without
one.
Parameters
zaudbuffer | string— A ZAUD payload — a buffer or a binary string.
Returns (AudioLoopSeam?, string?) — An AudioLoopSeam table, or (nil, err).
local seam = audio.loopSeam(clipRef:getBytes()); print(seam.ratio, seam.seamless)
typed/builtin//modules/api/engine/audio/audio/mixer
audio.mixer() -> AudioMixerLevels
The levels the mixer is applying to the mix right now: the master
level, whether the mix is muted, and the level of every channel one has
been set on. A channel absent from channels plays at unity, so a
source naming it is heard at the volume it asks for.
Returns AudioMixerLevels — An AudioMixerLevels.
local m = audio.mixer(); print(m.master, m.muted, m.channels.music)
typed/builtin//modules/api/engine/audio/audio/observe
audio.observe() -> AudioObservation
Report what the mixer is making audible right now, and why a source is not. One read covering every live voice with the mixer's own playback state and effective gain, the master mix's level, the mixer's voice accounting, the listener, the output device the mix is reaching, and what the subsystem costs. Answers in edit mode as well as play mode.
Returns AudioObservation — An AudioObservation.
local a = audio.observe(); print(a.audibleCount, a.levels.rms)
for _, v in audio.observe().voices do print(v.entity, v.mixerState, v.silence) end
typed/builtin//modules/api/engine/audio/audio/peakSince
audio.peakSince(window: number) -> number?
The loudest peak the master mix reached across the meter's windows
that closed after its windows count stood at window. audio.levels()
carries the window that closed last, so a reader sees the windows its own
frames happen to land on; this spans all of them, which is what measuring
a sound shorter than the gap between two reads takes. Take the mark from
audio.levels().windows before the sound starts, wait until windows has
advanced past the sound's length, then read the span.
Parameters
windownumber— Awindowscount taken fromaudio.levels()earlier.
Returns number? — The loudest window peak in the span, or nil when the meter holds no peak for it — nothing has closed since window, or the span reaches further back than the meter's history of recent windows, so a reader that came back too late learns that instead of reading the maximum of the part that survived.
local mark = audio.levels().windows
local peak = audio.peakSince(mark)
typed/builtin//modules/api/engine/audio/audio/peaks
audio.peaks(zaud: buffer | string, buckets: number) -> ({ number }?, string?)
The loudest sample in each of buckets equal spans of a clip, across
its channels, as an absolute value held to 1: the shape a waveform is
drawn from. A span is frames // buckets frames (at least one), and the
frames past buckets * span fall in no bucket; a clip shorter than
buckets frames fills one bucket per frame and leaves the rest at 0. The
payload is decoded a block at a time, so the work never holds the clip's
whole PCM, however long it runs.
Parameters
zaudbuffer | string— A ZAUD payload — a buffer or a binary string.bucketsnumber— How many spans to divide the clip into: an integer from 1 to 4096.
Returns ({ number }?, string?) — One peak per bucket, or (nil, err).
local bars = audio.peaks(clipRef:getBytes(), 96)
typed/builtin//modules/api/engine/audio/audio/profile
audio.profile() -> AudioProfile
What the audio subsystem has cost since the profiling window opened —
the streaming pump (topping up the rings of the streamed clips, which the
audio output does on its own clock, frames or none), clip decode, clip
encode, voice starts, and building the observation itself. Every total is
a SUM across that window rather than a per-frame figure, and the window
runs from the last audio.resetProfile() or from engine start. For what a
frame costs now, reset, let frames pass, then divide the frame-bound
stages by the frames the window reports; the pump's total over the
window's windowMs is what streaming costs per second.
Returns AudioProfile — An AudioProfile.
audio.resetProfile(); task.wait(1); local p = audio.profile()
print("per frame:", p.observe.totalMs / p.frames, "pump per second:", p.pump.totalMs / (p.windowMs / 1000))
typed/builtin//modules/api/engine/audio/audio/resetProfile
audio.resetProfile()
Open a new audio profiling window, discarding what the previous one
measured. Call this before timing a stretch of frames: without it
audio.profile() reports totals reaching back to engine start.
audio.resetProfile()
typed/builtin//modules/api/engine/audio/audio/setChannelVolume
audio.setChannelVolume(channel: string, volume: number)
Set the level of one mixer channel — the channel an Audio
component names, such as "sfx", "music" or "ambient", or any name the
scene invents. It scales every voice on that channel and nothing else,
reaches voices that are already playing, and comes back per voice as
gain.channel. A channel no level has been set on plays at unity.
Parameters
channelstring— The channel name, matchingAudio.channel.volumenumber— Channel level, 0..1.
audio.setChannelVolume("music", 0.3)
for _, v in audio.voices() do print(v.channel, v.gain.channel) end
typed/builtin//modules/api/engine/audio/audio/setMasterVolume
audio.setMasterVolume(volume: number)
Set the master level of the mix, on the engine's 0..1 amplitude
scale. It scales every voice whatever channel it plays on, reaches
voices that are already playing, and comes back per voice as
gain.master.
Parameters
volumenumber— Master level, 0..1.
audio.setMasterVolume(0.5)
typed/builtin//modules/api/engine/audio/audio/setMuted
audio.setMuted(muted: boolean)
Silence or unsilence the whole mix. A muted mix sounds nothing
whatever its master and channel levels read, every voice reports
masterSilent, and unmuting hands the levels back untouched.
Parameters
mutedboolean— Whether the mix is silenced.
audio.setMuted(true)
typed/builtin//modules/api/engine/audio/audio/stream
audio.stream(entity: any?, options: AudioStreamOptions?) -> (AudioStream?, string?)
Play PCM a script produces while it sounds — synthesis, an emulator's
sound chip, procedural engine or wind noise, decoded voice — through the
voice of entity. Opens a stream at the options' sample rate and
channels and puts an audio source on the entity that plays it, so the
voice is placed, attenuated and Doppler shifted when spatial, follows
pitchValue / volumeValue, and is levelled by its channel and the
master mix like every other source. Push samples each frame with
stream:push, as many as stream:wanted() asks for, and the stream
stays latencyMs ahead of the mixer, further on a host whose frames run
long; a frame longer than the audio queued runs it dry, which
stream:status().underruns counts. Frames pushed before the voice starts
are the first it plays, and a stream not yet fed counts no underrun. Any sample
rate from 4000 to 192000 Hz plays at its own pitch. The entity carries
one voice: one already carrying an audio source is refused. The stream
lives while the entity's audio source names it: removing the source,
despawning the entity, putting another source in its place or rewriting
the source's stream field closes it.
Parameters
entityany(optional) — The entity whose voice plays the stream: a proxy or its id.optionsAudioStreamOptions(optional) — AnAudioStreamOptions, every field optional. The PCM:sampleRate(4000 to 192000 Hz, default the mixer's rate),channels(1, the default, or 2 interleaved left then right),format("f32", the default, or "i16": how a pushed buffer or string is read),latencyMs(the least audio kept queued ahead of the mixer, default 100),bufferMs(the most the ring holds, default four timeslatencyMsand at least 500). The voice, as anAudiocomponent carries it:volume,pitch,spatial,maxDistance,rolloff,doppler,channel,sourceType,pitchValue,volumeValue, andautoplay(default true).
Returns (AudioStream?, string?) — An AudioStream, or (nil, err).
local synth = audio.stream(e, { sampleRate = 22050, channels = 2, latencyMs = 80, spatial = true })
local n = s:wanted(); for i = 0, n - 1 do buffer.writef32(buf, i * 4, math.sin(phase)); phase += step end; s:push(buf, n)
typed/builtin//modules/api/engine/audio/audio/voice
audio.voice(entityId: string) -> AudioVoice?
The voice on one entity, or nil when that entity carries no audio
source. An entity despawned since the frame the observation describes
answers with its report from that frame, so an onDestroyed handler reads
how the entity's voice stood as it went.
Parameters
entityIdstring— The entity's stable id.
Returns AudioVoice? — An AudioVoice, or nil.
local v = audio.voice(e.id); print(v and v.mixerState)
typed/builtin//modules/api/engine/audio/audio/voiceAccounting
audio.voiceAccounting() -> AudioVoiceAccounting
How many voices the mixer can hold, how many are in use, how many
are free — read off the mixer's own tracks, so the free count is the one
a play call is granted or refused against. The two pools are reported
apart: capacity / inUse / free are the main track, which carries
the NON-spatial voices, while a spatial voice plays through its own
sub-track and is counted by spatialInUse instead. sourcesHolding
counts both pools from the sources that own them, so it equals
inUse + spatialInUse while every voice answers to a source.
Returns AudioVoiceAccounting — An AudioVoiceAccounting.
local v = audio.voiceAccounting(); print(v.inUse .. "/" .. v.capacity)
local v = audio.voiceAccounting(); print(v.sourcesHolding - (v.inUse + v.spatialInUse))
typed/builtin//modules/api/engine/audio/audio/voices
audio.voices() -> { AudioVoice }
Every live audio source with the mixer's opinion of it.
Returns { AudioVoice } — An array of AudioVoice.
for _, v in audio.voices() do print(v.clip, v.gain.effective) end
typed/builtin//modules/api/engine/audio/audio/whySilent
audio.whySilent(entityId: string) -> (string?, string?)
Why the source on an entity is making no sound. Returns nil when it
IS sounding, and one of noBackend, noDevice, notResident, neverStarted,
refused, paused, ended, gainZero, channelSilent,
masterSilent, outOfRange when it is not — the nearest cause, so the
answer names the thing to change. A second
return carries the mixer's own words when it refused the source, and
"no audio source on this entity" when nothing there plays at all.
Parameters
entityIdstring— The entity's stable id.
Returns (string?, string?) — (reason, detail).
local why = audio.whySilent(e.id); if why then print(why) end
typed/builtin//modules/api/engine/audio/audiostream_close
audiostream_close(self: AudioStream) -> boolean
Close the stream: its voice falls silent and the entity's audio
source comes off. Despawning the entity, removing its audio source,
putting another audio source in its place or rewriting the source's
stream field closes the stream the same way.
Parameters
selfAudioStream— The streamaudio.streamreturned.
Returns boolean — Whether the stream was open.
s:close()
typed/builtin//modules/api/engine/audio/audiostream_flush
audiostream_flush(self: AudioStream) -> boolean
Drop every frame queued on the stream, on the mixer's next buffer.
Parameters
selfAudioStream— The streamaudio.streamreturned.
Returns boolean — false once the stream is closed.
s:flush()
typed/builtin//modules/api/engine/audio/audiostream_pause
audiostream_pause(self: AudioStream)
Pause the stream's voice. The queue holds what it has, and wanted()
stays at 0 while it is full.
Parameters
selfAudioStream— The streamaudio.streamreturned.
s:pause()
typed/builtin//modules/api/engine/audio/audiostream_play
audiostream_play(self: AudioStream)
Start or resume the stream's voice. A voice started after an earlier one ended reads a fresh, empty queue.
Parameters
selfAudioStream— The streamaudio.streamreturned.
s:play()
typed/builtin//modules/api/engine/audio/audiostream_push
audiostream_push(self: AudioStream, pcm: any?, frames: number?) -> (number?, string?)
Queue interleaved samples on the stream. pcm is a buffer or a
string holding samples in the stream's format, or an array of numbers;
frames takes only that many frames from its start, so one buffer can be
reused frame after frame. Every sample must be finite and the samples a
whole number of frames.
Parameters
selfAudioStream— The streamaudio.streamreturned.pcmany(optional) — A buffer or string of samples, or an array of numbers.framesnumber(optional) — How many frames from the start ofpcmto push; all of them when omitted.
Returns (number?, string?) — The frames the stream took, fewer than handed over when its ring is full, or (nil, err) for a closed stream or samples it cannot read.
local n = s:wanted(); fill(buf, n); s:push(buf, n)
typed/builtin//modules/api/engine/audio/audiostream_set
audiostream_set(self: AudioStream, settings: { [string]: any })
Change the stream's voice: any of volume, pitch, spatial,
maxDistance, rolloff, doppler, channel, sourceType, pitchValue and
volumeValue, as an Audio component carries them. A voice already
sounding takes the change on the next frame, except spatial, which a
voice takes as it starts: placed and attenuated, or played unplaced.
Parameters
selfAudioStream— The streamaudio.streamreturned.settings{ [string]: any }— The settings to change.
s:set({ pitch = 1.2, volume = 0.5 })
typed/builtin//modules/api/engine/audio/audiostream_status
audiostream_status(self: AudioStream) -> AudioStreamStatus?
Where the stream stands, nil once it is closed: sampleRate,
channels, format; queuedFrames and queuedMs (what is queued and
how far ahead of the mixer that is); capacityFrames; targetFrames
(the queue it asks for) and producerGapMs (the longest recent gap
between pushes behind it); wantedFrames; framesPushed,
framesRefused (frames the full ring could not take) and
framesPlayed; underruns (times it ran dry while it played) and
starvedFrames (the silence played in their place); voice
("waiting", "playing", "paused" or "ended"); rate (the rate the mixer
reads it at, pitch times Doppler).
Parameters
selfAudioStream— The streamaudio.streamreturned.
Returns AudioStreamStatus? — An AudioStreamStatus, or nil.
local st = s:status(); print(st.queuedMs, st.underruns)
typed/builtin//modules/api/engine/audio/audiostream_wanted
audiostream_wanted(self: AudioStream) -> number
How many frames to push now to bring the queue up to its target: the stream's latency, or one and a half times the longest recent gap between pushes when that is longer. Push this many every frame and the stream stays fed through frames as long as the ones before them. 0 once the stream is closed.
Parameters
selfAudioStream— The streamaudio.streamreturned.
Returns number — Frames wanted.
local n = s:wanted()
typed/builtin//modules/api/engine/av/av/capabilities
av.capabilities() -> AvCapabilities
Report what this engine's encoder records, before a take asks for
it. backend and codecs are av.status()'s. hdr.transfers lists the
HDR transfers a take is coded in, "hlg" (the default) then "pq", and
hdr.codecs the codecs a 10-bit BT.2100 take is encoded through, the
default first. On an encoder that records no HDR both are empty and
hdr.reason names why (an 8-bit-only backend, a driver with no 10-bit
encode entrypoint, a platform whose encoder records SDR on this engine);
av.record refuses an HDR take with that reason.
Returns AvCapabilities — What the encoder records.
local caps = av.capabilities(); print(#caps.hdr.transfers, caps.hdr.reason)
typed/builtin//modules/api/engine/av/av/is_live
av.is_live() -> boolean
True if a live-stream session is currently active.
Returns boolean — Whether the live encoder is running.
if av.is_live() then av.stop_live() end
typed/builtin//modules/api/engine/av/av/is_recording
av.is_recording() -> boolean
True if a recording session is currently active.
Returns boolean — Whether a recording is in progress.
print("recording:", av.is_recording())
typed/builtin//modules/api/engine/av/av/live
av.live(opts: LiveOpts?) -> (string?, string?)
Start the live-stream encoder. The stream is served at
/engine/live.stream and reverse-proxied at
/stream/<instance>/live.stream as a binary length-prefixed
protocol consumed by the multiviewer UI's WebCodecs decoder. A
browser engine encodes it with the browser's WebCodecs encoder, and
the proxy reads it over the ZeroMind bridge and serves it at the
same /stream/<instance>/live.stream. When texture_handle is set,
the encoder reads from that GPU texture's guid (a Camera pointed at
it via setTargetTexture) instead of the scene's viewport: that's
how spectator cameras work. The stream carries the texture as its
camera wrote it, so a spectator camera whose stream carries the
all-layer effects the screen shows states
textureColorSpace = "presented". A stream runs beside an av.record
take. Returns the stream URL once the encoder is open and
streaming, or nil and the reason it is not: no encoder on this
engine that streams H.264, a stream already running, an odd
dimension, a session the encoder refuses (a size it will not
encode, a spectator texture with no size to stream at). The engine
opens the encoder, so the call waits for it: run it where it can
yield, wrapping it in task.spawn from a callback that cannot. The
reason also stands on av.status().liveError, which is where a
stream that ends on a failure later says why.
Parameters
optsLiveOpts(optional) — Encoder options.
Returns (string?, string?) — Stream URL, or nil. Why the stream was refused, when it was.
local url, why = av.live({ width = 1280, height = 720, fps = 60 })
typed/builtin//modules/api/engine/av/av/record
av.record(path: string, opts: RecordOpts?) -> (string?, string?, Durability?)
Start recording the engine output to a VFS path. For a clip of the
scene or the editor with no options to choose, zero recording start (and
F9 in the editor) wraps this call and names the take by the time. Default dir
is /zero/source/local/recordings/ when path is not absolute: that
directory is this machine's own content, writable in every mode, kept
across restarts and outside the world's sync, so a take named relative
to it is read back with vfs.read in this session and the next. A take
is written to disk as it records and read from disk, so it holds no
engine memory. A destination under /zero/source/ is
world content, which the world's sync uploads when the take is
filed. The
take runs until av.stop_recording() unless opts bounds it
with max_duration_sec (seconds of the take's own clock) or
frames (captured frames); max_duration_sec wins when both are
given, and the bound in force reads back as
av.status().recordingBound. With
no chroma/range opts the format defaults to full-range 4:4:4
HEVC where the GPU supports it, else 4:2:0. In the browser the
browser's WebCodecs encoder converts the picture itself, so the take
is 4:2:0 in the code range that encoder chooses, which an H.264 or
AV1 file states, and grain above 0, chroma = "444" and any stated range
are refused by name, and the master mix is encoded by the
browser's WebCodecs AudioEncoder. On the "software"
backend the take is H.264 encoded on the CPU, which costs the run
it records: read av.status().recordingAchievedFps against
recordingRequestedFps to see the rate it reached. What the take
did with the master mix reads back as
av.status().recordingAudio. cadence picks the clock the take
stamps its frames from. "realtime" (the default) stamps each
frame with the wall-clock slot it was captured in, so a recorded
session is watched back at the speed it happened and an engine
ticking under fps leaves slots empty. "frame" stamps every
rendered frame one fixed slot after the last, so a timeline whose
own clock advances a step per rendered frame — a cutscene, a
scripted demo, anything on a fixed timestep — is delivered at the
length that timeline runs to, however slowly the engine drew it: a
take of frames = n at fps is n / fps seconds of film, and a
max_duration_sec bound counts that film's seconds. A "frame"
take carries no master mix, because the mix plays in wall-clock
seconds and cannot share a file with a fixed-step picture;
recordingAudio says so, and an explicit audio = true beside it
is refused. audioTrack is the way a take of either cadence carries
sound: the VFS path of an audio file (wav, ogg, mp3 or flac) the take
writes as its Opus track in place of the master mix. The file's first
sample sits at the first frame, the track ends where the film does
(a longer file is cut, a shorter one ends early), and on "frame" the
track advances with the film's own clock, so a pre-mixed soundtrack lines
up with a fixed-step picture however slowly the engine drew it. The file
is read and decoded away from the engine thread; a file that cannot be
read or decoded, or runs past fifteen minutes, ends the take with the
reason on av.status().recordingError. recordingAudio reads
"opus: <path>" for such a take. quality runs 1 to 100: the default
of 75 is the recording quality, and 100 is the near-lossless picture a
master is cut from, at several times the default's bitrate.
camera names the camera the take draws its film from — an entity
proxy, an entity id, or an entity name. That camera holds the viewport
for as long as the take runs, above the priority contest and above
camera.setEditorOverride, so the film is its view and the frames
carry everything the presented frame carries. Only frames that camera
drew go into the film, and a camera that never draws the viewport ends
the take with the reason on av.status().recordingError — so a take is
the view it named or it is no take. The camera belongs to the take:
nothing is written to it, and the viewport is back under its own
contest the moment the take ends. It reads back as
av.status().recordingCamera while the take runs. Omitted, the take
records whichever camera holds the viewport, which in an engine on the
editor profile is the editor's own fly camera rather than the scene's.
renderLayers is the render-layer include spec the viewport is
drawn under for as long as the take runs — the same token string a
capture takes: all seeds every layer, name adds one and !name
drops one, so "all !EditorUI !debug" films the scene without the
editor's chrome or the authoring overlays (gizmos, light and probe
icons, frustums, collider wireframes) over it, and
"all !ui !EditorUI !debug" drops the authored HUD as well. The
viewport admits geometry and screens by that one spec, so it states
the whole picture. It belongs to the take: nothing is written to the
camera it is stated against, and the moment the take ends — its
bound reached, stopped, or refused — the viewport is back under the
camera's own spec. While a take states layers, the window shows what
the film holds, and av.status().recordingLayers reads the spec
back. Omitted, the take records the engine output as presented.
hdr records the take in HDR: true or "hlg" records 10-bit HLG
(ARIB STD-B67), "pq" 10-bit PQ (SMPTE ST 2084), both BT.2020 colour,
4:2:0 and limited range unless range names full; false or nil records
SDR as every other take. An HDR take holds the HDR picture whatever the
display shows: while it records, every frame is drawn into a float picture
whose highlights reach the take's peak, and an SDR window shows that
picture with its highlights clipped at SDR white. HLG puts SDR white
(203 cd/m2) at the 75% reference level of a 1000 cd/m2 nominal display,
so the film also reads on a display that ignores its signalling, and
needs no luminances stated. PQ shows SDR white at paperWhiteNits
(default 203) and highlights up to peakNits (default 1000, at least the
paper white, at most 10000), and states BT.2020 mastering-display
metadata to the peak and a MaxCLL of the peak. The stream and the MP4
both state the primaries, transfer and matrix. av.capabilities().hdr
names what the encoder records in HDR; a take it cannot record is
refused with its reason, and so are chroma = "444", a codec it does not
list, and paperWhiteNits or peakNits beside HLG or an SDR take. The
transfer the take records in reads back as av.status().recordingHdr.
width / height are the film's size: the whole of the presented
frame (in an editor layout, the rect the scene is drawn into) is
resampled to it, and a side left out takes the presented frame's.
Returns the destination path of a session that is open and
recording, or nil
and the reason it is not: an adapter that cannot encode, a take
already running, an option the encoder rejects, a resolution the
device refuses, a destination the VFS cannot write (a read-only
path, a directory, a host filesystem path). The engine opens the
session, so the call waits for it: run it where it can yield,
wrapping it in task.spawn from a callback that cannot. How a
take finished reads back as
av.status().recordingEnd; a refused request puts its reason
there and on recordingError and leaves no take report behind,
while a request refused because a take is already running leaves
that take's report as it is.
Parameters
pathstring— VFS destination path, returned in its/zeroform; a relative name records under/zero/source/local/recordings/.optsRecordOpts(optional) — Encoder options (optional).
Returns (string?, string?, Durability?) — Destination VFS path of the open recording, or nil. Why the recording was refused, when it was. Where the film will land, as a THIRD return value: { durable = true } when the take is filed where this call named it and the next session reads it back, { durable = false, survivesRestart = …, warning = …, playShadow = …, shadowed = { … } } when the play shadow takes it: live in this session and discarded on a guarded play-exit unless kept, with survivesRestart saying whether a restart keeps it and playShadow naming the routes that keep it, and { durable = false, survivesRestart = false, warning = …, scratch = { … } } when it is filed in /source/tmp/ scratch, which is gone when the engine stops or restarts. The take is filed when it ENDS, so this is the verdict a write landing there gets on the terms standing at THIS call, answered here because here is where a caller can still act on it: a film recorded during play is kept with vfs.promotePlayShadow(path) and play keeps running. durable is present whatever the answer is, so its absence is never a reading. It is the same answer, in the same words, that asset.create returns and the MCP write_file / capture tools attach to their own results. A take opened in edit that runs on into play is filed on play's terms, so av.status().recordingDurability — which answers for the take still running — is where a take spanning a mode change reads.
local clip = av.record("intro.mp4", { fps = 60 })
local film = av.record("cut.mp4", { fps = 24, frames = 24 * 181, cadence = "frame" })
local clean = av.record("take.mp4", { fps = 24, renderLayers = "all !EditorUI !debug" })
local hlg = av.record("sunset.mp4", { fps = 30, hdr = true })
local pq = av.record("sunset-pq.mp4", { fps = 30, hdr = "pq", peakNits = 1000 })
local shot = av.record("film.mp4", { fps = 24, frames = 240, camera = "FilmCamera" })
local take, why, d = av.record("take.mp4", { fps = 24 })
if d and d.playShadow then log.warn(d.warning .. " " .. d.playShadow) end
typed/builtin//modules/api/engine/av/av/save
av.save(path: string, opts: SaveOpts?) -> (boolean, string, SaveReport?)
Save a finished take to the device of the person at the screen, so
the recording outlives the machine's own storage. path
names the take the way av.record did: a relative name is the take of
that name under /zero/source/local/recordings/, and any VFS path works too.
The person decides where it lands. In the browser the take downloads at
once when the save rides a click or key press of the person at the
screen, so call it from a button's click handler; a save with no such
gesture behind it (an agent, a timer, the end of a take) makes the page
show the person an offer they save with a click of their own, because a
browser starts a download only for a person who just acted. A native
engine opens the host's save dialog in their downloads folder, with the
take's name filled in, and writes it where they choose; an engine with
no window has no person at its screen and refuses. An Android engine
adds the take to the device's gallery (Movies, in a folder named for the
app) and answers "saved" once it is there. The call waits for
the first answer, so run it where it can yield (task.spawn from a
callback). Returns true, a sentence saying where the take went, and the
report { state, detail, name, size, path } with state
"saved" (on the device) or "offered" (in front of the person, as the
page's offer or the save dialog); or false and why it was refused: a
take still recording (it is filed when it ends), no file at the path, a
host path, a name with a folder in it, no window, or a take too large
for the browser to hold, which the page shows the person as well. The
saved file is the take byte for byte. userfile.save saves any other
file the engine holds.
Parameters
pathstring— The take: its name under/zero/source/local/recordings/, or a VFS path.optsSaveOpts(optional) —{ name }, the file name the device gets (the take's own when omitted).
Returns (boolean, string, SaveReport?) — Whether the device took the take. Where it went, or why it was refused. The save report, when the device took the take.
local ok, where = av.save("take.mp4")
local ok, where, report = av.save("take.mp4", { name = "boss-fight.mp4" })
typed/builtin//modules/api/engine/av/av/status
av.status() -> AvStatus
Report the encoder subsystem's state. Always available
regardless of GPU support. backend is the encode backend in use:
"vulkan" or "vaapi" on an adapter with a media engine,
"mediacodec" on Android, where the device's own encoder takes the
frames, "software" where a desktop engine encodes on the CPU, and
"webcodecs" in the browser, where the browser's own WebCodecs
encoder takes the frames. hardware is true for the first three, and
in the browser when the browser reports a hardware encoder for the
default codec, so a caller that pays for the take in engine time
knows which it is getting. codecs lists what the backend encodes
with the recording default first (h264 in the browser and on Android,
which every engine plays back with video.create; an Android device
lists h265 after it where its media hardware encodes HEVC).
reason is "supported", "not_probed" before the engine has
asked its encoder,
"unsupported_adapter" for a native adapter with no encoder, or
"unsupported_browser" for a browser whose WebCodecs encodes none
of the codecs the engine offers. live is true while the
av.live stream is running, and liveError is why the most recent
stream was refused or ended on a failure: nil while one runs and
after av.stop_live() ended one that had opened, and the reason
that names av.stop_live() after it ended one still opening. A take of its own reads back on the
recording fields: recording is the destination of the take in
flight, recordingBound what will end it, recordingEnd how the
most recent one ended, and recordingError why one produced no
file. recordingAudio is the codec the take is writing the master
mix with ("opus"), or the reason the file carries no audio track
— read it to tell a film with a soundtrack from a silent one.
recordingHdr is the HDR transfer the take records in ("hlg" or
"pq"), nil for an SDR take, and stands as the most recent take's once
it ends.
recordingLayers is the render-layer include spec the armed take is
drawing the viewport under, in the words its caller wrote, and nil for
a take that stated none — the reading that answers what is in the
picture rather than how much of it there is. recordingCamera is the
entity id of the camera the take's most recent captured frame was drawn
from, and stands as the source of the most recent take once that take
has ended — it is read off the frame the engine drew, so it answers
which view a film holds whether or not the take named a camera.
recordingScope is the picture the take in flight films, "viewport"
(the scene view) or "window" (the whole presented window), and nil when
no take runs.
recordingCadence is the clock the take stamps its frames from,
"realtime" or "frame", and so what the tally below is a reading
against. What the take produced reads off recordingFrames,
recordingBytes (every byte the take has produced so far, climbing
while it runs and ending equal to the size of the file),
recordingSeconds (the timeline those frames cover),
recordingAchievedFps (the rate they arrived at) and
recordingRequestedFps (the rate asked for) — live while a take
runs, and its final tally once it ends. On "realtime" the
requested rate is a ceiling and an engine ticking under it reaches
less; on "frame" every rendered frame is a slot of the recorded
timeline, so recordingSeconds is that timeline's length and
recordingAchievedFps is the rate it plays back at.
recordingDurability is where the film in flight lands on the terms
standing now — the report av.record returns as its third value, asked
again for the take still running, so a caller polling status learns the
play shadow is taking the film in time to keep it, a take that entered
play after it opened included. It is present while a take names a
destination.
Returns AvStatus — Encoder status table.
local s = av.status(); print(s.backend, s.hardware, s.recordingAudio)
typed/builtin//modules/api/engine/av/av/stop_live
av.stop_live() -> boolean
Stop any active live-stream session.
Returns boolean — True if a session was stopped, false if none was active.
av.stop_live()
typed/builtin//modules/api/engine/av/av/stop_recording
av.stop_recording(handle: string?) -> (boolean, string?)
Stop the active recording (or the one for the given promise
handle). Returns true when a recording was armed at call time. A
false return carries a second value naming how the most recent
recording already ended (the bound it reached, or the failure
that cut it short), and nil when no recording has run at all. The
engine finalizes the take once the call returns. A take stopped
before its first frame is captured runs on until that frame lands
and ends holding it, and one whose first frame has not landed 120
frames after the stop ends with none. Wait for
av.is_recording() to go false, then read what it produced off
av.status().
Parameters
handlestring(optional) — Promise handle of a specific recording (optional).
Returns (boolean, string?) — True if a recording was stopped. How the most recent recording ended, when nothing was armed.
local stopped, ended = av.stop_recording()
typed/builtin//modules/api/engine/base64/base64/decode
base64.decode(text: string) -> (string?, string?)
Decode standard-alphabet base64 text back to the original binary string.
Parameters
textstring— Base64 text to decode.
Returns (string?, string?) decoded bytes on success, or (nil, errmsg).
local bytes = base64.decode(encoded)
typed/builtin//modules/api/engine/base64/base64/encode
base64.encode(bytes: buffer | string) -> string
Encode a binary string to standard-alphabet (padded) base64 text.
Parameters
bytesbuffer | string— Binary bytes to encode.
Returns string — Base64 text.
local text = base64.encode(jpegBytes)
typed/builtin//modules/api/engine/blend/blend/destroyLayout
blend.destroyLayout(handle: number) -> boolean
Drop the layout from the registry.
Parameters
handlenumber— Layout handle.
Returns boolean — True if the layout existed and was removed.
typed/builtin//modules/api/engine/blend/blend/layout
blend.layout(slots: { BlendSlot }, totalStride: number?, tail: number?) -> number?
Register a record-stride layout. Each slot is
{ offset, stride, op } where op is "lerp" / "slerp" /
"sum" / "step". Slerp slots must have stride 4.
totalStride defaults to max(offset + stride) across slots;
pass an explicit value when records contain padding past the
last slot. tail is a run of scalars after the last record,
each lerp-blended on its own: a pose's bone records followed by
its blend-shape weights blend under one layout.
Parameters
slots{ BlendSlot }— Array of slot tables.totalStridenumber(optional) — Optional explicit record stride.tailnumber(optional) — Optional count of scalars after the records (defaults to 0).
Returns number? — Layout handle, or nil.
local l = blend.layout({ { offset = 0, stride = 3, op = "lerp" } })
local pose = blend.layout(slots, 10, 2 * #shapeOrder)
typed/builtin//modules/api/engine/blend/blend/lerpInto
blend.lerpInto(outBuffer: Substrate.TypedBuffer, layout: number, aBuffer: Substrate.TypedBuffer, bBuffer: Substrate.TypedBuffer, t: number) -> boolean
Two-input crossfade shortcut. Equivalent to
blend.weightedInto(out, layout, { {a, 1-t}, {b, t} }).
Faster for the common A/B fade case because it skips the
inputs-table walk.
Parameters
outBufferSubstrate.TypedBuffer— The buffer written into.layoutnumber— Layout handle.aBufferSubstrate.TypedBuffer— The A side of the fade.bBufferSubstrate.TypedBuffer— The B side of the fade.tnumber— Crossfade weight on B (0..1).
Returns boolean — True on success.
typed/builtin//modules/api/engine/blend/blend/weightedInto
blend.weightedInto(outBuffer: Substrate.TypedBuffer, layout: number, inputs: { BlendInput }) -> boolean
Combine N weighted input buffers into the output buffer
using the layout's slot ops. The output buffer's length, less
the layout's tail, must be a whole multiple of
layout.totalStride; every input
buffer must be at least as long as the output. Returns false
on any handle / size mismatch.
Parameters
outBufferSubstrate.TypedBuffer— The buffer written into.layoutnumber— Layout handle.inputs{ BlendInput }— Array of{ buffer, weight }.
Returns boolean — True on success.
typed/builtin//modules/api/engine/camera/camera/active
camera.active() -> string?
Entity id of the on-screen render camera this frame — whichever camera wins the viewport by priority (the editor fly-camera in edit mode, the gameplay camera in play). Render features, billboards, and input bases that must follow the human's on-screen view read this.
Returns string? — Entity id of the on-screen camera, or nil if none is active — including the frame after that camera's entity is despawned.
local camId = camera.active()
typed/builtin//modules/api/engine/camera/camera/cut
camera.cut()
Declare that the camera on screen cuts: the next frame it draws stands somewhere it did not travel to. Motion vectors are the difference between where a surface projects now and where it projected on the camera's previous frame, and everything temporal reads that difference — the shutter reconstructs the frame by walking it, a temporal resolve reprojects its history along it. Across a cut that difference describes a displacement no surface made, so the frame is reconstructed from taps a whole screen away and belongs to neither shot. A declared cut leaves the camera with no previous frame for exactly one frame, which is the state its very first frame is already in, so every consumer reads zero motion across the cut. Declare it in the same step that places the camera at the new station; declaring it again before that frame draws still costs the one frame. Handing the viewport from one camera to another is already a cut without being declared one: the incoming camera stands where it always stood, and the engine performs the handover, so it is what states it.
camera.cut(); entity(camId).position = { 40, 6, -12 }
typed/builtin//modules/api/engine/camera/camera/editor
camera.editor() -> string?
Entity id of the editor fly-camera (the EditorOnly authoring camera), or
nil if the scene has none. This is the camera the editor viewport renders
through, so it is the one a capture of the screen sees. Its pose is its
entity transform: assign entity(id).position to move it and aim it with
the camera toolbox's lookAt, which makes a screen capture repeatable
instead of whatever pose the instance booted with.
Returns string? — Entity id of the editor camera, or nil.
local camId = camera.editor()
local id = camera.editor(); entity(id).position = { 12, 8, 12 }; tools.use("camera", "lookAt", id, { 0, 0, 0 })
typed/builtin//modules/api/engine/camera/camera/editorOverride
camera.editorOverride() -> string?
Entity id currently overriding viewport selection, or nil when the viewport is decided by highest-priority-wins.
Returns string? — Entity id of the overriding camera, or nil.
local owner = camera.editorOverride()
typed/builtin//modules/api/engine/camera/camera/facing
camera.facing(target: (string | EntityRef), axis: string) -> Vec3Value?
The direction a camera faces as the person looking through it sees it,
for the one camera whose facing is not its entity's own rotation: the
on-screen camera during an XR session. There the camera entity's
position and rotation are the game's own, the pose the rig is built
from, and the facing is the person's head's (the dominant controller's aim
when the person's aim setting is controller). transform.forward,
right and up of that entity and the Camera component's forward,
right and up read this, so aiming and movement relative to the camera
follow the view in a headset with no change of its own.
Parameters
target(string | EntityRef)— Entity id, name, or proxy of the camera.axisstring—"forward","right"or"up".
Returns Vec3Value? — The unit direction in world space, or nil when the entity's own transform is the facing: any other camera, and every camera outside a session.
local f = camera.facing(camera.active(), "forward"); if f then print(f.x, f.z) end
typed/builtin//modules/api/engine/camera/camera/get
camera.get(target: (string | EntityRef)) -> CameraReport?
One camera's report from the observation — the same record
camera.list yields, for the camera the caller names. Takes an entity id,
an entity name, or an entity proxy, the same way the camera tools do.
Parameters
target(string | EntityRef)— Entity id, entity name, or entity proxy of the camera to report on.
Returns CameraReport? — The report, or nil when nothing resolves or that camera has none.
local c = camera.get(camera.active()); print(c.frame.far, c.authored.far)
local c = camera.get("minimapCam"); print(c.rendering, c.reason)
typed/builtin//modules/api/engine/camera/camera/list
camera.list() -> { CameraReport }
Every camera in the world as a compact row each, ordered the way the
renderer resolves the on-screen camera: highest priority first. Reads the
same observation camera.observe does, so a row can never disagree with
the full report about whether a camera is enabled or which one drew.
Returns { CameraReport } — One row per camera entity, or an empty list before the first frame.
for _, c in ipairs(camera.list()) do print(c.name, c.enabled, c.rendering) end
typed/builtin//modules/api/engine/camera/camera/main
camera.main() -> string?
Entity id of the main scene camera — the scene camera the viewport is
drawn from, and while the editor fly-camera holds the screen, the scene
camera that would take it. The gameplay/PlayerPrototype camera, an
agent-placed scene camera, or a cutscene camera. Never the editor camera;
nil if the scene has only the editor camera. It comes off the same
selection the frame does, so writing a pose to it moves what is drawn
whenever a scene camera is on screen. The scene camera with the highest
authored priority takes it; cameras tied on priority settle on the order
the frame visits them, so a scene that needs a specific camera — a
prototype and the clone play makes of it both stand at 0 — states a
distinct priority rather than resting on that order. For the camera drawn
on screen whichever partition owns it, use camera.active().
Returns string? — Entity id of the main scene camera, or nil — including the frame after that camera's entity is despawned, before the scene elects another.
local camId = camera.main(); local cam = camId and entity(camId)
typed/builtin//modules/api/engine/camera/camera/motionTally
camera.motionTally() -> { frames: number, withoutHistory: number }
Frames the camera on screen has drawn, and how many of them had no previous frame to difference their motion vectors against — its first frame, every declared cut, and every frame the viewport changes hands on. Both counts are monotonic across the session, so two readings either side of a run say what happened in between.
Returns { frames: number, withoutHistory: number } — { frames, withoutHistory }.
local before = camera.motionTally().withoutHistory
typed/builtin//modules/api/engine/camera/camera/observe
camera.observe() -> CameraObservation?
Every camera in the world, for the frame that has just been drawn.
lastRender retains the latest submitted frame, target and pending build
count while the camera exists, including frames when it is disabled.
engineFrame identifies the script frame (time.frameCount()) that drew.
Answers "why is this camera not showing what I expect" in one call:
rendering says whether each camera drew and reason names the single
cause when it did not — "disabled", "entityInactive", "targetMissing",
"noLayers", "outranked", "notDrawn", "paced" for a texture camera
whose per-frame render waits for the next frame the frame pacer admits, or
"awaitingPipelines" for a deferrable render queued behind pipeline
builds. Explicit camera renders draw the requested frame and report its
pending builds in lastRender.
pipelinesPending counts the builds a camera is waiting on: what a held
render is queued behind, and — for a camera that DID draw — what the frame
it drew was drawn WITHOUT: the pipeline builds in flight, the shader
compiles and resolve gates a material waits on, and the material rows
the routing left waiting on them (such a material draws the magenta
placeholder until they land). It is absent once a camera's frame was drawn
with everything the scene asked for. Each camera carries both
projections: authored is what the Camera component holds and frame is
what the renderer actually built, with mismatch naming every field the
two disagree on — so a clip range or a lens the frame did not use is one
field read. frame, viewProj, frustum and the cost numbers describe
a camera that drew; every cost is for that one frame.
One snapshot is published per drawn frame, from after the frame is drawn,
so a read describes the last frame rather than the world at the instant of
the call — a write and a read in one script step return the frame that ran
before the write. Put a task.wait() between them to compare a camera
either side of a change; frame counts the frames observed, so a poll can
wait for it to advance.
Returns CameraObservation? — The observation, or nil before the first frame has been drawn.
local obs = camera.observe(); for _, c in ipairs(obs.cameras) do print(c.name, c.rendering, c.reason) end
local dark = {}; for _, c in ipairs(camera.observe().cameras) do if not c.rendering then table.insert(dark, c.name .. ": " .. tostring(c.reason)) end end
typed/builtin//modules/api/engine/camera/camera/setEditorOverride
camera.setEditorOverride(entityId: string?)
Give one camera the viewport outright, or pass nil to clear it. While
set, that camera IS the on-screen camera and priority is never consulted,
so no authored priority can take the viewport from it — which is what makes
an authoring camera safe to fly over a scene holding a camera at any
priority. An override naming a camera that is despawned or disabled falls
back to highest-priority-wins rather than blanking the screen.
The override holds across a change of engine.mode: the flip rebuilds
the scene and materialises its cameras again, and an override whose
camera the rebuilt scene holds under the same entity id names it again
once the rebuild has ended. One whose camera the rebuilt scene does not
hold (a temporary camera, or one play replaces with a clone of its own)
ends there: a warning notice and the engine log name the camera it held,
and the wld.play / wld.edit result reports it under viewportOverride.
An override on a camera that draws nothing in the new mode (an EditorOnly
camera sits out play) stands, and the highest-priority camera holds the
viewport until its camera draws again; viewportOverride.onScreen names
the camera holding it.
Parameters
entityIdstring(optional) — Entity id of the camera to route the viewport to, or nil to clear.
camera.setEditorOverride(camera.editor())
camera.setEditorOverride(nil)
typed/builtin//modules/api/engine/camera/camera/verticalFov
camera.verticalFov(fov: number, fovAxis: string?, aspect: number) -> number
The vertical angle a perspective camera stating fov on fovAxis
draws a frame of aspect (width over height) at, in degrees: the rule the
renderer applies to every Camera. "shorter" holds fov vertically on a
landscape frame and horizontally on a portrait one; "vertical" and
"horizontal" hold it on that axis. An aspect that is not a positive number
answers fov unchanged.
Parameters
fovnumber— Field of view in degrees across the sidefovAxisnames.fovAxisstring(optional) — "shorter", "vertical" or "horizontal"; nil is "shorter".aspectnumber— The frame's width divided by its height.
Returns number — The vertical field of view in degrees.
local v = camera.verticalFov(cam.fov, cam.fovAxis, w / h)
typed/builtin//modules/api/engine/camera/camera/viewData
camera.viewData(target: ((string | EntityRef)?)?) -> CameraView?
Camera render data. Called with no argument it is the active viewport
camera's data for this frame: world position, which projection it drew and
the field describing that frame, the viewport (its origin in the window's
physical pixels, its pixel size, and scaleX / scaleY, its pixels per
window pixel: 1 while it is shown at its own size, and its size over the
rect it is shown in while renderer.setPictureSize draws a device
screen's size scaled to fit a Scene panel), the 6 world-space
frustum planes (the same inward-pointing, normalized planes the renderer
culls with), and the view-projection matrix. The camera state a render
feature needs for camera-relative work — LOD selection, frustum culling,
billboards. Render features also get it as ctx.camera.
The bare form is built once per view: every read while the camera, its
projection and the viewport stand returns the same read-only table, so a
component reading it every frame on many entities allocates nothing, and
a read after the view moves returns a new one. Copy a field out to change
it.
Called with an entity id it is that camera's data, read from the frame's
camera observation, and carries the identity the bare form has no room for:
which camera it describes, which frame it was built for, what it rendered
into, and the render layers it resolved to.
Parameters
target((string | EntityRef)?)(optional) — Entity id, name, or proxy of the camera to read, or nil for the viewport camera.
Returns CameraView? — The camera view data, or nil when that camera drew no frame.
local c = camera.viewData(); if c then print(c.position.x, c.fovY) end
local minimap = camera.viewData("minimapCam"); print(minimap.output.target, minimap.viewport.w)
typed/builtin//modules/api/engine/cameraInput/cameraInput/devices
cameraInput.devices() -> { CameraDevice }
Every capture device the platform offers: id is what
cameraInput.open takes as device, name the label a person
recognises, facing which way it points. Until camera access has been
granted, id and name read as empty strings and facing as
"unknown": the list is part of what the permission protects, so a
first open takes the default camera or a facing, and the list names the
devices after that.
Returns { CameraDevice } — Array of { id, name, facing, default }.
for _, d in ipairs(cameraInput.devices()) do print(d.name, d.facing) end
typed/builtin//modules/api/engine/cameraInput/cameraInput/feeds
cameraInput.feeds() -> { CameraFeedEntry }
Every open feed, with the owning context that opened it (scope,
the same tag scopes.list() shows), whose end stops the feed.
Returns { CameraFeedEntry } — Array of { id, scope, state, device, texture }.
for _, f in ipairs(cameraInput.feeds()) do print(f.id, f.state, f.scope) end
typed/builtin//modules/api/engine/cameraInput/cameraInput/onDeviceChange
cameraInput.onDeviceChange(callback: (devices: { CameraDevice }) -> ()) -> () -> ()
Call callback with the new device list every time a camera is
added or removed, or the platform names its devices after access is
granted. Each listener is watched by a task of the context that
registered it, so a listener a component registered ends when that
component is removed, and every other listener goes on hearing changes.
Parameters
callback(devices: { CameraDevice }) -> ()— Receives the device list, ascameraInput.devices()returns it.
Returns () -> () — A function that removes this listener.
local off = cameraInput.onDeviceChange(function(devices) print(#devices) end)
typed/builtin//modules/api/engine/cameraInput/cameraInput/open
cameraInput.open(opts: CameraOpenOpts?) -> (CameraFeed?, string?)
Open a camera as a feed. Returns the feed at once; it reads
permissionPending while the platform asks for access, then running
(or denied / failed with a reason). Wait with feed:awaitRunning().
feed.texture is a texture handle that shows the camera's current frame:
put it on a surface as a session material's base_color_texture
(renderer.material.create, worn with Model:applySessionMaterial) or in
a slot of a material that exists (renderer.material.setTexture(key, "base_color_texture", feed.texture)), in UI as
{ type = "image", props = { src = feed.texture } },
and av.record films it like any other scene content.
device names a camera by the id or name cameraInput.devices() lists;
facing asks for the "front" or "back" camera instead; with neither,
the platform's default camera opens. width, height and fps are hints:
the device delivers the nearest it can, and feed:status() reports what it
delivers. A second feed on a camera already open shares it.
Returns nil and the reason for a request refused before any camera is touched: a hint outside its range, a facing other than front or back, a device the platform does not offer.
Parameters
optsCameraOpenOpts(optional) —{ device, facing, width, height, fps }, every field optional.
Returns (CameraFeed?, string?) — The feed, or nil and the reason.
local feed = cameraInput.open({ facing = "front", width = 1280, height = 720 })
local screen = feed and renderer.material.create({ shader = "unlit", textures = { base_color_texture = feed.texture } }, "tv_screen")
typed/builtin//modules/api/engine/cameraInput/cameraInput/stopAll
cameraInput.stopAll() -> number
Stop every open feed and release every camera, whatever opened them.
Returns number — How many feeds stopped.
cameraInput.stopAll()
typed/builtin//modules/api/engine/carried/carried/heldBytes
carried.heldBytes() -> number
The bytes every carried mount holds in this engine's memory.
Returns number — Bytes.
print(carried.heldBytes())
typed/builtin//modules/api/engine/carried/carried/list
carried.list() -> { Status }
The status of every carried mount of this session.
Returns { Status } — One status per mount.
for _, m in carried.list() do print(m.key, m.state) end
typed/builtin//modules/api/engine/carried/carried/manifest
carried.manifest(key: string) -> string?
The manifest of the ready mount at key: the JSON bytes the
content store served ($schema zero/closure/v1, root, and entries,
one per file and folder with its world path, asset_guid, checksum,
size_bytes, kind and origin, plus one engine entry per builtin it
was built against). Their sha-256 is the mount's closureSha. Nil until
the mount is ready.
Parameters
keystring— The mount's key.
Returns string? — The manifest's bytes, or nil.
local entries = require("@builtin::modules.json").decode(carried.manifest("ada.avatar")).entries
typed/builtin//modules/api/engine/carried/carried/mount
carried.mount(closureSha: string, options: MountOptions?) -> Status
Hold the carried mount of the closure whose manifest address is
closureSha and start filling it, unless it is already held. The mount
stands at /zero/runtime/carried/<key>/; a key holds one closure for as
long as anyone uses it, and every mount of the same closure at the same
key holds it once more. Answers at once with the mount's status (state
resolving while it fills); carried.wait yields until it settles.
Raises when the key is malformed, closureSha is no sha-256, or the key
holds another closure.
Parameters
closureShastring— The sha-256 hex digest of the closure's manifest.optionsMountOptions(optional) —key: the mount's folder name (one path segment of letters, digits,.,_,-), defaultclosure-<first 16 hex digits>;commit: the commit the closure was published at, stated in the status.
Returns Status — The mount's status.
local m = carried.mount(sha, { key = "ada.avatar" }); local s = carried.wait(m.key)
typed/builtin//modules/api/engine/carried/carried/mountDraft
carried.mountDraft(assetPath: string, options: MountOptions?) -> Status
Hold a draft carried mount of the asset at assetPath, an asset of
the open world's working tree (or of your home folder): the engine walks
the asset and every asset its files reference, writes that closure and
its manifest into the device's content cache, and mounts it from there
the way a published closure mounts, labelled draft = true. It is this
engine's alone. Mounting it again rebuilds it from the tree as it stands.
A draft holding a home folder's content is that folder's: it is made for
code that reaches the folder, and its files, listing, status and
manifest answer that code alone. Raises, naming the folder, when the
asset or anything it reaches is in a home folder the calling code does
not reach.
Parameters
assetPathstring— The asset, e.g./zero/source/chars/ada.avatar.optionsMountOptions(optional) —key: the mount's folder name, defaultdraft-<asset name>.
Returns Status — The mount's status.
local d = carried.mountDraft("/zero/source/props/lamp.model"); carried.wait(d.key)
typed/builtin//modules/api/engine/carried/carried/release
carried.release(key: string) -> number
Let one holder of the mount at key go. The last one takes it
down: its folder leaves /zero/runtime/carried/ and its bytes leave this
engine's memory, while the device's content cache keeps them for the
next mount. Raises when no mount is held at key.
Parameters
keystring— The mount's key.
Returns number — How many holders still hold it.
carried.release("ada.avatar")
typed/builtin//modules/api/engine/carried/carried/resolve
carried.resolve(key: string, reference: string) -> string?
What reference, written by content of the closure at key,
names: a guid the closure carries, a path of its world
(props/lamp.model, /zero/source/props/lamp.model) or an identity of
its world (props.lamp) answers the file inside the mount; a reference
to the engine library answers the library asset, taken to the version of
an engine builtin the closure was built against when the mount holds that
version. The open world's own content answers none of it. Nil when
nothing answers.
Parameters
keystring— The mount's key.referencestring— A guid, path, identity or library reference.
Returns string? — A VFS path, or nil.
local tex = carried.resolve("ada.avatar", "chars.ada_albedo")
typed/builtin//modules/api/engine/carried/carried/status
carried.status(key: string) -> Status?
Where the mount at key stands, as <key>/status states it:
state is resolving, fetching, measuring, ready, refused or
none; reason is a word saying why nothing is mounted (unreachable,
notFound, incomplete) or why the closure was refused, with detail
the sentence; bytesFetched / bytesTotal count the files read;
measured counts files, folders and bytes per kind once ready;
builtin names how each engine builtin the closure was built against
resolves (host, mount, or hostOtherVersion with why). Nil when
no mount is held at key, and when the mount holds a home folder's
content the calling code does not reach.
Parameters
keystring— The mount's key.
Returns Status? — The status, or nil.
print(carried.status("ada.avatar").state)
typed/builtin//modules/api/engine/carried/carried/wait
carried.wait(key: string, seconds: number?) -> Status
Yield until the mount at key settles (ready, refused or
none) or seconds pass, and answer its status then. Raises when no
mount is held at key, or when it holds a home folder's content the
calling code does not reach.
Parameters
keystring— The mount's key.secondsnumber(optional) — How long to wait, default 120.
Returns Status — The status.
local s = carried.wait("ada.avatar", 30); assert(s.state == "ready", s.detail)
typed/builtin//modules/api/engine/channel/channel/create
channel.create(opts: ChannelOpts) -> number?
Register a keyframe channel. times is the sorted keyframe
time array; values is the packed value array (layout depends
on interp); stride is the floats-per-sample width; interp
is "step" | "linear" | "slerp" | "cubicHermite". Returns
the channel handle, or nil on malformed input.
Parameters
optsChannelOpts—{ times, values, stride, interp }.
Returns number? — Channel handle, or nil.
local h = channel.create({ times = ts, values = vs, stride = 3, interp = "linear" })
typed/builtin//modules/api/engine/channel/channel/destroy
channel.destroy(handle: number) -> boolean
Drop the channel from the registry.
Parameters
handlenumber— Channel handle.
Returns boolean — True if the channel existed and was removed.
typed/builtin//modules/api/engine/channel/channel/sampleInto
channel.sampleInto(ch: number, time: number, buf: Substrate.TypedBuffer, offset: number) -> boolean
Sample the channel at time and write stride floats into
the buffer starting at f32 index offset. Returns false
on unknown handle, layout mismatch, or out-of-bounds; the
buffer is unchanged on failure.
Parameters
chnumber— Channel handle.timenumber— Sample time in seconds.bufSubstrate.TypedBuffer— The buffer written into.offsetnumber— Starting f32 index in the buffer.
Returns boolean — True on success.
typed/builtin//modules/api/engine/channel/channel/sampleManyInto
channel.sampleManyInto(ch: number, time: number, buf: Substrate.TypedBuffer, offsets: { number }) -> boolean
Sample once, blit the result into every position in
offsets. Saves the per-offset binary search when one channel
feeds many bones / particles / parameters.
Parameters
chnumber— Channel handle.timenumber— Sample time in seconds.bufSubstrate.TypedBuffer— The buffer written into.offsets{ number }— Array of f32 indices.
Returns boolean — True on success.
typed/builtin//modules/api/engine/channel/channel/sampleQuat
channel.sampleQuat(ch: number, time: number) -> (number?, number?, number?, number?)
Convenience accessor for stride-4 quaternion channels.
Parameters
chnumber— Channel handle.timenumber— Sample time.
Returns (number?, number?, number?, number?) — (x, y, z, w) or nil.
typed/builtin//modules/api/engine/channel/channel/sampleVec3
channel.sampleVec3(ch: number, time: number) -> (number?, number?, number?)
Convenience accessor for stride-3 channels. Returns the three components as multiret, or nil if the channel is unknown / has a different stride.
Parameters
chnumber— Channel handle.timenumber— Sample time.
Returns (number?, number?, number?) — (x, y, z) or nil.
local x, y, z = channel.sampleVec3(h, t)
typed/builtin//modules/api/engine/client_settings/clientSettings/buildSection
clientSettings.buildSection(model: { [string]: any }) -> { [string]: any }
The System tab's widget tree, drawn from list(), in the room
model.width x model.height the app menu leaves it: the visible groups
as sections (down the side on a desktop and a headset's panel, across the
top on a phone) and the entries of the one chosen, each with its control,
and a way to put the group back to its defaults.
Parameters
model{ [string]: any }—{ width, height, presentation?, group?, groups? }:groupsis thelist()to draw, the current one when left out.
Returns { [string]: any } — The widget tree.
typed/builtin//modules/api/engine/client_settings/clientSettings/close
clientSettings.close()
Close the app menu.
typed/builtin//modules/api/engine/client_settings/clientSettings/get
clientSettings.get(key: string) -> any
The value of the setting under key: the one the person chose, or
the setting's default while they chose none.
Parameters
keystring— The setting's dotted key, e.g."xr.perspective".
Returns any — The value; nil for a key no setting is declared under.
local perspective = clientSettings.get("xr.perspective")
typed/builtin//modules/api/engine/client_settings/clientSettings/isOpen
clientSettings.isOpen() -> boolean
Whether the app menu shows the System tab.
Returns boolean
typed/builtin//modules/api/engine/client_settings/clientSettings/list
clientSettings.list() -> { GroupRow }
Every group declared, in its order, each with its entries: a
setting's value, default, where the value comes from ("player" once the
person chose one, "default" before), its scope, its choices or range,
and whether it can be used now; an action's button. A group's visible
says whether its tab shows on this client now. The settings menu draws
exactly this.
Returns { GroupRow }.
for _, g in clientSettings.list() do print(g.title, #g.entries) end
typed/builtin//modules/api/engine/client_settings/clientSettings/onChanged
clientSettings.onChanged(fn: (key: string?, value: any) -> ()) -> () -> ()
Call fn(key, value) whenever a setting changes, and fn(nil) when
the account they belong to changes.
Parameters
fn(key: string?, value: any) -> ()— The listener.
Returns () -> () — A function that stops the listener.
typed/builtin//modules/api/engine/client_settings/clientSettings/open
clientSettings.open(group: string?)
Open the app menu on its System tab: over the window on desktop, as a world panel in front of the person in a headset. Every way in opens the same menu, a world's own pause tab included.
Parameters
groupstring(optional) — The section to open on ("vr"), or the one shown last.
typed/builtin//modules/api/engine/client_settings/clientSettings/reachable
clientSettings.reachable() -> boolean
Whether some group of the settings shows on this client now. The System tab of the app menu and the editor's ways into it (its menu, the dock in a headset) show while one does.
Returns boolean — Whether some group is visible.
typed/builtin//modules/api/engine/client_settings/clientSettings/register
clientSettings.register(list: { Entry })
Declare settings and actions, each naming the group it shows in. Each setting's value is applied at once. An entry declared again under its key replaces the earlier one.
Parameters
list{ Entry }— The entries:{ key, group, label, description?, field?, labels?, step?, format?, scope?, kept?, effect, button?, danger?, available? }. A setting names itsscope, or carrieskept = { get, set }when the system it configures keeps the person's choice.
typed/builtin//modules/api/engine/client_settings/clientSettings/registerGroup
clientSettings.registerGroup(group: Group)
Declare a group of settings: one tab of the menu. A group declared again under its id replaces the earlier declaration and keeps its entries.
Parameters
groupGroup—{ id, title, description?, icon?, order?, visible? }.
typed/builtin//modules/api/engine/client_settings/clientSettings/reset
clientSettings.reset(target: string)
Return a setting, or every setting of a group, to its default: the
person's choice is forgotten and the effect carried out with the default.
Refused, like set, with world or agent code behind it.
Parameters
targetstring— A setting's key, or a group's id.
clientSettings.reset("vr")
typed/builtin//modules/api/engine/client_settings/clientSettings/run
clientSettings.run(key: string)
Run the action declared under key (recenter, enter VR, exit VR), as
its button in the menu does. Refused with world or agent code behind it.
Parameters
keystring— The action's key.
typed/builtin//modules/api/engine/client_settings/clientSettings/set
clientSettings.set(key: string, value: any?)
Change the setting under key to value as the person's choice: the
value is held to the setting's field, kept in its scope, and its effect
carried out. The person's settings are changed by the engine: a call with
world or agent code behind it (on the stack, or behind the coroutine or
task it runs on) raises, naming the setting.
Parameters
keystring— The setting's dotted key.valueany(optional) — A value the setting's field takes.
clientSettings.set("xr.turn", "smooth")
typed/builtin//modules/api/engine/client_settings/clientSettings/writable
clientSettings.writable() -> boolean
Whether a change made from here would be taken: true for the engine's own code, false with world or agent code behind the call: on the stack, or behind the coroutine or task it runs on.
Returns boolean — Whether set, reset and run would be taken.
typed/builtin//modules/api/engine/color/color/coerce
color.coerce(value: any?) -> Color?
Read a value written in any of the shapes a colour is authored
in — a hex string, an {r=,g=,b=,a=} map, or an {r,g,b,a} array
— as an sRGB color table. Returns nil when the value does not
describe a colour, so a caller can name the value it was handed
instead of substituting one. Channels absent from a map or array
read as 0; alpha absent reads as 1.
Parameters
valueany(optional) — Value to read as a colour.
Returns Color? — sRGB color table, or nil when value is not a colour.
local c = color.coerce("#5a5a62") or color.coerce({ 0.2, 0.7, 0.2 })
typed/builtin//modules/api/engine/color/color/complementary
color.complementary(c: Color) -> Color
Complementary color — rotate hue 180° in Oklch space.
Parameters
cColor— Input color.
Returns Color — Complementary sRGB color.
local accent = color.complementary(primary)
typed/builtin//modules/api/engine/color/color/darken
color.darken(c: Color, amount: number) -> Color
Decrease the lightness of a color in Oklch perceptual space.
Parameters
cColor— Input color.amountnumber— Lightness decrease 0-1.
Returns Color — Darkened sRGB color.
local pressed = color.darken(base, 0.1)
typed/builtin//modules/api/engine/color/color/desaturate
color.desaturate(c: Color, amount: number) -> Color
Decrease the chroma (saturation) of a color in Oklch space.
Parameters
cColor— Input color.amountnumber— Chroma decrease (typically 0-0.2).
Returns Color — Less saturated sRGB color.
local muted = color.desaturate(base, 0.05)
typed/builtin//modules/api/engine/color/color/hex
color.hex(hexString: string) -> Color?
Parse a hex color string into an sRGB color table. Accepts 3,
4, 6, or 8 hex digits with or without a leading # (e.g. "#f00",
"f00f", "#ff0000", "ff000080"). Returns nil on parse failure.
Parameters
hexStringstring— Hex color string.
Returns Color? — sRGB color table or nil.
local fromCss = color.hex("#ff8800")
typed/builtin//modules/api/engine/color/color/hsl
color.hsl(h: number, s: number, l: number) -> Color
Build a color from HSL (h: 0-360, s: 0-1, l: 0-1).
Returned as sRGB.
Parameters
hnumber— Hue (degrees, 0-360).snumber— Saturation (0-1).lnumber— Lightness (0-1).
Returns Color — sRGB color table { r, g, b, a = 1 }.
local teal = color.hsl(180, 0.5, 0.5)
typed/builtin//modules/api/engine/color/color/hsla
color.hsla(h: number, s: number, l: number, a: number) -> Color
Build a color from HSLA, returned as sRGB.
Parameters
hnumber— Hue (0-360).snumber— Saturation (0-1).lnumber— Lightness (0-1).anumber— Alpha (0-1).
Returns Color — sRGB color table { r, g, b, a }.
local fadedTeal = color.hsla(180, 0.5, 0.5, 0.3)
typed/builtin//modules/api/engine/color/color/hsv
color.hsv(h: number, s: number, v: number) -> Color
Build a color from HSV (h: 0-360, s: 0-1, v: 0-1).
Parameters
hnumber— Hue (0-360).snumber— Saturation (0-1).vnumber— Value / brightness (0-1).
Returns Color — sRGB color table { r, g, b, a = 1 }.
local primary = color.hsv(220, 0.7, 0.9)
typed/builtin//modules/api/engine/color/color/lighten
color.lighten(c: Color, amount: number) -> Color
Increase the lightness of a color in Oklch perceptual space.
Parameters
cColor— Input color.amountnumber— Lightness increase 0-1.
Returns Color — Lightened sRGB color.
local hover = color.lighten(base, 0.1)
typed/builtin//modules/api/engine/color/color/linear
color.linear(r: number, g: number, b: number, a: number?) -> Color
Build a color from linear RGB values (not gamma-corrected), output converted to sRGB. Useful for GPU-correct blending. Alpha defaults to 1.
Parameters
rnumber— Linear red (0-1).gnumber— Linear green (0-1).bnumber— Linear blue (0-1).anumber(optional) — Alpha (0-1, default 1).
Returns Color — sRGB color table { r, g, b, a }.
local gpuBlue = color.linear(0.0, 0.0, 1.0)
typed/builtin//modules/api/engine/color/color/mix
color.mix(c1: Color, c2: Color, t: number) -> Color
Perceptually blend two colors in Oklch space — better than RGB mixing for gradients.
Parameters
c1Color— First color.c2Color— Second color.tnumber— Blend factor 0-1 (0 = c1, 1 = c2).
Returns Color — Blended sRGB color.
local mid = color.mix(color.rgb(255, 0, 0), color.rgb(0, 0, 255), 0.5)
typed/builtin//modules/api/engine/color/color/mixRgb
color.mixRgb(c1: Color, c2: Color, t: number) -> Color
Linearly blend two colors in sRGB space — simple, but not
perceptually uniform. Prefer color.mix for natural gradients.
Parameters
c1Color— First color.c2Color— Second color.tnumber— Blend factor 0-1.
Returns Color — Blended sRGB color.
local plain = color.mixRgb(a, b, 0.5)
typed/builtin//modules/api/engine/color/color/oklch
color.oklch(l: number, c: number, h: number) -> Color
Build a color from Oklch perceptual color space (l: 0-1,
c: 0-0.4, h: 0-360). Ideal for perceptually uniform gradients
and color manipulation.
Parameters
lnumber— Lightness (0-1).cnumber— Chroma / saturation (0-0.4).hnumber— Hue (0-360).
Returns Color — sRGB color table { r, g, b, a = 1 }.
local accent = color.oklch(0.7, 0.15, 30)
typed/builtin//modules/api/engine/color/color/rgb
color.rgb(r: number, g: number, b: number) -> Color
Build an sRGB color from CSS-style 0-255 RGB channels. Alpha defaults to 1. Channels are normalised to 0-1 on the way out so the result composes with every other color helper.
Parameters
rnumber— Red channel (0-255).gnumber— Green channel (0-255).bnumber— Blue channel (0-255).
Returns Color — sRGB color table { r, g, b, a = 1 }, normalised to 0-1.
local red = color.rgb(255, 0, 0)
typed/builtin//modules/api/engine/color/color/rgba
color.rgba(r: number, g: number, b: number, a: number) -> Color
Build an sRGB color from CSS-style 0-255 RGB channels with explicit alpha. RGB are normalised to 0-1; alpha is taken as-is in the 0-1 range.
Parameters
rnumber— Red channel (0-255).gnumber— Green channel (0-255).bnumber— Blue channel (0-255).anumber— Alpha (0-1).
Returns Color — sRGB color table { r, g, b, a }.
local halfRed = color.rgba(255, 0, 0, 0.5)
typed/builtin//modules/api/engine/color/color/rotateHue
color.rotateHue(c: Color, degrees: number) -> Color
Rotate the hue of a color by a given number of degrees in Oklch space.
Parameters
cColor— Input color.degreesnumber— Hue rotation (positive or negative).
Returns Color — Hue-rotated sRGB color.
local triadic = color.rotateHue(base, 120)
typed/builtin//modules/api/engine/color/color/saturate
color.saturate(c: Color, amount: number) -> Color
Increase the chroma (saturation) of a color in Oklch space.
Parameters
cColor— Input color.amountnumber— Chroma increase (typically 0-0.2).
Returns Color — More saturated sRGB color.
local pop = color.saturate(base, 0.05)
typed/builtin//modules/api/engine/color/color/toHex
color.toHex(c: Color) -> string
Convert a color to a hex string. Returns "#rrggbb" or
"#rrggbbaa" if alpha is not 1.
Parameters
cColor— Input color.
Returns string — Hex color string.
print(color.toHex(color.rgb(255, 136, 0))) -- "#ff8800"
typed/builtin//modules/api/engine/color/color/toHsl
color.toHsl(c: Color) -> HslColor
Convert a color to HSL.
Parameters
cColor— Input color.
Returns HslColor — HSL color table { h, s, l, a } (h: 0-360, s/l: 0-1).
local hsl = color.toHsl(base)
typed/builtin//modules/api/engine/color/color/toLinear
color.toLinear(c: Color) -> Color
Convert a color from sRGB to linear RGB space — useful for GPU calculations that need linear-space values.
Parameters
cColor— Input sRGB color.
Returns Color — Linear RGB color table.
local gpu = color.toLinear(base)
typed/builtin//modules/api/engine/color/color/toOklch
color.toOklch(c: Color) -> OklchColor
Convert a color to Oklch perceptual color space.
Parameters
cColor— Input color.
Returns OklchColor — Oklch color table { l, c, h, a } (l: 0-1, c: 0-0.4, h: 0-360).
local okl = color.toOklch(base)
typed/builtin//modules/api/engine/color/color/withAlpha
color.withAlpha(c: Color, a: number) -> Color
Return a copy of a color with a different alpha value.
Parameters
cColor— Input color.anumber— New alpha (0-1).
Returns Color with modified alpha.
local ghost = color.withAlpha(base, 0.3)
typed/builtin//modules/api/engine/compute/compute/absentReasons
compute.absentReasons() -> { string }
Every reason compute.diagnose reports, sorted. resident is the one
that means the resource is there.
Returns { string } — The closed set, as strings.
for _, r in ipairs(compute.absentReasons()) do print(r) end
typed/builtin//modules/api/engine/compute/compute/beginBvh
compute.beginBvh(instances: { any }, opts: { [string]: any }?) -> (number?, string?)
Start the build compute.buildBvh runs, without running any of it.
Takes the same instances and options and reports the same non-resident
guids, and returns an id compute.stepBvh advances a bounded slice at a
time and compute.finishBvh collects. Each mesh the instances name is
copied as this is called — once per guid however many instances share it
— so the CPU mesh may be unloaded on the next line and the build still
finishes on the copy it holds. compute.buildBvhSliced is the whole loop
as one call.
Parameters
instances{ any }— Array of{ guid, transform, attributes? }mesh instances.opts{ [string]: any }(optional) — Optional{ maxLeaf? }— max triangles per leaf.
Returns (number?, string?) — The build id, or (nil, err) naming any non-resident guid.
local id = compute.beginBvh(gather.instances)
typed/builtin//modules/api/engine/compute/compute/buildBvh
compute.buildBvh(instances: { any }, opts: { [string]: any }?) -> (any, string?)
Build a bounding-volume hierarchy over the world-space triangles of a
set of mesh instances and upload it as two named compute buffers —
geometry never passes through the scripting heap. Each instance is
{ guid, transform, attributes? }: guid names a mesh resident in the
meshcpu store (materialise with ref:load() / meshcpu.load),
transform is 16 numbers, row-major, translation in slots 4/8/12, and
attributes is up to 40 floats stamped onto every triangle of that
instance (surface colors, material ids, physics tags — whatever the
consuming shader wants per-surface). Triangles pack 18 vec4 each
(v0/v1/v2, n0/n1/n2, uvs, then 10 attribute vec4s — float slots 32..
carry the instance attributes, zero when absent) in BVH leaf order;
nodes 2 vec4 each (min + first-or-left, max + leaf-tagged
count-or-right). Consumers: GI baking, ray-traced passes, GPU picking,
navmesh and SDF generation.
Parameters
instances{ any }— Array of{ guid, transform, attributes? }mesh instances.opts{ [string]: any }(optional) — Optional{ maxLeaf? }— max triangles per leaf.
Returns (any, string?) — { nodes, tris, nodeCount, triCount } — nodes and tris are buffer handles the caller owns, passed to a dispatch like any other and destroyed when the hierarchy is done with. Or (nil, err) naming any non-resident guid.
local bvh = compute.buildBvh(instances)
asset.resolve("raytrace", "computeShader"):dispatch({ buffers = { bvh.nodes, bvh.tris }, workgroups = { 64, 1, 1 } })
typed/builtin//modules/api/engine/compute/compute/buildBvhSliced
compute.buildBvhSliced(instances: { any }, opts: { [string]: any }?) -> (any, string?)
The hierarchy compute.buildBvh builds, spread over as many frames as
it takes: a slice of the build per frame, so a scene's triangle count
costs the frame loop budgetMs at a time instead of the whole build at
once. Yields, so it is called from a task. The result is the same pair of
buffers and the same counts compute.buildBvh returns.
Parameters
instances{ any }— Array of{ guid, transform, attributes? }mesh instances.opts{ [string]: any }(optional) — Optional{ maxLeaf?, budgetMs? }— max triangles per leaf, and the wall time one frame may spend on the build (default 4 ms).
Returns (any, string?) — { nodes, tris, nodeCount, triCount }, or (nil, err).
local built, err = compute.buildBvhSliced(gather.instances, { budgetMs = 4 })
typed/builtin//modules/api/engine/compute/compute/bvhBuilds
compute.bvhBuilds() -> { any }
What the builds started by compute.beginBvh and not yet finished are
costing, oldest id first. Each row is { id, phase, triangles, units, slices, cpuMs, uploadedBytes }: phase is "gather", "build",
"serialize", "upload" or "ready", triangles how many have been
gathered, units the work units run, slices the compute.stepBvh
calls they ran in, cpuMs the wall time spent inside those calls, and
uploadedBytes how much of the hierarchy has reached the GPU.
Returns { any } — Array of build rows.
print(#compute.bvhBuilds(), "hierarchies in flight")
typed/builtin//modules/api/engine/compute/compute/cancelBvh
compute.cancelBvh(id: number) -> boolean
Drop a build along with the triangles it has gathered.
Parameters
idnumber— Build id fromcompute.beginBvh.
Returns boolean — True when the id named a build.
compute.cancelBvh(id)
typed/builtin//modules/api/engine/compute/compute/compile
compute.compile(nameOrHandle: string | { [string]: any } | AssetRef, opts: { [string]: any }?) -> (boolean, string?)
Compile a compute shader from inline WGSL + a declarative binding
schema — the same codegen a .computeShader asset uses. The engine
generates the @group/@binding declarations from bindings/params,
so the source writes only @compute fn main. Symmetric with
registerShader, but with zero-scaffolding bindings (incl. textures,
samplers, storage textures and a params uniform). For asset-backed
shaders prefer authoring a .computeShader (compiled automatically);
use this for dynamic/generated compute shaders.
Parameters
nameOrHandlestring | { [string]: any } | AssetRef— Shader identity to register under (string or asset handle).opts{ [string]: any }(optional) —{ source, entryPoint?, bindings, params? }—bindingsis an ordered list of{ name, kind, access?, element?, format?, array?, sample? }.
Returns (boolean, string?) — True when the program is queued to register; false with the reason when the schema or the module is one the device would refuse.
compute.compile("my_sim", { source = WGSL, bindings = { { name = "data", kind = "buffer", access = "read_write", element = "f32" } } })
typed/builtin//modules/api/engine/compute/compute/compileByName
compute.compileByName(ref: string | { [string]: any } | AssetRef)
Optional explicit pre-warm for a .computeShader asset (idempotent —
fingerprint-guarded). NORMALLY UNNECESSARY: compute.dispatch / dispatchEx
auto-compile a .computeShader on first use. Reach for this only to avoid
the one-frame first-dispatch warm-up in a latency-critical spot. Accepts an
identity/guid string or a resolved asset handle (its .identity is used).
Parameters
refstring | { [string]: any } | AssetRef— A.computeShaderidentity/guid string, or a resolved asset handle.
compute.compileByName("@builtin::shaders.compute_double")
typed/builtin//modules/api/engine/compute/compute/copyBufferToTexture
compute.copyBufferToTexture(bufferName: string, textureKey: string, width: number, height: number, format: string?, rowBytes: number?) -> boolean
Copy a compute buffer into a cached GPU texture under
textureKey, staying on the GPU. The path for an image a compute
pass produced: the buffer holds tightly-packed rows in the format's
texel layout, and the result is an ordinary cached texture — sample
it from a material, or pack it into the shared feature-texture array.
The copy reads rows 256-byte aligned: rows packed tight must be a
multiple of 256 bytes (at rgba16f, any width that is a multiple of 32),
and any other width is laid out with its rows padded to that alignment
and rowBytes saying how far apart they are.
The key names a live texture from this call until destroyTexture
releases it, so a material slot given the key in the same tick binds
what the copy writes. A dispatchEx sampling the key, queued after the
copy, samples what the copy wrote when no dispatchEx earlier in the
same tick writes the buffer it copies.
Parameters
bufferNamestring— Source compute buffer.textureKeystring— Cache key to register the texture under.widthnumber— Texture width in texels.heightnumber— Texture height in texels.formatstring(optional) — Texel format:"rgba16f"(default),"rgba32f","rgba8".rowBytesnumber(optional) — Bytes from one row's start to the next when rows are padded pastwidthtexels — a multiple of 256 at least a row's texels long.
Returns boolean — True when the copy was queued.
compute.copyBufferToTexture("gi_resolved", "lm_wall", 128, 128)
compute.copyBufferToTexture("heights_packed", "heights", 300, 300, "rgba16f", 2560)
typed/builtin//modules/api/engine/compute/compute/createBuffer
compute.createBuffer(name: string, opts: { [string]: any }) -> boolean
Allocate a buffer under name, sized in bytes.
Parameters
namestring— The name a dispatch binds it by.opts{ [string]: any }—{ size, readback? }—sizein bytes.
Returns boolean — True once allocated.
typed/builtin//modules/api/engine/compute/compute/createSampler
compute.createSampler(name: string, opts: { [string]: any }?) -> boolean
Create a named GPU sampler. opts: filter/wrap settings.
Parameters
namestringopts{ [string]: any }(optional)
Returns boolean
typed/builtin//modules/api/engine/compute/compute/createStorageTexture2D
compute.createStorageTexture2D(name: string, opts: { [string]: any }) -> boolean
Create a 2D storage texture (compute-writable render target). opts: { width, height, format? }.
Parameters
namestringopts{ [string]: any }
Returns boolean
typed/builtin//modules/api/engine/compute/compute/createTexture3D
compute.createTexture3D(name: string, opts: { [string]: any }) -> boolean
Create a 3D texture volume. opts: { width, height, depth, format?, storage? }.
Parameters
namestring— Unique volume name.opts{ [string]: any }— Dimensions + format (r8/r16f/r32f/rgba8/rgba16f/rgba32f).
Returns boolean — True on success (mutation queued).
typed/builtin//modules/api/engine/compute/compute/createTextureHistory
compute.createTextureHistory(name: string, opts: { [string]: any }) -> boolean
Create a temporal history buffer (ping-pong textures) for a target. opts: { width, height, format? }.
Parameters
namestringopts{ [string]: any }
Returns boolean
typed/builtin//modules/api/engine/compute/compute/destroyBuffer
compute.destroyBuffer(name: string) -> boolean
Release the buffer allocated under name.
Parameters
namestring— The name it was created under.
Returns boolean — True if a buffer under that name was released.
typed/builtin//modules/api/engine/compute/compute/destroySampler
compute.destroySampler(name: string) -> boolean
Release a named sampler created by compute.createSampler and free
it. The counterpart to that call, alongside destroyBuffer,
destroyTexture, destroyTexture3D, destroyStorageTexture2D and
destroyTextureHistory. The manager's own defaults (linear_clamp,
linear_repeat, nearest_clamp) are kept for the session, since a
compute pass binds them by name.
Parameters
namestring— Sampler name.
Returns boolean — True when the release was queued.
compute.createSampler("soft", { filter = true }); compute.destroySampler("soft")
typed/builtin//modules/api/engine/compute/compute/destroyShader
compute.destroyShader(name: string) -> boolean
Destroy a named compute shader pipeline.
Parameters
namestring— Shader name.
Returns boolean — True on success.
typed/builtin//modules/api/engine/compute/compute/destroyShaderEx
compute.destroyShaderEx(name: string) -> boolean
Destroy a shader registered via registerShaderEx.
Parameters
namestring
Returns boolean
typed/builtin//modules/api/engine/compute/compute/destroyStorageTexture2D
compute.destroyStorageTexture2D(name: string) -> boolean
Destroy a named 2D storage texture.
Parameters
namestring
Returns boolean
typed/builtin//modules/api/engine/compute/compute/destroyTexture
compute.destroyTexture(textureKey: string) -> boolean
Release the cached GPU texture copyBufferToTexture registered
under textureKey, freeing its memory. Call it once the image is no
longer sampled. Writing the same key again replaces the texture, so a
key you keep re-using holds one allocation. A release queued after a
dispatchEx that samples the key runs once that dispatch has sampled it.
Parameters
textureKeystring— Cache key the texture was registered under.
Returns boolean — True when the release was queued.
compute.destroyTexture("lm_wall")
typed/builtin//modules/api/engine/compute/compute/destroyTexture3D
compute.destroyTexture3D(name: string) -> boolean
Destroy a named 3D volume and free its GPU memory.
Parameters
namestring
Returns boolean
typed/builtin//modules/api/engine/compute/compute/destroyTextureHistory
compute.destroyTextureHistory(name: string) -> boolean
Destroy a named texture-history buffer.
Parameters
namestring
Returns boolean
typed/builtin//modules/api/engine/compute/compute/diagnose
compute.diagnose(key: string) -> { [string]: any }
Whether a resource is filed under key right now, and when none is,
which state the inventory says the key is in. A key out of a dispatch
failure resolves here; a mistyped one reports why it does not.
Parameters
keystring— The resource key, verbatim.
Returns { [string]: any } — { key, exists, reason, resource?, current? }. resource is the row when one is filed under the key. reason is one of compute.absentReasons(). current names the live key when the owner holds a resource under the same name at a different serial.
local d = compute.diagnose(key)
if not d.exists then print(d.reason, d.current) end
typed/builtin//modules/api/engine/compute/compute/dispatch
compute.dispatch(shaderNameOrHandle: string | { [string]: any } | AssetRef, opts: DispatchOpts) -> boolean
Dispatch a compute shader with bound buffers. Accepts a
shader name string or an asset handle from asset.load().
Parameters
shaderNameOrHandlestring | { [string]: any } | AssetRef— Shader name or asset handle.optsDispatchOpts—{ buffers, workgroups }. A zero in any workgroup dimension is refused and recorded as a dispatch failure — clamp a computed count withmath.max(1, math.ceil(n / 64)).
Returns boolean — True once the dispatch is queued. What the engine then did with it is in compute.failing().
compute.dispatch("blur", { buffers = { "src", "dst" }, workgroups = { 8, 8 } })
typed/builtin//modules/api/engine/compute/compute/dispatchEx
compute.dispatchEx(shaderNameOrHandle: string | { [string]: any } | AssetRef, opts: { [string]: any }) -> boolean
Dispatch a compute shader with extended texture/storage/sampler bindings.
Asset-backed .computeShaders resolve to their stable guid (collision-safe,
lazily compiled on first dispatch); raw registerShaderEx names pass through.
resources covers the bindings the shader DECLARES. A params: block's
uniform is engine-owned — the compile creates and packs it, setParam
writes it, and the dispatch binds it — so it takes no entry here.
Parameters
shaderNameOrHandlestring | { [string]: any } | AssetRef— Shader name or asset handle.opts{ [string]: any }—{ resources, workgroups, params? }— each resource is{ kind, name };paramsgives the shader'sparams:fields values for this dispatch alone. A zero in any workgroup dimension is refused and recorded as a dispatch failure — clamp a computed count withmath.max(1, math.ceil(n / 64)).
Returns boolean — True once the dispatch is queued. What the engine then did with it is in compute.failing().
typed/builtin//modules/api/engine/compute/compute/dispatchOnVertices
compute.dispatchOnVertices(shaderNameOrHandle: string | { [string]: any } | AssetRef, opts: DispatchOnVerticesOpts) -> boolean
Dispatch a compute shader with a model's vertex buffer bound
at binding 0 (read_write). Use to mutate vertex positions
directly. Asset-backed .computeShaders resolve to their stable guid
(collision-safe, lazily compiled on first dispatch); raw
registerShader names pass through.
Parameters
shaderNameOrHandlestring | { [string]: any } | AssetRef— Shader name or asset handle.optsDispatchOnVerticesOpts—{ model, buffers?, workgroups }. A zero in any workgroup dimension is refused and recorded as a dispatch failure — clamp a computed count withmath.max(1, math.ceil(n / 64)).
Returns boolean — True once the dispatch is queued. What the engine then did with it is in compute.failing().
compute.dispatchOnVertices("flatten", { model = "@user/mesh", workgroups = { 64 } })
typed/builtin//modules/api/engine/compute/compute/failing
compute.failing() -> { { [string]: any } }
Every compute dispatch whose most recent run FAILED, one record per
(shader, target) pair. A dispatch is recorded into a command encoder
frames after the call that asked for it returned, so a pass that stops
running reports here rather than through that call's return value: each
record carries the shader key, the target it writes (a mesh guid for a
dispatch over vertices, the buffers it bound for one that writes only
those), how
many dispatches and failures it has had, and lastError. An empty result
means every dispatch the engine has been given is running.
Returns { { [string]: any } } — Array of { shader, target, dispatches, failures, ok, lastFrame, lastFailedFrame?, lastError? }.
for _, d in ipairs(compute.failing()) do print(d.shader, d.lastError) end
typed/builtin//modules/api/engine/compute/compute/finishBvh
compute.finishBvh(id: number) -> (any, string?)
Hand over a finished build's hierarchy as the same two buffers
compute.buildBvh returns, and release the build. The slices put every
byte of it on the GPU as they ran, so this costs the frame it is called
in the handover and nothing of the scene.
Parameters
idnumber— Build id fromcompute.beginBvh, stepped until"ready".
Returns (any, string?) — { nodes, tris, nodeCount, triCount }, or (nil, err) when the id names no build or the build still has work left.
local built = compute.finishBvh(id)
typed/builtin//modules/api/engine/compute/compute/getReadbackResult
compute.getReadbackResult(resultKey: string) -> { number }?
Poll for a completed read-back and return its bytes as a
1-indexed array of f32 values, nil if pending. The f32
reinterpretation applies to whatever the buffer holds: bytes
written as u32 1, 2, 3, 4 read back here as 1.4e-45, 2.8e-45, 4.2e-45, 5.6e-45 — use getReadbackResultU32() for those, or
getReadbackResultBytes() for a buffer the rest of the buffer
surface accepts. Result is consumed on retrieval, and polling a key
that was never issued raises rather than reading as forever-pending.
Parameters
resultKeystring— Key returned byreadBuffer().
Returns { number }? — 1-indexed array of f32 values, or nil if not ready.
local floats = compute.getReadbackResult(key)
typed/builtin//modules/api/engine/compute/compute/getReadbackResultBytes
compute.getReadbackResultBytes(resultKey: string) -> buffer?
Poll for a completed read-back and get its raw bytes as a
buffer, copied once. The read counterpart of writeBufferBytes:
read values out with buffer.readf32 / buffer.readu32, or hand the
buffer straight to writeBuffer — a payload that stays packed never
becomes a table. Result is consumed on retrieval.
Parameters
resultKeystring— Key returned byreadBuffer().
Returns buffer? — The read-back's bytes, or nil if not ready.
local bytes = compute.getReadbackResultBytes(key)
local firstTexel = buffer.readf32(bytes, 0)
typed/builtin//modules/api/engine/compute/compute/getReadbackResultU32
compute.getReadbackResultU32(resultKey: string) -> { number }?
Poll for a completed read-back interpreting bytes as u32. Returns array of integer values if ready, nil if pending.
Parameters
resultKeystring— Key returned byreadBuffer().
Returns { number }? — Array of u32 values, or nil if not ready.
typed/builtin//modules/api/engine/compute/compute/isReadbackReady
compute.isReadbackReady(resultKey: string) -> boolean
Check if a readback result is available without consuming it.
Raises for a key this engine never issued, or whose result was already
drained — nil/false already means "still in flight", so a mistyped
key reports itself instead of polling forever. Use readbackState()
to test that case without raising.
Parameters
resultKeystring— Key returned byreadBuffer().
Returns boolean — True if the result is ready.
typed/builtin//modules/api/engine/compute/compute/markBaseline
compute.markBaseline() -> number
Record which compute resources are resident right now, and make that the
point compute.resetToBaseline returns to.
A caller that runs work in someone else's engine — a sweep of test suites sharing one, an editor tool driving a session — allocates as it goes: a pass builds the grid its quality asks for and keeps it, a shader files the uniform it was compiled with. Kept is right for a frame that draws again and wrong for the next caller, which then reads an inventory it did not make. This is how a caller says where its own allocations start.
Returns number — The mark's generation, counting from 1 — what compute.resetToBaseline takes to restore to this mark.
local mark = compute.markBaseline() -- then run, then compute.resetToBaseline(mark)
typed/builtin//modules/api/engine/compute/compute/observe
compute.observe() -> { [string]: any }
Every GPU resource the compute subsystem is holding right now — its storage and uniform buffers, its 3D textures, its 2D storage targets, its history pairs and its samplers — with what each one costs and which shader asked for it. This is the call to reach for when compute is holding memory and you do not know what, or when a key out of a dispatch failure needs matching against what exists.
Returns { [string]: any } — { published, generation, resources, totals }. Each row of resources carries key, kind (buffer / uniformBuffer / texture3d / storageTexture2d / textureHistory / sampler), owner ({ shader, name, serial }, read off the key), bytes, format, width, height, depth, usage (the bits it was created with — storage, copySrc, copyDst, vertex, index, indirect, uniform, sampled, sampler) and createdFrame. totals is { count, bytes, byKind }, what the rows sum to — and totals.bytes is the compute figure of renderer.gpuMemory(), read off the same registries. published is false when no renderer has published a reading yet, which is the engine saying it cannot answer rather than answering with nothing. The reading is the one the renderer published, republished on a frame where a registry gained or lost an entry: a resource created earlier in this same script is in the next reading, so wait a frame before asking about it, and generation moves when it arrives.
local r = compute.observe()
print(r.totals.count, r.totals.bytes)
for _, res in ipairs(r.resources) do print(res.key, res.kind, res.bytes) end
typed/builtin//modules/api/engine/compute/compute/program/compile
compute.program.compile(key: string, spec: { [string]: any }) -> (boolean, string?)
Register a compiled program under key from WGSL plus a declared
binding schema. Each #include of the source that names a
.shaderModule absolutely (a guid, an identity, an @root:: or
@builtin:: path) reaches the compiler as that module's guid, with the
module filed first from the text the VFS serves for it now. The engine
then generates the @group/@binding declarations from the schema,
expands the #includes, naga-validates, and registers the result.
Parameters
keystring— The key to register under.spec{ [string]: any }—{ source, entryPoint?, bindings, params, ranges? }— the parsed schema. A buffer binding statingrange = true(or every array buffer binding, withranges = true) takes a range of a buffer: a dispatch binds it withzero_base_NAME/zero_len_NAMEin its params, and the body'sNAME[i]andarrayLength(&NAME)address that range. One that states no range binds the whole buffer.
Returns (boolean, string?) — True when the program is queued to register; false with the reason when the schema or the module is one the device would refuse.
typed/builtin//modules/api/engine/compute/compute/program/destroy
compute.program.destroy(key: string) -> boolean
Release the program registered under key.
Parameters
keystring— The program's key.
Returns boolean — True on success.
typed/builtin//modules/api/engine/compute/compute/program/dispatch
compute.program.dispatch(key: string, opts: { [string]: any }) -> boolean
Dispatch the program under key with one buffer per declared storage
binding, in declaration order.
Parameters
keystring— The program's key.opts{ [string]: any }—{ buffers, workgroups, params? }.paramsgives values of the program'sparams:uniform, by name, to this dispatch alone: two dispatches of one program in a frame each read their own, and a value left out reads what the program holds. A zero in any workgroup dimension is refused and recorded as a dispatch failure — clamp a computed count withmath.max(1, math.ceil(n / 64)).
Returns boolean — True once the dispatch is queued. What the engine then did with it is in compute.program.status(key).
typed/builtin//modules/api/engine/compute/compute/program/dispatchEx
compute.program.dispatchEx(key: string, opts: { [string]: any }) -> boolean
Dispatch the program under key with explicit resources — one
{ kind, name } per declared binding, in declaration order.
Parameters
keystring— The program's key.opts{ [string]: any }—{ resources, workgroups, params? }. A zero in any workgroup dimension is refused and recorded as a dispatch failure — clamp a computed count withmath.max(1, math.ceil(n / 64)).
Returns boolean — True once the dispatch is queued. What the engine then did with it is in compute.program.status(key).
typed/builtin//modules/api/engine/compute/compute/program/dispatchOnVertices
compute.program.dispatchOnVertices(key: string, opts: { [string]: any }) -> boolean
Dispatch the program under key over a mesh's vertices. The mesh
opts.model names fills the shader's vertices binding, and opts.buffers
fills the remaining storage bindings.
Parameters
keystring— The program's key.opts{ [string]: any }—{ model, buffers?, workgroups, params? }.paramsgives values of the program'sparams:uniform to this dispatch alone. A zero in any workgroup dimension is refused and recorded as a dispatch failure — clamp a computed count withmath.max(1, math.ceil(n / 64)).
Returns boolean — True once the dispatch is queued. What the engine then did with it is in compute.program.status(key).
typed/builtin//modules/api/engine/compute/compute/program/dispatches
compute.program.dispatches() -> number
How many dispatches the running thread has queued since it began, a run of a compute list counting each dispatch the list holds. Two readings taken around a piece of work give what that work dispatched.
Returns number — The count, which only grows.
typed/builtin//modules/api/engine/compute/compute/program/dropList
compute.program.dropList(key: string) -> boolean
Forget the compute list under key.
Parameters
keystring— The list's key.
Returns boolean — True once the removal is queued.
typed/builtin//modules/api/engine/compute/compute/program/forPlugin
compute.program.forPlugin(key: string, bindings: number | { string }) -> any
The program under key as a handle a script passes a plugin in a call,
for it to dispatch over the GPU buffers and textures it was handed.
bindings is how many storage buffers the shader binds, or the kind of
each binding in declaration order as bindings.yaml spells them
(buffer, texture3d, storage3d, storage2d).
Parameters
keystring— The program's key.bindingsnumber | { string }— A count of buffers, or each binding's kind.
Returns any — A handle for a plugin call.
typed/builtin//modules/api/engine/compute/compute/program/list
compute.program.list(key: string, entries: { { [string]: any } }) -> boolean
Register the compute list under key, replacing one already there: an
ordered run of dispatches and buffer writes that runList queues in one
call, each value a run supplies named as a slot.
Parameters
keystring— The key to register the list under.entries{ { [string]: any } }— The dispatches and writes, in the order they run. A dispatch is{ program, buffers, workgroups, params?, slots?, runs?, writes?, when? },slotsmapping a param name to the slot that gives it its value.runsnames the runs the dispatch reaches through a page it binds andwritesthe ones of those it writes: the list holds them standing (a replay over a run that was let go of is refused, not run) and moves the write revision of the ones it writes. A write is{ write = bufferName, offset?, values, unsigned?, slots?, when? }:offsetin 32-bit words,valueswritten as f32 (u32 whenunsigned),slotsmapping a value's place, from 1, to the slot that gives it.whennames a slot: a run giving it 0 leaves the entry out.
Returns boolean — True once the registration is queued.
typed/builtin//modules/api/engine/compute/compute/program/listCost
compute.program.listCost(key: string) -> (number?, number?)
What recording the runs of the compute list under key has cost the
render side so far. A run is recorded on a frame after the one that queued
it, so a cost read just after runList holds the runs before that one.
Parameters
keystring— The list's key.
Returns (number?, number?) — The CPU milliseconds every run recorded took between them, and how many runs that was; nil when no list is registered under key.
typed/builtin//modules/api/engine/compute/compute/program/record
compute.program.record(fn: ({ { [string]: any } }) -> ()) -> { { [string]: any } }
Run fn and answer every compute.program.dispatch it made, in order,
as the entries of a compute list: { program, buffers, workgroups, params }
each. The dispatches are queued as they always are; the answer is what
compute.program.list takes to replay them. fn is handed the entries as
they are made, so it can add slots to one it just dispatched.
Parameters
fn({ { [string]: any } }) -> ()— The work to run, given the entries recorded so far.
Returns { { [string]: any } } — The dispatches fn made, as list entries.
typed/builtin//modules/api/engine/compute/compute/program/registered
compute.program.registered(key: string) -> boolean
Whether a program compiled under key by compute.program.compile is still registered: false once it was
destroyed by compute.program.destroy or closed by compute.resetToBaseline, and for a key nothing compiled.
A table read, so a caller that keeps a program's name between uses can ask before every use instead of
asking the engine; the device registers the program again after a rebuild.
Parameters
keystring— The program's key.
Returns boolean — True while the program stands.
if not compute.program.registered(key) then compute.program.compile(key, spec) end
typed/builtin//modules/api/engine/compute/compute/program/runList
compute.program.runList(key: string, slots: { [string]: number }?, label: string?) -> boolean
Queue the compute list under key: every entry in order, each value an
entry names a slot for taken from slots, every other value as the list
holds it. While the GPU profiler is read the run is recorded as a compute
pass of its own, and its GPU time is the compute.list:<label> row of the
gpu report.
Parameters
keystring— The list's key.slots{ [string]: number }(optional) — The value of each slot for this run, by name.labelstring(optional) — The name the run's GPU time is reported under; the list's key when absent.
Returns boolean — True once the run is queued.
typed/builtin//modules/api/engine/compute/compute/program/setParam
compute.program.setParam(key: string, prop: string, value: number) -> boolean
Write one scalar of the program's params: uniform. A value set before
the program's first compile is the value it starts with.
Parameters
keystring— The program's key.propstring— Parameter name as declared.valuenumber— New scalar value.
Returns boolean — True on success.
typed/builtin//modules/api/engine/compute/compute/program/spec
compute.program.spec(key: string) -> { [string]: any }?
The spec the program under key was compiled from (compute.program.compile): { source, entryPoint, bindings, params, ranges, ... } as it was filed, each #include naming the module it reached. Compiling it under
the same key in another engine makes the same program. A copy; nil for a key nothing compiled from a spec (a
program registered from a shader asset included), or one destroyed.
Parameters
keystring— The program's key.
Returns { [string]: any }? — The spec, or nil.
local spec = compute.program.spec(key)
typed/builtin//modules/api/engine/compute/compute/program/status
compute.program.status(key: string) -> { { [string]: any } }
What the engine did with the dispatches of the program under key,
one record per target.
Parameters
keystring— The program's key.
Returns { { [string]: any } } — Array of dispatch records, most recently dispatched first.
typed/builtin//modules/api/engine/compute/compute/program/target
compute.program.target(buffers: { string }) -> string
The target a dispatch over buffers is recorded against in
compute.program.status: the record its outcome lands in. A program
several callers dispatch over their own buffers has one record per
target, so this is how a caller picks out what became of its own
dispatches.
Parameters
buffers{ string }— The buffer names the dispatch binds, in binding order.
Returns string — The record's target.
local mine = compute.program.target({ "positions", "out" })
typed/builtin//modules/api/engine/compute/compute/programSource
compute.programSource(key: string) -> string?
The chunk that compiled the program registered under key, as
debug.info names a chunk: a module's identity, a test suite's, an
execute body's.
The record is the key's for as long as a program stands under it, across a
device rebuilt underneath it. A variant the ABI module compiles answers
for the chunk that asked for it. A .computeShader asset's program is
keyed by the asset's guid and answers for the .computeShader assetType,
which compiles it for the asset and releases it when the asset goes.
Parameters
keystring— The key the program was registered under.
Returns string? — The compiling chunk's name, or nil.
if compute.programSource("blur") then print("compiled under a key") end
typed/builtin//modules/api/engine/compute/compute/programState
compute.programState(ref: string | { [string]: any } | AssetRef) -> (string, string?)
Where a shader's compiled program stands. A registration is queued
from script and the pipeline is built on the render side frames later,
so the call that asked for the compile cannot say whether it produced a
program: "absent" (the engine holds nothing under this key and nothing
is in flight — never asked for, or released), "pending" (asked for, not
on the device yet — a recompile of a resident program reads pending too,
because what it produces is a different program from the one bound now),
"ready" (compiled and resident, so a dispatch binds it), or "failed"
(the most recent registration produced no program), returned with the
reason as a second value. A .computeShader whose bindings.yaml its
compile refuses reads "failed", with the reason naming the file and the
line, because no program is compiled from the file as it stands. Wait for
"ready" before a dispatch whose result is read back, rather than for a
count of frames.
Parameters
refstring | { [string]: any } | AssetRef— A.computeShaderidentity/guid string, a resolved asset handle, or the name a raw registration chose.
Returns (string, string?) — "absent", "pending", "ready" or "failed", and the reason when "failed".
if compute.programState(carve) == "ready" then carve:dispatch(opts) end
typed/builtin//modules/api/engine/compute/compute/readBuffer
compute.readBuffer(name: string) -> string
Start a GPU→CPU read of the buffer under name.
Parameters
namestring— The name it was created under.
Returns string — The result key to poll with getReadbackResult*. A read that could not start answers with the empty key, which every drain reports as unknown — the same shape a caller already handles.
typed/builtin//modules/api/engine/compute/compute/readTexture3D
compute.readTexture3D(name: string) -> string
Start a GPU→CPU readback of a named 3D volume. Returns a result key to poll.
Parameters
namestring
Returns string
typed/builtin//modules/api/engine/compute/compute/readbackPromise
compute.readbackPromise(resultKey: string) -> any
The promise that settles when a read-back reaches a terminal state,
delivered or given up on. task.await it to wait for the read without
polling: where the engine can wait on the device the coroutine resumes in
the frame the device answered, so a task that reads, uses the answer and
reads again does all of it in one frame; elsewhere it resumes on the next
frame the answer reaches the engine. Answers nil when the read-back is
not in flight (already delivered, failed, drained or never issued), and
readbackState() then says which.
Parameters
resultKeystring— Key returned byreadBuffer().
Returns any — A promise to await, or nil when there is nothing to wait for.
local promise = compute.readbackPromise(key); if promise then task.await(promise) end
typed/builtin//modules/api/engine/compute/compute/readbackState
compute.readbackState(resultKey: string) -> string
Where a readback key stands, without consuming it and without
raising: "pending" (issued, GPU has not delivered), "ready"
(delivered, waiting to be drained), "failed" (given up on, with the
reason as a second return), or "unknown" (never issued by
readBuffer(), or already drained — a result is delivered once).
Every read leaves "pending": one the GPU does not answer inside the
bound the engine holds it to reaches "failed" naming the buffer. A
wait on readbackState(key) ~= "pending" therefore ends on what the
read did, which a count of engine frames cannot say.
Parameters
resultKeystring— Key returned byreadBuffer().
Returns string — "pending", "ready", "failed" (and the reason), or "unknown".
if compute.readbackState(key) == "ready" then ... end
typed/builtin//modules/api/engine/compute/compute/registerShader
compute.registerShader(nameOrHandle: string | { [string]: any } | AssetRef, opts: ShaderOpts?) -> boolean
Register a compute shader. Accepts an asset handle from
asset.load(), or (name, opts) with inline WGSL source.
Parameters
nameOrHandlestring | { [string]: any } | AssetRef— Shader name or asset handle.optsShaderOpts(optional) — Shader options.bindingscomes from the source's own@group(0) @binding(n)declarations when omitted; supplying a count that disagrees with them raises. EveryreadOnlyBindingsentry names one of those declared bindings, as a whole number from 0 tobindings - 1; an entry outside that run raises.
Returns boolean — True on success.
compute.registerShader("blur", { source = WGSL, entryPoint = "main" })
typed/builtin//modules/api/engine/compute/compute/registerShaderEx
compute.registerShaderEx(nameOrHandle: string | { [string]: any } | AssetRef, opts: { [string]: any }?) -> boolean
Register a compute shader with extended texture/sampler bindings. Accepts a name + opts or an asset handle.
Parameters
nameOrHandlestring | { [string]: any } | AssetRefopts{ [string]: any }(optional)
Returns boolean
typed/builtin//modules/api/engine/compute/compute/releaseBaseline
compute.releaseBaseline(generation: number) -> boolean
Drop the mark generation names, and every mark taken after it, once
the caller that took it is done resetting to it. It touches the
marks alone.
Parameters
generationnumber— The mark to drop, ascompute.markBaselinereturned it.
Returns boolean — True when the mark stood.
compute.releaseBaseline(mark) -- the run is over
typed/builtin//modules/api/engine/compute/compute/resetToBaseline
compute.resetToBaseline(generation: number?) -> number
Release every compute resource allocated since compute.markBaseline,
except resources owned by standing render features. Restore the renderer
baseline first so resources of nonbaseline features are released. Resources
recorded by the mark are left where they are.
Each kind this closes is one a caller allocated under a name it chose, so
the next caller finds that name free. A storage buffer is such a resource
and is not closed here: every one a caller can make is a substrate buffer,
and substrate.resetToBaseline is what puts those back. A compiled
shader's params uniform is not, and is left where it is: it is filed under
its shader's guid, which no other caller can ask for, and it belongs to
the .computeShader asset that compiled it, released when that is.
mark is closed; nothing the mark recorded is touched.
Parameters
generationnumber(optional) — The mark to restore to, ascompute.markBaselinereturned it; the newest mark when omitted. The marks taken after it go with the reset.
Returns number — How many resources were released.
local released = compute.resetToBaseline(mark)
typed/builtin//modules/api/engine/compute/compute/resources
compute.resources(owner: any?) -> { any }
The resource rows on their own, optionally narrowed to what one shader owns.
Parameters
ownerany(optional) — A.computeShaderref, its guid, or its asset identity. Omit for every resource compute holds. A value carrying no shader raises, so a narrowing that cannot be done reads as an error rather than as the whole inventory. A guid stands for itself, so resources outlive the asset that made them and stay reachable by their owner.
Returns { any } — An array of rows in the shape compute.observe().resources carries. Empty when the owner holds nothing.
for _, r in ipairs(compute.resources(shaderRef)) do print(r.key, r.bytes) end
typed/builtin//modules/api/engine/compute/compute/setParam
compute.setParam(nameOrHandle: string | { [string]: any } | AssetRef, prop: string, value: number) -> boolean
Set a named scalar parameter on a .computeShader (a params:
entry in its bindings.yaml). Updates the shader's params uniform
in place; the next dispatch sees the new value. No effect on raw
registerShader shaders, which have no params block.
Parameters
nameOrHandlestring | { [string]: any } | AssetRef— Shader identity (the.computeShaderasset name), or the handleasset.load/asset.resolvereturns — the same formsdispatchtakes.propstring— Parameter name as declared inbindings.yaml.valuenumber— New scalar value (numbers only).
Returns boolean — True on success.
compute.setParam("my_sim", "scale", 4.0)
typed/builtin//modules/api/engine/compute/compute/stepBvh
compute.stepBvh(id: number, budgetMs: number?) -> (string?, string?)
Advance a build by as many work units as budgetMs buys, and report
whether it has finished: "pending" means there is work left,
"ready" means compute.finishBvh will hand over the buffers. The
slices carry the hierarchy onto the GPU as well as building it, so a
build that reads "ready" has already uploaded every byte of itself. A
slice always runs at least one unit, so a budget of 0 advances the build
by exactly one and the largest single unit sets the floor under a slice.
Parameters
idnumber— Build id fromcompute.beginBvh.budgetMsnumber(optional) — Wall time this slice may spend, in milliseconds (default 4).
Returns (string?, string?) — "pending" or "ready", or (nil, err) when the id names no build.
while compute.stepBvh(id, 4) == "pending" do task.wait() end
typed/builtin//modules/api/engine/compute/compute/textureForPlugin
compute.textureForPlugin(name: string) -> any
The texture this script created under name as a handle a script
passes a plugin in a call. The handle holds the texture by an id of its
own, never by the name: once the texture is destroyed the handle refuses,
even when the name is made again. Only a texture made by
compute.createTexture3D or compute.createStorageTexture2D can be
handed over.
Parameters
namestring— The texture's name.
Returns any — A handle for a plugin call.
typed/builtin//modules/api/engine/compute/compute/textureFormatBytes
compute.textureFormatBytes(format: string) -> number
Bytes-per-voxel for a texture format string (rgba16f, r8, ...).
Parameters
formatstring
Returns number
typed/builtin//modules/api/engine/compute/compute/writeBuffer
compute.writeBuffer(name: string, values: { number } | buffer | string, offset: number?) -> boolean
Write words into the buffer under name.
Parameters
namestring— The name it was created under.values{ number } | buffer | string— The floats to write, or abuffer/ binary string already holding them.offsetnumber(optional) — 32-bit word offset to write at.
Returns boolean — True on success.
typed/builtin//modules/api/engine/compute/compute/writeBufferBytes
compute.writeBufferBytes(name: string, bytes: buffer | string, offsetBytes: number?) -> boolean
Write packed bytes into the buffer under name.
Parameters
namestring— The name it was created under.bytesbuffer | string— The payload.offsetBytesnumber(optional) — Byte offset to write at.
Returns boolean — True on success.
typed/builtin//modules/api/engine/compute/compute/writeBufferU32
compute.writeBufferU32(name: string, values: { number } | buffer | string, offsetBytes: number?) -> boolean
Write 32-bit words into the buffer under name.
Parameters
namestring— The name it was created under.values{ number } | buffer | string— The words to write.offsetBytesnumber(optional) — Byte offset to write at.
Returns boolean — True on success.
typed/builtin//modules/api/engine/compute/compute/writeFloatsTexture3D
compute.writeFloatsTexture3D(name: string, floats: { number }, formatOrOpts: (string | { [string]: any })?) -> boolean
Upload float values into a named 3D volume, packed via the given format (default rgba16f).
Parameters
namestringfloats{ number }formatOrOpts(string | { [string]: any })(optional)
Returns boolean
typed/builtin//modules/api/engine/compute/compute/writeTexture3D
compute.writeTexture3D(name: string, data: buffer | string | { number }) -> boolean
Upload raw bytes (u8) into a named 3D volume. A buffer or a binary
string holds the volume's byte layout verbatim and crosses in one copy —
the shape a file's voxel payload arrives in; an array carries one byte
value (0..255) per entry.
Parameters
namestring— Volume name.databuffer | string | { number }— Voxel bytes as abuffer, a binary string, or an array of bytes.
Returns boolean — True on success (mutation queued).
typed/builtin//modules/api/engine/debugger/debugger/__diagnostics
debugger.__diagnostics() -> DebuggerDiagnostics
Internal diagnostic counters for debugging the debugger
itself: { installs, debugbreakHits }.
Returns DebuggerDiagnostics — Diagnostic counters.
typed/builtin//modules/api/engine/debugger/debugger/addWatch
debugger.addWatch(expr: string) -> number
Register an expression to re-evaluate on every pause.
Parameters
exprstring— Luau expression.
Returns number — Watch id.
typed/builtin//modules/api/engine/debugger/debugger/continue_
debugger.continue_() -> boolean
Resume the paused thread. The thread resumes on the next scheduler tick. A task's thread settles like any resumed task: a wait it reaches is armed, what it returns is its result, and an error it raises is the task's error, reported the way every task error is. A task cancelled while paused does not run on. A coroutine a task resumed itself runs on with nothing waiting for it, and an error it raises is logged.
Returns boolean — True if a thread was paused, false if nothing was paused.
typed/builtin//modules/api/engine/debugger/debugger/disableAll
debugger.disableAll()
Disable every registered breakpoint. Records persist; bytecode BREAK ops are cleared.
typed/builtin//modules/api/engine/debugger/debugger/disconnect
debugger.disconnect(handle: number) -> boolean
Disconnect an onBreak or onResume callback.
Parameters
handlenumber— Handle returned by onBreak/onResume.
Returns boolean — True if the handle existed.
typed/builtin//modules/api/engine/debugger/debugger/enableAll
debugger.enableAll()
Enable every registered breakpoint and re-install them in the VM bytecode.
typed/builtin//modules/api/engine/debugger/debugger/evaluate
debugger.evaluate(expr: string, frame: number?) -> (string?, string?)
Evaluate an expression against the paused frame's
environment. Returns (value, error).
Parameters
exprstring— Luau expression.framenumber(optional) — 1-based frame index (default 1).
Returns (string?, string?) — (value, error).
typed/builtin//modules/api/engine/debugger/debugger/getLocals
debugger.getLocals(frame: number?) -> { [string]: string }
Locals captured at the active pause for the given frame index (1 = top). Values are stringified for safe display.
Parameters
framenumber(optional) — 1-based frame index (default 1).
Returns { [string]: string } — { [name] = string }.
typed/builtin//modules/api/engine/debugger/debugger/getPauseInfo
debugger.getPauseInfo() -> PauseInfo?
Info about the active pause, or nil if nothing is paused.
Returns PauseInfo? — { path, line, reason } or nil.
typed/builtin//modules/api/engine/debugger/debugger/getStack
debugger.getStack() -> { Frame }
Captured stack from the active pause, top frame first. Empty when nothing is paused.
Returns { Frame } — Array of Frame tables.
typed/builtin//modules/api/engine/debugger/debugger/getUpvalues
debugger.getUpvalues(frame: number?) -> { [string]: string }
Upvalues captured at the active pause for the given frame.
Parameters
framenumber(optional) — 1-based frame index.
Returns { [string]: string } — { [name] = string }.
typed/builtin//modules/api/engine/debugger/debugger/getWatchValue
debugger.getWatchValue(id: number) -> (string?, string?)
Re-evaluate the watch expression against the paused frame's
environment and return (value, error).
Parameters
idnumber— Watch id.
Returns (string?, string?) — (value, error).
typed/builtin//modules/api/engine/debugger/debugger/getWatches
debugger.getWatches() -> { Watch }
Snapshot of all watches with their last evaluated value and error, sorted by id.
Returns { Watch } — Array of Watch tables.
typed/builtin//modules/api/engine/debugger/debugger/isPauseOnError
debugger.isPauseOnError() -> boolean
Current pause-on-error toggle state for this VM.
Returns boolean — True if enabled.
typed/builtin//modules/api/engine/debugger/debugger/isPaused
debugger.isPaused() -> boolean
Whether the debugger currently has a paused thread.
Returns boolean — True if paused.
typed/builtin//modules/api/engine/debugger/debugger/listBreakpoints
debugger.listBreakpoints() -> { Breakpoint }
Snapshot of every registered breakpoint, sorted by id
ascending. Each entry reports whether it is installed:
chunkNames lists the loaded chunks carrying it, and
pendingReason says why an empty list is empty.
Returns { Breakpoint } — Array of breakpoint tables.
typed/builtin//modules/api/engine/debugger/debugger/onBreak
debugger.onBreak(fn: (PauseInfo) -> ()) -> number
Register a callback invoked on every pause with
{ path, line, reason }. Returns a handle usable with
debugger.disconnect.
Parameters
fn(PauseInfo) -> ()— Callback.
Returns number — Handle.
typed/builtin//modules/api/engine/debugger/debugger/onResume
debugger.onResume(fn: () -> ()) -> number
Register a callback invoked when the paused thread is resumed.
Parameters
fn() -> ()— Callback.
Returns number — Handle.
typed/builtin//modules/api/engine/debugger/debugger/removeBreakpoint
debugger.removeBreakpoint(id: number) -> boolean
Remove the breakpoint with the given id.
Parameters
idnumber— Breakpoint id returned by setBreakpoint.
Returns boolean — True if removed, false if the id was unknown.
typed/builtin//modules/api/engine/debugger/debugger/removeWatch
debugger.removeWatch(id: number) -> boolean
Remove the watch with the given id.
Parameters
idnumber— Watch id.
Returns boolean — True if removed.
typed/builtin//modules/api/engine/debugger/debugger/setBreakpoint
debugger.setBreakpoint(path: string, line: number, opts: BreakpointOpts?) -> Breakpoint
Set a breakpoint at line in the script path names — its
VFS path, its require identity, or the chunk name it loaded
under. An installed breakpoint carries resolvedLine and lists
the loaded chunks holding it in chunkNames; one whose script is
not loaded carries pendingReason, an empty chunkNames, and
installs itself when that script loads.
Parameters
pathstring— VFS path, require identity, or chunk name.linenumber— 1-based source line.optsBreakpointOpts(optional) —{ condition?, logMessage?, hitCount?, notify?, enabled? }.notifymakes it a TRACEPOINT: the hit firesonBreakhandlers against the frame it stopped in —getStack,getLocals,getUpvaluesandevaluateall answer for that frame — and then runs on, instead of holding the thread until something resumes it. That is how code observes a moment without stopping it; halting is for a person at a keyboard. A breakpoint on any line drops the enclosing function out of native code until its chunk reloads, so one left armed on a per-frame function costs more than it reports.
Returns Breakpoint — The breakpoint table.
local bp = debugger.setBreakpoint("/zero/source/main.luau", 42)
print(bp.pendingReason or ("installed in " .. bp.chunkNames[1]))
typed/builtin//modules/api/engine/debugger/debugger/setPauseOnError
debugger.setPauseOnError(enabled: boolean)
When true, uncaught Luau errors fire the onBreak callback (observation only — the error still propagates).
Parameters
enabledboolean— Toggle state.
typed/builtin//modules/api/engine/debugger/debugger/stepInto
debugger.stepInto() -> boolean
Run until the next line, descending into any function call.
Returns boolean — True if a step was scheduled.
typed/builtin//modules/api/engine/debugger/debugger/stepOut
debugger.stepOut() -> boolean
Run until the current frame returns; pauses in the caller.
Returns boolean — True if a step was scheduled.
typed/builtin//modules/api/engine/debugger/debugger/stepOver
debugger.stepOver() -> boolean
Run until the next line in the current frame. Calls inside the current line are skipped.
Returns boolean — True if a step was scheduled.
typed/builtin//modules/api/engine/debugger/debugger/toggleBreakpoint
debugger.toggleBreakpoint(path: string, line: number) -> Breakpoint?
Toggle a breakpoint at the given line: removes if present, adds otherwise.
Parameters
pathstring— VFS path, require identity, or chunk name.linenumber— 1-based line.
Returns Breakpoint? — Breakpoint table if added, nil if removed.
typed/builtin//modules/api/engine/ecs/blobs/blobs/clear
blobs.clear(handle: string)
Drop a staged payload that will not be consumed, freeing its memory.
Parameters
handlestring— Handle returned byecs.blobs.set.
ecs.blobs.clear(handle)
typed/builtin//modules/api/engine/ecs/blobs/blobs/get
blobs.get(handle: string) -> string?
Read back a copy of the bytes staged under handle without removing
them. Returns nil for an unknown or already-cleared handle.
Parameters
handlestring— Handle returned byecs.blobs.set.
Returns string? — The staged bytes, or nil.
local bytes = ecs.blobs.get(handle)
typed/builtin//modules/api/engine/ecs/blobs/blobs/set
blobs.set(bytes: string) -> string
Stage binary bytes and return a handle to pass through a component field; a native consumer reads the bytes back by that handle.
Parameters
bytesstring— Binary payload (e.g.vfs.read(clipPath .. "/data.zaud")).
Returns string — String handle for the staged bytes.
local h = ecs.blobs.set(assert(vfs.read(path .. "/data.zaud")))
typed/builtin//modules/api/engine/egress/egress/credentialNames
egress.credentialNames() -> { string }
List the names in the local credential store. Names only — secret values are never exposed to Luau.
Returns { string } — Array of configured credential names.
for _, n in ipairs(egress.credentialNames()) do print(n) end
typed/builtin//modules/api/engine/egress/egress/fetch
egress.fetch(name: string, method: string, url: string, headers: Headers?, body: JsonBody?, response: EgressResponseType?) -> PromiseHandle?
Perform an HTTP request using a named credential. A bound world
forwards the request to ZeroMind, which resolves its world secret and
enforces the allowed destination. Await the returned handle; a refused
forwarded request returns the HTTP error JSON with __http_error = true.
With a local credential store, an unknown name or a URL outside its
allowed prefix returns nil immediately. Credential values stay with
the store or forwarding server and never enter world code.
Parameters
namestring— Local credential name or bound-world secret handle.methodstring— HTTP method, e.g. "GET" or "POST".urlstring— Request URL allowed by the selected credential's destination rules.headersHeaders(optional) — Extra header key-value pairs.bodyJsonBody(optional) — JSON body (encoded automatically).responseEgressResponseType(optional) —"json"(default) or"bytes".
Returns PromiseHandle? — Promise handle for task.await(), or nil on an immediate local refusal.
local h = egress.fetch("meshy", "POST", url, nil, { prompt = p })
typed/builtin//modules/api/engine/egress/egress/hasCredential
egress.hasCredential(name: string) -> boolean
Whether the local credential store holds a name. Returns only a boolean. World secrets are resolved by ZeroMind when a forwarded request runs; this probe answers for the local store.
Parameters
namestring— Credential name.
Returns boolean — True if configured.
if not egress.hasCredential("meshy") then error("set MESHY_API_KEY") end
typed/builtin//modules/api/engine/engine/M/editWaiters
M.editWaiters() -> { EditWaiter }
Everyone waiting for this engine to leave play so their edit-mode work
can run, oldest first. Each entry is { key, id, name, reason, heldSeconds }: id is the waiting caller, the same value
vfs.currentAuthor().id reads, and heldSeconds is how long it has been
waiting. A session holding play reads this to see whose work it is
holding. Empty in edit mode and whenever nobody has said they are waiting.
Returns { EditWaiter } — The waiter records.
for _, who in ipairs(engine.editWaiters()) do
log.warn(("%s has waited %.0fs for edit mode"):format(who.name or who.key, who.heldSeconds))
end
typed/builtin//modules/api/engine/engine/M/engineRecord
M.engineRecord(record: { [any]: any })
Declare record an engine record: a table a subsystem keeps as its
own account of what the engine holds — the renderer's registry of live
features, its capture views — and puts back through its own reset.
engine.snapshotModuleState neither copies nor walks it, and
engine.restoreModuleState leaves it as that reset left it, so a module
restore never seats a record back around what the reset did: a feature a
suite destroyed stays destroyed, and one it made again under its identity
stays the one the renderer ticks.
Parameters
record{ [any]: any }— The table.
engine.engineRecord(activeFeatures)
typed/builtin//modules/api/engine/engine/M/holdTimeScale
M.holdTimeScale(scale: number, options: TimeScaleHoldOptions?) -> () -> ()
Run the simulation at scale for as long as the hold stands, and
return the release. engine.timeScale is one number for the whole
process, so a rate one agent sets is the rate every other agent's
entities and measurements run at; a hold records who set it and refuses a
plain engine.timeScale write from anywhere else while it stands, so the
rate cannot move under a measurement without the measurement hearing
about it.
Holds nest: the innermost names the rate, and the rate that stood before
the outermost is back once the last release is called. Each release takes
its own hold off the stack whatever order the releases come in.
exclusive takes the rate for the owner key the call states: while that
hold stands, a hold is admitted only when it states the same key, and
every other one is refused with an error naming the key and the rate. That
is what lets one caller pin the rate its run is measured at while another
agent drives the same engine.
Parameters
scalenumber— The rate to run at: 1 is real time, 0.5 half speed, 0 frozen, 2 double. Finite and>= 0.optionsTimeScaleHoldOptions(optional) —owneris the key this hold is taken under, a non-empty string, and an exclusive hold states one. A hold that states no key takes the key of the agent the call is attributed to, or a mintedhold#nwhen the call carries no agent identity, so every hold answers to a keyengine.releaseTimeScaleaccepts andengine.timeScaleOwnerreports asid.exclusivetakes the rate for the stated key until the hold is released.
Returns () -> () — A function that releases this hold. Calling it twice releases once.
local release = engine.holdTimeScale(0.08) ; task.wait(0.12) ; release()
local release = engine.holdTimeScale(1, { exclusive = true, owner = "duel-measurement" })
typed/builtin//modules/api/engine/engine/M/inBackground
M.inBackground() -> boolean
Whether the app is in the background now: the engine's Android
activity is stopped, the desktop window is minimized, or the browser tab
is hidden. engine.onBackgroundChange fires on each change.
Returns boolean — True while the app is in the background.
if engine.inBackground() then return end -- nobody sees this frame
typed/builtin//modules/api/engine/engine/M/markBaseline
M.markBaseline() -> number
Read this module's own memory — the time-scale holds standing, who
wrote the rate last, the rate that stood before any hold, the
onTimeScaleChange subscribers and the highest watcher id each registry
has handed out — and answer with a generation engine.resetToBaseline
puts exactly that back from. Take it once, before the work whose changes
are to be undone.
Returns number — The generation of this reading.
local mark = engine.markBaseline() -- then run, then engine.resetToBaseline(mark)
typed/builtin//modules/api/engine/engine/M/markScriptingBaseline
M.markScriptingBaseline() -> number
Record the scripting registries — world-event subscriptions, the
four lifecycle-watcher lists, and the require cache — as they stand
right now, as a mark engine.resetScriptingState() restores to. Marks
stack: a reset names the generation it restores to, and the marks taken
after that one go with it. Returns the new mark's generation, counting
from 1.
Mark once the engine is serving rather than while it boots: the
registries keep growing as the prelude subscribes, the world
entrypoint runs and the startup scene loads, so a mark taken partway
through sits below the rest of that work and the first reset would
remove it.
Returns number
engine.markScriptingBaseline()
world.on("player_join", function() end)
engine.resetScriptingState() -- the subscription above is gone
typed/builtin//modules/api/engine/engine/M/offBackgroundChange
M.offBackgroundChange(id: number) -> boolean
Remove an engine.onBackgroundChange subscriber by its watcher id.
Returns true when a live watcher carried that id, false when it named
none: already removed, or never registered.
Parameters
idnumber— Watcher id returned byengine.onBackgroundChange.
Returns boolean
local id = engine.onBackgroundChange(function() end)
engine.offBackgroundChange(id)
typed/builtin//modules/api/engine/engine/M/offDeviceRebuilt
M.offDeviceRebuilt(id: number) -> boolean
Remove an engine.onDeviceRebuilt subscriber by its watcher id.
Returns true when a live watcher carried that id, false when it named
none — already removed, or never registered.
Parameters
idnumber— Watcher id returned byengine.onDeviceRebuilt.
Returns boolean
local id = engine.onDeviceRebuilt(function() end)
engine.offDeviceRebuilt(id)
typed/builtin//modules/api/engine/engine/M/offMemoryPressure
M.offMemoryPressure(id: number) -> boolean
Remove an engine.onMemoryPressure subscriber by its watcher id.
Returns true when a live watcher carried that id, false when it named
none: already removed, or never registered.
Parameters
idnumber— Watcher id returned byengine.onMemoryPressure.
Returns boolean
local id = engine.onMemoryPressure(function() end)
engine.offMemoryPressure(id)
typed/builtin//modules/api/engine/engine/M/offModeChange
M.offModeChange(id: number) -> boolean
Remove an engine.onModeChange subscriber by its watcher id.
Returns true when a live watcher carried that id, false when it
named none — already removed, or never registered.
Parameters
idnumber— Watcher id returned byengine.onModeChange.
Returns boolean
local id = engine.onModeChange(function() end)
engine.offModeChange(id)
typed/builtin//modules/api/engine/engine/M/offPauseChange
M.offPauseChange(id: number) -> boolean
Remove an engine.onPauseChange subscriber by its watcher id.
Returns true when a live watcher carried that id, false when it
named none.
Parameters
idnumber— Watcher id returned byengine.onPauseChange.
Returns boolean
typed/builtin//modules/api/engine/engine/M/offTimeScaleChange
M.offTimeScaleChange(id: number) -> boolean
Remove an engine.onTimeScaleChange subscriber by its watcher id.
Returns true when a live watcher carried that id, false when it named
none.
Parameters
idnumber— Watcher id returned byengine.onTimeScaleChange.
Returns boolean
local id = engine.onTimeScaleChange(function() end)
engine.offTimeScaleChange(id)
typed/builtin//modules/api/engine/engine/M/offWorldLoaded
M.offWorldLoaded(id: number) -> boolean
Remove an onWorldLoaded subscriber by its watcher id.
Parameters
idnumber
Returns boolean
typed/builtin//modules/api/engine/engine/M/offWorldReady
M.offWorldReady(id: number) -> boolean
Remove an engine.onWorldReady subscriber by its watcher id.
Returns true when a live watcher carried that id, false when it
named none.
Parameters
idnumber— Watcher id returned byengine.onWorldReady.
Returns boolean
typed/builtin//modules/api/engine/engine/M/offWorldUnloading
M.offWorldUnloading(id: number) -> boolean
Remove an engine.onWorldUnloading subscriber by its watcher
id. Returns true when a live watcher carried that id, false when it
named none.
Parameters
idnumber— Watcher id returned byengine.onWorldUnloading.
Returns boolean
typed/builtin//modules/api/engine/engine/M/onBackgroundChange
M.onBackgroundChange(callback: (boolean, string) -> ()) -> number
Register a callback that fires when the app goes into the background
and again when it comes back. The callback receives whether the app is
in the background now and who reported it: "android" (the engine's
activity was stopped or started), "window" (the desktop window was
minimized or restored), "page" (the browser tab was hidden or shown) or
"script" (engine.signalBackground). Returns a watcher id.
The platform may end the process at any moment once the app is in the
background, with no further frame: Android ends a stopped app to take its
memory back, and a browser discards a hidden tab. Save what the player
would lose here: write it to runtime_data, which the next session reads
back. The world's /source writes are kept already: each is recorded on
the device as it is made and reaches the world when a session next
connects. The engine writes what it keeps across launches before this
fires.
While the app is in the background the engine keeps running, more slowly, and draws nothing.
Parameters
callback(boolean, string) -> ()— Function invoked as(inBackground: boolean, source: string).
Returns number
engine.onBackgroundChange(function(inBackground, source)
if inBackground then
runtime_data.player(runtime_data.localId()).set("save/checkpoint", { level = 3, coins = 120 })
end
end)
typed/builtin//modules/api/engine/engine/M/onDeviceRebuilt
M.onDeviceRebuilt(callback: (number) -> ()) -> number
Register a callback that fires after the engine has answered a lost render device by building another one. The callback receives the new device generation — a number that counts the devices this session has run on, and moves exactly once per rebuild. Returns a watcher id.
A device is lost when the driver resets, when the GPU is taken away, or when a browser reclaims a WebGPU context. Everything the engine can re-derive by itself it does: meshes, materials, shaders, render passes and the UI are all back on the new device before this fires. What it cannot re-derive is what YOUR content made and only the GPU held — a texture uploaded from pixels a script computed, a compute buffer it filled, a render target it created. Make those again here.
Content that owns no GPU resource of its own needs no subscriber: asset handles re-materialise on their next use.
Parameters
callback(number) -> ()— Function invoked as(generation: number).
Returns number
engine.onDeviceRebuilt(function(generation)
-- the noise field lived only on the GPU, so it is computed again
print("upload the noise field again for device generation", generation)
end)
typed/builtin//modules/api/engine/engine/M/onMemoryPressure
M.onMemoryPressure(callback: (string, string) -> ()) -> number
Register a callback that fires when the system says it is short of
memory, after the engine has released what that level of pressure
releases. The callback receives the level ("normal", "moderate",
"low" or "critical") and who reported it: onTrimMemory(<level>) for
Android's report, script for renderer.signalMemoryPressure. Returns a
watcher id.
The engine frees what it can rebuild by itself: mip levels the frame does
not sample, render-target storage nothing is drawing into, and from
"critical" half the texture budget. What it cannot free is what YOUR
content keeps: a cache of generated meshes, a table of decoded audio,
pixels kept for a later upload. Drop those here and build them again when
they are next needed. A level stands for a minute after the last report,
and renderer.memoryPressure() reads the level in force and what the
engine released.
Parameters
callback(string, string) -> ()— Function invoked as(level: string, source: string).
Returns number
engine.onMemoryPressure(function(level, source)
if level ~= "normal" then
decodedClips = {} -- decoded again on next play
end
end)
typed/builtin//modules/api/engine/engine/M/onModeChange
M.onModeChange(callback: (string, string) -> ()) -> number
Parameters
callback(string, string) -> ()
Returns number
typed/builtin//modules/api/engine/engine/M/onPauseChange
M.onPauseChange(callback: (boolean, boolean) -> ()) -> number
Register a callback that fires synchronously whenever the gameplay
pause flag flips via an explicit engine.paused write. Callback
receives (newPaused, oldPaused) as booleans. Returns a watcher id.
Pause is independent of engine.mode: pausing play mode returns the
editor authoring surface (free camera + EditorOnly entities) over the
frozen play world, and resuming hides it again. Mode-driven pause
resets (the edit=paused / play=running defaults applied on a mode flip)
are delivered through onModeChange, not this hook.
Parameters
callback(boolean, boolean) -> ()— Function invoked as(newPaused: boolean, oldPaused: boolean).
Returns number
local id = engine.onPauseChange(function(paused)
print(paused and "frozen" or "running")
end)
typed/builtin//modules/api/engine/engine/M/onTimeScaleChange
M.onTimeScaleChange(callback: (number, number, TimeScaleOwner?) -> ()) -> number
Register a callback that fires on every move of the simulation rate,
whoever moved it: an engine.timeScale write, a hold taken at a rate
other than the one in force, a release that hands a different rate back.
The callback receives (newScale, oldScale, owner), where owner is the
record engine.timeScaleOwner answers with. It counts transitions, so a
write or a hold landing on the rate already in force moves nothing and
announces nothing; engine.timeScaleOwner is what answers who holds a
rate that has stayed where it is. Several agents drive one engine at once,
so this is how a run whose numbers depend on the rate learns that somebody
else moved it instead of reading the number and finding out afterwards.
Returns a watcher id.
Parameters
callback(number, number, TimeScaleOwner?) -> ()— Function invoked as(newScale: number, oldScale: number, owner: TimeScaleOwner?).
Returns number
local id = engine.onTimeScaleChange(function(new, old, who)
log.warn(("rate %g -> %g by %s"):format(old, new, who and who.id or "nobody"))
end)
typed/builtin//modules/api/engine/engine/M/onWorldLoaded
M.onWorldLoaded(callback: () -> ()) -> number
Register a callback fired (no args) when the world is fully
LOADED — its .world_entrypoint.luau ran AND its onWorldLoad
returned (the startup scene loaded, defaults seeded, editor UI
mounted). This is strictly AFTER onWorldReady (content synced):
ready = "bytes are in the VFS"; loaded = "the entrypoint has run".
LATCHED — a callback registered after the world is already loaded
fires immediately, so a late consumer never misses it and never has
to poll. Read the same state synchronously via engine.worldLoaded.
Parameters
callback() -> ()— Function invoked with no arguments.
Returns number
typed/builtin//modules/api/engine/engine/M/onWorldReady
M.onWorldReady(callback: () -> ()) -> number
Register a callback fired (no args) when the bound world's
content has been synced into the VFS, the packages the world
installs have materialized, and the world is ready to load. This
is the race-free, user-space hook that drives the whole world-VM
lifecycle: the builtin world-entrypoint loader subscribes
to it and, when it fires, loadstring(vfs.read(...))s
/source/.world_entrypoint.luau and runs its onWorldLoad —
exactly the way a scene entrypoint loads. The trusted VM fires this
(via world.markReady()) ONLY once the bytes are in the VFS, so a
subscriber never sees a half-synced world. Returns a watcher id.
Parameters
callback() -> ()— Function invoked with no arguments.
Returns number
typed/builtin//modules/api/engine/engine/M/onWorldUnloading
M.onWorldUnloading(callback: () -> ()) -> number
Symmetric teardown of engine.onWorldReady: register a callback
fired (no args) when the bound world is unbinding/swapping out. The
builtin loader runs the world entrypoint's onWorldUnload here, so
the world entrypoint has the same load/unload parity a scene
entrypoint has. Returns a watcher id.
Parameters
callback() -> ()— Function invoked with no arguments.
Returns number
typed/builtin//modules/api/engine/engine/M/releaseBaseline
M.releaseBaseline(generation: number) -> boolean
Drop the mark generation names, and every mark taken after it, once
the caller that took it is done resetting to it. It touches the
marks alone.
Parameters
generationnumber— The mark to drop, asengine.markBaselinereturned it.
Returns boolean — True when the mark stood.
engine.releaseBaseline(mark) -- the run is over
typed/builtin//modules/api/engine/engine/M/releaseScriptingBaseline
M.releaseScriptingBaseline(generation: number) -> boolean
Drop the scripting mark generation names, and every mark taken
after it, once the caller that took it is done resetting to it. The
registries stay as they stand, and a watcher removed since that only the
dropped marks stood to put back is let go. A mark holds the require cache's keys as
they stood, so a caller that marks once per run drops each mark when its
run is over.
Parameters
generationnumber— The mark to drop, asengine.markScriptingBaselinereturned it.
Returns boolean — True when the mark was in force.
engine.releaseScriptingBaseline(mark) -- the run is over
typed/builtin//modules/api/engine/engine/M/releaseTimeScale
M.releaseTimeScale(owner: string) -> number
Parameters
ownerstring
Returns number
typed/builtin//modules/api/engine/engine/M/resetScriptingState
M.resetScriptingState(generation: number?) -> { [string]: number }
Drop every world-event subscription, lifecycle watcher and
cached module registered since the mark generation names — the
newest engine.markScriptingBaseline() when omitted — leaving
everything registered before it in place, including the builtin
world-entrypoint loader, which subscribes at VM boot and so always
sits below any mark. A subscription or watcher that stood at the mark
and was removed since goes back in under its own id, with the record of
who registered it (engine.watcherSources), when its callback is a
closure of a module the mark held in the require cache and no component
instance's own code removed it. The marks taken after that
one go with the reset. A module with a frame on the stack keeps its cache entry and
its registrations. Raises when no such mark is in force. Returns
per-registry counts of what was removed: worldEvents,
modeWatchers, worldReadyWatchers, worldUnloadingWatchers,
pauseWatchers, deviceRebuiltWatchers, memoryPressureWatchers,
backgroundWatchers, modules, and total.
Parameters
generationnumber(optional) — The generation to restore to, asmarkScriptingBaselinereturned it; the newest mark when omitted.
Returns { [string]: number }
typed/builtin//modules/api/engine/engine/M/resetToBaseline
M.resetToBaseline(generation: number?) -> number
Put this module's own memory back as engine.markBaseline read it:
every time-scale hold taken since comes off, every onTimeScaleChange
subscriber added since is removed, the last writer and the base rate read
as they did, the rate in force follows, and the record of who registered
each watcher forgets the ids handed out since. The marks taken after
generation go with the reset.
Parameters
generationnumber(optional) — The mark to restore to; the newest when omitted.
Returns number — How many things were put back.
engine.resetToBaseline(mark)
typed/builtin//modules/api/engine/engine/M/restoreModuleState
M.restoreModuleState(snapshot: { [string]: any }, options: { remint: { [string]: string }?, gone: ((any) -> boolean)?, successor: ((any) -> any?)?, only: { [string]: boolean }? }?) -> { [string]: any }
Put every module's state back to what engine.snapshotModuleState
read. A table is refilled in place, so a closure holding it sees the
restored contents, and the upvalue is pointed back at it, so a module that
assigned its local a new table is reading the restored one again.
The same snapshot restores to the same state however many times it is used, so one reading taken before a run puts every later point in that run back to it.
A value whose reading names an object the engine no longer holds — a
buffer whose storage was destroyed since, answering alive false — is
left as it stands: what it remembered cannot be given back to it, and
what it holds now is what it went on to make. The module holding it is
left whole, because what it remembers beside that object — the count it
sized the object for, the flag that says it made one — is the state of
the object it now holds instead; it is counted under stale. A data
table naming a gone object in one of its fields is a registry, and is
refilled around that field.
Called from a coroutine that can yield, the restore gives the frame back every few milliseconds.
the engine re-minted since replaced by the id it now uses.
Parameters
snapshot{ [string]: any }options{ remint: { [string]: string }?, gone: ((any) -> boolean)?, successor: ((any) -> any?)?, only: { [string]: boolean }? }(optional) —remintmaps an id the reading holds to the id the engine now uses for the same thing — a render feature's guid after the feature was made again under its identity.goneanswers whether a value the reading holds names something the engine no longer holds — a record carrying a render feature's guid when no feature carries it now; a handle answeringalivefalse is known without it.successoranswers, for an object that has gone, the live object standing in for it — the handle under a buffer's name after the buffer was made again under it — and the reading is put back holding that one, its own fields left as they are. A handle that already answeredalivefalse when the reading was taken is the module's own record of something gone before it, and is put back as it is.sameanswers whether a value a module holds now already stands in for the gone object a successor was found for — the module's own live handle to the buffer made again under the name — and such a value is kept, the successor released.onlynames the modules to put back, by module name, and every other module's reading is left untouched — a second pass over the modules an earlier one left as they stood, once what stands in for the objects they named exists.
Returns { [string]: any } — { restored, refused, recached, stale, staleModules, staleObjects, failed, failedModules } — how many values were written, how many the engine would not write, how many require-cache entries were put back to the module they held, how many modules hold a value left as it stood because its reading names something the engine no longer holds, and those modules by name, each with the gone object the reading named; then how many modules hold a value whose restore raised, and those by name with the error. A value whose restore raises is counted and passed over, and the rest of the reading is put back.
engine.restoreModuleState(snap)
engine.restoreModuleState(snap, { remint = { [oldGuid] = newGuid } })
typed/builtin//modules/api/engine/engine/M/scriptingRegistryCounts
M.scriptingRegistryCounts() -> { [string]: number }
How many subscriptions each scripting registry holds right now,
plus the size of the require cache and the generation of the mark in
force. Keys: worldEvents, modeWatchers, worldReadyWatchers,
worldUnloadingWatchers, pauseWatchers, deviceRebuiltWatchers,
memoryPressureWatchers, backgroundWatchers, modules, and baselineGeneration (nil when
no mark has been taken).
Returns { [string]: number }
typed/builtin//modules/api/engine/engine/M/setMode
M.setMode(mode: string, options: { strict: boolean?, endSession: boolean? }?) -> { mode: string, bypassed: { any }, leftPlaySession: boolean }
Change the engine mode with per-call control over the play gate, and
read back what the change went past. engine.mode = value is the same
flip with the defaults.
options.strict = false lets THIS call enter play while your own content
carries error-severity diagnostics. It settles with the call: the world's
lsp.strict_mode is untouched, so no other session and no later session
of the world sees a different gate. The returned bypassed array holds
the diagnostics the call went past — each { path, line, col, code, message, severity } — and the engine log carries the same list. An
error in content another session wrote never gates the flip, so it never
appears here; a push still refuses to publish while any of them stands.
Parameters
modestring—"edit"or"play".options{ strict: boolean?, endSession: boolean? }(optional) —{ strict: boolean?, endSession: boolean? }.strict = falsewaives the play gate for this call;trueor omitted honours the world'slsp.strict_mode.endSession = truewith"edit"ends the running play session for every caller in it, whether or not you take part, and answers for everything the session holds (engine.discardPlayChanges()arms its discard); without it, an"edit"from one of several callers in play takes only that caller out, and one from a caller outside the session is refused.
Returns { mode: string, bypassed: { any }, leftPlaySession: boolean } — { mode, bypassed, leftPlaySession }: the mode now in force, the diagnostics this call entered play past (empty when it went past none), and whether an "edit" took this caller out of a play session that keeps running for other callers, in which case mode still reads "play".
local report = engine.setMode("play", { strict = false })
for _, d in ipairs(report.bypassed) do
print(("entered play past %s:%d — %s"):format(d.path, d.line, d.message))
end
typed/builtin//modules/api/engine/engine/M/signalBackground
M.signalBackground(inBackground: boolean) -> boolean
Report the app going into the background (true) or coming back
(false) the way the platform does, so the path content takes on a
real backgrounding can be run on demand: the engine writes what it keeps
across launches and engine.onBackgroundChange subscribers hear it with
source "script" on the next frame. The live world session reacts as it
does to a hidden browser tab or a minimized window. A later report from
the platform that changes where the app is stands over it. Returns whether
the report changed what engine.inBackground() answers.
Parameters
inBackgroundboolean— Whether the app goes into the background.
Returns boolean — True when the report changed the app's presence.
engine.signalBackground(true) -- subscribers save on the next frame
engine.signalBackground(false)
typed/builtin//modules/api/engine/engine/M/snapshotModuleState
M.snapshotModuleState() -> { [string]: any }
Read the state every cached module holds — the upvalues of the closures
it hands back — and answer with it, so engine.restoreModuleState can put
exactly that back later.
Take it once, before the work whose changes are to be undone. Data is copied, so a table a module goes on mutating does not change what was read; an object — a table carrying a metatable or methods of its own — is kept by reference and its fields copied, so restoring returns the object every other holder is still attached to rather than a lookalike that answers none of its methods.
A module with a frame on the stack while the reading is taken — the caller, and whatever called it — is mid-operation, and what it holds is left out: neither copied here nor written back by the restore, however another module reaches it. Called from a coroutine that can yield, the walk gives the frame back every few milliseconds, so the engine keeps stepping through a reading that takes seconds.
Returns { [string]: any } — { entries, cache, modules, inUse, unreachable } — what was captured, the require cache as { key, value } pairs, how many modules it covers, how many were left out for executing, and the count of values that could not be read.
local snap = engine.snapshotModuleState()
typed/builtin//modules/api/engine/engine/M/timeScaleHolds
M.timeScaleHolds() -> { string }
Returns { string }
typed/builtin//modules/api/engine/engine/M/waitForEdit
M.waitForEdit(reason: string?) -> () -> ()
Say that this caller's edit-mode work is waiting on the play session, and get back the call that takes the wait off.
One process runs one simulation, so a play session holds the engine in
play for every caller outside it, and an agent whose edit-mode work
cannot proceed has no way to say so. While this wait stands it rides the
run-state block of every response any session gets from this engine, so
the callers in the play session learn somebody is waiting for it. Read
engine.playSession for who they are, and engine.modeOwner for who
entered play and how long ago.
A wait is keyed by the caller the call was attributed to, so a named caller that registers twice moves its own entry forward rather than queueing behind itself: one caller waits once. A call carrying no agent identity is named by nothing to key on, so each such ask stands as its own waiter and the release it handed back takes that one off. Reaching edit mode takes every wait off, so a caller whose release is lost with the task that held it leaves nothing standing.
Parameters
reasonstring(optional) — What this caller is waiting to do, shown beside its name.
Returns () -> () — A function that takes this caller's wait off.
local done = engine.waitForEdit("promote my scene edits")
-- ... once the engine reaches edit and the work is taken ...
done()
typed/builtin//modules/api/engine/engine/M/watcherSources
M.watcherSources() -> { [string]: { [number]: string } }
Who registered each watcher still standing, by registry: modeWatchers,
pauseWatchers, deviceRebuiltWatchers, memoryPressureWatchers,
backgroundWatchers, worldReadyWatchers and worldUnloadingWatchers, each a map from watcher id to the source and
line that registered it. A watcher registered before this module loaded
is absent. What a reading of the registry counts names when it finds a
watcher more than it began with.
Returns { [string]: { [number]: string } } — The sources, by registry and watcher id.
for id, at in pairs(engine.watcherSources().modeWatchers) do print(id, at) end
typed/builtin//modules/api/engine/engine/engine/discardPlayChanges
engine.discardPlayChanges() -> { paths: { string }, keep: string }
Arm the leave-play safeguard's deliberate discard for your next engine.mode = "edit" in the play session this is called from, so it proceeds and discards your unaccepted changes. A call that leaves the world in play (world.swap, world.checkout, and world.leave on an engine that waits for a world) ends the session for every caller in it and takes the arm the same way as the exit that ends it. While other callers stay in the session that is your own work: the /source edits you made in play, which revert, and the entities you tuned. The last caller to leave takes the engine to edit, and its discard throws away everything play made: the entities and tuning, and every /source file edit play holds on its shadow. Called by a caller outside the session, it arms the discard of engine.setMode("edit", { endSession = true }), which ends the session for every caller in it. A call that names no caller (a transport that attests no caller for it) cannot be told apart from any caller, so the exit that ends the session takes an arm made for the whole session from the other side: an exit that names no caller takes the arm a named caller made, and a named caller's exit takes the arm a call that named no caller made. Returns paths, the source files the flip would throw away if it ran now, and keep, the routes that keep any of them first; a notice names the same paths. The flip throws away what the shadow holds when it runs, so an edit made after the arm goes with the rest, and the flip names every path it took in a notice and the engine log (vfs.discardPlayShadow() states the same set). A discarded source edit whose pre-play copy is not on this engine yet keeps the play bytes until that copy lands and is put back; the flip names each such path, and vfs.playDiscardsOwed() lists them until then.
Returns { paths: { string }, keep: string }
typed/builtin//modules/api/engine/engine/engine/editWaiters
engine.editWaiters() -> { { key: string, id: string?, agent: string?, name: string?, reason: string?, heldSeconds: number } }
Everyone waiting for this engine to leave play, oldest first. A session holding play reads this to see whose work it is holding; heldSeconds is how long each has been waiting. Empty in edit mode and whenever nobody has said they are waiting.
Returns { { key: string, id: string?, agent: string?, name: string?, reason: string?, heldSeconds: number } }
typed/builtin//modules/api/engine/engine/engine/gameplayReady
engine.gameplayReady -> boolean
Whether gameplay simulation is running: not paused, and the play scene materialized. Read-only. Whether the world is ready to play at all (a player the person controls, its controls and a camera), in edit mode as in play, with a wait and the first moment it was, is playable.
Returns boolean
typed/builtin//modules/api/engine/engine/engine/gpuCompute
engine.gpuCompute -> boolean
Whether this process holds a live GPU device, so compute dispatch is available. Read-only.
Returns boolean
typed/builtin//modules/api/engine/engine/engine/headless
engine.headless -> boolean
Whether this boot renders offscreen with no window a person can see. Content that only serves someone at a display stands down when it reads true. Read-only.
Returns boolean
typed/builtin//modules/api/engine/engine/engine/mode
engine.mode -> "edit" | "play"
The engine mode this process is in, edit or play. Assigning it takes the flip, side effects and all.
Returns "edit" | "play"
typed/builtin//modules/api/engine/engine/engine/modeOwner
engine.modeOwner -> { id: string?, agent: string?, name: string?, heldSeconds: number }?
Who flipped the engine out of the mode it booted into, and how long ago, while that caller still holds it. In play, engine.playSession names every caller the session belongs to now. id is the caller key, the same value vfs.currentAuthor().id reads, and nil when that flip carried no agent identity; agent is the name the world's roster holds for that caller now, the one to ask by, and name the username of its account, which every agent of the account shares. Nil in the mode the engine booted into (a flip back to it ends the hold), once the caller that flipped it has left the play session it entered, and once that caller is no longer on the world's roster. Read-only.
Returns { id: string?, agent: string?, name: string?, heldSeconds: number }?
typed/builtin//modules/api/engine/engine/engine/pauseOwner
engine.pauseOwner -> { id: string?, agent: string?, name: string?, heldSeconds: number }?
Who asked for the standing gameplay pause, and for how long they have held it. One process runs one simulation, so a pause another agent took freezes update(dt), fixedUpdate(dt), physics and every gameplay clock for everybody: a component reading its own state while this is non-nil is reading the same instant over and over, and a sampling loop across task.wait returns the identical sample every time. id is the caller key, the same value vfs.currentAuthor().id reads, and nil when that call carried no agent identity; agent is the name the world's roster holds for that caller now, and name the username of its account, which every agent of the account shares. Nil while the engine is running, and nil when the standing pause is the mode's own rather than something somebody asked for. Read-only.
Returns { id: string?, agent: string?, name: string?, heldSeconds: number }?
typed/builtin//modules/api/engine/engine/engine/paused
engine.paused -> boolean
Whether gameplay is paused: update(dt) component callbacks are gated off while editorUpdate(dt) keeps firing in edit mode. A component's gameplay task (one spawned from awake, start, onEnable, update, fixedUpdate or another gameplay task) is held for the whole pause: a task.wait it started keeps the time it had left, and a task.waitRealtime is held too, but its deadline runs through the pause, so it comes due on the first frame after it. A task spawned from editorUpdate and a task.spawnSystem task run while paused. The scripting-and-tasks guide's "When a task runs" states the whole rule.
Returns boolean
typed/builtin//modules/api/engine/engine/engine/platform
engine.platform -> "native" | "browser" | "android" | "unknown"
Which build of the engine this process is: native for the desktop binary, browser for the wasm one, android for the Android app. unknown says the binary named no build, which a binary older than the field does. Read-only.
Returns "native" | "browser" | "android" | "unknown"
typed/builtin//modules/api/engine/engine/engine/playSession
engine.playSession -> { agents: { { key: string, agent: string? } }, takesPart: boolean }?
The play session the engine is running, as you stand towards it. Play belongs to the callers that take part in it: the caller that entered play, and every caller that writes engine.mode = "play" while it runs. agents are those callers still connected, in the order they joined, each with its stable key (vfs.currentAuthor().stable) and the name the world's roster holds for it. takesPart is whether you are one of them: your /source writes are play work, and your engine.mode = "edit" takes you out of the session, which keeps running for the others and ends with the last of them. While it is false you author beside the session: your /source writes land on canonical source, and the session is theirs to end. Nil in edit mode, in the runtime profile, and while the engine plays for nobody in particular (a Play button press, a boot into play). Read-only.
Returns { agents: { { key: string, agent: string? } }, takesPart: boolean }?
typed/builtin//modules/api/engine/engine/engine/profile
engine.profile -> "editor" | "runtime"
The boot profile this process started under, editor or runtime. Read-only.
Returns "editor" | "runtime"
typed/builtin//modules/api/engine/engine/engine/storefront
engine.storefront -> "direct" | "googlePlay" | "unknown"
The storefront this build ships through: googlePlay for the Android build distributed through Google Play, whose Payments policy holds every purchase surface (no text, button or link in the app invites buying credits, a plan or anything else outside Google Play's billing), and direct for a build OrigoZero distributes itself (the web engine, the desktop installer, every development build). Text that points a person to buying something reads it and shows that only where it reads direct. unknown says the binary named no storefront, which a binary older than the field does. Read-only.
Returns "direct" | "googlePlay" | "unknown"
typed/builtin//modules/api/engine/engine/engine/timeScale
engine.timeScale -> number
The global time scale applied to the fixed-timestep accumulator, to update(dt), and to the seconds task.wait and task.delay count: 1.0 is real time, 0.0 frozen, 2.0 double speed. So a task.wait(1) returns after four wall-clock seconds at 0.25 and never comes due at 0. task.waitRealtime(1) is one wall-clock second at every scale. One number for the whole process, shared by every agent driving this engine: engine.timeScaleOwner names who it answers to, engine.onTimeScaleChange reports every move of it, and engine.holdTimeScale takes it for a named owner so a write from anywhere else is refused while the hold stands. A script computing a delta of its own from a wall clock multiplies it by this, and one reading time.deltaTime() or a callback's dt already has it applied.
Returns number
typed/builtin//modules/api/engine/engine/engine/timeScaleOwner
engine.timeScaleOwner -> { id: string?, name: string?, scale: number, exclusive: boolean, held: boolean }?
Who engine.timeScale answers to: the hold naming the rate while one stands, and otherwise whoever wrote the rate outright last. scale is the rate in force, the same number engine.timeScale reads. While held is true, id is a key engine.releaseTimeScale hands the rate back by; for a write it is the agent the call was attributed to, and nil when the call carried no agent identity. name is that agent's username when its token carried one. exclusive is true while the hold refuses every other key. Nil when nothing has moved the rate this session. Read-only.
Returns { id: string?, name: string?, scale: number, exclusive: boolean, held: boolean }?
typed/builtin//modules/api/engine/engine/engine/vertexStride
engine.vertexStride -> number
Byte stride of the engine's standard GPU Vertex layout, which a mesh built from a compute buffer sizes and strides its writes to. Read-only.
Returns number
typed/builtin//modules/api/engine/engine/engine/waitForEdit
engine.waitForEdit(reason: string?) -> () -> ()
Say that this caller's edit-mode work is waiting on whoever holds play, and get back the call that takes the wait off. While the wait stands it rides the run-state block of every response any session gets from this engine, so the session holding play reads that somebody is waiting for it rather than finding out hours later. reason is what you are waiting to do, and it is shown beside your name. The wait is keyed by the caller the call was attributed to, so a named caller asking twice holds one entry carrying its newer reason, and a call carrying no agent identity stands as a waiter of its own. Reaching edit mode takes every wait off, so a caller that never calls the release leaves nothing behind.
Parameters
reasonstring(optional)
Returns () -> ()
typed/builtin//modules/api/engine/engine/engine/worldLoaded
engine.worldLoaded -> boolean
Whether the world entrypoint's onWorldLoad has run to completion. Read-only.
Returns boolean
typed/builtin//modules/api/engine/entity/E/batchAddComponent
E.batchAddComponent(targets: { string | entityRef }, type_name: string, data: table?) -> number
Add the same component type to many entities in one call. Returns the count of entities the component was added to — an entity already carrying an unnamed instance of the same type is skipped rather than double-added.
Parameters
targets{ string | entityRef }— Array of entity ids or entity proxies (e.g. the return ofentity.batchSpawnorentity.findAll).type_namestring— Component type to add to every entity.datatable(optional) — Init data: one table applied identically to every entity — the same shape the second arg toentity(id).component.add(type, data)takes — or an array holding one such table per target, in the targets' order, so each entity is added with its own values.
Returns number — How many entities had the component added.
local n = entity.batchAddComponent(ids, "Debris", { lifetime = 5 })
entity.batchAddComponent({ a, b }, "Debris", { { lifetime = 2 }, { lifetime = 7 } })
typed/builtin//modules/api/engine/entity/E/batchDespawn
E.batchDespawn(targets: { string | entityRef }) -> number
Despawn many entities in one call. Locked or unresolvable entities are skipped. Returns the count queued for despawn.
Parameters
targets{ string | entityRef }— Array of entity ids, entity proxies, or display names (e.g. the return ofentity.batchSpawn/entity.findAll).
Returns number — Count of entities queued for despawn.
local n = entity.batchDespawn(ids)
typed/builtin//modules/api/engine/entity/E/batchProxy
E.batchProxy(targets: { string | entityRef }) -> { entityRef? }
Resolve an array of entity ids to proxies in one call. Each output
slot is the standard entity(id) proxy; ids missing from the frame
cache surface as nil at that index. Use when iterating over a snapshot
of entities so per-id lookups don't dominate the hot path.
Parameters
targets{ string | entityRef }— Array of entity ids or entity proxies.
Returns { entityRef? } — Array of proxies (nil for missing ids).
local proxies = entity.batchProxy(ids)
typed/builtin//modules/api/engine/entity/E/batchRead
E.batchRead(target: { string | entityRef } | binding, component: string?, field: string?, sink: TypedBuffer?) -> { any? } | number
Read a component-field across many entities in one call.
Polymorphic on the shape of target and sink:
entity.batchRead(ids)/(ids, comp)/(ids, comp, field)— returns one value per entity (a whole snapshot, one component table, or one field value). Missing entities/components/fields surface as nil at that slot.entity.batchRead(binding, comp, field, buffer)— reads each entity's field directly into a typed CPU substrate buffer (substrate.createBuffer({type="vec3"}), etc.) with no per-entity Lua table allocation. Returns the count of successful reads.Transform.worldMatrixreads each entity's world matrix — its own transform folded with its ancestors', the oneentity(id).worldMatrix()answers — as 16 column-major numbers: into amat4buffer, or as an array of 16 per entity. It is read, never written.targetaccepts an entity-id array or aecs.bindEntities(ids)handle. Buffer sinks require a binding — the typed kernel is binding-only.
Parameters
target{ string | entityRef } | binding— Array of entity ids or entity proxies, or a binding handle fromecs.bindEntities(ids).componentstring(optional) — Component type name (e.g. "Transform").fieldstring(optional) — Field name (e.g. "position").sinkTypedBuffer(optional) — Typed CPU buffer fromsubstrate.createBuffer({...})to memcpy field values into. Required whentargetis a binding.
Returns { any? } | number — Per-entity values when reading into Lua tables; count of reads when reading into a buffer.
local snapshot = entity.batchRead(ids)
local positions = entity.batchRead(ids, "Transform", "position")
entity.batchRead(ecs.bindEntities(ids), "Transform", "worldMatrix", matrices)
typed/builtin//modules/api/engine/entity/E/batchReadToBuffer
E.batchReadToBuffer(binding: number, component: string, field: string, buffer: number) -> number
FFI primitive backing entity.batchRead(binding, ..., buffer).
Prefer the unified entity.batchRead, which auto-dispatches by
argument shape. Reads each entity's component field directly into a
typed CPU substrate buffer, with no per-entity Lua table allocation.
After the call, read the buffer via buf:read(0, count*stride).
Parameters
bindingnumber— Binding id fromecs.bindEntities(ids).id, live while its handle is held.componentstring— Component type name.fieldstring— Field name to read.buffernumber— Destination buffer id (must be the matching type).
Returns number — Count of successful reads.
entity.batchReadToBuffer(binding.id, "Transform", "position", buf.id)
typed/builtin//modules/api/engine/entity/E/batchSpawn
E.batchSpawn(count: number, name_prefix: string?, opts: { temporary: boolean?, parent: (string | entityRef)? }?) -> { string }
Spawn count entities in one call. Returns an array of the new
entity ids in spawn order. Each entity is given a display name of
<name_prefix><i> (or entity<i> if the prefix is omitted). Prefer this
over looping entity.spawn when creating large entity counts.
Parameters
countnumber— How many entities to spawn (capped at 1,000,000).name_prefixstring(optional) — Display-name prefix appended with the 1-based index. Defaults to "entity".opts{ temporary: boolean?, parent: (string | entityRef)? }(optional) —{ temporary?, parent? }— a temporary batch is one the scene does not save, the same thingentity.spawn({ temporary = true })asks for. The component goes on in one crossing, so a batch of a hundred thousand costs what one does. A batch spawned inside an entrypoint that is itself temporary is temporary whatever this says.parent— an id or an entity — makes every entity in the batch its child as it is made, so the batch stands, moves and goes with it.
Returns { string } — Array of newly-spawned entity ids.
local ids = entity.batchSpawn(100, "grass_")
local particles = entity.batchSpawn(5000, "spark_", { temporary = true })
local parts = entity.batchSpawn(8, "part_", { temporary = true, parent = owner })
typed/builtin//modules/api/engine/entity/E/batchWrite
E.batchWrite(target: { string | entityRef } | binding, component: string, field: string, source: { any? } | TypedBuffer) -> number
Write a single component-field across many entities in one call.
Polymorphic on the shape of target and source:
entity.batchWrite(ids, comp, field, values)— per-call entity-id resolution;valuesis an array the same length asids(nil slots are skipped). Use for one-shot writes.entity.batchWrite(binding, comp, field, values)— binding handle fromecs.bindEntities(ids); skips per-call id resolution. Use for per-frame writes against a stable entity set.entity.batchWrite(binding, comp, field, buffer)— typed CPU buffer source (substrate.createBuffer({type="vec3"}), etc.), with no per-entity table allocation. Returns the count of successful writes. Buffer sources require a binding — the typed kernel is binding-only.
Parameters
target{ string | entityRef } | binding— Array of entity ids or entity proxies, or a binding handle fromecs.bindEntities(ids).componentstring— Component type name.fieldstring— Field name to write.source{ any? } | TypedBuffer— Per-entity values array (nil entries are skipped), or a typed CPU buffer fromsubstrate.createBuffer({...}). A buffer source requires a bindingtarget.
Returns number — Count of successful writes.
entity.batchWrite(ids, "Transform", "position", positions)
typed/builtin//modules/api/engine/entity/E/batchWriteBound
E.batchWriteBound(binding: number, component: string, field: string, values: { any? }) -> number
FFI primitive backing entity.batchWrite(binding, ...) with a
per-entity values table. Prefer the unified entity.batchWrite, which
auto-dispatches by argument shape; this entry stays for power users /
debug code that wants to skip dispatch overhead.
Parameters
bindingnumber— Binding id fromecs.bindEntities(ids).id, live while its handle is held.componentstring— Component type name.fieldstring— Field name to write.values{ any? }— Per-entity source values (nil = skip). Length must match the binding's entity count.
Returns number — Count of successful writes.
entity.batchWriteBound(binding.id, "Transform", "position", values)
typed/builtin//modules/api/engine/entity/E/batchWriteFromBuffer
E.batchWriteFromBuffer(binding: number, component: string, field: string, buffer: number) -> number
FFI primitive backing entity.batchWrite(binding, ..., buffer).
Prefer the unified entity.batchWrite, which auto-dispatches by
argument shape. Caller fills a typed substrate buffer
(substrate.createBuffer({type="vec3"})) once via buf:write(...),
then this memcpys 12 (vec3) or 16 (quat) bytes per entity into the
component field. Buffer count and binding count should match — a
mismatch processes the smaller of the two.
Parameters
bindingnumber— Binding id fromecs.bindEntities(ids).id, live while its handle is held.componentstring— Component type name.fieldstring— Field name to write.buffernumber— Buffer id fromsubstrate.createBuffer({type="vec3", len=N}).id.
Returns number — Count of successful writes.
entity.batchWriteFromBuffer(binding.id, "Transform", "position", buf.id)
typed/builtin//modules/api/engine/entity/E/capture
E.capture(builder: () -> (), opts: {isolated: boolean?}?) -> ({ string }, any?, { string }, { any })
Run builder inside an entity capture scope and return the entity ids
it minted, in creation order, the error it raised (if any), and the ids
among them that a component the builder attached minted in its own
lifecycle. Every id minted while the builder runs is recorded — through
entity.spawn, entity.spawnSynced, entity.batchSpawn, and
entity.instantiate alike. Scopes nest: an id minted inside an inner
capture is recorded by that capture AND every enclosing one — the
innermost capture answers, so a nested build shapes its own entities,
not the ones around it. A builder that raises still returns its ids, so
the caller can despawn what a failed build left behind; the scope closes
either way and never outlives this call. While the builder runs, an
operation whose result cannot be composed into a record is refused
rather than applied, and so is any operation aimed at an entity the
builder did not mint — a builder that returned while something it did
was refused comes back with an error naming every refusal.
Parameters
builder() -> ()— Function run inside the scope; the entities it creates are what comes back.opts{isolated: boolean?}(optional) —isolatedrefuses persistent side effects during candidate evaluation and nested calls. Component-owned tasks may run inline; their remaining work stops when the capture closes.entity.isolated()reports this policy in nested callbacks.
Returns ({ string }, any?, { string }, { any }) — Entity ids minted while the builder ran, in creation order; the error it raised (or the refusals it hit), or nil; the ids a component the builder attached minted in its own lifecycle; and the refusals the scope issued, each with message, at and source.
local ids, err, reproduced, refusals = entity.capture(function() entity.spawn("chair") end)
typed/builtin//modules/api/engine/entity/E/capturing
E.capturing() -> boolean
Whether an entity.capture builder (a scene build) is running on the
calling thread. A component a build adds takes the world's Preset Manager
rows in every mode, so a scene built in a play session holds what the
same build holds in edit mode.
Returns boolean — true inside a capture scope.
if entity.capturing() then return end
typed/builtin//modules/api/engine/entity/E/despawn
E.despawn(target: string | entityRef)
Despawn an entity and all its components. Pass an id string or an entity proxy to despawn that ONE entity. Pass a name to despawn EVERY entity with that name — names are not unique, so a name argument despawns all matches, not one arbitrary match. A despawned id becomes invalid after this call. Raises if no entity matches; for a bulk name despawn, locked entities are skipped with a logged summary and only raise if every match is locked.
Parameters
targetstring | entityRef— Entity id, name, or entity proxy. A name despawns all entities sharing that name.
entity.despawn(id)
entity.despawn("Enemy") -- despawns every entity named "Enemy"
typed/builtin//modules/api/engine/entity/E/duplicate
E.duplicate(sourceId: string | entityRef, name: string?, opts: table?) -> string?
Duplicate an entity with all its components (transform, script
components, attributes, visuals, material) and its descendants. Returns
the new entity's id, or nil when sourceId names no live entity.
Descendants marked temporary are left out of the copy: they are
scaffolding whatever spawned them re-creates, so a component that
regenerates its own children rebuilds them on the copy rather than the
copy carrying a second set. includeTemporary copies them too, for the
hierarchy that IS the temporary thing.
Parameters
sourceIdstring | entityRef— Entity id or entity proxy of the source entity to clone.namestring(optional) — Display name for the copy (defaults to source name + " (copy)").optstable(optional) —{ includeTemporary?: boolean, descendants?: boolean, components?: table, name?: string }:descendants = falsecopies the source entity alone, leaving its children to it;componentslays fields over the copy's script components by type ({ SoftBody = { mass = 2 } }), merged over the state copied from the source;nameis the same field thenameargument sets, and wins when both are given.
Returns string? — The new entity's id, or nil when the source is not live.
local copyId = entity.duplicate(id); if copyId then entity(copyId).position = { 1, 0, 0 } end
local copyId = entity.duplicate(id, "Turret", { includeTemporary = true })
local lone = entity.duplicate(id, nil, { descendants = false, components = { SoftBody = { mass = 2 } } })
typed/builtin//modules/api/engine/entity/E/exists
E.exists(idOrProxy: string | entityRef) -> boolean
Check whether an entity currently exists in the scene. Accepts an
entity-id string or an entity proxy, matched by entity id — so it agrees
exactly with entity(id). A name is a different kind of identifier: a
string that misses as an id but names a live entity raises rather than
answering false, since false there is indistinguishable from absence.
Check by name with entity.find(name) ~= nil.
Parameters
idOrProxystring | entityRef— Entity id or an entity proxy.
Returns boolean — true if the entity exists.
if entity.exists(id) then ... end
typed/builtin//modules/api/engine/entity/E/find
E.find(nameOrGlob: string) -> entityRef?
Find the first entity matching nameOrGlob. A plain string matches
an exact id or Name component; a string containing * (any run of
characters) or ? (any single character) matches Names as a glob, so
entity.find("enemy_*") is the first entity whose name starts with
enemy_. A glob addresses Names only, never ids. Same-frame pending
spawns are searched too, and anything queued for despawn in the same
frame is skipped. Names are NOT unique — use entity.findAll when every
match matters; find is the first entity findAll lists. Inside a build
(a scene's content(), a module's builder), a name the build's own
entities carry resolves to those first, so entity.spawn("door")
followed by entity.find("door") is the door the build just made even
when the world around it holds another door.
Parameters
nameOrGlobstring— Exact entity Name or id, or a*/?glob over Names.
Returns entityRef? — First matching entity proxy, or nil.
local e = entity.find("enemy_*")
typed/builtin//modules/api/engine/entity/E/findAll
E.findAll(nameOrGlob: string?) -> { entityRef }
Enumerate entity proxies. With a nameOrGlob argument, returns every
entity whose Name component or id matches (names are not unique): a
plain string matches exactly, while a * / ? glob matches Names. With
no argument, returns every entity in the current snapshot —
findAll("") is the exact-match filter for the empty name, which
normally matches nothing. Same-frame pending spawns are included and
same-frame despawns filtered out. Elements are entity proxies, not id
strings — for ids, wrap the result: entity.ids(entity.findAll(...)).
Inside a build (a scene's content(), a module's builder), the entities
the build made come first and the world's same-named entities follow.
For the entities carrying a component, entity.withComponent(type)
answers from the component index instead of walking the scene.
Parameters
nameOrGlobstring(optional) — Exact entity Name or id to filter by, or a*/?glob over Names. Omit to enumerate every entity.
Returns { entityRef } — Array of entity proxies, possibly empty.
for _, e in entity.findAll("enemy_*") do e:despawn() end
typed/builtin//modules/api/engine/entity/E/getChildren
E.getChildren(id: string | entityRef) -> { entityRef }
Get an array of the direct children as entity proxies. Each element
carries .name, .id, .position, .component, and the rest of the
per-entity surface, the same shape entity.findAll returns. A string
that names a live entity rather than identifying it raises, naming
entity.find(name), the lookup that takes a name.
Parameters
idstring | entityRef— Entity id or entity proxy.
Returns { entityRef } — Array of child entity proxies, possibly empty.
for _, c in entity.getChildren(id) do c.internal = true end
typed/builtin//modules/api/engine/entity/E/getDescendants
E.getDescendants(id: string | entityRef) -> { entityRef }
Get every descendant (children, grandchildren, and deeper) of the
given entity as entity proxies in breadth-first order, excluding the
entity itself. Resolves the whole subtree in one linear pass over the
entity set, so a large subtree costs proportionally to the entity count
rather than to the subtree size times the entity count. A string that
names a live entity rather than identifying it raises, naming
entity.find(name), the lookup that takes a name.
Parameters
idstring | entityRef— Entity id or entity proxy.
Returns { entityRef } — Array of descendant entity proxies, possibly empty.
local all = entity.getDescendants(id)
typed/builtin//modules/api/engine/entity/E/getParent
E.getParent(id: string | entityRef) -> entityRef?
Get the parent entity proxy, or nil if the entity is a root entity.
The returned proxy carries .name, .id, .position, .component,
and the rest of the per-entity surface — the same shape entity.find
returns. A string that names a live entity rather than identifying it
raises, naming entity.find(name), the lookup that takes a name:
answering it as an id would read the same as a root entity.
Parameters
idstring | entityRef— Entity id or entity proxy.
Returns entityRef? — Parent entity proxy, or nil.
local p = entity.getParent(id)
typed/builtin//modules/api/engine/entity/E/instantiate
E.instantiate(handle: EntityTemplate, count: number, fn: ((number) -> EntityInstantiateOverrides?)?) -> { string }
Spawn count instances of a template registered with
entity.template. Each instance gets a fresh entity id; the optional
fn(i) callback runs per instance (i in 1..=count) and may return an
overrides table. Override keys: name, position, rotation, scale,
parent, temporary / active / internal, attributes, components
(script components, merged over the template body's data for that type
— a type the template lacks is added fresh), and ecs (native
components, merged the same way). Each override supersedes the
template's shared config for that instance. The whole batch crosses in
one call and lands as a single deferred mutation the engine expands
into bulk work — per-instance cost drops from a full round trip to one
callback plus one mutation. Inside queue() the batch is deferred onto
the cross-frame ring; outside, it lands in the next frame's drain.
Returns the array of newly-minted entity ids in spawn order.
Parameters
handleEntityTemplate— Template handle fromentity.template.countnumber— Number of instances to spawn (capped at 1,000,000).fn((number) -> EntityInstantiateOverrides?)(optional) — Per-instance override callback(i) -> table?.
Returns { string } — Array of newly-spawned entity ids in spawn order.
local ids = entity.instantiate(h, 50, function(i) return { position = { i, 0, 0 } } end)
typed/builtin//modules/api/engine/entity/E/isolated
E.isolated() -> boolean
Whether isolated candidate policy applies to this call, including component callbacks.
Returns boolean — True while evaluating an isolated candidate.
typed/builtin//modules/api/engine/entity/E/sceneWalks
E.sceneWalks() -> number
How many whole-scene walks entity.findAll has made since the module
loaded. A walk is priced by the number of entities the scene holds, so a
caller that must not scale with the scene — a per-frame push, a write
that reaches its target through a record — is read either side of its
work against this count, which a walk raises by one.
Returns number — The count of walks.
local before = entity.sceneWalks(); entity(id):rename("door"); assert(entity.sceneWalks() == before)
typed/builtin//modules/api/engine/entity/E/spawn
E.spawn(nameOrOpts: (string | SpawnOpts)?, opts: SpawnOpts?) -> entityRef
Spawn a new entity and return its PROXY (the same value entity(id)
yields) — act on it immediately (entity.spawn(name).component.add(...),
.localPosition = ...) with no second entity(id) round trip. The proxy
still exposes .id for the rare site that needs the raw string. An
entity with no components carries only a Transform and is invisible;
pass components to give it the components that make it visible in the
same call — entity.spawn { name = "crate", components = { Model = { model = "cube" } } } — or add them afterwards through the returned
proxy. Mirrors entity.find / entity.findAll, which also return
proxies. The options table can be passed on its own with the name inside
it — entity.spawn { name = "turret", position = { 1, 2, 3 } } is the
same call as entity.spawn("turret", { position = { 1, 2, 3 } }).
Parameters
nameOrOpts(string | SpawnOpts)(optional) — Display name for the entity, or the options table itself.optsSpawnOpts(optional) — Options:components= component types to attach to the new entity, keyed by type name with each value the component's init table (attached in sorted type order; a failing add raises),internal= take the entity out of the default entity listings (it still renders —entity(id):hide()stops the draw),parent= parent entity id or proxy,temporary= skip this entity (and descendants) from scene/world saves,position/rotation/scale= place the entity's Transform at spawn,attributes= per-entity attribute values keyed by name ({ role = "guard" }, the same valuesentity(id).attribute.set(key, value)writes andentity.template/entity.instantiatetake),synced= flag the entity multiplayer-synced (whatentity.spawnSyncedimplies),active= false spawns it inactive,scene_owner= the scene layer guid the entity is attributed to (inherited from the spawning scene when unset),id= restore a previously-assigned entity id (scene_loader use; leave unset for a normal spawn). An unrecognised key is rejected loudly.
Returns entityRef — Proxy for the new entity (carries .id, .component, transform properties, etc.).
local e = entity.spawn("crate", { components = { Model = { model = "cube" } } })
local e = entity.spawn { name = "turret", position = { 1, 2, 3 } }
local guard = entity.spawn("guard", { attributes = { role = "guard", hp = 3 } })
typed/builtin//modules/api/engine/entity/E/spawnSynced
E.spawnSynced(nameOrOpts: (string | SpawnOpts)?, opts: SpawnOpts?) -> entityRef
Spawn an entity already flagged multiplayer-synced at the root — the
explicit form of entity.spawn for SHARED, host-authoritative content.
The entity's existence broadcasts to every peer; joiners receive it from
the relay snapshot instead of spawning their own copy. Use this (NOT
entity.spawn) for anything that must be the SAME object on all
clients: enemies, pickups, projectiles, dynamic world props. Call it
ONLY where exactly one client runs the code — a scene's onHostLoad
(host-only) phase, or behind multiplayer.isHost(). Calling it in
all-client code makes every client spawn+sync its own copy — the
double-spawn "explosion". Equivalent to
entity.spawn(name, { synced = true }); identical in every other
respect.
Parameters
nameOrOpts(string | SpawnOpts)(optional) — Display name for the entity, or the options table itself.optsSpawnOpts(optional) — Same options asentity.spawn(syncedis already implied).
Returns entityRef — Proxy for the new synced entity.
if multiplayer.isHost() then entity.spawnSynced("Goblin") end
typed/builtin//modules/api/engine/entity/E/template
E.template(def: EntityTemplateDef) -> EntityTemplate
Construct a reusable spawn template. Captures a shared entity config
ONCE and returns an EntityTemplate handle for entity.instantiate(handle, count, fn?) — one call per batch instead of one per entity. The template
lives as long as a script holds the handle: once nothing reaches it, the
collector releases the template, and the entities already instantiated
from it stay as they are. Keep the handle (a module-level local, a field)
for as long as more instances may follow. def keys:
components (script components, { [type] = init-data }), ecs
(array of native ecs.X{...} components), temporary (instances skip
scene/world saves), active (spawn state), internal (instances are
taken out of the default entity listings; they still render),
attributes ({ key = value } applied to every instance). Every value
is a shared default; a per-instance entity.instantiate override
supersedes it. The template body is captured by value — later edits to
the source table do not affect templates already created.
Parameters
defEntityTemplateDef— Template definition:components/ecs/temporary/active/internal/attributes. Per-instancename/position/rotation/scale/parentand any override go through theinstantiatecallback.
Returns EntityTemplate — The template's handle for entity.instantiate.
local h = entity.template({ components = { Model = { model = "cube" } } })
typed/builtin//modules/api/engine/entity/E/tree
E.tree(opts: { [string]: any }?) -> { [string]: any }
A windowed, lean view over the scene's entity tree, in one crossing.
Rows carry id, name, parentId, depth, childCount, active, sceneLayer and
componentNames — names only, never component values — so the call costs
the rows it answers with rather than the size of the scene. Entities group
under scene layers, per-layer roots and children name-sorted; internal
entities and their subtrees stay out. expanded names the ids whose
children unfold, and a collapsed node still reports its childCount;
filter keeps the rows whose name or id contains the needle plus every
ancestor on a path to one, auto-unfolded, with the actual matches flagged
matched. offset / limit window the flattened rows, layer scopes the
window and its total to one layer while layers still reports every
layer's row count, and revision echoes
getEntitiesRevision("structure"), which moves only on structural change.
Parameters
opts{ [string]: any }(optional) —{ layer?, expanded?, filter?, offset?, limit? }.
Returns { [string]: any } — { rows, total, layers, revision }.
local view = entity.tree({ filter = "crate", limit = 50 })
typed/builtin//modules/api/engine/entity/E/withComponent
E.withComponent(componentType: AssetRef<component> | string) -> { entityRef }
Every entity carrying a component of componentType, as entity
proxies, answered from the engine's index of each component type's
instances: the call costs what it returns rather than what the scene
holds, so asking for the 200 lights of a 2,000-entity scene reads 200
entries where entity.findAll() filtered by e.component.has("Light")
walks all 2,000. Each entity is listed once, however many instances of
the type it carries, in entity-id order. The type is named the way
e.component.has names it: the registered name, the package-qualified
identity, or the component's AssetRef. For the entities carrying an
engine-native ECS component (ecs.Transform, ecs.Mesh), or several
components at once, ecs.query(...) answers the same way. A type no
entity carries answers an empty array, as does a name no component type
is registered under, the way e.component.has answers false for it.
Parameters
componentTypeAssetRef<component> | string— The component type: its registered name ("Light"), its package-qualified identity, or its component AssetRef.
Returns { entityRef } — Array of entity proxies, possibly empty.
for _, e in entity.withComponent("Light") do e:hide() end
local lights = #entity.withComponent(asset.resolve("Light", "component"))
typed/builtin//modules/api/engine/entity/entityHierarchy/swap
entityHierarchy.swap(entityId: string, assetPath: string, opts: { [string]: any }?) -> (string?, string?)
Replace a blockout entity with a generated or imported asset, fitting the asset to the source's bounds. Answers the new entity id, or nil and an error string.
Parameters
entityIdstringassetPathstringopts{ [string]: any }(optional)
Returns (string?, string?)
typed/builtin//modules/api/engine/entity/members/entityAttributes/get
entityAttributes.get(key: string) -> any?
The value stored under a key, or nil when the entity carries none.
Parameters
keystring
Returns any?
typed/builtin//modules/api/engine/entity/members/entityAttributes/list
entityAttributes.list() -> { string }
Every attribute key this entity carries.
Returns { string }
typed/builtin//modules/api/engine/entity/members/entityAttributes/remove
entityAttributes.remove(key: string) -> ()
Drop the value stored under a key.
Parameters
keystring
Returns ()
typed/builtin//modules/api/engine/entity/members/entityAttributes/set
entityAttributes.set(key: string, value: any) -> ()
Store a value under a key on this entity.
Parameters
keystringvalueany
Returns ()
typed/builtin//modules/api/engine/entity/members/entityComponents/add
entityComponents.add(type: AssetRef | string, data: table?) -> table?
Attach a component, answering its live public proxy — nil when the add was deferred or skipped as a duplicate.
Parameters
typeAssetRef | stringdatatable(optional)
Returns table?
typed/builtin//modules/api/engine/entity/members/entityComponents/addSynced
entityComponents.addSynced(type: AssetRef | string, data: table?) -> table?
Attach a component and replicate it to every peer.
Parameters
typeAssetRef | stringdatatable(optional)
Returns table?
local health = entity(id).component.addSynced('Health', { hp = 100 })
typed/builtin//modules/api/engine/entity/members/entityComponents/clear
entityComponents.clear() -> ()
Detach every component this entity carries.
Returns ()
typed/builtin//modules/api/engine/entity/members/entityComponents/create
entityComponents.create(type: AssetRef | string, data: table?) -> table?
Attach a fresh instance even where one of the type is already present.
Parameters
typeAssetRef | stringdatatable(optional)
Returns table?
typed/builtin//modules/api/engine/entity/members/entityComponents/get
entityComponents.get(type: AssetRef | string, instanceName: string?) -> table?
This entity's live component proxy of the type, or nil when it carries none.
Parameters
typeAssetRef | stringinstanceNamestring(optional)
Returns table?
typed/builtin//modules/api/engine/entity/members/entityComponents/getAll
entityComponents.getAll(type: (AssetRef | string)?) -> table
Every component on this entity, or every instance of one type.
Parameters
type(AssetRef | string)(optional)
Returns table
typed/builtin//modules/api/engine/entity/members/entityComponents/getFromChildren
entityComponents.getFromChildren(type: AssetRef | string) -> table?
The first descendant's component of the type, or nil when no descendant carries one.
Parameters
typeAssetRef | string
Returns table?
typed/builtin//modules/api/engine/entity/members/entityComponents/getFromParent
entityComponents.getFromParent(type: AssetRef | string) -> table?
The nearest ancestor's component of the type, or nil when no ancestor carries one.
Parameters
typeAssetRef | string
Returns table?
typed/builtin//modules/api/engine/entity/members/entityComponents/has
entityComponents.has(type: AssetRef | string) -> boolean
Whether this entity carries a component of the type.
Parameters
typeAssetRef | string
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityComponents/list
entityComponents.list() -> { string }
The identity string of every component type this entity carries, each of which get takes.
Returns { string }
for _, identity in ipairs(entity(id).component.list()) do
local component = entity(id).component.get(identity)
component.enabled = false
end
typed/builtin//modules/api/engine/entity/members/entityComponents/lock
entityComponents.lock(names: { string } | string, flags: { [string]: any }?) -> ()
Lock named components on this entity against removal or writes.
Parameters
names{ string } | stringflags{ [string]: any }(optional)
Returns ()
typed/builtin//modules/api/engine/entity/members/entityComponents/locks
entityComponents.locks() -> { [string]: any }
The lock state of this entity's components.
Returns { [string]: any }
typed/builtin//modules/api/engine/entity/members/entityComponents/pending
entityComponents.pending(type: (AssetRef | string)?) -> { { type: string, instance: string?, instanceId: string, fields: { { name: string, path: string, spec: string, value: string, held: boolean, state: string, reason: string, detail: string } } } }
One record per component holding an asset reference no asset answers yet, naming the component and each such reference: its field (name), where it sits in the field (path: the field's name for its own value, skins[2] for an element of a list field), the spec of the slot holding it, the reference (value), held (true when the component already runs and the write waits; false when its awake() waits on the field), and where the reference stands (state pending or refused, with reason and detail); every such component when no type is given. asset.pending() lists them across the whole engine.
Parameters
type(AssetRef | string)(optional)
Returns { { type: string, instance: string?, instanceId: string, fields: { { name: string, path: string, spec: string, value: string, held: boolean, state: string, reason: string, detail: string } } } }
local waiting = entity(id).component.pending('Terrain')
if #waiting > 0 then print(waiting[1].fields[1].name, waiting[1].fields[1].value) end
typed/builtin//modules/api/engine/entity/members/entityComponents/remove
entityComponents.remove(type: AssetRef | string, instanceName: string?) -> ()
Detach a component, by type and optionally by instance name.
Parameters
typeAssetRef | stringinstanceNamestring(optional)
Returns ()
typed/builtin//modules/api/engine/entity/members/entityComponents/setEnabled
entityComponents.setEnabled(type: AssetRef | string, enabled: boolean) -> ()
Enable or disable a component without detaching it.
Parameters
typeAssetRef | stringenabledboolean
Returns ()
typed/builtin//modules/api/engine/entity/members/entityComponents/unlock
entityComponents.unlock(names: ({ string } | string)?, flags: { [string]: any }?) -> ()
Release locks this entity's components hold; every one of them when no name is given.
Parameters
names({ string } | string)(optional)flags{ [string]: any }(optional)
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/AddDebris
entityRef.AddDebris(self, lifetime: number?) -> ()
Despawn this entity after a lifetime, defaulting to 10 seconds.
Parameters
selflifetimenumber(optional)
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/active
entityRef.active -> boolean
Whether this entity is active.
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/activeInHierarchy
entityRef.activeInHierarchy -> boolean
Whether this entity is active via its ancestors.
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/attribute
entityRef.attribute -> entityAttributes
Free-form key/value attributes stored on this entity.
Returns entityAttributes
typed/builtin//modules/api/engine/entity/members/entityRef/bounds
entityRef.bounds(self) -> { min: any, max: any, center: any, size: any }?
This entity's world-axis bounding box.
Parameters
self
Returns { min: any, max: any, center: any, size: any }?
typed/builtin//modules/api/engine/entity/members/entityRef/bundleLink
entityRef.bundleLink -> any?
This entity's link back to its bundle.
Returns any?
typed/builtin//modules/api/engine/entity/members/entityRef/bundleProvenance
entityRef.bundleProvenance -> { [string]: any }?
Which bundle produced this entity.
Returns { [string]: any }?
typed/builtin//modules/api/engine/entity/members/entityRef/component
entityRef.component -> entityComponents
Script components attached to this entity.
Returns entityComponents
typed/builtin//modules/api/engine/entity/members/entityRef/despawn
entityRef.despawn(self) -> ()
Remove this entity from the scene.
Parameters
self
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/destroy
entityRef.destroy(self) -> ()
Remove this entity from the scene.
Parameters
self
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/duplicate
entityRef.duplicate(self, name: string?, opts: { [string]: any }?) -> string?
Copy this entity.
Parameters
selfnamestring(optional)opts{ [string]: any }(optional)
Returns string?
typed/builtin//modules/api/engine/entity/members/entityRef/eulerAngles
entityRef.eulerAngles -> { [string]: any }
World rotation, as euler degrees.
Returns { [string]: any }
typed/builtin//modules/api/engine/entity/members/entityRef/exists
entityRef.exists -> boolean
Whether this entity is still in the world. Never raises — a proxy over an id nothing carries reads false.
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/getChildren
entityRef.getChildren(self) -> { entityRef }
This entity's direct children.
Parameters
self
Returns { entityRef }
typed/builtin//modules/api/engine/entity/members/entityRef/getDescendants
entityRef.getDescendants(self) -> { entityRef }
Every entity below this one.
Parameters
self
Returns { entityRef }
typed/builtin//modules/api/engine/entity/members/entityRef/getParent
entityRef.getParent(self) -> entityRef?
This entity's parent, or nil.
Parameters
self
Returns entityRef?
typed/builtin//modules/api/engine/entity/members/entityRef/hidden
entityRef.hidden -> boolean
Whether hide() has switched this entity off (read-only; hide() / show() set it). Separate from a Model / SkinnedModel visible field: the mesh draws only while neither hides it.
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/hide
entityRef.hide(self) -> ()
Stop drawing this entity and its descendants, and stop the lights they carry lighting the scene: a hidden light holds no light row or shadow, and hands the sun or ambient term it holds to a light still shown. Works the same on a Model and a SkinnedModel, and holds until show(): editing the component's fields does not undo it. The component's own visible field is a second, separate switch; the mesh draws only while both allow it.
Parameters
self
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/hierarchyBounds
entityRef.hierarchyBounds(self) -> { min: any, max: any, center: any, size: any }?
The world-axis box around this entity's subtree.
Parameters
self
Returns { min: any, max: any, center: any, size: any }?
typed/builtin//modules/api/engine/entity/members/entityRef/id
entityRef.id -> string
This entity's id string.
Returns string
typed/builtin//modules/api/engine/entity/members/entityRef/inMotion
entityRef.inMotion -> boolean
Whether the running world moves this entity or an ancestor (read-only): an engine system such as an animation, or in play a component's update, has placed it on more than one frame, and no authoring write has placed it since. Model mobility "auto" resolves such geometry movable.
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/internal
entityRef.internal -> boolean
Whether default listings skip this entity.
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/isLocal
entityRef.isLocal(self) -> boolean
Whether this peer owns this entity.
Parameters
self
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/localEulerAngles
entityRef.localEulerAngles -> { [string]: any }
Parent-relative euler degrees.
Returns { [string]: any }
typed/builtin//modules/api/engine/entity/members/entityRef/localPosition
entityRef.localPosition -> { [string]: any }
Parent-relative position.
Returns { [string]: any }
typed/builtin//modules/api/engine/entity/members/entityRef/localRotation
entityRef.localRotation -> { [string]: any }
Parent-relative rotation quaternion.
Returns { [string]: any }
typed/builtin//modules/api/engine/entity/members/entityRef/localScale
entityRef.localScale -> { [string]: any }
Parent-relative scale.
Returns { [string]: any }
typed/builtin//modules/api/engine/entity/members/entityRef/lock
entityRef.lock(self) -> ()
Set this entity's destroy lock.
Parameters
self
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/lock_components
entityRef.lock_components(self, names: { string }, flags: { [string]: any }?) -> ()
Lock named components on this entity.
Parameters
selfnames{ string }flags{ [string]: any }(optional)
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/locked
entityRef.locked -> boolean
Whether this entity carries a destroy lock.
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/locks
entityRef.locks(self) -> { destroy: boolean, components: { [string]: any } }
This entity's current lock state.
Parameters
self
Returns { destroy: boolean, components: { [string]: any } }
typed/builtin//modules/api/engine/entity/members/entityRef/lookAt
entityRef.lookAt(self, target: any, up: any?) -> (boolean, string?)
Aim this entity at a world point: writes the world rotation whose forward points at the target. Takes three coordinates, one point table or vec handle, or an entity by id, name or proxy. The optional up decides the roll around the aim.
Parameters
selftargetanyupany(optional)
Returns (boolean, string?)
typed/builtin//modules/api/engine/entity/members/entityRef/lossyScale
entityRef.lossyScale -> { [string]: any }
World scale, as the hierarchy leaves it.
Returns { [string]: any }
typed/builtin//modules/api/engine/entity/members/entityRef/name
entityRef.name -> string
This entity's Name component value.
Returns string
typed/builtin//modules/api/engine/entity/members/entityRef/networkScope
entityRef.networkScope -> string
How far this entity replicates.
Returns string
typed/builtin//modules/api/engine/entity/members/entityRef/orientedBounds
entityRef.orientedBounds(self) -> { min: any, max: any, center: any, size: any }?
The subtree's extents in this entity's own frame.
Parameters
self
Returns { min: any, max: any, center: any, size: any }?
typed/builtin//modules/api/engine/entity/members/entityRef/origin
entityRef.origin -> string
What produced this entity.
Returns string
typed/builtin//modules/api/engine/entity/members/entityRef/owner
entityRef.owner(self) -> number
The peer owning this entity.
Parameters
self
Returns number
typed/builtin//modules/api/engine/entity/members/entityRef/parent
entityRef.parent -> entityRef?
This entity's parent, or nil for a root. Assigning an entity (an entityRef or an id) reparents this one and keeps its world transform, so it stays where it stands; assigning nil detaches it the same way. setParent(parent, { keepWorldTransform = false }) reparents it keeping its local transform instead.
Returns entityRef?
child.parent = group
print(child.parent.name)
child.parent = nil
typed/builtin//modules/api/engine/entity/members/entityRef/participation
entityRef.participation -> string
This entity's runtime participation.
Returns string
typed/builtin//modules/api/engine/entity/members/entityRef/position
entityRef.position -> { [string]: any }
World position.
Returns { [string]: any }
typed/builtin//modules/api/engine/entity/members/entityRef/rename
entityRef.rename(self, newName: string) -> ()
Change this entity's Name component.
Parameters
selfnewNamestring
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/renderLayer
entityRef.renderLayer -> string
The render layers this entity is on, space-separated.
Returns string
typed/builtin//modules/api/engine/entity/members/entityRef/rotation
entityRef.rotation -> { [string]: any }
World rotation, as a quaternion.
Returns { [string]: any }
typed/builtin//modules/api/engine/entity/members/entityRef/saveAs
entityRef.saveAs(self, name: string) -> any
Save this entity as a content asset.
Parameters
selfnamestring
Returns any
typed/builtin//modules/api/engine/entity/members/entityRef/setActive
entityRef.setActive(self, active: boolean) -> ()
Set whether this entity is active.
Parameters
selfactiveboolean
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setInternal
entityRef.setInternal(self, internal: boolean) -> ()
Set whether default listings skip this entity.
Parameters
selfinternalboolean
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setNetworkScope
entityRef.setNetworkScope(self, scope: string) -> ()
Set how far this entity replicates.
Parameters
selfscopestring
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setParent
entityRef.setParent(self, parentId: string, opts: { [string]: any }?) -> ()
Reparent this entity. Keeps its world transform; pass { keepWorldTransform = false } to keep its local transform instead. Assigning entity(id).parent is the same reparent with the world transform kept.
Parameters
selfparentIdstringopts{ [string]: any }(optional)
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setParticipation
entityRef.setParticipation(self, mode: string) -> ()
Set this entity's runtime participation.
Parameters
selfmodestring
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setRenderLayer
entityRef.setRenderLayer(self, names: any) -> ()
Set this entity's render layer.
Parameters
selfnamesany
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setRenderLayerTree
entityRef.setRenderLayerTree(self, names: any) -> ()
Set render layer for this entity and its descendants.
Parameters
selfnamesany
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setRenderLayers
entityRef.setRenderLayers(self, names: any) -> ()
Set this entity's render layers.
Parameters
selfnamesany
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setSessionScoped
entityRef.setSessionScoped(self, scoped: boolean) -> ()
Scope this entity to the session.
Parameters
selfscopedboolean
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setSynced
entityRef.setSynced(self, synced: boolean) -> ()
Set whether this entity replicates.
Parameters
selfsyncedboolean
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setSyncedTree
entityRef.setSyncedTree(self, synced: boolean) -> ()
Set replication for this entity and its descendants.
Parameters
selfsyncedboolean
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/setTemporary
entityRef.setTemporary(self, temporary: boolean) -> ()
Set whether saves skip this entity.
Parameters
selftemporaryboolean
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/show
entityRef.show(self) -> ()
Resume drawing this entity and its descendants and lighting the scene with the lights they carry, undoing hide(): a light that held the sun or ambient term when it was hidden takes it back. A mesh whose Model / SkinnedModel visible field is false stays hidden.
Parameters
self
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/synced
entityRef.synced -> boolean
Whether this entity replicates.
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/temporary
entityRef.temporary -> boolean
Whether saves skip this entity.
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/temporaryInHierarchy
entityRef.temporaryInHierarchy -> boolean
Whether saves skip this entity via an ancestor.
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityRef/transform
entityRef.transform -> { [string]: any }
This entity's transform.
Returns { [string]: any }
typed/builtin//modules/api/engine/entity/members/entityRef/unlock
entityRef.unlock(self) -> ()
Clear every lock on this entity.
Parameters
self
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/unparent
entityRef.unparent(self, opts: { [string]: any }?) -> ()
Detach this entity from its parent.
Parameters
selfopts{ [string]: any }(optional)
Returns ()
typed/builtin//modules/api/engine/entity/members/entityRef/values
entityRef.values -> entityValues
Named values this entity holds: numbers, vectors and booleans that scripts and engine systems write and read cheaply, and that materials, audio, the UI and replication follow. Kept on this engine unless declared to replicate. The values global takes the same calls with the entity first.
Returns entityValues
typed/builtin//modules/api/engine/entity/members/entityRef/worldMatrix
entityRef.worldMatrix -> { number }
This entity's world matrix.
Returns { number }
typed/builtin//modules/api/engine/entity/members/entityValues/clear
entityValues.clear() -> number
Drop every named value this entity holds; answers how many it held.
Returns number
typed/builtin//modules/api/engine/entity/members/entityValues/declare
entityValues.declare(name: string, declaration: { type: string?, default: (number | vector | boolean)?, replicate: number? }?) -> ()
State a named value's type, the default it starts at, and the rate in Hz it replicates at; a value with no replicate rate stays on this engine.
Parameters
namestringdeclaration{ type: string?, default: (number | vector | boolean)?, replicate: number? }(optional)
Returns ()
car.values.declare("throttle", { type = "number", replicate = 10 })
typed/builtin//modules/api/engine/entity/members/entityValues/describe
entityValues.describe() -> { { name: string, type: string, value: number | vector | boolean, writer: string, revision: number, replicate: number?, declared: boolean } }
Every named value this entity holds with its type, last writer, revision and replication rate, sorted by name.
Returns { { name: string, type: string, value: number | vector | boolean, writer: string, revision: number, replicate: number?, declared: boolean } }
typed/builtin//modules/api/engine/entity/members/entityValues/get
entityValues.get(name: string) -> (number | vector | boolean)?
The named value this entity holds, or nil.
Parameters
namestring
Returns (number | vector | boolean)?
local rpm = car.values.get("rpm") or 0
typed/builtin//modules/api/engine/entity/members/entityValues/list
entityValues.list() -> { [string]: number | vector | boolean }
Every named value this entity holds, by name.
Returns { [string]: number | vector | boolean }
typed/builtin//modules/api/engine/entity/members/entityValues/remove
entityValues.remove(name: string) -> boolean
Drop a named value; answers whether this entity held it.
Parameters
namestring
Returns boolean
typed/builtin//modules/api/engine/entity/members/entityValues/set
entityValues.set(name: string, value: (number | vector | boolean)?) -> ()
Write a named value: a number, a vector or a boolean; nil removes it. A name keeps the kind of its first value. Nothing is replicated unless the name is declared to replicate.
Parameters
namestringvalue(number | vector | boolean)(optional)
Returns ()
car.values.set("rpm", 3200)
typed/builtin//modules/api/engine/entity/members/entityValues/subscribe
entityValues.subscribe(name: string?, callback: ((number | vector | boolean)?, string, string) -> ()) -> { Connected: boolean, Disconnect: (any) -> () }
Call callback(value, name, entityId) once per frame in which a named value changed, whoever changed it; nil name follows every value of this entity.
Parameters
namestring(optional)callback((number | vector | boolean)?, string, string) -> ()
Returns { Connected: boolean, Disconnect: (any) -> () }
car.values.subscribe("gear", function(gear) print(gear) end)
typed/builtin//modules/api/engine/entity/ref/M/build
M.build(id: string) -> EntityRef
Factory that backs entity(id). Returns a cached proxy when one already exists for id; otherwise allocates and caches a fresh one. The cache is weak-valued so unreferenced proxies are GC'd.
Parameters
idstring— The entity id string.
Returns EntityRef — The (cached) entity proxy — an EntityRef.
local EntityProxy = require("@builtin::modules.api.engine.entity.ref")
local proxy = EntityProxy.build("some-entity-id")
typed/builtin//modules/api/engine/entity/ref/M/componentNameResolutions
M.componentNameResolutions() -> number
How many times normalizing a component name has looked a dotted name up in the asset index, counted since the module loaded.
Returns number
typed/builtin//modules/api/engine/entity/ref/M/componentRoleReads
M.componentRoleReads() -> number
How many times a role query (component.hasRole, byRole,
allByRole) has read a component type's declared role from the
component registry, counted since the module loaded.
Returns number
typed/builtin//modules/api/engine/entity/ref/M/registeredComponentName
M.registeredComponentName(identity: string) -> string
Resolve an asset-qualified component name to the registry key used by component attachment.
Parameters
identitystring
Returns string
typed/builtin//modules/api/engine/environment/environment/capture
environment.capture(x: number, y: number, z: number) -> boolean
Bake the scene into the environment from (x, y, z) as the single global
reflection (slot 0 + one full-coverage probe). Every PBR surface reflects it.
Queued — takes effect on the next frame. For multiple proximity-blended
probes use the reflectionProbe system instead.
Parameters
xnumber— World X of the capture position.ynumber— World Y of the capture position.znumber— World Z of the capture position.
Returns boolean — True — the capture was queued.
environment.capture(0, 2, 0)
typed/builtin//modules/api/engine/environment/environment/captureSky
environment.captureSky(x: number?, y: number?, z: number?, strengths: { diffuse: number?, reflection: number? }?) -> boolean
Render the SKY alone into the environment's sky slot from (x, y, z) and
arm the sky fallback. A reflective surface no probe covers then reflects the
sky rather than black, and a partially covered one blends the shortfall
against it. The capture holds whatever the scene's sky draws — a gradient, a
physical atmosphere, a skybox material — with no geometry in it, so it stays
correct wherever the camera goes. Once captured, the slot follows the sky
the scene draws: a sky that changes is recaptured from the same position.
strengths states how much of the slot's light a surface takes: diffuse
as irradiance (zpbr_sky_irradiance), reflection as reflection
(zpbr_sky_environment), each 1 when omitted. A member that publishes its
sky into the slot states its own. Queued — takes effect on the next frame.
Parameters
xnumber(optional) — World X of the capture position. Defaults to 0.ynumber(optional) — World Y of the capture position — the altitude a height-dependent atmosphere is sampled at. Defaults to 0.znumber(optional) — World Z of the capture position. Defaults to 0.strengths{ diffuse: number?, reflection: number? }(optional) —{ diffuse: number?, reflection: number? }, each 1 when omitted.
Returns boolean — True — the sky capture was queued.
environment.captureSky()
environment.captureSky(0, 2, 0, { diffuse = 0.15, reflection = 0.25 })
typed/builtin//modules/api/engine/environment/environment/captureSlot
environment.captureSlot(slot: number, x: number, y: number, z: number) -> boolean
Bake the scene into reflection-probe slot from (x, y, z).
Renders the FULL scene (geometry + sky) six times from that
point into that slot. Register the probe's position+radius via setProbes
so surfaces blend it by proximity. Queued — takes effect next frame.
Parameters
slotnumber— Reflection-probe slot (0-based).xnumber— World X of the capture position.ynumber— World Y of the capture position.znumber— World Z of the capture position.
Returns boolean — True — the capture was queued.
environment.captureSlot(0, 0, 2, 0)
typed/builtin//modules/api/engine/environment/environment/captureSlotToAsset
environment.captureSlotToAsset(name: string, slot: number, x: number, y: number, z: number, timeoutFrames: number?) -> (string?, string?)
Bake the scene into reflection-probe slot from (x, y, z) AND persist
the 6 rendered faces into a faces6 .texture cubemap asset at
/source/<name>.texture/ (px/nx/py/ny/pz/nz PNGs + a cube.yaml sidecar).
Survives an engine restart and syncs like any other texture. Yields a few
frames while the bake + GPU readback complete; must be called from a
task/coroutine context (component hook, task.spawn, or execute).
Parameters
namestring— Destination asset identity (writes/source/<name>.texture/).slotnumber— Reflection-probe slot (0-based).xnumber— World X of the capture position.ynumber— World Y of the capture position.znumber— World Z of the capture position.timeoutFramesnumber(optional) — Optional max frames to wait for the readback (default 900, past the frames the engine gives a readback before it gives up on one, so what ends the wait is the readback's own answer).
Returns (string?, string?) — The asset path on success, or (nil, errorMessage) on failure.
environment.captureSlotToAsset("probe_lobby", 0, 0, 2, 0)
typed/builtin//modules/api/engine/environment/environment/captureToAsset
environment.captureToAsset(name: string, x: number, y: number, z: number) -> (string?, string?)
Bake the single global reflection AND persist it to a faces6 .texture
asset (slot 0). Yields a few frames; call from a task/coroutine context.
Parameters
namestring— Destination asset identity (writes/source/<name>.texture/).xnumber— World X of the capture position.ynumber— World Y of the capture position.znumber— World Z of the capture position.
Returns (string?, string?) — The asset path on success, or (nil, errorMessage) on failure.
environment.captureToAsset("env_main", 0, 2, 0)
typed/builtin//modules/api/engine/environment/environment/clearSkyVisibility
environment.clearSkyVisibility() -> boolean
Retract the sky-visibility field, so the sky lights every surface as if nothing stood between it and the sky. Queued — takes effect on the next frame.
Returns boolean — True — the retraction was queued.
environment.clearSkyVisibility()
typed/builtin//modules/api/engine/environment/environment/ensureSkyFallback
environment.ensureSkyFallback() -> boolean
Ensure the scene's sky is in the environment's sky slot: a reflective surface no probe covers then reflects the sky rather than black, and a partially covered one blends the shortfall against it. Queues a capture when the sky slot holds none, and re-arms the fallback when a capture is there but switched off. The engine's own state answers both questions, so every member that asks for the sky's light shares one capture. Once captured, the slot follows the sky the scene draws on its own. The slot is filled only by a call like this one: drawing a sky puts nothing in it.
Returns boolean — True if a capture was queued, false if the sky slot already holds one.
environment.ensureSkyFallback()
typed/builtin//modules/api/engine/environment/environment/loadFromAsset
environment.loadFromAsset(name: string) -> (boolean, string?)
Load a persisted global reflection asset into slot 0 and make it the active single reflection (one full-coverage probe).
Parameters
namestring— Source asset identity (reads/source/<name>.texture/).
Returns (boolean, string?) — True on success, or (false, errorMessage) on failure.
environment.loadFromAsset("env_main")
typed/builtin//modules/api/engine/environment/environment/loadSlotFromAsset
environment.loadSlotFromAsset(name: string, slot: number) -> (boolean, string?)
Load a persisted faces6 .texture cubemap (written by
captureSlotToAsset) into reflection-probe slot WITHOUT re-rendering the
scene. Reads the 6 face PNGs from /source/<name>.texture/ and uploads them
into the slot's cube layers. How a persisted probe restores its baked
environment on reload.
Parameters
namestring— Source asset identity (reads/source/<name>.texture/).slotnumber— Reflection-probe slot (0-based).
Returns (boolean, string?) — True on success, or (false, errorMessage) on failure.
environment.loadSlotFromAsset("probe_lobby", 0)
typed/builtin//modules/api/engine/environment/environment/releaseSky
environment.releaseSky() -> boolean
Empty the environment's sky slot and disarm the sky fallback, the state
a renderer starts in: renderer.reflectionEnvironment() reads
skyCaptured = false until a sky is captured again. While the scene draws
a sky, the drawn-sky follower captures it again within a quarter second,
so on a scene with a sky this retakes the slot from scratch.
Returns boolean — True — the release was queued.
environment.releaseSky()
typed/builtin//modules/api/engine/environment/environment/setProbes
environment.setProbes(probes: { any }) -> boolean
Set the active reflection probes' blend data. probes is an array of
{ x, y, z, radius } (or { position = {x,y,z}, radius = r }); index i is
probe slot i. Surfaces blend the probe slots by proximity to these
positions, gathering the highest priority first — each rank takes the
coverage the ranks above it left, so a small interior probe ranked above a
large exterior one wins outright wherever it reaches full weight. Coverage
left over reflects the sky once captureSky has run. Queued for next frame.
Parameters
probes{ any }— Array of{ x, y, z, radius, priority? }, one per active probe slot.prioritydefaults to 0.
Returns boolean — True — the probe data was queued.
environment.setProbes({ { x = 0, y = 2, z = 0, radius = 12 } })
typed/builtin//modules/api/engine/environment/environment/setSkyFallback
environment.setSkyFallback(active: boolean, strengths: { diffuse: number?, reflection: number? }?) -> boolean
Arm or disarm the sky fallback against the sky already captured, with no
recapture. Disarmed, reflections come from the probes alone. Arming is
refused while the sky slot holds no capture (captureSky fills it), since
an uncaptured slot reflects black; renderer.reflectionEnvironment()
reports whether the fallback ended up armed. strengths, when stated, is
how much of the slot's light a surface takes from then on, as captureSky
states it.
Parameters
activeboolean— Whether reflections fall back to the captured sky.strengths{ diffuse: number?, reflection: number? }(optional) —{ diffuse: number?, reflection: number? }, each 1 when omitted.
Returns boolean — True — the change was queued.
environment.setSkyFallback(false)
typed/builtin//modules/api/engine/environment/environment/setSkyVisibility
environment.setSkyVisibility(buffer: any?, field: { [string]: any }) -> (boolean, string?)
Make the cells a compute buffer holds the sky-visibility field: the
share of the world's sky each point sees, which the sky light every
surface receives (its diffuse light and its reflection) is scaled by. A
sealed room sees none of the sky and takes none of its light; a room with a
window takes the sky the window opens on. The buffer holds two vec4s per
cell, X-fastest then Y then Z, res cells standing at the corners of the
box boundsMin .. boundsMax, in the layout zero::environment_types
states. The cells are copied GPU to GPU behind the dispatches that wrote
them, so the buffer can be written and published in the same frame.
@builtin::systems.skyVisibility.skyVisibility builds and keeps this
field for the scene's static geometry; renderer.reflectionEnvironment()
reports the field held as skyVisibility. Queued — takes effect on the
next frame.
Parameters
bufferany(optional) — The compute buffer holding the cells: a buffer handle or its name.field{ [string]: any }—{ boundsMin = {x,y,z}, boundsMax = {x,y,z}, res = {x,y,z} }; every axis needs at least 2 cells, and the field at most 65536.
Returns (boolean, string?) — True once the field is queued, or (false, reason) when it is refused.
environment.setSkyVisibility(cells, { boundsMin = { -8, -1, -8 }, boundsMax = { 8, 6, 8 }, res = { 33, 15, 33 } })
typed/builtin//modules/api/engine/environment/environment/stateFromAsset
environment.stateFromAsset(identity: string) -> (boolean, string?)
Make a faces6 .texture cubemap the environment that cameras stating
it reflect. A camera rendering an isolated environment reflects only what
it states — never the world's sky or reflection probes — so this is what a
mirror or a pane of glass in its frame shows. The cube is stated under
identity, which is the name a camera's environmentMap gives it; stating
one already stated, from the same bytes, reads nothing. Called from a task,
it waits for faces whose bytes are still being fetched (the web build
fetches builtin images); called outside one, a face not yet fetched is
answered as missing.
Parameters
identitystring— The cube texture, by the identityasset.resolvetakes.
Returns (boolean, string?) — True once the environment is queued, or (false, errorMessage).
task.spawn(environment.stateFromAsset, "@builtin::textures.studio_environment")
typed/builtin//modules/api/engine/font/font/coverage
font.coverage(bytes: buffer | string) -> string?
The codepoints a font file maps to a glyph, as the coverage text
font.declare reads: comma-separated inclusive hexadecimal ranges.
Parameters
bytesbuffer | string— Raw font-file bytes (TTF / OTF), or a bakedZFNTpayload.
Returns string? — Coverage text, or nil if the bytes don't parse as a font.
local cov = font.coverage(assert(vfs.read("/zero/source/fonts/MyCJK.otf")))
typed/builtin//modules/api/engine/font/font/declare
font.declare(name: string, coverage: string, opts: table) -> number
Declare an on-demand face: a face known by the codepoints it covers
and the names that select it, whose bytes are read only when a text
surface first needs it. Until then the face costs its declaration and
nothing else, so a session that never shows its script or names its family
never reads its file. When a label, a text.* object, SVG text or
font.prefetch reaches a covered character no installed face draws, or a
text names the face's own name, its family or one of its aliases in its
font family, the engine requests the face: its file is read and registered
with font.register(name, bytes, opts), and every text surface draws from
it from then on. A family name requests the face of the family whose
role the text's weight and slant ask for. font.glyph,
font.textMesh and font.load install a face they name. Every .font
asset declares its faces through this call.
Parameters
namestring— The name the face is declared and registered under.coveragestring— The codepoints it covers: comma-separated inclusive hexadecimal ranges ("3040-30ff,4e00"), the textfont.coverage(bytes)writes;""for a face selected by its names alone.optstable—{ file: string, family: string?, role: string?, aliases: {string}? }naming the VFS path of the font file (TTF / OTF, or a baked ZFNT) and thefont.registeroptions it installs with;family,roleandaliasesare also the names and slot that select it.
Returns number — How many codepoints the coverage holds.
font.declare("MyCJK", assert(font.coverage(assert(vfs.read("/zero/source/fonts/MyCJK.otf")))), { file = "/zero/source/fonts/MyCJK.otf" })
typed/builtin//modules/api/engine/font/font/glyph
font.glyph(name: string, codepoint: number) -> any
Read one glyph's vectorized outline from a registered font, in font
units (resolution-independent — scale by fontSize / unitsPerEm). A face
declared on demand (font.declare, a .font asset) that name selects
is installed by the call when its file can be read now, and requested
otherwise (font.load waits for it).
Parameters
namestring— Registered family name.codepointnumber— Unicode codepoint (e.g.string.byte("A")).
Returns any — { advance, unitsPerEm, bbox = {xMin,yMin,xMax,yMax}, contours } where each contour is { start = {x,y}, segments = { {kind="line|quad|cubic", ...} } }, or nil if the font isn't registered.
local g = font.glyph("Inter", string.byte("A"))
typed/builtin//modules/api/engine/font/font/list
font.list() -> { string }
List every registered font family name.
Returns { string } — Array of family-name strings.
for _, fam in font.list() do print(fam) end
typed/builtin//modules/api/engine/font/font/load
font.load(name: string, opts: { bold: boolean?, italic: boolean? }?) -> (string?, string?)
Install the face a text naming the family name is drawn in, and wait
until it is: the face declared on demand that name selects (its own name,
its family's or an alias) in the weight and slant opts asks for, read
and registered on every text surface: the UI and SVG text draw in it from
the frame after the one it registered in, so the call returns in such a
frame. A face installed in an earlier frame, or a name only a registered
face answers to, answers at once. Yields while the face loads.
Parameters
namestring— A face's name, or a family or alias name ("serif","Arial").opts{ bold: boolean?, italic: boolean? }(optional) —{ bold: boolean?, italic: boolean? }: the face of the family to install.
Returns (string?, string?) — The name the installed face is registered under, or nil and why when no face answers to name or its file could not be installed.
local face = font.load("serif", { bold = true })
typed/builtin//modules/api/engine/font/font/observe
font.observe() -> { any }
What the text system is holding for fonts: one row per family the
shaper can resolve, with its face count, the numeric weights those faces
carry, whether any of them is slanted, and whether the family arrived
through a registration rather than from the platform. weights is what a
style's weight can name for that family. The same rows are fonts in
text.observe().
Returns { any } — Array of { family, faces, weights, italic, loaded }.
for _, f in ipairs(font.observe()) do print(f.family, #f.weights) end
typed/builtin//modules/api/engine/font/font/onDemand
font.onDemand() -> { any }
Every on-demand face font.declare declared, in declaration order, and
where each stands: declared (its file never read), requested (a
character it covers, or a family name selecting it, reached a text
surface that could not draw it, and its file is being read), installed (registered on every text surface; bytes
is the size of the file it installed from) or failed (error says why).
requestedBy is the character whose miss requested it, requestedFor
the family name whose use requested it, family the family group it
installs into (opts.family of its font.declare, else its own name) and
role the slot it fills there; ui.listFonts() lists each face under
that family's row.
Returns { any } — Array of { name, family, role, state, codepoints, requestedBy, requestedFor, bytes, error }.
for _, f in ipairs(font.onDemand()) do print(f.name, f.state, f.requestedBy) end
typed/builtin//modules/api/engine/font/font/parse
font.parse(bytes: buffer | string) -> string?
Parse a font file (TTF / OTF raw bytes) ONCE into the baked, vectorized
glyph format (ZFNT): per-glyph vector outlines + metrics + character map,
plus the original bytes. Heavy — run at import time (the .font assetType's
onCreate / the font importer), then store the result as the asset payload.
font.register loads it cheaply.
Parameters
bytesbuffer | string— Raw font-file bytes (binary-safe) — TTF / OTF.
Returns string? — Baked ZFNT payload (binary-safe string), or nil if the bytes don't parse as a font.
local zfnt = font.parse(assert(vfs.read("/zero/source/Inter.ttf")))
typed/builtin//modules/api/engine/font/font/prefetch
font.prefetch(text: string) -> number
Request, ahead of drawing it, every on-demand face covering a character
of text that no requested or installed face covers and the face every
text surface starts with does not draw: a screen about to show a script
starts reading its faces before its first frame.
Parameters
textstring— Text whose characters the faces must cover.
Returns number — How many faces this call requested.
font.prefetch("日本語")
typed/builtin//modules/api/engine/font/font/ready
font.ready(text: string) -> boolean
Whether text draws without waiting on an on-demand face: no
character of it is covered by a face still declared or requested.
Call font.prefetch(text) first, then open the screen once this answers
true, and its first frame draws every glyph. True as well for a character
no declared face covers (ui.missingGlyphs() names it once drawn), for one
the face every text surface starts with draws, and for a face that failed
(font.onDemand() says why).
Parameters
textstring— Text to be drawn.
Returns boolean — Whether every on-demand face the text needs is installed.
font.prefetch(title); task.spawn(function() while not font.ready(title) do task.wait() end; ui.showScreen("title") end)
typed/builtin//modules/api/engine/font/font/reconcile
font.reconcile() -> { any }
Every family the text shaper can resolve, held against what the shaper
does with it. family is the name, faces how many faces of it the font
database holds, weights the numeric weights those faces carry, loaded
whether it arrived through a registration rather than from the platform,
registered whether content registered the name, selectable whether some
style naming the family reaches it, matched whether fontFamily = family
on its own reaches it — the family name at the default weight over Latin
text — weight the weight it needs when the default is not it, shapedWith
the family the name selects, spelled the way the font file spells it, which
for a registration name is the family declared inside the file rather than
the name the asset carries, and reason why when the face that answered is
not that family. A
family is probed at its own weights and over content from several scripts,
so a family reachable only at one weight or covering only one script is
reported selectable, with matched false and weight naming what the style
must carry. Every probe object is destroyed again, so the live text-object
count is where it was.
Returns { any } — Array of { family, faces, weights, loaded, registered, selectable, matched, weight, shapedWith, reason }.
for _, f in ipairs(font.reconcile()) do if f.selectable and not f.matched then print(f.family, f.weight) end end
typed/builtin//modules/api/engine/font/font/register
font.register(name: string, zfnt: string, opts: table?) -> any
Register a baked font (ZFNT from font.parse) under name, making it
usable on every text surface via fontFamily = "<name>". Loads the
vectorized glyph data into the runtime store (for font.glyph /
font.textMesh) and feeds the embedded face to the 2D text and egui UI
systems. Raw font bytes (TTF / OTF) register too: their tables are read
and the glyph outlines are baked the first time font.glyph /
font.textMesh reads one. A name declared with font.declare is installed
by this call. Registering a name again replaces what the earlier call
installed under it: a name, group or slot the earlier call gave the face
and this one does not stops selecting it, and text laid out under a name
whose face changed is laid out again.
opts groups several weight/style faces under one CSS family and maps
web-font names onto it: opts.family is the shared group key, opts.role
is "regular" | "bold" | "italic" | "bolditalic", and opts.aliases is a
list of extra selectable names (web fonts + CSS generics like "Arial",
"sans-serif") that resolve to this group, matched case-insensitively.
With a group set, font-weight / font-style on a font-family pick the
real metric-compatible face instead of a synthesized one.
Parameters
namestring— Family name to register under.zfntstring— BakedZFNTpayload fromfont.parse(binary-safe string).optstable(optional) —{ family: string?, role: string?, aliases: {string}? }— group key, weight/style role, and case-insensitive selectable aliases.
Returns any — { family, faces, glyphCount } on success, or nil on failure.
local info = font.register("Inter", assert(font.parse(assert(vfs.read("/zero/source/Inter.ttf")))))
typed/builtin//modules/api/engine/font/font/textMesh
font.textMesh(name: string, text: string, opts: table?) -> any
Tessellate a string into renderable mesh geometry from a registered
font's glyph outlines — true 3D text, laid out left-to-right by advance
(newlines drop a line). Hand the result to renderer.mesh.create() (GPU)
or asset.create("mesh") (persistable). A face declared on demand that
name selects is installed by the call when its file can be read now.
Parameters
namestring— Registered family name.textstring— String to lay out.optstable(optional) —{ size?=1, depth?=0 (extrude, EM units), tolerance?=0.0015, letterSpacing?=0, lineHeight?=0 }.
Returns any — { positions, indices, normals, uvs } as flat float / u32 arrays, or nil if the font isn't registered or the string is all whitespace.
local geom = font.textMesh("Inter", "Hello", { size = 1, depth = 0.1 })
typed/builtin//modules/api/engine/frameStream/frameStream/attach
frameStream.attach(texture: string, stream: string, opts: AttachOpts?) -> (string?, string?)
Carry an image the GPU drew out to an open byte stream, frame
after frame. texture is the guid of the render target it was
drawn into — renderer.texture.create({ width = W, height = H })
makes one, and a Camera component draws into it as its
textureHandle; the session reads that target back when a frame
comes due, so what the camera drew last reaches the far end.
stream is a handle from stream.open. What reaches the stream
is one frame's pixels then the next frame's, with nothing between
them: a frame is width * height * bytesPerPixel bytes of tight
rows, written in a single call so a consumer reads a whole frame
or none of it. Each frame is read back off the render thread, so
the stream never holds the renderer up. fps caps how often a
frame is taken and defaults to one per rendered frame; format
accepts "rgb24" (3 bytes per pixel, the default) or "rgba8"
(4) — a call with a format outside those two raises, naming both;
flipY writes the last texture row first. Returns the session
handle, or nil and the reason an empty texture, a handle naming no
open stream, a stream another session already carries, or a
non-positive fps was refused with.
Parameters
texturestring— Guid of the render target the image was drawn into (a Camera's textureHandle).streamstring— Stream handle from stream.open.optsAttachOpts(optional) — Rate, pixel layout and row order (optional).
Returns (string?, string?) — Session handle, or nil and the refusal reason.
local session = frameStream.attach(rt.guid, handle, { fps = 30 })
typed/builtin//modules/api/engine/frameStream/frameStream/detach
frameStream.detach(handle: string) -> boolean
End the session and free the staging buffers it read frames back through. The stream stays open — whoever opened it closes it.
Parameters
handlestring— Session handle from frameStream.attach.
Returns boolean — True if a session was ended, false if handle already named none.
frameStream.detach(session)
typed/builtin//modules/api/engine/frameStream/frameStream/list
frameStream.list() -> { string }
Every live session handle, in a stable order.
Returns { string } — Array of session handles.
for _, h in frameStream.list() do frameStream.detach(h) end
typed/builtin//modules/api/engine/frameStream/frameStream/status
frameStream.status(handle: string) -> FrameStreamStatus?
Report what the session has carried and lost. frames counts
the frames the stream accepted and bytes the bytes they
carried. dropped counts the frames it refused, of which
droppedBackpressure is the part refused because the consumer was
behind; stalledReadbacks counts the frames that came due while
every staging buffer still held a copy on its way from the GPU.
achievedFps is the rate the accepted frames arrived at, across
the span from the first to the most recent, and reads 0 until two
have been accepted — compare it against requestedFps to see a
display running slower than it was asked to. lastCopyFrame is
the engine frame, in time.frameCount() numbering, the copy of the
most recent accepted frame was taken on, and is nil until one is
accepted: every copy one engine frame takes of a texture holds the
same image, so two sessions on one texture whose lastCopyFrame
agree hold the same image as the newest frame of their streams.
lastOutcome names what became of the most recent frame offered.
nil when handle names no live session.
Parameters
handlestring— Session handle from frameStream.attach.
Returns FrameStreamStatus? — Session status, or nil when handle names no live session.
local s = frameStream.status(session); print(s.frames, s.dropped, s.achievedFps)
typed/builtin//modules/api/engine/home/home/ensure
home.ensure() -> (string, boolean)
The guid of the account's home world, created the first time it is
needed: an account with no home world gets a new private world, owned
by the person the account acts for (an agent account's is its person's),
and every later call answers that same world. It is the world whose
content home.folder() mounts; a launch with --home-world-guid names
it for the session. Yields while ZeroMind answers. Raises, naming the
reason, on an engine that booted offline, one signed in to no account,
or when ZeroMind cannot be read.
Returns (string, boolean) the home world's guid, and true when this call created it.
local guid, created = home.ensure(); print(guid, created)
typed/builtin//modules/api/engine/home/home/folder
home.folder() -> (string?, string?)
The home folder mounted in this session, /zero/home/<username>,
or nil and the reason no home folder is mounted.
Returns (string?, string?) the folder, or nil and why there is none.
local folder, why = home.folder()
typed/builtin//modules/api/engine/home/home/get
home.get() -> string?
The guid of the account's home world, or nil when the account has
none; it never creates one (home.ensure() does). The same world
home.ensure() answers, whose content home.folder() mounts. Yields while
ZeroMind answers. Raises, naming the reason, on an engine that booted
offline, one signed in to no account, or when ZeroMind cannot be read.
Returns string? the home world's guid, or nil when the account has none.
local guid = home.get(); if guid == nil then print("no home world yet") end
typed/builtin//modules/api/engine/home/home/status
home.status() -> Status
Where the home folder stands in this session. state is
"mounted" (with folder, the path to read and write, owner, the
account it belongs to, world, the guid of the home world that holds it,
files, how many files the home world held when it was mounted, and
from, "launch" or "zeromind", saying where that world was named),
"mounting" while a world load is mounting it, or "unmounted" with
reason saying why no home folder is mounted, and undecided true
while no world has been opened in the editor yet to decide it. While the
open world is the account's home world, the status is "unmounted" with
openWorld true and world naming it: its content is /zero/source.
Returns Status — The home folder's status.
local s = home.status(); if s.state == "mounted" then vfs.write(s.folder .. "/notes.md", "hi") end
typed/builtin//modules/api/engine/http/http/get_bytes
http.get_bytes(url: string, headers: Headers?, timeoutMs: TimeoutMs?, expectedStatuses: ExpectedStatuses?) -> PromiseId
Async HTTP GET returning raw bytes (binary-safe string).
Suitable for piping into vfs.write to download a file.
Parameters
urlstring— Request URL.headersHeaders(optional) — Header key-value pairs (optional).timeoutMsTimeoutMs(optional) — How long the request is given to be answered, in milliseconds; the engine's own bound when left out, none when 0 (optional).expectedStatusesExpectedStatuses(optional) — HTTP statuses this caller handles as an answer it expected, e.g.{ 404 }: a response with one settles the future as any other non-2xx does and is logged as information rather than an error (optional).
Returns PromiseId — A future (PromiseHandle): f:await() or task.await(f) delivers the response, f:state() reads whether it has.
local bytes = task.await(http.get_bytes("https://example.com/sound.ogg"))
typed/builtin//modules/api/engine/http/http/get_json
http.get_json(url: string, headers: Headers?, timeoutMs: TimeoutMs?, expectedStatuses: ExpectedStatuses?) -> PromiseId
Async HTTP GET returning JSON. Returns a future (a
PromiseHandle) at once, with the request in flight: keep it,
f:await() (or task.await(f)) when the response is needed, and
f:state() to see whether it has arrived without waiting.
Parameters
urlstring— Request URL.headersHeaders(optional) — Header key-value pairs (optional).timeoutMsTimeoutMs(optional) — How long the request is given to be answered, in milliseconds; the engine's own bound when left out, none when 0 (optional).expectedStatusesExpectedStatuses(optional) — HTTP statuses this caller handles as an answer it expected, e.g.{ 404 }: a response with one settles the future as any other non-2xx does and is logged as information rather than an error (optional).
Returns PromiseId — A future (PromiseHandle): f:await() or task.await(f) delivers the response, f:state() reads whether it has.
local data = task.await(http.get_json("https://api.example.com/info"))
local record = task.await(http.get_json(recordUrl, nil, nil, { 404 })) -- a missing record is an answer
typed/builtin//modules/api/engine/http/http/post_bytes
http.post_bytes(url: string, headers: Headers?, body: JsonBody?, timeoutMs: TimeoutMs?, expectedStatuses: ExpectedStatuses?) -> PromiseId
Async HTTP POST returning raw bytes — use for APIs that accept JSON input but return binary output (audio, images).
Parameters
urlstring— Request URL.headersHeaders(optional) — Header key-value pairs (optional).bodyJsonBody(optional) — JSON body (optional).timeoutMsTimeoutMs(optional) — How long the request is given to be answered, in milliseconds; the engine's own bound when left out, none when 0 (optional).expectedStatusesExpectedStatuses(optional) — HTTP statuses this caller handles as an answer it expected, e.g.{ 404 }: a response with one settles the future as any other non-2xx does and is logged as information rather than an error (optional).
Returns PromiseId — A future (PromiseHandle): f:await() or task.await(f) delivers the response, f:state() reads whether it has.
local audio = task.await(http.post_bytes(ttsUrl, nil, { text = "hello" }))
typed/builtin//modules/api/engine/http/http/post_json
http.post_json(url: string, headers: Headers?, body: JsonBody?, timeoutMs: TimeoutMs?, expectedStatuses: ExpectedStatuses?) -> PromiseId
Async HTTP POST returning JSON. Body is a Luau table; the FFI layer JSON-encodes it before the request goes out.
Parameters
urlstring— Request URL.headersHeaders(optional) — Header key-value pairs (optional).bodyJsonBody(optional) — JSON body (optional).timeoutMsTimeoutMs(optional) — How long the request is given to be answered, in milliseconds; the engine's own bound when left out, none when 0 (optional).expectedStatusesExpectedStatuses(optional) — HTTP statuses this caller handles as an answer it expected, e.g.{ 404 }: a response with one settles the future as any other non-2xx does and is logged as information rather than an error (optional).
Returns PromiseId — A future (PromiseHandle): f:await() or task.await(f) delivers the response, f:state() reads whether it has.
local r = task.await(http.post_json(url, nil, { name = "Alice" }))
typed/builtin//modules/api/engine/http/http/progress
http.progress(handle: PromiseId) -> UploadProgress?
How far the upload http.upload returned handle for has got:
sent, the bytes of its file sent so far, and total, the bytes the
file holds. Nil for a handle that names no upload in flight: one never
made, or one whose future has settled.
Parameters
handlePromiseId— The futurehttp.uploadreturned.
Returns UploadProgress? — { sent, total }, or nil.
local p = http.progress(f) if p then print(p.sent, "of", p.total) end
typed/builtin//modules/api/engine/http/http/request
http.request(method: string, url: string, headers: Headers?, body: JsonBody?, timeoutMs: TimeoutMs?, expectedStatuses: ExpectedStatuses?) -> PromiseId
Async HTTP request with an arbitrary verb (GET/POST/PUT/PATCH/ DELETE/…) returning JSON. Body is a Luau table; an empty 2xx response resolves to an empty table.
Parameters
methodstring— HTTP verb (case-insensitive).urlstring— Request URL.headersHeaders(optional) — Header key-value pairs (optional).bodyJsonBody(optional) — JSON body (optional).timeoutMsTimeoutMs(optional) — How long the request is given to be answered, in milliseconds; the engine's own bound when left out, none when 0 (optional).expectedStatusesExpectedStatuses(optional) — HTTP statuses this caller handles as an answer it expected, e.g.{ 404 }: a response with one settles the future as any other non-2xx does and is logged as information rather than an error (optional).
Returns PromiseId — A future (PromiseHandle): f:await() or task.await(f) delivers the response, f:state() reads whether it has.
local w = task.await(http.request("PATCH", url, hdrs, { description = "hi" }))
typed/builtin//modules/api/engine/http/http/request_raw
http.request_raw(method: string, url: string, headers: Headers?, body: buffer | string | nil?, timeoutMs: TimeoutMs?, expectedStatuses: ExpectedStatuses?) -> PromiseId
Async HTTP request with an arbitrary verb and a RAW binary request body (a binary-safe string), for content-addressed blob uploads. The resolved value is the response body text.
Parameters
methodstring— HTTP verb (case-insensitive).urlstring— Request URL.headersHeaders(optional) — Header key-value pairs (optional).bodybuffer | string | nil(optional) — Raw binary request body (optional).timeoutMsTimeoutMs(optional) — How long the request is given to be answered, in milliseconds; the engine's own bound when left out, none when 0 (optional).expectedStatusesExpectedStatuses(optional) — HTTP statuses this caller handles as an answer it expected, e.g.{ 404 }: a response with one settles the future as any other non-2xx does and is logged as information rather than an error (optional).
Returns PromiseId — A future (PromiseHandle): f:await() or task.await(f) delivers the response, f:state() reads whether it has.
local r = task.await(http.request_raw("POST", blobsUrl, hdrs, pngBytes))
typed/builtin//modules/api/engine/http/http/upload
http.upload(method: string, url: string, headers: Headers?, path: string, timeoutMs: TimeoutMs?, expectedStatuses: ExpectedStatuses?) -> PromiseId
Async HTTP request whose body is the file at a VFS path, read a
piece at a time from where it lies and sent as it is read, so a file
of any size (a recorded film) is never held whole in memory. The
request is sent once. The resolved value is the response body text.
http.progress(f) reads how much of the file has been sent while it
runs.
Parameters
methodstring— HTTP verb (case-insensitive).urlstring— Request URL.headersHeaders(optional) — Header key-value pairs (optional).pathstring— VFS path of the file sent as the body; a relative path resolves under/source/. The file is held to what the caller's ownvfs.readreaches: a file in a home folder is refused to code a world ships.timeoutMsTimeoutMs(optional) — How long the request is given to be answered, in milliseconds; the engine's own bound when left out, none when 0 (optional).expectedStatusesExpectedStatuses(optional) — HTTP statuses this caller handles as an answer it expected, e.g.{ 404 }: a response with one settles the future as any other non-2xx does and is logged as information rather than an error (optional).
Returns PromiseId — A future (PromiseHandle): f:await() or task.await(f) delivers the response, f:state() reads whether it has.
local f = http.upload("PUT", url, { ["Content-Type"] = "video/mp4" }, "/source/local/recordings/take.mp4", 0)
typed/builtin//modules/api/engine/httpServer/httpServer/address
httpServer.address(path: string) -> (string?, string?)
The URL a path answers on — scheme, host, port and the /app mount,
ready to be fetched or printed for someone to open. Takes the same path
spelling route does, and reads the interface and port from the socket
routes answer on: the address listen opened while one is open, and the
engine's own server otherwise.
Parameters
pathstring— Path under the/appmount, e.g. "/status".
Returns (string?, string?) — The URL, or nil plus the reason there is none — this engine holds no address, or the path is not one a route can be registered at.
print(httpServer.address("/status")) --> http://127.0.0.1:7607/app/status
typed/builtin//modules/api/engine/httpServer/httpServer/listen
httpServer.listen(target: string) -> (HttpListener?, string?)
Hold an interface and port of this world's own, and answer content routes on it.
The host in target is the interface bound, and the whole of what decides
who can reach those routes: "127.0.0.1:8080" answers programs on this
machine, "0.0.0.0:8080" answers any host that routes to this machine on
that port — a phone on the same wifi, and whatever else the network lets
through. Bind loopback unless you want that. A port of 0 asks the
operating system for a free one, which the returned record reports, and
http:// may be spelled out in front.
This address serves the routes registered under the /app mount. The
engine's own /engine/* tree answers on the loopback server it booted
with, whose interface stays what the boot bound.
The address belongs to the chunk that opened it and is released when that chunk runs again, so an edited module holds the address its current source names. Asking for the address already held is the same address back.
Parameters
targetstring— Interface and port to hold, e.g. "0.0.0.0:8080".
Returns (HttpListener?, string?) — The listener record, or nil plus the reason the target or the bind was refused.
local l = assert(httpServer.listen("0.0.0.0:8080"))
typed/builtin//modules/api/engine/httpServer/httpServer/route
httpServer.route(method: string, path: string, handler: HttpHandler, options: HttpRouteOptions?) -> (number?, string?)
Serve one method and path from this engine, answering each matching
request with handler.
The path is relative to the /app mount, and a trailing /* segment
matches the rest of the path — "/files/*" answers /app/files/a/b, with
"a/b" in request.wildcard. An exact path answers ahead of a wildcard,
and among wildcards the longest one wins.
One method and path is served by one handler. Registering an address
another chunk serves returns nil and a reason naming the handle and the
chunk holding it; httpServer.routes() finds that handle and
httpServer.unroute frees the address. Registering an address this same
chunk already serves takes it back and releases the handler it replaces,
so a chunk that runs twice serves the handler it just built.
The handler runs on the script thread; a route registered from a worker job keeps its handler in that worker's VM, which runs it once per request as the job that registered it while the request waits for its value and the engine thread waits for nothing. The route lasts until it is unregistered or the world changes or the scripting state resets, whatever became of the job that made it. Raising inside the handler answers 500 and writes the error to the engine log; returning something that is not a response table or a string answers 500 saying what arrived.
Parameters
methodstring— HTTP verb, e.g. "GET" or "POST".pathstring— Path under the/appmount, e.g. "/status" or "/files/*".handlerHttpHandler— Called with the request table; returns a response table or a body string.optionsHttpRouteOptions(optional) —{ timeoutMs? }— how long a request waits for this handler.
Returns (number?, string?) — The route handle, or nil plus the reason it was not registered.
local h = httpServer.route("GET", "/status", function(req)
typed/builtin//modules/api/engine/httpServer/httpServer/routes
httpServer.routes() -> { HttpRoute }
Every route this engine currently serves, in registration order — handle, method, registered path, the address it answers on, its full URL, the chunk that registered it, and how long a request for it waits.
Returns { HttpRoute } — An array of route records.
for _, r in ipairs(httpServer.routes()) do print(r.method, r.url, r.owner) end
typed/builtin//modules/api/engine/httpServer/httpServer/status
httpServer.status() -> HttpServerStatus
Whether this engine serves content routes, on which interface, port
and mount, who can reach them, and how many routes and waiting requests it
holds. host, port, url and reach are read from the socket routes
answer on — the one listen opened while one is open, and the engine's
own server otherwise — and listeners carries every address, each with
its own reach. When supported is false, reason says why: a browser tab
answers HTTP requests and holds no address of its own.
Returns HttpServerStatus — { supported, reason?, host?, port?, url?, reach?, prefix, routeCount, pending, listeners }.
local s = httpServer.status(); print(s.url, s.reach)
typed/builtin//modules/api/engine/httpServer/httpServer/unlisten
httpServer.unlisten() -> boolean
Release the address listen opened. Returns once the socket is free,
so the same port binds again straight after.
Returns boolean — True when an address was held.
httpServer.unlisten()
typed/builtin//modules/api/engine/httpServer/httpServer/unroute
httpServer.unroute(handle: number) -> boolean
Stop serving a route and release its handler. The address is free for another registration once this returns true.
Parameters
handlenumber— The handlehttpServer.routereturned.
Returns boolean — True when a route with this handle was registered.
httpServer.unroute(h)
typed/builtin//modules/api/engine/i18n/i18n/check
i18n.check(root: string?) -> CheckResult
Run the catalog checks origozero.ai runs over every catalog of a
root (<root>/locales/<tag>/*.json, en the source): files that do not
parse, keys a translation has that English lacks, placeholders or markup
that differ from English, plural forms the locale does not use, a
translation with no current review record (<namespace>.review.json;
the finding prints the record to write), and the rest of the shared
checks. A translated locale's terms are held to its glossary,
<root>/glossary/<tag>.json ({ "terms": [ { "source": ["coin", "coins"], "target": ["moeda*"] } ], "exceptions": [], "same_as_english": [] }); without one the check warns.
Parameters
rootstring(optional) — The folder holdinglocales/; the world's/zero/sourceby default.
Returns CheckResult — { root, errors, warnings }, one line per finding.
local r = i18n.check(); for _, e in r.errors do print(e) end
typed/builtin//modules/api/engine/i18n/i18n/choice
i18n.choice() -> string?
The locale the player chose for themselves, or nil when they chose none and the chain decides.
Returns string? — The player's choice.
typed/builtin//modules/api/engine/i18n/i18n/choose
i18n.choose(tag: string?) -> ChooseResult
Choose tag as the player's locale, kept on this device for their
ZeroMind account (or for the signed-out player), so it wins the chain
from now on and on every later boot. nil clears the choice and the
chain decides again. A tag no offered locale matches is refused, naming
the offered tags.
Parameters
tagstring(optional) — A tag fromi18n.offered(), or nil to clear the choice.
Returns ChooseResult — { ok, locale?, decidedBy?, reason?, offered? }.
local r = i18n.choose("pt-BR")
if not r.ok then log.warn(r.reason) end
typed/builtin//modules/api/engine/i18n/i18n/emulate
i18n.emulate(tags: { string }?) -> { ok: boolean, locale: string?, platform: { string }?, reason: string? }
Stand tags in for the platform's preferred languages, the way a
visitor whose device or browser reads them would arrive, and negotiate
again: i18n.preferred(), i18n.pick, i18n.locale() and
i18n.onChange all answer as they would for that visitor. nil reads
the platform's own list again. A report the platform makes afterwards
(a language change, a desktop window regaining focus) replaces it. The
player's own choice (i18n.choose) still comes first in the chain, so
clear it with i18n.choose(nil) to see the list decide.
Parameters
tags{ string }(optional) — BCP 47 tags, most preferred first, or nil for the platform's own list.
Returns { ok: boolean, locale: string?, platform: { string }?, reason: string? } — { ok, locale?, platform?, reason? }: the locale and list now in force.
i18n.emulate({ "pt-BR", "en" }) -- try the world as a Brazilian visitor
i18n.emulate(nil) -- back to this machine's own languages
typed/builtin//modules/api/engine/i18n/i18n/explain
i18n.explain(key: string, values: { [string]: any }?) -> Explanation
Where the text of key comes from for the caller: the text, the
locale and file it was found in, and every file searched in order
(locale by locale, layer by layer). The first thing to read when a
screen shows a key, English in a translated screen, or another layer's
wording.
Parameters
keystring—<namespace>.<key>.values{ [string]: any }(optional) — Parameter values, asi18n.ttakes them.
Returns Explanation — { key, found, text, locale?, path?, searched }.
local e = i18n.explain("hud.score"); print(e.found, e.path, e.locale)
typed/builtin//modules/api/engine/i18n/i18n/fallback
i18n.fallback() -> { string }
The chosen locale's fallback chain: the locales a string missing from its catalog is looked up in, in order.
Returns { string } — The fallback locales, en last; empty for en itself.
typed/builtin//modules/api/engine/i18n/i18n/formatAgo
i18n.formatAgo(amount: number, unit: string?, locale: string?) -> string
How long ago something happened, as the caller's text locale writes
it in CLDR's narrow style: seconds before now in the largest unit that
fits (45s ago, 3h ago), or with unit (second, minute, hour,
day, month, year) that many of that unit (há 5 min.).
Parameters
amountnumber— Seconds before now, or a count ofunit.unitstring(optional) — The unitamountcounts, or nil for seconds in the unit that fits.localestring(optional) — A locale tag, in place of the caller's text locale.
Returns string — The relative time.
typed/builtin//modules/api/engine/i18n/i18n/formatBytes
i18n.formatBytes(bytes: number, locale: string?) -> string
A size in decimal units as the caller's text locale or locale
writes it: 228 B, 16.2 KB, 1.5 MB (16,2 KB in Brazilian
Portuguese).
Parameters
bytesnumber— The size in bytes.localestring(optional) — A locale tag, in place of the caller's text locale.
Returns string — The size.
typed/builtin//modules/api/engine/i18n/i18n/formatCompact
i18n.formatCompact(n: number, locale: string?) -> string
A count in the short compact form of the caller's text locale or
locale: 1.2K, 1,2 mil. Below a thousand the number is written whole.
Parameters
nnumber— A whole number.localestring(optional) — A locale tag, in place of the caller's text locale.
Returns string — The count.
typed/builtin//modules/api/engine/i18n/i18n/formatDate
i18n.formatDate(date: { year: number, month: number, day: number }, style: string?, locale: string?) -> string
A calendar date as the caller's text locale (i18n.textLocale())
or locale writes it. style is long (October 1, 2026, 1 de outubro de 2026; the default), medium (Oct 1, 2026), monthYear
(October 2026) or monthDay (Oct 1). Pass the result into a
message as text: i18n.t("hud.last_played", { date = i18n.formatDate(d) }).
Parameters
date{ year: number, month: number, day: number }—{ year, month, day }(the shapeos.date("*t")returns).stylestring(optional) — The date style.localestring(optional) — A locale tag, in place of the caller's text locale.
Returns string — The date.
print(i18n.formatDate(os.date("*t")))
typed/builtin//modules/api/engine/i18n/i18n/formatMoney
i18n.formatMoney(amountMinor: number, currency: string, locale: string?) -> string
An amount of money as the caller's text locale or locale writes
it, given in the currency's minor unit (cents for USD): $12.50,
R$ 12,50.
Parameters
amountMinornumber— The amount in minor units.currencystring— An ISO 4217 code such asBRL.localestring(optional) — A locale tag, in place of the caller's text locale.
Returns string — The amount.
typed/builtin//modules/api/engine/i18n/i18n/formatNumber
i18n.formatNumber(n: number, locale: string?) -> string
A whole number as the caller's text locale (i18n.textLocale()) or
locale writes it: 1,234,567 in English, 1.234.567 in Brazilian
Portuguese.
Parameters
nnumber— A whole number.localestring(optional) — A locale tag, in place of the caller's text locale.
Returns string — The number.
typed/builtin//modules/api/engine/i18n/i18n/has
i18n.has(key: string) -> boolean
Whether a catalog the caller reads holds key, in the player's
locale, its fallback chain or en.
Parameters
keystring—<namespace>.<key>.
Returns boolean — True when some catalog holds it.
typed/builtin//modules/api/engine/i18n/i18n/isText
i18n.isText(value: any?) -> boolean
Whether value is an i18n.text value.
Parameters
valueany(optional) — Any value.
Returns boolean — True for an i18n.text value.
typed/builtin//modules/api/engine/i18n/i18n/locale
i18n.locale() -> string
The locale the engine chose for the player for its own text, a BCP
47 tag such as en or pt-BR. It is always one of i18n.offered();
en, the engine's source language, until a negotiation states another.
To choose among your own content's languages, use i18n.pick.
Returns string — The chosen locale.
if i18n.locale() == "pt-BR" then label.text = "Olá" end
typed/builtin//modules/api/engine/i18n/i18n/offChange
i18n.offChange(id: number) -> boolean
Remove an i18n.onChange subscriber by its watcher id. Returns true
when a live watcher carried that id (false for one already removed, or
ended with the component that made it).
Parameters
idnumber— Watcher id returned byi18n.onChange.
Returns boolean
typed/builtin//modules/api/engine/i18n/i18n/offered
i18n.offered() -> { Locale }
The locales the engine offers for its own text, sorted by tag. Only
an offered locale can be chosen or negotiated. Content picks among its
own languages with i18n.pick.
Returns { Locale } — One { tag, name, nativeName, fallback } per offered locale.
typed/builtin//modules/api/engine/i18n/i18n/onChange
i18n.onChange(callback: (string, { string }) -> ()) -> number
Run callback each time the player's language changes: the
platform's preferred list changes (the player changed their OS, browser
or device language while the engine runs, or i18n.emulate stood a list
in), the player chooses or clears a choice, the ZeroMind language moves,
the offered locales change, the pseudo-locale is switched, or a catalog
file this VM read text from is edited. Called as (locale, preferred),
after every screen built from i18n.text values redrew, and after the
engine renegotiated, so i18n.pick inside it answers for the new state.
A change i18n.emulate or i18n.choose makes reaches this VM's
subscribers before that call returns; one the platform reports reaches
them within a tenth of a second.
A subscription made from a component ends with that component. Returns
a watcher id for i18n.offChange.
Parameters
callback(string, { string }) -> ()— Function invoked as(locale: string, preferred: {string}).
Returns number — The watcher id.
local id = i18n.onChange(function(locale, preferred)
log.info(("locale %s, platform %s"):format(locale, table.concat(preferred, ",")))
end)
typed/builtin//modules/api/engine/i18n/i18n/pick
i18n.pick(available: { string }) -> string
Which of available, the languages your content has text for,
this player reads: the tag the engine's chain picks from the player's
own choice, the language ZeroMind shows them and their platform's list,
matched by the same rules (same tag, the tag truncated, the same
language). The first of available when none of them matches, so list
your fallback first. Call it again (or from i18n.onChange) to follow a
change while they play.
Parameters
available{ string }— BCP 47 tags your content has text for, fallback first.
Returns string — One of available, exactly as written there.
local lang = i18n.pick({ "en", "pt", "es" })
label.text = ({ en = "Welcome!", pt = "Bem-vindo!", es = "¡Bienvenido!" })[lang]
typed/builtin//modules/api/engine/i18n/i18n/plural
i18n.plural(count: number, locale: string?) -> string
The CLDR plural category count takes in the caller's text locale
(i18n.textLocale()), or locale: zero, one, two, few, many
or other. A catalog's plural message picks its form this way; use it
for a choice that is not text.
Parameters
countnumber— The number.localestring(optional) — A locale tag, in place of the caller's text locale.
Returns string — The category.
typed/builtin//modules/api/engine/i18n/i18n/preferred
i18n.preferred() -> { string }
The languages the player's platform says they read, as BCP 47 tags,
most preferred first: the OS language list on Linux, Windows and macOS,
navigator.languages in a browser, the device (or per-app) language list
on Android. Empty when the platform states none.
Returns { string } — The platform's preferred languages.
local first = i18n.preferred()[1]
typed/builtin//modules/api/engine/i18n/i18n/pseudo
i18n.pseudo(on: (boolean | "accented" | "unreadable")?) -> boolean
Show a pseudo-locale in every VM, or stop showing one (false).
true (or "accented") shows qps: every catalog text renders as
accented, bracketed English (⟦Ŝçöŕé⟧), padded by about a third, so
text that did not come from a catalog reads as plain English and a label
too narrow for a longer language overflows. "unreadable" shows qpu:
every catalog text is read in the player's language and drawn at its
length, spaces and punctuation kept, each letter and digit a glyph nobody
reads, so a path walked under it shows whether a person who cannot read
gets through it from pictures, sound and place alone; text that did not
come from a catalog stays readable. Screens built from i18n.text
values redraw. With no argument it changes nothing.
Parameters
on(boolean | "accented" | "unreadable")(optional) —trueor"accented","unreadable", orfalse; nil reads the current state.
Returns boolean — Whether a pseudo-locale is shown; i18n.pseudoLocale() names which.
i18n.pseudo(true) -- every English string left on screen is one no catalog holds
i18n.pseudo("unreadable") -- walk the screen as a person who cannot read
i18n.pseudo(false)
typed/builtin//modules/api/engine/i18n/i18n/pseudoLocale
i18n.pseudoLocale() -> ("accented" | "unreadable")?
The pseudo-locale shown, if any: "accented" (qps, set by
i18n.pseudo(true)) or "unreadable" (qpu, set by
i18n.pseudo("unreadable")).
Returns ("accented" | "unreadable")? — "accented", "unreadable", or nil when none is shown.
if i18n.pseudoLocale() == "unreadable" then print("walking without words") end
typed/builtin//modules/api/engine/i18n/i18n/revision
i18n.revision() -> number
A number that moves whenever a catalog text may read differently: the locale changed, the pseudo-locale was switched, or a catalog file this VM read was written. A build that caches text compares it.
Returns number — The revision.
typed/builtin//modules/api/engine/i18n/i18n/sources
i18n.sources() -> Sources
Every link of the chain the locale was chosen from: the player's
choice, the zeromind language, the platform list, and which link
decided (decidedBy: choice, zeromind, platform or default)
with the tag it matched; and where a choice is kept (choiceKept:
device, or run in an offline engine, which keeps it for that run alone).
Returns Sources — { locale, decidedBy, matched, choice?, zeromind?, platform, signedIn, choiceKept }.
typed/builtin//modules/api/engine/i18n/i18n/t
i18n.t(key: string, values: { [string]: any }?) -> string
The text of key in the player's language, from the catalogs: the
world's /zero/source/locales/<tag>/<namespace>.json, then (for code of
a package) the package's own locales/, then the built-in library's.
A key is <namespace>.<key>: hud.score_label is score_label in
hud.json. A world's (or an installed package's) catalogs are read in
whichever of their languages the player reads (the chain i18n.pick
runs), then en; the library's in the engine's locale, its fallback
chain, then en. The first layer holding the key gives it. values
fills the message's {{ name }} parameters: text as written, whole
numbers grouped the way the message's language groups them, an
i18n.text value as its text, a function as what it returns when the
text renders; count also picks the plural
form (items_one / items_other in the file). A key no catalog holds
reads as the key, said once in the log. While the pseudo-locale is shown
(i18n.pseudo(true)) the text is accented, bracketed English.
Parameters
keystring—<namespace>.<key>, lowercase words joined by.and_.values{ [string]: any }(optional) — Parameter values by name;countpicks the plural form.
Returns string — The text, rendered now.
-- /zero/source/locales/en/hud.json: { "score": "Score: {{ points }}", "lives_one": "{{ count }} life", "lives_other": "{{ count }} lives" }
label.text = i18n.t("hud.score", { points = 1250 }) -- "Score: 1,250"; "Pontos: 1.250" in pt-BR
print(i18n.t("hud.lives", { count = 3 })) -- "3 lives"
typed/builtin//modules/api/engine/i18n/i18n/text
i18n.text(key: string, values: { [string]: any }?) -> Text
A value that reads as the text of key (see i18n.t): tostring
renders it in the player's language at that moment. Pass it wherever a
widget takes text (text, title, header, placeholder, tooltip,
a dropdown's options; every edui widget's label), and the screen
follows the player's language, the pseudo-locale and edits to the
catalog without being built again (ui.refreshLiveText). A value of
values may itself be an i18n.text value, or a function called each
time the text renders, so a value written in the player's language
follows it too: { date = function() return i18n.formatDate(d) end }.
Parameters
keystring—<namespace>.<key>.values{ [string]: any }(optional) — Parameter values by name;countpicks the plural form.
Returns Text — The text value.
ui.registerScreen("hud", { type = "label", props = { text = i18n.text("hud.title") } })
edui.button({ label = i18n.text("editor.save"), onClick = save })
i18n.text("hud.last_played", { date = function() return i18n.formatDate(lastPlayed) end })
typed/builtin//modules/api/engine/i18n/i18n/textLocale
i18n.textLocale() -> string
The locale the caller's text is shown in: for a world's code, the
one of the world's catalog languages the player reads (pt-BR for a
Brazilian player of a world with a locales/pt-BR, even while the
engine shows its own text in English); for a package's code, its
package's; for the engine's own code, i18n.locale(). The formatting
helpers write in it by default, so a date or a count reads in the same
language as the sentence around it.
Returns string — A locale tag.
local lang = i18n.textLocale() -- "pt-BR" for a Brazilian player of a world with pt-BR catalogs
typed/builtin//modules/api/engine/i18n/i18n/upper
i18n.upper(text: string, locale: string?) -> string
text in capitals by the case rules of the caller's text locale or
locale (CONEXÃO, Turkish İ). string.upper changes ASCII letters
only.
Parameters
textstring— The text.localestring(optional) — A locale tag, in place of the caller's text locale.
Returns string — The text in capitals.
typed/builtin//modules/api/engine/jobs/JobHandle/cancel
JobHandle.cancel(self) -> boolean
Drop one refcount. The last drop unregisters the job and the dispatcher stops invoking it.
Parameters
self
Returns boolean
typed/builtin//modules/api/engine/jobs/JobHandle/destroy
JobHandle.destroy(self) -> boolean
Drop one refcount. The last drop unregisters the job and the dispatcher stops invoking it.
Parameters
self
Returns boolean
typed/builtin//modules/api/engine/jobs/JobHandle/id
JobHandle.id -> number
This job's substrate id. Zero once the handle has been cancelled.
Returns number
typed/builtin//modules/api/engine/jobs/JobHandle/info
JobHandle.info(self) -> JobInfo?
This job's latest snapshot row, or nil once the substrate no longer tracks it.
Parameters
self
Returns JobInfo?
typed/builtin//modules/api/engine/jobs/JobHandle/pause
JobHandle.pause(self) -> boolean
Skip this job on subsequent ticks, leaving it registered. False once the substrate no longer tracks it.
Parameters
self
Returns boolean
typed/builtin//modules/api/engine/jobs/JobHandle/resume
JobHandle.resume(self) -> boolean
Run this job again, clearing an errored status. False once the substrate no longer tracks it.
Parameters
self
Returns boolean
typed/builtin//modules/api/engine/jobs/JobHandle/status
JobHandle.status(self) -> JobStatus?
This job's scheduler status, or nil once the substrate no longer tracks it.
Parameters
self
Returns JobStatus?
typed/builtin//modules/api/engine/jobs/JobHandle/valid
JobHandle.valid(self) -> boolean
Whether the substrate still tracks this job.
Parameters
self
Returns boolean
typed/builtin//modules/api/engine/jobs/M/context
M.context() -> JobContext?
What the running item runs as, on a worker: worker, the pool slot of its worker; key, the item's key (nil for an item dispatched without one, and outside an item, as in a watcher); fresh, true for the first item a key runs in this VM since the key bound, so a module tells a cold cache from a missing entry. On the engine thread it answers nil, which is also how code asks whether it runs on a worker.
Returns JobContext? — { worker, key, fresh } on a worker; nil on the engine thread.
local ctx = jobs.context(); if ctx and ctx.fresh then cache = {} end
typed/builtin//modules/api/engine/jobs/M/dispatch
M.dispatch(module: string, entry: string, args: any?, opts: DispatchOptions?) -> PromiseHandle
Run the function entry of the module module on a worker thread and answer a promise of its result, so a long computation holds no frame. module is a require path, read from this line as require reads it. The module and the modules it requires run in a worker VM that boots the prelude and requires modules as the engine thread's VM does, so it has the same globals and modules/api modules: the entry computes from its arguments and returns a value, which the code awaiting the promise applies to the world. A call to a function only the engine thread serves (one that reads or changes the ECS world, the component instances its VM holds, or a table the engine thread has not published yet) is forwarded: from a job it runs on the engine thread, with the same arguments, after every write the job recorded before it, as the principal the job runs as, and its answer or its error returns to the job. The task that made it waits as it waits on a promise, so the worker keeps serving its other tasks and the time parked never counts toward the deadline; each forwarded call takes at least one engine frame, and job:info().forwarded_calls and the system.schedule.frame.forwarded_calls profiler count report them. Arguments and answers cross as copies; a call whose argument holds a function, coroutine or userdata handle, whose answer holds an object of the engine thread's VM, or that is made where the script cannot wait (a metamethod, the top level of a module being required, a batch or queue body) raises an error naming the function and the reason. A watcher the module registers (engine.onModeChange, modules.watch, world.on, vfs.watch and the other engine events) is kept by the worker VM and fires when that VM next starts an item, for the events raised since it registered; save.onMarksLanded is refused there, because the engine reads the value its callback returns inside its own frame. A function the module registers with renderfeature.setTick, jobs.register or httpserver.route stays in the worker VM that registered it, and that VM stays in service for it after the item returns, until the function is unregistered or the world changes or the scripting state resets: the engine posts each call to the worker and never waits for it, and reads the latest completed output (a tick's passes are drawn one frame after the tick that made them, and a frame whose call is still running keeps the last completed output and counts a late call). The entry is a task of the worker VM's own scheduler: it waits on time (task.wait), on frames (task.waitFrames) and on promises (task.await), starts tasks and scopes, and returns its result. The promise settles once the engine thread has applied every write the entry and the tasks it started made before it returned, so the code awaiting it reads all of those writes, as it would after making the same calls on the engine thread; an entry whose last write the engine thread applies in the frame the entry returned settles as soon as one that writes nothing, and otherwise one frame later. It waits as long as the writes do (while no world is open, say) and then resolves with the entry's result. It rejects only when the engine resets the scripting state or changes its world first, and then none of those writes is applied. The tasks it started keep running until they end or the item's deadline ends them; a write one of them makes after the entry returned is not part of what the promise waits for. A promise the worker makes settles on that worker (delay, http.* and jobs.dispatch serve one), and a call whose promise an engine-thread system settles (queue, shell.run of a command it would queue) is refused, naming it. An item runs on whichever worker takes it. With opts.key (a string of 1 to 256 bytes) it runs in the worker VM the key is bound to, after every item of the key dispatched before it has settled and its writes have applied, one at a time and in order, so module state an item of the key leaves (a cache, a plan, a parsed asset) is there for the next; jobs.context().fresh tells the first item of a key in a VM since the key bound, jobs.release ends the binding, and jobs.warm runs a module's one-time setup in every worker VM before items need it. A key's item waits for its VM even while other workers are idle, and /runtime/workers reports the wait per key. An item awaiting an item of its own key is refused at the await, naming the key: the awaiting item holds the key's turn, and the awaited item starts only after it settles; dispatching to its own key without awaiting runs that item after it. Items of a key queued before the world changes or the scripting state resets are refused unrun, naming the reset. opts.supersede = true with a key rejects every item of the key that has not started, naming this one; the running item is untouched. The pool holds at most 65,536 keys at once, and a dispatch with a key past that is refused at the call, naming the bound. args and the result cross as copies: nil, booleans, numbers, strings, buffers, vectors and tables of those, and any other value is refused at this call naming its key path. The promise rejects with the entry's error and stack, or names the deadline when one run of the entry, from a resume to the next yield, takes longer than opts.deadline seconds (default and at most the longest hold on one run, 60 seconds on every platform, native and browser alike; any number above 0 up to it, which a caller may lower and may not raise: a larger one is refused at the call naming the cap). The clock starts at each resume and stops at each yield, so time parked on a promise, task.wait or a frame never counts, every yield resets it, and no sum across runs is kept: an entry that keeps yielding runs until it returns or is cancelled. The tasks it resumed are held to the same deadline. Cancelling the promise (p:cancel()) halts a running entry and keeps a queued one from running. An edit of the module reaches the next dispatch.
Parameters
modulestring— Require path of the module, asrequiretakes it.entrystring— Name of the function in the module's export table.argsany(optional) — The value the entry receives, copied.optsDispatchOptions(optional) — Optional{ deadline: number?, name: string?, key: string?, supersede: boolean? }: the deadline in seconds, what a rejection calls the item, the key it runs as, and whether it supersedes the key's items that have not started.
Returns PromiseHandle — A PromiseHandle settling with a copy of the entry's result.
local heights = jobs.dispatch("@root::terrain.noise", "heights", { size = 256, seed = 7 }):await()
local p = jobs.dispatch("@root::sim.solver", "solve", state, { deadline = 2, name = "solver" }); p:cancel()
local route = jobs.dispatch("@root::paths.graph", "route", { map = "level3", from = a, to = b }, { key = "level3" }):await()
local preview = jobs.dispatch("@root::graph.cook", "cook", edit, { key = graphId, supersede = true })
typed/builtin//modules/api/engine/jobs/M/find
M.find(name: string) -> JobHandle?
Look up a registered job by name. Returns a JobHandle or nil for anonymous / unknown names. Single FFI crossing — returns the id directly, no registry snapshot.
Parameters
namestring— Job name supplied tojobs.register.
Returns JobHandle? — JobHandle or nil.
local job = jobs.find("animation_blend_main")
typed/builtin//modules/api/engine/jobs/M/inspect
M.inspect(target: JobHandle | string) -> JobInfo?
Return a snapshot row by job handle or by name without retrieving a full handle. Single FFI crossing — pulls only the matching row.
Parameters
targetJobHandle | string— JobHandle, or job name string.
Returns JobInfo? — Snapshot row or nil.
local info = jobs.inspect("animation_blend_main")
typed/builtin//modules/api/engine/jobs/M/list
M.list(phase: string?) -> { JobInfo }
List registered job summaries. Pass a phase name to filter to a single phase. Single FFI crossing — only the requested rows cross the bridge.
Parameters
phasestring(optional) — Optional phase filter — nil returns every job.
Returns { JobInfo } — Array of JobInfo rows.
local rows = jobs.list("main")
typed/builtin//modules/api/engine/jobs/M/onRelease
M.onRelease(watcher: (key: string) -> ()) -> () -> ()
Hold watcher in the VM of the module that calls it: each time a key bound to that VM is released (jobs.release), watcher(key) runs there as a task of the VM's scheduler, once per release, so the module drops what it keeps for the key. A worker VM keeps its own watchers, as it keeps engine.on* watchers; a module registers at its top level, which every worker VM that requires it runs. The engine thread's VM holds no key, so a watcher there is held and never called. Answers the function that removes the watcher.
Parameters
watcher(key: string) -> ()— Called with the released key.
Returns () -> () — A function that removes the watcher.
jobs.onRelease(function(key) plans[key] = nil end)
typed/builtin//modules/api/engine/jobs/M/parallelFor
M.parallelFor(module: string, entry: string, over: number | { first: number, last: number } | buffer, args: any?, opts: { deadline: number?, name: string?, chunks: number?, stride: number? }?) -> PromiseHandle
Split a loop across the worker pool and answer a promise of the chunks' results in chunk order, so a loop over many indices or many elements of a buffer holds no frame and uses every worker. over is a count of indices (1..over), a table { first = a, last = b } of whole numbers, or a buffer whose elements are opts.stride bytes each (default 1). The range is cut into opts.chunks runs (default four per worker, at most one per element), as even as it divides, and each run is an item the pool's workers take: entry, a function of the module module, is called with one table chunk = { index, count, first, last, args, data }, where first and last are the run's indices (for a buffer, its element numbers from 1), args is a copy of args, and data is the run's slice of a buffer. The promise settles once every chunk has returned and the engine thread has applied every write the chunks made before they returned, with { chunk 1 result, chunk 2 result, ... } in chunk order whichever chunk finished first. A chunk that raises, or runs past its deadline (opts.deadline seconds for one run of each chunk between a resume and the next yield, default and at most the hold on one run, 60 seconds on every platform), rejects the promise naming the chunk (chunk 3 of 8) and cancels the chunks still queued or running; cancelling the promise (p:cancel()) cancels every chunk. It runs from the engine thread and from a worker: a worker that awaits the call runs queued chunks itself, so a call made inside a chunk completes however many workers are busy. The module, its worker VMs, args and result copies follow the rules of jobs.dispatch.
Parameters
modulestring— Require path of the module, asrequiretakes it.entrystring— Name of the function in the module's export table; it receives the chunk table.overnumber | { first: number, last: number } | buffer— A count of indices, a{ first, last }range, or a buffer.argsany(optional) — A value every chunk receives aschunk.args, copied.opts{ deadline: number?, name: string?, chunks: number?, stride: number? }(optional) — Optional{ deadline: number?, name: string?, chunks: number?, stride: number? }: the deadline in seconds of one run of each chunk, what a rejection calls the call, the number of chunks, and the bytes in one element of a buffer.
Returns PromiseHandle — A PromiseHandle settling with a table of the chunks' results in chunk order.
local sums = jobs.parallelFor("@root::sim.reduce", "sumChunk", 100000, { scale = 2 }):await()
local out = jobs.parallelFor("@root::pixels.tint", "tint", pixels, nil, { stride = 4, chunks = 16 }):await()
typed/builtin//modules/api/engine/jobs/M/register
M.register(descriptor: table) -> JobHandle?
Register a substrate job. Returns a JobHandle on success, nil on validation failure. Dispatches by executor.kind:\n - "kernel" / "stub" → standard __jobs.register (JSON-only descriptor).\n - "luau" → __jobs.register_luau(descriptor, executor.run) so the Luau function survives the JSON crossing as a stable registry ref. The dispatcher invokes the run closure once per frame; the closure captures any bindings/buffers it needs.\n - "compute" → the shader reference resolves to its registration key, and the job queues one dispatch per frame.\n - "worker" → __jobs.register_worker(descriptor, executor.input, executor.apply): each frame input() runs on the engine thread, its value is copied to a worker where the module's entry runs, and the result reaches apply(result) on the engine thread the frame it lands, one item in flight at a time. An input that returns nil queues no item that frame. A job that errors logs its name and message once, and job:info().last_error holds it. Without a key, its items can run on different workers, each with module state of its own, so what carries from one item to the next travels through the result and input. key (a string of 1 to 256 bytes) runs every item of the job as that key, in the worker VM the key is bound to, so module state one item leaves there is there for the next (see jobs.dispatch); job:info().waited_for_vm_ms is the time its items waited for that VM. A job registered from a worker VM keeps its function (run, or input and apply) in that VM: the dispatcher posts each frame's call to the worker and never waits for it, the writes it records apply one frame later, a raise marks the job errored one frame later, and job:info().worker reports the calls, the late calls and the failed calls. A worker job whose input or apply is not a function, whose deadline is not a number of seconds above 0 and at most the hold on one run (60 seconds on every platform), or whose key is not a string of 1 to 256 bytes, is raised at the call, naming why. deadline (default and at most that hold: it may be lowered and never raised) is the longest one run of an item may take between a resume and the next yield, counted on monotonic time per run and never summed across runs.\n\nA job holds every CPU buffer its reads and writes name (resource = { kind = "buffer", id = buf.id }) until it ends, so the buffer stays while the job does once its handles are destroyed or collected.\n\norigin is auto-filled with the VFS path of the calling script unless the descriptor already supplies one — surfaced under /zero/runtime/jobs/<phase>/<key>/origin.txt for agent traceability. Single FFI crossing — auto-origin runs Rust-side via lua_getinfo, no separate stack-inspection trip.
Parameters
descriptortable— Job declaration with theJobDescriptorshape —name?,phase,reads?,writes?,executor,ordering?,pure?,origin?,metadata?. Param is typed astablerather thanJobDescriptorbecause the LSP doesn't yet narrow string literals to their literal types in record fields, so aJobDescriptorannotation rejects the tagged-unionexecutordiscriminator on every call site (literalkind = "kernel"infers askind: string, doesn't subtypeKernelExecutor.kind: "kernel"). Runtime validation in__jobs.registerenforces the actual structure; see theJobDescriptortype alias above for the canonical shape.
Returns JobHandle? — JobHandle or nil.
local job = jobs.register({ phase = "main", executor = { kind = "kernel", kernel = "copy_buffer" }, reads = {{resource={kind="buffer",id=src.id},mode="r"}}, writes = {{resource={kind="buffer",id=dst.id},mode="w"}} })
local job = jobs.register({ phase = "main", executor = { kind = "luau", run = function() print("tick") end } })
local job = jobs.register({ phase = "main", executor = { kind = "compute", shader = asset.resolve("carve", "computeShader"), buffers = { "heights" }, workgroups = { 64 } } })
local job = jobs.register({ name = "crowd", phase = "main", executor = { kind = "worker", module = "@root::crowd.sim", entry = "step", input = function() return { count = 100 } end, apply = function(result) print(result) end } })
typed/builtin//modules/api/engine/jobs/M/release
M.release(key: string) -> boolean
End the binding of key to its worker VM once the items of the key dispatched before this call have settled. That VM then runs its jobs.onRelease watchers with the key, each as a task of its scheduler, and the key's next item binds anew and runs with jobs.context().fresh true. Without a release, a VM keeps each key's state for as long as it lives (until the world changes or the scripting state resets); /runtime/workers lists the keys each worker holds. Runs from the engine thread and from a worker.
Parameters
keystring— The key, asjobs.dispatchwas given it inopts.key.
Returns boolean — True when the pool held the key: a binding, or items queued or running, which the release runs after; false, doing nothing, for a key with none of those, a key whose only entry is a release under way among them.
jobs.release(graphId)
typed/builtin//modules/api/engine/jobs/M/shared/atomic
M.shared.atomic(t: SharedTable<T>, key: string | number, fn: (current: T?) -> T?) -> T?
Read-modify-write of one key of a shared table without a race. fn receives the key's current value (nil when absent; a table arrives as a plain copy) and returns the new one (nil removes the key); the new value is stored only if no other write reached the table meanwhile, otherwise fn runs again on the newer value, so fn must be quick, pure and must not yield. A call that lost four attempts in a row takes its turn at the table, and the other atomic calls on a worker wait for it, so atomic calls never starve one another; after 256 attempts that all lost to plain writes the call raises naming the table and the key. Counters, flags and compare-and-set are this one call; a change across several keys is one atomic on the parent key that returns the whole new table.
Parameters
tSharedTable<T>— A shared table.keystring | number— The key to update.fn(current: T?) -> T?—(current) -> new.
Returns T? — The value now stored under the key.
jobs.shared.atomic(counts, "done", function(n) return (n or 0) + 1 end)
jobs.shared.atomic(flags, "claimed", function(was) if was then return was end return true end)
typed/builtin//modules/api/engine/jobs/M/shared/queue
M.shared.queue(name: string, opts: SharedQueueOptions?) -> SharedQueue<T>
The shared queue named name, made on first use: a bounded first-in-first-out queue between any VMs, for handing work or results from one job to another, or from a job to the game. push(v) puts a copy of v at the back from anywhere; pop() takes the front value and waits for one when there is none (a worker parks, and on the engine thread only the calling task suspends, so a frame is never held); tryPop() takes it without waiting and answers nil when empty. A value is any non-nil data that a shared table holds. A full queue raises naming the queue and its capacity: it never drops. The capacity is opts.capacity (default 1024, at most 65,536); asking for the name again with another capacity raises. The queue is process memory with the lifetime of a shared table: when the world changes or the scripting state resets, every task parked on pop is rejected with the reason.
Parameters
namestring— The queue's name, at most 256 bytes.optsSharedQueueOptions(optional) — Optional{ capacity: number? }.
Returns SharedQueue<T> — The queue.
local work = jobs.shared.queue("terrain.chunks", { capacity = 256 }); work:push({ x = 3, z = 4 })
-- in a job: while true do local chunk = work:pop(); build(chunk) end
typed/builtin//modules/api/engine/jobs/M/shared/revision
M.shared.revision(t: SharedTable<T>) -> number
A number that every write to the shared table, or to any table nested in it, advances. One atomic read: game code that polls a table each frame compares it with the number it saw and reads the table only when it changed.
Parameters
tSharedTable<T>— A shared table.
Returns number — The revision.
local seen = 0; -- each frame: local now = jobs.shared.revision(progress); if now ~= seen then seen = now; redraw(progress) end
typed/builtin//modules/api/engine/jobs/M/shared/snapshot
M.shared.snapshot(t: SharedTable<T>) -> { [string | number]: T }
An ordinary table holding a deep copy of a shared table, for the code that wants a stable view (JSON, comparison, the table library on a frozen picture). Each table of the copy is read at one version; tables read at different moments may be of different versions.
Parameters
tSharedTable<T>— A shared table.
Returns { [string | number]: T } — A plain table.
local picture = jobs.shared.snapshot(progress)
typed/builtin//modules/api/engine/jobs/M/shared/table
M.shared.table(name: string) -> SharedTable<T>
The shared table named name, made on first use. The engine's VM and every worker VM read and write the same table with the syntax of an ordinary table: t.x = 1, t.player.hp -= 5, #t, for k, v in t, pairs, next, table.insert, table.remove, table.sort, table.concat, table.find, table.unpack, table.clone, table.clear, rawget, rawset. A job streams results to the game through it while it runs, and the game reads them each frame. It holds data: booleans, numbers, integers, strings, vectors, buffers and tables of those; assigning a table copies it in (later edits of the local table are not seen), and a function, coroutine, userdata or a table with a metatable raises naming the key path. A value reads back as the type it was written with. t.a where t.a is a table is that table, so t.a.b = 1 writes through; a table replaced or removed raises on any use, naming where it was. Each access is atomic on its table; a loop walks the table as it stood when the loop started. The store is process memory: not persisted and not replicated (runtime_data and synced component fields are those). It lasts until the world changes or the scripting state resets (play entry keeps it); after that a held table raises, naming the reason. A table holds at most 1,048,576 entries and 64 MiB (32 MiB in the browser), nested at most 64 deep; the process holds at most 4,096 names and 256 MiB (128 MiB in the browser); a write past a bound raises and changes nothing.
Parameters
namestring— The table's name, at most 256 bytes.
Returns SharedTable<T> — The shared table.
local progress = jobs.shared.table("terrain.progress"); progress.done = 0
-- in a job: progress.done += 1 -- in the game each frame: print(progress.done)
typed/builtin//modules/api/engine/jobs/M/warm
M.warm(module: string, entry: string) -> PromiseHandle
Run the function entry of the module module once in every worker VM, to build the state the module keeps in its own VM (a registry, compiled rules, a table it loads) before an item needs it. The pool starts every worker it may start; each VM up runs the entry as its next item, and a VM made later (after a panic, or one the pool starts later) runs it before its first item, whichever boot made it. The entry is called with nil and builds state in its own VM: it runs under the hold on one run (60 seconds from a resume to the next yield), and its whole run, waits included, under the warm bound of 60 seconds of wall time from its start to its end, read between runs, so a run in progress at the bound goes on to its next yield: an entry that does not yield runs at most the bound plus one hold, about 120 seconds. It may wait on time and frames, and it does not wait on the pool: an await of a jobs.dispatch, a jobs.parallelFor or a jobs.warm promise by the entry or a task it started, while the entry runs, raises, naming what it awaited, whether or not the promise has settled, and so does making a future combinator over one, at the call (dispatching without awaiting is fine: the item runs once the VM is warm). No item starts on the VM until its warm pass is over; tasks the VM already holds go on between the entry's waits. The promise settles once every VM up at the call has run it: it resolves when every run ended well, and rejects naming each worker whose run raised, panicked or ran past the warm bound, and its error. It is kept for the life of the scripting state: a second call for the same module and entry runs nothing more and answers the same. An entry that raises is logged, naming its module, entry and worker, and the VM serves on. An entry that panics the engine or runs past the warm bound runs on no later VM until the scripting state resets: it is logged once and ended, and the VM made after a panic runs the rest of the pass before any item. A panic in code outside the entry while it runs (the VM's boot, a watcher, a task another entry left behind) ends that VM, and the VM made next runs it once more; these endings are counted per entry, across every worker of the pool, for the epoch, and the second one fails the entry for the epoch, naming the panic. The entry runs on workers only; the calling thread pays the dispatch. Call it from the engine thread or from an item, awaited or not, whatever principal the item runs as: the item's worker runs the warm job for its own VM before the item resumes. Call it when the module is first used in a world, so a world that never uses it pays nothing; /runtime/workers lists each worker's warm runs with their milliseconds, and the failed ones with why.
Parameters
modulestring— Require path of the module, asrequiretakes it.entrystring— Name of the function in the module's export table.
Returns PromiseHandle — A PromiseHandle settling once every worker VM up at the call has run the entry: nil when every run ended well, otherwise rejected naming each failed run.
jobs.warm("@root::graph.nodes", "buildRegistry")
jobs.warm("@root::paths.graph", "loadTables"):await()
typed/builtin//modules/api/engine/jobs/jobhandle_cancel
jobhandle_cancel(self: JobHandle) -> boolean
Cancel the job — drops one refcount, last drop unregisters and the dispatcher stops invoking it. Symmetric with vfs.remove("/runtime/jobs/<phase>/<id>").
Parameters
selfJobHandle— JobHandle returned byjobs.register.
Returns boolean — True if the substrate still tracked the job at call time.
job:cancel()
typed/builtin//modules/api/engine/jobs/jobhandle_info
jobhandle_info(self: JobHandle) -> JobInfo?
Latest snapshot row for this job (id, name, phase, status, origin, metadata, reads, writes…). Single FFI crossing — pulls only this job's row, not the full registry.
Parameters
selfJobHandle— JobHandle returned byjobs.register.
Returns JobInfo? — Snapshot row or nil if the job is no longer tracked.
local info = job:info(); print(info.origin)
typed/builtin//modules/api/engine/jobs/jobhandle_pause
jobhandle_pause(self: JobHandle) -> boolean
Pause the job — skipped on subsequent ticks but stays registered.
Parameters
selfJobHandle— JobHandle returned byjobs.register.
Returns boolean — True if the substrate still tracked the job.
local job = jobs.register({...}); job:pause()
typed/builtin//modules/api/engine/jobs/jobhandle_resume
jobhandle_resume(self: JobHandle) -> boolean
Resume a paused or errored job (clears Errored → Pending).
Parameters
selfJobHandle— JobHandle returned byjobs.register.
Returns boolean — True if the substrate still tracked the job.
job:resume()
typed/builtin//modules/api/engine/jobs/jobhandle_status
jobhandle_status(self: JobHandle) -> JobStatus?
Read the job's current scheduler status.
Parameters
selfJobHandle— JobHandle returned byjobs.register.
Returns JobStatus? — "pending" / "running" / "errored", or nil if the id is no longer tracked.
local s = job:status() -- "pending"
typed/builtin//modules/api/engine/jobs/jobhandle_valid
jobhandle_valid(self: JobHandle) -> boolean
Whether the substrate still tracks this job (false after :cancel/:destroy).
Parameters
selfJobHandle— JobHandle returned byjobs.register.
Returns boolean — True if the underlying job is still registered.
if not job:valid() then return end
typed/builtin//modules/api/engine/layers/M/_watchInitialLayers
M._watchInitialLayers(budgetSeconds: number?, read: (() -> { any })?) -> nil
Internal: dispatch fireLoad for each layer in __layers.loaded()
that layers.load has not dispatched. An additive layer is dispatched
once it is seen, a non-additive one once the scene's local player has
registered, so onLoad callbacks always see a live player. A layer
whose unload has begun is never dispatched. The watch reads on every
frame the engine runs and asks a still engine for none: a load and a
player's registration each run frames of their own. It ends on the first
frame it reads a dispatched root layer, and otherwise once
budgetSeconds of real time have passed since it started, or since the
first layer it saw waiting when that came later. install runs it once
per VM.
Parameters
budgetSecondsnumber(optional) — Seconds the watch lasts without reading a dispatched root layer (default 10).read(() -> { any })(optional) — Where the watch reads the layers the engine holds, as rows of__layers.loaded()(default__layers.loaded).
Returns nil
task.spawn(layers._watchInitialLayers)
typed/builtin//modules/api/engine/layers/M/cost
M.cost() -> { SceneLayerCost }
What each loaded scene's per-frame tick costs, attributed to the layer
that owns it — the update / editorUpdate its entrypoint declares,
timed where it runs. totalMs is a SUM across the window
layers.observe().window reports, so divide by calls (or read avgMs)
for the per-tick figure; a tick that runs every frame makes that the
per-frame figure. Call layers.resetCostWindow() first to time a
particular stretch. A layer whose entrypoint declares no tick is absent.
Returns { SceneLayerCost } — An array of SceneLayerCost.
layers.resetCostWindow(); task.wait(1); for _, c in layers.cost() do print(c.name, c.avgMs) end
typed/builtin//modules/api/engine/layers/M/find
M.find(ref: AssetRef<scene> | string) -> any?
The loaded layer for a scene, matched on guid — the canonical identity, since display names can collide and paths drift when assets move. A layer torn down but not yet pumped out of the engine's loaded list reads as gone.
Parameters
refAssetRef<scene> | string— A sceneAssetRef, or an identity string resolved throughasset.ref.
Returns any? — The scene proxy, or nil when that scene has no loaded layer.
local layer = layers.find("scenes.arena")
typed/builtin//modules/api/engine/layers/M/fireBeforeLoad
M.fireBeforeLoad(proxy: any?) -> nil
Announce that a scene layer is about to load: clears any pending
unload for that layer slot, marks the proxy loading, and fans out to every
layers.onBeforeLoad subscriber. The scene-load pipeline calls this.
Parameters
proxyany(optional) — The scene proxy about to load.
Returns nil
layers.fireBeforeLoad(sceneProxy)
typed/builtin//modules/api/engine/layers/M/fireLoad
M.fireLoad(proxy: any?) -> nil
Announce that a scene layer has loaded, fanning out to every
layers.onLoad subscriber. The layer is pinned as the active one for the
duration of the fan-out, so entities a subscriber spawns are attributed to
it rather than landing orphaned. The scene-load pipeline calls this.
Parameters
proxyany(optional) — The loaded scene proxy.
Returns nil
layers.fireLoad(sceneProxy)
typed/builtin//modules/api/engine/layers/M/fireUnload
M.fireUnload(proxy: any?) -> nil
Announce that a scene layer is unloading: fans out to every
layers.onUnload subscriber, then drops the layer's cached proxy and
per-layer state so the next load of that scene rebuilds from disk. The
unload path calls this.
Parameters
proxyany(optional) — The scene proxy being unloaded.
Returns nil
layers.fireUnload(sceneProxy)
typed/builtin//modules/api/engine/layers/M/install
M.install() -> nil
Install the layers global. layers.active is exposed as a property
whose every read resolves the current root scene, so it tracks scene
changes without manual invalidation; other keys resolve against this
module. The prelude calls this once at boot.
Returns nil
layers.install()
typed/builtin//modules/api/engine/layers/M/inventory
M.inventory() -> { SceneLayerInventory }
What each loaded layer holds: the entities the engine attributes to it,
whether it came up whole, and how many failures it carries. unattributed
in layers.observe().totals counts what exists in the world that no layer
claims.
Returns { SceneLayerInventory } — An array of SceneLayerInventory.
for _, l in layers.inventory() do print(l.name, l.entities, l.ok) end
typed/builtin//modules/api/engine/layers/M/is_loaded
M.is_loaded(ref: AssetRef<scene> | string) -> boolean
Whether a scene currently has a loaded layer — the boolean form of
layers.find. A scene counts as loaded from the frame the engine holds a
layer slot for it — the same slot its entities are attributed to — until
an unload is issued against that slot. So a gate like
if layers.is_loaded(ref) then layers.unload(ref) end sees the layer on
the frame its entities exist.
Parameters
refAssetRef<scene> | string— A sceneAssetRef, or an identity string.
Returns boolean — True when the scene is loaded as a layer.
if not layers.is_loaded("scenes.hud") then layers.load("scenes.hud", { additive = true }) end
typed/builtin//modules/api/engine/layers/M/lastLoad
M.lastLoad() -> SceneLoadReport?
The most recent load's report: what it loaded, what root it replaced and which overlays went with it, the entity counts on each side, how long each phase took, and every failure it produced. Nil on an engine that has loaded nothing — which is how "nothing has loaded" reads differently from a load that changed nothing.
Returns SceneLoadReport? — A SceneLoadReport, or nil.
local r = layers.lastLoad(); print(r.name, r.outcome, r.entities.added)
typed/builtin//modules/api/engine/layers/M/lastUnload
M.lastUnload() -> SceneUnloadReport?
The most recent unload's report: the layer it took down under the name it was loaded with, the overlays it cascaded, and the entities that went with them. A guid no longer resolves to a name once its layer is gone, so this is where that name survives.
Returns SceneUnloadReport? — A SceneUnloadReport, or nil.
local u = layers.lastUnload(); print(u.name, u.entities.removed)
typed/builtin//modules/api/engine/layers/M/list
M.list() -> { any }
Every loaded scene layer as a proxy, root and additive alike, in the
order the engine reports them. A proxy carries name, sceneIdentity
(the scene asset it was loaded from, e.g. scenes.main), guid, path,
additive, persistent and visible. The root one — the open scene — is
also layers.active.
Returns { any } — Array of scene proxies — empty before any scene is loaded.
for _, layer in ipairs(layers.list()) do print(layer.name, layer.sceneIdentity, layer.additive) end
print("open scene:", layers.active.sceneIdentity)
typed/builtin//modules/api/engine/layers/M/load
M.load(ref: AssetRef<scene> | string, opts: LoadOpts?) -> any
Parameters
refAssetRef<scene> | stringoptsLoadOpts(optional)
Returns any
typed/builtin//modules/api/engine/layers/M/loadHistory
M.loadHistory() -> { SceneLoadReport }
Every load report the engine still holds, oldest first. Bounded — old reports fall off the front, so a long session's memory does not grow with how many times a scene was swapped.
Returns { SceneLoadReport } — An array of SceneLoadReport.
for _, r in layers.loadHistory() do print(r.name, r.durationMs) end
typed/builtin//modules/api/engine/layers/M/loadInFlight
M.loadInFlight() -> number
Returns the number of scene loads currently in flight (queued
but not yet visible via onLoad dispatch). Returns 0 when the
engine is in a stable load state. Used by engine.mode = ... to
block flips while a load is mid-air; agents can read this to wait
for a load to finish before driving the next operation.
Returns number
typed/builtin//modules/api/engine/layers/M/observe
M.observe() -> SceneObservation
What every scene load did, and what each loaded scene costs. One read covering the last load's report (what it produced, what it replaced, what it failed to produce and why, and how long each phase took), the load and unload history, a per-layer inventory of what the engine attributes to each layer, and the per-frame cost of each layer's entrypoint tick. Answers in edit mode as well as play.
Returns SceneObservation — A SceneObservation.
local o = layers.observe(); print(o.lastLoad.outcome, o.lastLoad.durationMs)
for _, c in layers.observe().cost do print(c.name, c.avgMs) end
typed/builtin//modules/api/engine/layers/M/offBeforeLoad
M.offBeforeLoad(h: number) -> boolean
Cancel a layers.onBeforeLoad subscription.
Parameters
hnumber— The handlelayers.onBeforeLoadreturned.
Returns boolean — True when a subscription was removed.
layers.offBeforeLoad(h)
typed/builtin//modules/api/engine/layers/M/offEntityChanged
M.offEntityChanged(h: number) -> boolean
Remove a subscription made with layers.onEntityChanged.
Parameters
hnumber— The handle returned bylayers.onEntityChanged.
Returns boolean — True when the subscription existed and was removed.
layers.offEntityChanged(handle)
typed/builtin//modules/api/engine/layers/M/offLoad
M.offLoad(h: number) -> boolean
Cancel a layers.onLoad subscription.
Parameters
hnumber— The handlelayers.onLoadreturned.
Returns boolean — True when a subscription was removed.
layers.offLoad(h)
typed/builtin//modules/api/engine/layers/M/offUnload
M.offUnload(h: number) -> boolean
Cancel a layers.onUnload subscription.
Parameters
hnumber— The handlelayers.onUnloadreturned.
Returns boolean — True when a subscription was removed.
layers.offUnload(h)
typed/builtin//modules/api/engine/layers/M/onBeforeLoad
M.onBeforeLoad(cb: (any) -> ()) -> number
Run a callback just before a scene layer loads, while the previous layer's entities are still present.
Parameters
cb(any) -> ()— Receives the scene proxy about to load.
Returns number — A handle to pass to layers.offBeforeLoad.
local h = layers.onBeforeLoad(function(scene) print("loading", scene.name) end)
typed/builtin//modules/api/engine/layers/M/onEntityChanged
M.onEntityChanged(cb: (any) -> ()) -> number
Subscribe to authored entity changes. The callback runs once per
frame with every entity edited since the previous frame, batched by
layer as { { scene = string, entities = { string } } } — a moved
transform, an edited component field, a spawn, or a despawn (the id
of a despawned entity arrives with entity.exists already false).
Any number of subscribers can watch the same edits.
Scope: authored edits in edit mode — what lands in the scene's dirty
overlay. Mutations a component makes from its own update are runtime
behavior and do not appear, so a subscriber that rebuilds derived data
cannot re-trigger itself.
Parameters
cb(any) -> ()— Called with the change batch.
Returns number — A handle for layers.offEntityChanged.
layers.onEntityChanged(function(batch)
for _, row in ipairs(batch) do
for _, id in ipairs(row.entities) do print("changed", id) end
end
end)
typed/builtin//modules/api/engine/layers/M/onLoad
M.onLoad(cb: (any) -> ()) -> number
Run a callback once a scene layer has loaded — the point where its entities exist and player / camera spawners can attach to them.
Parameters
cb(any) -> ()— Receives the loaded scene proxy.
Returns number — A handle to pass to layers.offLoad.
local h = layers.onLoad(function(scene) print("loaded", scene.name) end)
typed/builtin//modules/api/engine/layers/M/onUnload
M.onUnload(cb: (any) -> ()) -> number
Run a callback as a scene layer unloads, while its entities are still addressable — the place to release anything keyed to them.
Parameters
cb(any) -> ()— Receives the scene proxy being unloaded.
Returns number — A handle to pass to layers.offUnload.
local h = layers.onUnload(function(scene) print("unloaded", scene.name) end)
typed/builtin//modules/api/engine/layers/M/problems
M.problems(ref: (AssetRef<scene> | string | any)?) -> { SceneLoadFailure }
What a layer failed to produce, and why. Each entry names the phase it happened in, one reason from the closed set, and the engine's own words — plus the entity, component or lifecycle hook it is about when it is about one.
Parameters
ref(AssetRef<scene> | string | any)(optional) — A sceneAssetRef, an identity string, or a scene proxy. Omit for the active root layer.
Returns { SceneLoadFailure } — An array of SceneLoadFailure — empty for a layer that came up whole.
for _, f in layers.problems() do print(f.reason, f.entity, f.message) end
typed/builtin//modules/api/engine/layers/M/rebuildInFlight
M.rebuildInFlight() -> boolean
Whether the engine is rebuilding the live scene right now: a scene
load is carrying entities in, an edit↔play flip's transition is
materialising the layer set, or a scene's build.luau build is landing
what it produced. A flip unloads the root layer and loads it again for the
new mode across many frames, and each mode materialises a different set of
entities; a build lands its records and saves the scene over several
frames. Either way the live entities are a stage of a scene being built
while this reads true. A caller whose answer belongs to the settled scene,
a test taking a root or a validator judging the live tree, polls it down
to false first.
Returns boolean — true while a load, a mode-flip transition or a scene build is converging.
if not layers.rebuildInFlight() then print(#entity.findAll(), "entities settled") end
typed/builtin//modules/api/engine/layers/M/reload
M.reload(ref: (AssetRef<scene> | string)?) -> any?
Unload and re-load a scene layer in place, so an edited scene asset
takes effect without rebuilding the surrounding layer stack. The scene's
build.luau runs against what it resolves right now, so a build script
whose inputs moved (a component that now exists, an asset that now
resolves) produces the scene it describes today. The rebuild saves the
scene, as a write to build.luau does, so scene.json holds what the
reload built and the next play loads it; unsaved edits in the scene are
saved with it. A library scene (under /libs/) is rebuilt in the live
scene alone. A reload asked for while
a build of the scene is landing (a write to build.luau rebuilds over
several frames) waits for that build to land and save first.
Parameters
ref(AssetRef<scene> | string)(optional) — A sceneAssetRef, or an identity string. Omit to reload the active root scene.
Returns any? — What the scene's build.luau did: { built = true, content, editorOnly, saved } with the entity counts each half placed and whether scene.json now holds them (false for a library scene), carrying refused and a message reading them out when an operation the build ran was refused, or { built = false, reason, message } naming what stood in the way. Nil when no layer matched, which is a no-op.
layers.reload("scenes.arena")
typed/builtin//modules/api/engine/layers/M/resetCostWindow
M.resetCostWindow() -> nil
Open a new cost window, discarding what the previous one measured. Call this before timing a stretch of frames; the load history is untouched.
Returns nil
layers.resetCostWindow()
typed/builtin//modules/api/engine/layers/M/unload
M.unload(refOrProxy: (AssetRef<scene> | string | any)?) -> nil
Unload a scene layer. Unloading the root cascades through its additive overlays first, most-recently-loaded first, so none is left as a layer the engine still lists after its entities are gone; persistent additive layers survive the cascade. A scene with no loaded layer is a no-op. An unload made while a load is part way through a scene's records waits for that load to apply the rest.
Parameters
refOrProxy(AssetRef<scene> | string | any)(optional) — A sceneAssetRef, an identity string, or a scene proxy. Omit to unload the active root scene.
Returns nil
layers.unload("scenes.hud")
layers.unload() -- the active root, plus its non-persistent overlays
typed/builtin//modules/api/engine/layers/M/whyPartial
M.whyPartial(ref: (AssetRef<scene> | string | any)?) -> (string?, string?)
Why a layer is not whole. Returns nil when it IS — everything the scene
declared was produced — and otherwise the nearest cause from the closed set
loaderRaised, entrypointCompileFailed, entrypointBodyRaised,
entrypointRaised, buildRaised, entityFailed, parentMissing,
parentRefused, parentAbandoned, componentUnresolved,
componentRefused, subscriberRaised, updateRaised. A second return
carries the engine's own words for that cause.
Parameters
ref(AssetRef<scene> | string | any)(optional) — A sceneAssetRef, an identity string, or a scene proxy. Omit for the active root layer.
Returns (string?, string?) — (reason, detail).
local why, detail = layers.whyPartial(); if why then print(why, detail) end
typed/builtin//modules/api/engine/layers/layers/active
layers.active -> any
The root scene's proxy, re-resolved on every read.
Returns any
typed/builtin//modules/api/engine/layers/layers/camera
layers.camera -> any
The active root scene's camera handle, the same value layers.active.camera answers.
Returns any
typed/builtin//modules/api/engine/layers/layers/localPlayer
layers.localPlayer -> any
The active root scene's local player handle, the same value layers.active.players.localPlayer answers.
Returns any
typed/builtin//modules/api/engine/library/library/has
library.has(path: string) -> boolean
Check if a library asset exists at the given path. Answers from
the content the engine holds: an imported library's namespace
("@mylib") and its assets answer true once its pinned commit is
mounted, and false while only its marker is there.
Parameters
pathstring— Library asset path (e.g. "@builtin/models/Sample/DamagedHelmet").
Returns boolean — True if the asset exists in the library.
assert(library.has("@builtin/models/Cube"))
typed/builtin//modules/api/engine/library/library/import
library.import(namespace: string, worldRef: string) -> LibraryImport
Import another world as a library under the given namespace.
Resolves the world, pins its current commit, and writes the
library marker at /source/libs/@<namespace>, then waits while the
engine fetches the pinned commit from ZeroMind and mounts it. When
it returns, the imported tree answers to
require("@<namespace>::path") and is listed by library.list().
A library that does not mount raises naming why, and running the
import again retries it.
Parameters
namespacestring— Library namespace, with or without the leading@(e.g."@mylib"or"mylib").worldRefstring— The upstream world's guid, or its name as it appears inworld.list().
Returns LibraryImport — Record describing the import: the local name, the marker path, the upstream world_guid, and the pinned commit as version.
library.import("@mylib", "my-shared-world")
typed/builtin//modules/api/engine/library/library/list
library.list(assetType: string?) -> { LibraryAsset }
List all available library assets. Optionally filter by asset
type — call asset.categories() for the live set.
Parameters
assetTypestring(optional) — Asset type filter (optional).
Returns { LibraryAsset } — Array of asset descriptors. path is the @builtin::* identity, type is one of the valid type strings, format is the original file extension (e.g. "glb", "luau", "wgsl").
for _, a in ipairs(library.list("model")) do print(a.path) end
typed/builtin//modules/api/engine/logs/logs/clear
logs.clear() -> boolean
Drop all buffered log entries. Lifetime per-level counts
(logs.count) are preserved.
Returns boolean — True on success.
logs.clear()
typed/builtin//modules/api/engine/logs/logs/count
logs.count(opts: LogQueryOpts?) -> LogCounts
Aggregate counters for the log ring. Lifetime counts survive
eviction, so errors reflects the total seen even if the lines
have scrolled out of the buffer. opts takes the same filter table
as logs.query, and matched is how many held entries it selects,
counted without materialising them — limit and newest_first bound
and order what a query RETURNS, so they leave matched alone. mcp
is how many held entries record your own tool traffic; a query leaves
those out, so with no opts, matched + mcp is everything held.
last_seq is the cursor for
incremental polling: read it before an action, then pass it as
logs.query({ since = <that> }) afterwards to see only what the
action logged. The ring is bounded, so lines logged after that cursor
can be evicted before the query runs: logs.count({ since = <that> })
then carries evicted (how many it no longer holds) and
complete_from (the seq from which it holds every line), and carries
neither when nothing after the cursor was lost. A since_time /
until_time window states its loss the same way.
Parameters
optsLogQueryOpts(optional) — Filter options, aslogs.querytakes.
Returns LogCounts — Counts summary table.
print("errors:", logs.count().errors)
local before = logs.count().last_seq
typed/builtin//modules/api/engine/logs/logs/errors
logs.errors(limit: number?) -> { LogEntry }
Most-recent ERROR-level entries (newest first). limit
defaults to 100.
Parameters
limitnumber(optional) — Maximum entries to return.
Returns { LogEntry } — Array of ERROR log-entry tables.
for _, e in ipairs(logs.errors(20)) do print(e.message) end
typed/builtin//modules/api/engine/logs/logs/find
logs.find(text: string, limit: number?) -> { LogEntry }
Case-insensitive substring search over log messages. limit
defaults to 200 (keeps the most recent matches). Searches what the
engine logged; logs.query({ contains = ..., include_mcp = true })
searches your own tool traffic too.
Parameters
textstring— Substring to search for.limitnumber(optional) — Maximum entries to return.
Returns { LogEntry } — Array of matching log-entry tables in chronological order.
local hits = logs.find("MY_MARKER")
typed/builtin//modules/api/engine/logs/logs/query
logs.query(opts: LogQueryOpts?) -> { LogEntry }
Query the engine's in-memory log ring — the filtered view of what
also reads as plain text at /zero/runtime/logs/engine. Answers about what the
engine logged: the MCP record of your own tool traffic (the tool each
call ran, its caller and the size of each argument) is left out.
type = "MCP" selects them;
include_mcp = true mixes them in with everything else. On a world
several sessions share, origin = "local" narrows the answer to the
lines this session's own authoring caused.
Parameters
optsLogQueryOpts(optional) — Filter options.
Returns { LogEntry } — Array of matching log-entry tables.
logs.query({ entity = "guard-1", limit = 20 })
logs.query({ level = "error", context = 3 })
for _, e in ipairs(logs.query({ level = "warn", limit = 50 })) do print(e.message) end
typed/builtin//modules/api/engine/logs/logs/tail
logs.tail(limit: number?) -> { LogEntry }
Most-recent entries of any level in chronological order.
limit defaults to 100.
Parameters
limitnumber(optional) — Maximum entries to return.
Returns { LogEntry } — Array of the most recent log-entry tables.
for _, e in ipairs(logs.tail(20)) do print(e.level, e.message) end
typed/builtin//modules/api/engine/logs/logs/template
logs.template(message: string) -> string
Normalize a message to its template — the same line with the parts that vary between occurrences (numbers, hashes, entity ids) masked out. Two messages that differ only in those parts share a template, which is what turns "this error repeated 400 times" into one row instead of 400. The engine keys its own error retention by the same normalization, so grouping built on this agrees with what survives ring eviction.
Parameters
messagestring— Log message to normalize.
Returns string — The message template.
local key = logs.template(entry.message)
typed/builtin//modules/api/engine/logs/logs/warnings
logs.warnings(limit: number?) -> { LogEntry }
Most-recent WARN+ entries (newest first). limit defaults
to 100.
Parameters
limitnumber(optional) — Maximum entries to return.
Returns { LogEntry } — Array of WARN+ log-entry tables.
print(#logs.warnings(), "warnings")
typed/builtin//modules/api/engine/lsp/lsp/analysisFlags
lsp.analysisFlags() -> AnalysisFlags
The feature-flag configuration upstream Luau's analysis library
(the linter and .luaurc parser behind these checks) runs under,
read back from Luau's flag registry. It is upstream's own: every
Luau* flag the analysis sources declare is on unless upstream's
experimental list names it, and every other flag they declare keeps
the value Luau registers it at. The flags the analysis library reads
from the parser and the VM are shared: they run at the value the
engine's runtime gives them, and one that differs from upstream's
carries its deviation. flags lists every flag those sources
declare or read, sorted by name; atUpstream counts the linked ones
whose value is upstream's. available is false, with reason, on a
build that does not link the analysis library.
Returns AnalysisFlags — { available, reason?, declared, shared, linked, atUpstream, flags }.
typed/builtin//modules/api/engine/lsp/lsp/check
lsp.check(path: string, opts: CheckFileOpts?) -> DiagnosticsResult
Validate a single .luau file in the VFS and return its
diagnostics. A path the check could not read comes back as one
lsp-check-* error naming the path and the reason, and a file past the
2 MiB analysis bound as one source-too-large warning with
checked = false, so checked with errors == 0 means a code body was
analysed and is clean.
opts.upstream (true, or the options of lsp.upstreamCheck) also
checks the file with upstream Luau's type checker and sets upstream to
what lsp.upstreamCheck returns for it, whose modules say how the
check of each module it reached ended and how long it took; the
diagnostics and counts stay the engine checker's.
Parameters
pathstring— VFS path.optsCheckFileOpts(optional) —{ severity?, limit?, context?, upstream? }.
Returns DiagnosticsResult — Array of diagnostic tables.
local diags = lsp.check("/zero/source/main.luau")
typed/builtin//modules/api/engine/lsp/lsp/checkAll
lsp.checkAll(opts: CheckAllOpts?) -> CheckAllResult
Validate the user's Luau scripts and return an aggregate
summary plus diagnostic list. opts.scope = "user" (default)
skips library mounts; "all" includes them. The sweep is
time-budgeted (ZERO_EXECUTE_INLINE_BUDGET_MS, ~20s by default): if
the budget elapses it returns the partial result gathered so far
with budgetExceeded = true rather than blocking the engine.
opts.budgetMs sets the budget for the call and opts.maxFiles caps
the files it checks. opts.upstream (true, or the options of
lsp.upstreamCheck) also checks each file with upstream Luau's type
checker once the engine's own pass is done, within the same budget, and
sets upstream to what that pass found: every module it reached, once,
with how its check ended ("completed", "timedOut", "internal", or
"notAnalysable" with the reason) and how long it took, reused marking a
module checked before the pass reached it and unchanged since.
The pass starts no file once the budget is spent, so it ends within the
budget plus the check of the one file in progress.
Parameters
optsCheckAllOpts(optional) —{ scope?, severity?, limit?, budgetMs?, maxFiles?, upstream? }.
Returns CheckAllResult — { filesChecked, errors, warnings, info, hints, budgetExceeded, diagnostics, upstream? }.
typed/builtin//modules/api/engine/lsp/lsp/checkCode
lsp.checkCode(source: string, opts: CheckOpts?) -> DiagnosticsResult
Validate inline Luau source without a backing file. Useful
for checking code before writing it to disk. A source past the 2 MiB
analysis bound comes back as one source-too-large warning with
checked = false.
Parameters
sourcestring— Luau source.optsCheckOpts(optional) —{ severity?, limit?, context? }.
Returns DiagnosticsResult — Array of diagnostic tables.
typed/builtin//modules/api/engine/lsp/lsp/checkDirty
lsp.checkDirty() -> DiagnosticsResult
Drain the dirty-file set populated by the hot-reload hook, validate each, and return the combined diagnostic list.
Returns DiagnosticsResult — Array of diagnostic tables.
typed/builtin//modules/api/engine/lsp/lsp/definitions
lsp.definitions(opts: DefinitionsOpts?) -> Definitions
The engine's API as a Luau definitions source, upstream Luau's
.d.luau form (declare statements and export type aliases),
generated from the live API registry: the documented members, the
--!global-types aliases and the asset-category shapes lsp.check
types against, bound under the same names. It declares each global the
calling script's globals hold, so a user script, a trusted script and a
worker each get the globals they have; a name upstream's builtin
environment declares keeps upstream's type and is left out.
lsp.upstreamCheck loads the same source into every module it checks,
and an external editor running luau-lsp reads it as a definitions file
(lsp.exportDefinitions writes it out). It is generated again whenever
the registry changes, a library hot reload included. package (@zero)
keys each global's documentation symbol (@zero/global/<name>,
@zero/global/<name>.<member>). Each type string the registry holds is
declared as written, or listed in unrepresented with the reason and
declared any; a declaration upstream refuses to load (an alias that
reaches itself through aliases alone) is listed with upstream's reason,
so the rest of the source loads. opts.documentation = true also returns
documentation, the JSON documentation file luau-lsp reads beside the
definitions: each symbol's signature and description. available is
false, with reason, on a build that does not link the analysis library.
Parameters
optsDefinitionsOpts(optional) —{ documentation? }.
Returns Definitions — { available, reason?, package, source, bytes, globals, types, unrepresented, documentation? }.
local d = lsp.definitions()
print(d.bytes, #d.globals, #d.unrepresented)
typed/builtin//modules/api/engine/lsp/lsp/describe
lsp.describe(path: string, opts: DescribeOpts?) -> DocEntry?
Inspect a single documented entry. Returns the full doc
table (signature, args, returns, examples, level), or nil.
The path is resolved independently of which root the doc is
registered under and of separator style, so the spelling that reads
off the API surface (renderer.texture.create) finds the entry
registered as globals/renderer/texture/create. A path naming a
binding the engine registered internally answers with the entry a Luau
module publishes over it where there is one, so the signature is the
call content makes; opts.includeInternal answers with the internally
registered entry itself. When a path does not resolve,
lsp.describePaths says what the registry holds near it.
Parameters
pathstring— Doc path (e.g."asset/resolve","renderer.texture.create").optsDescribeOpts(optional) — Optional{ includeInternal? }— default prefers the published entry.
Returns DocEntry? — Full doc table or nil.
local doc = lsp.describe("renderer.texture.create")
typed/builtin//modules/api/engine/lsp/lsp/describePaths
lsp.describePaths(path: string) -> { string }
List the registered doc paths related to path. A path that names
an entry returns every root it is registered under (the first is what
lsp.describe resolves to); a path that names a namespace returns the
entries registered under it. Empty when the registry holds nothing
near the path — so a lookup that returns nil can always be turned into
the list of what does exist.
Parameters
pathstring— Doc path in any spelling ("renderer.texture","ecs/query").
Returns { string } — Array of registered doc paths, most canonical first.
for _, p in ipairs(lsp.describePaths("renderer.texture")) do print(p) end
typed/builtin//modules/api/engine/lsp/lsp/describeTool
lsp.describeTool(path: string) -> string?
Return the full documentation text for a code-mode tool.
Parameters
pathstring— Tool path (e.g."scene/spawnLight").
Returns string? — Full tool docs or nil.
typed/builtin//modules/api/engine/lsp/lsp/dirtyStatus
lsp.dirtyStatus() -> DirtyStatus
How many files wait to be re-validated and how many of them a peer
wrote (held), whether a drain job holds
the set, whether a caller waits for that drain, how many drains have run
in a caller's frame and on a job, and how many slices the drains off the
frame ran and the longest one held its worker.
Returns DirtyStatus — The dirty set's state.
typed/builtin//modules/api/engine/lsp/lsp/docsByKind
lsp.docsByKind(kind: string) -> { MethodSummary }
List every doc whose registration kind matches kind.
Valid: "binding", "runtime_tool", "module", "component",
"library", "lua_export".
Parameters
kindstring— Registration kind.
Returns { MethodSummary } — Array of doc summary tables.
typed/builtin//modules/api/engine/lsp/lsp/drainDirty
lsp.drainDirty(opts: DrainDirtyOpts?) -> boolean
Start re-validating every file marked dirty on a job off the frame,
and return whether a job started. The job is background work cut into
short slices, so other work off the frame (module compiles, texture
decodes) runs between them. opts.awaited = true says the caller waits
for the drain to end, as the play gate does: the drain started, or the
one already running, then queues its slices as ordinary work, in turn
with the jobs queued around it, until it ends. opts.own = true takes
only the files this session answers for: a file whose latest write is a
peer's, made while this session was bound to the world, stays in the set
(held in lsp.dirtyStatus()) for a drain without own or for the play
gate, which drains every file before it reads. The answers land in the
cache the play gate reads; lsp.dirtyStatus() reports pending == 0
and running == false once none are left.
Parameters
optsDrainDirtyOpts(optional) —{ awaited?, own? }.
Returns boolean — Whether a drain job started.
typed/builtin//modules/api/engine/lsp/lsp/exportDefinitions
lsp.exportDefinitions(dir: string) -> ExportDefinitionsResult
Write the engine's API out for an external editor (VS Code, Neovim, or
any editor running luau-lsp), so it types the engine's
globals: <dir>/zero.d.luau
(the definitions lsp.definitions returns), <dir>/zero.docs.json (the
documentation file naming each global's and member's signature and
description) and <dir>/.luaurc (nonstrict mode). Point luau-lsp at the
first two (its types.definitionFiles and types.documentationFiles
settings) and it types the engine's globals: entity.spawn("x") checks
against its signature and entity.spwan("x") is an unknown member. The
files hold the globals the calling script's globals hold; call it from
the tier whose globals the editor should know. The files land in the
VFS: userfile.save(path) (the Files panel's "Save to this device")
puts each one on the machine of the person at the screen, and over HTTP
the engine's GET /engine/vfs/<path> reads it. The engine's own checker
reads a *.d.luau file the way upstream does, by loading it, so the
files can stay in a world's content. Writing again replaces them.
globals, types and unrepresented are the lists lsp.definitions
returns; the guide topics/external-editor walks through the editor
setup.
Parameters
dirstring— VFS directory to write into, such as/zero/source/editor.
Returns ExportDefinitionsResult — { available, reason?, files, bytes, globals, types, unrepresented }.
local r = lsp.exportDefinitions("/zero/source/editor")
print(r.files[1], r.bytes, #r.globals)
typed/builtin//modules/api/engine/lsp/lsp/getStrictMode
lsp.getStrictMode() -> StrictMode
Return the current strict mode.
Returns StrictMode — "off" | "soft" | "strict".
typed/builtin//modules/api/engine/lsp/lsp/isStrict
lsp.isStrict() -> boolean
Is the pre-execute LSP gate fully strict? False when off or in soft mode.
Returns boolean — True when fully strict.
typed/builtin//modules/api/engine/lsp/lsp/lastCheckGen
lsp.lastCheckGen() -> number
Generation counter — bumped each time the cache is rebuilt. UI polls this to know when to redraw.
Returns number — Generation number.
typed/builtin//modules/api/engine/lsp/lsp/methods
lsp.methods(namespace: string, opts: MethodsOpts?) -> { MethodSummary } | { string }
List every documented method / entry under a namespace. A broad
namespace (ui, renderer) returns a large dump by default, so two
options narrow it: opts.filter keeps only methods whose name (or
doc path) contains the substring, case-insensitively; opts.namesOnly
returns a plain list of method-name strings instead of the full
per-method summary tables, which is much smaller and leaves nothing to
unwrap. A name, in either form (a summary's name field or a
namesOnly string), is the member's path below the namespace,
dot-joined (texture.create under renderer, proxy.component.get
under entity), so each one names a single member and
lsp.describe(namespace .. "." .. name) answers for it. The listing
answers with the surface content calls: an entry registered internally
is left out where its signature spells the __ binding or a Luau
module publishes the same member, and opts.includeInternal lists
every registered entry instead.
Parameters
namespacestring— Namespace name (e.g."entity","modules/Transform").optsMethodsOpts(optional) — Optional{ filter?, namesOnly?, includeInternal? }.
Returns { MethodSummary } | { string } — Array of method summary tables, or plain name strings when namesOnly is set (empty when the namespace is unknown or nothing matches the filter).
for _, name in ipairs(lsp.methods("ui", { namesOnly = true })) do print(name) end
lsp.methods("renderer", { filter = "shadow" })
typed/builtin//modules/api/engine/lsp/lsp/modules
lsp.modules() -> { ModuleEntry }
List every Luau library module the engine currently knows
about — discovered via --!module headers, library scans, and
manually-recorded docs.
Returns { ModuleEntry } — Array of module summary tables.
typed/builtin//modules/api/engine/lsp/lsp/namespaces
lsp.namespaces(opts: NamespacesOpts?) -> { NamespaceEntry }
List the documentation namespaces reachable from Luau. By
default only namespaces exposing at least one PUBLIC method are
returned, so the list matches what you can actually call — internal
FFI plumbing (e.g. pause, native_entity), whose public surface
lives elsewhere (engine.paused, the entity proxy, …), is left
out. Pass { includeInternal = true } to list every namespace,
internal ones included.
Parameters
optsNamespacesOpts(optional) — Optional{ includeInternal? }— default lists public only.
Returns { NamespaceEntry } — Array of namespace summary tables.
for _, ns in ipairs(lsp.namespaces()) do print(ns.name) end
typed/builtin//modules/api/engine/lsp/lsp/readDirectives
lsp.readDirectives(source: string) -> DirectiveBlock
Parse the leading --! directive block of a Luau source
string. Used by UIs that audit which files have skip directives
and what they suppress.
Parameters
sourcestring— Luau source text.
Returns DirectiveBlock — { mode, codes? }.
typed/builtin//modules/api/engine/lsp/lsp/search
lsp.search(query: string, opts: SearchOpts?) -> { MethodSummary }
Case-insensitive substring search across every registered
doc's path, signature, and description. Hits answer with the surface
content calls: an entry registered internally is left out where its
signature spells the __ binding or a Luau module publishes the same
member, and opts.includeInternal searches every registered entry.
Parameters
querystring— Substring to search for.optsSearchOpts(optional) —{ limit? = 50, includeInternal? }.
Returns { MethodSummary } — Array of method summary tables.
typed/builtin//modules/api/engine/lsp/lsp/setStrict
lsp.setStrict(enabled: boolean) -> boolean
Toggle the pre-execute LSP gate. Returns true when the change
was persisted to .world_settings, false when the play-mode write
lock blocked the write.
Parameters
enabledboolean— True = strict, false = off.
Returns boolean — Persistence signal.
typed/builtin//modules/api/engine/lsp/lsp/setStrictMode
lsp.setStrictMode(mode: StrictMode) -> boolean
Set the pre-execute strict gate's mode. Returns true when the
change was persisted to .world_settings, false when the
play-mode write lock blocked the write.
Parameters
modeStrictMode—"off"|"soft"|"strict".
Returns boolean — Persistence signal.
typed/builtin//modules/api/engine/lsp/lsp/summary
lsp.summary() -> Summary
Counts only — does not re-run validation.
Returns Summary — Counts of cached diagnostics by severity.
typed/builtin//modules/api/engine/lsp/lsp/symbolAt
lsp.symbolAt(path: string, line: number, col: number, name: string, chain: string?) -> SymbolHit?
The identifier name where it stands in path at line:col
(1-based, the file's own columns), with the static type it resolves to
THERE — a local inside a function body, a parameter, a field, a global —
and, for a name a statement in the file introduced, declaredAt = {line, col}. The answer a hover shows and a go-to-definition jumps
to. nil when nothing at that position is a reference to name: a
word in a comment or a string, a keyword.
Parameters
pathstring— VFS path of the file.linenumber— 1-based line.colnumber— 1-based column in the file's own text.namestring— The identifier at that position.chainstring(optional) — The access path the identifier ends —entity.component.addfor a pointer onadd— which is where its API page is filed.
Returns SymbolHit? — The type descriptor of the reference (kind, display, and for a function its params and returns), with name, symbolKind (local, parameter, function, field, global, namespace, module), declaredAt when the file introduced the name, members and memberCount for a table, modulePath and moduleFile for a required module, and doc — the comment block above the declaration (--!desc, --!arg, --!return, --!example), the required module's header, or the API page under chain. nil when nothing there is a reference to name.
local hit = lsp.symbolAt("/zero/source/main.luau", 12, 9, "add", "entity.component.add")
typed/builtin//modules/api/engine/lsp/lsp/tools
lsp.tools() -> { ToolEntry }
List every code-mode tool registered in the VFS under
/zero/docs/tools/<category>/<tool>.
Returns { ToolEntry } — Array of tool summary tables.
typed/builtin//modules/api/engine/lsp/lsp/typeOf
lsp.typeOf(expr_source: string, context_path: string?) -> TypeDescriptor
Infer the static type of a Luau expression. When
context_path is given, the file is loaded and walked so the
inference env contains every local + alias in scope at its end.
An expression past the 2 MiB analysis bound answers kind unknown,
and a context file past it adds nothing to the env.
Parameters
expr_sourcestring— Luau expression source (no surrounding chunk).context_pathstring(optional) — VFS path whose scope should be visible.
Returns TypeDescriptor — Type descriptor table.
local td = lsp.typeOf("Transform.lookAt", "/zero/source/main.luau")
typed/builtin//modules/api/engine/lsp/lsp/upstreamCheck
lsp.upstreamCheck(path: string, opts: UpstreamCheckOpts?) -> UpstreamCheck
Type-check a .luau file with upstream Luau's own type checker (its
Frontend), and every module the file requires, and return what upstream
reports as data. What lsp.check, the execute gate and the play gate
report is unchanged by it. Each require literal resolves to the source
file lsp.check's require-unresolved pass holds it to, which is the
file the runtime loads wherever the runtime loads one, in whichever form
it is written (@builtin::a.b, @ns::, @root::, a bare dotted a.b,
.x, ..x, ./x, ../x, ~.x, ~pkg.x, an absolute path, a folder
asset), and
requires lists each literal of the file with the file it reached
(module) and the file the runtime's require loads for it from this
file (runtimeModule), nil where either reaches none.
findings carry upstream's error kind or lint rule, the module they are
in and 1-based positions in that module as written; they cover the file,
and with opts.includeRequired the type errors of every module it
reaches come back as well. Upstream reads every module through its
analysis view: the engine's typed declarations read as the plain Luau
functions they declare, their generic, parameter and return annotations
kept, a return type written after -> read after :, and every line
and column as in the source; view lists where the view of the file
differs from it as { line, col, written, reads }. A module whose
findings come back that upstream cannot parse through its view or past
the 2 MiB analysis bound is listed in notAnalysable with the reason,
and when that is the file itself analysable is false. The checked
modules are kept between calls: checkedModules names the ones this call
type-checked, empty when nothing the file reaches changed, and a write to
a source re-checks that module and the modules depending on it. The
phases of a module's check whose work grows with the types they meet
stop at opts.timeLimitMs, and modules
says of each module the call reached how its check ended ("completed",
"timedOut" or "internal") and how long it took, reused marking one an
earlier call checked that is unchanged since. The modules
held between calls are bounded: once a call returns their sources sum to
at most held.limitBytes, the modules the least recent calls reached
going first, and held and evicted report it. A failure
inside the analysis library comes back as an "internal" finding with
completed false, and the internal errors upstream reports for a
module come back as one "internal" finding whose count says how many. opts.typeCheck = false reads the file and every
module it reaches and resolves their requires without checking types. available is false, with reason, on a build that
does not link the analysis library.
Parameters
pathstring— VFS path of a .luau file, a module identity, or a@scope::path.optsUpstreamCheckOpts(optional) —{ solver?, mode?, timeLimitMs?, includeRequired?, typeCheck? }.
Returns UpstreamCheck — { available, path, analysable, reason?, completed, solver, mode, elapsedMs, findings, notAnalysable, requires, view, checkedModules, timedOut, modules, held, evicted, errors, warnings }.
local r = lsp.upstreamCheck("@builtin::modules.boids", { mode = "strict" })
typed/builtin//modules/api/engine/luau_profile/luau_profile/begin
luau_profile.begin(name: string) -> number
Open a named manual region. Returns an opaque integer id;
pass it back to end_region(id) to close and record elapsed
wall-clock under name.
Parameters
namestring— Region name; aggregated across opens.
Returns number — Region id.
local id = luau_profile.begin("walk"); ...; luau_profile.end_region(id)
typed/builtin//modules/api/engine/luau_profile/luau_profile/end_region
luau_profile.end_region(id: number)
Close a region previously opened by begin(name). Records
elapsed wall-clock under the region's name. Silently no-ops on
unknown id (typically a double-close or swapped-out VM).
Parameters
idnumber— Region id returned bybegin().
luau_profile.end_region(id)
typed/builtin//modules/api/engine/luau_profile/luau_profile/folded
luau_profile.folded() -> string
The folded-stack dump as a string, one line per stack as
<ticks> <stack_csv> — the format upstream Luau emits and
tools/perfgraph.py consumes unchanged. The same bytes dump
writes, handed back instead of written, so the profile can go
wherever the caller keeps it: vfs.write puts it in the engine
filesystem, where bash and vfs.read reach it.
Returns string — Folded-stack text; empty when nothing was sampled.
vfs.write("/source/tmp/sample.folded", luau_profile.folded())
typed/builtin//modules/api/engine/luau_profile/luau_profile/is_running
luau_profile.is_running() -> boolean
True iff the background sampler is currently running.
Returns boolean — Sampler running state.
if luau_profile.is_running() then luau_profile.stop() end
typed/builtin//modules/api/engine/luau_profile/luau_profile/reset
luau_profile.reset()
Clear every accumulated sample and region stat. The sampler keeps running if it was already on; only the data is wiped.
luau_profile.reset()
typed/builtin//modules/api/engine/luau_profile/luau_profile/sampling_available
luau_profile.sampling_available() -> boolean
True on platforms where the background sampler can run (native targets), false on WASM. Manual regions work everywhere — only the sampler is platform-gated.
Returns boolean — Whether start() would actually spawn a sampler.
if luau_profile.sampling_available() then luau_profile.start() end
typed/builtin//modules/api/engine/luau_profile/luau_profile/snapshot
luau_profile.snapshot(top_n: number?) -> Snapshot
Snapshot the current accumulator without touching the
filesystem — cheap enough for per-frame UI polling. top_n
truncates stacks to the N hottest entries; omitting it
returns all stacks sorted descending by self_us. regions
is always returned in full (sorted by total_us).
Parameters
top_nnumber(optional) — Truncate stacks to this many entries; omit for all.
Returns Snapshot — Profile snapshot.
local snap = luau_profile.snapshot(10)
typed/builtin//modules/api/engine/luau_profile/luau_profile/start
luau_profile.start(hz: number?) -> StartResult
Start the background Luau sampling profiler at hz samples
per second (default 1000, clamped to [1, 100000]). Idempotent
— calling while already running is a no-op. Returns
{ available, hz } — available = false on WASM (no
std::thread). Manual regions work regardless.
Parameters
hznumber(optional) — Sampling rate in Hz.
Returns StartResult — Effective sampler state.
luau_profile.start(500)
typed/builtin//modules/api/engine/luau_profile/luau_profile/stop
luau_profile.stop()
Stop the background sampler. Blocks until the sampler thread
joins (typically <1ms). Safe when not running. Does not clear
the accumulator — call reset() to drop samples.
luau_profile.stop()
typed/builtin//modules/api/engine/mathx/mathx/addScaledVec3
mathx.addScaledVec3(dstBuffer: Substrate.TypedBuffer, srcBuffer: Substrate.TypedBuffer, count: number, scale: number) -> boolean
dst[i] += src[i] * scale for count vec3 elements. Both
buffers must hold at least count * 3 floats. Useful for
particle integration (position += velocity * dt) and accumulator
passes.
Parameters
dstBufferSubstrate.TypedBuffer— The buffer written into.srcBufferSubstrate.TypedBuffer— The buffer read from.countnumber— Number of vec3 elements.scalenumber— Multiplier applied to every src element.
Returns boolean — True on success.
mathx.addScaledVec3(positions, velocities, n, dt)
typed/builtin//modules/api/engine/mathx/mathx/dampScalar
mathx.dampScalar(buffer: Substrate.TypedBuffer, offset: number, count: number, target: number, smoothTime: number, dt: number) -> boolean
Critically-damped exponential approach toward target for
count scalars at buffer[offset .. offset+count]. smoothTime
is the time constant (~ 0.16 ⇒ ~63% per frame at 60 Hz). Pass
smoothTime <= 0 to snap to the target.
Parameters
bufferSubstrate.TypedBuffer— The buffer to operate on.offsetnumber— Starting f32 index.countnumber— Number of scalars.targetnumber— Target value all scalars approach.smoothTimenumber— Time constant (≤ 0 snaps to target).dtnumber— Frame time in seconds.
Returns boolean — True on success, false on a bad handle or out-of-range slice.
mathx.dampScalar(buf, 0, 16, 0.0, 0.16, dt)
typed/builtin//modules/api/engine/mathx/mathx/lerpVec3
mathx.lerpVec3(buffer: Substrate.TypedBuffer, offset: number, count: number, tx: number, ty: number, tz: number, t: number) -> boolean
Element-wise linear blend of count vec3s in
buffer[offset .. offset+count*3] toward (tx, ty, tz) by t.
Parameters
bufferSubstrate.TypedBuffer— The buffer to operate on.offsetnumber— Starting f32 index.countnumber— Number of vec3 elements.txnumber— Target X.tynumber— Target Y.tznumber— Target Z.tnumber— Blend amount (0..1).
Returns boolean — True on success.
mathx.lerpVec3(buf, 0, n, 0, 1, 0, 0.5)
typed/builtin//modules/api/engine/mathx/mathx/normalizeQuat
mathx.normalizeQuat(buffer: Substrate.TypedBuffer, offset: number, count: number) -> boolean
Re-normalise count quaternions in place. Zero-length quats
become identity (0, 0, 0, 1) so downstream code never sees NaN.
Parameters
bufferSubstrate.TypedBuffer— The buffer to operate on.offsetnumber— Starting f32 index.countnumber— Number of quaternions.
Returns boolean — True on success.
mathx.normalizeQuat(buf, 0, n)
typed/builtin//modules/api/engine/mathx/mathx/slerpQuat
mathx.slerpQuat(buffer: Substrate.TypedBuffer, offset: number, count: number, tx: number, ty: number, tz: number, tw: number, t: number) -> boolean
Slerp count quaternions (xyzw) at buffer[offset..] toward
(tx, ty, tz, tw) by t. Falls back to nlerp+normalize for
very-close quats. Always picks the shortest-arc path.
Parameters
bufferSubstrate.TypedBuffer— The buffer to operate on.offsetnumber— Starting f32 index.countnumber— Number of quaternions.txnumber— Target quat X.tynumber— Target quat Y.tznumber— Target quat Z.twnumber— Target quat W.tnumber— Slerp amount (0..1).
Returns boolean — True on success.
mathx.slerpQuat(buf, 0, n, 0, 0, 0, 1, 0.25)
typed/builtin//modules/api/engine/mathx/mathx/transformVec3
mathx.transformVec3(buffer: Substrate.TypedBuffer, offset: number, count: number, mat16: { number }) -> boolean
Treat each vec3 in buffer[offset..] as a position (w = 1),
multiply by the 4x4 column-major matrix mat16 (16-element
array), write .xyz of the result back. Layout matches glam,
wgpu, and GLSL conventions.
Parameters
bufferSubstrate.TypedBuffer— The buffer to operate on.offsetnumber— Starting f32 index.countnumber— Number of vec3 elements.mat16{ number }— Column-major 4x4 matrix as a 16-element array.
Returns boolean — True on success.
mathx.transformVec3(positions, 0, n, worldMatrix)
typed/builtin//modules/api/engine/mcpLog/mcpLog/clear
mcpLog.clear() -> boolean
Clear all entries from the engine's MCP log ring buffer.
Returns boolean — True on success.
mcpLog.clear()
typed/builtin//modules/api/engine/mcpLog/mcpLog/query
mcpLog.query(limit: number?) -> { McpLogEntry }
Return the most-recent MCP tool-call entries from the engine's
MCP log ring buffer (newest last). Pass limit to cap how many
entries are returned — omit for the full ring (up to 500 entries).
Parameters
limitnumber(optional) — Maximum number of entries to return.
Returns { McpLogEntry } — Array of tool-call entry tables.
for _, e in ipairs(mcpLog.query(50)) do print(e.tool_name, e.status) end
typed/builtin//modules/api/engine/microphone/microphone/awaitRunning
microphone.awaitRunning(timeout: number?) -> (MicState, string?)
Wait until the capture settles out of starting and
permissionPending, and report where it landed. Returns as soon as the
state settles, or when timeout seconds have passed, whichever comes
first — a browser permission prompt nobody answers never settles, so
the wait is always bounded.
Parameters
timeoutnumber(optional) — Seconds to wait at most. Defaults to 10.
Returns (MicState, string?) — The state reached, and its reason where it has one.
microphone.start(); local state, why = microphone.awaitRunning()
typed/builtin//modules/api/engine/microphone/microphone/devices
microphone.devices() -> { MicDevice }
Every input device the platform offers. id is what
microphone.start takes to select one and is stable across reboots
where the platform provides a stable identifier; name is the label a
person recognises.
An empty list is a legitimate answer, not a failure: a machine with no input hardware offers none, and a browser names none until microphone access has been granted at least once — the labels are part of what the permission protects.
Returns { MicDevice } — Array of { id, name, default }.
for _, d in ipairs(microphone.devices()) do print(d.name, d.default) end
typed/builtin//modules/api/engine/microphone/microphone/frequencies
microphone.frequencies() -> { number }
The frequency each spectrum bin is centred on, in Hz, as an array
parallel to microphone.spectrum(). Derived from the capture's rate and
transform size, so it changes only when a capture is started with
different ones. Empty while no capture is running.
Returns { number } — Array of centre frequencies, one per bin.
local hz = microphone.frequencies(); print(hz[#hz]) -- the Nyquist frequency
typed/builtin//modules/api/engine/microphone/microphone/level
microphone.level() -> number
Loudness of the most recent analysis window, as an RMS amplitude in 0..1. A full-scale sine reads about 0.707 and silence reads 0.
Measured over only the samples that have arrived, so a capture that has just started reports the loudness of what it holds rather than a level diluted by a window it has not filled yet. 0 while no capture is running.
Returns number — RMS amplitude, 0..1.
if microphone.level() > 0.05 then print("someone is talking") end
typed/builtin//modules/api/engine/microphone/microphone/peak
microphone.peak() -> { [string]: number }?
The bin carrying the most energy and what it says: the frequency it is centred on, its amplitude, and the loudness of the whole window. A capture reading silence answers with amplitude 0 at bin 1.
Returns { [string]: number }? — { bin, hz, amplitude, level }, or nil while no capture is running.
local p = microphone.peak(); if p and p.amplitude > 0.05 then print(p.hz) end
typed/builtin//modules/api/engine/microphone/microphone/samples
microphone.samples(max: number?) -> buffer?
Captured mono PCM no caller has taken yet, oldest sample first, as a
buffer of little-endian f32 read with buffer.readf32. The samples are
removed, so successive calls walk forward through the capture and a
caller doing its own analysis sees every frame once.
nil while no capture is running, and a zero-length buffer when the
capture is running and nothing new has arrived. Samples nobody takes
are discarded once the queue fills, and status().overruns counts
every one.
Parameters
maxnumber(optional) — How many samples to take at most. Omitted, everything held comes back.
Returns buffer? — Buffer of f32 samples, or nil when no capture is running.
local pcm = microphone.samples(); if pcm then print(buffer.len(pcm) // 4) end
typed/builtin//modules/api/engine/microphone/microphone/spectrum
microphone.spectrum() -> { number }
Amplitude per frequency bin over the most recent analysis window:
fftSize / 2 + 1 numbers, DC at index 1 through the Nyquist frequency
at the last. Bin i covers (i - 1) * status().binHz Hz.
Each value is an amplitude estimate rather than a raw transform magnitude, so a full-scale tone sitting on a bin centre reads about 1.0 and the numbers stay comparable across transform sizes.
The window is multiplied by a Hann taper before the transform. An untapered window ends abruptly at both edges and the transform reads that as energy spread across every bin, smearing one tone into a skirt that buries quieter tones beside it. Hann trades a slightly wider main lobe — a tone occupies about three bins rather than one — for sidelobes that fall away steeply, which is what lets neighbouring tones be told apart. Read a peak as "a tone near here", not "a tone exactly here".
Reading this takes no samples away from microphone.samples(). Empty
while no capture is running.
Returns { number } — Array of amplitudes, one per bin.
local bins = microphone.spectrum(); print(#bins, bins[1])
typed/builtin//modules/api/engine/microphone/microphone/start
microphone.start(opts: MicOpts?) -> (MicState?, string?)
Open an input device and begin capturing. Returns the state the
capture reached — "running" once a device is delivering, or
"permissionPending" where the platform must ask for access first,
which is the browser's normal path and Android's on the first start.
Poll microphone.status() from there, or use
microphone.awaitRunning(). Where access is refused without asking (a
permission refused for good, the system's microphone privacy toggle, a
native engine's fake microphone presented as deny), it returns
"denied", and status().reason names the refusal. Started while the
app is in the background, it returns "starting", and the device opens
once the app returns to the foreground.
A request that cannot be made at all returns nil and the reason: an
fftSize that is not a whole power of two between 64 and 16384, a
device no machine here offers, a rate the device does not capture at,
or a capture that is already running.
Omitting device opens the platform default. Omitting sampleRate
takes the device's own rate, which is what avoids a resample.
fftSize is how many samples one analysis window covers and defaults
to 1024 — at 48 kHz that spans ~21 ms and resolves ~47 Hz per bin.
Parameters
optsMicOpts(optional) —{ device, sampleRate, fftSize }.
Returns (MicState?, string?) — The state reached, or nil and the reason the request was refused.
local state, why = microphone.start({ fftSize = 2048 })
typed/builtin//modules/api/engine/microphone/microphone/status
microphone.status() -> MicStatus
Where the capture stands.
reason carries the platform's own message: the refusal for denied
(naming the system settings or the privacy toggle where that is what
grants access), the device's message for failed, what is being
waited on for permissionPending, and the app being in the background
for a starting capture held there. binHz is the width of one spectrum bin and
bins how many microphone.spectrum() returns.
framesCaptured counts every mono frame the device delivered whether
or not anything drained it, so a silent room reads differently from a
stalled device. overruns counts samples discarded because a consumer
did not keep up — it standing still is what says the readings are
continuous, and it climbing is why a caller sees gaps.
Returns MicStatus — { state, reason, device, sampleRate, fftSize, binHz, bins, framesCaptured, overruns }.
local s = microphone.status(); print(s.state, s.framesCaptured, s.overruns)
typed/builtin//modules/api/engine/microphone/microphone/stop
microphone.stop() -> boolean
Stop the capture and release the device. True when a capture was open or being opened at call time. The device is let go before this returns, so a stop followed by a start opens it again rather than finding it held.
Returns boolean — Whether a capture was active.
microphone.stop()
typed/builtin//modules/api/engine/mode_flip_guard/M/acrossRebuild
M.acrossRebuild(taken: (mode: string) -> (), settled: (mode: string) -> ()) -> nil
Carry state across the rebuild a mode flip makes. The rebuild unloads
the scene's layers and loads them again for the new mode, so every entity
the scene holds is despawned and materialised again over the frames after
the flip. taken runs as the flip is taken, before the teardown removes
anything, with the mode being entered; settled runs once the rebuild has
ended, with the mode it materialised, before isInFlight reads false. A
flip that arrives while a rebuild runs is carried by that rebuild, so each
rebuild runs one taken and one settled. A watcher that raises is
logged and the others still run.
Parameters
taken(mode: string) -> ()— Called with the mode being entered as the flip is taken.settled(mode: string) -> ()— Called with the mode the rebuild materialised once it has ended.
Returns nil
typed/builtin//modules/api/engine/mode_flip_guard/M/beginPlaySession
M.beginPlaySession() -> number
Open a play session, advancing the play-session id. engine.module
calls this from its mode-change watcher as the engine enters play, so
every play session the engine runs carries an id of its own whichever
route flipped the mode.
Returns number — The id of the play session being opened.
typed/builtin//modules/api/engine/mode_flip_guard/M/isInFlight
M.isInFlight() -> boolean
Whether a mode-flip transition is materialising the scene. The
transition unloads the root layer and reloads it for the new mode across
many frames, so while this reads true the live entities are a partial
rebuild of the scene; code that judges authored scene state waits for it
to clear.
Returns boolean — true while the transition is running.
typed/builtin//modules/api/engine/mode_flip_guard/M/isOwned
M.isOwned() -> boolean
Whether the layers module currently owns the mode-flip reset.
Returns boolean — true while the layers transition owns the flip; spawners stand down.
typed/builtin//modules/api/engine/mode_flip_guard/M/playSession
M.playSession() -> number
The id of the play session the engine is in. State that belongs to a single play session records this id when it is armed and compares it before it is spent, so an arm outlives exactly the session that made it.
Returns number — The current play-session id.
typed/builtin//modules/api/engine/mode_flip_guard/M/rebuildSettled
M.rebuildSettled(mode: string) -> nil
Run every acrossRebuild watcher's settled. The layers module calls
this once the rebuild has materialised the mode the engine is in.
Parameters
modestring— The mode the rebuild materialised.
Returns nil
typed/builtin//modules/api/engine/mode_flip_guard/M/rebuildTaken
M.rebuildTaken(mode: string) -> nil
Run every acrossRebuild watcher's taken. The layers module calls
this as it takes a flip that starts a rebuild, before the teardown.
Parameters
modestring— The mode being entered.
Returns nil
typed/builtin//modules/api/engine/mode_flip_guard/M/setInFlight
M.setInFlight(v: boolean) -> nil
Set whether a mode-flip transition is materialising the scene.
Parameters
vboolean—truefor the span of the transition,falseonce it has settled.
Returns nil
typed/builtin//modules/api/engine/mode_flip_guard/M/setOwned
M.setOwned(v: boolean) -> nil
Set whether the layers module owns the current mode-flip reset.
Parameters
vboolean—trueto claim ownership,falseto release.
Returns nil
typed/builtin//modules/api/engine/modelImport/modelImport/decompose
modelImport.decompose(bytes: buffer | string, format: string) -> PromiseHandle
Parse raw model bytes on a background thread. format is the real source
extension ("fbx", "obj", "dae", "gltf", "glb", "stl", "ply",
"3ds", …), forwarded to assimp as the format hint. Returns a promise
handle: task.await it, then read the data with result(handle).
Parameters
bytesbuffer | string— Raw model file bytes (fromvfs.readAsync).formatstring— The source file extension (lowercase, no dot).
Returns PromiseHandle — Promise handle for task.await.
local h = modelImport.decompose(bytes, "obj"); task.await(h)
typed/builtin//modules/api/engine/modelImport/modelImport/decomposeFiles
modelImport.decomposeFiles(files: { ModelFile }, mainName: string) -> PromiseHandle
Parse a model plus its companion files on a background thread, so assimp
resolves the model's external references (a .gltf's external .bin and
image files, an .obj's .mtl colors/textures, MD5's .md5anim, …).
files is an array of { name = basename, bytes = <bytes> } that MUST
include the model file itself; mainName is that file's basename. Returns a
promise handle: task.await it, then read the data with result(handle) —
the same shape decompose produces.
Parameters
files{ ModelFile }— Array of{ name, bytes }: the model file plus its companions.mainNamestring— Basename of the model file to import (one offiles' names).
Returns PromiseHandle — Promise handle for task.await.
local h = modelImport.decomposeFiles(files, "CesiumMilkTruck.gltf"); task.await(h)
typed/builtin//modules/api/engine/modelImport/modelImport/extractAnimation
modelImport.extractAnimation(sourcePath: string, clipName: string) -> PromiseHandle
Read a model source file and extract one animation clip to its .zanim
payload, stashed for retrieval. The source extension decides the parser, so
this is format-agnostic. Returns a promise handle: task.await it, then
extractAnimationResult(handle) returns the bytes.
Parameters
sourcePathstring— VFS path to the source model file.clipNamestring— Clip name as returned byresult(handle).animations[i].name.
Returns PromiseHandle — Promise handle for task.await.
typed/builtin//modules/api/engine/modelImport/modelImport/extractAnimationResult
modelImport.extractAnimationResult(handle: PromiseHandle | string) -> string?
After awaiting an extractAnimation handle, return the extracted
.zanim bytes (binary-safe), consuming them. The bytes to hand to
asset.create("animation", name, { bytes }). Returns nil on failure or if
already taken.
Parameters
handlePromiseHandle | string— Promise handle fromextractAnimation.
Returns string? — The clip's .zanim payload bytes, or nil.
typed/builtin//modules/api/engine/modelImport/modelImport/result
modelImport.result(handle: PromiseHandle | string) -> any?
Read the decomposed model after decompose's handle has been awaited.
Every format decomposes into the same shape, so this is format-agnostic.
Runs on the main thread; consumes the stored result.
Parameters
handlePromiseHandle | string— Promise handle fromdecompose.
Returns any? — { nodes, meshes, materials, textures, animations, hasSkeleton, skeletonRootNode?, skeleton? }, or nil.
typed/builtin//modules/api/engine/modelImport/modelImport/retryHandle
modelImport.retryHandle(makeHandle: () -> any, retries: number?, yield: (() -> ())?) -> (PromiseHandle | string)?
Parameters
makeHandle() -> anyretriesnumber(optional)yield(() -> ())(optional)
Returns (PromiseHandle | string)?
typed/builtin//modules/api/engine/modelImport/modelImport/rigFromMeshSkin
modelImport.rigFromMeshSkin(meshBytes: buffer | string) -> string?
Lift the skeleton out of a skinned .mesh (ZMSH) payload and return it
as a .rig JSON document: bones (hierarchy, rest pose, inverse-bind). The
source rig a skinned mesh's clips retarget through. Returns nil when the
bytes are not a mesh or carry no skin.
Parameters
meshBytesbuffer | string— Raw ZMSH mesh bytes carrying a skin.
Returns string? — .rig JSON document, or nil.
typed/builtin//modules/api/engine/modelImport/modelImport/rigFromSkeleton
modelImport.rigFromSkeleton(skeleton: AnimationSkeleton) -> string?
Build a .rig JSON document from the skeleton an animation-only file was
authored on — result(handle).skeleton, the bones its clips drive with
their local rest transforms. Forward kinematics over the locals resolves
globals + inverse-bind. The source rig a standalone clip retargets through.
Returns nil on malformed input.
Parameters
skeletonAnimationSkeleton—{ names, parents, locals }(adecomposeresult'sskeleton).
Returns string? — .rig JSON document, or nil.
local rigJson = modelImport.rigFromSkeleton(data.skeleton)
typed/builtin//modules/api/engine/multiplayer/multiplayer/avatarEmote
multiplayer.avatarEmote(entityId: (string | entityRef), id: number, startAt: number?) -> number
Play an emote on an avatar this peer owns: id (an integer 0 to
65535 the avatar's animator names) starting at the session time
startAt (sessionTime() seconds; now when left out). It rides every
frame of the avatar's channel for half a second, so a lost datagram
does not lose it, and every peer lists it in avatarState(e).emotes
with that start time, so each plays it in phase
(sessionTime() - startedAt is how far in it is).
Parameters
entityId(string | entityRef)— An avatar on the channel.idnumber— The emote, 0 to 65535.startAtnumber(optional) — The session time it starts at; now when left out.
Returns number — The session time the emote starts at, in seconds.
local startedAt = multiplayer.avatarEmote(self.entity, 3)
typed/builtin//modules/api/engine/multiplayer/multiplayer/avatarState
multiplayer.avatarState(entityId: (string | entityRef)) -> AvatarReading?
Read an avatar on the channel as this peer last drew or sent it, or
nil for an entity with no channel open or nothing drawn or sent yet.
owned is true on the peer that owns and states it. moment is the
session time drawn (a frame's stamp on the owner); velocity (m/s),
gait and grounded are the locomotion at that moment; parameters
the declared parameters by name as every peer reads them;
parametersAt the session time each of those took its value, the stamp
of the first frame that carried it, which every peer that took that frame
reads alike (on the owner, the frame it went out in); targets the
IK targets by name in the root's frame; emotes those started within
the last 10 s as { id, startedAt } in the order they arrived; view
the direction the owner's viewer looks. traffic counts what this peer
sent (owned) or received (remote) of the avatar: frames and bytes a
second over the last 2 s and running totals. On a receiver stream
holds the frames received, those reordered on the way, parameter
blocks packed under another declaration than this peer's
(layoutMismatches, each unread), the interarrival jitterMs and the
frames buffered. The root pose is the entity's own transform;
smoothing(entityId).stream says how it is drawn.
Parameters
entityId(string | entityRef)— An avatar on the channel.
Returns AvatarReading? — The avatar as last drawn or sent, or nil.
local a = multiplayer.avatarState(other); if a then print(a.gait, a.parameters.Smile) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/beginOperation
multiplayer.beginOperation(description: string)
Begin recording an undoable operation. All mutations until
commitOperation() are grouped into one undo entry.
Parameters
descriptionstring— Human-readable label.
multiplayer.beginOperation("move cube")
typed/builtin//modules/api/engine/multiplayer/multiplayer/canRedo
multiplayer.canRedo() -> boolean
Check if this client has any redoable operations.
Returns boolean — True if redo is available.
typed/builtin//modules/api/engine/multiplayer/multiplayer/canUndo
multiplayer.canUndo() -> boolean
Check if this client has any undoable operations.
Returns boolean — True if undo is available.
typed/builtin//modules/api/engine/multiplayer/multiplayer/cancelOperation
multiplayer.cancelOperation()
Cancel the current operation and restore all properties to their values at begin time.
multiplayer.cancelOperation()
typed/builtin//modules/api/engine/multiplayer/multiplayer/childPoseFromOwner
multiplayer.childPoseFromOwner(entityId: (string | entityRef)) -> boolean
Whether this peer drew the entity's local pose, on the last frame,
from what the peer that owns its parent states of it: a child
syncChildPose names under a synced entity another peer publishes. A
component that turns or moves a child on its own (a character's facing
derived from its motion) leaves a child this answers true for to its
owner. False on the peer that owns the parent, offline, and for any
other entity.
Parameters
entityId(string | entityRef)— The child to ask about.
Returns boolean — True while the child is drawn from its owner.
if not multiplayer.childPoseFromOwner(turretId) then aimTurret() end
typed/builtin//modules/api/engine/multiplayer/multiplayer/claimOwnership
multiplayer.claimOwnership(entityId: (string | entityRef)?) -> boolean
Request ownership of an entity. The relay grants a claim on
an entity no peer owns (never claimed, or released by its owner)
and tells every peer; an entity another peer owns stays theirs, and
the refusal is counted in getDiagnostics().refusals and named by
lastRefusal. The owner hands an entity on by releasing it.
Parameters
entityId(string | entityRef)(optional) — Entity id or proxy to claim.
Returns boolean — True once the claim is on its way to the relay.
typed/builtin//modules/api/engine/multiplayer/multiplayer/clearHistory
multiplayer.clearHistory()
Drop this client's whole undo/redo history — for boundaries where old edits stop being meaningful (a scene load, a test rig reset).
multiplayer.clearHistory()
typed/builtin//modules/api/engine/multiplayer/multiplayer/commitOperation
multiplayer.commitOperation()
Finalize the current operation and push it onto the undo stack. Only changes that actually differ from the start state are recorded.
multiplayer.commitOperation()
typed/builtin//modules/api/engine/multiplayer/multiplayer/connect
multiplayer.connect(relayUrl: string)
Connect to a multiplayer relay server for the current world.
Uses the loaded world's world_id as the room prefix for scene
isolation. A world must be loaded before connecting.
Parameters
relayUrlstring— Relay server URL.
multiplayer.connect("https://relay.example.com")
typed/builtin//modules/api/engine/multiplayer/multiplayer/disconnect
multiplayer.disconnect()
Disconnect from the multiplayer relay server.
multiplayer.disconnect()
typed/builtin//modules/api/engine/multiplayer/multiplayer/explain
multiplayer.explain(entityId: (string | entityRef), componentType: string, property: string) -> DeliveryVerdict
Why a synced property is not reaching the peers this client shares its entity's room with. Answers from the engine's own registry, so a name the component never registered is reported as such instead of inferred from a second client's silence.
Parameters
entityId(string | entityRef)— Entity id or proxy.componentTypestring— Component type name, e.g. "Health".propertystring— Property name as written in the component'ssync {}block.
Returns DeliveryVerdict — arriving true when the property is on its way; otherwise reason names the cause and property carries the registry's record of it when one exists.
local v = multiplayer.explain(player, "Health", "hp")
if not v.arriving then print(v.reason) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/getDiagnostics
multiplayer.getDiagnostics() -> SyncDiagnostics
Get sync diagnostics — traffic counts, bandwidth, link quality,
peer count. The counts — bytesSent/Received,
datagramsSent/Received, rpcsSent/Received, ownershipChanges,
refusals — are running totals for the session, so a sparse event
stays readable long after it happened; subtract two samples for the
rate over the interval between them. refusals counts the messages
of this session's the relay refused (a claim on an entity another
peer owns, a change to one, a room outside the world the connection
was admitted to), and lastRefusal names the latest in the relay's
words once there is one. bytesSentPerSec / bytesReceivedPerSec are
averages over the last completed ~1 second window.
rttMs is the smoothed round-trip time to the relay and
packetLoss the fraction (0..1) of packets lost over the last 5
seconds; both read 0 until the transport has sampled a live
connection. messagesAwaitingEntity counts the sync messages this
peer is holding for an entity it has not received yet — each waits
for the spawn that names it, applies the moment it arrives, and is
released once its wait runs out. reliableInFlight counts the
reliable messages this peer has sent that the relay has not yet taken:
it reads near 0 while the link keeps up with what this peer sends, and
a count that grows names a link carrying less than that, every
reliable change sent behind it (a Sync field, a spawn) waiting with it.
Returns SyncDiagnostics — Diagnostics table.
local d = multiplayer.getDiagnostics()
if d.packetLoss > 0.05 then log.warn(("unstable connection, %d ms round trip"):format(d.rttMs)) end
print(d.messagesAwaitingEntity .. " message(s) waiting for their entity")
typed/builtin//modules/api/engine/multiplayer/multiplayer/getPeerId
multiplayer.getPeerId() -> number?
Get the peer ID the relay issued this client's connection.
Returns number? — Local peer ID, or nil exactly when isConnected() is false: while dialing, before the relay names the connection, and after it drops.
typed/builtin//modules/api/engine/multiplayer/multiplayer/getPeers
multiplayer.getPeers() -> { PeerInfo }
Get a list of all connected peers in the current session.
Returns { PeerInfo } — Array of peer info tables.
for _, p in ipairs(multiplayer.getPeers()) do print(p.name) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/getRoomPeers
multiplayer.getRoomPeers(roomKey: string) -> { PeerInfo }
Get the peers this client shares the given room with, ordered by
peer id. getPeers answers for the whole session — the union of every
room this client is in — while this answers for one room, so a peer
that leaves this room while staying in another disappears from here
and remains in getPeers.
Parameters
roomKeystring— Fully-qualified room key ({worldGuid}/{profile}/{branch}/{mode}/{sceneGuid}).
Returns { PeerInfo } — Array of peer info tables for that room.
for _, p in ipairs(multiplayer.getRoomPeers(key)) do print(p.id) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/getRooms
multiplayer.getRooms() -> { string }
The relay rooms this client has joined, sorted. A broadcast reaches
only the peers that share one of these. They are the rooms of
observe() as of the last frame, read from the rooms the session
publishes every frame, so a component can ask every frame.
Returns { string } — Room keys.
for _, key in ipairs(multiplayer.getRooms()) do print(key) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/getTickRate
multiplayer.getTickRate() -> number
Get the current sync tick rate (network updates per second).
Returns number — Sync ticks per second (default 20).
typed/builtin//modules/api/engine/multiplayer/multiplayer/heldMessages
multiplayer.heldMessages() -> { HeldMessage }
The sync messages this peer is holding for entities it has not
received — what getDiagnostics().messagesAwaitingEntity counts, one
entry each, with the entity sync id it names, its age and the grace it
is held against.
Returns { HeldMessage } — Held messages.
for _, m in ipairs(multiplayer.heldMessages()) do print(m.kind, m.ageMs) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/holdRoom
multiplayer.holdRoom(scene: string, held: boolean)
Keep this client in the relay room of a scene while its layer unloads and loads again, as a rebuild in place does. A held room is left only once it is released and its scene is no longer loaded.
Parameters
scenestring— The scene guid.heldboolean— True to hold the room, false to release it.
multiplayer.holdRoom(layers.active.guid, true)
typed/builtin//modules/api/engine/multiplayer/multiplayer/isConnected
multiplayer.isConnected() -> boolean
Check if a multiplayer session is connected to a relay and the
relay has named this client. True exactly when getPeerId() answers
an id.
Returns boolean — True if connected under the peer id the relay issued.
typed/builtin//modules/api/engine/multiplayer/multiplayer/isHost
multiplayer.isHost() -> boolean
Whether THIS client is the host (authoritative owner) of the
current scene's play room — the relay room CREATOR, or offline /
single-player. Host code spawns the shared synced world (via
entity.spawnSynced or a scene's onHostLoad) and runs authoritative
simulation; a non-host (JOINER) receives that content from the relay
snapshot and must NOT re-create it. Gate ANY code that spawns synced
entities or owns shared state with this so it runs on exactly one
client — running it on every peer is the double-spawn 'explosion'.
Returns boolean — True on the host / offline / single-player; false on a confirmed joiner. Defaults to true when the role isn't known yet (degrade to host so single-player and pre-join code still run) — pair with a scene's onHostLoad hook when exact one-shot timing matters.
if multiplayer.isHost() then enemy = entity.spawnSynced("enemy") end
typed/builtin//modules/api/engine/multiplayer/multiplayer/isOperationOpen
multiplayer.isOperationOpen() -> boolean
Whether an operation is open: true between beginOperation and
its commitOperation or cancelOperation. A caller that records file
writes reads the file's prior contents only while one is open.
Returns boolean — True while an operation is open.
if multiplayer.isOperationOpen() then before = vfs.read(p) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/isOwner
multiplayer.isOwner(entityId: (string | entityRef)?) -> boolean
Check if the local client owns the given entity (or the current entity if called from a component). Only the owner can modify synced properties directly.
Parameters
entityId(string | entityRef)(optional) — Entity id or proxy to check (defaults toself.entityIdin component context).
Returns boolean — True if the local client is the owner.
typed/builtin//modules/api/engine/multiplayer/multiplayer/isRoomCreator
multiplayer.isRoomCreator(roomKey: string) -> boolean?
Whether this client created the given room — it was the FIRST peer to join it (race-free; the relay assigns it on join). In play mode the creator instantiates the scene's entities (synced) and every other joiner receives them from the relay snapshot, so the scene is never double-instantiated.
Parameters
roomKeystring— Fully-qualified room key ({worldGuid}/{profile}/{branch}/{mode}/{sceneGuid}).
Returns boolean? — True if this client created the room, false if it joined an existing one, nil if the relay hasn't reported a role yet (offline / not joined).
if multiplayer.isRoomCreator(key) ~= false then layers.load(scene) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/joinRoom
multiplayer.joinRoom(roomKey: string)
Join a relay room. Room keys are built as
{worldGuid}/{profile}/{branch}/{mode}/{sceneGuid} — five segments, the
{profile} one keeping a runtime peer (published content) and an
editor peer (live content) in separate rooms even when both are in
play mode. Rooms partition the relay's fan-out: only peers in the
same room receive each other's broadcasts. getRooms() reports the
keys this client is already in and roomFor(entity) the one an
entity broadcasts into, so a key can be read rather than rebuilt.
A relay that verifies its peers holds each connection to the world
it was admitted to: a key whose first segment names another world
is refused, and getDiagnostics().refusals counts the refusal and
lastRefusal names it. No-op when not connected or already joined.
Parameters
roomKeystring— Fully-qualified room key.
multiplayer.joinRoom(multiplayer.roomKeyFor(sceneGuid, "play"))
typed/builtin//modules/api/engine/multiplayer/multiplayer/leaveRoom
multiplayer.leaveRoom(roomKey: string)
Leave a relay room. The key is reported under
observe().withdrawnRooms until joinRoom names it again. No-op
when not connected or not joined.
Parameters
roomKeystring— Fully-qualified room key.
typed/builtin//modules/api/engine/multiplayer/multiplayer/loopback
multiplayer.loopback() -> { [string]: any }
Loopback testing harness. Returns a table with enable(),
disable(), flush(), receive() methods for testing sync
without a relay server.
Returns { [string]: any } — Loopback API table.
typed/builtin//modules/api/engine/multiplayer/multiplayer/observe
multiplayer.observe() -> ReplicationObservation
Report what this peer is replicating and why a property is not
arriving. Carries the rooms this client joined, one record per entity
with a sync id — its owner, the room it broadcasts into, how many
other peers share that room, and every REGISTERED synced component
with its declared property names, wire indices, public/private table
and dirty bits — the messages held for entities that have not arrived,
and the registry's totals. Every property carries notArriving: one
name from reasons, or nil when it is on its way. Answers in edit
mode as well as play mode, for what the relay carries in each: in
edit mode scene content is left out of the sync-id pass, so its
changes travel to the other clients with the source they are
written into and it reads entityNotSynced here. The document
describes the session as of the last frame: when no frame has
assembled one since the surface was last read, the call waits for the
next frame to assemble it, and a caller that cannot yield receives the
one published last.
Returns ReplicationObservation — The engine's current replication observation.
local o = multiplayer.observe()
print(#o.entities .. " entities, " .. o.totals.properties .. " synced properties")
typed/builtin//modules/api/engine/multiplayer/multiplayer/observeComponent
multiplayer.observeComponent(entityId: (string | entityRef), componentType: string) -> SyncedComponent?
The registered synced component of the named type on an entity's
record. Matches a fully-qualified type (@builtin::components.Model)
and the leaf name it ends in (Model) alike.
Parameters
entityId(string | entityRef)— Entity id or proxy.componentTypestring— Component type name or its leaf.
Returns SyncedComponent? — The registered component instance, or nil when none of that type is registered on the entity.
local c = multiplayer.observeComponent(player, "Health")
print(#c.properties .. " declared properties")
typed/builtin//modules/api/engine/multiplayer/multiplayer/observeEntity
multiplayer.observeEntity(entityId: (string | entityRef)) -> EntityReplication?
The replication record for one entity — its sync id, owner, room, and the synced components registered on it.
Parameters
entityId(string | entityRef)— Entity id or proxy.
Returns EntityReplication? — The entity's record, or nil when the engine holds no sync record for it.
local r = multiplayer.observeEntity(e)
for _, c in ipairs(r.components) do print(c.componentType) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/on
multiplayer.on(channel: string, callback: (number, ...any) -> ())
Subscribe to a custom message channel. The callback runs as
callback(fromPeerId, ...args) whenever another peer calls
multiplayer.send(channel, ...). Multiple callbacks per channel fire
in registration order.
Parameters
channelstring— Channel name to listen on.callback(number, ...any) -> ()—function(fromPeerId: number, ...)— the sender's peer id then the sent args.
typed/builtin//modules/api/engine/multiplayer/multiplayer/poseFrame
multiplayer.poseFrame(entityId: (string | entityRef)) -> string?
The entity a synced entity's pose is stated relative to: on the peer
that publishes it, the frame setPoseFrame named; on every other peer,
the frame entity it was drawn in on the last frame, the one its owner
stated its pose in. Nil for an entity stated in the world.
Parameters
entityId(string | entityRef)— The entity to ask about.
Returns string? — The frame entity's id, or nil.
if multiplayer.poseFrame(player) == deck.id then print("riding the deck") end
typed/builtin//modules/api/engine/multiplayer/multiplayer/recordFileWrite
multiplayer.recordFileWrite(path: string, before: string?, after: string?) -> boolean
Record a file write into the open operation. Undoing the
operation writes before back through the VFS (removing the file when
before is nil), which runs the owning asset type's onChange as the
original write did; redoing writes after. The path is resolved and held
to the rules vfs.write applies, so a sidecar (.meta, .refs), an
install's own entry or an asset root no script may write raises. A step's files
are put back all together or not at all: each file is checked (its asset
exists, and it holds what the step being reversed left in it) before any
is written and again immediately before it is written; when a check or a
write fails partway, the files the step already wrote go back to what
they held, and a notice names each file of the step and what happened to
it. Several writes of one path in an
operation undo to the first before. Records nothing and returns false
when no operation is open.
Parameters
pathstring— VFS path of the written file.beforestring(optional) — The file's contents before the write, nil when it did not exist.afterstring(optional) — The file's contents after the write, nil when the write removed it.
Returns boolean — True when the write was recorded.
local before = vfs.read(p); vfs.write(p, body); multiplayer.recordFileWrite(p, before, body)
typed/builtin//modules/api/engine/multiplayer/multiplayer/recordSpawn
multiplayer.recordSpawn(entityId: string)
Adopt an existing entity into the open operation as its spawn — for flows that create an entity before the operation opens (a drag preview adopted on drop). Undoing the operation despawns it.
Parameters
entityIdstring— Entity id to record as spawned by this operation.
multiplayer.recordSpawn(id)
typed/builtin//modules/api/engine/multiplayer/multiplayer/redo
multiplayer.redo() -> boolean
Redo this client's last undone operation.
Returns boolean — True if an operation was redone.
typed/builtin//modules/api/engine/multiplayer/multiplayer/releaseOwnership
multiplayer.releaseOwnership(entityId: (string | entityRef)?) -> boolean
Release ownership of an entity, leaving it unowned so another peer's claim takes it. Only the owner releases an entity.
Parameters
entityId(string | entityRef)(optional) — Entity id or proxy to release.
Returns boolean — True if ownership was released.
typed/builtin//modules/api/engine/multiplayer/multiplayer/roomFor
multiplayer.roomFor(entityId: (string | entityRef)) -> string?
The room key an entity's spawns and property deltas broadcast into:
the room of its observeEntity record as of the last frame, read from
the rooms the session publishes every frame, so a component can ask
every frame.
Parameters
entityId(string | entityRef)— Entity id or proxy.
Returns string? — The room key, or nil when the engine has established no scene context for the entity.
local key = multiplayer.roomFor(player)
if key then multiplayer.joinRoom(key) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/roomHeld
multiplayer.roomHeld(scene: string) -> boolean
Whether the room of a scene is held.
Parameters
scenestring— The scene guid.
Returns boolean — True while holdRoom holds it.
local held = multiplayer.roomHeld(layers.active.guid)
typed/builtin//modules/api/engine/multiplayer/multiplayer/roomKey
multiplayer.roomKey() -> string?
The relay room key of the root scene in the engine's current mode:
the room this client's entities for that scene broadcast into. nil
while no root scene is loaded.
Returns string? — The room key, or nil.
print(multiplayer.roomKey())
typed/builtin//modules/api/engine/multiplayer/multiplayer/roomKeyFor
multiplayer.roomKeyFor(sceneGuid: string, mode: string?) -> string
The relay room key of a scene in a mode: {worldGuid}/{profile}/{branch}/{mode}/{sceneGuid},
built the way the engine keys every room, so two clients on different
branches are in different rooms. The branch segment spells % as %25
and / as %2F.
Parameters
sceneGuidstring— The scene's guid.modestring(optional) —"edit"or"play"; the engine's current mode when omitted.
Returns string — The room key.
local key = multiplayer.roomKeyFor(layers.active.guid, "play")
typed/builtin//modules/api/engine/multiplayer/multiplayer/roomStartedAt
multiplayer.roomStartedAt(roomKey: string) -> number?
When the given room began, in seconds on this engine's clock (the
clock time.time() reads): the moment its first peer joined, as the relay
states it on this client's join, less half the link's round trip. Every
client of the room reads the same moment on its own clock. A room that
empties and is joined again begins again.
Parameters
roomKeystring— Fully-qualified room key ({worldGuid}/{profile}/{branch}/{mode}/{sceneGuid}).
Returns number? — The room's start in seconds, or nil while the relay has stated none (offline, not joined, or a relay that states no start).
local started = multiplayer.roomStartedAt(multiplayer.roomKey() or "")
typed/builtin//modules/api/engine/multiplayer/multiplayer/roomTime
multiplayer.roomTime() -> number
Seconds since the current room began, the same on every client of the
session. The clock follows the room of the root scene in the current mode
(multiplayer.roomKey()): it begins when the room's first peer joins and
begins again when the room empties and is joined again, and play and edit
are different rooms. Offline, in a world with no relay, with a relay that
states no start, or before this client's join is answered, it counts from
this engine's own start, recorded the first time it is read; once the
room's start arrives it counts from that. It runs in real seconds:
engine.paused and time.timeScale() do not reach it, so a reader that
holds still while paused keeps its own value while paused. Anything that
must agree across clients without sending a value every frame reads it: a
day cycle, a wind, a schedule.
Returns number — Seconds since the current room began.
local hour = (start + multiplayer.roomTime() * speed / 3600) % 24
typed/builtin//modules/api/engine/multiplayer/multiplayer/send
multiplayer.send(channel: string, ...: any?)
Broadcast a message on a named channel to every OTHER peer in the
room. The relay forwards it without reading its arguments and names this
peer as its sender; peers receive it via multiplayer.on. The relay holds
every peer to a message rate, a byte rate and a longest message: a message
past them reaches no peer, and multiplayer.getDiagnostics().refusals
counts the relay's answer. The arguments are delivered to listeners in order,
each one arriving as what it is, at the top level and at every depth
of a table:
nil, a boolean, a number and a string arrive as themselves.- A
vectorarrives as avector. - The proxy of a synced entity arrives as the receiving peer's proxy for that entity; the proxy of an entity no peer shares, as its id string.
- A synced component (its proxy, or the
componentRefenvelope naming it) arrives as that component on the receiving peer; the proxy of a component that holds no sync id, as the envelope{ __ref, entity, componentType }naming it. - A transform vector an entity hands out (
e.position,e.rotation,e.localScale, ...) arrives as the table of its components,{ x, y, z }or{ x, y, z, w }. - Every other table is data and arrives as a new table holding the same
keys, each key and each value carried by these same rules:
{ x = 5, kind = "coin" }arrives as{ x = 5, kind = "coin" },{ who = e, n = 1 }witht.whothe receiver's proxy fore,{ [5] = "a" }witht[5] == "a",{ 1, 2, label = "m" }with its list and itslabel,{ [true] = "yes" }witht[true] == "yes", and a list with anilin it with every entry after thenilat the index it was written under. A number inside a table arrives as that number,math.hugeand NaN included. - A value no peer can hold (a function, a thread, a buffer) arrives as
nil, and so does a table entry whose key is one; the sender logs a
warning naming the key's type.
The same rules carry the arguments of a
declare.syncedFunctionsmethod, the payload of aSyncevent and a synced table-valued field. No-op when not connected.
Parameters
channelstring— Channel name listeners subscribe to viamultiplayer.on....any(optional) — Zero or more values delivered to each listener after the sender's peer id.
typed/builtin//modules/api/engine/multiplayer/multiplayer/sessionClock
multiplayer.sessionClock() -> SessionClock
Read the session clock with what is known about it. time is
sessionTime(). synced is true once the relay has answered a clock
request, and stays true across a re-dial or a world swap while the clock
keeps counting this machine's clock. accuracyMs bounds how far time
lies from the relay's clock: half the round trip of the answer it
follows, the drift of this machine's clock since (0.1 ms a second) and
any correction still being worked off; nil while unsynced. Two peers
agree to within the sum of their accuracyMs. rttMs is that answer's
round trip and sampleAgeMs how long ago it arrived. wallOffsetMs is
time less this machine's wall clock: how far this machine's clock is
set from the session's.
Returns SessionClock — The session time and its accuracy.
local c = multiplayer.sessionClock(); if c.synced then print(c.accuracyMs) end
typed/builtin//modules/api/engine/multiplayer/multiplayer/sessionTime
multiplayer.sessionTime() -> number
The session time, in seconds since the Unix epoch: one timeline every
participant of a multiplayer session reads alike, placed on the relay's
clock with the round trip to it taken out. Use it wherever peers must act
in step (a shared countdown, a synchronised emote or animation, a high
five both sides start together, a looping effect in phase, a day/night
cycle, a beat): share a start time a little in the future (a Sync field,
an event or multiplayer.send) and let every peer compute
multiplayer.sessionTime() - start. It reads the moment it is called,
never decreases once synced, and corrects itself by running up to 10%
fast or slow rather than jumping (it jumps forward only when it trails
by more than a quarter second). Before the relay first answers, and with
no relay, it reads this machine's own wall clock; sessionClock() says
which and how accurate the reading is. ClipPlayer.startedAt takes such
a time to play a clip in phase on every peer.
Returns number — Seconds since the Unix epoch on the session timeline.
local startAt = multiplayer.sessionTime() + 0.5 -- share it, then on every peer:
local elapsed = multiplayer.sessionTime() - startAt
typed/builtin//modules/api/engine/multiplayer/multiplayer/setAvatarChannel
multiplayer.setAvatarChannel(entityId: (string | entityRef), channel: AvatarChannel?) -> boolean
Put a synced avatar on the avatar channel: the compact datagram
stream an avatar's motion and state travel on in place of generic
transform deltas. A frame is about 40 bytes, sent 20 times a second
while the avatar moves or changes (a walking avatar with changing
parameters costs under 1 KB/s) and once a second while it stands. Every
peer calls it for the avatar with the same channel (an avatar
component's start does). The peer that owns the avatar states it: its
root from the entity's transform, the velocity measured from it, and
what setAvatarState and avatarEmote state. Every other peer draws
it on the session clock, the root a short delay behind the newest frame
and interpolated through jitter and lost datagrams (smoothing tunes
it), and reads the rest with avatarState.
parameters declares the avatar's parameters in order, each
{ name, type } with type "bool" (1 bit), "int" (0 to 255) or
"float" (-1 to 1, 8 bits each), 256 bits in all at most; a peer reads a
parameter block only under the same declaration. rate (1 to 30,
default 20), parameterRate (at most 10, the default) and targetRate
(at most rate) say how many times a second it states the avatar,
changed parameters and changed IK targets. The relay takes the frames
from the avatar's owner alone, and forwards a peer every frame while
the avatar is within 10 m of an avatar that peer states (its own, or
any other it owns), about 10 a second further away inside its view and
about 2 a second behind it; a frame carrying a parameter block or an
emote a peer does not hold yet goes to that peer at once. nil closes
the channel and the entity goes back to generic transform sync.
Parameters
entityId(string | entityRef)— The avatar's synced root entity.channelAvatarChannel(optional) — The declared parameters and rates; nil closes the channel.
Returns boolean — False, opening nothing, for an entity that is not synced.
multiplayer.setAvatarChannel(self.entity, { parameters = {
{ name = "Smile", type = "float" }, { name = "Gesture", type = "int" },
{ name = "Seated", type = "bool" } } })
typed/builtin//modules/api/engine/multiplayer/multiplayer/setAvatarState
multiplayer.setAvatarState(entityId: (string | entityRef), state: AvatarStateInput) -> boolean
State what the avatar channel carries of an avatar this peer owns,
beside the root pose read from the entity's transform: any of gait
(the locomotion state the avatar's animator names, an integer 0 to
127), grounded, parameters (declared names to values: a boolean, an
integer 0 to 255 or a number -1 to 1 by declared type) and targets
(IK targets in the root's own frame by name: head, leftHand, rightHand,
hips, leftFoot, rightFoot; each { position, rotation? }, or false to
clear it). A field left out keeps its value. Call it whenever the state
changes: the channel sends a change at its rate and coalesces parameter
changes to its parameterRate. Raises for an entity with no channel
open, an undeclared parameter or a value of the wrong type, naming it.
Parameters
entityId(string | entityRef)— An avatar on the channel.stateAvatarStateInput— What to state.
Returns boolean — True once stated.
multiplayer.setAvatarState(self.entity, { gait = 1, grounded = true, parameters = { Smile = 0.6 } })
typed/builtin//modules/api/engine/multiplayer/multiplayer/setNeedsRebuild
multiplayer.setNeedsRebuild(scene: string, reason: string?, sinceMs: number?)
State the scene rebuild this client owes, for clients.<id>.content.needsRebuild
in the engine state. Called with only a scene it states that scene owes
none. Every client rebuilds from its own marks, so each states its own.
Parameters
scenestring— The scene guid.reasonstring(optional) — What changed.sinceMsnumber(optional) — When the change arrived, in milliseconds since the Unix epoch.
multiplayer.setNeedsRebuild(layers.active.guid, "PlayerSpawn moved", os.time() * 1000)
typed/builtin//modules/api/engine/multiplayer/multiplayer/setPoseFrame
multiplayer.setPoseFrame(entityId: (string | entityRef), frameEntityId: (string | entityRef)?) -> boolean
State a synced entity's pose relative to another synced entity it
rides (a character on a moving deck, a passenger in a car, a crate on a
ship), or in the world again with no frame. The peer that publishes the
entity states where it stands in the frame entity's space and how it is
turned there, and every other peer draws it where that peer draws the
frame entity, so the rider moves in step with the body it rides on
every screen however far behind each owner a peer draws the two. The
frame is the nearest synced entity at or above the one named (a
collider on a child of a synced ship names the ship). An entity whose
frame is not a synced entity in the world, or is the entity itself or
under it, is stated in the world. The name lasts until it is changed or
the entity leaves the world. A CharacterController names the moving
body it stands on by itself.
Parameters
entityId(string | entityRef)— The synced entity whose pose is stated.frameEntityId(string | entityRef)(optional) — The entity it rides; nil states it in the world.
Returns boolean — False, naming nothing, for an entity named as its own frame.
multiplayer.setPoseFrame(crate, ship)
multiplayer.setPoseFrame(crate, nil)
typed/builtin//modules/api/engine/multiplayer/multiplayer/setSmoothing
multiplayer.setSmoothing(entityId: (string | entityRef), values: SmoothingSettings?) -> boolean
Set how this peer draws one synced entity another peer simulates,
in place of the world's settings: any of enabled (false draws the
entity at the newest pose received), delay and extrapolation
(seconds, 0 to 2) and teleportSpeed (metres per second). A value left
out is the world's, and nil or an empty table hands the entity back to
them. The setting is this peer's own and lasts while the entity exists.
delay = 0 draws the newest pose delivered, which trails the owner by
the network transit; see smoothing for what is drawn and when.
smoothing(entityId) reads it back.
Parameters
entityId(string | entityRef)— Synced entity to set.valuesSmoothingSettings(optional) — The values to use for this entity; nil hands it back to the world's.
Returns boolean — False, setting nothing, for an entity that is not synced.
multiplayer.setSmoothing(projectile, { delay = 0.05, teleportSpeed = 600 })
multiplayer.setSmoothing(car, nil) -- back to the world's settings
typed/builtin//modules/api/engine/multiplayer/multiplayer/smoothing
multiplayer.smoothing(entityId: (string | entityRef)?) -> Smoothing
How this peer draws the remote entities other peers simulate. A
body another peer simulates is drawn a short delay behind the newest
pose received for it, interpolated between the poses either side of
that moment, so it moves smoothly whatever the frame rate on either
side and the jitter between them, and a pose that arrives after a newer
one never moves it back. When poses stop arriving it carries on along
its last motion for up to extrapolation seconds, then holds. When
they arrive again it catches up with them rather than jumping: each
frame it moves up to a quarter more (or less) than they move, plus
1 m/s, or a frame's share of the distance left over one second when
that is more, so a gap is made up within a couple of seconds. A body
carried past its poses slows onto them, and steps back only when it
stands farther ahead of them than they move in a second or they move
slower than 4/3 m/s. A distance
larger than teleportSpeed covers in a second is a cut. A step
faster than teleportSpeed (metres per second) is a teleport and is
drawn as a cut; a step across poses lost on the way, or across a stall
of the sender, is measured from the nearest point between where the
entity stood and where the motion before it carried it, so such a body
is caught up with. A stream whose sender
changes (an ownership
handover) starts over from its first pose. The owner's own view is
untouched. The moment drawn is the owner's now less the network transit
less delay; the transit stays in, so delay = 0 draws the newest pose
delivered and still trails the owner by it. A body that stops dead is
carried past its stop until the pose it rests at arrives, about 0.1 s
after it stops, when delay is shorter than that.
The settings come from the world's settings sync.interpolation
(boolean), sync.interpolation_delay, sync.extrapolation_limit
(seconds) and sync.teleport_speed, with this peer's setSmoothing
values for the entity in their place (overridden). For an entity
whose poses this peer receives, stream holds the poses buffered, how
far the newest stands ahead of the moment drawn (lag, seconds,
negative while extrapolating), whether the sender stamps its poses with
the session clock, the moment last drawn on the session clock and this
peer's clock it was drawn at (drawnAt), both in seconds so two reads
subtract into how far the drawn moment moved over how much time, how
far (correction, metres) the body is drawn from where its poses put
it while it catches up with them, and
the running counts of poses received, dropped as stale, stream
restarts and teleports. Reading asks the coming
frames to publish the streams, so the first read of one answers on the
next frame.
Parameters
entityId(string | entityRef)(optional) — Entity to read; omit for the world's settings.
Returns Smoothing — The settings in effect and, for a remote entity, its stream.
local s = multiplayer.smoothing(car); print(s.delay, s.stream and s.stream.lag)
settings.set("sync.interpolation_delay", "0.15") -- every remote entity, world-wide
typed/builtin//modules/api/engine/multiplayer/multiplayer/syncChildPose
multiplayer.syncChildPose(entityId: (string | entityRef), childName: string, on: boolean?) -> boolean
Name a direct child of a synced entity whose local pose (position
and rotation) travels with the entity. The peer that publishes the
entity states it whenever it changes, stamped on the session clock as
the entity's own pose is, and every other peer draws its own child of
that name there: a short delay behind the newest pose, interpolated on
the timeline the entity is drawn on (smoothing tunes both), so a
child turned at once is drawn turned within that delay and a peer that
joins later reads the pose it stands at. Every peer builds the entities
under a synced entity on its own, so each names the same children (a
component's start does), and a peer draws from its owner only the
children it names itself; an entity named before it is synced states
its children once it is. A child drawn this way reads true from
childPoseFromOwner, and what turns or moves it on its own leaves it
to its owner. A name lasts while the entity exists; on = false stops
naming it, and a child its owner stops naming is each peer's own to
pose again. Up to 16 children an entity, each name up to 64 bytes.
Parameters
entityId(string | entityRef)— The synced entity.childNamestring— The name of the direct child whose local pose travels.onboolean(optional) — false stops naming the child; true when left out.
Returns boolean — False, naming nothing, for an empty or longer name or a 17th child.
multiplayer.syncChildPose(self.entity, "turret")
typed/builtin//modules/api/engine/multiplayer/multiplayer/syncTotals
multiplayer.syncTotals() -> SyncTotals
What the sync registry holds across every entity: entities with a
registered synced component, component instances, declared properties,
declared functions, the component instances holding a dirty
property this tick, and the component instances whose ComponentAdd has
yet to go out (addsWaiting: queued for the next frame, or waiting for
their entity to be announced).
Returns SyncTotals — The registry totals.
print(multiplayer.syncTotals().properties .. " synced properties registered")
typed/builtin//modules/api/engine/multiplayer/multiplayer/undo
multiplayer.undo() -> boolean
Undo this client's last edit-mode operation.
Returns boolean — True if an operation was undone.
typed/builtin//modules/api/engine/notices/notices/post
notices.post(template: string, params: { [string]: any }?, opts: NoticeOpts?)
Post a notice. template is a fixed sentence used to collapse
repeats; put varying values in params. A param holding a picture — an
image value from mcp.image or a capture tool — is delivered as a
picture beside the notice's line rather than as text. opts.severity
defaults to "info"; opts.includeLocation attaches the emitting call
site. opts.actionable says whether the callers a notice is addressed
to are expected to act on it, rather than take it in as background; an
agent's event receiver starts an idle agent's turn for an actionable
notice and hands the rest to its context. opts.ephemeral posts a
reminder instead of a stored notice: an agent whose harness has an
ephemeral channel is shown it for a short window and it is never stored
in the agent's history, while an agent with no such channel gets it as a
normal background notice on its tool results, keyed as the stored notice
this code posts under the same template (or under opts.sameAs), so a
caller that mutes one is muted for both. opts.message is the catalog
key (<namespace>.<key>, see i18n.t) of the sentence a person reads the
notice as, in their language: the editor's notification bell shows it
(notices.text), read from the world's catalogs
(/zero/source/locales/<tag>/<namespace>.json) and then the built-in
library's, while an agent reads the template. A notice with no message
reads as its template everywhere. An ephemeral notice is identified by its
template, or by opts.sameAs when the post names one, and the code that
posted it: posting the same template, or another wording of the same
sameAs, again from the same code replaces the entry, so the template is
a fixed sentence and every varying value goes in params or into a
wording posted with sameAs.
opts.subject names the one thing a notice is about when the same code
posts the same sentence about several (a scene, a file, a job): the
notices about two subjects are two notices, each collapsing its own
repeats, and notices.withdraw given the subject takes that subject's
alone.
Parameters
templatestring— Fixed sentence identifying the notice.params{ [string]: any }(optional) — Optional table of named values rendered alongside the template; a picture in it arrives as a picture.optsNoticeOpts(optional) — Optional table: message (a catalog key), severity ("info" | "warn" | "error"), includeLocation (boolean), audience ("" | { string }?). Who sees the notice: "" addresses every caller; a list addresses those callers only, each entry an agent's name (as theagenttoolbox'srosterlists it) or a caller key<kind>:<id>such as "agent:". Defaults to the caller whose code is running, or every caller when none is. A notice reaches the agents on this engine: an entry naming no agent on this world's roster, an entry naming an agent the roster lists on another engine of the world, or an empty list, raises an error. actionable(boolean) states whether the callers it is addressed to are expected to act on it; omitted, a notice addressed to particular callers (the default audience included) is actionable, and one for every caller is background.ephemeral(boolean) posts a reminder: it is shown to an agent whose harness has an ephemeral channel for a short window and never stored in its history. For an ephemeral post the audience is not checked against the roster: a list entry naming no agent on it is kept for a key nobody reads, a bare agent name in a list is read asagent:<name>, and a single string audience is used as given;message,severity,includeLocationandactionablehave no effect on it.sticky(boolean, ephemeral only) keeps it visible on every read until it is replaced, withdrawn or expires 120 seconds after its last post; posting it again with identical text refreshes that lifetime.ttl(seconds, at most 600, ephemeral and sticky only) raises or lowers that lifetime.renew(boolean, ephemeral only) shows an entry again that a poster posts with identical text.sticky,ttlandrenewhave no effect on a post that is not ephemeral.subject(a non-empty string) names what the notice is about, keying it apart from the same template about another subject; an ephemeral post is identified by its template (or itssameAs) and the code that posted it, andsubjecthas no effect on it.sameAs(string) is the template of a notice this code posts that this post is another wording of: the same condition with its values written into the sentence, or a shorter wording an ephemeral post carries. The post is keyed as that notice (an ephemeral one is served under its key to an agent with no ephemeral channel), so a caller that muted it is muted for this post andnotices.withdraw(sameAs)takes both; omitted, the post's own template.
notices.post("wave complete", { wave = 3 })
notices.post("save slot corrupted, using defaults", { slot = id }, { severity = "warn" })
notices.post("bake finished", { shot = mcp.image("/source/tmp/bake.png") })
notices.post("boss defeated", nil, { audience = "*" })
notices.post("build ready for review", nil, { audience = { "terrain" }, actionable = true })
notices.post("the build is not published", { uncommitted = 4 }, { ephemeral = true, audience = "*" })
notices.post("the lift is out of order", nil, { ephemeral = true, sticky = true, ttl = 300, audience = { "terrain" } })
notices.post("The lift is out of order.", nil, { ephemeral = true, audience = "*", sameAs = "The lift is out of order: riders take the stairs until the repair crew reports it fixed." })
notices.post("wave complete", { wave = 3 }, { message = "hud.wave_complete" }) -- /zero/source/locales/<tag>/hud.json
notices.post("the level was rebuilt", { level = "north" }, { subject = "north" })
typed/builtin//modules/api/engine/notices/notices/text
notices.text(row: { template: string, message: string? }) -> any
The sentence a stored notice reads as for a person: its message in
the reader's language, read from the world's catalogs and then the
built-in library's, or its template when it names none. row is a notice
as the notices toolbox's list tool states it (template, message).
The value follows the language on screen, like i18n.text.
Parameters
row{ template: string, message: string? }— A notice row:{ template, message? }.
Returns any — The sentence, as an i18n.text value, or the template as a string.
for _, row in tools.use("notices", "list").pending do print(tostring(notices.text(row))) end
typed/builtin//modules/api/engine/notices/notices/withdraw
notices.withdraw(template: string, opts: { replacing: boolean?, subject: string? }?) -> number
Withdraw the notices this code posted under template that are still
stored, whoever they are addressed to, because what they state has
stopped being true: a caller that has not read one yet would be told
something that no longer holds. A notice is keyed by its template and by
the code that posted it, so a call reaches only notices posted from the
same place. A later notices.post under the template queues again, and
reaches the callers that muted it too: their mute acknowledged what the
withdrawn notices stated.
opts.replacing withdraws them to make way for a post of the same
condition with new values (a count that moved, a later reading): the
stale values go, and every caller that muted the template stays muted
for the post that follows.
opts.subject withdraws the notices posted under template about that
subject (opts.subject of notices.post) and leaves the same sentence
about every other subject; without it, the notices posted about no
subject are withdrawn.
Ephemeral notices this chunk posted under template, or as another
wording of it (opts.sameAs of notices.post), are withdrawn too when
no subject is named, as are stored notices posted as another wording of
it; a failure to reach the ephemeral ones is logged, and the stored
notices are withdrawn all the same.
Parameters
templatestring— The template the notices were posted under.opts{ replacing: boolean?, subject: string? }(optional) — Optional table: replacing (boolean), true when a post of the same condition follows; subject (string), the subject the notices were posted about.
Returns number — How many emissions the withdrawn notices held.
notices.withdraw("save slot corrupted, using defaults")
notices.withdraw("3 files unsaved", { replacing = true }) -- a post with the new count follows
notices.withdraw("the level was rebuilt", { subject = "north" }) -- the notices about "south" stay
typed/builtin//modules/api/engine/packages/packages/list
packages.list() -> { PackageEntry }
List every registered package across scopes.
Returns { PackageEntry } — Array of package entries.
for _, p in ipairs(packages.list()) do print(p.name, p.scope) end
typed/builtin//modules/api/engine/packages/packages/lookup
packages.lookup(name_or_scope: string, name: string?) -> PackageEntry?
Look up a single package by name (any scope) or by exact
(scope, name).
Parameters
name_or_scopestring— Package name, or scope if a second arg is given.namestring(optional) — Package name when the first arg is a scope.
Returns PackageEntry? — Package entry or nil.
local p = packages.lookup("@builtin", "audio")
typed/builtin//modules/api/engine/physics/P/addCollider
P.addCollider(entityId: string | entityRef, component: string, config: table?)
Add a collider component to an entity, naming the shape you want.
Parameters
entityIdstring | entityRef— Target entity id.componentstring— One ofPhysics.COLLIDER_COMPONENTS.configtable(optional) — The component's own fields, e.g.{ radius = 0.5 }for a sphere.
Physics.addCollider(id, "SphereCollider", { radius = 0.5 })
typed/builtin//modules/api/engine/physics/P/addConstraint
P.addConstraint(entityId: string | entityRef, opts: table?)
Add a transform constraint to an entity.
Parameters
entityIdstring | entityRef— Target entity id.optstable(optional) — Optional constraint description (targetEntityId, position, rotation, scale, lookAt, targetPosition, axes, weight).
Physics.addConstraint(id, { targetEntityId = parent, position = true })
typed/builtin//modules/api/engine/physics/P/addJoint
P.addJoint(entityIdA: string | entityRef, entityIdB: string | entityRef, opts: table?) -> any
Add a Joint component connecting two entities. Accepts either
vec3-style anchor inputs (localAnchor = {x,y,z}) or pre-split
scalar keys (localAnchorX/Y/Z); every other key is a Joint field or
name / enabled, which every component takes, and any other key
raises, naming it.
A body takes any number of joints: on an entity that already carries a
Joint the new one is added under name (or, without one, the first of
joint2, joint3, ... free on it), and each is its own solver joint.
An end entity that is no body itself joins the nearest body above it at
its own position and orientation, so a marker under a beam's end pins
the beam there: a truss is beams joined through end markers.
Parameters
entityIdAstring | entityRef— Entity that hosts the Joint component.entityIdBstring | entityRef— Connected entity.optstable(optional) — Optional joint description:kind(fixed, hinge, ball, prismatic, spring, rope, generic, rail),localAnchor,remoteAnchor,axis,remoteAxis,collideConnected, the limits (limitMin/limitMaxfor a hinge in degrees or a prismatic in metres,swingLimit/twistLimitfor a ball joint in degrees,axisLimitson any axis), the motor (motorMode"velocity" | "position",motorVelocity,motorTarget,motorStiffness,motorDamping,motorMaxForce,motorModel,axisMotorson any axis),lockedAxesfor a generic joint,stiffness,damping,restLength,maxDistance, the yield (yieldForcea rope pays out or a prismatic slides at,yieldTorquea hinge turns at, each holding again below it;reelSpeed, how fast a yielding rope winds in to a shortermaxDistance),breakForce,breakTorque,region,remoteRegion,articulated(a link of an articulation, solved in reduced coordinates: chains that do not stretch, limits that hold under load); a rail'spath(points in entity B's local space, or a spline),closed,ends("capped" | "open"),curve("smooth" | "linear"),toleranceandfriction. An articulated joint (articulated = true) makes entity A's body a link hanging from entity B's (or B's from A's, when A already hangs from a link or is not dynamic): the bodies articulated joints join form a tree, solved in reduced coordinates, so a chain does not stretch, every limit holds under load and a motorized arm tracks its targets. Build the tree from its root out or in any order; a joint that would close a loop is not built and names the loop in the Joint'serrors().Physics.articulationreads the tree. A rail holds the point atlocalAnchoron entity A topathon entity B: free to run along it under gravity and forces, held across it, read throughPhysics.jointState(progress,speed,onPath,atEnd) andPhysics.jointReaction(the force holding it,localForcealong the path, toward the bend's centre and across). Either end may be a soft body (an entity with aSoftBodycomponent):regionanchors this end on a region of entity A's soft body andremoteRegionthe other end on a region of B's, each asPhysics.softRegiontakes it ({ box = { min, max } }or{ nearest = point }); an end with no region is anchored on the soft body as a whole. The anchor of a region end is measured from the centre of its particles.
Returns any — The new Joint component (its live proxy), which every joint read and Physics.removeJoint take. A description the Joint refuses, of any kind (a rope with no maxDistance, a rail path that cannot be held or a rail given a spring's stiffness, a yield out of range or on a kind that cannot hold it), raises an error naming why, and the refused Joint is taken off the entity.
Physics.addJoint(a, b, { kind = "fixed" })
Physics.addJoint(a, b, { kind = "hinge", axis = {x=0,y=1,z=0} })
Physics.addJoint(door, frame, { kind = "hinge", axis = {0,1,0}, limitMin = 0, limitMax = 110 })
Physics.addJoint(arm, base, { kind = "hinge", axis = {0,0,1}, motorMode = "position", motorTarget = 90, motorMaxForce = 500 })
Physics.addJoint(forearm, upperArm, { kind = "ball", swingLimit = 45, twistLimit = 20, collideConnected = false })
Physics.addJoint(piston, cylinder, { kind = "prismatic", axis = {0,1,0}, limitMin = 0, limitMax = 0.5 })
Physics.addJoint(seat, rail, { kind = "generic", lockedAxes = {"linY", "linZ", "angX", "angY", "angZ"}, axisLimits = { linX = {-0.2, 0.2} } })
Physics.addJoint(a, b, { kind = "rope", maxDistance = 8 })
Physics.addJoint(hook, load, { kind = "rope", maxDistance = 4, yieldForce = 3000 })
Physics.addJoint(car, track, { kind = "rail", path = trackPoints, closed = true, collideConnected = false })
Physics.addJoint(trolley, cable, { kind = "rail", path = { {0, 12, 0}, {15, 6, 0}, {30, 3, 0} }, localAnchor = {0, 1, 0}, friction = 0.02 })
Physics.addJoint(door, frame, { kind = "rail", path = arcPoints, motorMode = "position", motorTarget = 1.2, motorMaxForce = 300 })
Physics.addJoint(a, b, { kind = "fixed", breakForce = 1200, breakTorque = 800 })
Physics.addJoint(bag, hook, { kind = "ball", region = { nearest = {0, 0.5, 0} } })
Physics.addJoint(jellyA, jellyB, { kind = "fixed", region = { box = { min = {0.4, -0.5, -0.5}, max = {0.5, 0.5, 0.5} } }, remoteRegion = { box = { min = {-0.5, -0.5, -0.5}, max = {-0.4, 0.5, 0.5} } } })
local grab = Physics.addJoint(hand, crate, { kind = "fixed", breakForce = 2000 }); Physics.removeJoint(grab)
for i = 2, #links do Physics.addJoint(links[i], links[i - 1], { kind = "ball", articulated = true, swingLimit = 30, collideConnected = false }) end
Physics.addJoint(forearm, upperArm, { kind = "hinge", axis = {0, 0, 1}, articulated = true, limitMin = 0, limitMax = 140, motorMode = "position", motorTarget = 45, motorMaxForce = 400 })
typed/builtin//modules/api/engine/physics/P/addVelocity
P.addVelocity(a: string | entityRef | number | vec3, b: (number | vec3)?, c: number?, d: number?)
Add to the linear velocity of an entity. Same call shapes as
setVelocity.
Parameters
astring | entityRef | number | vec3— dx, a{x, y, z}delta vector, or the target (explicit): the body's entity id or proxy, or an entity a collider of it was authored on (a hit'sentityIdorbody, an overlap's id); static world geometry such as the ground, like a static body, stays where it stands.b(number | vec3)(optional) — dy, dx, or the delta vector depending on call form.cnumber(optional) — dz or dy depending on call form.dnumber(optional) — Optional dz when targeting an explicit entity.
Physics.addVelocity(0, 5, 0)
Physics.addVelocity(entityId, 0, 5, 0)
Physics.addVelocity(entityId, {x=0, y=5, z=0})
typed/builtin//modules/api/engine/physics/P/addWheelCollider
P.addWheelCollider(entityId: string | entityRef, config: table?)
Add a WheelCollider to an entity. The entity must be a child (or descendant) of a rigid body — the system walks up the hierarchy to find the Physics component. Every wheel under one body is a wheel of that body's ray-cast vehicle.
Parameters
entityIdstring | entityRef— Target entity id.configtable(optional) — Optional wheel configuration (radius?,suspensionDistance?,springRate?,damperRate?,targetPosition?,maxSuspensionForce?,bumpStopRecovery?,bumpStopSpeed?,groundAngle?,motorTorque?,maxDriveSpeed?,brakeTorque?,steerAngle?,forwardFriction?,sidewaysFriction?,frictionSlip?,sideFrictionStiffness?,corneringStiffness?,forwardFrictionStiffness?,slideGrip?,slideSlip?,loadSensitivity?,referenceLoad?,inertia?,rollingResistance?,width?,is2D?,visual?,solid?,mass?,breakLoad?,attached?). Asolidwheel is a volume other bodies strike; abreakLoadabove 0 lets it come off as a body of its own (Physics.detachWheeltakes it off on command). Aninertiaabove 0 makes the wheel spin on its own (wheelspin, lock-up, drift), andmaxDriveSpeed(m/s at the tread) is the fastest its drive spins it; the tyre grip curve fields shape its grip over slip and load (Physics.tyreCurvemeasures it,@builtin::modules.tyresholds presets).
Physics.addWheelCollider(id, { radius = 0.35, motorTorque = 500 })
typed/builtin//modules/api/engine/physics/P/advance
P.advance(asked: number | PhysicsAdvanceOptions) -> PhysicsAdvance
Advance the physics simulation by exactly steps fixed steps (or the
simulated seconds the nearest whole number of steps covers), as fast as
the machine computes them, and return once the last one has run. This is
how to measure a physics outcome over many simulated seconds (an
acceleration run, a braking distance, a settle time, a lap, a bridge
under load, a replay of recorded inputs) in less wall time than the
seconds it covers, and how to run a fixed-step simulation exactly N steps
from a paused start and read the state after each (Physics.onAfterStep).
Every step is the step real-time play runs, at the same dt: the step
hooks, the forces bodies hold, contact and impact events, joint breaks and
fixedUpdate all run once per step, so from the same state a run driven
from the step hooks and fixedUpdate reaches the state the same steps
reach at wall-clock rate; only the wall time differs. It runs from a paused
clock (engine.paused = true), which stays paused afterwards, or a running
one; while it runs the frame clock adds no steps of its own, and per-frame
code (update, task.wait, animation) keeps the frame clock, so drive a
measured run from the step hooks or fixedUpdate. Each frame runs as many
steps as fit in frameBudgetMs of wall time (default 100, 1 to 1000), so
the engine keeps drawing and answering while a long advance runs. It ends
with an error when the engine leaves the mode it started in. Run it in
play for a measurement, so leaving play puts the scene back. The call
waits: run it where code can yield (a tool call, a task), wrapping it in
task.spawn from a callback that cannot. One advance runs at a time.
Parameters
askednumber | PhysicsAdvanceOptions— A number of steps (1 to 1000000), or{ steps = n }/{ seconds = s }, either with an optionalframeBudgetMs.
Returns PhysicsAdvance — What ran: steps, firstStep, lastStep, simulatedSeconds, wallSeconds, steppingSeconds, frames, tickRate.
engine.paused = true; local ran = Physics.advance(180); print(ran.lastStep, entity(crate).position.y)
local ran = Physics.advance({ seconds = 10 }); print(`{ran.simulatedSeconds} s simulated in {ran.wallSeconds} s`)
typed/builtin//modules/api/engine/physics/P/airDensity
P.airDensity(density: number?) -> number
The air's density, kg/m³: 1.225 by default (sea level, 15 °C). It
sets how hard the air drags on and lifts every body carrying
FluidForces or a LiftSurface. With density it sets it first:
thinner air high up or on another world, 0 for none.
Parameters
densitynumber(optional) — The density to set, 0 or more.
Returns number — The air's density now.
Physics.airDensity(0.02) -- the thin air of Mars
typed/builtin//modules/api/engine/physics/P/applyForce
P.applyForce(entityIdOrForce: string | entityRef | vec3, force: vec3?, region: PhysicsSoftRegion?)
Apply a force to an entity's rigid or soft body, in newtons, for a
span of simulated time, whatever the frame rate and the physics tick rate
are. Called from code that runs inside a physics step
(Physics.onBeforeStep / onAfterStep, a contact listener, fixedUpdate)
it acts on the next physics step alone: call it once per step for a
continuous force.
Called anywhere else (update, a task, a tool call) it acts over the
simulated time the next frame advances, shared across however many steps
that frame runs: call it once per frame for a continuous force. Either
way a continuous force integrates to force times elapsed time, so a body
pushed up with its own weight floats. A force that depends on where the
body is or how fast it moves (a spring, a field, a controller) belongs in
Physics.onBeforeStep, which reads the state the step starts from; a
pull that drives an orbit or an oscillation keeps its energy given there
as the momentum it makes over the step, Physics.applyImpulse(id, force * dt).
With one argument the
script-context entity is targeted; with two args the explicit entity
id wins. A soft body takes the force spread over its particles by mass,
so it accelerates as a whole the way a rigid body of its mass would;
region puts it on part of the body instead ({ box = { min, max } }
or { nearest = point }, as Physics.softRegion takes it), which
accelerates that part alike and leaves the rest to follow.
Parameters
entityIdOrForcestring | entityRef | vec3— A force vector for the script-context entity, OR (paired withforce) the body's entity id or proxy, or an entity a collider of it was authored on (a hit'sentityIdorbody, an overlap's id); static world geometry such as the ground, like a static body, stays where it stands.forcevec3(optional) — Optional force vector when targeting an explicit entity.regionPhysicsSoftRegion(optional) — Part of a soft body to push, asPhysics.softRegiontakes it; omit for the whole body.
Physics.applyForce({x=0, y=10, z=0})
Physics.applyForce(entityId, {x=0, y=10, z=0})
Physics.applyForce(cloth, {x=0, y=0, z=4}, { box = { min = {-0.5, -1, 0.4}, max = {0.5, 1, 0.5} } })
typed/builtin//modules/api/engine/physics/P/applyForceAtPoint
P.applyForceAtPoint(entityId: string | entityRef, force: vec3, point: vec3, opts: PhysicsPushOptions?)
Apply a force at a specific world-space point, over the span
Physics.applyForce states: from Physics.onBeforeStep (or
fixedUpdate) on the next step alone, from anywhere else over the next
frame's simulated time. On a rigid body it generates the matching torque from the lever
arm. On a soft body it pushes the particles around the point, weighted
from the whole at the point to nothing at opts.radius (by default
twice the spacing of the body's particles), so the body gives way there
first. It always reaches at least the four particles nearest the point,
the smallest patch a body can dent, so a radius finer than the particles
are spaced spreads over that patch.
Parameters
entityIdstring | entityRef— The target: the body's entity id or proxy, or an entity a collider of it was authored on (a hit'sentityIdorbody, an overlap's id); static world geometry such as the ground, like a static body, stays where it stands.forcevec3— Force vector, in newtons.pointvec3— World-space application point.optsPhysicsPushOptions(optional) —{ radius: number? }: how far into a soft body the force reaches, in metres.
Physics.applyForceAtPoint(id, {x=0,y=10,z=0}, {x=1,y=0,z=0})
Physics.applyForceAtPoint(jelly, {x=0,y=-40,z=0}, {x=0,y=1.5,z=0}, { radius = 0.3 })
typed/builtin//modules/api/engine/physics/P/applyImpulse
P.applyImpulse(entityIdOrImpulse: string | entityRef | vec3, impulse: vec3?, region: PhysicsSoftRegion?)
Apply an instantaneous impulse (one-shot velocity change). With
one argument the script-context entity is targeted; with two args
the explicit entity id wins. A soft body takes the impulse spread over
its particles by mass, so it moves off as a whole the way a rigid body
of its mass would; region puts it on part of the body instead (as
Physics.softRegion takes it), which sets that part moving and leaves
the rest to follow. applyImpulseAtPoint aims one at a point.
Parameters
entityIdOrImpulsestring | entityRef | vec3— An impulse vector for the script-context entity, OR (withimpulse) the body's entity id or proxy, or an entity a collider of it was authored on (a hit'sentityIdorbody, an overlap's id); static world geometry such as the ground, like a static body, stays where it stands.impulsevec3(optional) — Optional impulse vector when targeting an explicit entity.regionPhysicsSoftRegion(optional) — Part of a soft body to push, asPhysics.softRegiontakes it; omit for the whole body.
Physics.applyImpulse({x=0, y=5, z=0})
Physics.applyImpulse(entityId, {x=0, y=5, z=0})
Physics.applyImpulse(jelly, {x=0, y=-2, z=0}, { box = { min = {-0.5, 0.4, -0.5}, max = {0.5, 0.5, 0.5} } })
typed/builtin//modules/api/engine/physics/P/applyImpulseAtPoint
P.applyImpulseAtPoint(entityId: string | entityRef, impulse: vec3, point: vec3, opts: PhysicsPushOptions?)
Apply an instantaneous impulse at a world-space point: a hit, a kick,
a crash. On a rigid body it changes the body's velocity and spin as an
impulse at that point of it would. On a soft body it pushes the particles
around the point, weighted from the whole at the point to nothing at
opts.radius (by default twice the spacing of the body's particles), so
the body dents there and the rest of it is carried along through its
elastic elements. It always reaches at least the four particles nearest
the point, the smallest patch a body can dent, so a radius finer than
the particles are spaced spreads over that patch; a finer dent takes a
finer body (a higher resolution). The impulse is the momentum the body
gains, in newton-seconds, wherever it lands.
Parameters
entityIdstring | entityRef— The target: the body's entity id or proxy, or an entity a collider of it was authored on (a hit'sentityIdorbody, an overlap's id); static world geometry such as the ground, like a static body, stays where it stands.impulsevec3— The impulse, in newton-seconds.pointvec3— Where it lands, in world space: a contact point.optsPhysicsPushOptions(optional) —{ radius: number? }: how far into a soft body the impulse reaches, in metres.
Physics.applyImpulseAtPoint(crate, {x=0, y=0, z=-30}, hit.point)
local hit = Physics.raycast(muzzle, aim, 100); if hit then Physics.applyImpulseAtPoint(hit.body, {x=0, y=0, z=-30}, hit.point) end
local contact = Physics.contacts(shell)[1]; if contact then Physics.applyImpulseAtPoint(shell, {x=-60, y=0, z=0}, contact.points[1].point, { radius = 0.4 }) end
typed/builtin//modules/api/engine/physics/P/applyRadialImpulse
P.applyRadialImpulse(entityId: string | entityRef, center: vec3, magnitude: number, opts: PhysicsPushOptions?)
Push a body straight away from a world point, like a blast: the
push is magnitude newton-seconds at the centre, weighted to nothing at
opts.radius (omitted, it reaches any distance at full strength). A
rigid body is pushed by the distance to its centre of mass; a soft body
particle by particle, each away from the centre by its own distance, so
a blast beside a balloon pushes it off and one inside a body spreads it
out. Each moves off at the speed magnitude gives a body of its mass.
Parameters
entityIdstring | entityRef— The target: the body's entity id or proxy, or an entity a collider of it was authored on (a hit'sentityIdorbody, an overlap's id); static world geometry such as the ground, like a static body, stays where it stands.centervec3— The blast's world position.magnitudenumber— The impulse at the centre, in newton-seconds.optsPhysicsPushOptions(optional) —{ radius: number? }: how far the push reaches, in metres.
Physics.applyRadialImpulse(balloon, {x=0, y=1, z=-1}, 8, { radius = 3 })
for _, id in pile do Physics.applyRadialImpulse(id, blast, 20, { radius = 4 }) end
typed/builtin//modules/api/engine/physics/P/applyTorque
P.applyTorque(entityIdOrTorque: string | entityRef | vec3, torque: vec3?)
Apply a torque to an entity's rigid body, over the span
Physics.applyForce states: from Physics.onBeforeStep (or
fixedUpdate) on the next step alone, from anywhere else over the next
frame's simulated time. With one argument
the script-context entity is targeted; with two args the explicit
entity id wins.
Parameters
entityIdOrTorquestring | entityRef | vec3— A torque vector for the script-context entity, OR (withtorque) the body's entity id or proxy, or an entity a collider of it was authored on (a hit'sentityIdorbody, an overlap's id); static world geometry such as the ground, like a static body, stays where it stands.torquevec3(optional) — Optional torque vector when targeting an explicit entity.
Physics.applyTorque({x=0, y=1, z=0})
Physics.applyTorque(entityId, {x=0, y=1, z=0})
typed/builtin//modules/api/engine/physics/P/articulation
P.articulation(entityId: string | entityRef) -> table?
The articulation a body is a link of: the tree of bodies its
articulated joints (articulated = true) join, solved in reduced
coordinates. Its links are listed root first, each parent before its
children.
Parameters
entityIdstring | entityRef— An entity whose body is a link, or its proxy.
Returns table? — { root, links, parents, linkDofs, dofs, rootFree }, or nil when the body is a link of no articulation: links holds each link's entity id, parents[i] the index in links of link i's parent (0 for the root), linkDofs[i] how many coordinates link i's joint leaves free (a hinge 1, a ball 3, the root 6 when it moves freely and 0 when it stands fixed), dofs their sum, root the root's entity id and rootFree whether it moves.
local a = Physics.articulation(hand); print(#a.links, a.dofs)
typed/builtin//modules/api/engine/physics/P/attachSoftRegion
P.attachSoftRegion(softId: string | entityRef, targetId: string | entityRef, region: PhysicsSoftRegion?) -> number
Hold a region of a soft body to a rigid body, two-way: the region
follows the rigid body wherever it goes, and the rigid body carries the
region's weight and pull. Each particle in the region is tied to the
point of the rigid body it stands at when the attachment is made. The
attachment is an entry of the soft body's SoftBody component
(attachments), so it is saved with the scene, reaches every peer, and is
made again on a rebuilt body; it is released when either side is
removed. Its load reads back from Physics.softBodyState(softId).attachments.
A cloth's edge on a flagpole, a soft panel on a car's chassis, a jelly
glued to a moving platform. Where the rigid body's colliders touch the
soft body (a shell resting on its chassis), the contact and the hold push
on each other: keep them clear, or Physics.ignoreCollision(softId, targetId).
Parameters
softIdstring | entityRef— The soft body's entity (it carries aSoftBodycomponent).targetIdstring | entityRef— The rigid body's entity (it carriesPhysics), by id, name or proxy.regionPhysicsSoftRegion(optional) — Which particles to hold, asPhysics.softRegiontakes it:{ box = { min, max } },{ nearest = point }, withspace = "world"for world coordinates; nil holds the whole body.
Returns number — The attachment's index in the component's attachments.
Physics.attachSoftRegion(flag, pole, { box = { min = {-0.5, -1, -1}, max = {-0.45, 1, 1} } })
Physics.attachSoftRegion(shell, chassis, { box = { min = {-0.5, -0.5, -0.5}, max = {0.5, -0.4, 0.5} } })
typed/builtin//modules/api/engine/physics/P/attachWheel
P.attachWheel(entityId: string | entityRef) -> boolean
Put a wheel that came off back on its vehicle, at its mount: its own body goes, and the vehicle drives on it again from the next physics tick.
Parameters
entityIdstring | entityRef— The wheel entity (it carries the WheelCollider).
Returns boolean — True when the entity carries a WheelCollider.
Physics.attachWheel(wheel.id)
typed/builtin//modules/api/engine/physics/P/bodyOf
P.bodyOf(entityId: string | entityRef) -> PhysicsBodyOf?
The rigid body an entity stands for, or rides through the collider
authored on it: a ray or shape cast hit names the entity the collider was
authored on, and a collider on a child entity composes onto the nearest
ancestor's body, so this is the read that names the body to push, weigh
or follow. mass is the mass the solver holds, the one derived from the
colliders included, in kilograms.
Parameters
entityIdstring | entityRef— A body, or the entity a collider was authored on.
Returns PhysicsBodyOf? — A PhysicsBodyOf { entity, bodyType, mass }, or nil when the entity rides no rigid body (a world-space collider, an entity with none).
local hit = Physics.raycast(origin, dir, 20); local body = hit and Physics.bodyOf(hit.entityId)
local b = Physics.bodyOf(part); if b and b.bodyType == "dynamic" then Physics.applyImpulse(b.entity, { x = 0, y = 2 * b.mass, z = 0 }) end
typed/builtin//modules/api/engine/physics/P/bodyState
P.bodyState(entityId: string | entityRef) -> PhysicsBodyState?
Everything the solver holds for one body — its type, mass, centre of
mass, inertia, gravity scale, damping, lock flags, CCD, collision groups,
sleep state, velocities, the force and torque queued for the next step,
its colliders and whether it collides at all (collides, with
collisionDetail naming why a body holding no collider meets nothing),
contacts, joints and transform constraints, and why it is not moving.
The entry Physics.observe(entityId) carries, read without
the world's accounting, so it costs what the one body costs.
Parameters
entityIdstring | entityRef— Entity id or proxy.
Returns PhysicsBodyState? — A PhysicsBodyState (with exists = false for an entity that carries no rigid body, and waitingFor naming what its collider needs while that collider cannot be built), or nil when nothing in the scene answers to that id.
local b = Physics.bodyState(id); print(b.bodyType, b.mass, b.stillness)
local b = Physics.bodyState(id); if not b.exists then print(b.waitingFor or "no body was built") end
local b = Physics.bodyState(id); if not b.collides then print(b.collisionDetail) end
typed/builtin//modules/api/engine/physics/P/boxCast
P.boxCast(origin: vec3, halfExtents: vec3, direction: vec3, maxDistance: number?, exclude: (string | {string})?, options: PhysicsCastOptions?) -> PhysicsHit?
Cast a box along a direction and return the first hit.
A trigger (isTrigger) holds nothing up, so the sweep passes through it.
Many casts a frame: Physics.castMany answers them all in one call.
Parameters
originvec3— Box center at the start of the cast.halfExtentsvec3— Half the size of the box on each axis.directionvec3— Cast direction, of any length: the engine normalises it, somaxDistanceanddistanceare world units.maxDistancenumber(optional) — Optional distance limit.exclude(string | {string})(optional) — Optional entity id, or array of entity ids, to exclude from hits. Applied while sweeping rather than to the answer, so a cast that starts inside an excluded collider reports what is behind it.optionsPhysicsCastOptions(optional) — OptionalPhysicsCastOptions:{ mover = entity }casts for the entity the cast moves (a character controller, or anything moved by casts), so it meets colliders as that entity's body does: a one-way collider (oneWay) answers only on the face its direction points out of, to a cast that starts outside it; a collider whosecontactTagthe contact filter answers "ignore" or "sensor" with a tag of the mover's own colliders is passed; and the one-way collidersPhysics.passThrough(mover)drops the mover through are passed until it is clear of them.
Returns PhysicsHit? — Hit table { entityId, body, bodyType, point, normal, distance, startedInside, softBody?, surface?, surfaceVelocity? }, or nil if nothing hit. body is the id of the entity standing for the body the collider belongs to: the body's own entity when the collider was authored on a child entity (a part of a vehicle or an assembled prop, which composes onto its ancestor's body), and the collider's own entity for static world geometry that rides no body, such as the ground. bodyType is that body's kind ("dynamic", "static", "kinematic", "kinematicVelocity" or "soft"; "static" for static world geometry). The push verbs take body and entityId alike. startedInside is false for a surface the query crossed on its way there, and true when the query's own start already lay inside that collider — where distance is 0, point is the start itself, and normal is the shortest way out of the collider. normal is a unit vector either way. surface names the surface the collider is made of where the query met it (Physics.defineSurface; on a heightfield whose samples name layers, the layer of the sample nearest the point), and is absent for a collider naming none. surfaceVelocity is the collider's surfaceVelocity in world space (m/s), the motion its surface carries what stands on it with, and is absent for a collider whose surface holds still. softBody is set when what was hit is a soft body, whose surface the query meets as it is deformed now: a PhysicsSoftHit naming the surface triangle, the particles carrying it with the hit's weight on each, the particle nearest the hit, and region, the hit as a soft region to hand to Physics.applyImpulse, Physics.pinSoftRegion or Physics.softParticles. Physics.applyImpulseAtPoint takes the hit's point as it is.
local hit = Physics.boxCast(o, {x=0.5,y=0.5,z=0.5}, dir, 10)
local hit = Physics.boxCast(o, {x=0.5,y=0.5,z=0.5}, dir, 10, { selfId, carriedId })
typed/builtin//modules/api/engine/physics/P/capsuleCast
P.capsuleCast(origin: vec3, radius: number, halfHeight: number, direction: vec3, maxDistance: number?, exclude: (string | {string})?, axis: vec3?, options: PhysicsCastOptions?) -> PhysicsHit?
Cast a capsule along a direction and return the first hit. The
capsule stands upright, or along axis: the up of a body standing on the
side of a planet (Physics.upAt).
This is the sweep that answers whether a body of that shape fits through
a passage: a capsule of radius r reports a hit on anything that leaves
it less than 2 * r of clearance.
A trigger (isTrigger) holds nothing up, so the sweep passes through it.
Many casts a frame: Physics.castMany answers them all in one call.
Parameters
originvec3— Capsule centre at the start of the cast.radiusnumber— Capsule radius.halfHeightnumber— Distance from the centre to either cap centre. The capsule standshalfHeight + radiustall in each direction.directionvec3— Cast direction, of any length: the engine normalises it, somaxDistanceanddistanceare world units.maxDistancenumber(optional) — Optional distance limit.exclude(string | {string})(optional) — Optional entity id, or array of entity ids, to exclude from hits. Applied while sweeping rather than to the answer, so a cast that starts inside an excluded collider reports what is behind it.axisvec3(optional) — Optional direction the capsule stands along, of any length (defaults to up,{ 0, 1, 0 }).optionsPhysicsCastOptions(optional) — OptionalPhysicsCastOptions:{ mover = entity }casts for the entity the cast moves (a character controller, or anything moved by casts), so it meets colliders as that entity's body does: a one-way collider (oneWay) answers only on the face its direction points out of, to a cast that starts outside it; a collider whosecontactTagthe contact filter answers "ignore" or "sensor" with a tag of the mover's own colliders is passed; and the one-way collidersPhysics.passThrough(mover)drops the mover through are passed until it is clear of them.
Returns PhysicsHit? — Hit table { entityId, body, bodyType, point, normal, distance, startedInside, softBody?, surface?, surfaceVelocity? }, or nil if nothing hit. body is the id of the entity standing for the body the collider belongs to: the body's own entity when the collider was authored on a child entity (a part of a vehicle or an assembled prop, which composes onto its ancestor's body), and the collider's own entity for static world geometry that rides no body, such as the ground. bodyType is that body's kind ("dynamic", "static", "kinematic", "kinematicVelocity" or "soft"; "static" for static world geometry). The push verbs take body and entityId alike. startedInside is false for a surface the query crossed on its way there, and true when the query's own start already lay inside that collider — where distance is 0, point is the start itself, and normal is the shortest way out of the collider. normal is a unit vector either way. surface names the surface the collider is made of where the query met it (Physics.defineSurface; on a heightfield whose samples name layers, the layer of the sample nearest the point), and is absent for a collider naming none. surfaceVelocity is the collider's surfaceVelocity in world space (m/s), the motion its surface carries what stands on it with, and is absent for a collider whose surface holds still. softBody is set when what was hit is a soft body, whose surface the query meets as it is deformed now: a PhysicsSoftHit naming the surface triangle, the particles carrying it with the hit's weight on each, the particle nearest the hit, and region, the hit as a soft region to hand to Physics.applyImpulse, Physics.pinSoftRegion or Physics.softParticles. Physics.applyImpulseAtPoint takes the hit's point as it is.
local hit = Physics.capsuleCast(o, 0.3, 0.6, dir, 0.5)
local hit = Physics.capsuleCast(o, 0.3, 0.6, dir, 0.5, selfId)
local hit = Physics.capsuleCast(o, 0.3, 0.6, dir, 0.5, selfId, Physics.upAt(o))
local hit = Physics.capsuleCast(o, 0.3, 0.6, dir, 0.5, selfId, nil, { mover = selfId })
typed/builtin//modules/api/engine/physics/P/castMany
P.castMany(queries: { PhysicsQuery }, results: { PhysicsQueryResult }?, options: { exclude: (string | { string })?, mover: (string | entityRef)? }?) -> { PhysicsQueryResult }
Answer many rays, shape casts and sphere overlaps in ONE call: the
call for a script that casts many queries a frame (the sight lines of a
crowd of guards, a flock's obstacle probes, the sub-steps of many
projectiles, a vehicle's ring of ground probes). Calling
Physics.raycast once per ray pays a crossing into the engine and a
fresh hit table every time; castMany pays one crossing for the whole
set and writes every answer into the results array, reusing the
tables of the array handed back in.
Each answer is the one the single call of its kind gives
(Physics.raycast, Physics.sphereCast, Physics.capsuleCast,
Physics.boxCast, Physics.overlapSphere), and answers from colliders
alone as they do.
Parameters
queries{ PhysicsQuery }— Array ofPhysicsQuerytables, answered in order:origin,direction(any length),maxDistance(default 1000),kind("ray", the default; "sphere" withradius; "capsule" withradius,halfHeightand optionalaxis; "box" withhalfExtents; "overlapSphere" withradius, its centre atorigin), and optionalexclude(an entity id or array of ids) andmover(asPhysicsCastOptions.mover). Keep the query tables and change their fields from frame to frame.results{ PhysicsQueryResult }(optional) — Optional array to write the answers into: pass the array the previous call returned and its tables are rewritten in place. Entries past the last query are removed. A new array when nil.options{ exclude: (string | { string })?, mover: (string | entityRef)? }(optional) — Optional{ exclude?, mover? }every query naming none of its own takes.
Returns { PhysicsQueryResult } — The results array: one PhysicsQueryResult per query, at the query's index. hit says whether it met anything; a hit carries entityId, point, normal, distance, startedInside, body, bodyType, and surface, surfaceVelocity and softBody as Physics.raycast reports them, with point, normal and surfaceVelocity as vector values; an overlap carries entityIds. A query that is not a table, misses a field its kind needs, or carries a value that is not a finite number is refused, naming its index and the field.
local results = Physics.castMany({ { origin = eye, direction = toPlayer, maxDistance = 30, exclude = guardId } })
-- every guard's sight line to the player in one call, the tables kept across frames
local queries, results = {}, {}
local target = player.position
for i, guard in guards do local q = queries[i] or {}; queries[i] = q; local eye = guard.position; q.origin = vector.create(eye.x, eye.y + 1.6, eye.z); q.direction = vector.create(target.x - eye.x, target.y - eye.y, target.z - eye.z); q.maxDistance = 40; q.exclude = guard.id end
results = Physics.castMany(queries, results)
for i, r in results do guards[i].seesPlayer = r.hit and r.entityId == player.id end
local ground = Physics.castMany({ { kind = "sphere", radius = 0.3, origin = feet, direction = vector.create(0, -1, 0), maxDistance = 2 } })[1]
typed/builtin//modules/api/engine/physics/P/catchUp
P.catchUp() -> PhysicsCatchUp
How the frame clock kept up with real time: the frames it ran, those
that dropped simulated time, and the simulated seconds they dropped,
which is time the world ran in slow motion. A frame drops time when it
owes more than it may catch up (boundSeconds, from
Physics.solverSettings().maxCatchUpSeconds), or when its steps past
maxSubsteps fall behind the time they cover (framesBehind: steps
that cost more than real time, which no frame rate catches up). The same
figures worldState().catchUp carries. Counted since the engine
started; the difference of two reads covers the frames between them,
which is how a game or an agent reads whether a tick rate keeps up on
the frames this engine draws. profiler.counters("physics.catch_up_*")
counts the same per frame: physics.catch_up_frames_at_bound,
physics.catch_up_frames_behind and physics.catch_up_dropped_us (the
microseconds dropped).
Returns PhysicsCatchUp — A PhysicsCatchUp.
local c = Physics.catchUp(); print(c.framesAtBound, c.framesBehind, c.droppedSeconds, c.boundSeconds)
local a = Physics.catchUp(); task.wait(2); local b = Physics.catchUp()
print("dropped", b.droppedSeconds - a.droppedSeconds, "s over", b.frames - a.frames, "frames")
typed/builtin//modules/api/engine/physics/P/colliderCount
P.colliderCount() -> number
How many colliders the physics world holds. Zero means no ray, cast or overlap fired into this world can hit anything, so it is what separates a query that MISSED from a query fired into a world that holds nothing to hit. Read off the collider set itself, so it costs the same whatever the world holds.
Returns number — colliders across the whole physics world.
if Physics.colliderCount() == 0 then print("nothing here is solid") end
typed/builtin//modules/api/engine/physics/P/colliderGeometry
P.colliderGeometry(options: table?) -> table?
Read the physics world as drawable triangles: every collider triangulated in world space into one indexed mesh, in GPU buffers ready to draw.
Box, sphere, capsule, cylinder, cone, convex, triangle-mesh and heightfield
colliders return their real surface, and a compound returns its children
folded together; a shape with no triangulation returns its bounding box and
reports exact = false.
options.colors is POSITIONAL over colliderManifest() — entry i colours
collider i — so you can colour by role, shape, entity or anything else you
read there. A position you leave out takes options.defaultColor.
The returned buffers are yours: destroy them when you replace them.
Parameters
optionstable(optional) —{ tessellation = "low"|"medium"|"high", colors = { {r,g,b,a}, ... }, defaultColor = {r,g,b,a} }.
Returns table? — { vertices, indices, vertexCount, indexCount, colliders } where each entry of colliders is { entity, colliderName?, shapeType, role, exact, firstIndex, indexCount }.
local geo = Physics.colliderGeometry({ tessellation = "high" })
typed/builtin//modules/api/engine/physics/P/colliderManifest
P.colliderManifest() -> table
List every physics collider in the world with what it is and what it takes part in — no geometry, so it is the cheap read to make before deciding what to do with each one.
role is one of static, dynamic, kinematic, sensor. A sensor
is a collider the simulation holds as one, reported ahead of the body type
behind it, and a collider with no rigid body is static. exact says whether colliderGeometry would return this
collider's true surface or its bounding box.
Every collider of one entity shares its entity, so this is what to key
per-object decisions on. The order is stable across calls over an unchanged
world, which is what makes colliderGeometry's positional colours usable.
Returns table — Array of { entity, colliderName?, shapeType, role, exact }.
for _, c in ipairs(Physics.colliderManifest()) do print(c.entity, c.role) end
typed/builtin//modules/api/engine/physics/P/colliderOn
P.colliderOn(entityId: string | entityRef) -> string?
Which collider component an entity carries, or nil when it carries none.
Parameters
entityIdstring | entityRef— Target entity id.
Returns string? The component name, e.g. "SphereCollider".
local which = Physics.colliderOn(id)
typed/builtin//modules/api/engine/physics/P/colliderShapes
P.colliderShapes(entityId: string | entityRef) -> table
Read an entity's resolved physics collider shape(s) as the physics engine sees them, including auto-sized colliders.
shapeType is one of box, sphere, capsule, convex, mesh,
heightfield, compound, wire (a soft body's elements, colliding at
its particle radius), other: the shape the simulation is running, so
a mesh collider reads mesh.
params carries half-extents for a box, radius for a sphere, radius
and half-height for a capsule, and the collider's bounding half-extents
for the shapes that have no parametric description. A convex collider
reports its outline in linePoints instead.
Parameters
entityIdstring | entityRef— Target entity id.
Returns table — Array of resolved collider shapes (empty if none): { shapeType, position, rotation, params, linePoints, name? }.
local shapes = Physics.colliderShapes(id)
typed/builtin//modules/api/engine/physics/P/contactEvents
P.contactEvents(target: (string | entityRef)?) -> { PhysicsContactEvent }
Every collision and contact event kept for target since the last call
for it, oldest first, each from its own physics step: begin, persist, end,
impact, trigger enter and exit, as Physics.listenContacts started keeping
them. Reading empties the list.
Parameters
target(string | entityRef)(optional) — The entitylistenContactsnamed, ornilfor every contact.
Returns { PhysicsContactEvent } — An array of PhysicsContactEvent, empty when nothing happened or nothing is kept for target.
for _, e in Physics.contactEvents(ball) do print(e.kind, e.other, e.step) end
typed/builtin//modules/api/engine/physics/P/contactEventsDropped
P.contactEventsDropped() -> { engine: number, kept: number }
How many contact events the engine let go before anything read them:
its queue keeps 4096 between two deliveries, and each target listenContacts
keeps 1024. Zero when nothing was lost.
Returns { engine: number, kept: number } — { engine, kept }: dropped from the engine's queue, and from the lists listenContacts keeps, since the world started.
local lost = Physics.contactEventsDropped(); if lost.engine > 0 then log.warn("contact events dropped") end
typed/builtin//modules/api/engine/physics/P/contactFilters
P.contactFilters(into: { PhysicsContactFilter }?) -> { PhysicsContactFilter }
Every entry of the world's contact filter (Physics.setContactFilter),
in tag order.
Parameters
into{ PhysicsContactFilter }(optional) — A table to write the entries into and return, the one an earlier read returned: each entry is written into the table at its index, so a script reading the filter every frame allocates nothing. A new table when left out.
Returns { PhysicsContactFilter }: { a, b, mode } each (into when given).
for _, f in Physics.contactFilters() do print(f.a, f.b, f.mode) end
typed/builtin//modules/api/engine/physics/P/contactPeak
P.contactPeak(target: string | entityRef) -> PhysicsContactPeak?
The hardest hit target took since the last call for it: the largest
normal impulse one physics step put between it and anything it touched,
with who, on which step, how fast the two were closing as that step
began, and the surfaces each side is made of where the hit landed. Every
step counts, so an impact that began and ended between two reads is still
the peak it was. The engine keeps it while anything listens to target
(Physics.listenContacts, onContact, onImpact, onTrigger). Reading
starts the next peak afresh.
Parameters
targetstring | entityRef— A listened entity.
Returns PhysicsContactPeak? — A PhysicsContactPeak { other, impulse, closingSpeed, step, surface?, otherSurface? }, or nil when nothing pushed on it since the last read.
Physics.listenContacts(body); local peak = Physics.contactPeak(body); if peak then print(peak.impulse, peak.closingSpeed) end
typed/builtin//modules/api/engine/physics/P/contacts
P.contacts(entityId: string | entityRef, otherId: (string | entityRef)?) -> { PhysicsContact }
Every contact one body's colliders are in right now, with the other
entity, the normal, how deeply the two interpenetrate, the normal and
friction impulse the last step applied, how fast the two were closing as
that step began, the step, and each contact point: the read behind "is it
touching", "is it grounded" and "how hard did that hit land". It describes
the last physics step; to detect every collision, hit and impact as an
event on the step it happens, use Physics.onContact, Physics.onImpact
or Physics.contactPeak. A pair is listed while its
surfaces touch: a pair kept apart (Physics.ignoreCollision, collision
groups) or no longer touching is not. For a soft body these are the
contacts of its surface with every other collider, another soft body's
surface included. A contact with a soft body on either side names the
particles of it that are touching (particles for this side,
otherParticles for the other), so a hit can be answered where it
landed. Name otherId to read only the contacts with that one entity:
a body resting on the ground holds a contact point per surface element
that touches it, and a read of one pair costs that pair alone.
Parameters
entityIdstring | entityRef— Entity id or proxy.otherId(string | entityRef)(optional) — Optional entity id or proxy: report only the contacts with it.
Returns { PhysicsContact } — An array of PhysicsContact — empty when the body touches nothing, or when the entity carries neither a rigid body nor a soft body.
for _, c in Physics.contacts(id) do print(c.other, c.deepestPenetration) end
for _, c in Physics.contacts(truck, pole) do if c.totalImpulse > 5 then print("dented at", #c.particles, "particles") end end
typed/builtin//modules/api/engine/physics/P/cutSoftBody
P.cutSoftBody(softId: string | entityRef, blade: { vec3 } | { point: vec3, normal: vec3 })
Cut a soft body along a blade, every element of the body the blade
meets opening along it: { point = p, normal = n } cuts along the whole
plane through p facing n, splitting the body in two wherever it lies on
both sides; { a, b, c } cuts along that world-space triangle, which cuts
only as far as the triangle reaches. Applied straight after the next physics
step; a piece the cut separates becomes an entity of its own (see
onSoftBodyTear), and the cut reports as a tear of kind "cut". A plane is
measured against the body where that step leaves it, so it cuts a moving
body wherever it has gone; a cut that opens nothing is reported in the log.
Raises when the entity carries no SoftBody, and in edit mode, where
nothing simulates.
Parameters
softIdstring | entityRef— The soft body's entity.blade{ vec3 } | { point: vec3, normal: vec3 }—{ point = vec3, normal = vec3 }for a plane, or the triangle's three world-space corners{ a, b, c }.
Physics.cutSoftBody(jelly, { point = vector.create(0, 1, 0), normal = vector.create(1, 0, 0) }) -- in two along x = 0
Physics.cutSoftBody(jelly, { vector.create(0, -5, -5), vector.create(0, 5, -5), vector.create(0, 0, 10) })
-- slice off the part of a body 0.2 m above its centre
local c = Physics.softBodyState(jelly).centerOfMass
Physics.cutSoftBody(jelly, { point = vector.create(c.x, c.y + 0.2, c.z), normal = vector.create(0, 1, 0) })
typed/builtin//modules/api/engine/physics/P/debugLines
P.debugLines(opts: table?) -> (PhysicsDebugLines?, string?)
Draw what the physics world simulates beyond collider surfaces as
world-space lines, with what each object's lines picture as data. This is
the read the physics debug views draw from: capture { pass = "physics" }
and the edit-mode collider overlay (debugViz category colliders) both
show these lines.
Layers:
cage draws a soft body's elements coloured by load: slack blue, yellow
half way, red at the load it tears (see PhysicsSoftBodyDiagnostics for
how a load is read);
particles draws its particles: free ones as small grey crosses, pinned
ones as green octahedra, ones held to a rigid body as magenta octahedra;
contacts draws the contacts soft surfaces hold against soft surfaces
(their own included): the segment joining the two witness points in
orange, the normal in cyan;
wheels draws each WheelCollider wheel: its suspension ray as far as
it reaches, its whole travel and the tyre's radius below the mount (green
on ground, red in the air, as the wheel's isGrounded reads), the travel
from its mount to the tyre's centre coloured by how much of it is taken
up on the same ramp, its tyre circle in white across its steered axle,
and its ground point (yellow) and normal (cyan).
Answers in edit mode as well as play mode; in edit mode a vehicle stands
at rest with its wheels where they are authored.
Parameters
optstable(optional) —{ layers: {string}?, entities: {(string | entityRef)}? }:layersnames the layers to draw (every layer when omitted; an unknown name is an error naming the layers),entitieskeeps to those entities' objects (a wheel is kept by its own entity or its chassis').
Returns (PhysicsDebugLines?, string?) — A PhysicsDebugLines, or nil and the reason on a VM that holds no physics world (a worker).
local d = Physics.debugLines(); print(d.lineCount, #d.objects)
for _, o in Physics.debugLines({ layers = { "particles" } }).objects do print(o.entity, o.pinned, o.attached) end
local w = Physics.debugLines({ layers = { "wheels" }, entities = { truck } }); for _, o in w.objects do print(o.index, o.grounded, o.compression) end
typed/builtin//modules/api/engine/physics/P/defineSurface
P.defineSurface(name: string, surface: PhysicsSurfaceDefinition?)
Define a surface: a named material of contact coefficients that a
collider takes by naming it in its surface field (every collider
component carries one), and that a heightfield takes per sample through
surfaceLayers / surfaceMap (how each painted layer of a terrain is its
own ground). A surface holds friction, restitution,
rollingResistance (a body rolling on it loses speed at this many times
gravity on level ground, so a ball rolled at v stops after
v^2 / (2 * rollingResistance * 9.81)), spinningResistance (the same for
a body spinning on it about the contact normal) and free tags (what a
footstep, a skid mark or an impact sound reads it by). Per contact the
two sides' friction and restitution average and their resistances add
(a ball of none on a floor of c rolls against c). Contacts, contact
events and ray and shape cast hits name the surface each side is made of
at the point, and Physics.groundContact names what a body stands on.
Defining a name again replaces it, and every collider naming it takes the
new values from the next physics step; a collider naming a surface no one
defined keeps its own coefficients and still reports the name.
Parameters
namestring— The surface's name, 1 to 64 bytes.surfacePhysicsSurfaceDefinition(optional) —{ friction?, restitution?, rollingResistance?, spinningResistance?, tags? }; unstated coefficients take friction 0.5 and 0 for the rest.
Physics.defineSurface("gravel", { friction = 0.6, rollingResistance = 0.04, tags = { "loose", "crunchy" } })
Physics.defineSurface("ice", { friction = 0.05, rollingResistance = 0.002 })
entity("road").component.add("BoxCollider", { half = { 50, 0.5, 4 }, surface = "gravel" })
typed/builtin//modules/api/engine/physics/P/defineWater
P.defineWater(name: string, body: PhysicsWaterDefinition)
Define a body of water, which Physics.water then answers from at any
point and moment: physics, scripts and AI all read water through it.
body.kind is what the water is:
"flat": still water atlevel. Within aregionwhose min Y is finite, that is its floor: a pool, a tank, a flooded room (leveldefaults to the region's max Y)."waves": a sea over the stilllevel, the sum of the waves it lists (waves = { { amplitude, wavelength, direction, phase?, steepness?, omega? } }: heightamplitude * cos(k (d . p) - omega t + phase), the surface point moved sideways bysteepness * amplitudealong the directiond({x, z}or an angle from +X),omegadefaulting to deep water'ssqrt(9.81 k)) and of thelatticesof a spectrum's waves it carries (what a sea of the Tidewater water kit defines); its time is the water clock wrapped toperiodand scaled byspeed; over agroundgrid its waves shoal away to nothing at the waterline acrossshoalDepthmetres."grid": a landscape's lakes and rivers, a level per texel over the rectangle atorigin({x, z}) ofsize({x, z}) metres,columnsxrowstexels, dry where a texel carries no level. Its water runs down the slope of its own surface at Manning's speed over a bed ofroughness(default 0.035), so a level lake stands still and a river runs along its channel, unlessflowstates it per texel (finite at every wet texel).levels,ground.heightsandflowtake a list of numbers or the texels of a float texture ({ texels, channels = 4, channel = 1, wet = 2 }).
Every kind takes region, a current the whole body carries (m/s),
priority (where bodies overlap the higher answers, then the higher
surface; defaults waves 0, grid 1, flat 2), density (kg/m³, default
1000 for fresh water; 1025 for the sea), which a body carrying
FluidForces floats against and is dragged by, and entity, which the
body goes with. space says which coordinates the body is stated in:
"world" (the default) or "entity", the local space of its entity:
every position, level, size, region and current it states is then that
entity's, and the body stands, turns, tilts and scales wherever the
entity does, following it as it moves, the way the entity's own
colliders do, and covers no point while the entity is scaled to nothing
along an axis. A Terrain's water is stated in the landscape's own
coordinates this way. A Terrain with water and a sea of the Tidewater
water kit define theirs, a Water component places still water in a box
saved with its scene, and content defines a pool, a tank or a river of its
own. Defining a name again replaces the body; a body that cannot be
sampled is refused with the reason.
Parameters
namestring— The body's name, 1 to 128 bytes.bodyPhysicsWaterDefinition— The body, as above.
Physics.defineWater("pool", { kind = "flat", region = { min = { x = -5, y = 0, z = -5 }, max = { x = 5, y = 2, z = 5 } } })
Physics.defineWater("pond", { kind = "waves", level = 1, waves = { { amplitude = 0.1, wavelength = 6, direction = { x = 1, z = 0.3 } } } })
Physics.defineWater("canal", { kind = "flat", level = 0, region = { min = { x = 0, y = -3, z = -4 }, max = { x = 200, y = 0, z = 4 } }, current = { x = 1.5, y = 0, z = 0 } })
Physics.defineWater("deck pool", { kind = "flat", level = 1, region = { min = { x = -2, y = 0, z = -3 }, max = { x = 2, y = 1, z = 3 } }, entity = ship, space = "entity" })
typed/builtin//modules/api/engine/physics/P/defineWind
P.defineWind(name: string, wind: PhysicsWindDefinition)
Define a wind field: air moving through the world, which pushes on
every body carrying FluidForces (a soft body's triangles included) or a
LiftSurface inside each physics step, and which Physics.wind answers
with the same value so a flag, a tree or a particle system bends with
what the bodies feel. Every field covering a point adds to the wind
there. kind says what it blows at each point:
"steady" (the default) blows velocity (m/s) everywhere it reaches.
"grid" reads velocities between the centres of the texels around a
point, over the box at origin of size metres cut into columns
along X, rows along Z and layers along Y (default 1: a map, the same
at every height of its box): air around a building, a valley channelling
it, a storm front painted over a map. velocities lists x, y, z per
texel, along X first, then Z, then Y, or takes a float texture's texels,
{ texels = string | buffer of little-endian f32, channels = 4, x = 1, y = 2, z = 3 }, each axis naming the channel it reads (an axis named by
none reads 0). scroll (m/s) moves the pattern through its box on the
water clock, wrapping around it; wrap = true repeats the grid past its
box, where otherwise it blows nothing outside it.
"vortex" turns the air about axis (default up) through center, like
a solid body inside the core of radius metres and slowing as
radius / distance outside it; speed (m/s) is its speed at the core's
edge, by the right-hand rule about axis, so the core turns at
speed / radius rad/s; inflow (m/s) draws the air in toward the axis
and updraft (m/s) lifts it along the axis, from its full speed on the
axis to nothing at updraftRadius metres out (default radius: the
core alone; wider, a column that carries up what the vortex swings
around outside its core): a tornado, a dust devil, a whirlpool's air.
"radial" blows out of center at speed (m/s, negative draws it in) at
radius metres, rising from nothing at the centre and slowing past
radius by the square of the distance, or, with an axis, out across
that line and slowing by the distance: a blast, a rotor's downwash.
Every kind adds velocity on top. gust (m/s) is how far the speed at
a point rises and falls along the wind there over gustPeriod seconds
(default 4); gusts travel downwind at the wind's speed and differ across
it over gustSize metres (default 20); where a field blows nothing it
gusts along gustDirection. region ({ min, max }) keeps the field to
a box it reaches full strength falloff metres inside of: a fan, an
updraft, a wind tunnel, a gap between buildings. entity ties it to an
entity it goes with; with space = "entity" every position, size,
direction, region and velocity it states is in that entity's local
space, and the field stands, turns and scales wherever the entity does,
following it as it moves. Gusts and scrolling follow the water clock
(Physics.waterTime), so a step feels the wind of its own moment.
Defining a name again replaces the field; one that cannot be sampled is refused with the
reason. The Wind component places a wind as an entity saved with its
scene, a steady, grid, vortex or radial one.
Parameters
namestring— The field's name, 1 to 128 bytes.windPhysicsWindDefinition— The field, as above.
Physics.defineWind("breeze", { velocity = { x = 6, y = 0, z = 1 }, gust = 3 })
Physics.defineWind("updraft", { velocity = { x = 0, y = 9, z = 0 }, region = { min = { x = -3, y = 0, z = -3 }, max = { x = 3, y = 30, z = 3 } }, falloff = 1 })
Physics.defineWind("tornado", { kind = "vortex", center = { x = 40, y = 0, z = 0 }, radius = 6, speed = 30, inflow = 4, updraft = 12, updraftRadius = 15, region = { min = { x = 0, y = -5, z = -40 }, max = { x = 80, y = 60, z = 40 } }, falloff = 10 })
Physics.defineWind("valley", { kind = "grid", origin = { x = -50, y = 0, z = -50 }, size = { x = 100, y = 40, z = 100 }, columns = 2, rows = 2, velocities = { 4, 0, 0, 8, 0, 0, 2, 0, 3, 6, 0, 3 } })
Physics.defineWind("downwash", { kind = "radial", entity = heli, space = "entity", center = { x = 0, y = -1, z = 0 }, axis = { x = 0, y = 1, z = 0 }, radius = 3, speed = 12, velocity = { x = 0, y = -10, z = 0 }, region = { min = { x = -12, y = -20, z = -12 }, max = { x = 12, y = 0, z = 12 } } })
typed/builtin//modules/api/engine/physics/P/detachSoftRegion
P.detachSoftRegion(softId: string | entityRef, targetId: (string | entityRef)?) -> number
Release regions of a soft body held with attachSoftRegion (or
authored in its SoftBody component's attachments).
Parameters
softIdstring | entityRef— The soft body's entity.targetId(string | entityRef)(optional) — Release only the regions held to this rigid body; omit to release every one.
Returns number — How many attachments were released.
Physics.detachSoftRegion(flag, pole)
Physics.detachSoftRegion(shell)
typed/builtin//modules/api/engine/physics/P/detachWheel
P.detachWheel(entityId: string | entityRef) -> boolean
Take a wheel off its vehicle: it leaves as a dynamic body of its own
from where it stands, moving as it moved and spinning as it spun, with
its mass and with the wheel entity's own collider as its collider,
which leaves the chassis with it (a cylinder of its radius and width
for a wheel holding none or whose own collider is a trigger, which then
rides the wheel's body beside it), and the vehicle drives on the wheels
it has left. The wheel entity stays under the chassis in the hierarchy;
Physics.getVelocity, applyImpulse and the contact listeners reach
it as any body. A wheel also comes off by
itself when its reaction passes its breakLoad. On a shared world
the peer that may write the wheel takes it off for every peer.
Parameters
entityIdstring | entityRef— The wheel entity (it carries the WheelCollider).
Returns boolean — True when the entity carries a WheelCollider.
Physics.detachWheel(wheel.id); print(Physics.getWheelState(wheel.id).detachReason) -- "command"
typed/builtin//modules/api/engine/physics/P/digestLog
P.digestLog(opts: table?) -> PhysicsDigestLog
Read the digests the recording kept, oldest first: digests[i] is
the state digest at the end of step steps[i].
Parameters
optstable(optional) —{ from?, to?, frames? }:from/tobound the steps read (inclusive);frames = trueaddsframes, each step's recordedPhysicsStateDigestwith itsentries.
Returns PhysicsDigestLog — A PhysicsDigestLog. dropped counts the steps that fell out of the recording's bounds.
local log = Physics.digestLog(); print(#log.digests, log.digests[#log.digests])
typed/builtin//modules/api/engine/physics/P/drawnPose
P.drawnPose(entityId: string | entityRef, into: { [string]: any }?) -> PhysicsDrawnPose?
Where an entity is drawn this frame, and where its transform puts
it. The simulation advances in fixed ticks (physics.tick_rate, 60 a
second by default) while frames are drawn at the display's rate, so a
body with Physics.interpolation on is drawn blended between its last two
ticks, and everything parented under it is drawn moved with it.
entity.position reports the drawn pose from a component's update, a
task or a tool call, and the simulated pose, which moves only when a tick
runs, from code inside a step (step hooks, contact listeners,
fixedUpdate); this read reports both, wherever it is made. Its
simulatedPosition is the pose the last tick left.
Parameters
entityIdstring | entityRef— Entity id or proxy. Any entity answers; one the simulation does not blend is drawn at its simulated pose.into{ [string]: any }(optional) — A table to write the pose into and return, the one an earlier read returned: its position and rotation tables are written in place and a field the pose leaves out is cleared, so a script reading this every frame into one table allocates nothing. A new table when left out.
Returns PhysicsDrawnPose? — A PhysicsDrawnPose (into when given), or nil when nothing in the scene answers to that id.
local d = Physics.drawnPose(car); print(d.position.z, d.simulatedPosition.z, d.interpolated)
local d = Physics.drawnPose(tyre); print(d.interpolated, d.interpolatedBy)
local held = {}; local d = Physics.drawnPose(lift, held)
typed/builtin//modules/api/engine/physics/P/driveSoftElements
P.driveSoftElements(softId: string | entityRef, targets: { [number]: number }, opts: { speed: number? }?)
Drive the length of authored elements of a custom soft body: each
named element's rest length moves toward its target at opts.speed
(metres per second; 0 or omitted sets it at once), pushing and pulling
with no more than the element's own maxForce, so a blocked ram stalls
instead of tearing the body. A hydraulic ram, a muscle, a crane's luffing
cylinder. The drive holds until the element's fields are written again
(an element of kind "actuator" is driven to its targetLength from its
fields). Takes effect from the next physics step, on the peer that
simulates the body.
Parameters
softIdstring | entityRef— The soft body's entity.targets{ [number]: number }— Element number (as listed in the component'selements) to the length in metres it is driven to.opts{ speed: number? }(optional) —{ speed: number? }: how fast the lengths move, in metres per second.
Physics.driveSoftElements(crane, { [7] = 2.5, [8] = 2.5 }, { speed = 0.4 })
typed/builtin//modules/api/engine/physics/P/firstDivergence
P.firstDivergence(a: table, b: table) -> PhysicsDivergence?
Find where two simulations first part. Pass two Physics.stateDigest
results, or two Physics.digestLog results (read with frames = true to
name more than the step). Logs are compared step by step from their first
recorded step, over the steps both hold, so two engines that started
recording at the same point of the same scripted run line up whatever
their own step numbers. The answer names the first index and step whose
digests differ, then the first body, joint or soft body (in hash order)
whose own digest differs, then, when values were recorded, the first
field and component that differs, with both values. Values compare as
their bits, or under the digest's quantum when one was set.
Parameters
atable— The first engine's digest or log.btable— The second engine's digest or log, taken with the same options.
Returns PhysicsDivergence? — nil when they agree; otherwise a PhysicsDivergence: reason is "digest" (only the digests were kept), "missing" (an entry one side lacks: missingIn names the side), "entry" (the entry's digest differs, no values kept), "field" (field, component, axis, particle for a soft body, and the values a / b) or "count" (a soft body's particle counts differ). index is the log position, step / stepB each side's step number. The first entry in hash order is often a body whose state moved by the last bit only because the cause pushed it, so largest names the value that differs the most at that step across every entry with values: { kind, key, field, component, axis, particle, a, b, delta }.
local d = Physics.firstDivergence(logA, logB); if d then print(d.step, d.key, d.field, d.axis, d.a, d.b) end
typed/builtin//modules/api/engine/physics/P/fluidForces
P.fluidForces(entityId: string | entityRef) -> PhysicsFluidForces?
What the air and the water put on a body on the last physics step:
its FluidForces (buoyancy, drag, Magnus) and its LiftSurfaces (each
surface's lift, drag, angle of attack and stall), worked out from the
pose and velocity the body started that step at. Nil for a body neither
acts on, or one no step has worked them out for yet (a paused world).
For a soft body, the totals over its surface.
Parameters
entityIdstring | entityRef— Entity id or proxy of a rigid or soft body.
Returns PhysicsFluidForces?.
local f = Physics.fluidForces(crate); print(f.submerged, f.buoyancy.y)
for _, s in Physics.fluidForces(car).surfaces do print(s.name, s.lift.y, s.stalled) end
typed/builtin//modules/api/engine/physics/P/forces
P.forces(entityId: string | entityRef) -> PhysicsBodyForces?
Which forces act on a body from step to step, and their sum: every
Force component driving it (on its entity or an entity under it, each
named by its source entity and instance name), each evaluated at the
pose the body stands at now, in the world frame, as the next step
applies it. applied reads whether this engine's step applies them: an
enabled dynamic body takes them, a static or kinematic one carries them
unmoved. Forces written for one step (applyForce) are the body state's
queuedForce.
Parameters
entityIdstring | entityRef— Entity id or proxy of a body.
Returns PhysicsBodyForces? — A PhysicsBodyForces (force, torque, forces, applied), with empty forces and zero sums for a body carrying none, or nil when nothing in the scene answers to that id with a rigid body.
local f = Physics.forces(rocket); print(f.force.y, #f.forces)
typed/builtin//modules/api/engine/physics/P/getAngularVelocity
P.getAngularVelocity(entityId: (string | entityRef)?, into: { [string]: any }?) -> vec3?
Read the angular velocity of an entity's rigid body.
Parameters
entityId(string | entityRef)(optional) — Target entity id or proxy; resolves from script context when omitted.into{ [string]: any }(optional) — A table to write the angular velocity'sx,yandzinto and return: a script reading this every frame into one table allocates nothing. A new table when left out.
Returns vec3? — Angular velocity in rad/s (into when given), or nil if the entity has no rigid body.
local w = Physics.getAngularVelocity(id)
local held = {}; local w = Physics.getAngularVelocity(id, held)
typed/builtin//modules/api/engine/physics/P/getGravity
P.getGravity() -> vec3
Read the current world gravity vector.
Returns vec3 — Gravity vector in m/s² (negative y is "down" in the default world).
local g = Physics.getGravity()
typed/builtin//modules/api/engine/physics/P/getSurface
P.getSurface(name: string) -> PhysicsSurface?
The surface name names, as Physics.defineSurface defined it.
Parameters
namestring— The surface's name.
Returns PhysicsSurface?: nil when no surface of that name is defined.
local s = Physics.getSurface(hit.surface); if s and table.find(s.tags, "loose") then sprayGravel(hit.point) end
typed/builtin//modules/api/engine/physics/P/getVelocity
P.getVelocity(entityId: (string | entityRef)?, into: { [string]: any }?) -> vec3?
Read the linear velocity of an entity's rigid body, or of its soft body as a whole (its particles' velocities averaged by mass).
Parameters
entityId(string | entityRef)(optional) — Target entity id or proxy; resolves from script context when omitted.into{ [string]: any }(optional) — A table to write the velocity'sx,yandzinto and return: a script reading this every frame into one table allocates nothing. A new table when left out.
Returns vec3? — Velocity in m/s (into when given), or nil if the entity has no rigid body.
local v = Physics.getVelocity(id)
local held = {}; local v = Physics.getVelocity(id, held)
typed/builtin//modules/api/engine/physics/P/getWheelState
P.getWheelState(entityId: string | entityRef) -> PhysicsWheelState?
Read a wheel collider's runtime state. Reads the native component the wheel system writes after each physics step.
Parameters
entityIdstring | entityRef— Target entity id (must carry a WheelCollider component).
Returns PhysicsWheelState? — PhysicsWheelState: { entityId, isGrounded, compression, angularVelocity, rotation, skid, slipRatio, slipAngle, roadSpeed, load, peakSlipRatio, peakSlipAngle, sideGrip, sideImpulse, forwardImpulse, sideForce, forwardForce, suspensionForce, stopImpulse, center, hitPoint, hitNormal, surface?, ground?, solid, reaction, breakLoad, attached, detachReason?, detachLoad, vehicleOrder }, or nil if the component is absent. surface is the surface the tyre touches (Physics.defineSurface; the painted layer under it on a terrain), absent on ground naming none, and ground the entity id of what it touches, absent in the air. A tyre grips a defined surface with its stated grip times the surface's friction, and the surface's rollingResistance adds to the tyre's own. reaction is the force (N) the ground and whatever struck the wheel's volume put on it in the last tick, what breakLoad is measured against; attached is true while the wheel stands on its vehicle (false from the moment it is asked off or comes off, and true again once the physics tick after Physics.attachWheel has put it back on its mount), detachReason says why it came off ("load" or "command") and detachLoad the reaction it came off at; vehicleOrder is the wheel's place among its vehicle's wheels, from 1, the order the vehicle steps them in and Physics.vehicleState lists them in (a wheel that came off keeps the place it last held, and one that has not stepped on a vehicle reads 0). compression runs from 0 at the spring's rest up to suspensionDistance, where the bump stop is; angularVelocity is the wheel's spin (rad/s) and rotation its angle about its axle in radians, both growing as it rolls forward; skid is how fast the tyre slides (m/s) while its grip is used up, 0 while it holds (sideways only, unless the wheel spins on its own); slipRatio is the tread's speed less the road's under it, both positive rolling forward, as a share of the road speed, signed the way the tyre pushes the car (rolling forward: 0 rolling, positive in wheelspin, -1 locked; rolling backward the signs turn over; 0 for a wheel with no inertia, which rolls at the road speed); slipAngle is the angle in degrees between the line the tyre rolls along and the way its contact moves, positive toward the wheel's right (the drift angle at the tyre); roadSpeed is the ground's speed under the tyre along that line (m/s); load is the force the tyre presses the ground with (N); peakSlipRatio and peakSlipAngle (degrees) are the slip ratio and the slip angle its grip peaks at along the road and across it on the ground it touches, whatever its load (0 for a tyre that grips with nothing that way, and peakSlipRatio 0 for a wheel with no inertia), the peaks Physics.tyreCurve sweeps to, and sideGrip the share of its peak grip across the road it pushed across it with at the slip ratio and slip angle it ran at, at the load it carried (its grip along the road and its slide past its peak both counted; at most 1, and 1 for a tyre that grips with nothing across the road); the impulses are what the tyre applied to the chassis this tick (N·s) and the forces the same over the tick (N), and stopImpulse what the bump stop applied once the suspension was used up; center is the wheel centre in world space.
local state = Physics.getWheelState(id)
typed/builtin//modules/api/engine/physics/P/gravityAt
P.gravityAt(point: vec3, groups: number?, into: { [string]: any }?) -> vec3
The gravity at a point: the acceleration the physics step gives a
dynamic body standing there (gravity scale 1). Planet gravity, a pull
toward an axis or a surface, or a zone pulling its own way come from the
GravityField components acting there; elsewhere it is the world's
gravity vector. It is exactly what the step applies, so a character
controller, a follow camera, an AI or a vehicle takes its down from it.
Parameters
pointvec3— The point, in world space.groupsnumber(optional) — The collision membership of the body asking, as a bitmask; a field acts on a body whose membership shares a bit with itsgroups. Default: every group.into{ [string]: any }(optional) — A table to write the answer'sx,yandzinto and return: a script reading this every frame into one table allocates nothing. A new table when left out.
Returns vec3 — The gravity there, in m/s² (into when given).
local g = Physics.gravityAt(entity(ship).position)
local mass = 2; Physics.applyForce(ship, { -g.x * mass, -g.y * mass, -g.z * mass }) -- hover against any planet
local held = {}; local g = Physics.gravityAt(vector.create(x, y, z), nil, held)
typed/builtin//modules/api/engine/physics/P/gravityFieldsAt
P.gravityFieldsAt(point: vec3, groups: number?, into: { [string]: any }?) -> PhysicsGravityFieldsAt
Which gravity fields act at a point and what each gives there: the read that tells why a body falls the way it does near several planets, an inverted sphere or a zone.
Parameters
pointvec3— The point, in world space.groupsnumber(optional) — The collision membership of the body asking, as a bitmask. Default: every group.into{ [string]: any }(optional) — A table to write the answer into and return, the one an earlier read returned: itsgravity, itsfieldsand each entry of them are written in place, so a script reading this every frame into one table allocates nothing. A new table when left out.
Returns PhysicsGravityFieldsAt — A PhysicsGravityFieldsAt: gravity (as Physics.gravityAt), fromFields, and fields, each { entityId, shape, acceleration, counted } (into when given).
for _, f in Physics.gravityFieldsAt({ 0, 12, 0 }).fields do print(f.entityId, f.shape, f.counted) end
local held = {}; local here = Physics.gravityFieldsAt(vector.create(x, y, z), nil, held)
typed/builtin//modules/api/engine/physics/P/groundContact
P.groundContact(entityId: string | entityRef, maxSlope: number?) -> PhysicsGroundContact?
What a body stands on now: of its contacts whose normal leans less
than maxSlope degrees from straight up against gravity, the one the
last step pushed hardest, with the surface it is made of under the body.
The read a footstep sound, a tyre without a WheelCollider, a skid mark
or dust takes to know what is underfoot, on a painted terrain as well.
Parameters
entityIdstring | entityRef— Entity id or proxy carrying a rigid body.maxSlopenumber(optional) — Optional steepest ground counted, in degrees from level (default 60).
Returns PhysicsGroundContact?: nil when nothing holds the body up.
local g = Physics.groundContact(player); if g and g.surface == "gravel" then playStep("gravel") end
typed/builtin//modules/api/engine/physics/P/hasLineOfSight
P.hasLineOfSight(fromId: string | entityRef, toId: string | entityRef) -> boolean
Check whether two entities have line-of-sight between their
origins: a ray from the viewer's world position to the target's meets
no collider but the target's own. The colliders of the body each end
rides (its own body, or the body of its nearest ancestor carrying one)
and of every entity riding that body belong to that end, so neither the
viewer's own colliders nor the target's hold the sight line up.
Many viewers checked every frame (a crowd of guards): Physics.castMany
answers every sight line in one call, each query a ray from a viewer
toward the target that excludes the viewer, seeing it where entityId
is the target's.
Parameters
fromIdstring | entityRef— Viewer entity, an id or a proxy.toIdstring | entityRef— Target entity, an id or a proxy.
Returns boolean — true when no collider sits between them (including coincident origins), false otherwise. Raises naming the argument when fromId or toId names no entity.
if Physics.hasLineOfSight(a, b) then ... end
typed/builtin//modules/api/engine/physics/P/ignoreCollision
P.ignoreCollision(entityIdA: string | entityRef, entityIdB: string | entityRef, ignore: boolean?)
Keep two entities from colliding, or let them collide again. Covers
every collider each one owns (its rigid body with the shapes composed
onto it, its standalone collider, its ragdoll's bones, its soft body's
surface), so it keeps a soft shell off the chassis it is held to as well
as two rigid bodies apart. An ignored pair holds no contact: the solver
pushes neither one and Physics.contacts lists neither to the other.
It applies from the next physics step, to bodies already touching as
well, and lasts until it is turned off, either entity is despawned, or
the mode changes: entering or leaving play starts without it, so make
the call where the bodies are set up for play (a component's onLoad).
It stands beside collision groups: a pair either one excludes does not
collide. A vehicle's WheelColliders stand only where its chassis
collides, so the wheels of a chassis in an ignored pair pass the other
entity as the chassis does.
Parameters
entityIdAstring | entityRef— First entity id.entityIdBstring | entityRef— Second entity id.ignoreboolean(optional) — Whentrue(default) the pair is kept apart;falselets it collide again.
Physics.ignoreCollision(a, b, true)
typed/builtin//modules/api/engine/physics/P/immersion
P.immersion(target: string | entityRef) -> PhysicsImmersion?
How much of an entity stands in the water: the share of it under the
surface, the water it displaces, how deep its centre and its lowest point
stand, which body of water it is in and whether it is in the water by the
rule Physics.onWater raises entries and exits by. Works for any body
(with or without FluidForces), a character, a collider or an entity's
origin, in any water: a pool, a Water component, an ocean, a terrain's
lakes and rivers. For an entity Physics.onWater watches it is what the
last physics step measured; for any other it is measured now. Use it for
how wet something is, a swim depth, a boat's draft, a sinking timer.
Parameters
targetstring | entityRef— The entity.
Returns PhysicsImmersion? — A PhysicsImmersion { inWater, submerged, submergedVolume, volume, wetArea, depth?, deepest?, water?, surfacePoint?, center, velocity, step }, or nil when the entity has nothing to measure.
local w = Physics.immersion(boat); if w and w.submerged > 0.9 then print("sinking") end
local w = Physics.immersion(player); local wading = w ~= nil and (w.depth or -1) > -0.5
typed/builtin//modules/api/engine/physics/P/isSleeping
P.isSleeping(entityId: (string | entityRef)?) -> boolean?
Whether an entity's rigid or soft body is currently asleep (at rest and not simulating). A body sleeps once it stops moving, to save simulation cost.
Parameters
entityId(string | entityRef)(optional) — Target entity id or proxy; resolves from script context when omitted.
Returns boolean? — true if asleep, false if awake, or nil if the entity has neither a rigid nor a soft body.
if Physics.isSleeping(id) then Physics.wakeUp(id) end
typed/builtin//modules/api/engine/physics/P/jointBreaks
P.jointBreaks() -> table
Every joint that has broken since the last call to this function.
A joint breaks when the reaction it carries exceeds the breakForce
(newtons of force on the body carrying it) or breakTorque (newton-metres
of moment about its anchor) its joint was given; each joint
reports once and its constraint is already released when the record
arrives. The 256 most recent are kept: a structure that comes apart while
nothing reads them drops the oldest beyond that, as the engine's own queue
does beyond 1024.
Returns table — Array of { entityId, joint, jointEntityId, connectedEntityId, kind, impulse, angularImpulse, force, torque, position }, oldest first: entityId is the entity whose Joint broke and joint that Joint's name (nil for its unnamed Joint), so one of a body's several joints is named; jointEntityId is the entity carrying its constraint.
for _, e in ipairs(Physics.jointBreaks()) do print(e.entityId, e.force) end
typed/builtin//modules/api/engine/physics/P/jointReaction
P.jointReaction(entityId: string | entityRef | table, name: string?) -> PhysicsJointReaction?
The load (the stress) an entity's joint is carrying right now, as the
constraint solver resolved it on the last physics step: the force and the
moment it applies to the body carrying it, as vectors and read along the
member it holds, so tension tells from compression, axial load from shear
and bending from twist. This is the same quantity a break threshold is
measured against, and load is the share of breakForce / breakTorque
it stands at. A joint with a soft body at either end reads the same way.
Physics.jointReactions reads many joints in one call.
Parameters
entityIdstring | entityRef | table— Entity carrying the Joint component, or aJointcomponent.namestring(optional) — The Joint's name on that entity, for one of several joints; omit for its unnamed Joint.
Returns PhysicsJointReaction? — A PhysicsJointReaction, or nil when the entity owns no joint or its constraint is not built yet. axial is the force along the member at this body's end, positive pulling it outward (tension) and negative pushing it inward (compression): a member hanging 10 kg reads +98.1, one propping it -98.1. direction is that line, from the body's centre of mass out to its anchor; connectedAxial reads the connected body as a member the same way. tension is the pull along the line between the two anchors (a rope's or a spring's), 0 while they stand together. shear is the force across the member, bending the moment across it, torsion the moment about it. worldForce / worldTorque are the force and the moment about the anchor the joint applies to this body (N, N·m), localForce / localTorque the same along the joint frame's axes, and force / torque their sizes. load is the larger of force / breakForce and torque / breakTorque, 1 breaking the joint, 0 with no threshold. A joint Physics.listenJointLoads listens to carries peak, the largest load any step put on it since the last read, which reading takes.
local r = Physics.jointReaction(id); print(r and r.axial)
local r = Physics.jointReaction(beam, "right"); if r and r.axial < 0 then print("compressed", -r.axial) end
typed/builtin//modules/api/engine/physics/P/jointReactions
P.jointReactions(targets: any?, opts: { vectors: boolean?, fields: { string }? }?) -> PhysicsJointReactions
The load (the stress) of many joints in one call, as arrays of one
value per joint, each read the way Physics.jointReaction reads one: a
whole bridge or machine coloured by load in one read a frame. targets is
an array of Joint components and entities (each entity's unnamed Joint),
in the order the arrays answer; one entity, for every joint its body is in;
or nil for every joint in the world. Each joint is named by entityId
(whose Joint), joint (its name, empty for the unnamed one),
jointEntityId and connectedEntityId, and by bodyEntityId and
connectedBodyEntityId, the entities of the two bodies it holds: the
members to sum a structure's loads on. A joint Physics.listenJointLoads listens to gives
the peak it carried since its last read in peakLoad, peakMaxAxial and
peakMinAxial, which reading takes; every other joint gives its current
reading there.
Parameters
targetsany(optional) — An array of Joints and entities, one entity, or nil for every joint.opts{ vectors: boolean?, fields: { string }? }(optional) —{ fields = { "axial", "load" } }builds only the arrays it names (any listed in the return, the vectors and names included), the cheapest read of a large structure;{ vectors = true }adds the arraysworldForce,worldTorque,localForce,localTorque,directionandpositionof {x, y, z}. Reading the same joints every frame, pass theirjoint:jointEntityId()ids, taken once, in place of the Joints.
Returns PhysicsJointReactions — A PhysicsJointReactions: count, and the arrays exists (false while a joint's constraint is not built, its values 0), axial, connectedAxial, tension, shear, bending, torsion, force, torque, impulse, load, listened, peakLoad, peakMaxAxial, peakMinAxial.
local r = Physics.jointReactions(); for i = 1, r.count do print(r.entityId[i], r.axial[i], r.load[i]) end
local r = Physics.jointReactions(members); for i = 1, r.count do if r.load[i] > 0.8 then print(i, "near breaking") end end
local r = Physics.jointReactions(ids, { fields = { "axial", "load" } }); print(r.axial[1], r.load[1])
typed/builtin//modules/api/engine/physics/P/jointState
P.jointState(entityId: string | entityRef | table, name: string?) -> table?
Where an entity's joint stands as of the last physics step: the angle
of a hinge, the travel of a prismatic, the swing and twist of a ball
joint, whether it is at a limit, and the force its limit and motor
applied. axes holds the same for each axis of the joint's frame (the
frame's X along the joint's axis). Angles are degrees, angular
velocities radians per second, travels metres.
Parameters
entityIdstring | entityRef | table— Entity carrying the Joint component, or aJointcomponent.namestring(optional) — The Joint's name on that entity, for one of several joints; omit for its unnamed Joint.
Returns table? — { kind, angle?, offset?, swing?, twist?, velocity?, atLimit, limitForce, motorForce, distance, length?, slipping, axes }, or nil while the entity owns no built joint. A rail adds where its point stands on its path: progress (metres from the path's start), speed (m/s along it, positive toward its end), length, closed, laps (times round a loop, signed), onPath (false once it ran off an open end, left naming which), atEnd ("start" / "end" while a capped end holds it), offset (metres off the path), railMotorForce / frictionForce (newtons along the path, signed), tangent, normal (toward the bend's centre) and curvature (1/m). angle (hinge, degrees) or offset (prismatic, metres) with its velocity; swing / twist (ball, degrees); atLimit is true while any limit holds the joint at a bound or pushes on it; limitForce / motorForce are the largest force or torque a limit / the motor applied; distance is metres between the anchors; length (rope) is the rope's length as it stands, its maxDistance grown by whatever it paid out at its yieldForce; slipping is true when the joint gave way at its yieldForce / yieldTorque over the last step; axes.<linX..angZ> = { position, velocity, locked, limited, min, max, atLimit, limitForce, motorized, motorForce } with angles in degrees. articulated is true for a link of an articulation, whose limitForce and motorForce (and each axis') are nil: its limits and motors act on its coordinates, and their forces are not measured.
local s = Physics.jointState(door); print(s.angle, s.atLimit)
if Physics.jointState(elbow).atLimit then playSound("creak") end
typed/builtin//modules/api/engine/physics/P/listenContacts
P.listenContacts(target: (string | entityRef)?, opts: PhysicsContactOptions?) -> () -> ()
Start keeping an entity's collision and contact events for polling:
from now on every event of the kinds opts names is kept for
Physics.contactEvents(target) to read, and the hardest hit it takes for
Physics.contactPeak(target), however many physics steps run between two
reads. Keeps the most recent 1024 events per target. Calling it again for
the same target replaces the options. The events stop being kept when the
returned function runs, or when the component that called it is removed
or its entity destroyed.
Parameters
target(string | entityRef)(optional) — The entity whose events to keep, ornilfor every contact in the world.optsPhysicsContactOptions(optional) —PhysicsContactOptions, asonContacttakes it.
Returns () -> () — A function that stops keeping them and drops what was kept.
local stop = Physics.listenContacts(body, { minImpulse = 100 })
for _, e in Physics.contactEvents(body) do if e.kind == "impact" then print(e.other, e.impulse) end end
typed/builtin//modules/api/engine/physics/P/listenJointLoads
P.listenJointLoads(targets: any?, listen: boolean?)
Keep the peak load of joints between reads: from the next physics
step on, every step offers its load to each joint's peak, and
Physics.jointReaction(..).peak and the peak* arrays of
Physics.jointReactions take it, so a load that crossed a threshold for
one step and fell back is still read however many steps ran between two
reads. Only listened joints (and breakable ones) are measured every step.
Listening ends when listen is false or the joint's entity is gone.
Parameters
targetsany(optional) — AJoint, an entity (every joint its body is in), or an array of Joints and entities.listenboolean(optional) — True (the default) to keep the peak, false to stop.
Physics.listenJointLoads(bridgeJoints)
local r = Physics.jointReaction(cable); if r and r.peak and r.peak.load > 1 then print("overloaded at step", r.peak.step) end
typed/builtin//modules/api/engine/physics/P/loadReplay
P.loadReplay(data: string) -> PhysicsReplayInfo
Take a recording Physics.saveReplay wrote in place of the one held,
stopping a recording that runs and ending the replay; play it with
Physics.playReplay. It names its entities by id, so it plays over the
scene it was recorded in.
Parameters
datastring— The stringPhysics.saveReplayreturned.
Returns PhysicsReplayInfo — A PhysicsReplayInfo.
local data = vfs.read("/source/replays/crash.replay"); if data then Physics.loadReplay(data); Physics.playReplay({ rate = 0.5 }) end
typed/builtin//modules/api/engine/physics/P/loadSnapshot
P.loadSnapshot(source: string | buffer) -> PhysicsSnapshot
Read back a snapshot snapshot:save(path) wrote, or the bytes
snapshot:bytes() gave, on this engine or another one (native or
browser) holding the same bodies. The bytes are a versioned
little-endian format, the same on every platform. Returns a snapshot
Physics.restore takes.
Parameters
sourcestring | buffer— A VFS path the snapshot was saved to, or its bytes as a buffer.
Returns PhysicsSnapshot — The snapshot.
local s = Physics.loadSnapshot("/zero/source/saves/bridge.physics"); Physics.restore(s)
typed/builtin//modules/api/engine/physics/P/measureSoftBody
P.measureSoftBody(softId: string | entityRef, test: { [string]: any }) -> PhysicsSoftMeasurement?
Measure how a soft body responds to a stated load, without building a
rig: a copy of it, built from its component as authored, is pressed
between two plates, sent at a speed into a post or a wall, or dropped onto
a floor, in a world of its own at the tick and solver iterations the
world's settings state (in edit mode as in play), and every step is sampled: force against displacement, its
energy and what it absorbed. The live body is untouched. A press answers
its initial stiffness (N/m), peakForce, the work under the loading
curve and the permanentSet; an impact the crush, peakForce,
peakDeceleration, rebound and the share of its energy it absorbed
(absorbedShare); a drop the same against the height. Tune a material
toward "takes X kJ over Y m" with it, then build the body.
Parameters
softIdstring | entityRef— The soft body's entity.test{ [string]: any }— One load:{ press = { depth, axis?, speed?, hold?, settle?, friction? } }(axis "x", "y" or "z" in the body's own frame, default "y"; speed default depth / 2 s; frictionless plates unlessfrictionsays otherwise),{ impact = { speed, direction?, radius?, offset?, carried?, duration?, friction? } }(direction default "-z", a post ofradiusmetres or a wall when it is left out,carriedkilograms on a rigid block held to its trailing face) or{ drop = { height, duration?, friction? } }.
Returns PhysicsSoftMeasurement? — A PhysicsSoftMeasurement, or nil when nothing in the scene answers to that id. Its stability is the measured copy's stability report at the rate the test ran, so a body added in the same call reads one too. A test the body cannot run (a field out of range, a press deeper than the body, a mesh body whose model has not been filled yet) raises an error naming why. A body added in the same call is measured as its component builds it at the entity's pose and scale.
local m = Physics.measureSoftBody(block, { press = { depth = 0.05 } }); print(m.stiffness, m.work, m.absorbed)
local m = Physics.measureSoftBody(nose, { impact = { speed = 15, radius = 0.1, carried = 700 } }); print(m.crush, m.rebound, m.absorbedShare, m.peakDeceleration / 9.81)
local m = Physics.measureSoftBody(crate, { drop = { height = 2 } }); print(m.absorbed, m.elastic, m.dissipated, m.gravityWork)
typed/builtin//modules/api/engine/physics/P/motionPeak
P.motionPeak(target: string | entityRef, name: string?) -> PhysicsMotionSample?
The sample with the largest g-force (proper acceleration) a motion
probe took since the last call for it: the hardest moment of a crash, a
hit or a turn. Every sample counts, whether or not Physics.motionSamples
read it. Reading starts the next peak afresh.
Parameters
targetstring | entityRef— The probed entity.namestring(optional) — The probe's name, whenPhysics.probeMotiongave it one.
Returns PhysicsMotionSample? — A PhysicsMotionSample, or nil when the probe took nothing since the last read or no probe has that target and name.
local peak = Physics.motionPeak(car, "seat"); if peak and peak.g > 20 then print("severe impact", peak.g) end
typed/builtin//modules/api/engine/physics/P/motionProbe
P.motionProbe(target: string | entityRef, name: string?) -> PhysicsMotionProbeInfo?
What a motion probe is doing: the rate it samples at (samples per second), the length of its latest sample, how many samples the latest physics step took, how many it keeps and how many wait to be read, how many it let go since it was placed, and whether it is bound to a body (with the reason when it is not: no entity carries the id, or the entity holds no body the probe can measure).
Parameters
targetstring | entityRef— The probed entity.namestring(optional) — The probe's name, whenPhysics.probeMotiongave it one.
Returns PhysicsMotionProbeInfo? — A PhysicsMotionProbeInfo, or nil when no probe has that target and name.
local info = Physics.motionProbe(car, "seat"); print(info.rate, "samples/s", info.dropped, "dropped")
typed/builtin//modules/api/engine/physics/P/motionSamples
P.motionSamples(target: string | entityRef, name: string?) -> { PhysicsMotionSample }
Every sample a motion probe took since the last call for it, oldest
first, each from the solver substep (or physics step) it was taken in,
however many steps ran between two calls: read it once a frame, or from
fixedUpdate, and nothing is missed. A sample carries the point's
velocity, acceleration, proper acceleration (what is felt), g-force,
angular velocity and angular acceleration, and its step, time and length.
Reading empties the list. Physics.motionProbe states the rate the
samples are taken at and how many were let go.
Parameters
targetstring | entityRef— The probed entity.namestring(optional) — The probe's name, whenPhysics.probeMotiongave it one.
Returns { PhysicsMotionSample } — An array of PhysicsMotionSample, empty when the probe took none since the last read or no probe has that target and name.
for _, s in Physics.motionSamples(car, "seat") do if s.g > 4 then print("hard hit", s.g, s.step) end end
local samples = Physics.motionSamples(ball); local last = samples[#samples]; if last then print(last.acceleration, last.g) end
typed/builtin//modules/api/engine/physics/P/observe
P.observe(entityId: (string | entityRef)?, opts: table?) -> PhysicsObservation?
Read the solver's own state — the world's accounting, and what it
holds for each body plus why it is not moving one. Every value comes off
the simulation rather than the Physics component, so a write the solver
refused or clamped reads back as what it kept. Answers in edit mode as
well as play mode.
Parameters
entityId(string | entityRef)(optional) — Report on this one entity. Omit for every body in the world.optstable(optional) —{ bodies: boolean?, contactPoints: boolean? }—bodies = falsebuilds the world accounting alone, andcontactPoints = falsekeeps each contact pair's normal, depth, impulse and point count while leaving out the individual points. Both default to true.
Returns PhysicsObservation? — A PhysicsObservation, or nil when entityId names nothing in the scene. bodies is an array, not a table keyed by entity id — each entry names its own entity in entity.
local o = Physics.observe(); for _, b in o.bodies do print(b.entity, b.stillness) end
local o = Physics.observe(id); print(o.bodies[1].stillness, o.bodies[1].stillnessDetail)
typed/builtin//modules/api/engine/physics/P/onAfterStep
P.onAfterStep(fn: (number, number) -> ()) -> () -> ()
Call fn at the end of every physics step from now on, at the
physics tick rate, however many steps a frame runs. It runs once the step
has integrated, after that step's collision events reached their
listeners (Physics.onContact, onImpact, onTrigger) and before
fixedUpdate, so a read here sees what this step left: positions,
velocities, Physics.jointReaction, Physics.contactPeak. Use it to
sample a trajectory step by step, measure energy, record a replay, or
react to a step's result. A force written here acts on the next step. One
engine call runs every hook. The hook ends the way an onBeforeStep hook
ends, and must not wait either.
Parameters
fn(number, number) -> ()— Receives(dt, step): the step's length in seconds and its number.
Returns () -> () — A function that removes this hook.
local samples = {}; local off = Physics.onAfterStep(function(dt, step) table.insert(samples, entity(ball).position.y) end)
typed/builtin//modules/api/engine/physics/P/onBeforeStep
P.onBeforeStep(fn: (number, number) -> ()) -> () -> ()
Call fn at the start of every physics step from now on, at the
physics tick rate (physics.tick_rate), however many steps a frame runs.
It runs after the step's force reset and before the step integrates, so a
force, torque, impulse or velocity written here acts on this very step,
and a read here (a position, a velocity, a raycast) sees the state the
step starts from. This is the place for a force that depends on where a
body is or how fast it moves: gravity toward a planet, a spring, a
thruster holding altitude, buoyancy, a PID controller, an active
ragdoll's balance. applyForce holds a force over the whole step the
way gravity is held; a pull that stands in for gravity (an orbit) or
drives an oscillation keeps its energy when it is given as the momentum
it makes over the step instead: Physics.applyImpulse(id, force * dt).
One engine call runs every hook, so one hook looping
over many bodies costs about what the loop costs. Runs while the gameplay
clock runs, on every engine that steps the world: under multiplayer push
only the bodies this peer simulates. The hook ends when the returned
function is called, or when the component that registered it is removed,
its entity destroyed or its code reloaded. A hook must not wait
(task.wait); spawn a task from it for work that does. The engine runs
the hooks of the engine thread's VM, so a worker job's call (a
jobs.dispatch entry) raises, naming the refusal.
Parameters
fn(number, number) -> ()— Receives(dt, step): the step's length in seconds and its number, thestepthe contact events of this step carry.
Returns () -> () — A function that removes this hook.
local off = Physics.onBeforeStep(function(dt) Physics.applyForce(ship, { 0, 9.81 * 500, 0 }) end)
Physics.onBeforeStep(function(dt) local p = entity(moon).position; local r = math.sqrt(p.x * p.x + p.y * p.y + p.z * p.z); local k = -GM * mass * dt / (r * r * r); Physics.applyImpulse(moon, { p.x * k, p.y * k, p.z * k }) end)
typed/builtin//modules/api/engine/physics/P/onContact
P.onContact(target: (string | entityRef)?, fn: (PhysicsContactEvent) -> (), opts: PhysicsContactOptions?) -> () -> ()
Call fn for each collision and contact event of an entity's colliders
from now on: on collision begin, while the two stay in contact, on
collision end, on an impact (a hit, by how hard it lands), and on a
trigger's enter and exit. Events are recorded by the physics step itself
and fn runs once per step, before that step's fixedUpdate, so an
impact that lasts one step is heard even when a frame runs several steps.
The listener ends when the returned function is called, or when the
component that registered it is removed or its entity destroyed. Only the
colliders somebody listens to cost the step anything. Use it to detect a
hit, a landing, two things touching or parting, or a body in a zone.
Parameters
target(string | entityRef)(optional) — The entity whose contacts to hear: a body (every collider it is built from), a collider's own entity, a trigger, a soft body.nilhears every contact in the world.fn(PhysicsContactEvent) -> ()— Receives onePhysicsContactEventper event, seen fromtarget:{ kind, step, entity, other, collider, otherCollider, removed, otherRemoved, trigger, normal, closingSpeed, impulse, tangentImpulse, peakImpulse, totalImpulse, steps, pointCount, points }. The "end" a destroyed entity causes names it by the id it went by, withotherRemovedtrue.optsPhysicsContactOptions(optional) —PhysicsContactOptions:{ kinds?, minImpulse?, minSpeed? }.kindsdefaults to begin, end, enter and exit, plus impact whenminImpulseis given; add "persist" for an event on every step of a contact.
Returns () -> () — A function that removes this listener.
local off = Physics.onContact(ball, function(e) if e.kind == "begin" then print("hit", e.other, e.closingSpeed) end end)
Physics.onContact(nil, function(e) print(e.kind, e.entity, e.other) end, { kinds = { "begin", "end" } })
Physics.onContact(public.entityId, function(e) log.info(`{e.kind} with {e.other}`) end)
typed/builtin//modules/api/engine/physics/P/onImpact
P.onImpact(target: (string | entityRef)?, fn: (PhysicsContactEvent) -> (), opts: PhysicsContactOptions?) -> () -> ()
Call fn for every impact (a collision hit) on an entity from now on:
the physics step on which the normal impulse between it and something it
touches rises past minImpulse newton-seconds. Each impact is heard once,
on the step it lands, with the impulse of that step (impulse, N s; a
rigid stop of mass m from speed v is m * v), how fast the two were closing
as they met (closingSpeed, m/s) and where (points); the impulse divided
by the step's time is the mean impact force over it. Use it to detect a hit
and answer it: damage, impact sounds, fall damage, scoring, breaking things.
Runs once per physics step, before that step's fixedUpdate.
Parameters
target(string | entityRef)(optional) — The entity to hear impacts on, ornilfor every impact in the world.fn(PhysicsContactEvent) -> ()— Receives onePhysicsContactEvent(kind "impact") per impact.optsPhysicsContactOptions(optional) —{ minImpulse?, minSpeed? }: the impulse an impact must reach (default 0, the step a pair first takes any load) and the closing speed it must reach.
Returns () -> () — A function that removes this listener.
Physics.onImpact(box, function(e) print("hit by", e.other, e.impulse, "N s at", e.closingSpeed, "m/s") end, { minImpulse = 50 })
Physics.onImpact(player, function(e) if e.closingSpeed > 12 then takeFallDamage(e.closingSpeed) end end)
typed/builtin//modules/api/engine/physics/P/onJointBreak
P.onJointBreak(fn: (table) -> ()) -> () -> ()
Call fn for every joint that breaks from now on, with the same record
jointBreaks returns.
Parameters
fn(table) -> ()— Receives one break record per broken joint.
Returns () -> () — A function that removes this listener.
local off = Physics.onJointBreak(function(e) print(e.kind, e.force, e.position) end)
typed/builtin//modules/api/engine/physics/P/onLatch
P.onLatch(target: (string | entityRef)?, fn: (PhysicsLatchEvent) -> ()) -> () -> ()
Call fn each time two Latch points latch from now on: a hitch takes
its coupler, two train cars couple, a ship docks, a door catches. A step
latches two points that accept each other's tags when they come within
reach turned within their maxAngle and closing no faster than their
maxSpeed, and joins them with the joint the Latch states. fn runs once
per latch, on the peer that simulates both bodies, after the step that
made it and before its fixedUpdate, with the joint already made.
Parameters
target(string | entityRef)(optional) — The entity whose Latch point to hear, seen from it;nilhears every latch in the world once, seen from its host.fn(PhysicsLatchEvent) -> ()— Receives{ kind = "latch", latch, other, host, joint, position, distance, angle, speed, step }:latchthe point heard andotherthe one it latched to,hostthe point whose entity carries the joint,jointthatJoint(every joint read takes it),positionmidway between the points,distancemetres andangledegrees apart,speedm/s they closed at.
Returns () -> () — A function that removes this listener.
local off = Physics.onLatch(trailer, function(e) print("hitched to", e.other, e.distance) end)
Physics.onLatch(nil, function(e) print(e.latch, "latched", e.other, "at", e.speed, "m/s") end)
typed/builtin//modules/api/engine/physics/P/onSoftBodyTear
P.onSoftBodyTear(fn: (PhysicsSoftBodyTear) -> ()) -> () -> ()
Call fn for every tear of a soft body from now on: a body loaded past
its tearStrain or tearForce (fields of its SoftBody component), cut
by Physics.cutSoftBody or torn by Physics.tearSoftBody. The torn entity
keeps the largest piece; every piece split off is an entity of its own by
the time fn runs, standing at the root of the scene and carrying a
SoftBody with the torn body's fields, its share of the model and the
material, the velocity, dents and pins that fell on its side. Its body
joins it on the next frame, and an impulse applied to it in fn reaches
the body then. A piece is play state: it is left out of every save, and
leaving play takes it away and gives the torn entity back its whole body.
Parameters
fn(PhysicsSoftBodyTear) -> ()— Receives onePhysicsSoftBodyTearper tear:{ entity, pieces, position, kind, particles }.
Returns () -> () — A function that removes this listener.
local off = Physics.onSoftBodyTear(function(e) print(e.entity, #e.pieces, e.position) end)
Physics.onSoftBodyTear(function(e) for _, id in e.pieces do Physics.applyImpulse(id, { x = 0, y = 2, z = 0 }) end end)
typed/builtin//modules/api/engine/physics/P/onTrigger
P.onTrigger(target: (string | entityRef)?, fn: (PhysicsContactEvent) -> ()) -> () -> ()
Call fn when a body enters or leaves a trigger from now on (on
trigger enter, on trigger exit). A trigger is a collider with isTrigger
set: it holds nothing up and reports what overlaps it, whether it stands
alone or rides a body, and it detects dynamic and kinematic bodies alike.
A fixed trigger leaves out the fixed geometry it stands in, such as the
floor under a zone. An entity with no body of its own is heard by the
volume stated for it (Physics.setWaterVolume), standing where its
transform puts it: a CharacterController states its capsule, so the
player walking into a zone or over a pickup enters and leaves it.
Parameters
target(string | entityRef)(optional) — The trigger's entity, or the entity whose trigger overlaps to hear;nilhears every trigger in the world.fn(PhysicsContactEvent) -> ()— Receives onePhysicsContactEventper enter ("enter") and exit ("exit"), seen fromtarget, withotherthe entity that entered or left. An entity destroyed inside the trigger leaves it with an "exit" naming the id it went by,otherRemovedtrue.
Returns () -> () — A function that removes this listener.
Physics.onTrigger(zone, function(e) if e.kind == "enter" then print(e.other, "entered") end end)
Physics.onTrigger(coin, function(e) if e.kind == "enter" and e.other == layers.active.players.localPlayer.avatar.id then print("collected") end end)
typed/builtin//modules/api/engine/physics/P/onUnlatch
P.onUnlatch(target: (string | entityRef)?, fn: (PhysicsLatchEvent) -> ()) -> () -> ()
Call fn each time two latched Latch points come apart from now on:
released (Physics.releaseLatch, a Latch's :release(), or the latch's
Joint taken off with Physics.removeJoint), broken (the latch joint's
breakForce / breakTorque exceeded), or removed (a point or its entity
went away). A freed point latches again once it has stood
clear of every point it latches to.
Parameters
target(string | entityRef)(optional) — The entity whose Latch point to hear, seen from it;nilhears every unlatch once.fn(PhysicsLatchEvent) -> ()— Receives{ kind = "unlatch", latch, other, reason, force?, torque?, position? }:reasonis "release", "break" (with the break'sforceN,torqueN m andposition), "removed", or "refused" (the latch's joint could not be made:errornames why).
Returns () -> () — A function that removes this listener.
Physics.onUnlatch(door, function(e) if e.reason == "break" then print("burst open at", e.force, "N") end end)
typed/builtin//modules/api/engine/physics/P/onWater
P.onWater(target: (string | entityRef)?, fn: (PhysicsWaterEvent) -> (), opts: { kinds: { string }? }?) -> () -> ()
Call fn each time an entity goes into or comes out of the water from
now on: any body of water Physics.defineWater defined, a Water
component, an ocean, a terrain's lakes and rivers. A body, a character, a
thrown object or a projectile goes in ("enter") on the physics step 1% or
more of it stands under the surface, and comes out ("exit") on the step
no part of it does, so a body floating or bobbing at the surface stays in
until it leaves the water whole and raises nothing while it bobs. An
entity destroyed while in the water, or one no listener watches any more,
comes out on that step, at the surface it stood in, so every entry is
followed by one exit (a count of what is in the pool stays right). The
event carries where it crossed the surface, how fast (normalSpeed, the
speed into the water along the surface normal at the moment it met the
surface: a ball dropped from 5 m enters at 9.9 m/s) and which water. The
step measures it however fast it moves, and fn runs once per step,
before that step's fixedUpdate. Use it for splashes and splash sounds,
wet footsteps, a swim state, a fish taking a bait, a boat taking on
water, scoring a dive, a water hazard. The listener ends when the
returned function is called, or when the component that registered it is
removed or its entity destroyed. An entity is measured by the volume
Physics.setWaterVolume states (a CharacterController states its
capsule), else its rigid body, else its own collider, else its origin.
Physics.immersion reads how much of it is under at any time.
Parameters
target(string | entityRef)(optional) — The entity to watch, ornilfor every dynamic and kinematic body and every character in the world.fn(PhysicsWaterEvent) -> ()— Receives onePhysicsWaterEventper entry or exit:{ kind, step, entity, water, point, normal, normalSpeed, velocity, submerged, depth }.opts{ kinds: { string }? }(optional) —{ kinds? }: the kinds to hear, default both "enter" and "exit".
Returns () -> () — A function that removes this listener.
Physics.onWater(ball, function(e) if e.kind == "enter" then print("splash at", e.point, e.normalSpeed, "m/s") end end)
Physics.onWater(nil, function(e) log.info(`{e.entity} {e.kind} {e.water}`) end)
local off = Physics.onWater(player, function(e) swimming = e.kind == "enter" end)
typed/builtin//modules/api/engine/physics/P/orbitVelocity
P.orbitVelocity(point: vec3, centre: vec3, axis: vec3?, groups: number?) -> vec3
The velocity that carries a body on a circular orbit through point
about centre, under the gravity at point (Physics.gravityAt): the
speed sqrt(pull * r) from the pull toward centre there and the
distance r to it, across the radius and axis (the orbit's own axis,
default +Y, the orbit then lying level). Set it on a moon, a satellite or
a slingshot projectile and a GravityField toward centre keeps it
going round. Errors when nothing pulls toward centre at point, or
when axis runs along the radius. A GravityField added this frame
stands in the physics world from the next step, so an orbit set up in
the same script as its planet is started from Physics.onBeforeStep.
Parameters
pointvec3— Where the orbit passes, in world space.centrevec3— What it goes round: the field's centre (a planet's position).axisvec3(optional) — The axis the orbit turns about. Default: +Y.groupsnumber(optional) — The collision membership of the orbiting body, as a bitmask. Default: every group.
Returns vec3 — The velocity, in m/s.
local v = Physics.orbitVelocity(entity(moon).position, entity(planet).position); Physics.setVelocity(moon, v)
typed/builtin//modules/api/engine/physics/P/overlapSphere
P.overlapSphere(center: vec3, radius: number) -> { string }
Find every entity id whose colliders overlap a sphere.
A trigger (isTrigger) holds nothing up, so it is left out.
Many overlaps a frame: Physics.castMany answers them all in one call.
Parameters
centervec3— Sphere center in world space.radiusnumber— Sphere radius.
Returns { string } — Array of overlapping entity ids: a collider on a body is named by the entity standing for that body, once however many of its colliders overlap, and a collider with no body (static world geometry such as the ground) by its own entity. Each id is what the push verbs take.
local ids = Physics.overlapSphere({x=0,y=0,z=0}, 5)
typed/builtin//modules/api/engine/physics/P/passThrough
P.passThrough(entityId: string | entityRef, throughId: (string | entityRef)?)
Let a rigid body standing on one-way colliders drop through them (a
platformer's "down + jump"). A collider is one-way when its oneWay
field names the direction bodies pass through it along; on the next
physics step every one-way collider the body touches, or with throughId
only those that entity owns, stops holding it, and the body falls
through until it is clear. A one-way collider it reaches afterwards
holds it as before. Wakes the body. The entity's rigid body (a Physics
component, or a ragdoll's bones) is what drops. An entity with no rigid
body is a mover the engine moves by casts (a CharacterController):
every cast made for it (options.mover of Physics.raycast and the
shape casts) passes the one-way colliders it stands on (its own collider,
or its origin, within 0.1 m of them or inside them) until it is clear of
each, so it falls through them under its own gravity.
Parameters
entityIdstring | entityRef— The body that drops through: entity id or proxy.throughId(string | entityRef)(optional) — Optional entity id or proxy: drop through only its one-way colliders.
Physics.passThrough(player)
Physics.passThrough(player, entity("ledge"))
typed/builtin//modules/api/engine/physics/P/pinSoftRegion
P.pinSoftRegion(softId: string | entityRef, region: PhysicsSoftRegion?, opts: { name: string?, target: vec3? }?) -> string
Pin a region of a soft body: its particles are held kinematic, where
they stand now, and the rest of the body hangs from them, rests on them
or swings about them through its elastic elements. A cloth pinned by two
corners hangs; a jelly pinned along its base stays put while its top
wobbles. Give the pin a target (or set one later with
Physics.setPinTarget) and the pinned particles move together so their
centre stands there, dragging the body after them: a hand grabbing a
corner, a press driven down into a block. The pin is an entry of the soft
body's SoftBody component (pins), so it is saved with the scene,
reaches every peer and is made again on a rebuilt body; it reads back
from Physics.softBodyState(softId).pins.
Parameters
softIdstring | entityRef— The soft body's entity (it carries aSoftBodycomponent).regionPhysicsSoftRegion(optional) — Which particles to pin, asPhysics.softRegiontakes it:{ box = { min, max } }or{ nearest = point }in the entity's unit box (-0.5 to 0.5 on each axis),space = "world"for world coordinates; nil pins the whole body.opts{ name: string?, target: vec3? }(optional) —{ name: string?, target: vec3? }: the name the pin is addressed by (by defaultpin1,pin2, ...), and a world position to move the pinned particles' centre to.
Returns string — The pin's name.
local corner = Physics.pinSoftRegion(cloth, { nearest = {-0.5, 0, 0.5} })
Physics.pinSoftRegion(cloth, { box = { min = {-0.5, -1, 0.45}, max = {0.5, 1, 0.5} } }, { name = "top" })
local grab = Physics.pinSoftRegion(jelly, { nearest = hit.point, space = "world" }, { target = hit.point })
typed/builtin//modules/api/engine/physics/P/planeHold
P.planeHold(entityId: string | entityRef) -> PhysicsPlaneHold?
Which plane holds a body, and where the hold comes from: the
PlaneHold covering the body (on its entity or an ancestor, a group
hold over its collision groups, or a world hold), as the physics world
applied it. A rigid or a soft body answers alike.
Parameters
entityIdstring | entityRef— Entity id or proxy of a body.
Returns PhysicsPlaneHold? — A PhysicsPlaneHold (normal, point, holder, covers), or nil when no hold holds the body (or nothing in the scene answers to that id).
local h = Physics.planeHold(crate); if h then print(h.holder, h.covers, h.normal.z) end
typed/builtin//modules/api/engine/physics/P/playReplay
P.playReplay(opts: (table | boolean)?) -> PhysicsReplayInfo
Play the recorded replay back, or steer the one playing: slow motion,
fast forward, reverse, a jump to a recorded second (scrubbing), a loop.
Every recorded entity is drawn where it was at the replay's time, blended
between the recorded steps either side of it; whatever is parented under
a body (wheels, its model) moves with it, a soft body takes the shape its
recorded particles held, and a ragdoll's bones their recorded poses. The
replay draws and nothing more: the live simulation holds still while
gameplay is paused (engine.paused = true) or steps on underneath while
it runs, and every read of it (entity.position, velocities,
Physics.stateDigest) answers the live state, so the simulation is
exactly where it was when the replay ends. Physics.drawnPose answers
the replayed pose (replayed = true), so a camera following a body's
drawn pose follows it through the replay, and any camera can watch it.
The replay moves on the frame clock at rate recorded seconds per
second, whatever engine.timeScale is, and stops at the end it runs to
unless it loops. Pass false to end it: everything is drawn where the
simulation holds it again.
Parameters
opts(table | boolean)(optional) —{ rate?, time?, loop? }:rate(1 by default, -64 to 64) in recorded seconds per second: 0.25 for quarter-speed slow motion, negative to play backwards, 0 to hold a moment;timejumps to that recorded second (Physics.replayInfo().fromto.to);loop = truewraps around. A replay started with notimestarts at the first recorded step, or the last for a negative rate. Fields left out keep what the playing replay has.falseends the replay.
Returns PhysicsReplayInfo — A PhysicsReplayInfo, with the replay's time and rate.
engine.paused = true; Physics.playReplay({ rate = 0.25 })
local info = Physics.replayInfo(); Physics.playReplay({ time = info.to - 2, rate = 0 })
Physics.playReplay({ rate = -1 })
Physics.playReplay(false); engine.paused = false
typed/builtin//modules/api/engine/physics/P/probeMotion
P.probeMotion(target: string | entityRef, opts: PhysicsMotionProbeOptions?) -> () -> ()
Place a motion probe: a measuring point on a body (an accelerometer, a
g-force sensor) whose velocity, acceleration, angular velocity and angular
acceleration the physics step samples, for Physics.motionSamples and
Physics.motionPeak to read. On a rigid body it measures a point of the
body, the rotation terms (centripetal and tangential acceleration)
included, at every solver substep: the rate the solver actually steps the
body, which rises when the body's island runs extra substeps. A step the
solver does not move the body in (asleep, settled) takes one sample. On a
soft body it measures a region's particles, their velocity averaged by
mass, at the same rate: a hit soft body's extra substeps are each sampled.
Each sample also
reads the proper acceleration, what a rider or sensor at the point feels
(0 g in free fall, 1 g at rest), and its size in g. Use it for g-force
readouts, impact severity, crash and hit strength, controller haptics,
flight and roller-coaster feel, and telemetry. A body with no probe costs
nothing. The probe follows the entity id across a mode switch or a
respawn, and each new body it measures (play starting, a respawn) starts
its record afresh: the samples, the peak and the clock. It ends when the
returned function runs or the component that placed it is removed or its
entity destroyed. Placing it again with the same name replaces its
options and keeps what it recorded.
Parameters
targetstring | entityRef— The entity whose body to measure: a rigid body, or withopts.regiona soft body.optsPhysicsMotionProbeOptions(optional) —PhysicsMotionProbeOptions:{ point?, region?, name?, capacity?, substeps? }.
Returns () -> () — A function that removes the probe and drops what it kept.
local stop = Physics.probeMotion(car, { point = {0, 0.6, -0.3}, name = "seat" })
Physics.probeMotion(ball)
Physics.probeMotion(dummy, { region = { nearest = {0, 0.4, 0} }, name = "head" })
typed/builtin//modules/api/engine/physics/P/pumpContactEvents
P.pumpContactEvents()
Deliver every collision and contact event the physics steps recorded
since the last delivery to the onContact, onImpact and onTrigger
listeners and the lists listenContacts keeps. The engine calls this
after every physics step that recorded any, before that step's
fixedUpdate, so listeners hear each step's events at the physics rate.
Physics.pumpContactEvents()
typed/builtin//modules/api/engine/physics/P/pumpJointBreaks
P.pumpJointBreaks()
Deliver every joint break the simulation has recorded to the registered
listeners. The engine calls this after every physics step that broke a
joint, before that step's fixedUpdate, so listeners hear each break at
the physics rate whichever way the joint was made.
Physics.pumpJointBreaks()
typed/builtin//modules/api/engine/physics/P/pumpLatches
P.pumpLatches()
Deliver every latch the simulation made since the last delivery: join
each latched pair of Latch points with its joint and run the listeners
Physics.onLatch / Physics.onUnlatch registered. The engine calls this
after every physics step that latched or freed a point, before that
step's fixedUpdate, so the step that follows holds the joint.
Physics.pumpLatches()
typed/builtin//modules/api/engine/physics/P/pumpSoftBodyTears
P.pumpSoftBodyTears()
Give every piece the soft bodies tore off since the last call its
entity, and deliver each tear to the onSoftBodyTear listeners. Every
SoftBody component calls this each frame, so tears are handled on their
own; the work is done once per frame however many call it.
Physics.pumpSoftBodyTears()
typed/builtin//modules/api/engine/physics/P/pumpWaterEvents
P.pumpWaterEvents()
Deliver every entry into and exit from the water the physics steps
recorded since the last delivery to the Physics.onWater listeners. The
engine calls this after every physics step that recorded any, before
that step's fixedUpdate, so listeners hear each one at the physics rate.
Physics.pumpWaterEvents()
typed/builtin//modules/api/engine/physics/P/raycast
P.raycast(origin: vec3, direction: vec3, maxDistance: number?, exclude: (string | {string})?, options: PhysicsCastOptions?) -> PhysicsHit?
Cast a ray and return the first hit. Answers from COLLIDERS ALONE: a
mesh that renders but carries no collider is not in the physics world, so a
ray fired through it reports the same nil a ray through open air does.
renderer.raycast answers the same ray against the geometry the renderer
DRAWS, which is what reads the surface of a terrain, a procedurally
generated mesh, or any plain Model.
A trigger (isTrigger) holds nothing up, so the ray passes through it.
Many rays a frame (a crowd's sight lines, a flock's probes, many
projectiles): Physics.castMany answers them all in one call.
Parameters
originvec3— Ray origin in world space.directionvec3— Ray direction, of any length: the engine normalises it, somaxDistanceanddistanceare world units.maxDistancenumber(optional) — Maximum distance along the ray (defaults to 1000).exclude(string | {string})(optional) — Optional entity id, or array of entity ids, to exclude from hits.optionsPhysicsCastOptions(optional) — OptionalPhysicsCastOptions:{ mover = entity }casts for the entity the cast moves (a character controller, or anything moved by casts), so it meets colliders as that entity's body does: a one-way collider (oneWay) answers only on the face its direction points out of, to a cast that starts outside it; a collider whosecontactTagthe contact filter answers "ignore" or "sensor" with a tag of the mover's own colliders is passed; and the one-way collidersPhysics.passThrough(mover)drops the mover through are passed until it is clear of them.
Returns PhysicsHit? — Hit table { entityId, body, bodyType, point, normal, distance, startedInside, softBody?, surface?, surfaceVelocity? }, or nil if nothing hit. body is the id of the entity standing for the body the collider belongs to: the body's own entity when the collider was authored on a child entity (a part of a vehicle or an assembled prop, which composes onto its ancestor's body), and the collider's own entity for static world geometry that rides no body, such as the ground. bodyType is that body's kind ("dynamic", "static", "kinematic", "kinematicVelocity" or "soft"; "static" for static world geometry). The push verbs take body and entityId alike. startedInside is false for a surface the query crossed on its way there, and true when the query's own start already lay inside that collider — where distance is 0, point is the start itself, and normal is the shortest way out of the collider. normal is a unit vector either way. surface names the surface the collider is made of where the query met it (Physics.defineSurface; on a heightfield whose samples name layers, the layer of the sample nearest the point), and is absent for a collider naming none. surfaceVelocity is the collider's surfaceVelocity in world space (m/s), the motion its surface carries what stands on it with, and is absent for a collider whose surface holds still. softBody is set when what was hit is a soft body, whose surface the query meets as it is deformed now: a PhysicsSoftHit naming the surface triangle, the particles carrying it with the hit's weight on each, the particle nearest the hit, and region, the hit as a soft region to hand to Physics.applyImpulse, Physics.pinSoftRegion or Physics.softParticles. Physics.applyImpulseAtPoint takes the hit's point as it is. A nil says the ray met no COLLIDER, which Physics.colliderCount() separates from a world that holds none for it to meet.
local hit = Physics.raycast({x=0,y=2,z=0}, {x=0,y=-1,z=0})
local hit = Physics.raycast(origin, dir, 50, { selfId, carriedId })
local ground = Physics.raycast(feet, {x=0,y=-1,z=0}, 0.3, selfId, { mover = selfId })
local hit = Physics.raycast(muzzle, aim, 100); if hit and hit.softBody then Physics.applyImpulseAtPoint(hit.entityId, {x=0, y=0, z=-20}, hit.point, { radius = 0.3 }) end
if Physics.colliderCount() == 0 then hit = renderer.raycast(eye, down, 200) end
typed/builtin//modules/api/engine/physics/P/raycastAll
P.raycastAll(origin: vec3, direction: vec3, maxDistance: number?, maxHits: number?, exclude: (string | {string})?, options: PhysicsCastOptions?) -> { PhysicsHit }
Cast a ray and return every hit up to maxHits. Answers from COLLIDERS
ALONE, so a rendered mesh with no collider is absent from the result;
renderer.raycastAll answers the same ray against the geometry the
renderer draws.
A trigger (isTrigger) holds nothing up, so the ray passes through it.
Parameters
originvec3— Ray origin in world space.directionvec3— Ray direction, of any length: the engine normalises it, somaxDistanceanddistanceare world units.maxDistancenumber(optional) — Optional distance limit along the ray.maxHitsnumber(optional) — Optional cap on the number of hits returned.exclude(string | {string})(optional) — Optional entity id, or array of entity ids, to exclude from hits.optionsPhysicsCastOptions(optional) — OptionalPhysicsCastOptions:{ mover = entity }casts for the entity the cast moves (a character controller, or anything moved by casts), so it meets colliders as that entity's body does: a one-way collider (oneWay) answers only on the face its direction points out of, to a cast that starts outside it; a collider whosecontactTagthe contact filter answers "ignore" or "sensor" with a tag of the mover's own colliders is passed; and the one-way collidersPhysics.passThrough(mover)drops the mover through are passed until it is clear of them.maxHitscounts the hits the mover meets.
Returns { PhysicsHit } — Array of hit tables { entityId, body, bodyType, point, normal, distance, startedInside, softBody?, surface?, surfaceVelocity? }: empty when nothing was hit. body is the id of the entity standing for the body the collider belongs to: the body's own entity when the collider was authored on a child entity (a part of a vehicle or an assembled prop, which composes onto its ancestor's body), and the collider's own entity for static world geometry that rides no body, such as the ground. bodyType is that body's kind ("dynamic", "static", "kinematic", "kinematicVelocity" or "soft"; "static" for static world geometry). The push verbs take body and entityId alike. startedInside is false for a surface the query crossed on its way there, and true when the query's own start already lay inside that collider — where distance is 0, point is the start itself, and normal is the shortest way out of the collider. normal is a unit vector either way. surface names the surface the collider is made of where the query met it (Physics.defineSurface; on a heightfield whose samples name layers, the layer of the sample nearest the point), and is absent for a collider naming none. surfaceVelocity is the collider's surfaceVelocity in world space (m/s), the motion its surface carries what stands on it with, and is absent for a collider whose surface holds still. softBody is set when what was hit is a soft body, whose surface the query meets as it is deformed now: a PhysicsSoftHit naming the surface triangle, the particles carrying it with the hit's weight on each, the particle nearest the hit, and region, the hit as a soft region to hand to Physics.applyImpulse, Physics.pinSoftRegion or Physics.softParticles. Physics.applyImpulseAtPoint takes the hit's point as it is.
local hits = Physics.raycastAll(origin, dir, 50, 4)
typed/builtin//modules/api/engine/physics/P/raycastBetween
P.raycastBetween(fromId: string | entityRef, toId: string | entityRef, maxDistance: number?) -> PhysicsHit?
Cast a ray from one entity toward another and return the first hit. The ray runs from the source's world position toward the target's world position, wherever each sits in the hierarchy, and passes over the source's own colliders: those of the body it rides (its own body, or the body of its nearest ancestor carrying one) and of every entity riding that body. With nothing between them, the first hit is the target's collider.
Parameters
fromIdstring | entityRef— Origin entity, an id or a proxy.toIdstring | entityRef— Target entity, an id or a proxy.maxDistancenumber(optional) — Optional distance cap (default 1000).
Returns PhysicsHit? — PhysicsHit, or nil if the entities are coincident or nothing was hit before the target's position. Raises naming the argument when fromId or toId names no entity.
local hit = Physics.raycastBetween(a, b)
typed/builtin//modules/api/engine/physics/P/raycastScreen
P.raycastScreen(sx: number, sy: number, maxDistance: number?, exclude: (string | {string})?) -> PhysicsHit?
Cast a ray from a screen pixel into the scene and return the first hit. Unprojects the pixel with screenToRay, then casts with raycast.
Parameters
sxnumber— Screen X in the scene viewport's physical pixels, measured from the top-left of the rect the scene is drawn into: the space ofinput.snapshot().mouse_position,worldToScreenandscreenToRay. A point in the UI's logical points (a widget's position,ui.screenSize()coordinates) is carried here byui.toViewport(x, y).synumber— Screen Y in the same space assx.maxDistancenumber(optional) — Maximum distance along the ray (defaults to 1000, matchingraycast).exclude(string | {string})(optional) — Optional entity id, or array of entity ids, to exclude from hits.
Returns PhysicsHit? — Hit table { entityId, body, bodyType, point, normal, distance, startedInside, softBody?, surface?, surfaceVelocity? }, or nil on a miss or when no camera has rendered yet. body is the id of the entity standing for the body the collider belongs to: the body's own entity when the collider was authored on a child entity (a part of a vehicle or an assembled prop, which composes onto its ancestor's body), and the collider's own entity for static world geometry that rides no body, such as the ground. bodyType is that body's kind ("dynamic", "static", "kinematic", "kinematicVelocity" or "soft"; "static" for static world geometry). The push verbs take body and entityId alike. startedInside is false for a surface the query crossed on its way there, and true when the query's own start already lay inside that collider — where distance is 0, point is the start itself, and normal is the shortest way out of the collider. normal is a unit vector either way. surface names the surface the collider is made of where the query met it (Physics.defineSurface; on a heightfield whose samples name layers, the layer of the sample nearest the point), and is absent for a collider naming none. softBody is set when what was hit is a soft body, whose surface the query meets as it is deformed now: a PhysicsSoftHit naming the surface triangle, the particles carrying it with the hit's weight on each, the particle nearest the hit, and region, the hit as a soft region to hand to Physics.applyImpulse, Physics.pinSoftRegion or Physics.softParticles. Physics.applyImpulseAtPoint takes the hit's point as it is.
local Zin = require("@builtin::modules.zinput")
local x, y = Zin.state.mousePosition(); local hit = Physics.raycastScreen(x, y)
typed/builtin//modules/api/engine/physics/P/recordDigests
P.recordDigests(opts: (table | boolean)?) -> table
Record the state digest of every physics step from now on, as
Physics.stateDigest takes it when the step ends, keeping the most recent
steps of them for Physics.digestLog. Two engines that run the same
steps each record, then compare their logs with Physics.firstDivergence
to find the first step, body and field where their simulations parted.
A run repeated in the same engine, the first run despawned before it,
records the same steps as the first, so one engine checks a scene
against its own earlier run (Physics.stateDigest states the
conditions). Pass false to stop; what was recorded stays readable. Starting again
drops the earlier recording. The recording is the engine's, so a worker
job reads and changes the same one.
Parameters
opts(table | boolean)(optional) — ThePhysics.stateDigestoptions plussteps(600 by default, at most 100000). Each step keeps its entries (so a divergence names the body) unlessentries = false;values = truealso keeps the numbers (so it names the field).falsestops recording.
Returns table — { recording, steps, recorded }.
Physics.recordDigests({ steps = 1200, key = "name", values = true })
Physics.recordDigests(false)
typed/builtin//modules/api/engine/physics/P/recordReplay
P.recordReplay(opts: (table | boolean)?) -> PhysicsReplayInfo
Record a replay of the physics simulation from now on: at the end of
every step, the pose and velocities of each rigid body and ragdoll bone,
the pose and particles of each soft body, and each moment two of their
colliders begin or stop touching. It keeps the most recent seconds
inside maxBytes, dropping the oldest steps past either, so a game can
record all the time and play the last few seconds back on demand: an
instant replay, a crash replay, a kill cam, a ghost. Play it with
Physics.playReplay, read it with Physics.replayFrame and
Physics.replayContacts, keep it with Physics.saveReplay. Pass false
to stop; what was recorded stays to play. Starting again drops the earlier
recording. A recording belongs to the play session it ran in: leaving
play stops it and ends a replay, keeping what it holds. Recording runs
inside the step at the step rate, in play or
while Physics.advance steps; Physics.replayInfo reports its size, its
bytes per recorded second and what it costs a step.
Parameters
opts(table | boolean)(optional) —{ entities?, seconds?, maxBytes?, contacts? }:entities, an array of entity ids, records those entities (any body type), by default every entity whose body moves (dynamic and kinematic bodies, ragdoll bones, soft bodies);seconds(30 by default, at most 3600) is how much recent simulation it keeps;maxBytes(64 MiB by default, 64 KiB to 1 GiB) bounds its memory;contacts = falseleaves the contacts out.falsestops recording.
Returns PhysicsReplayInfo — A PhysicsReplayInfo.
Physics.recordReplay({ seconds = 10 })
Physics.recordReplay({ entities = { car, wall }, seconds = 5 })
Physics.recordReplay(false)
typed/builtin//modules/api/engine/physics/P/releaseLatch
P.releaseLatch(id: string | entityRef) -> boolean
Release the latch an entity's Latch point holds: its joint comes off,
both points are freed and Physics.onUnlatch hears reason "release". A
freed point latches again once it has stood clear of every point it
latches to, so pulling apart and backing in again re-latches. A latch with
lock = "permanent" on either point holds until its joint breaks or a
point is removed, and refuses, naming the point.
Parameters
idstring | entityRef— The entity carrying the Latch (either point of the pair).
Returns boolean — true when a latch was released, false when the point was free.
Physics.releaseLatch(trailerCoupler)
typed/builtin//modules/api/engine/physics/P/releasePin
P.releasePin(softId: string | entityRef, name: string?) -> number
Release a pin of a soft body, or every pin: its particles take their mass back, keep the velocity they had, and move with the body again.
Parameters
softIdstring | entityRef— The soft body's entity.namestring(optional) — The pin to release; omit to release every one.
Returns number — How many pins were released.
Physics.releasePin(cloth, corner)
Physics.releasePin(cloth)
typed/builtin//modules/api/engine/physics/P/removeCollider
P.removeCollider(entityId: string | entityRef) -> string?
Remove whichever collider component an entity carries.
Parameters
entityIdstring | entityRef— Target entity id.
Returns string? The component that was removed, or nil when there was none.
Physics.removeCollider(id)
typed/builtin//modules/api/engine/physics/P/removeConstraint
P.removeConstraint(entityId: string | entityRef, index: number?)
Remove transform constraints from an entity (if any are present).
Parameters
entityIdstring | entityRef— Target entity id.indexnumber(optional) — Optional constraint index (currently ignored — the whole component is removed).
Physics.removeConstraint(id)
typed/builtin//modules/api/engine/physics/P/removeJoint
P.removeJoint(entityId: string | entityRef | table, name: string?)
Remove one joint, leaving every other joint on its bodies standing:
the Joint an entity carries (its unnamed one, or the one name names),
or the Joint component given itself, as Physics.addJoint returns it.
Parameters
entityIdstring | entityRef | table— Target entity id, or aJointcomponent.namestring(optional) — The Joint's name on that entity; omit for its unnamed Joint.
Physics.removeJoint(id)
Physics.removeJoint(beam, "right")
local grab = Physics.addJoint(hand, crate); Physics.removeJoint(grab)
typed/builtin//modules/api/engine/physics/P/removeSurface
P.removeSurface(name: string)
Remove a surface Physics.defineSurface defined. Colliders naming it
keep the name and collide with their own coefficients from the next step.
Parameters
namestring— The surface's name.
Physics.removeSurface("ice")
typed/builtin//modules/api/engine/physics/P/removeWater
P.removeWater(name: string)
Remove a body of water Physics.defineWater defined.
Parameters
namestring— The body's name.
Physics.removeWater("pool")
typed/builtin//modules/api/engine/physics/P/removeWheelCollider
P.removeWheelCollider(entityId: string | entityRef)
Remove the WheelCollider component from an entity (if present).
Parameters
entityIdstring | entityRef— Target entity id.
Physics.removeWheelCollider(id)
typed/builtin//modules/api/engine/physics/P/removeWind
P.removeWind(name: string)
Remove a wind field Physics.defineWind defined.
Parameters
namestring— The field's name.
Physics.removeWind("breeze")
typed/builtin//modules/api/engine/physics/P/repairSoftBody
P.repairSoftBody(softId: string | entityRef) -> number
Restore the shape a soft body was built in: every permanent dent,
crumple and crease it took past its plasticYield is undone, and the body
is put back in that shape where it stands, keeping its motion as a whole. The repair is the
SoftBody component's repairs count raised by one, so it reaches every
peer. Physics.softBodyState(softId).plastic reads 0 once it is applied
(at the start of the next frame), and a Physics.setSoftParticles made
before then is put back in the built shape with the rest of the body.
Parameters
softIdstring | entityRef— The soft body's entity (it carries aSoftBodycomponent).
Returns number — The component's new repairs count.
Physics.repairSoftBody(shell)
typed/builtin//modules/api/engine/physics/P/replayContacts
P.replayContacts(opts: table?) -> { PhysicsReplayContact }
Read the contacts the replay recording kept, oldest first: each
moment two colliders of the recorded entities began (kind = "begin")
or stopped ("end") touching, the two entities by id, and for a begin
where they touched, the normal from a to b, the impulse and how fast
they were closing. A replay plays its sounds and sparks at these moments.
Parameters
optstable(optional) —{ from?, to? }: the recorded seconds to read between (inclusive).
Returns { PhysicsReplayContact } — An array of PhysicsReplayContact.
for _, c in Physics.replayContacts() do if c.kind == "begin" then print(c.time, c.a, c.b, c.impulse) end end
typed/builtin//modules/api/engine/physics/P/replayFrame
P.replayFrame(opts: table?) -> PhysicsReplayFrame?
Read the recorded state at one recorded second, blended between the steps either side of it the way a replay draws it: a plot synced to a replay's timeline, a ghost placed at a recorded pose, a check that what was drawn is what was recorded.
Parameters
optstable(optional) —{ time?, velocities? }:time(the playing replay's time, else the last recorded step) is held inside the recording;velocities = trueadds each body'slinvel/angveland each soft body's particlevelocities.
Returns PhysicsReplayFrame? — A PhysicsReplayFrame, or nil when nothing was recorded.
local f = Physics.replayFrame({ time = 1.5 }); print(f.bodies[car].position.y)
typed/builtin//modules/api/engine/physics/P/replayInfo
P.replayInfo() -> PhysicsReplayInfo
What the replay recording holds and what the replay playing it does:
whether it is recording and playing, the recorded seconds it spans
(from, to, duration), its steps and stepRate, what its last step
holds (bodies, bones, softBodies, particles), the contacts it
keeps, its memory (bytes, and bytesPerSecond per recorded second),
and what recording took a step (recordMs mean, recordMsMax). While a
replay plays: its time, rate, loop, ended once it ran to an end,
and missing, the keys of the recorded tracks the scene holds nothing to
draw on (an entity id or ragdoll bone it does not hold, or a soft body of
another particle count), which stay drawn where the live simulation holds
them.
Returns PhysicsReplayInfo — A PhysicsReplayInfo.
local info = Physics.replayInfo(); print(info.duration, info.bytesPerSecond, info.recordMs)
typed/builtin//modules/api/engine/physics/P/restore
P.restore(snapshot: PhysicsSnapshot) -> PhysicsRestore
Put the physics simulation back to a snapshot Physics.snapshot took
or Physics.loadSnapshot read: bodies, joints, soft bodies, contacts,
each entity's transform and velocity, and the settings of every
component the solver is built from stand as they stood, so a setting
written since reads back the snapshot's value, the value the solver
simulates with, and the next steps
run exactly as they ran from it. A joint that broke since comes back, and
a wheel that came off its vehicle since goes back on. The
world has to hold the bodies the snapshot was taken over (the same
entities with the same bodies, colliders, soft bodies and joints,
whatever order the world built them in); the restore is refused,
changing nothing, when an entity it holds is gone, an entity has a body
it does not hold (made since: remove it first) or an entity's bodies,
colliders or soft body differ from the snapshot's, or a component the
solver is built from was added to or removed from an entity since, and
the error names every such entity. Forces, drives and kinematic moves queued for the coming steps
stay queued, and listeners, recordings and probes keep running.
Parameters
snapshotPhysicsSnapshot— A snapshot.
Returns PhysicsRestore — What was put back, with the restore's wall time in ms.
local start = Physics.snapshot(); Physics.advance(300); Physics.restore(start)
local ok, why = pcall(Physics.restore, start); if not ok then print(why) end
typed/builtin//modules/api/engine/physics/P/resumeReplay
P.resumeReplay(time: number?) -> PhysicsReplayFrame
Carry the live simulation to a recorded second and go on from there:
puzzle undo, a retry from just before the crash, a replay a player takes
over. It ends the replay, then writes the state the recording holds at
time into the simulation: each recorded rigid body's pose and linear
and angular velocity, and each recorded soft body's particle positions
and velocities (Physics.setSoftParticles). The simulation steps on from
that state once gameplay runs. Ragdoll bones, joints' carried impulses
and a soft body's plastic flow carry on from the live state.
Parameters
timenumber(optional) — The recorded second (the playing replay's time by default, else the last recorded step).
Returns PhysicsReplayFrame — The PhysicsReplayFrame written.
engine.paused = true; Physics.resumeReplay(Physics.replayInfo().to - 3); engine.paused = false
typed/builtin//modules/api/engine/physics/P/runStepHooks
P.runStepHooks(phase: string, dt: number, step: number)
Run the step hooks registered for one side of a physics step. The
engine calls this with "before" at the start of every step and with
"after" at its end while Physics.onBeforeStep or
Physics.onAfterStep hooks are registered.
Parameters
phasestring—"before"or"after".dtnumber— The step's length in seconds.stepnumber— The step's number.
Physics.runStepHooks("before", 1 / 30, 1)
typed/builtin//modules/api/engine/physics/P/saveReplay
P.saveReplay() -> string
The replay recording as a string of bytes, the same on every
platform: keep it with vfs.write, play it again with
Physics.loadReplay here or in another engine (a native engine's
recording plays in a browser engine and the other way round).
Returns string — The recording's bytes.
vfs.write("/source/replays/crash.replay", Physics.saveReplay())
typed/builtin//modules/api/engine/physics/P/setAngularDamping
P.setAngularDamping(entityIdOrDamping: string | entityRef | number, damping: number?)
Set angular damping on an entity's rigid body. One-arg form targets the script-context entity.
Parameters
entityIdOrDampingstring | entityRef | number— The entity's id or proxy (withdamping) OR the damping value (script-context entity).dampingnumber(optional) — Optional explicit damping when targeting another entity.
Physics.setAngularDamping(0.1)
Physics.setAngularDamping(entityId, 0.1)
typed/builtin//modules/api/engine/physics/P/setAngularVelocity
P.setAngularVelocity(a: string | entityRef | number | vec3, b: (number | vec3)?, c: number?, d: number?)
Set the angular velocity of an entity (radians/sec). Same call
shapes as setVelocity.
Parameters
astring | entityRef | number | vec3— x-component, a{x, y, z}vector, or the target (explicit): the body's entity id or proxy, or an entity a collider of it was authored on (a hit'sentityIdorbody, an overlap's id); static world geometry such as the ground, like a static body, stays where it stands.b(number | vec3)(optional) — y-component, x-component, or the vector depending on call form.cnumber(optional) — z-component or y-component depending on call form.dnumber(optional) — Optional z-component when targeting an explicit entity.
Physics.setAngularVelocity(0, 0, 1)
Physics.setAngularVelocity(entityId, 0, 0, 1)
Physics.setAngularVelocity(entityId, {x=0, y=0, z=1})
typed/builtin//modules/api/engine/physics/P/setBodyType
P.setBodyType(entityId: string | entityRef, bodyType: string)
Change a rigid body's type at runtime. Mass, colliders, and joints are preserved — only the body's response to forces and position writes changes.
Parameters
entityIdstring | entityRef— Target entity id.bodyTypestring— One of"dynamic","kinematic","static".
Physics.setBodyType(entityId, "kinematic")
typed/builtin//modules/api/engine/physics/P/setCcdEnabled
P.setCcdEnabled(entityIdOrEnabled: string | entityRef | boolean, enabled: boolean?)
Enable or disable continuous collision detection on an entity's rigid body. One-arg form targets the script-context entity.
Parameters
entityIdOrEnabledstring | entityRef | boolean— The entity's id or proxy (withenabled) OR the boolean (script-context entity).enabledboolean(optional) — Optional explicit boolean when targeting another entity.
Physics.setCcdEnabled(true)
Physics.setCcdEnabled(entityId, true)
typed/builtin//modules/api/engine/physics/P/setCollisionGroups
P.setCollisionGroups(entityId: string | entityRef, membership: number, filter: number)
Set the collision-group membership and filter bitmasks on an
entity's colliders. Adds a CollisionGroup component if missing; the
component holds the groups, so they apply to the colliders of the
entity's rigid body, its standalone collider (a collider with no
Physics is a static collider) and the shape it composes onto an
ancestor's body, and a body or collider built or rebuilt later takes
them as it is built, in edit mode as well as play. A shape a child
entity composes onto a body takes the child's groups when the child has
a CollisionGroup of its own, and the body entity's otherwise, so one
body can carry shapes in different groups. An entity with no collider
and no body logs a warning naming it, since its groups reach no collider
until one is added. A soft body's groups are its SoftBody component's
collisionMemberships and collisionFilter. A vehicle's
WheelColliders stand only on colliders its chassis' groups collide
with.
Parameters
entityIdstring | entityRef— Target entity id.membershipnumber— Bitmask: which groups this collider belongs to.filternumber— Bitmask: which groups this collider can collide with.
Physics.setCollisionGroups(id, 0x0001, 0xFFFF)
typed/builtin//modules/api/engine/physics/P/setContactFilter
P.setContactFilter(tagA: string, tagB: string, mode: string?)
Decide what happens when two kinds of collider meet, by tag: every
collider component carries a contactTag field, and the world's contact
filter answers a pair of tags with a mode. "ignore": the two pass
through each other and report nothing (a team's shots through its own
players, ghosts through walls). "sensor": the two report their contacts
(Physics.contacts, Physics.onContact) and push nothing (a pickup a
player runs through, a shield that only registers hits). "solid": the
two collide, which every pair the filter does not name does; it takes
the entry out. A tag may be paired with itself. The filter is data the
physics step reads, so it costs no script per contact. It applies from
the next physics step, to colliders already touching as well, and lasts
until changed. A pair collision groups or Physics.ignoreCollision
keep apart stays apart whatever the filter says. A vehicle's
WheelColliders pass a collider the filter answers "ignore" or
"sensor" with its chassis' tag, as the chassis does.
Parameters
tagAstring— A contact tag, 1 to 64 bytes.tagBstring— Another contact tag (or the same one).modestring(optional) — "ignore", "sensor" or "solid"; nil is "solid".
Physics.setContactFilter("redTeam", "redShot", "ignore")
Physics.setContactFilter("player", "coin", "sensor")
entity("shot").component.add("SphereCollider", { radius = 0.1, contactTag = "redShot" })
typed/builtin//modules/api/engine/physics/P/setGravity
P.setGravity(gravity: vec3)
Replace the world gravity vector.
Parameters
gravityvec3— New gravity vector in m/s².
Physics.setGravity({x=0, y=-9.81, z=0})
typed/builtin//modules/api/engine/physics/P/setGravityScale
P.setGravityScale(entityIdOrScale: string | entityRef | number, scale: number?)
Set the per-entity gravity scale (1.0 = normal, 0.0 = no gravity). One-arg form targets the script-context entity.
Parameters
entityIdOrScalestring | entityRef | number— The entity's id or proxy (withscale) OR the scale value (script-context entity).scalenumber(optional) — Optional explicit scale when targeting another entity.
Physics.setGravityScale(0.5)
Physics.setGravityScale(entityId, 0.5)
typed/builtin//modules/api/engine/physics/P/setJointMotor
P.setJointMotor(entityId: string | entityRef | table, targetVelocity: number, maxForce: number, name: string?)
Drive an entity's joint motor at targetVelocity with at most
maxForce. The joint is the one entityId carries, or, when it carries
none, the joint it is the connected end of. Writes the joint's own motor
fields (motorMode = "velocity", motorVelocity, motorMaxForce), so the
motor is component data that syncs and reads back. A hinge turns at
radians per second under newton-metres, a prismatic slides at metres per
second under newtons, a ball joint drives each of its angles (velocity 0
holds it still: joint friction up to maxForce), a generic joint every
free axis. For a target angle or travel set motorMode = "position" and
motorTarget on the Joint; for single axes, its axisMotors. A Joint
given a yieldForce or yieldTorque refuses, its yield holding the axes
the motor would drive.
Parameters
entityIdstring | entityRef | table— Entity carrying the Joint component, or the body it connects to, or aJointcomponent.targetVelocitynumber— Velocity the motor holds: rad/s for an angle, m/s for a travel.maxForcenumber— The most force or torque the motor applies; 0 leaves it uncapped.namestring(optional) — The Joint's name on that entity, for one of several joints; omit for its unnamed Joint.
Physics.setJointMotor(wheel, 10, 50)
Physics.setJointMotor(piston, 0.5, 2000)
Physics.setJointMotor(arm, 2, 300, "elbow")
typed/builtin//modules/api/engine/physics/P/setLinearDamping
P.setLinearDamping(entityIdOrDamping: string | entityRef | number, damping: number?)
Set linear damping on an entity's rigid body (0 = no damping). One-arg form targets the script-context entity.
Parameters
entityIdOrDampingstring | entityRef | number— The entity's id or proxy (withdamping) OR the damping value (script-context entity).dampingnumber(optional) — Optional explicit damping when targeting another entity.
Physics.setLinearDamping(0.05)
Physics.setLinearDamping(entityId, 0.05)
typed/builtin//modules/api/engine/physics/P/setMass
P.setMass(entityIdOrMass: string | entityRef | number, mass: number?)
Set the mass of an entity's rigid body (kg). One-arg form targets the script-context entity.
Parameters
entityIdOrMassstring | entityRef | number— Entity id (withmass) OR mass value (script-context entity).massnumber(optional) — Optional explicit mass when targeting another entity.
Physics.setMass(10)
Physics.setMass(entityId, 10)
typed/builtin//modules/api/engine/physics/P/setPinTarget
P.setPinTarget(softId: string | entityRef, name: string, position: vec3?)
Drive a pin of a soft body to a world position: its particles move
together over the next step so the centre they had when the pin was made
stands at position, with the velocity that carries them there, and the
rest of the body follows. Set it every frame to drag the region along a
path. nil stops driving it and holds it where it stands. The target is
the pin's entry in the SoftBody component's pins, so it reaches every
peer.
Parameters
softIdstring | entityRef— The soft body's entity.namestring— The pin's name, aspinSoftRegionreturned it.positionvec3(optional) — The world position for the pinned particles' centre; nil holds them where they stand.
Physics.setPinTarget(cloth, corner, {x=2, y=3, z=0})
typed/builtin//modules/api/engine/physics/P/setRotationLocks
P.setRotationLocks(entityId: string | entityRef, x: boolean, y: boolean, z: boolean)
Lock or unlock rotation on specific axes.
Parameters
entityIdstring | entityRef— Target entity id.xboolean— Lock rotation about the world X axis.yboolean— Lock rotation about the world Y axis.zboolean— Lock rotation about the world Z axis.
Physics.setRotationLocks(id, false, true, false)
typed/builtin//modules/api/engine/physics/P/setSoftParticles
P.setSoftParticles(softId: string | entityRef, particles: PhysicsSoftParticlesWrite) -> number?
Write a soft body's particles: where each stands, how fast it
moves, and where it stands in the body's rest shape, the shape it springs
back to. The body simulates on from the written state, so a shape read
once can be put back: a replay or a rewind, a saved game holding a
damaged object, a level that starts with something already bent, a
correction from the network, a repair that pushes one dent out. The
write is applied at once on the peer that simulates the body: a read
straight after sees it, and the next physics step starts from it. Written
from Physics.onBeforeStep, it is the state that step starts from, ahead
of the step's drives, tears and solve. positions and velocities move
the particles and leave the rest shape as it was, so the body springs
back from a written shape toward its rest shape (a dent past its
plasticYield can then set); restPositions changes the rest shape
itself, the permanent part of the shape, which stays once the body
settles, the way a dent past the yield stays (Physics.softBodyState(id) .plastic reads it, and Physics.repairSoftBody undoes it). A read's
restPositions are where each particle rests, which a crumple's elements
pull the body away from, so to keep the shape a body stands in after a
crash, write its positions as restPositions. Positions are
written first and the body's frame fitted to them, then the rest places
are measured through that frame, and each element of the body takes the
rest shape its particles' places give it, which can differ from the one
a crumple's elements flowed to: a body whose flow left its elements
pulling against one another (a deep crumple) keeps the written dent and
settles a little way from the written shape, into it or out of it. Rest places that state the shape the
body was built in (a read taken before its first dent) put that shape
back exactly, the way Physics.repairSoftBody does, so a rewind to a
moment before a crash replays it the same way each time. A write that
places every particle (a whole read written back) is the whole state the
body steps on from, so two rewinds to one read fall the same way, and the
frame after a write draws the body where it was written, paused or not.
A rewind starts from the read alone, while the run the read came from
carried on with what the solver had built up, so the two can part by
rounding where a hit amplifies it; writing the read back the moment it is
taken (from Physics.onBeforeStep) makes that run a replay of it too.
A read's rest places say where each particle rests, while each element
of a crumple keeps a flow of its own: written back over the body while it
still holds the read's dent, a read leaves those elements as they are,
and written over any other state it gives each element the rest its
particles' places give, so a body read with a deep crumple steps on from
the two a little apart (about 1.5 cm over 20 steps where a 3 m slab's
crumple pulls hardest).
A repair (Physics.repairSoftBody) applies at the start of the next
frame and puts the body back in its built shape over a write made before
it; a written restPositions in the built shape is the same repair, at
once. A pinned particle stands where it is written and its pin holds it
there, whatever velocity is written to it (a read before the next step
reads that velocity; the step keeps the particle in place).
A Physics.softParticles read is a write of this shape, so
Physics.setSoftParticles(id, read) puts back the particles it read,
their rest places included.
Parameters
softIdstring | entityRef— The soft body's entity (it carries aSoftBodycomponent).particlesPhysicsSoftParticlesWrite—PhysicsSoftParticlesWrite:indices(zero-based, asPhysics.softParticlesreads them; omit to write every particle in order) and any ofpositions,velocitiesandrestPositions, one value per named particle, in world space.
Returns number? — How many particles were written; nil from a worker VM, whose write the engine thread applies.
local saved = Physics.softParticles(shell); if saved then Physics.setSoftParticles(shell, saved) end -- later: put the shell back as it was
local bent = Physics.softParticles(bar); if bent then Physics.setSoftParticles(bar, { restPositions = bent.positions }) end -- the shape it stands in becomes its rest shape
Physics.setSoftParticles(jelly, { indices = { 0, 7 }, velocities = { {x=0, y=3, z=0}, {x=0, y=3, z=0} } })
typed/builtin//modules/api/engine/physics/P/setTranslationLocks
P.setTranslationLocks(entityId: string | entityRef, x: boolean, y: boolean, z: boolean)
Lock or unlock translation on specific axes.
Parameters
entityIdstring | entityRef— Target entity id.xboolean— Lock translation along the world X axis.yboolean— Lock translation along the world Y axis.zboolean— Lock translation along the world Z axis.
Physics.setTranslationLocks(id, false, false, true)
typed/builtin//modules/api/engine/physics/P/setVelocity
P.setVelocity(a: string | entityRef | number | vec3, b: (number | vec3)?, c: number?, d: number?)
Set the linear velocity of an entity. Accepts (x, y, z) or a
{x, y, z} vector for the script-context entity, or the same
prefixed with an explicit entityId.
Parameters
astring | entityRef | number | vec3— x-component, a{x, y, z}vector, or the target (explicit): the body's entity id or proxy, or an entity a collider of it was authored on (a hit'sentityIdorbody, an overlap's id); static world geometry such as the ground, like a static body, stays where it stands.b(number | vec3)(optional) — y-component, x-component, or the vector depending on call form.cnumber(optional) — z-component or y-component depending on call form.dnumber(optional) — Optional z-component when targeting an explicit entity.
Physics.setVelocity(0, 10, 0)
Physics.setVelocity(entityId, 0, 10, 0)
Physics.setVelocity(entityId, {x=0, y=10, z=0})
typed/builtin//modules/api/engine/physics/P/setWaterVolume
P.setWaterVolume(target: string | entityRef, volume: PhysicsWaterVolume?) -> () -> ()
Measure an entity in the water by a volume stated in its own frame
(its position and turn, unscaled, metres) in place of its body,
colliders or origin: what a character moved by casts, with no body of its
own, is measured by (a CharacterController states its capsule).
Physics.onWater and Physics.immersion read it from then on, and a
listener for every body (Physics.onWater(nil, fn)) watches it. An
entity with no rigid or soft body of its own is heard by triggers by the
same volume (Physics.onTrigger): it enters and leaves a trigger as a
body does. The
volume stands until the returned function is called, or the component
that stated it is removed or its entity destroyed; the latest volume
still standing is the one the entity is measured by.
Parameters
targetstring | entityRef— The entity.volumePhysicsWaterVolume(optional) — APhysicsWaterVolume:{ shape = "capsule", radius, height, center? }(standing along its up axis,heightfrom the bottom of the lower cap to the top of the upper one),{ shape = "sphere", radius, center? }or{ shape = "box", size, center? }; nil takes every volume stated for it away, so it is measured by its body, collider or origin again.
Returns () -> () — A function that takes this volume away again.
local off = Physics.setWaterVolume(diver, { shape = "capsule", radius = 0.3, height = 1.8, center = vector.create(0, 0.9, 0) })
Physics.setWaterVolume(buoy, { shape = "sphere", radius = 0.4 })
typed/builtin//modules/api/engine/physics/P/shaftNetworkState
P.shaftNetworkState(entityId: string | entityRef) -> table?
Read a ShaftNetwork (a drivetrain, gearbox, differential, clutch,
gear train, winch or other network of rotating parts on shafts) as of the
last physics tick: every part's speed and torques and every link's torque,
slip and lock, by name. The same reading as the component's state().
Parameters
entityIdstring | entityRef— The entity carrying the ShaftNetwork.
Returns table? — { parts, links, settled }, or nil when the entity carries none. settled is whether the tick held every link, friction, brake and drive where its bounds allow (every shaft and gear at its ratio, every differential at the mean of its sides, every clutch and lock holding inside its capacity or slipping at it); false when the links ask for speeds the parts cannot take together (a part shafted to two immovable parts turning at different speeds), and the parts then turn as near to every link as they can come. parts.<name> = { speed, rpm, torque, brakeTorque, linkTorque, throttle, brake, wheel?, joint?, problem? }: speed in rad/s (a wheel part's is its wheel's spin, a joint part's its hinge's turn), torque what its source applied (its curve times its throttle plus its constant torque), brakeTorque what its friction, brake and drag applied and linkTorque what the links put on it, all N·m; throttle and brake the inputs in effect; problem why the part turns on its own though it names a wheel or a joint (absent while it turns with it). links.<name> = { kind, ratio, engage, locked, torque, lockTorque, slip, slipping, windup }: ratio, engage and locked the inputs in effect (a gear indicator reads ratio), torque (N·m) the link takes from a (a differential's from input), lockTorque what a differential's lock passes from a to b (or a spring pushes back with), slip how fast a turns against b (rad/s; against ratio times b for a gear), slipping whether a clutch or a differential's lock lets its sides turn apart, windup a spring's wound-up angle (radians).
local s = Physics.shaftNetworkState(car.id); print(s.parts.engine.rpm, s.links.clutch.slipping)
typed/builtin//modules/api/engine/physics/P/sleep
P.sleep(entityId: (string | entityRef)?)
Put an entity's rigid body to sleep at rest where it lies, from the
next step. It stays asleep until something wakes it: a contact with a
moving body, a joint to one, a motion setter or Physics.wakeUp. A
resting pile put to sleep stops costing a solve at once instead of after
the half second the solver waits on its own. Raises, naming the body
and why, for a static body and a body whose Physics component sets
canSleep = false. A call made before the body is built (in the turn
its entity takes its Physics component) is applied to the body as it
is built; on an entity that carries no Physics component it does
nothing, and the log says so, naming the entity. A call from a worker
VM is carried out with the frame's other writes, and a refusal of it is
logged as a warning in the same words.
Parameters
entityId(string | entityRef)(optional) — Target entity id or proxy; resolves from script context when omitted.
Physics.sleep(id)
typed/builtin//modules/api/engine/physics/P/snapshot
P.snapshot() -> PhysicsSnapshot
Take a snapshot of the whole physics simulation as it stands between
steps, to put the world back to later with Physics.restore: every
rigid body, collider, joint (its limits, motors and the impulses it
carries) and soft body (its particles, elements and plastic state), the
islands, every contact with the impulses it carries into the next step,
the continuous-collision state, the vehicles and their wheels, the
drivetrains, held forces and plane holds, and every entity's transform
and velocity with the settings of the components the solver is built
from (Physics, Joint, its collider, SoftBody, CollisionGroup,
PlaneHold: every component declaring simulation = "physics").
Stepping N steps
after a restore reaches the state N steps after the snapshot reached,
bit for bit
(Physics.stateDigest reads the same digest), however many times it is
restored: a bridge builder tests a bridge and resets it, a crash test
retries from the moment before impact, a puzzle undoes a move.
snapshot:size() is the bytes it is saved as, snapshot:info() what it
holds and how long it took, snapshot:save(path) writes it to the VFS for
Physics.loadSnapshot. A snapshot lives in memory until nothing holds it
or snapshot:release(); live snapshots together hold at most 1 GiB. The
physics guide's "Snapshots" section states what it costs.
Returns PhysicsSnapshot — The snapshot.
local before = Physics.snapshot(); print(before:size(), before:info().bodies)
local s = Physics.snapshot(); Physics.advance(120); Physics.restore(s)
typed/builtin//modules/api/engine/physics/P/softBodyEnergy
P.softBodyEnergy(softId: string | entityRef, opts: { mark: boolean? }?) -> PhysicsSoftBodyEnergy?
Read a soft body's energy ledger, to tune a deformable by numbers:
the kinetic and elastic energy it holds now, and since the mark the work
gravity did on it, the work plastic flow absorbed, the energy tears and
cuts took out of it, what pieces split off carried away and what it lost
otherwise (damping, friction, contacts, less what whatever holds or
pushes it gave it), each by region too, with the peak acceleration of
its centre of mass.
opts.mark = true sets the mark first and starts the ledger again; a body
never marked reads its kinetic and elastic energy only (accounted is
false), and costs nothing per step. A marked body is accounted after
every step that moves it, so a crash read straight after it reads the
whole crash: mark before, read after.
Parameters
softIdstring | entityRef— The soft body's entity.opts{ mark: boolean? }(optional) —{ mark: boolean? }.
Returns PhysicsSoftBodyEnergy? — A PhysicsSoftBodyEnergy ledger, or nil when nothing in the scene answers to that id.
Physics.softBodyEnergy(shell, { mark = true }) -- before the crash
local e = Physics.softBodyEnergy(shell); print(e.absorbed, e.elastic, e.dissipated) -- after it: joules
for _, r in Physics.softBodyEnergy(shell).regions do print(r.name, r.absorbed) end
typed/builtin//modules/api/engine/physics/P/softBodySettings
P.softBodySettings(changes: table?) -> PhysicsSoftBodySettings
The settings every soft body of the world is simulated under, and the
way to change them: how many extra substeps a second a hard hit may add, how stiff
soft contacts are, which tangle and overlap recovery runs, and how far
the FEM solver (SoftBody.solver = "fem") solves each step. Each one
trades simulation quality for cost; Physics.stepCost().softBodies shows
what each body costs under them. They are world settings
(physics.soft_body_* in .world_settings) saved with the world: a
change reads back at once and the solver runs under it from the next
physics tick. Written during play, they land on the play shadow like any
other /source write: the solver runs under them at once, and they are
gone when the play edits are discarded. Write them in edit mode (or keep
them with vfs.promotePlayShadow("/zero/source/.world_settings")) for the
world to keep them.
Parameters
changestable(optional) — OptionalPhysicsSoftBodySettingsfields to change; the fields left out keep their values. A field the settings do not have, or a value of the wrong type or out of range, is refused by name.
Returns PhysicsSoftBodySettings — The settings with changes applied: what the next tick runs under.
print(Physics.softBodySettings().maxExtraSubstepRate)
Physics.softBodySettings({ maxExtraSubstepRate = 60 }) -- cheaper hard hits
Physics.softBodySettings({ tangleDetection = false, overlapConstraints = false })
Physics.softBodySettings({ femMaxIterations = 60 }) -- FEM bodies converge further each substep
typed/builtin//modules/api/engine/physics/P/softBodyState
P.softBodyState(entityId: string | entityRef, opts: table?) -> PhysicsSoftBodyState?
What the solver holds for one soft body (an entity with a SoftBody
component): its particle, cell and edge counts, the volume it encloses
against its rest volume, its centre of mass and frame, the box around its
particles, how fast they move, whether it sleeps, and what it touches,
and in render how the entity's model is drawn carried by the body.
plastic is how deep the deformation that stayed is, in metres (a dent
past the component's plasticYield; plasticMean the mean over the
particles), 0 for a body that only deformed elastically.
diverged is true while a step has carried the body into a state no
material reaches (its particles spread, or its volume grown, past ten
times the shape it is held at, or a particle carried to a value that is
not a number), and divergence says what was measured; the engine log
names the body the step it diverges.
tearStrain and tearForce are the thresholds it tears past (0 tears
never), and piece names the torn piece a body split off another
continues (nil for a body built from its fields).
attachments lists the regions held to rigid bodies (attachSoftRegion)
with the force each pulls with, attachedParticles counts the particles
tied, and clusters counts the body's frame plus one per joint end
anchored on a region of it. pins lists the regions pinned
(pinSoftRegion) with how many particles each holds, its target and
where its particles' centre stands, and pinnedParticles counts the
particles held kinematic. diagnostics is what the physics debug views
picture of the body as numbers: inverted cells, self-crossings, element
loads (maxLoad, loadedElements), pinned and attached particles (see
PhysicsSoftBodyDiagnostics; Physics.debugLines draws them).
replication, on a synced entity in a multiplayer session, says which
peer simulates the body (authority "local" or "remote", owner)
and what it costs on the wire here (lastSync in seconds,
bytesPerSecond).
stability compares the body's stiffest elements with the rate the
solver runs them at, from the moment it is built, before it steps (see
PhysicsSoftBodyStability): holds is false and cannotHold names each
part, with its frequency and the substep rate, when the default solver
holds it softer than it is stated.
status says where the body stands: "built", "pending" (the
component stands and the body is not built yet, waitingFor naming what
the build waits on), "refused" (refusal says why the component was
not built) or "none" (no SoftBody component). A body is built at the
start of the frame after its component is added, so a read in the call
that added it answers "pending"; wait on status rather than reading
exists = false as a refusal. Answers in edit mode as well as play mode.
Parameters
entityIdstring | entityRef— Entity id or proxy.optstable(optional) —{ positions: boolean?, contactPoints: boolean?, contactsWith: (string | entityRef)? }:positions = trueadds every particle's world position;contactPoints = trueadds each contact's individual points (each contact names its count, normal, depth, impulse and particles either way);contactsWithreports only the contacts with that one entity, so a read about one pair costs that pair alone.
Returns PhysicsSoftBodyState? — A PhysicsSoftBodyState, or nil when nothing in the scene answers to that id.
local s = Physics.softBodyState(jelly); print(s.particleCount, s.volumeRatio, s.sleeping)
print(Physics.softBodyState(shell).plastic) -- metres of dent the shell kept
local s = Physics.softBodyState(shell); if s.diverged then print(s.divergence) end
for _, p in Physics.softBodyState(jelly, { positions = true }).positions do print(p.y) end
local r = Physics.softBodyState(jelly).render; print(r.drawn, r.vertexCount, r.uploadedThisFrame)
local s = Physics.softBodyState(jelly); if s.status == "pending" then print("waiting for", s.waitingFor) end
local st = Physics.softBodyState(beam).stability; if not st.holds then print(st.cannotHold[1]) end
typed/builtin//modules/api/engine/physics/P/softBodyTears
P.softBodyTears() -> { PhysicsSoftBodyTear }
Every soft body tear since the last call to this function, oldest
first, with the entities of the pieces each split off: the same records
onSoftBodyTear delivers. The 256 most recent are kept.
Returns { PhysicsSoftBodyTear } — Array of PhysicsSoftBodyTear.
for _, t in Physics.softBodyTears() do print(t.kind, t.entity, #t.pieces) end
typed/builtin//modules/api/engine/physics/P/softElements
P.softElements(softId: string | entityRef) -> PhysicsSoftElements?
Read every element of a soft body in one call: the force each carries
(newtons, positive pulling, negative pushing), its strain, length, rest
length, permanent set, its load against its break limit, whether it
broke, and where its two ends stand in world space (endA, endB; a
broken element's are where its particles went), as arrays indexed by
element. A custom body's authored elements read by their number in
the component's list, wherever a tear left them, the same read from the
body's entity and from each piece's; any other body's edges
read in its own order with a / b naming their particles. The way to
colour a structure by stress, draw its members, find its most loaded
member or watch a span carry a load, at the cost of one call per frame.
Parameters
softIdstring | entityRef— The soft body's entity.
Returns PhysicsSoftElements? — A PhysicsSoftElements report, or nil when nothing in the scene answers to that id.
local s = Physics.softElements(bridge); for i = 1, s.count do if s.load[i] > 0.8 then print("member", i, "near breaking", s.force[i]) end end
local s = Physics.softElements(bridge); for i = 1, s.count do if not s.broken[i] then print("member", i, "from", s.endA[i], "to", s.endB[i]) end end
typed/builtin//modules/api/engine/physics/P/softParticles
P.softParticles(softId: string | entityRef, region: PhysicsSoftRegion?) -> PhysicsSoftParticles?
Read the particles of a soft body that a region selects: where each
stands, how fast it moves, where it stands in the body's rest shape and
whether it is pinned, with the selection's centre of mass and mean
velocity. Physics.setSoftParticles writes a read back as it is. The way to see a dent where a hit
landed, how far a pinned corner was dragged, or how a region moves.
indices name the particles for comparing two reads of the same body.
The region is resolved at each call against where the particles stand
then (a local-space region in the body's frame as it stands now), so a
read after the body moved can select other particles than an earlier
read of the same region; a pin's own particles read back through
Physics.softBodyState(softId).pins (center) and the pinned flags.
Parameters
softIdstring | entityRef— The soft body's entity.regionPhysicsSoftRegion(optional) — Which particles to read, asPhysics.softRegiontakes it; nil reads the whole body.
Returns PhysicsSoftParticles? — A PhysicsSoftParticles report (exists, count, indices from 0, world positions, velocities and restPositions, pinned, center, meanVelocity, refusal), or nil when nothing in the scene answers to that id.
local top = Physics.softParticles(jelly, { box = { min = {-0.5, 0.4, -0.5}, max = {0.5, 0.5, 0.5} } }); print(top.count, top.center.y)
local near = Physics.softParticles(shell, { box = { min = {1.6, 0, -0.3}, max = {2.2, 1, 0.3} }, space = "world" })
typed/builtin//modules/api/engine/physics/P/softRegion
P.softRegion(region: PhysicsSoftRegion?) -> { [string]: any }
The engine form of a soft body region: the record the SoftBody
component's attachments and a Joint's soft body ends carry. A region
names part of a soft body by where its particles stand: { box = { min, max } } is every particle between the two corners, { nearest = point }
the one particle nearest the point, and nil (or {}) the whole body.
Coordinates are in the soft body entity's local space, the unit box it
is built in (-0.5 to 0.5 on each axis, before its scale; for a custom
body, the space its particles are listed in), so a region
stays the same part of the body wherever the body is; space = "world"
reads them in world space instead. A box counts a particle whose contact
skin reaches into it: a generated body's outer particles stand that skin
inside the unit box, so a box flat on one of its faces
(min = {-0.5, -1, -1}, max = {-0.5, 1, 1}) holds that face's particles.
Errors naming the key that is wrong.
Parameters
regionPhysicsSoftRegion(optional) —{ box = { min = v, max = v } | { v, v }, nearest = v, space = "local" | "world" }, or nil for the whole body.
Returns { [string]: any } — { kind = "Whole" | "Box" | "Nearest", min, max, point, world }.
Physics.softRegion({ box = { min = {-0.5, 0.45, -0.5}, max = {0.5, 0.5, 0.5} } })
Physics.softRegion({ nearest = {0, 0.5, 0} })
typed/builtin//modules/api/engine/physics/P/solveIk
P.solveIk(endEffector: string | entityRef, target: any?, opts: table?) -> table
Solve an articulation's joints for one of its links to reach a
target: inverse kinematics by damped least squares over the joints'
coordinates, each joint's travel or single angle held inside its range and
each angle with no range turned at most half a turn from where it stands. By
default the links are put where the solve found; with apply = false it
only answers, and each joint's found position is the motorTarget a
position motor drives the arm there with (degrees for an angle).
Parameters
endEffectorstring | entityRef— The link that reaches (an entity whose body is a link below the root).targetany(optional) — Where it reaches: a point{x, y, z}in world space.optstable(optional) — Optional:offset(the point of the link that reaches, in its own frame; its origin by default),rotation({x, y, z, w}or an entity'srotation, the turn the link is to stand at as well),from(the link whose joint, with every joint below it, moves; every joint from the root's children down by default),iterations(default 50),damping(default 0.1; larger is steadier near a stretched-out pose),tolerance(metres, and radians forrotation; default 0.001),apply(default true).
Returns table — { reached, error, angleError, iterations, joints }: reached when the point stands within tolerance of the target, error its distance in metres, angleError the degrees from rotation (0 when none was asked), and joints each moved joint from the top down as { entityId, angle?, offset?, axes }: angle (degrees) for a joint whose one free axis is an angle, offset (metres) for one whose one free axis is a travel, and axes.<linX..angZ> the same per free axis (a ball joint's three angles read none). A target out of reach answers reached = false with the arm stretched toward it.
local r = Physics.solveIk(hand, { 1.2, 0.8, 0 }); print(r.reached, r.error)
local r = Physics.solveIk(gripper, cup.position, { apply = false }); for _, j in r.joints do entity(j.entityId).component.get("Joint").motorTarget = j.angle end
typed/builtin//modules/api/engine/physics/P/solverSettings
P.solverSettings(changes: table?) -> PhysicsSolverSettings
The settings the constraint solver runs every step of the world under,
and the way to change them: the tick rate, how much simulated time a
frame may catch up and how many of its steps run whatever they cost,
the substeps each step is divided into, the passes within
a substep, how much of its last impulse a contact (and, with joint warm
starting, a joint) starts from, how stiff and how damped contacts are,
the solver's tolerances and their length unit, continuous collision's
substeps and the friction model. Each field is the world
setting physics.<name> (physics.solver_iterations,
physics.pgs_iterations, ...) saved with the world in
.world_settings; PhysicsSolverSettings states each one's default and
range, and the physics guide's "Tuning the solver" what each changes. A
change reads back at once and the solver runs under it from the next
physics step, with no restart; Physics.worldState().solverSettings
reads what the solver holds. Written during play, they land on the play
shadow like any other /source write: the solver runs under them at once,
and they are gone when the play edits are discarded. Write them in edit
mode (or keep them with vfs.promotePlayShadow("/zero/source/.world_settings"))
for the world to keep them.
Parameters
changestable(optional) — OptionalPhysicsSolverSettingsfields to change; the fields left out keep their values. A field the settings do not have, or a value of the wrong type or out of range, is refused by name.solverIterationsalso takes"auto", the default: enough substeps for 120 solves a second at the tick rate (and at least 2), worked out again whenever the tick rate changes. A count equal to the one the tick rate works out to is saved as"auto", so the settings read and written back unchanged keep the count following the tick rate.
Returns PhysicsSolverSettings — The settings with changes applied: what the next step runs under.
print(Physics.solverSettings().solverIterations)
Physics.solverSettings({ tickRate = 60, solverIterations = 8 }) -- a long bridge or chain
Physics.solverSettings({ solverIterations = "auto" }) -- substeps follow the tick rate again
Physics.solverSettings({ lengthUnit = 100 }) -- a world built in centimetres
Physics.solverSettings({ contactFrequency = 15 }) -- softer, squashier contacts
Physics.solverSettings({ tickRate = 240, maxCatchUpSeconds = 0.1 }) -- a frame catches up at most 0.1 s
typed/builtin//modules/api/engine/physics/P/sphereCast
P.sphereCast(origin: vec3, radius: number, direction: vec3, maxDistance: number?, exclude: (string | {string})?, options: PhysicsCastOptions?) -> PhysicsHit?
Cast a sphere along a direction and return the first hit.
A trigger (isTrigger) holds nothing up, so the sweep passes through it.
Many casts a frame: Physics.castMany answers them all in one call.
Parameters
originvec3— Sphere center at the start of the cast.radiusnumber— Sphere radius.directionvec3— Cast direction, of any length: the engine normalises it, somaxDistanceanddistanceare world units.maxDistancenumber(optional) — Optional distance limit.exclude(string | {string})(optional) — Optional entity id, or array of entity ids, to exclude from hits. Applied while sweeping rather than to the answer, so a cast that starts inside an excluded collider reports what is behind it.optionsPhysicsCastOptions(optional) — OptionalPhysicsCastOptions:{ mover = entity }casts for the entity the cast moves (a character controller, or anything moved by casts), so it meets colliders as that entity's body does: a one-way collider (oneWay) answers only on the face its direction points out of, to a cast that starts outside it; a collider whosecontactTagthe contact filter answers "ignore" or "sensor" with a tag of the mover's own colliders is passed; and the one-way collidersPhysics.passThrough(mover)drops the mover through are passed until it is clear of them.
Returns PhysicsHit? — Hit table { entityId, body, bodyType, point, normal, distance, startedInside, softBody?, surface?, surfaceVelocity? }, or nil if nothing hit. body is the id of the entity standing for the body the collider belongs to: the body's own entity when the collider was authored on a child entity (a part of a vehicle or an assembled prop, which composes onto its ancestor's body), and the collider's own entity for static world geometry that rides no body, such as the ground. bodyType is that body's kind ("dynamic", "static", "kinematic", "kinematicVelocity" or "soft"; "static" for static world geometry). The push verbs take body and entityId alike. startedInside is false for a surface the query crossed on its way there, and true when the query's own start already lay inside that collider — where distance is 0, point is the start itself, and normal is the shortest way out of the collider. normal is a unit vector either way. surface names the surface the collider is made of where the query met it (Physics.defineSurface; on a heightfield whose samples name layers, the layer of the sample nearest the point), and is absent for a collider naming none. surfaceVelocity is the collider's surfaceVelocity in world space (m/s), the motion its surface carries what stands on it with, and is absent for a collider whose surface holds still. softBody is set when what was hit is a soft body, whose surface the query meets as it is deformed now: a PhysicsSoftHit naming the surface triangle, the particles carrying it with the hit's weight on each, the particle nearest the hit, and region, the hit as a soft region to hand to Physics.applyImpulse, Physics.pinSoftRegion or Physics.softParticles. Physics.applyImpulseAtPoint takes the hit's point as it is.
local hit = Physics.sphereCast(o, 0.5, dir, 10)
local hit = Physics.sphereCast(o, 0.5, dir, 10, selfId)
typed/builtin//modules/api/engine/physics/P/stateDigest
P.stateDigest(opts: table?) -> PhysicsStateDigest
Take a digest of the physics simulation's state as it stands: one hash,
sixteen hex digits, over every rigid body's type, pose, velocities and
sleep state, every joint's carried impulses and every soft body's
particles. Two engines whose digests are equal hold the same state, so a
native and a browser player, two peers on one world or two runs of one
scripted scene check they agree by comparing digests instead of every
pose. Read it from Physics.onAfterStep for the state each step left, or
any time on demand. The digest depends on the state alone and is the
same on every platform for the same state. Two runs of one scene reach
the same state when they run the same script with the same inputs on the
same steps: in two freshly started engines (native or browser), and in
one engine that despawned the first run before building the second (a
level restarted in the same session, or in a new play session),
whatever else that engine built and removed before. The physics guide's
"State digests and determinism" section states every condition and what
was measured.
Parameters
optstable(optional) —{ quantum?, key?, entities?, entries?, values? }.entities, an array of entity ids, covers only those entities' bodies, joints and soft bodies (every entity by default), so a game hashes its own simulation apart from the rest of the world.quantum(0, the exact bits, by default) rounds each value to that step before hashing, so two states within it read alike.keynames each entry by the entity's"id"(default; engines on one world share ids) or its"name"(engines that each spawned the same scene share names).entries = truelists each body, joint and soft body with its own digest;values = trueadds the numbers each was hashed from, whichPhysics.firstDivergencenames a difference by.
Returns PhysicsStateDigest — A PhysicsStateDigest: digest, step, the counts, and entries when asked.
local d = Physics.stateDigest(); print(d.step, d.digest)
local d = Physics.stateDigest({ key = "name", values = true }); print(#(d.entries :: any))
typed/builtin//modules/api/engine/physics/P/stepCost
P.stepCost() -> PhysicsStepCost?
What the last physics step cost, stage by stage — the same figures
worldState().step carries, for a caller that wants only these. Each
covers that one step rather than a window of them, and consecutive steps
over the same resting scene vary by tens of percent, so several samples
averaged is the honest read of what a step costs. softBodyMs is the
soft body part of the step and softBodies each soft body's part of it.
A frame can run several steps; recent lists the last 64 with their
ordinals (step), so a loop reading once a frame counts every step.
Physics.catchUp() states how many frames dropped simulated time
catching up and how much.
Returns PhysicsStepCost? — A PhysicsStepCost, or nil on a frame where the pipeline did not step — a paused simulation, or a world still bootstrapping.
local c = Physics.stepCost(); if c then print(c.stepMs, c.narrowPhaseMs) end
local c = Physics.stepCost(); if c then for _, b in c.softBodies do print(b.entity, b.ms, b.particles) end end
local seen, total = 0, 0
-- once a frame: every step since the last read, however many a frame ran
local c = Physics.stepCost(); if c then for _, s in c.recent do if s.step > seen then total += s.softBodyMs; seen = s.step end end end
typed/builtin//modules/api/engine/physics/P/stillnessReasons
P.stillnessReasons() -> { string }
Every reason whyStill can answer with, in the order the engine
considers them. Read from the engine, so the list is the one the answers
come from.
Returns { string } — An array of reason names.
for _, reason in Physics.stillnessReasons() do print(reason) end
typed/builtin//modules/api/engine/physics/P/surfaces
P.surfaces() -> { [string]: PhysicsSurface }
Every surface Physics.defineSurface defined, by name.
Returns { [string]: PhysicsSurface }.
for name, s in Physics.surfaces() do print(name, s.friction, s.rollingResistance) end
typed/builtin//modules/api/engine/physics/P/tearSoftBody
P.tearSoftBody(softId: string | entityRef, region: PhysicsSoftRegion)
Tear a soft body at a region: every edge and cell holding a particle of
the region comes apart there, opening a hole or, when the region runs
across the body, splitting it. Applied straight after the next physics
step; a piece the tear separates becomes an entity of its own (see
onSoftBodyTear), and it reports as a tear of kind "tear". Raises when the
entity carries no SoftBody, for a region naming no box and no point (the
whole body), and in edit mode, where nothing simulates.
Parameters
softIdstring | entityRef— The soft body's entity.regionPhysicsSoftRegion— Which particles to tear through, asPhysics.softRegiontakes it:{ box = { min, max } }or{ nearest = point }in the entity's unit box (-0.5 to 0.5 on each axis),space = "world"for world coordinates.
Physics.tearSoftBody(cloth, { nearest = hit.point, space = "world" })
Physics.tearSoftBody(sheet, { box = { min = {-0.02, -1, -0.5}, max = {0.02, 1, 0.5} } })
typed/builtin//modules/api/engine/physics/P/touching
P.touching(entityId: string | entityRef, otherId: string | entityRef) -> (boolean, number, { PhysicsContactPoint })
Whether two entities are touching, and how deeply.
Parameters
entityIdstring | entityRef— Entity id or proxy.otherIdstring | entityRef— The other entity id or proxy.
Returns (boolean, number, { PhysicsContactPoint }) — (touching, deepestPenetration, points) — deepestPenetration is in metres and 0 for surfaces that meet without overlapping.
local hit, depth = Physics.touching(a, b); print(hit, depth)
typed/builtin//modules/api/engine/physics/P/tyreCurve
P.tyreCurve(entityId: string | entityRef, opts: table?) -> table?
Measure a wheel's tyre grip curve: the force its tyre pushes with at a steady slip, swept over slip ratio (along the road), slip angle (across it) and load, as the wheel's WheelCollider fields state its grip and as its solve settles on at that slip. Tune a tyre by numbers: its peak, where it peaks, how far it falls past the peak, and how its grip per newton falls with load.
Parameters
entityIdstring | entityRef— The wheel entity (it carries the WheelCollider).optstable(optional) — Optional{ loads = { N... }?, slipRatios = { ... }?, slipAngles = { degrees... }?, at = { { slipRatio, slipAngle }... }?, surface = string? }: the loads to sweep (default the load the wheel carries now, or itsreferenceLoad), the slip ratios (default 0 to 1 by 0.025), the slip angles (default 0 to 30 degrees by 1), pairs of slips to answer together, and the surface the tyre grips (default the one it touches now; a surfacePhysics.defineSurfacedefined scales every peak and the combined limit by itsfriction).
Returns table? — { entity, spins, surface?, surfaceGrip, loads = { { load, gripScale, side, forward? } }, at? }, or nil if the entity carries no WheelCollider. surface names the surface the curve is on and surfaceGrip the share of its stated grip the tyre grips it with (its friction when defined, else 1). side is { slipAngles, forces, perLoad, peak = { slipAngle, force, perLoad }, slide = { slipAngle, force, perLoad } } (forces in newtons, perLoad each over the load, peak the curve's peak, at the slip its grip peaks at, slide the force at the sweep's widest slip); forward is the same against slipRatios, present for a wheel that spins on its own (spins, an inertia above 0); gripScale is the share of its stated grip the tyre has per newton at that load (loadSensitivity); at lists { slipRatio, slipAngle, forward, side, grip } for each pair, at the first load.
local curve = Physics.tyreCurve(wheel.id); print(curve.loads[1].side.peak.slipAngle, curve.loads[1].side.peak.perLoad)
typed/builtin//modules/api/engine/physics/P/upAt
P.upAt(point: vec3, groups: number?, into: { [string]: any }?) -> vec3
Up at a point: the unit direction against the gravity there
(Physics.gravityAt). The way a character stands on a small planet, a
camera keeps level and a walker's feet point away from. Where no gravity
acts at all it is up against the world's gravity vector, and +Y where
that is zero too.
Parameters
pointvec3— The point, in world space.groupsnumber(optional) — The collision membership of the body asking, as a bitmask. Default: every group.into{ [string]: any }(optional) — A table to write the answer'sx,yandzinto and return: a script reading this every frame into one table allocates nothing. A new table when left out.
Returns vec3 — The unit up direction there (into when given).
local up = Physics.upAt(entity(player).position)
typed/builtin//modules/api/engine/physics/P/vehicleState
P.vehicleState(chassisId: string | entityRef) -> PhysicsVehicleState?
Read a vehicle: the chassis body's forward speed and the state of every wheel under it (the wheels whose nearest rigid-body ancestor is this chassis), and the wheels that came off it.
Parameters
chassisIdstring | entityRef— The chassis entity (the rigid body the wheels sit under).
Returns PhysicsVehicleState? — PhysicsVehicleState: { speed, groundedWheels, wheels, detachedWheels }, or nil when the chassis has no WheelCollider under it. speed is metres per second along the chassis' forward (-Z), negative in reverse; groundedWheels is how many of wheels touch the ground; wheels lists getWheelState tables of the wheels on the vehicle, each with its entityId, in the order the vehicle steps them, which is the order the wheels arrived in the world (the first spawned first), the same on every run and every engine (a wheel that has not stepped yet comes after those, by name); detachedWheels lists the wheels that came off it the same way, in the order they held on it, each with its detachReason and detachLoad.
local car = Physics.vehicleState(carId); print(car.speed, car.groundedWheels)
typed/builtin//modules/api/engine/physics/P/wakeUp
P.wakeUp(entityId: (string | entityRef)?)
Wake an entity's sleeping rigid or soft body so it resumes
simulating. The motion setters (applyImpulse, setVelocity,
setAngularVelocity) wake the body for you; call this to wake one
explicitly.
Parameters
entityId(string | entityRef)(optional) — Target entity id or proxy; resolves from script context when omitted.
Physics.wakeUp(id)
typed/builtin//modules/api/engine/physics/P/water
P.water(point: vec3, moment: number?, body: string?) -> PhysicsWaterSample?
The water at a point: where the surface over it stands, which way the
surface faces and moves, how deep the point is, where the bottom is and
how the water there moves (PhysicsWaterSample), from every body of water
defined: a water kit's sea, a Terrain's lakes and rivers, a pool content
declared (Physics.defineWater). Nil where no water covers the point. It
reads the water at moment on the water clock (Physics.waterTime), by
default now: inside a physics step the moment that step reaches, so a
force applied from Physics.onBeforeStep reads the water of its own step,
and otherwise the frame's. Evaluated on the CPU from the definition the
water is drawn from, so the same point and moment answer the same on every
peer, at any rate a script calls it. body asks one body alone, whatever
else covers the point.
Parameters
pointvec3— The point, in world space.momentnumber(optional) — Seconds on the water clock. Default: now.bodystring(optional) — The name of the one body to answer for.
Returns PhysicsWaterSample?.
local w = Physics.water(entity(buoy).position); if w and w.submerged then Physics.applyForce(buoy, { 0, w.depth * 1000 * 9.81, 0 }) end
Physics.onBeforeStep(function() local w = Physics.water(entity(raft).position); if w and w.submerged then Physics.setVelocity(raft, w.velocity) end end)
typed/builtin//modules/api/engine/physics/P/waterEventsDropped
P.waterEventsDropped() -> number
How many water entries and exits the engine let go before anything read them: its queue keeps 4096 between two deliveries. Zero when nothing was lost.
Returns number — The count since the world started.
if Physics.waterEventsDropped() > 0 then log.warn("water events dropped") end
typed/builtin//modules/api/engine/physics/P/waterMany
P.waterMany(points: { vec3 }, moment: number?, body: string?) -> { PhysicsWaterSample | false }
Physics.water at each of points, all at one moment: a hull's
sample points in one call. A point no water covers answers false.
Parameters
points{ vec3 }— The points, in world space.momentnumber(optional) — Seconds on the water clock. Default: now.bodystring(optional) — The name of the one body to answer for.
Returns { PhysicsWaterSample | false } — One PhysicsWaterSample (or false) per point, in order.
for i, w in Physics.waterMany(hullPoints) do if w and w.submerged then lift += w.depth end end
typed/builtin//modules/api/engine/physics/P/waterTime
P.waterTime() -> number
The water clock now: the seconds of simulation this engine has run.
It is the moment Physics.water reads at by default:
inside a physics step the moment that step reaches, otherwise the moment
the frame draws at: the share of the way between the last two steps the
frame draws an interpolated body at (Physics.drawnPose), or the last
step's moment in a world that draws its bodies unblended
(physics.interpolation off), so a body floating on the water is drawn on
the surface drawn with it. Each step carries it on by the simulated
seconds it covers, so it stands still while the simulation is held (edit
mode, a paused play), follows engine.timeScale, drops the seconds of the
steps a slow frame drops, and Physics.advance carries it on by the steps
it runs: a sea drawn at it is the sea the steps float bodies on. In a
multiplayer session every peer reads one moment, to within the session
clock's accuracy (multiplayer.sessionClock): the session's time wrapped
at 8192 s, which the steps keep the clock on by gaining or losing up to a
tenth of each step's seconds; a peer entering play, coming out of a pause
or a stall of more than half a second rejoins it at its next step. A peer
with no session counts from 0. The clock wraps at 8192 s, so a 32-bit
float holds it to half a millisecond and a shader takes it as a float
uniform; the built-in sea's waves repeat over 8192 s and run on across
the wrap without a seam.
Returns number — Seconds on the water clock.
local ahead = Physics.water(p, Physics.waterTime() + 0.5)
typed/builtin//modules/api/engine/physics/P/waters
P.waters() -> { [string]: any }
Every body of water defined, by name, with what it is: its kind,
priority, density, entity, space (with, for a body stated in its entity's
space, the frame the entity stands it at: position, rotation
{ x, y, z, w } and scale, or nowhere = true while the entity is
scaled to nothing along an axis), region, current, and for a sea its waves,
lattices, period, speed and shoalDepth, for a grid its columns,
rows, texels wet and whether its flow is stated or follows the
slope.
Returns { [string]: any } — { [string]: table }.
for name, w in Physics.waters() do print(name, w.kind) end
typed/builtin//modules/api/engine/physics/P/whyStill
P.whyStill(entityId: string | entityRef) -> (string?, string?)
Why the solver is not moving a body. Returns nil when it IS moving
it, and otherwise one of noBody, simulationNotStepping, disabled,
static, kinematic, infiniteMass, translationLocked,
gravityDisabled, asleep, outsideIsland, resting, aboutToMove —
the nearest cause, so the answer names the thing to change. A second return
carries the detail: which collider it rests on and how deeply, what its
effective gravity works out to, and so on.
Parameters
entityIdstring | entityRef— Entity id or proxy.
Returns (string?, string?) — (reason, detail).
local why, detail = Physics.whyStill(id); if why then print(why, detail) end
typed/builtin//modules/api/engine/physics/P/wind
P.wind(point: vec3, moment: number?) -> vec3
How the air at a point moves, m/s: every wind field covering it,
summed, at moment on the water clock (Physics.waterTime), by default
now (inside a physics step, the moment that step reaches). Zero where no
field blows. The same point and moment answer the same on every peer.
Parameters
pointvec3— The point, in world space.momentnumber(optional) — Seconds on the water clock. Default: now.
Returns vec3 — The wind's velocity.
local w = Physics.wind(entity(flag).position); print(w.x, w.z)
typed/builtin//modules/api/engine/physics/P/winds
P.winds() -> { [string]: any }
Every wind field defined, by name: its kind, velocity, gust,
gustPeriod, gustSize, gustDirection, space, its region,
falloff and entity where it has them, the frame its entity stands
a field in that entity's space at (or nowhere = true), and what its
kind is made of (a grid's origin, size, columns, rows, layers,
scroll, wrap; a vortex's or radial wind's center, axis,
radius, speed, and a vortex's inflow, updraft and
updraftRadius).
Returns { [string]: any } — { [string]: table }.
for name, w in Physics.winds() do print(name, w.velocity.x) end
typed/builtin//modules/api/engine/physics/P/worldState
P.worldState() -> PhysicsWorldState
How many bodies, colliders, joints and contacts the simulation holds
right now, with world gravity, the timestep, whether the pipeline is
stepping at all, what the last step cost, and how many step hooks run
around every step (stepHooks). Counted off the solver, so
a body that failed to build is absent here while its Physics component
still exists.
Returns PhysicsWorldState — A PhysicsWorldState.
local w = Physics.worldState(); print(w.bodies.awake .. "/" .. w.bodies.total .. " awake")
print(Physics.worldState().contacts.touchingPairs .. " pairs touching")
typed/builtin//modules/api/engine/playable/playable/_carried
playable._carried(report: { client: string, declared: { by: string, note: string?, at: number }? }) -> boolean
Internal: take in the playable statement an agent made in a sub-client
of the user's editor, which the editor hands the user's client so the
person reads the milestone the agent stated. report.client names the
sub-client; report.declared ({ by, note?, at }) is its statement, and
absent it withdraws the statement that sub-client made, leaving one made
anywhere else.
Parameters
report{ client: string, declared: { by: string, note: string?, at: number }? }—{ client, declared? }.
Returns boolean — true when the milestone took the report in.
typed/builtin//modules/api/engine/playable/playable/_judgeCounts
playable._judgeCounts() -> { judged: number, fingerprints: number }
Test-only: how many times the scene has been judged since the engine
started (judged), and how many of those read the scene through its
fingerprint (fingerprints) rather than answering from the counters a
still edit-mode scene's verdict moves with.
Returns { judged: number, fingerprints: number } — { judged, fingerprints }.
typed/builtin//modules/api/engine/playable/playable/_reset
playable._reset()
Test-only: clear the agent's statement, the first moment and the change count, so a suite starts from a freshly opened world.
typed/builtin//modules/api/engine/playable/playable/_worldIdentityDrill
playable._worldIdentityDrill(reader: (() -> string?)?)
Test-only: stand in for reading which world the engine is bound to
(its guid and branch), so a suite drives a move to another world, or a
read that fails, through the engine's own world lifecycle. The reader
returns the identity, or raises to stand for a read that fails. Nil
reads the bound world again; playable._reset does the same.
Parameters
reader(() -> string?)(optional) — The stand-in, or nil.
typed/builtin//modules/api/engine/playable/playable/declare
playable.declare(opts: { by: string?, note: string? }?) -> PlayableState
State that the world is playable, as the agent building it: a first
version ready, or a game the scene rule cannot see. It holds until
playable.withdraw, or until the engine moves to another world (another
guid, or another branch), and readers see source read "agent" (or
"both" while the scene sets it too). While a world is being left and the
next one opened it stands without making the world playable; a statement
made then is about the world arriving, and stands in it. Made in a
sub-client the user's editor runs for an agent, the statement (and its
withdrawal) reaches the user's client too, which reads it in declared
with the sub-client named as client, while it is on the same world and
branch.
Parameters
opts{ by: string?, note: string? }(optional) —{ by?, note? }: who states it (default"agent") and a line saying what is ready.
Returns PlayableState — The state after the statement.
playable.declare({ by = "DotBot", note = "First version: tap the ball to bounce it" })
typed/builtin//modules/api/engine/playable/playable/install
playable.install()
Internal: start the engine's judging loop, which judges the scene on every frame the engine runs so the first playable moment is kept whether or not anything reads it, and follow the world's lifecycle so each world opened starts from its own verdict. Called once by the prelude on the engine thread.
typed/builtin//modules/api/engine/playable/playable/isPlayable
playable.isPlayable() -> boolean
Whether the world is playable right now, set by the scene or by an agent.
Returns boolean — true when playable.
if playable.isPlayable() then showPlayButton() end
typed/builtin//modules/api/engine/playable/playable/offChange
playable.offChange(handle: number) -> boolean
Drop an onChange subscription by its handle.
Parameters
handlenumber— The handleplayable.onChangereturned.
Returns boolean — true when a live subscription carried it.
playable.offChange(h)
typed/builtin//modules/api/engine/playable/playable/onChange
playable.onChange(callback: (PlayableState, PlayableState?) -> ()) -> number
Run a callback each time the world goes in or out of the playable state,
or the source that sets it changes. It fires on the frame the change is
judged, with the new state and the one before it. A callback registered
while the world is playable is not fired for that state; read
playable.state() for it. The subscription ends with the context that
made it as well: a module body's with the module's next run or its leaving
the require cache (the world's content ending as the engine leaves the
world included), a component's with that component instance.
Parameters
callback(PlayableState, PlayableState?) -> ()— Called ascallback(state, previous).
Returns number — The handle playable.offChange takes.
local h = playable.onChange(function(s) playButton.visible = s.playable end)
typed/builtin//modules/api/engine/playable/playable/state
playable.state() -> PlayableState
The milestone as it stands this frame. playable is the verdict;
source names what set it ("scene", "agent" or "both"); scene is the
scene's own verdict and declared the agent's statement; missing lists why
the scene does not set it (each { code, message, entity? }); player names
the spawn, prototype, body, camera and controlling components the verdict
rests on; since is when the current playable stretch began and first the
first time the world reached it since it was opened (each { at, engineTime, frame, source }, at in Unix seconds); changes counts the times the
verdict or its source has changed since then.
Returns PlayableState — The PlayableState.
local s = playable.state()
if not s.playable then print(s.missing[1].message) end
typed/builtin//modules/api/engine/playable/playable/wait
playable.wait(opts: PlayableWaitOpts?) -> (boolean, PlayableState)
Wait until the world is playable, at most timeout seconds of wall
clock (default 60). source = "scene" waits for the scene's own verdict and
source = "agent" for an agent's statement; omitted, either one ends the
wait. Returns at once when it already holds.
Parameters
optsPlayableWaitOpts(optional) —{ timeout?, source? }.
Returns (boolean, PlayableState) — true, state once playable; false, state when the timeout passes first, with state.missing naming what the scene still lacks.
local ok, s = playable.wait({ timeout = 120 })
if not ok then print("not playable yet:", s.missing[1] and s.missing[1].message) end
typed/builtin//modules/api/engine/playable/playable/withdraw
playable.withdraw() -> boolean
Withdraw an agent's statement that the world is playable. The scene's own verdict is unchanged.
Returns boolean — true when a statement stood.
playable.withdraw()
typed/builtin//modules/api/engine/playerSetupValidation/M/checkActiveScene
M.checkActiveScene() -> { { entity: string, message: string } }
Gather every player-setup validation message for the live active-layer scene: the per-entity rules across all PlayerSpawn / PlayerPrototype entities, the competing-camera rule, and the scene-intent rule. Returns a flat list an agent can read to see what to fix. The verdict belongs to the settled scene, so the call holds while a scene load or a mode-flip transition is rebuilding the live tree, and judges what the rebuild lands on.
Returns { { entity: string, message: string } } — An array of { entity = name/id, message = string }.
typed/builtin//modules/api/engine/playerSetupValidation/M/checkEntity
M.checkEntity(entityId: string) -> { string }
Validate a single PlayerSpawn or PlayerPrototype entity, returning agent-facing messages naming what is wrong and what to do. An entity carrying neither component (or one that does not exist) yields no messages.
Parameters
entityIdstring— The entity to inspect.
Returns { string } — An array of message strings; empty when the entity is well-formed.
typed/builtin//modules/api/engine/playerSetupValidation/M/checkScene
M.checkScene(opts: { playerIntent: string, spawnCount: number, cameraCount: number }) -> { string }
Validate a scene's player intent against its PlayerSpawn / Camera counts, returning agent-facing messages. A "spawns" scene with no PlayerSpawn, or a "none" scene with no Camera, yields a message; every other combination is clean.
Parameters
opts{ playerIntent: string, spawnCount: number, cameraCount: number }—{ playerIntent: string, spawnCount: number, cameraCount: number }.
Returns { string } — An array of message strings; empty when the scene is well-formed.
typed/builtin//modules/api/engine/playerSetupValidation/M/checkSceneJson
M.checkSceneJson(sceneJson: { [string]: any }) -> { { code: string, severity: string, message: string } }
Validate a decoded scene.json document statically: the full player-setup
rule set (per-entity, competing-camera, scene-intent) run over the scene's
authored entity tree without loading it. This is what the scene assetType's
validate hook calls, so asset.validate / worldValidation / the
world.push gate all report a broken player setup at authoring time.
Parameters
sceneJson{ [string]: any }— The decoded scene.json table ({ player, version, entities }).
Returns { { code: string, severity: string, message: string } } — An array of { code, severity, message } problem records.
typed/builtin//modules/api/engine/playerSetupValidation/M/entityProblems
M.entityProblems(entityId: string) -> { { entity: string, code: string, severity: string, message: string } }
The problems of a single PlayerSpawn or PlayerPrototype entity as
records, the rules checkEntity runs, each carrying the stable code a
reader branches on beside the message an agent reads. An entity carrying
neither component (or one that does not exist) yields none.
Parameters
entityIdstring— The entity to inspect.
Returns { { entity: string, code: string, severity: string, message: string } } — An array of { entity, code, severity, message }; empty when the entity is well-formed.
typed/builtin//modules/api/engine/playerSetupValidation/M/playReadinessProblems
M.playReadinessProblems() -> { { entity: string, message: string } }
The player-setup problems that must block a flip into play: the per-entity spawn/prototype rules (body + camera refs set, resolving to descendants, a single referenced camera) and the scene-intent rule, over the LIVE active scene. A "spawns" scene with none of these problems is ready to play. The competing-camera rule is deliberately excluded — the editor's own free-fly camera is a live viewport camera outside every prototype, so running it here would false-positive on every edit session; that rule stays a static / publish-time concern. Empty for a non-"spawns" scene (no player requirement), and empty while the active scene is still being materialised — the verdict belongs to the settled scene, so it waits for the layer to finish loading and for any mode-flip transition to converge.
Returns { { entity: string, message: string } } — An array of { entity = name/id, message = string }; empty = ready.
typed/builtin//modules/api/engine/player_prototype_spawn/M/applyNetworkScope
M.applyNetworkScope(cloneRootId: string, isOwner: boolean, isAuthority: boolean)
Prune a clone subtree by each node's networkScope against the caller's
role. Walks the subtree from cloneRootId; a node scoped OwnerOnly is
despawned when the caller is not the owner, AuthorityOnly when the caller is
not the authority, and Replicated (or any other value) is kept.
Parameters
cloneRootIdstring— The clone's root entity id.isOwnerboolean— Whether the caller owns this clone.isAuthorityboolean— Whether the caller is the simulation authority for this clone.
typed/builtin//modules/api/engine/player_prototype_spawn/M/authorDefault
M.authorDefault() -> { [string]: string }
Author the canonical default player setup into the active scene — the same shape the default world and the static_player canonical scene ship: a PrototypeOnly prototype whose body adopts the humanoid avatar and whose OwnerOnly camera rig runs the orbital follow behavior, plus a spawn at the origin. Returns the authored entity ids. This is the single builder the scene.player tool set to "spawns" and the "player" scene template both resolve to, so a joining user's avatar always replaces the same authored body.
Returns { [string]: string } — { setups, prototype, body, camera, spawns, spawn } — the authored ids.
typed/builtin//modules/api/engine/player_prototype_spawn/M/captureTemplatesFromEntities
M.captureTemplatesFromEntities(entities: { any })
Build the prototype-template registry from a scene's authored entity records (the parsed scene data, not live entities). This is the primary capture path: it is independent of scene-load order and runtime composition, so it captures the clean authored subtree (no composed avatar) and works in the runtime profile, which boots straight to play. Called by the scene loader for v7 scenes.
Parameters
entities{ any }— The scene's authored entity records (each{ id, name, parent, networkScope, renderLayer, transform, components }).
typed/builtin//modules/api/engine/player_prototype_spawn/M/capturedTemplate
M.capturedTemplate(prototypeId: string) -> any
The captured authored subtree for a PlayerPrototype — the clone source
spawnFor instantiates for each joining player, keyed by the prototype's
authored entity id (the id a PlayerSpawn's prototype field carries). Each
node is { id, name, participation, networkScope, renderLayer, position, rotation, scale, components = { [type] = data }, namedComponents?, children }:
components holds each type's anonymous instance, and namedComponents = { [type] = { [instanceName] = data } } the instances added under a name. Where the
materialisation keeps authored prototype subtrees out of the live scene —
play — this template is the authored prototype, and it is the subtree
spawnFor clones for each joining player.
Parameters
prototypeIdstring— The PlayerPrototype root's authored entity id.
Returns any — The template node, or nil when no template is captured for that id.
local proto = player_prototype_spawn.capturedTemplate(spawn.prototype.id)
typed/builtin//modules/api/engine/player_prototype_spawn/M/chooseSpawn
M.chooseSpawn(ctx: any?) -> (string?, { [string]: any }?, string?)
Pick the PlayerSpawn-carrying entity to spawn from. Enumerates entities
carrying the PlayerSpawn component in the joining user's ROOT scene, skipping
any that live in an additive overlay layer (editor UI, HUD scenes). When the
root scene resolves (ctx.rootSceneGuid, else layers.active.guid), only
spawns in that scene's layer are considered; otherwise every non-overlay
spawn is eligible. Spawns with no layer attribution yet belong to the world
root and stay eligible either way. Honors an optional ctx.spawnId
override (used for
deterministic selection), otherwise returns the first matching spawn.
Parameters
ctxany(optional) — A table;ctx.spawnIdoptionally names the spawn entity to select,ctx.rootSceneGuidoptionally names the scene layer to scope the search to.
Returns (string?, { [string]: any }?, string?) — (spawnEntityId, playerSpawnComponentProxy, spawnSceneLayer), or (nil, nil, nil) when none match. spawnSceneLayer is the chosen spawn's own scene-layer guid — the scene the clone must belong to.
typed/builtin//modules/api/engine/player_prototype_spawn/M/clearJoinHook
M.clearJoinHook(guid: string)
Clear a scene's join-hook flag. Called when a "spawns" scene unloads so the once-registered connect / play-entry handlers stand down (they no-op while no wired scene remains). Idempotent for an unknown guid.
Parameters
guidstring— The scene guid passed to installJoinHook.
typed/builtin//modules/api/engine/player_prototype_spawn/M/heldAsTemplate
M.heldAsTemplate(entityId: string) -> (any, string?)
The captured template node holding an authored entity the live scene leaves out. Where the materialisation keeps authored PlayerPrototype subtrees out of the scene (play), every entity of such a subtree is held by its prototype's template instead, carrying the authored state the scene's records give it, unsaved edits included. Answers that node and the prototype's id; nil for an entity no template holds, and wherever prototypes materialise as live entities (edit).
Parameters
entityIdstring— The authored entity's id.
Returns (any, string?) — The template node ({ id, name, components = { [type] = data }, namedComponents?, children, ... }) and the id of the prototype whose template holds it, or nil.
local node, prototypeId = player_prototype_spawn.heldAsTemplate(row.id)
typed/builtin//modules/api/engine/player_prototype_spawn/M/installJoinHook
M.installJoinHook(sceneProxy: any?, opts: { materialisedForPlay: boolean? }?) -> boolean
Wire spawnFor to the world's connected-user join event. When a user
connects, the hook picks a PlayerSpawn and instantiates that user's prototype
instance (internal identity + avatar + camera-follow) via spawnFor. The
trigger is world.connectedUsers.onConnect — the WORLD-level "a user joined
the session" event — not the room players registry, so the internal identity the
clone becomes (which folds into that registry) does not re-trigger a spawn.
Entering play spawns every already-connected user (their onConnect fired in
edit, ignored then). A scene wired while ALREADY in play — the runtime
profile boots straight into play, or a scene swapped in mid-play — gets that
same sweep immediately, since no play flip follows to trigger it. Every spawn
path is per-user idempotent: a user who already owns a live clone is skipped,
so overlapping paths and re-flips never produce a second player. A scene
whose load placed its prototypes for edit (opts.materialisedForPlay = false, a flip to play that landed part-way through its load) takes no
sweep: the flip rebuilds that scene for play, and the rebuilt scene's
hook places every connected user. Idempotent per scene proxy: a second
call for the same scene installs nothing further.
Parameters
sceneProxyany(optional) — A non-additive Scene proxy.opts{ materialisedForPlay: boolean? }(optional) — Optional{ materialisedForPlay: boolean? }: whether the scene's load placed its prototypes as play's clone sources. Absent reads as true.
Returns boolean — true when the hook was installed (or was already installed), false when the connected-users surface is unavailable.
typed/builtin//modules/api/engine/player_prototype_spawn/M/runtimeSpawnedInfo
M.runtimeSpawnedInfo(id: string) -> { [string]: any }?
Read back the runtime provenance stamped on a clone root by spawnFor.
Parameters
idstring— The clone root entity id.
Returns { [string]: any }? — { sourcePrototype, ownerUserId, ownerPlayer }, or nil when the entity carries no provenance.
typed/builtin//modules/api/engine/player_prototype_spawn/M/spawnFor
M.spawnFor(ctx: any?) -> string?
Spawn a player instance for a joining user from the chosen PlayerSpawn's
prototype. Chooses a spawn (honoring ctx.spawnId), resolves and validates
its prototype, clones the prototype subtree, activates and reveals the clone,
prunes it by networkScope against the caller's owner/authority role (both
default true), marks the clone RuntimeOnly, stamps provenance attributes,
places the clone at the spawn's world transform, and registers it with the
prototype lifecycle so it is despawned on the return to edit.
Parameters
ctxany(optional) —{ userId, playerEntityId?, spawnId?, isOwner?, isAuthority? }.
Returns string? — The clone root entity id, or nil when no eligible spawn / prototype exists.
typed/builtin//modules/api/engine/player_prototype_spawn/M/storePrototypeTemplate
M.storePrototypeTemplate(prototypeId: string)
Capture a PlayerPrototype's authored subtree into the template registry. Called by PlayerPrototype.awake (before its Asset composes and before it deactivates) so spawnFor can instantiate the authored structure per player.
Parameters
prototypeIdstring— The PlayerPrototype root entity id.
typed/builtin//modules/api/engine/player_prototype_spawn/M/userHasSpawnedPlayer
M.userHasSpawnedPlayer(userId: string?) -> boolean
Whether a live clone spawned by spawnFor already carries this user's owner
provenance. Scans the live entities for a root whose ownerUserId attribute
matches. The idempotency guard the auto-spawn paths use so a user who already
has a spawned player never gets a second one.
Parameters
userIdstring(optional) — The joining user's account id.
Returns boolean — true when a live clone owned by userId exists.
typed/builtin//modules/api/engine/players/playerHandle/avatar
playerHandle.avatar -> entityRef?
This player's body in the 3D world, or nil until a live one is bound. Assign a live entity ref to bind a body, or nil to clear it.
Returns entityRef?
typed/builtin//modules/api/engine/players/playerHandle/displayName
playerHandle.displayName -> string
The name this player shows as, empty until the owner stamps it or it replicates.
Returns string
typed/builtin//modules/api/engine/players/playerHandle/identity
playerHandle.identity -> string
The account id this player belongs to, under the second name it answers to.
Returns string
typed/builtin//modules/api/engine/players/playerHandle/isLocal
playerHandle.isLocal -> boolean
Whether this session owns this player.
Returns boolean
typed/builtin//modules/api/engine/players/playerHandle/ready
playerHandle.ready -> boolean
Whether this player has a live body bound.
Returns boolean
typed/builtin//modules/api/engine/players/playerHandle/userId
playerHandle.userId -> string
The account id this player belongs to, empty until the owner stamps it or it replicates.
Returns string
typed/builtin//modules/api/engine/players/players/count
players.count(self) -> number
How many players are connected to this room.
Parameters
self
Returns number
typed/builtin//modules/api/engine/players/players/exists
players.exists(self, id: string) -> boolean
Whether a player with this account id or identity entity id is connected.
Parameters
selfidstring
Returns boolean
typed/builtin//modules/api/engine/players/players/get
players.get(self, key: string) -> playerHandle?
The connected player with this account id or identity entity id, or nil.
Parameters
selfkeystring
Returns playerHandle?
typed/builtin//modules/api/engine/players/players/list
players.list(self) -> { playerHandle }
Every player connected to this room, as a snapshot.
Parameters
self
Returns { playerHandle }
typed/builtin//modules/api/engine/players/players/localPlayer
players.localPlayer -> playerHandle?
The player this session owns, or nil before its identity has landed.
Returns playerHandle?
typed/builtin//modules/api/engine/players/players/localPlayerEntityId
players.localPlayerEntityId -> string?
The id of the local identity entity, answerable before its UserIdentity component has attached.
Returns string?
typed/builtin//modules/api/engine/players/players/localReady
players.localReady -> boolean
Whether the local player is loaded: its identity exists with a live avatar, or the scene opted the avatar out.
Returns boolean
typed/builtin//modules/api/engine/players/players/offJoin
players.offJoin(self, handle: number) -> boolean
Remove an onJoin subscription by its handle.
Parameters
selfhandlenumber
Returns boolean
typed/builtin//modules/api/engine/players/players/offLeave
players.offLeave(self, handle: number) -> boolean
Remove an onLeave subscription by its handle.
Parameters
selfhandlenumber
Returns boolean
typed/builtin//modules/api/engine/players/players/offLocalReady
players.offLocalReady(self, handle: number) -> boolean
Remove an onLocalReady subscription by its handle.
Parameters
selfhandlenumber
Returns boolean
typed/builtin//modules/api/engine/players/players/onJoin
players.onJoin(self, cb: (playerHandle) -> ()) -> number
Subscribe to players joining the room, firing once for each player already in it. Answers a handle for offJoin.
Parameters
selfcb(playerHandle) -> ()
Returns number
typed/builtin//modules/api/engine/players/players/onLeave
players.onLeave(self, cb: (playerHandle) -> ()) -> number
Subscribe to players leaving the room. Answers a handle for offLeave.
Parameters
selfcb(playerHandle) -> ()
Returns number
typed/builtin//modules/api/engine/players/players/onLocalReady
players.onLocalReady(self, cb: (playerHandle) -> ()) -> number
Subscribe to the local player becoming ready, firing immediately for a subscriber that arrives after it already has. Answers a handle for offLocalReady.
Parameters
selfcb(playerHandle) -> ()
Returns number
typed/builtin//modules/api/engine/players/players/ownerOf
players.ownerOf(self, avatar: any) -> playerHandle?
The connected player whose body is this avatar, taken as an entity ref or an entity id.
Parameters
selfavatarany
Returns playerHandle?
typed/builtin//modules/api/engine/plugins/plugins/awaitingPerson
plugins.awaitingPerson(plugin: string) -> boolean
Whether a call to this plugin is waiting on a person to answer the engine's consent dialog.
Parameters
pluginstring— The plugin asset's library identity, written as a LITERAL.
Returns boolean — True while a dialog for this plugin is unanswered.
if plugins.awaitingPerson(PLUGIN) then print("waiting for you") end
typed/builtin//modules/api/engine/plugins/plugins/call
plugins.call(plugin: string, method: string, ...: any?) -> any
Call a method the plugin at plugin exposes.
Parameters
pluginstring— The plugin asset's identity, written as a LITERAL: the same stringasset.identityanswers for it (motionfor a plugin in this world,@publisher::path.namefor one in a library), or its path. A computed identity is refused: runtime code has no dynamic requires and a plugin is no exception, because a name the reference deriver cannot read at authoring time is a dependency that never enters the graph.methodstring— A method the plugin'splugin.yamlexposes. One it does not is not callable, whatever the component carries....any(optional) — The call's arguments: numbers, strings, booleans, nil, buffers and tables of them. A whole number arrives as an integer. One call's arguments hold at most 16,384 values (a table held by several entries counted at each) and 64 MiB of strings and buffers; a call past that, or holding a table inside itself, is refused by name. Bulk data crosses as a buffer.
Returns any — A promise of the plugin's answer, as a value: a table as a table, a number as a number. A refusal raises where it is awaited.
local agents = await(plugins.call("@builtin/plugins/dotbot.plugin", "agents"))
typed/builtin//modules/api/engine/plugins/plugins/isLoaded
plugins.isLoaded(plugin: string) -> boolean
Whether the plugin is loaded and answering calls.
Parameters
pluginstring— The plugin asset's identity, written as a LITERAL.
Returns boolean — True while it is loaded. Never raises: a caller asking is usually waiting for a plugin that is still loading.
while not plugins.isLoaded("motion") do task.wait(0.1) end
typed/builtin//modules/api/engine/plugins/plugins/off
plugins.off(plugin: string, id: number) -> boolean
Stop a listener plugins.on started.
Parameters
pluginstring— The same identity the listener was started with.idnumber— The idplugins.onanswered.
Returns boolean — Whether a listener was removed.
typed/builtin//modules/api/engine/plugins/plugins/on
plugins.on(plugin: string, listener: (string, any) -> ()) -> number
Listen to the events a plugin raises.
Parameters
pluginstring— The plugin asset's library identity, written as a LITERAL.listener(string, any) -> ()—function(eventType, payload)—payloadis the event's decoded JSON.
Returns number — The subscription id, for plugins.off.
local id = plugins.on("@builtin/plugins/dotbot.plugin", function(kind, body) end)
typed/builtin//modules/api/engine/plugins/plugins/openUrl
plugins.openUrl(plugin: string, url: string) -> any
Ask the person to open one of the plugin's own pages.
Parameters
pluginstring— The plugin asset's library identity, written as a LITERAL.urlstring— An https URL whose host the plugin declared undernetwork.hosts. Anywhere else is refused — otherwise this would be an unbounded way to put an address in front of somebody.
Returns any — A promise: true when it opened, or the refusal.
await(plugins.openUrl("@builtin/plugins/dotbot.plugin", "https://claude.ai/login"))
typed/builtin//modules/api/engine/plugins/plugins/state
plugins.state(plugin: string) -> { state: string, reason: string? }
Where the plugin asset at plugin stands, so a caller can tell a
plugin that is still loading from one that failed to load.
Parameters
pluginstring— The plugin asset's identity, written as a LITERAL.
Returns { state: string, reason: string? } — { state, reason }. state is loaded (answering calls), loading (its component is compiling and starting), failed (its most recent load settled without a plugin), stopped (the plugin stopped on its own) or none (no load of it has started). reason says why for failed and stopped. Never raises.
local s = plugins.state("motion")
if s.state == "failed" then print("motion did not load: " .. s.reason) end
typed/builtin//modules/api/engine/plugins/plugins/status
plugins.status() -> { [string]: any }
What the plugin host loaded, and what refused to load.
Returns { [string]: any } — started is whether the host has run; plugins lists each one with loaded, and the error that refused it where there is one. Once the host has run, execution states how plugin code runs: native (compiled to the CPU's own instructions, the desktop build), interpreted (wasmtime's Pulley interpreter, every Android build) or browser (the browser's own WebAssembly engine). On the web build it also carries what the browser offers of JavaScript Promise Integration, which every plugin's host calls are lowered onto.
local report = plugins.status()
print(report.started, #report.plugins)
typed/builtin//modules/api/engine/postprocess/postprocess/add
postprocess.add(name: string, shader: string | AssetRef, opts: PostprocessOpts?) -> (boolean, string?)
Register a fullscreen post-process effect. This call is what
puts a pass into the frame — a post-process .shader asset defines an
effect, and renders only once registered here. The chain applies the
registration on the caller's own stack and the returned boolean is its
answer, so a setProperty or setTexture naming the effect in the same
call finds it. shader is a .shader asset reference whose shader.wgsl
provides fn fragment(in: PostInput) -> vec4<f32> and whose
properties.yaml declares the effect's properties; the engine generates the
group(0) framework + schema-driven group(1) from that schema. Editing that
shader afterwards recompiles this effect in place, keeping its enabled
state, priority, layer and tuned property values. Registering again under
a name the chain already holds puts this registration in that effect's
place and keeps each value setProperty wrote into it for a property this
registration declares and takes that value for, and each texture
setTexture bound to a slot it declares; postprocess.remove before the
registration starts the effect from its defaults. WGSL text is accepted
in place of a shader reference, and then opts.properties is the whole
schema — this form is deprecated and will be removed, author the effect
as a .shader asset instead. The chain effects of one stage run in
priority order (lower first, default 100); priority = "last" runs the
effect after every numbered chain effect of its stage, and chain effects
sharing a priority (two "last" among them) run in the order they
registered; a priority of 0 or below runs first. A render feature's
passes of the stage run where renderer.post.stages() lists them: in
ui, an afterPost pass runs after every chain effect.
A priority of 4294967295 or above, and any other string, is refused with
the range.
A registered effect runs over the live viewport's frame AND over every
offscreen one — a capture from a world-space station, one orbiting an
entity, one of a named camera, a render-to-texture camera. A texture
camera's picture reaches the screen through the frame that shows it, so an
all-layer effect runs there, over the texture along with the rest of the
interface, and once: the camera's own render runs the scene and display
layers, and the all layer too only with textureColorSpace = "presented"
(a capture's camera, which reads its texture back as the finished frame;
see the Camera component). In each of those
the effect's engine.view_proj / engine.prev_view_proj /
engine.inv_view_proj are the camera THAT render was drawn from and
engine.resolution is that target's own size, so a pass reconstructing
world space from zero_scene_depth(uv) reconstructs against the station
and lens the capture asked for. An offscreen capture is therefore an oracle
for an authored grade: it photographs a chosen station without taking the
on-screen camera from whoever else is driving the scene, and a capture's
postProcessing = false is the one control that takes the chain off the
frame it returns. An offscreen render keeps no view history of its own, so
engine.prev_view_proj there holds that same matrix rather than the frame
before it, and a pass taking camera motion from the two reads none.
Parameters
namestring— Unique effect name.shaderstring | AssetRef— A resolvedshaderasset reference, or author WGSL (fn fragment(in: PostInput)only).optsPostprocessOpts(optional) —{ priority = 100 | "last", enabled = true, stage = "optics"|"display"|"ui", layer = "scene"|"display"|"all" (omitted: follows stage, else space), space = "light"|"display", properties = {{name, type, default?, min?, max?, textureDefault?}}, passes = {{name, entry, scale?, inputs?}} }— with a shader asset,propertieslayers over the asset's own schema.stagenames the post stage of the frame the effect runs in (renderer.post.stages()lists them):"optics"runs it before the display transform, over the scene's light;"display"after the display transform and before the UI, over code values;"ui"after the UI. With a shader asset it defaults to thestage:the asset declares. A stage the frame does not have, or one only render features run in, is refused with the stages there are.layerpicks which composited image the effect grades:"scene"runs it before the UI is drawn, over the scene's own light in a float target, so it grades the rendered picture and leaves every widget on screen as authored;"display"runs it before the UI is drawn too, over the picture the display transform fitted to the screen, and leaves every widget as authored; and"all"runs it after the UI has landed, over that picture, so the interface is graded along with the picture. A call that names neither takes the layer itsspacebelongs to: a"light"effect grades"scene"and a"display"effect grades"display", so a bloom reads the scene's highlights where they still stand above 1.0 and a lookup table reads code values. Naming"all"is what an effect that must grade the interface says — and on a world several authors share, it grades everyone else's screens too.spacenames whatfragment()reads and returns:"light"(the default) for a threshold/blur/grade on the scene,"display"for a lookup table, dither ladder or authored overlay working on code values. With a shader asset, defaults to what that asset'sgetSpace()declares.passesnames the passes the effect draws, each an entry in the shader, a fraction of the view it draws at, and what it reads. With a shader asset, defaults to what that asset'sgetPasses()declares; a single-pass effect (the common case) declares none.textureDefaultis what atype = "texture"property samples while nothing is bound to it:"white"(1,1,1,1 — the default),"black"(0,0,0,1),"normal"(0.5,0.5,1,1) or"transparent"(0,0,0,0). An effect that lays its texture over the scene wants"transparent", so the frame is untouched untilsetTexturebinds a texture that exists.
Returns (boolean, string?) — True when the chain took the effect; false and the compiler's message when it refused it. A shader that does not compile draws nothing at any property value, so it is not registered and postprocess.list() never names it. __display__, __output__ and __blit__ are the renderer's own effects, and a registration under any of them is refused with a message saying so. A call made from inside queue() or batch(), where the engine has not run the registration by the time the call returns, answers true for the queued request.
postprocess.add("vignette", asset.resolve("@builtin::shaders.post.vignette", "shader"))
postprocess.add("vignette", VIGNETTE_WGSL, { properties = {{ name = "intensity", type = "float", default = 0.5 }} })
typed/builtin//modules/api/engine/postprocess/postprocess/describe
postprocess.describe(name: string) -> PostprocessDescription?
One effect by name, read in full: the chain state
postprocess.status() lists for it, and on top of that properties — the
schema the effect declared, each entry { name, type, default?, min?, max?, textureDefault?, options? } in the shape add takes — and values, what
each of those properties currently holds. A property's value is the one
the last setProperty wrote, or the schema's own default where nothing
has written one, and it comes back as a number for a scalar, as the array
for a wider value, and as the option's name for a property with
options (__display__'s curve reads "agx"), which is what
setProperty takes, so a property read here is written straight back.
This is the read-back for a property write. setProperty answers whether
the uniform took the value; this answers what the effect holds now, which
is the reading a pass that writes its properties every frame needs and the
one that tells a mistyped property name from an effect that is not
grading. The schema and the values are the engine's own record of the
effect — the schema it was registered with and every write the chain
accepted into its uniform, the same record /runtime/fx/<name>/meta.json
is serialized from. A write the chain refused is not in it, and neither is
one made against a property the schema does not declare.
Before an effect is registered its schema lives on the .shader asset it
will render: asset.resolve("@builtin::shaders.post.bloom", "shader"):getProperties() names what that shader declares.
Parameters
namestring— Effect name.
Returns PostprocessDescription? — The effect's state, schema and live values, or nil when nothing is registered under the name. An effect the renderer registers itself declares no properties of its own, and its properties and values are empty.
local e = postprocess.describe("vignette")
print(if e then e.values.intensity else "not registered")
for _, p in ipairs(postprocess.describe("bloom").properties) do
print(p.name, p.type, p.min, p.max)
end
typed/builtin//modules/api/engine/postprocess/postprocess/displayCurves
postprocess.displayCurves() -> { string }
The display curves __display__ draws with, by name, in the order of
their numbers: clamp (each channel clipped at the peak), reinhard,
aces (the ACES 1.x RRT + sRGB ODT tone scale, Hill's fit), pbrNeutral
(Khronos PBR Neutral), agx (the default), agxPunchy, tony (Tony
McMapface) and gt (Gran Turismo). Every curve but the clamp and Tony
McMapface keeps a brightening colour's hue, and every curve but the clamp
carries light too bright for its colour on toward white with every step
still showing; Tony McMapface turns a bright colour's hue the way the eye
sees it turn. Pass a name to
setProperty("__display__", "curve", name); the curves are
@builtin::shaderModules.displayCurves.
Returns { string } — The curve names, a fresh array.
postprocess.setProperty("__display__", "curve", postprocess.displayCurves()[5])
typed/builtin//modules/api/engine/postprocess/postprocess/list
postprocess.list() -> { string }
List all registered post-process effect names in renderer priority order (lower priority runs first).
Returns { string } — Array of effect names.
for _, n in ipairs(postprocess.list()) do print(n) end
typed/builtin//modules/api/engine/postprocess/postprocess/remove
postprocess.remove(name: string) -> boolean
Queue removal of a post-process effect. Takes effect on the next frame. Removing a name that isn't registered is a silent no-op.
Parameters
namestring— Effect name to remove.
Returns boolean — True when the mutation was queued. False, named in a WARN, for the effects the renderer registers itself: __display__, the chain's display transform, which stays in every frame and is tuned through its curve and exposure properties, __output__, the output stage that writes the presented surface (renderer.output), and __blit__, the copy that carries every render into its target, every capture and the viewport included.
postprocess.remove("vignette")
typed/builtin//modules/api/engine/postprocess/postprocess/setEnabled
postprocess.setEnabled(name: string, enabled: boolean) -> boolean
Queue an enable/disable toggle on a registered post-process effect. Targeting an unknown name is a silent no-op.
Parameters
namestring— Effect name.enabledboolean— True to enable, false to disable.
Returns boolean — True when the mutation was queued. False, named in a WARN, for a __display__ disable (the chain's display transform stays in every frame, and curve = "clamp" is its linear curve), for an __output__ disable (renderer.output.set({ dither = "off" }) writes the frame undithered) and for a __blit__ enable (the copy that carries every render into its target joins no chain).
postprocess.setEnabled("bloom", false)
typed/builtin//modules/api/engine/postprocess/postprocess/setProperty
postprocess.setProperty(name: string, prop: string, value: (number | { number } | string)) -> boolean
Set a named material property on a registered post-process
effect. The property must be declared in the effect's properties
schema; read in WGSL as material.<prop>. value is a number or a
number array (vec/color), inside the range the schema declares. A
property with options (describe lists them) takes one of their names:
__display__'s curve takes a display curve's name
(postprocess.displayCurves()), and its number is the deprecated form.
Parameters
namestring— Effect name.propstring— Declared property name.value(number | { number } | string)— Number, array of numbers, or the name of one of the property's options.
Returns boolean — True when the effect's uniform took the value; false when it did not — an effect that is not registered, one that declares no property by that name, a value outside the declared range, and a name none of the property's options carry are each named in a WARN in the engine log. A call made from inside queue() or batch(), where the engine has not run the write by the time the call returns, answers true for the queued request.
postprocess.setProperty("vignette", "intensity", 0.6)
postprocess.setProperty("__display__", "curve", "agx")
typed/builtin//modules/api/engine/postprocess/postprocess/setSampler
postprocess.setSampler(name: string, opts: { [string]: any }) -> boolean
Configure the per-effect user sampler shared by the effect's declared texture properties. opts.filter = "linear" (default) or "nearest". opts.wrap (alias .address) = "clamp" (default), "repeat", or "mirror" — applied to all axes.
Parameters
namestring— Effect name.opts{ [string]: any }—{ filter = "linear"|"nearest", wrap = "clamp"|"repeat"|"mirror" }.
Returns boolean — True — the mutation was queued.
postprocess.setSampler("blur", { filter = "linear", wrap = "clamp" })
typed/builtin//modules/api/engine/postprocess/postprocess/setTexture
postprocess.setTexture(name: string, prop: string, path: string) -> boolean
Bind a texture to one of an effect's declared texture properties.
Declare it in properties ({ name = "noise", type = "texture" }) and
sample in WGSL as textureSample(noise, noise_sampler, in.uv). path
is a texture asset (a guid, an identity such as
@builtin::textures.foo, a name, a .texture path), a color:1,0,0 /
default:white spec, a render-target or compute-target name, or an
array:a|b of texture layers. A texture asset the slot takes is put on
the GPU and bound by its guid, which is the name postprocess.status()
reports the binding under. A path whose texture has not reached the GPU yet is held
and bound as soon as it does; postprocess.status() reports it under
pendingTextures until then.
Parameters
namestring— Effect name.propstring— Declared texture-property name.pathstring— Texture asset, spec, or render-target name.
Returns boolean — True when the slot took the binding, including one held until its texture reaches the GPU; false when it did not — an effect that is not registered, or one that declares no texture property by that name, is named in a WARN in the engine log. A call made from inside queue() or batch(), where the engine has not run the binding by the time the call returns, answers true for the queued request.
postprocess.setTexture("__vsky_composite", "cloud", "cloud_target")
typed/builtin//modules/api/engine/postprocess/postprocess/status
postprocess.status() -> { PostprocessStatus }
Every registered effect in chain order with the state that decides
whether it reaches the frame — enabled flag, priority, layer, the
shader's compile error when it has one, the .shader asset it renders
when it was registered from one, the texture each declared slot is bound
to (textures) and the bindings still waiting for their texture
(pendingTextures) — and drawn, whether it drew into the last frame
the renderer drew. drawn is the renderer's own record of the draws it
made, whoever drew the effect: the chain, a render feature's pass using
it as its shader (such an effect is registered enabled = false and
still draws), or the renderer's own stages. So a survey of the chain
answers "is this one affecting the picture right now?" without capturing
a frame and reading pixels, and a script waits for an effect to reach
the picture by waiting for drawn.
An effect this script has just registered is listed with pending = true until the renderer publishes it, since a registration is queued
for the next frame. A published effect reads drawn = false until a
frame includes it: while its pipeline is still building, and for as long
as no camera that draws runs post-processing (the editor camera draws
without it).
Returns { PostprocessStatus } — Array of per-effect state, in the order the chain runs them.
for _, e in ipairs(postprocess.status()) do
print(e.name, e.enabled, e.layer, e.error)
end
typed/builtin//modules/api/engine/profiler/profiler/begin
profiler.begin(name: string)
Start a named profiling block. Call profiler.finish(name) to
record the duration. Blocks appear in profiler.stats() under
"script.<name>" and inside captures.
Parameters
namestring— Block name (e.g. "MyComponent.update").
profiler.begin("MyComponent.update"); ...; profiler.finish()
typed/builtin//modules/api/engine/profiler/profiler/captureFrames
profiler.captureFrames(label: string?, first: number?, count: number?) -> ({ CaptureFrame }?, string?)
Frames first .. first + count - 1 (numbered from 1) of a
stored capture, each { frame, total_ms, agent_ms, capture_ms, capture, cpu_ms, wait_ms, gpu_ms, t_ms, systems, agent_by_caller }
built straight from its records, frame numbered from 0 within the
capture. capture marks a capture frame: one that spent
capture_ms drawing renders a caller's tool call asked for or
copying their readbacks, or ran while such a readback was in flight
on the GPU. cpu_ms,
wait_ms and gpu_ms are the engine thread's CPU time, its wait
for a core and the engine's GPU time, each absent where the platform
gives none (frameCost says why). A read takes the memory of the
frames it asks for, so a long capture read a page at a time holds
one page at once. Empty past the capture's last frame.
Parameters
labelstring(optional) — The capture's label (default: the last completed capture).firstnumber(optional) — The first frame to read, from 1 (default 1).countnumber(optional) — How many frames to read (default: every frame fromfirst).
Returns ({ CaptureFrame }?, string?) — The frames, or nil and why there is no such capture, as profiler.captureInfo states it.
local page, why = profiler.captureFrames("combat", 1, 64)
typed/builtin//modules/api/engine/profiler/profiler/captureInfo
profiler.captureInfo(label: string?) -> (CaptureInfo?, string?)
A stored capture (a stopped recording, a retro snapshot or
drained watchdog hits) without its frames: { label, frame_count, started_at, ended_at, source, summary, callers, bytes, budget_bytes, dropped_for_budget, let_go, frame_cost }, the fields of
stopCapture but frames; frame_cost is the
profiler.frameCost report of its frames. It costs a few
kilobytes however many frames the capture holds; read them with
profiler.captureFrames. When there is no such capture it
answers nil and why: the capture was let go to keep the stored
captures inside their bound, no capture is stored under the
label, or none has completed yet.
Parameters
labelstring(optional) — The capture's label (default: the last completed capture).
Returns (CaptureInfo?, string?) — The capture's header, or nil and why there is none.
local info, why = profiler.captureInfo("combat")
typed/builtin//modules/api/engine/profiler/profiler/captureSeries
profiler.captureSeries(label: string?, series: "memory" | "gpu" | "jobs" | "hitches", first: number?, count: number?) -> (CaptureSeriesPage?, string?)
Items first .. first + count - 1 (from 1) of one series of a
stored capture, as { total, items }: "memory" (a recording at the
memory level or above; each item a CaptureMemorySample), "gpu"
(a comprehensive recording; each a CaptureGpuFrame), "jobs" (a
comprehensive recording; each a CaptureJob, in the order they
started) or "hitches" (every capture; each a CaptureHitch, the
frames at twice the median and 8 ms above it with the keys that took
the most of them and the jobs that ran across them). A series the capture's level did
not keep answers nil and the level that keeps it.
Parameters
labelstring(optional) — The capture's label (nil: the last completed capture).series"memory" | "gpu" | "jobs" | "hitches"—"memory","gpu","jobs"or"hitches".firstnumber(optional) — The first item to read, from 1 (default 1).countnumber(optional) — How many items to read (default: every item fromfirst).
Returns (CaptureSeriesPage?, string?) — The page, or nil and why there is none.
local mem = profiler.captureSeries("bench", "memory")
for _, m in mem.items do print(m.t_ms, m.private_bytes, m.vms.user.live_bytes) end
typed/builtin//modules/api/engine/profiler/profiler/counters
profiler.counters(pattern: string?) -> { ProfilerCount }
Get the profiler's counts: unitless per-frame tallies (for example
the waits the engine thread made on the process-wide lock, under
system.schedule.frame.process_local_waits), kept apart from the
millisecond timings of stats. frame is the tally of the frame in
progress, prev_frame the last complete frame's, max_frame the
highest complete-frame tally and total the tally since the profiler
started. Optional glob pattern filters by name (supports * and ?).
Parameters
patternstring(optional) — Filter pattern (e.g. "system.schedule.frame.*").
Returns { ProfilerCount } — Array of profiler counts.
for _, c in ipairs(profiler.counters("system.schedule.frame.*")) do print(c.name, c.prev_frame) end
typed/builtin//modules/api/engine/profiler/profiler/disableRing
profiler.disableRing()
Disable the ring buffer and clear its history.
profiler.disableRing()
typed/builtin//modules/api/engine/profiler/profiler/enableRing
profiler.enableRing(seconds: number?) -> boolean
Enable the always-recording ring buffer, retaining the last
seconds of per-frame data (default 20, 1 to 600) at any frame
rate, within a fixed memory budget (budget_bytes of
profiler.ringStatus(), 32 MiB): once the window's frames would
take more, the oldest leave first and dropped_for_budget counts
them. Query it AFTER the fact with profiler.retro() —
latency-immune, since the data is historical. Editor profile only:
returns false in the runtime profile. The enable is the gate; the
ring costs nothing until on. memory.report() states what the
frames hold as profiler.frames.
Parameters
secondsnumber(optional) — Seconds of history to retain (default 20, 1 to 600).
Returns boolean — True if enabled, false if refused (runtime profile).
if profiler.enableRing(30) then ... end
typed/builtin//modules/api/engine/profiler/profiler/exportCapture
profiler.exportCapture(label: string?, format: "json" | "csv" | "trace" | "stacks" | "scopes" | "stacksSvg" | "scopesSvg") -> (CaptureExport?, string?)
Where a stored capture reads out in format: a file of
/zero/runtime/profiler/, generated when it is read. "json" is the
whole capture (header, frames, series, hitches); "csv" one row per
frame with its times, counts, memory, each schedule's time and each
profiler count it tallied;
"trace" trace-event JSON Perfetto and chrome://tracing open
(frames as spans; schedules, memory, Luau heaps and GPU passes as
counter tracks; each pool worker's jobs as spans on a track of its
own; hitches as markers); "stacks" the sampled Luau
stacks folded root first (frame;frame;... microseconds, the form
speedscope, inferno and flamegraph.pl read); "scopes" the
engine's timed scopes folded, each by its own time in microseconds;
"stacksSvg" and "scopesSvg" the same drawn as a flame graph, an
SVG a browser opens (each frame as wide as its time, its time and
share in its tooltip).
The file is read from outside the engine like any VFS file (the
proxy's download_file, GET /engine/vfs/<path>), so a long capture
never passes through a call's answer.
Parameters
labelstring(optional) — The capture's label (nil: the last completed capture).format"json" | "csv" | "trace" | "stacks" | "scopes" | "stacksSvg" | "scopesSvg"—"json","csv","trace","stacks","scopes","stacksSvg"or"scopesSvg".
Returns (CaptureExport?, string?) — { path, format, bytes }, or nil and why: no such capture, or stacks a recording below comprehensive (or an engine with no sampler) did not take.
local trace = profiler.exportCapture("bench", "trace")
local flame = profiler.exportCapture("bench", "scopesSvg") -- an SVG a browser opens
typed/builtin//modules/api/engine/profiler/profiler/finish
profiler.finish(name: string?) -> number?
Finish a profiling block and record the elapsed duration as
"script.<name>". Without an argument, closes the most-recently-
begun block (LIFO stack). With a name, closes the most recent
block whose name matches — useful when blocks of different names
are nested.
Parameters
namestring(optional) — Block name to finish. Omit to pop the top of the stack.
Returns number? — Elapsed milliseconds, or nil if no matching block was active.
local ms = profiler.finish("MyComponent.update")
typed/builtin//modules/api/engine/profiler/profiler/frameCost
profiler.frameCost(opts: FrameCostOptions?) -> FrameCostReport
What the engine itself spent per frame over a window, beside the
wall time, so a frame cost read on a machine shared with other work
names how much of each frame was the engine and how much the
machine. With opts.seconds (default 5) it measures the frames of
the next that many seconds of wall clock and returns when they have
run (the calling task waits on the wall clock, so the window has the
same length at every engine.timeScale, 0 included; GPU timing runs
for the window); with
opts.last it reads the frames of the last that many seconds the
engine already holds, at once. cpu is the engine thread's CPU time
per frame from the thread's own clock (source = "thread_clock";
in a browser the worker's own time, the frame less the host's
waiting and busy, source = "worker", which still holds the
worker's waits for a core). waitingForCore is the
time per frame the thread was ready to run and waited for a core
other processes held, with its share of the wall time. gpu.own
is the engine's own GPU time per frame: the GPU driver's account of
the process on the busiest of the GPU's engines where it gives one
(drm_fdinfo), otherwise the
engine's timed passes (timestamp_queries, which other clients'
work on a busy GPU lengthens). hostBoundFps is the frame rate the
world would hold with the machine to itself, 1000 over the larger of
cpu.mean and gpu.own.mean, beside fps, the rate it ran at.
build, luau and drawn name the engine that produced the
numbers. Frames that drew a capture a caller's tool call asked for
are left out and counted under excluded.capture. A caller's queued
work (an execute, the shell command reading the window) is taken
out of the wall and CPU time of the frames it ran in, so a window
read from the shell or a running call measures the world's frames;
a frame that spent half its wall time or more on it is left out and
counted under excluded.callerWork. A figure the platform does not give carries
available = false and the platform's reason, never a zero.
Parameters
optsFrameCostOptions(optional) —{ seconds = n }to measure the next n seconds (default 5, at most 120), or{ last = n }to read the last n seconds held.
Returns FrameCostReport — The window's frame cost.
local r = profiler.frameCost({ seconds = 10 }); print(r.fps, r.cpu.mean, r.waitingForCore.mean, r.hostBoundFps)
local r = profiler.frameCost({ last = 5 })
typed/builtin//modules/api/engine/profiler/profiler/gpuFrame
profiler.gpuFrame() -> GpuFrameReport
Label-aggregated GPU pass timings over the last window_frames
resolved frames, measured with GPU timestamp queries. supported
is false when the device lacks timestamp queries — spans stays
empty. Each span covers every render/compute pass recorded under
one label — compute.<shader> per compute dispatch, scene.* for
the scene passes, post.<effect> per post-process effect,
feature.* for render-feature passes: ms is the median of its
per-frame totals, min_ms/max_ms the range that median sits in,
count the passes per frame and frames how much of the window
carried it. at_floor marks a label whose every sample landed
within a few ticks of the device's timestamp counter (tick_ms) —
those passes ran and the device resolved no duration for them,
which is not the same as a measured zero. ran is whether the
label recorded a measured pass in the newest resolved frame, and
last_frame the newest frame that did. The window outlives the
work it describes, so a pass that stops being recorded leaves a row
standing for up to window_frames frames carrying the median of
the frames it did run in: read ran to answer whether a pass is
running, frame - last_frame for how many resolved frames ago it
last did, and ms as the cost of the frames it ran in.
frame_span_ms (first pass begin to last pass end) and
total_ms are medians too, so
rows do not sum to total_ms, and the GPU may overlap passes so
total_ms can exceed frame_span_ms. The readback is
asynchronous: the window lags the live frame by a few frames.
Returns GpuFrameReport — GPU timing window, spans ranked by median ms descending.
local g = profiler.gpuFrame(); print(g.frame_span_ms, g.spans[1] and g.spans[1].label)
typed/builtin//modules/api/engine/profiler/profiler/hits
profiler.hits(label: string?, opts: StopCaptureOptions?) -> string?
Drain the watchdog's recorded hit frames into a capture stored
under label (default "watch_hits") and clear the buffer.
Returns the capture JSON (same shape as stopCapture), or nil if
there were no hits. opts.frames = false leaves frames out; read
them a page at a time with profiler.captureFrames(label, first, count).
Parameters
labelstring(optional) — Capture label to store under (default "watch_hits").optsStopCaptureOptions(optional) —{ frames = false }to leave the per-frame array out.
Returns string? — Capture JSON of the hit frames, or nil if none.
local json = profiler.hits()
local head = profiler.hits("collapse", { frames = false })
typed/builtin//modules/api/engine/profiler/profiler/isCapturing
profiler.isCapturing() -> boolean
Check if a profiler capture is currently active.
Returns boolean — True if a capture is in progress.
if profiler.isCapturing() then ... end
typed/builtin//modules/api/engine/profiler/profiler/lastCapture
profiler.lastCapture(opts: StopCaptureOptions?) -> string?
Get the most recent completed capture result as a JSON string.
Same shape as profiler.stopCapture(). Returns nil if no capture
has been completed yet. opts.frames = false leaves frames out;
read them a page at a time with profiler.captureFrames.
Parameters
optsStopCaptureOptions(optional) —{ frames = false }to leave the per-frame array out.
Returns string? — JSON string of the last capture, or nil.
local last = profiler.lastCapture()
local head = profiler.lastCapture({ frames = false })
typed/builtin//modules/api/engine/profiler/profiler/perfLine
profiler.perfLine() -> string?
The engine's own one-line performance summary, exactly as it
rides a tool response: the headline frame time, and when the frame
is slow or CPU moved since the last edit, the severity marker, the
delta and the systems the time went to. A DIFFERENT measurement
from everything below: this is the published smoothed frame, while
stats and the profiler toolbox report the effective frame time
(wall clock minus the cost of the call doing the asking), so a line
composed from those disagrees with what other callers are told
about the same engine. Reading it does not move the edit-to-edit
baseline the delta is measured against.
Returns string? — The summary line, or nil before the first frame is published.
local line = profiler.perfLine()
typed/builtin//modules/api/engine/profiler/profiler/recordingHold
profiler.recordingHold() -> string?
Who holds the one windowed recording, as a JSON string
{ label, owner, started_at, stops_in_seconds?, held_seconds, frames, bytes, budget_bytes, dropped_for_budget, span_seconds }, or nil when
nothing is recording. stops_in_seconds is how long until a recording
started with seconds stops on its own. frames and bytes are what the recording
holds, budget_bytes the most it may, dropped_for_budget the
oldest frames that left to keep it there, and span_seconds the
seconds between the oldest and the newest frame it holds. owner is the caller key of whoever called
startCapture, the same value vfs.currentAuthor().id reads for
the calling caller, so a caller refused the slot tells its own
earlier recording from a sibling session's; it is absent when that
call attested no caller. Several agent sessions share one engine and
one recording, which is why a refusal is answered with this.
Returns string? — JSON hold description, or nil when no recording is active.
local held = profiler.recordingHold()
typed/builtin//modules/api/engine/profiler/profiler/retro
profiler.retro(seconds: number?, label: string?) -> { [string]: any }?
Retroactively aggregate the last seconds of the ring (default:
the whole ring). The full per-frame capture is retained under label
(default "retro") for in-engine drill-down (the frame / hotspots
tools);
this RETURNS a compact structured aggregate table (frame-time distribution
- per-system summary), never the raw per-frame array — bounded, so it is
safe over the ZeroMind bridge. Code-facing primitive; the
retrotool renders the agent-facing report. Latency-immune: the data is historical.
Parameters
secondsnumber(optional) — How many seconds back to include (default: whole ring).labelstring(optional) — Capture label to store under (default "retro").
Returns { [string]: any }? — A compact aggregate { label, source, frames, seconds, exclude_agent, agent_frames, dt = { avg, p50, p90, p99, max, min }, summary = {...} }, or nil if the ring holds nothing.
local agg = profiler.retro(8, "collapse")
typed/builtin//modules/api/engine/profiler/profiler/ringStatus
profiler.ringStatus() -> string
Ring buffer status as a JSON string: { enabled, frames, seconds, span_seconds, bytes, budget_bytes, dropped_for_budget }.
seconds is the retention asked for and span_seconds the span
held; bytes is what the held frames take and budget_bytes the
most they may; dropped_for_budget counts the frames that left
inside the retention window to keep the ring in its budget.
Returns string — JSON status string.
local s = profiler.ringStatus()
typed/builtin//modules/api/engine/profiler/profiler/setStoredBudget
profiler.setStoredBudget(bytes: number?) -> number
Hold the stored captures to bytes in all, at most the default
of 64 MiB; nil restores the default. Captures past the new budget
are let go at once, the least recently stored or read first and the
last completed capture kept.
Parameters
bytesnumber(optional) — The most the stored captures may hold (default and most 67108864).
Returns number — The budget the stored captures now hold to, in bytes.
profiler.setStoredBudget(8 * 1024 * 1024)
typed/builtin//modules/api/engine/profiler/profiler/startCapture
profiler.startCapture(label: string?, opts: (CaptureOptions | number)?) -> boolean
Start recording every frame, held by the calling caller, until
stopCapture(). The engine records each frame in Rust as it closes:
no Luau runs and nothing is allocated in Luau for the recording, in
the editor and the runtime profile alike, so a benchmark measures its
run rather than its collection. opts.level chooses what is kept:
"frames" (the default) keeps each frame's wall time, the engine
thread's CPU time and wait for a core, the engine's GPU time, every
profiler key's time (each schedule, system and script block, the GC
step, each VM's tick) and its counts (entities, draws, instances,
Luau bytes allocated); "memory" adds a memory sample every
opts.memoryIntervalMs (default 100): the process's private and
resident bytes, the allocator's live heap, every source
memory.report() names (GPU textures, meshes, geometry, shadow
pool, the VFS store...) and each Luau VM's heap; "comprehensive"
adds every GPU frame the timer resolves with each pass's time, every
job the worker pools run (asset decodes and imports, shader compiles,
module loads, each with its pool, kind, worker, start and length), and
the user VM's Luau call stacks sampled at opts.stackHz (default 1000)
for a flame graph. Read it back with captureInfo (which names its
hitches), captureFrames and captureSeries; read it out as a CSV, a
trace Perfetto and chrome://tracing open, flame graphs as SVGs a
browser opens, or folded stacks with exportCapture. guides { path = "topics/profiling" } covers
recording a benchmark and what each level costs. A number in place of
opts is budgetBytes. A recording holds at most
budgetBytes of frame records (default and most 32 MiB), however
long it stays open and at any frame rate: past it the oldest frames
leave first, and profiler.recordingHold() and the stopped capture
state bytes, budget_bytes and dropped_for_budget. The
recording is one engine-wide slot, so a start while another
recording holds it returns false and profiler.recordingHold()
names the label and the caller holding it. The stopped capture is
stored under its label beside the other stored captures, which hold
to their own bound (profiler.storedCaptures()).
Parameters
labelstring(optional) — Capture label (default"capture").opts(CaptureOptions | number)(optional) —{ level, memoryIntervalMs, stackHz, budgetBytes, seconds }, or the budget in bytes alone;secondsstops the recording on its own at the first frame past that many seconds, stored under its label asstopCapturestores it.
Returns boolean — True if capture started, false when another recording holds the slot.
if profiler.startCapture("frame-spike") then ... end
profiler.startCapture("bench", { level = "comprehensive" })
typed/builtin//modules/api/engine/profiler/profiler/stats
profiler.stats(pattern: string?) -> { ProfilerStat }
Get current EMA profiling statistics from the SystemProfiler.
Optional glob pattern filters by metric name (supports * and ?
wildcards). Each entry carries two averages: avg_ms averages one
RUN of the block and is folded when the block runs, so a block that
has stopped running keeps the last value it saw; avg_frame_ms
averages one FRAME and is folded every frame, including the frames
the block did not run in, so it is the block's share of the current
frame and falls back to zero once the block stops running.
Parameters
patternstring(optional) — Filter pattern (e.g. "schedule.", "system.schedule.render.").
Returns { ProfilerStat } — Array of profiler block stats.
for _, s in ipairs(profiler.stats("schedule.*")) do print(s.name, s.avg_frame_ms) end
typed/builtin//modules/api/engine/profiler/profiler/stopCapture
profiler.stopCapture(opts: StopCaptureOptions?) -> string?
Stop the active profiler capture and return its result as a
JSON string. The capture is stored under its label, read back at
/zero/runtime/profiler/<label>.json, while the stored captures'
byte bound keeps it. Top-level fields: label,
frame_count, started_at, ended_at, frames, summary,
callers, bytes, budget_bytes, dropped_for_budget, let_go. Compute
duration as ended_at - started_at. callers holds { caller, total_ms, max_ms, frames } per caller whose queued Luau ran in the
window, heaviest first, and each frame carries its own split as
agent_by_caller. frame_count is the frames the recording held
when it stopped, and dropped_for_budget the older frames it let go
to stay inside budget_bytes; once it let any go, started_at is
the oldest frame it held, so ended_at - started_at is the span its
frames cover. let_go names the stored captures that storing this
one let go to keep the stored captures inside their bound
(profiler.storedCaptures()). opts.frames = false leaves frames
out, so the string costs a few kilobytes however long the recording
was; read the frames a page at a time with profiler.captureFrames.
Parameters
optsStopCaptureOptions(optional) —{ frames = false }to leave the per-frame array out.
Returns string? — JSON capture result, or nil if no capture was active.
local json = profiler.stopCapture()
local head = profiler.stopCapture({ frames = false })
typed/builtin//modules/api/engine/profiler/profiler/storedCaptures
profiler.storedCaptures() -> StoredCaptures
What the stored captures (stopped recordings, retro
snapshots, drained watchdog hits) hold and what they let go. They
hold at most budget_bytes in all (64 MiB unless set lower with
profiler.setStoredBudget), each counted with every frame it holds:
past it the capture least recently stored or read leaves first, and
the capture just stored stays. labels names the stored captures,
the next to leave first; let_go and let_go_bytes count every
capture let go since the engine started and what they held;
let_go_labels names the newest 256 of them, oldest first.
memory.report() states the same under profiler.frames.
Returns StoredCaptures — { captures, labels, bytes, budget_bytes, let_go, let_go_bytes, let_go_labels }.
local stored = profiler.storedCaptures()
typed/builtin//modules/api/engine/profiler/profiler/unwatch
profiler.unwatch()
Disarm the watchdog. Recorded hits are kept for a final
profiler.hits().
profiler.unwatch()
typed/builtin//modules/api/engine/profiler/profiler/watch
profiler.watch(ceilingMs: number, mode: string?, excludeAgent: boolean?, maxHits: number?) -> boolean
Arm the frame-time watchdog. When a frame's EFFECTIVE time
(total minus agent-injected execute cost) crosses ceilingMs,
mode "record" logs every offending frame (read with
profiler.hits()), and mode "pause" pauses gameplay ONCE to
freeze the bad state, then disarms. Editor profile only: returns
false in the runtime profile. excludeAgent (default true) keeps
the agent's own calls, its captures included, from tripping it.
Parameters
ceilingMsnumber— Effective frame-time ceiling in ms.modestring(optional) — "record" (default) or "pause".excludeAgentboolean(optional) — Subtract agent cost before comparing and pass over frames that did an agent's capture work (default true).maxHitsnumber(optional) — Max frames retained in record mode (default 240).
Returns boolean — True if armed, false if refused (runtime profile).
if profiler.watch(50, "pause") then ... end
typed/builtin//modules/api/engine/profiler/profiler/watchStatus
profiler.watchStatus() -> string
Watchdog status as a JSON string: { armed, ceiling_ms, mode, exclude_agent, hits, dropped_hits, tripped }.
Returns string — JSON status string.
local s = profiler.watchStatus()
typed/builtin//modules/api/engine/prototype_lifecycle/M/activatePrototypes
M.activatePrototypes()
Reactivate and unhide every prototype root and EditorOnly entity.
typed/builtin//modules/api/engine/prototype_lifecycle/M/applyCurrentMode
M.applyCurrentMode()
Hold what is live now to the invariant of the mode the engine is in.
A scene load that lands while play runs (a root scene, an additive overlay
such as the editor UI layer, or a load a slow boot finishes after the flip)
brings in prototypes and EditorOnly entities after enterPlay ran. In play
this deactivates and hides every prototype root, and holds the EditorOnly
authoring surface to the state the session's pause gave it: stood down
while play runs, live while a pause has it shown over the frozen world. It
tracks that surface either way, so pause and resume reach it. In edit both
are already live, and it changes nothing.
PrototypeLifecycle.applyCurrentMode()
typed/builtin//modules/api/engine/prototype_lifecycle/M/deactivatePrototypes
M.deactivatePrototypes()
Deactivate and hide every prototype root and EditorOnly entity so play mode neither simulates nor renders them.
typed/builtin//modules/api/engine/prototype_lifecycle/M/despawnClones
M.despawnClones()
Despawn every still-existing tracked clone and clear the tracking list.
typed/builtin//modules/api/engine/prototype_lifecycle/M/enterEdit
M.enterEdit()
Enter edit mode: despawn runtime clones, then reactivate prototypes and EditorOnly entities.
typed/builtin//modules/api/engine/prototype_lifecycle/M/enterPlay
M.enterPlay()
Enter play mode: deactivate and hide prototypes and EditorOnly entities.
typed/builtin//modules/api/engine/prototype_lifecycle/M/hideEditorSurface
M.hideEditorSurface()
Deactivate and hide the EditorOnly authoring surface without touching player-prototype roots. Used when play mode resumes so the surface disappears and gameplay cameras take the viewport back.
typed/builtin//modules/api/engine/prototype_lifecycle/M/install
M.install()
Keep the play-mode invariant applied for every flip, in every world.
enterPlay / enterEdit are what make PrototypeOnly and EditorOnly
mean something at runtime, and until something calls them on the flip a
template stays live: its camera competes for the viewport with the camera
of the player cloned from it, carries no follow target, and holds the shot
at the spawn point; its body answers the same input as a second character.
Registered from the prelude beside the other engine installs rather than from a scene-load path — a load that does not run leaves the invariant unapplied with nothing reporting it, and a flip that reloads no scene never reaches a loader hook at all. Idempotent: a second call registers nothing, and the current mode is applied once on install so a world opened straight into play does not start with its templates live.
PrototypeLifecycle.install()
typed/builtin//modules/api/engine/prototype_lifecycle/M/prototypeRoots
M.prototypeRoots() -> { string }
Ids of every active-layer entity carrying the PlayerPrototype component.
Returns { string } — An array of entity ids.
typed/builtin//modules/api/engine/prototype_lifecycle/M/registerClone
M.registerClone(id: string)
Track a runtime clone root so it can be despawned on the return to edit.
Parameters
idstring— The clone's root entity id.
typed/builtin//modules/api/engine/prototype_lifecycle/M/showEditorSurface
M.showEditorSurface()
Reactivate and unhide the EditorOnly authoring surface (free camera + editor-only visualizers) without touching player-prototype roots. Used when play mode is paused so the editor camera returns over the frozen world.
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/add
reflectionProbe.add(x: number, y: number, z: number, opts: { [string]: any }?) -> string
Add a reflection probe at (x, y, z) in one call: spawns a probe entity
carrying a ReflectionProbe component, which registers it and loads its
persisted bake when one exists. A probe with no bake reflects nothing until
it is baked (bakeAll(), or bake(id)). The probe is an editor gizmo,
invisible in play mode. Returns the probe entity id.
Parameters
xnumber— World X.ynumber— World Y.znumber— World Z.opts{ [string]: any }(optional) — Optional{ radius = 12, probeId = "...", name = "..." }.probeIdis the STABLE asset identity (so a re-created probe reloads the same baked cube); defaults to the entity id. The probe does NOT bake on add — callbakeAll()once the scene is built (baking is an authoring step).
Returns string — The probe entity id.
reflectionProbe.add(0, 3, 0, { radius = 15, probeId = "lobby" })
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/apply
reflectionProbe.apply() -> number
Push the current active-probe blend data (live positions + radii) to the renderer. Builds a dense slot array so each probe's data lands at its cube slot; freed/missing slots, and the slot of a probe that holds no cube yet, become inert placeholders that reach no surface. Called automatically by add / bake / remove; call it directly after moving a probe entity.
Returns number — The number of probes applied that reflect (registered, live and baked).
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/bake
reflectionProbe.bake(id: string) -> (string?, string?)
Bake the scene into probe id's cube slot from its current position AND
persist it to a faces6 .texture asset (so it survives reload + syncs),
then re-apply the probe set. Yields a few frames; call from a task/coroutine
context (component hook via task.spawn, bakeAll, or execute).
Parameters
idstring— Probe entity id.
Returns (string?, string?) — The asset path on success, or (nil, errorMessage) on failure.
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/bakeAll
reflectionProbe.bakeAll() -> { baked: number, failed: number, errors: { string } }
Bake EVERY registered probe in the active layers, in one call. Captures
each probe's scene from its position into its slot, persists it, and
applies the full probe set; the sky fallback is armed by a probe whose
skyFallback is set. The agent/editor one-liner. Yields; call from a task/coroutine context (execute, a tool, or
task.spawn).
Returns { baked: number, failed: number, errors: { string } } — { baked = N, failed = M, errors = { ... } }.
reflectionProbe.bakeAll()
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/baking
reflectionProbe.baking(id: string?) -> boolean
Whether a bake under way will reach probe id: its own bake, or a
bakeAll that has it still to reach. With no id, whether any bake is
under way.
Parameters
idstring(optional) — Optional probe entity id.
Returns boolean — True while a bake that reaches the probe (or any bake) runs.
reflectionProbe.baking(id)
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/count
reflectionProbe.count() -> number
Number of registered probes.
Returns number
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/ensureSkyFallback
reflectionProbe.ensureSkyFallback() -> boolean
Ensure the scene's sky is in the environment's sky fallback: a reflective surface no probe covers then reflects the sky rather than black, and a partially covered one blends the shortfall against it. Queues a capture when the sky slot holds none, and re-arms the fallback when a capture is there but switched off. The engine's own state answers both questions, so calling this on every probe that comes up costs one capture between them, and a scene that lost its fallback gets it back. Once captured, the fallback follows the sky the scene draws on its own.
Returns boolean — True if a capture was queued, false if the sky slot already holds one.
reflectionProbe.ensureSkyFallback()
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/isBaked
reflectionProbe.isBaked(id: string) -> boolean
Whether probe id holds a cube it reflects: baked by bake / bakeAll,
or loaded from its persisted bake by loadBaked. An unbaked probe adds
nothing to the frame.
Parameters
idstring— Probe entity id.
Returns boolean — True once the probe holds a cube; false for an unbaked or unregistered probe.
reflectionProbe.isBaked(id)
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/list
reflectionProbe.list() -> { any }
List every registered probe: { { id, slot, radius, priority, baked, asset, position }, ... }.
baked is whether the probe holds a cube it reflects; an unbaked probe adds
nothing to the frame. asset names the persisted bake once there is one.
Returns { any } — The probe list.
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/loadBaked
reflectionProbe.loadBaked(id: string) -> boolean
Load probe id's PERSISTED baked cube (probe_<key>.texture) into its
slot WITHOUT re-rendering the scene — the runtime path. A probe bakes once at
authoring time and loads the asset on every subsequent scene load. Returns
false (not an error) when no baked asset exists yet.
Parameters
idstring— Probe entity id.
Returns boolean — True if a baked asset was loaded, false if none exists / load failed.
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/register
reflectionProbe.register(id: string, radius: number, key: string?) -> number?
Register a reflection probe for entity id with influence radius.
Assigns a free cube slot and applies the updated probe set. Idempotent — a
re-register keeps the same slot and just updates the radius. Called by the
ReflectionProbe component's awake; rarely called directly.
Parameters
idstring— Probe entity id.radiusnumber— Influence radius (world units) — surfaces within blend it.keystring(optional) — Optional STABLE asset identity (the probe's probeId). Defaults toid. The baked cube persists atprobe_<key>.textureso an authored probe keeps the same asset across reloads even though its runtime entity id changes.
Returns number? — The assigned cube slot, or nil if all MAX_PROBES slots are taken.
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/setPriority
reflectionProbe.setPriority(id: string, priority: number)
Set a probe's blend rank against the probes it overlaps, and re-apply. Probes are gathered highest rank first and each rank takes the coverage the ranks above it left, so a small interior probe ranked above the large exterior one it sits inside wins outright wherever it reaches full weight, while probes of equal rank crossfade by proximity as before.
Parameters
idstring— Probe entity id.prioritynumber— Blend rank. Defaults to 0 on every probe.
reflectionProbe.setPriority(interiorId, 1)
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/setProxy
reflectionProbe.setProxy(id: string, kind: string, x: number, y: number, z: number)
Anchor a probe's reflections to a proxy volume and re-apply. A cube records the environment from one point, so sampling it along the raw reflection vector puts everything it recorded at infinity and the reflection slides across a surface as the camera moves. Sizing a proxy to the geometry the probe recorded — a room's walls, say — keeps the reflection anchored to what it depicts.
Parameters
idstring— Probe entity id.kindstring— "box" (sized by all three half-extents), "sphere" (sized byx), or "none" to sample along the raw reflection vector.xnumber— Half-extent along X, in world units — the sphere radius for "sphere".ynumber— Half-extent along Y.znumber— Half-extent along Z.
reflectionProbe.setProxy(id, "box", 5, 3, 4) -- a 10x6x8 room
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/setRadius
reflectionProbe.setRadius(id: string, radius: number)
Update a probe's influence radius and re-apply.
Parameters
idstring— Probe entity id.radiusnumber— New influence radius.
typed/builtin//modules/api/engine/reflectionProbe/reflectionProbe/unregister
reflectionProbe.unregister(id: string)
Unregister entity id's probe, freeing its cube slot, and re-apply.
Parameters
idstring— Probe entity id.
typed/builtin//modules/api/engine/renderer/renderer/activity
renderer.activity() -> Activity
Why this engine is busy, in one reading. fps is the rate its loop
ran frames at and drawnFps the rate its renderer drew them at, and
cpuPercent the CPU its process spent as a percentage of one core
(absent where the platform states none, as in a browser), each over the
last ten seconds (spanMs, longer when the loop ran no frame inside
them). still is whether the engine stated itself still at the end of
its last frame and movingBecause what moves it otherwise (the names
renderer.framePacing().movingBecause takes: picture, gameplay,
tasks, input, calls, ...).
wokenBy names what ran the frames the engine ran while still over the
last 5 to 10 seconds, at most 5, the most frames first, each with its
source, owner, recent, total and agoMs, as
renderer.framePacing().wokenBy lists them: an arrival (input /
pointer, write / file written, message / datagram, ...) or
the schedule its tasks set (task waits on frames, task timer,
task waits at its rate, longest gap).
redrawReasons names the owners whose changes moved the picture in the
last 5 to 10 seconds, at most 5, the most changes first, each with its
source, owner, recent, total and agoMs, as
renderer.framePacing().redrawReasons lists them: the screen a UI pass
laid out, the component and entity a world write changed, the program
reading the clock. busyJobs names the kinds of job the engine's worker
pools ran over the last 5 to 10 seconds, at most 3, the most busy time
over that span first, each with its pool, kind (the name a job gave
itself, else the place in the engine's source that handed it over),
recentJobs and recentBusyMs (the jobs of the kind that ended over
that span and the time they spent running), jobs and busyMs (the
same over the session) and sinceLastMs.
The engine's GET /engine/status carries the same reading under
activity, which the proxy's list_instances and instance_health
print for every engine.
Returns Activity — { spanMs?, fps?, drawnFps?, cpuPercent?, still, movingBecause?, wokenBy, redrawReasons, busyJobs }
local a = renderer.activity()
print(a.fps, a.cpuPercent, a.movingBecause, a.redrawReasons[1] and a.redrawReasons[1].owner)
typed/builtin//modules/api/engine/renderer/renderer/anisotropy
renderer.anisotropy() -> number
The maximum anisotropy material textures are sampled with right now — the requested level clamped to what this device honours.
Returns number — The effective level, 1 through 16.
if renderer.anisotropy() < 4 then ... end
typed/builtin//modules/api/engine/renderer/renderer/atmospherics/held
renderer.atmospherics.held() -> boolean
Whether a hold is standing on the air right now.
Returns boolean — True while at least one renderer.atmospherics.hold stands.
if renderer.atmospherics.held() then print("clear air") end
typed/builtin//modules/api/engine/renderer/renderer/atmospherics/hold
renderer.atmospherics.hold(share: number?, options: AtmosphericsHoldOptions?) -> () -> ()
Hold the air between the camera and every surface at a stated share of
what the scene authored, and return the release. At the default 0 the
media contribute nothing and a surface renders in its own colour, which is
what lets a reader judge an albedo, a tint or a material while another
slice of a shared world drives the weather. The share reaches aerial
perspective, height fog and volumetric light scattering; the sky, the sun
and the light they put on a surface are untouched, because those are what
the surface's colour is made of. Holds nest: the innermost names the
share, and the authored air is back once the last release is called. Each
release ends its own hold whatever order the releases come in, so two
callers holding at once each end their own.
exclusive takes the air for the owner key the call states: while that
hold stands, a hold is admitted only when it states the same key, and
every other one is refused with an error naming the key and the share
holding it. That is what lets one caller clear the air to read a surface
and keep it clear while another agent drives the same engine. The key is
what an owner presents to take a nested hold of its own, and what
renderer.atmospherics.release hands the air back by.
Parameters
sharenumber(optional) — How much of the authored air reaches the image, in [0, 1]. Defaults to 0 -- no air at all.optionsAtmosphericsHoldOptions(optional) —owneris the key this hold is taken under, and an exclusive hold states one. A hold that states no key is labelled with the caller the call is attributed to, which names the calling session where the transport attested one and the ZeroMind account otherwise.exclusivetakes the air for the stated key until the hold is released.
Returns () -> () — A function that releases this hold. Calling it twice releases once.
local release = renderer.atmospherics.hold() ; local picture = tools.use("capture", "fromPosition", { position = { 0, 2, 8 } }) ; release()
local release = renderer.atmospherics.hold(0, { exclusive = true, owner = "albedo-read" })
typed/builtin//modules/api/engine/renderer/renderer/atmospherics/onChange
renderer.atmospherics.onChange(listener: (number) -> ()) -> () -> ()
Register a listener called with the share now in force whenever it changes — a hold taken, a hold released — and return the unsubscribe. A system that packs a medium into a GPU buffer registers here and re-packs what it has already pushed, so the buffer carries the share before the frame the hold was taken on is drawn rather than a frame later.
Parameters
listener(number) -> ()— Called with the share now in force, in [0, 1].
Returns () -> () — A function that removes this listener.
local stop = renderer.atmospherics.onChange(function(share) print("atmosphere share", share) end)
typed/builtin//modules/api/engine/renderer/renderer/atmospherics/owner
renderer.atmospherics.owner() -> { id: string?, name: string?, share: number, exclusive: boolean }?
The hold naming the share of the authored air that reaches the image
right now: who took it, what share it asked for, and whether it took the
air exclusively. Several agents drive one engine at once and a hold any of
them takes moves the air every surface in every other agent's frame is
rendered through, so this is how a caller sees that another agent holds it
before its own share is quietly replaced -- and, when exclusive is true,
id is the key a hold of its own states to be admitted, and the key
renderer.atmospherics.release hands the air back by. id and name are
nil for a hold that stated no key and that the engine attributes to no
agent.
Returns { id: string?, name: string?, share: number, exclusive: boolean }? — { id, name, share, exclusive } for the standing hold, or nil when the authored air is what reaches the image.
local who = renderer.atmospherics.owner()
if who ~= nil and who.exclusive then print(who.name, "holds the air at", who.share) end
typed/builtin//modules/api/engine/renderer/renderer/atmospherics/release
renderer.atmospherics.release(owner: string) -> number
Hand the air back by the key its holds were taken under, and report how many came off. A hold stands until its release is called, and the release is a closure the call that took the hold holds: a caller that takes a hold in one call and comes back in another, and a task that ends between the two, both leave the air pinned with nobody holding a release for it. Naming the key is how the authored air comes back, and how a caller refused by an exclusive hold takes one over.
Parameters
ownerstring— The key the holds to release were taken under -- whatownerstated when they were taken, whichrenderer.atmospherics.ownerreports.
Returns number — How many holds came off the stack.
renderer.atmospherics.release("albedo-read")
typed/builtin//modules/api/engine/renderer/renderer/atmospherics/share
renderer.atmospherics.share() -> number
The share of the authored air that reaches the image: the innermost
hold's share while one stands, and 1 otherwise. A system that packs a
medium multiplies its extinction — aerial, a fog density — by this,
and a hold then reaches that medium however it is being driven.
Returns number — A number in [0, 1]. 1 when nothing holds.
local density = state.density * renderer.atmospherics.share()
typed/builtin//modules/api/engine/renderer/renderer/blendedBatching
renderer.blendedBatching() -> boolean
Whether blended neighbours sharing a draw key draw together.
Returns boolean
typed/builtin//modules/api/engine/renderer/renderer/bounds/clear
renderer.bounds.clear(id: string) -> boolean
Withdraw the box an entity published, so it stops contributing to the entity's reported extent.
Parameters
idstring— Entity id.
Returns boolean — True when there was a published box to withdraw.
renderer.bounds.clear(id)
typed/builtin//modules/api/engine/renderer/renderer/bounds/set
renderer.bounds.set(id: string, min: any?, max: any?) -> boolean
Publish the local-space box an entity's content-drawn geometry occupies.
entity:bounds() and entity:hierarchyBounds() union it with whatever
mesh geometry the entity has, each carried out of its own local space, so
framing a camera on the entity frames what a feature actually draws.
Parameters
idstring— Entity id.minany(optional) — Local-space minimum corner — a Vec3 table or a 3-element array.maxany(optional) — Local-space maximum corner, same shape asmin.
Returns boolean — True when the box was stored; false for a non-finite or inverted box.
renderer.bounds.set(id, cloud.boundsMin, cloud.boundsMax)
typed/builtin//modules/api/engine/renderer/renderer/captureView/channelId
renderer.captureView.channelId(name: string) -> number?
The debug channel a registered view draws on — what a feature passes as
its pass debugChannel. Nil when no view is registered under name.
Parameters
namestring— The view name.
Returns number? — The channel number or nil.
local debugChannel = renderer.captureView.channelId("lightmap") -- a render feature passes it as an enqueued pass's `debugChannel`
typed/builtin//modules/api/engine/renderer/renderer/captureView/list
renderer.captureView.list() -> { any }
Every registered capture view as { name, channel, description } records
— what backs the discoverability of capture pass=<name> and the
unknown-view error's suggestion list.
Returns { any } — An array of view records.
for _, v in ipairs(renderer.captureView.list()) do ... end
typed/builtin//modules/api/engine/renderer/renderer/captureView/ready
renderer.captureView.ready(name: string) -> boolean
Whether a registered view can draw yet. A view's passes are enqueued
from the moment its render feature first runs, but they are skipped while
the materials they name have no pipeline — their shader is still compiling —
so for the first frames of a session a camera bound to the view renders the
ORDINARY view into its target, and the image gives no sign of it. This
reports the difference, and reports it before any camera is on the view, so
it is answerable for the first camera bound to one. Asking builds the
view's parts if they are not yet there. A view that registered
a ready of its own is also held to it, so a view whose feature is not
running, or whose draw has not landed, reads false. False for an
unregistered name.
Parameters
namestring— The view name.
Returns boolean — Whether this view's passes have resolved everything drawing needs.
repeat task.wait() until renderer.captureView.ready("zfighting")
typed/builtin//modules/api/engine/renderer/renderer/captureView/register
renderer.captureView.register(name: string, config: any?) -> number
Register (or update) a content capture view under name and return the
debug CHANNEL number assigned to it. A render feature gates its pass to this
channel (debugChannel = channel) so the pass draws only when a capture
selects the view. Idempotent: re-registering the same name keeps its channel.
Parameters
namestring— The view name, selected viacapture pass=<name>.configany(optional) —{ description?, ensure?, ready?, warmup?, renderLayers? }.ensureis called before a capture of this view so the feature that draws it is live (e.g. create it on demand).readyis the view's own statement of whether what it draws is in place: afunction(): (boolean, string?)answering true, or false and the reason. A capture of the view waits on it afterensureand before it renders, so a view whose draw lands over the frames afterensure(an entity it spawns, a feature that reads the stateensurebuilt on its next frame, a material still compiling) is drawn rather than captured empty, and a view that stays unready is refused with that reason.warmupis how many present frames a capture lets the view accumulate, once it is ready, before it reads: set it when the feature retains prior-frame state (a temporal diff) so the first capture reads a warm result.renderLayersis the layer spec a capture of this view uses when the caller named none. A view that draws its own geometry and wants the scene's kept out of the frame (and out of the depth buffer it tests against) names only its own layer.
Returns number — The channel number assigned to the view.
local ch = renderer.captureView.register("lightmap", { description = "...", ensure = fn })
typed/builtin//modules/api/engine/renderer/renderer/captureView/resolve
renderer.captureView.resolve(name: string) -> any
Resolve a capture view by name to its { channel, ensure, ready, description, warmup, renderLayers } record, or nil when no view is
registered under name.
Parameters
namestring— The view name.
Returns any — The view record or nil.
local v = renderer.captureView.resolve("lightmap")
typed/builtin//modules/api/engine/renderer/renderer/captureView/unregister
renderer.captureView.unregister(name: string) -> boolean
Withdraw a capture view. A subsequent capture pass=<name> no longer
resolves to it (falls through to the unknown-view error).
Parameters
namestring— The view name.
Returns boolean — True when a view was registered under name.
renderer.captureView.unregister("lightmap")
typed/builtin//modules/api/engine/renderer/renderer/clearShadowHero
renderer.clearShadowHero() -> boolean
Release the hero caster, so every receiver samples the level its footprint selects again.
Returns boolean — Whether a caster was registered.
renderer.clearShadowHero()
typed/builtin//modules/api/engine/renderer/renderer/clearShadowProxy
renderer.clearShadowProxy(mesh: string?) -> number
Stop proxying mesh, so it rasterizes its own geometry into shadow
pages again. Called with no argument, drops every registration.
Parameters
meshstring(optional) — The mesh to stop proxying. Omit to clear all of them.
Returns number — How many registrations were removed.
renderer.clearShadowProxy(statueMesh)
print(renderer.clearShadowProxy(), "proxies dropped")
typed/builtin//modules/api/engine/renderer/renderer/clusterErrorPx
renderer.clusterErrorPx(px: number?) -> number
The cluster cut's error threshold, in pixels. Every static mesh draws the coarsest clusters whose simplification error projects to at most this many pixels in the view drawing it — measured against that view's own pixel height and projection, so a small render target draws coarser geometry than the full-screen view does from the same place. Lower draws finer geometry at more cost; higher draws coarser geometry. A client graphics setting. Default 1.
Parameters
pxnumber(optional) — A finite number above 0. Omit to read the threshold.
Returns number — The threshold in effect.
renderer.clusterErrorPx(0.5) -- finer geometry on this machine
typed/builtin//modules/api/engine/renderer/renderer/collect
renderer.collect() -> RuntimeCollection
Release every runtime texture, material, mesh and render feature nothing
holds: no handle a script still reaches, no live owner, no reference from
live engine state (a render feature's queued passes among it), no asset
backing it, no hold. A root scene load runs this
once the new scene stands, so what the previous scene's content created and
nothing still wears goes with that scene; calling it directly collects at
any other moment. A session material's handle counts as reached while the
entity it was keyed for stands, and stops counting once that entity is
gone.
It reaches the GPU textures the device holds beside the registry's own: a
texture the cache loaded for an asset goes once nothing live names it and
is read back from that asset the next time something asks for it, and a
texture array the cache assembled from its layers (an array: key) goes
once nothing live names it and is assembled again from those layers the
next time something does, while one
no asset answers for stays, there being nothing to read it back from — a
render pass's own target, a colour swatch, an atlas the engine built. A
texture the ASSET path uploaded and whose asset has since been removed has
nothing to come back from either, and the collection decides about it from
its holders the way it does about every other resource: a handle a script
still reaches, a live owner, a reference from live engine state, a hold.
So is a mesh the asset path uploaded (a .mesh asset's :handle()) once
its asset is removed; while that asset stands it holds the mesh.
A material an asset backs stays while nothing else holds it, except one
whose slots name a texture the cache loaded for an asset: that material
goes once no entity, handle, owner, reference or hold names it, because
its asset files the record again, and materialises its textures, the next
time the material is used.
Features go first, then materials, then meshes, then textures, so a texture
only a released material named goes with the material. Runs a full garbage
collection first, so a handle nothing reaches counts as let go, and yields
for the frame the census runs on. A handle the calling function still has
in a variable — or in a temporary it has not overwritten — is one a script
reaches, so a resource created in the function that collects is let go by
the next collection rather than this one. A runtime texture, material,
mesh or render feature needs no call: once the garbage collector has taken
its last handle, the engine judges it against the same holders within a
few dozen frames, again whenever its hold is released (and for a mesh,
whenever what displays it changes), and every few hundred frames while
something holds it, and releases it once nothing does. A texture or mesh
the asset path uploaded needs no call either once its asset is removed:
with its last handle taken by the collector, the engine judges it against
the same holders within a few dozen frames of the removal. Nor does an array
the cache assembled: once a material naming it is released, or the slot
naming it is set to another texture, the engine judges it against the
same holders within a few dozen frames. One kept by the
component or scene load that created it alone stays while that owner
does, and the log names an owner once it holds 64 of one kind that way,
and again each time that count doubles. What a component's task created
is kept by that component only while the task can still use it: once the
task is cancelled, each resource it created is kept by a handle a script
reaches, an entity or draw displaying it, or a hold, and is judged again
within a few dozen frames, so work a component cancels part way gives back
everything it made that nothing went on to use. A render feature holds what it
created through the handles it keeps and the passes it queues, so a
target whose handle it dropped and that no pass of its names any more
goes while the feature stands.
Returns once what it released has left the device: the GPU objects of the
textures and meshes it let go are freed over the frames after the call,
and it waits for those frames (up to 60 drawn frames), so
renderer.texture.list, renderer.mesh.list, renderer.material.list,
renderer.textureMemory() and renderer.gpuMemory() read after it in the
same script no longer count anything it reports released. landed says
whether every release left the device within that wait; false names a
texture or mesh something put back on the device before it could be seen
gone, which renderer.references explains. Code that cannot yield (a
metamethod, onDestroy, a module's top level while require runs it)
is answered at once, without the wait: there landed is false while a
release is still on its way, and the listings and totals stop counting it
over the drawn frames that follow.
Returns RuntimeCollection — { released = { texture, material, mesh, feature }, kept, entries, landed }: the counts released per kind, how many stayed, every resource's status with action = "released" | "kept", and whether every release had left the device when the call returned.
local c = renderer.collect() print(c.released.texture, c.kept)
local c = renderer.collect() print(c.landed, renderer.gpuMemory().meshes)
typed/builtin//modules/api/engine/renderer/renderer/compiledShaders
renderer.compiledShaders() -> { string }
Every key renderer.compiledSource answers for — one per shader key
(guid@checksum) or variant program a compile has run under, whether it
succeeded or failed, for as long as the shader that compiled under it
stands: a removed .shader takes its keys with it. What makes the
composed-source surface enumerable rather than something to guess a key
for.
Returns { string } — An array of keys, sorted.
for _, name in renderer.compiledShaders() do print(name) end
typed/builtin//modules/api/engine/renderer/renderer/compiledSource
renderer.compiledSource(shader: string) -> string?
The WGSL the shader compiler received under one name, exactly as it
received it — the composed module, which is what a compile error's line
numbers and handle indices are positions in. Answers for a shader key
(guid@checksum), a program from renderer.shaderVariants(), or any
reference to a shader asset (identity, path, guid), which reaches the key
of the version that reference resolves to now; for a shader that declares
no features, and for a shader whose compile FAILED, which is the case it
exists for: a message about a function body carries a position and nothing
else, and the text that position is in is this. The failed text stands for
as long as shaderRef:compileStatus() reports that failure.
Parameters
shaderstring— A shader key, ashaderVariants()program name, or a reference to a shader asset.
Returns string? — The composed WGSL, or nil when no compile has run for it or its shader was removed.
local status = asset.resolve("myShader", "shader"):compileStatus()
if status.status == "failed" then
print(status.error)
print(renderer.compiledSource("myShader"))
end
typed/builtin//modules/api/engine/renderer/renderer/compositeSize
renderer.compositeSize() -> { width: number, height: number }
The size of the image the post-scene phases worked on in the last
presented frame — the target the UI composites onto, which every pass
after the scene reads as @scene.color and writes into, and which a
screenSpace = "composite" render target follows. While the renderer
presents the viewport itself that is the display's own size, whatever
fraction of it the scene rasterized at; while a UI viewport panel owns
the presentation it is the size the scene rasterized at, since the panel
draws the scene target at its own rect and nothing upscales before the
composite. Both read 0 before a frame has drawn.
Returns { width: number, height: number } in pixels.
local c = renderer.compositeSize()
typed/builtin//modules/api/engine/renderer/renderer/cullStats
renderer.cullStats() -> {
What the last completed frame decided to draw. total renderables went
into the frustum test, culled fell outside it and visible survived. Of
those, occlusion culling measured occlusionTested against the depth
pyramid and proved occlusionCulled were entirely behind other geometry —
both 0 while renderer.occlusionCulling() is false. A renderable the
pyramid has no say over — one that laid no depth in the visibility raster, one whose
bounds were never recorded, one straddling the near plane — is measured
against nothing and counted in neither, so the gap between visible and
occlusionTested reads how much of the frame the test could speak for.
The two are read back from the GPU for a reader: every call asks for
them, the two rendered frames after each call read them back, and
otherwise one rendered frame in 60 does. So a script reading them each
frame reads each frame's counts, a frame or two behind as the readback
lands, and a read after a pause answers counts at most as old as the
pause and never more than 60 rendered frames, with the frames after it
answering fresh.
This answers for the main camera. What the shadow page cull did with the
frame's casters for each light is on that light's row in
renderer.shadowViews().
views is the engine cull's own count, one row per camera view that
rendered: view is "main" for the main camera and the camera's entity
id for an offscreen one, kind says which, and frame is the frame the
counts describe. The main view's row is first. drawn is whether a
render drew the view in that frame: a frame the renderer declined still
ran the cull's first test, so its row carries that test's counts and no
second one, for a picture nothing rasterized. The
counts are read back from the GPU and handed out oldest first, one frame
per render, so a script reading once a frame reads the frames in the
order they ran. A frame's counts wait at most two renders to be handed
out: a row describes a frame as many frames back as the read took and at
most two more, and when more frames' counts come back at once than that
lets wait, the oldest of them are the frames a script does not read.
instancesTested renderables were tested;
instancesCulled breaks the rejections down by reason (hidden, layer, range,
frustum, screenSize, occludedPass1/occludedPass2 for occlusion
against the depth of the frame that last drew the view and then this
frame's, rasterShaded for the renderables the view shades on the
legacy lane, as renderer.setRasterShading describes, and detail for the
levels of an ecs.MeshLevels chain the view does not draw: a level whose
band does not hold the span of the view's height its subject covers, as
the view's own camera measures it); instancesRecovered
came back in the second test. Then the clusters of the survivors:
clustersTested, rejected by the level-of-detail cut
(clustersLodRejected), the frustum (clustersFrustumCulled), facing away
(clustersConeCulled) or occlusion (clustersOccludedPass1, of which
clustersRecovered came back), and clustersDrawn / trianglesDrawn.
binsPending counts material pipelines still compiling, whose clusters wait
a frame; overflow counts clusters that did not fit the view's lists.
total/culled/visible and occlusionTested/occlusionCulled above are
the main view's count for the renderables drawn outside the cluster lists.
Returns { total: number, culled: number, visible: number, occlusionTested: number, occlusionCulled: number, views: { { [string]: any } } }
local s = renderer.cullStats(); print(s.visible - s.occlusionCulled, "drawn")
for _, v in renderer.cullStats().views do if v.view == "main" then print(v.clustersDrawn, "clusters,", v.instancesCulled.frustum, "outside the frustum") end end
typed/builtin//modules/api/engine/renderer/renderer/debugPass/builtins
renderer.debugPass.builtins() -> { string }
The built-in debug-pass names, one per channel in channel order — the engine's built-in pass vocabulary (final, albedo, normal, depth, …).
Returns { string } — An array of built-in pass names.
for _, n in ipairs(renderer.debugPass.builtins()) do ... end
typed/builtin//modules/api/engine/renderer/renderer/debugPass/channel
renderer.debugPass.channel(name: string) -> number?
The channel a debug-pass NAME renders on: a built-in pass, else a content
capture view registered via renderer.captureView. Nil when the name is
neither — the signal a selector uses to reject an unknown pass.
Parameters
namestring— A debug-pass name (e.g. "normal", "depth", "lightmap").
Returns number? — The channel number, or nil for an unknown name.
local ch = renderer.debugPass.channel("normal") -- 7
typed/builtin//modules/api/engine/renderer/renderer/debugPass/list
renderer.debugPass.list() -> { string }
Every selectable debug-pass name: the built-in passes plus every registered content capture view. What a debug-pass selector offers.
Returns { string } — An array of pass names.
local passes = renderer.debugPass.list()
typed/builtin//modules/api/engine/renderer/renderer/debugPass/name
renderer.debugPass.name(channel: number) -> string?
The canonical NAME for a debug channel: a built-in pass name for a built-in channel, else a registered capture view's name. Channel 0 is "final" (the lit image). Nil when no pass owns the channel.
Parameters
channelnumber— The channel number.
Returns string? — The pass name, or nil.
local name = renderer.debugPass.name(7) -- "normal"
typed/builtin//modules/api/engine/renderer/renderer/destroy
renderer.destroy(handleOrKind: any?, id: string?) -> boolean
Free the GPU resource a renderer resource holds (the GPU-destroy verb).
Takes any of the forms that name it: the handle a create returned, routed
by its category so one call releases a mixed set of handles; the id a
listing hands out, whose kind is read back off what the renderer holds
under it — the runtime registry, the material definitions, the live
features, and the device itself for an asset's own texture or mesh; or the
kind with the id beside it, the shape renderer.hold and
renderer.references take, which is what names the kind for an id two of
them answer to. An id nothing holds anything under releases nothing and
answers false. The on-disk asset, if any, is untouched. A CPU handle's
:unload() frees the CPU copy separately.
Parameters
handleOrKindany(optional) — AMeshHandle,TextureHandle,MaterialHandleor feature handle; the id itself; or the kind ("texture","material","mesh","feature") with the id as the second argument.idstring(optional) — The guid or registry key, when the first argument is a kind.
Returns boolean true if a GPU resource was known under the id.
renderer.destroy(meshHandle); renderer.destroy(materialHandle)
renderer.destroy(renderer.texture.list()[1].guid)
renderer.destroy("mesh", guid)
typed/builtin//modules/api/engine/renderer/renderer/deviceErrors
renderer.deviceErrors(sinceSeq: number?) -> { latestSeq: number, [number]: { seq: number, frame: number, kind: string, message: string } }
The uncaptured errors the render device reported (validation failures,
out-of-memory answers, internal errors) after sinceSeq, oldest first, from
a ring of the newest 64.
Each entry is { seq, frame, kind, message }: seq the number the error
arrived as (it only grows), frame the drawn frame it arrived on, kind one
of "validation", "out_of_memory" and "internal", and message what the
device said. The table's latestSeq is the newest number recorded so far,
zero before any error. Read it before a long GPU job starts and pass it back
afterwards to see what the device said while the job ran. Omit sinceSeq to
read everything the ring holds. Each error is also written to the engine log.
Parameters
sinceSeqnumber(optional) — Return only errors with a higherseq; omit for every error the ring holds.
Returns { latestSeq: number, [number]: { seq: number, frame: number, kind: string, message: string } } — The errors, oldest first, with latestSeq beside them.
local mark = renderer.deviceErrors().latestSeq
-- ... a long GPU job runs ...
for _, e in ipairs(renderer.deviceErrors(mark)) do print(e.kind, e.message) end
typed/builtin//modules/api/engine/renderer/renderer/deviceGeneration
renderer.deviceGeneration() -> number
Which render device this process is on, counted from the first.
A render device is lost when a driver resets, when the GPU is taken away,
or when a browser reclaims a WebGPU context. The engine answers by building
another device and re-deriving this session's resources onto it, and this
number moves by one each time it does. Anything held across frames that was
built from a GPU resource records this beside it and remakes it when the two
differ; engine.onDeviceRebuilt is the hook that fires when it moves.
Returns number — The current device generation, counting from 1.
local generation = renderer.deviceGeneration()
engine.onDeviceRebuilt(function(g) print("device " .. g) end)
typed/builtin//modules/api/engine/renderer/renderer/deviceLimits
renderer.deviceLimits() -> {
The sizes this device allocates and binds, for work that sizes itself to the device it runs on.
maxBufferBytes is the largest single GPU buffer the device creates.
maxStorageBindingBytes is the largest range of one buffer a dispatch binds
as a storage buffer: a GPU buffer one dispatch binds must fit in it, and a
dispatch that binds a larger one is refused with the reason.
maxWorkgroupsPerDimension is the most workgroups one dispatch spans along
an axis. memoryBudgetBytes is the memory the device affords to GPU
content, the figure renderer.textureStreaming() reports. A baseline WebGPU
device reads 134217728 for maxStorageBindingBytes; a desktop GPU reads
more.
Returns { maxBufferBytes, maxStorageBindingBytes, maxWorkgroupsPerDimension, memoryBudgetBytes }
local limits = renderer.deviceLimits()
print(limits.maxStorageBindingBytes // 1024 // 1024, "MiB per storage binding")
typed/builtin//modules/api/engine/renderer/renderer/deviceState
renderer.deviceState() -> string
Whether the render device this process draws through is the one it is using, one it is replacing, or one the platform has refused every quick attempt to replace.
"ready" is a live device. "rebuilding" is the window between a device
reporting itself lost and another being in place: every GPU resource built
from the old one is invalid, the frames in that window draw nothing, and
anything reaching the GPU refuses. "abandoned" is after every quick
attempt at another device was refused (a browser whose GPU process crashed
twice answers no adapter for minutes): nothing is drawn, the engine log
names the platform's last answer, and the engine keeps asking at a slower
pace, so the state returns to "ready" on its own once the platform hands
a device over. Restarting the engine (reloading the page on the web)
builds one from scratch.
Work that spans the device — build a render target, draw into it, read it
back — reads this to tell an operation that failed because the device went
out from under it, which is worth doing again once
renderer.deviceGeneration() moves, from one that failed on its own terms.
The loss is reported before the next device exists, so the two readings
answer different halves: this one says a replacement is coming, the
generation says it arrived.
Returns string — "ready" | "rebuilding" | "abandoned".
if renderer.deviceState() == "rebuilding" then return end
typed/builtin//modules/api/engine/renderer/renderer/drawDiagnostics
renderer.drawDiagnostics() -> { DrawDiagnostic }
Every renderable that is NOT drawing what its material says — the one
call for "why does this surface look wrong". Three states land here: a
surface rendering as the magenta placeholder (substituted), one the
renderer could bind nothing for at all (outcome = "skipped"), and one
drawing a program whose most recent compile FAILED (stale), which is what
a shader edited into brokenness looks like — the pipeline its last good
compile built keeps drawing, so the picture is intact and answers to none of
the edits since. Each row names the entity, the program asked for, the
program bound, programStatus — the compile gate's word about the program
the material NAMED — and the one cause
from shaderCompileFailed / shaderNotRegistered / shaderNotCompiledYet
/ noGbufferEntry / renderStateKeyNotBuilt / noPipelineForTarget /
unshaded, with the compiler's own message in detail or programError.
Covers every renderable the renderer holds, whether or not a camera reached
it: a row with observed = false and outcome = "notDrawn" carries the
renderer's own resolution for one this frame drew nowhere, so a broken
surface off-screen is reported the same as one in frame. An empty result
means every renderable the renderer holds is drawing the program its
material named and that program compiles. Answers on the deferred path as
well as forward, and in edit mode as well as play.
Returns { DrawDiagnostic }
for _, d in renderer.drawDiagnostics() do print(d.entity, d.reason, d.detail) end
if #renderer.drawDiagnostics() == 0 then print("every surface is drawing what it says") end
typed/builtin//modules/api/engine/renderer/renderer/drawStats
renderer.drawStats() -> {
What the last completed frame actually submitted. draws counts every
geometry draw call the frame issued — the camera's passes, each shadow
view a shadow-casting light adds, and whatever a render feature draws —
and instances counts the instances those draws covered. The pair is what
separates one draw carrying five hundred instances from five hundred draws
carrying one each, so it reads how well the scene batches rather than how
many objects are in it.
compacted is how many of those instances the frame planned through draws
whose instance count the GPU decides: the culler's own per-object answers
packed into a dense run, so an object it rejects is absent from the draw
instead of collapsing to nothing in the vertex stage. compactedDrawn is
how many of them survived, counted on the GPU as it packed them — a pass
that then skips a whole draw over its own layer or visibility answer
leaves that draw's instances in both numbers.
The plan is made over the populations the frame draws, and the tests
answer which of their instances the packing keeps. That packing runs
before any pass has resolved the depth occlusion culling is tested
against, so on its own it reads the frustum and screen-size answers
alone. With setOcclusionCulling armed the frame packs the same plan a
second time once the test has answered, and compactedDrawn then counts
what came through occlusion as well.
compactedDrawn comes back from the buffer the GPU wrote, so it describes
a frame that has finished while compacted describes the most recent
plan, and it holds the last count the GPU wrote until another arrives — a
frame that compacts nothing reads compacted 0 beside the count from the
last frame that did. In a scene standing still the gap between the two is
the front-end work culling removed. It is read back for a reader the way
cullStats().occlusionTested is: on the two rendered frames after each
call, and one rendered frame in 60 otherwise.
materialBinds is how many times the frame's geometry passes set a
material group's textures (group 1), and materialBindsElided how
many times a pass reached that decision and found the group already bound.
On the bindless backend every material group binds the one texture group
of the frame, so a pass binds it once; on buckets a pass binds once per
group it draws (see renderer.materialTable().groups). Their sum is how many times the
decision was reached — once per unit of geometry submitted, which sits at
or below draws, since a mesh of several primitives draws once per
primitive under one set of binds. materialExtraBinds and
materialExtraBindsElided are the same pair for group 2, the storage
buffers a shader declares, bound per distinct buffer set, which only the
shaders that declare them ever bind.
pipelineBinds and pipelineBindsElided are the same pair for the
pipeline itself: how many times the frame's geometry passes set one, and
how many times a pass reached that decision and found the pipeline it
wanted already bound. Which pipeline a unit needs follows its shader, its
material's render state and its mesh's vertex layout together, so a scene
whose units share all three costs one set for the run of them, while units
differing in any one of the three each pay their own. Their sum is how
many units reached the pipeline decision, which sits at or above what the
material pair reports: a unit the pass settles a pipeline for and then
abandons — one whose material group resolved to nothing — counts here and
never reaches the material decision.
Every figure here is the whole frame's. renderer.shadowViews() carries
the main camera's own share of compacted and compactedDrawn.
clusters and clusterTriangles are the clusters and triangles the
camera views drew from the cluster lists, from the GPU's own count.
drawsByPass splits draws by the part of the frame that submitted
them — visibility (the id raster: one draw per raster bin per Hi-Z
phase in each camera view, submitted whether or not the GPU cull left
anything in the bin), resolve (one draw per resolve draw in each
camera view: one per shader, and on the array-bucket backend one per
shader and material group), legacy (geometry drawn outside cluster
storage: skinned, morphed and compute-written meshes, line topology,
shaders that write their own vertex stage), blended, exception
(opaque materials whose depth state the visibility buffer cannot
express), featureGeometry, featureDraw, shadow and splat (one
draw per splat buffer a render feature draws) — and the nine sum to
draws.
instances counts instances named by draws whose size the CPU decided;
the visibility raster's work is clusters and clusterTriangles, which
the GPU decided. pixelsResolved is how many pixels the resolve shaded,
summed over camera views, and pixelsByShader the same split by shader.
clusters, clusterTriangles, pixelsResolved and pixelsByShader
come back from the GPU and describe the frame numbered frame, which is
earlier than the frame draws describes. A frame counts them, and reads
them back, for a reader: the two rendered frames after each
drawStats() read, and one frame in 60 otherwise, so a read after a
pause answers a frame at most as old as the pause and never more than 60
rendered frames, and a script reading every frame reads every frame's.
frame is the renderer's own
frame number, counted from 0 when the renderer was built (again after a
device loss), a count of its own that compares only with another
drawStats().frame.
Returns { draws: number, instances: number, compacted: number, compactedDrawn: number, materialBinds: number, materialBindsElided: number, materialExtraBinds: number, materialExtraBindsElided: number, pipelineBinds: number, pipelineBindsElided: number, clusters: number, clusterTriangles: number, drawsByPass: { visibility: number, resolve: number, legacy: number, blended: number, exception: number, featureGeometry: number, featureDraw: number, shadow: number, splat: number }, pixelsResolved: number, pixelsByShader: { [string]: number }, frame: number }
local d = renderer.drawStats(); print(d.instances / math.max(d.draws, 1), "instances per draw")
print(renderer.drawStats().compactedDrawn, "of", renderer.drawStats().compacted, "survived the cull")
local d = renderer.drawStats(); print(d.materialBinds, "material group binds over", d.materialBinds + d.materialBindsElided, "units")
local d = renderer.drawStats(); print(d.pipelineBinds, "pipeline sets over", d.pipelineBinds + d.pipelineBindsElided, "units")
local d = renderer.drawStats(); print(d.clusters, "clusters,", d.clusterTriangles, "triangles from the cluster lists")
local d = renderer.drawStats(); print(d.drawsByPass.visibility, "id-raster draws,", d.drawsByPass.resolve, "resolve draws")
local d = renderer.drawStats(); for shader, px in d.pixelsByShader do print(shader, px) end
typed/builtin//modules/api/engine/renderer/renderer/feature/configure
renderer.feature.configure(handleOrRef: any?, settings: { [string]: any }) -> { [string]: any }
Lay settings over a live feature's knobs. Any omitted knob keeps its
value; a knob the feature never declared, or a value of the wrong shape, is
refused by name. The feature reads the result as ctx.settings from its
next frame: a new table, so a feature finds a change with one reference
test.
Parameters
handleOrRefany(optional) — ARenderFeatureHandle, its guid, or the feature's ref.settings{ [string]: any }— The knob values to apply.
Returns { [string]: any } — The feature's full settings now in force.
renderer.feature.configure(h, { intensity = 0.5, quality = "medium" })
typed/builtin//modules/api/engine/renderer/renderer/feature/create
renderer.feature.create(ref: any?, opts: (string | { guid: string?, settings: { [string]: any }? })?) -> any
Instantiate a render feature so the engine calls its render(ctx) hook
every frame. ref is an AssetRef<renderFeature> whose init.luau returns
{ setup?, render, teardown? }. Returns a live RenderFeatureHandle (its
guid is the stable id, same as mesh/texture handles); tear it down with
renderer:destroy(handle). Pass guid to assign a specific id. The
feature runs while its handle is reachable from a script or something
else holds it (its renderFeature asset, the component or scene load that
started it, a renderer.hold); once nothing does and the garbage
collector has taken its last handle, the engine tears it down mid-session.
A write to the feature's asset (its init.luau, or a module beside it)
starts the live feature again on the stored definition from the next frame:
teardown runs, setup runs on the new definition, the guid and every
handle stay, and the knobs set through settings or configure carry over
when the new definition still declares them. A definition that fails to
load leaves the running one in place.
Parameters
refany(optional) — AnAssetRef<renderFeature>, or a string identity/guid resolved viaasset.resolve(ref, "renderFeature"). An identity written as a literal (or held in a file constant) is a reference of the script that wrote it, so the.renderFeatureit names is carried by an install of that script and the create reaches the installed copy.opts(string | { guid: string?, settings: { [string]: any }? })(optional)
Returns any — A RenderFeatureHandle.
local h = renderer.feature.create(asset.resolve("acrylic", "renderFeature"))
local h = renderer.feature.create("acrylic")
local h = renderer.feature.create("@builtin::systems.reflections.ssr", { settings = { intensity = 0.8 } })
typed/builtin//modules/api/engine/renderer/renderer/feature/destroy
renderer.feature.destroy(handleOrGuid: any?) -> boolean
Tear down a live render feature by its RenderFeatureHandle OR its guid
string — the by-id path for when the handle was lost (e.g. across execute
calls). Same effect as renderer.destroy(handle). Returns true if a feature
was live under that id.
Parameters
handleOrGuidany(optional) — ARenderFeatureHandleor itsguidstring.
Returns boolean
renderer.feature.destroy("eb623975-d8bd-47a1-a0a4-5c0e56238e2f")
typed/builtin//modules/api/engine/renderer/renderer/feature/drawn
renderer.feature.drawn() -> { [string]: { objects: number, triangles: number } }
What each geometry pass a render feature enqueued drew on the last
drawn frame, keyed by the pass's material: how many objects it drew (each
copy of an instanced population counts) and how many triangles it
rasterized, which is what its cost follows. A pass stating detail draws
each mesh at the coarsest cut of its cluster hierarchy within that size,
and one stating rigid leaves out the meshes a skeleton or morph targets
deform; this is the reading that shows what each left. Summed over every
camera the frame drew; a pass no camera recorded is absent.
Returns { [string]: { objects: number, triangles: number } } — { [material: string]: { objects: number, triangles: number } } — last drawn frame.
for name, d in pairs(renderer.feature.drawn()) do print(name, d.objects, d.triangles) end
typed/builtin//modules/api/engine/renderer/renderer/feature/find
renderer.feature.find(ref: any?) -> any
The live handle of the feature running ref — an AssetRef
Parameters
refany(optional) — An AssetRef, a renderFeature identity, or a guid.
Returns any — The RenderFeatureHandle, or nil.
local h = renderer.feature.find("@builtin::systems.reflections.ssr")
typed/builtin//modules/api/engine/renderer/renderer/feature/list
renderer.feature.list() -> { { guid: string, identity: string, settings: { [string]: any }, keptPasses: number, handedFrame: number, contentRevision: number?, settingsRendered: boolean, heldBack: { PassScheduleHeldBack } } }
List every render feature currently live (running its render(ctx) each
frame). Each entry is { guid, identity, settings } — the guid is the same
id a RenderFeatureHandle carries, so you can tear a feature down by guid
even after losing its handle (e.g. across separate execute calls), and
settings is every knob the feature declares at the value in force.
keptPasses is how many passes the engine keeps for it: a render that
hands over only specs frozen all the way down has the engine run them on
every frame until it hands over a different list. handedFrame is the
frame its passes were last handed to the engine (-1 before the first), so
a feature whose passes hold still reads the same frame while it runs.
contentRevision is how many times the settings of a feature with a pass
that runs in environment captures have changed value (a reload of its
definition counts as one), nil for a feature with no such pass: a capture
of the sky or of a reflection probe's surroundings draws what that
feature's settings state, so a reader that took one reads the revision to
learn the capture is out of date. settingsRendered is whether the
feature's latest render ran with the settings it holds now.
heldBack lists the feature's passes the last drawn frame held back
because a render target they sample holds no picture and no pass wrote
it that frame (the renderer.passSchedule().heldBack entries naming the
feature): a feature handing its passes over every frame whose picture
never changes names here the input that keeps them from running.
Returns { { guid: string, identity: string, settings: { [string]: any }, keptPasses: number, handedFrame: number, contentRevision: number?, settingsRendered: boolean, heldBack: { PassScheduleHeldBack } } }
for _, f in renderer.feature.list() do print(f.identity, f.guid, f.keptPasses) end
for _, f in renderer.feature.list() do for _, h in f.heldBack do print(f.identity, h.slot, h.message) end end
typed/builtin//modules/api/engine/renderer/renderer/feature/notice
renderer.feature.notice(handleOrRef: any?) -> string?
What a live feature states about its settings as they stand: the
sentence its definition's notice(settings) returns (a feature whose
settings hide something its author wrote says so there), or nil for a
feature that states nothing or declares no notice.
Parameters
handleOrRefany(optional) — ARenderFeatureHandle, its guid, or the feature's ref.
Returns string? — The notice, or nil.
local n = renderer.feature.notice("@builtin::systems.sky.backdrops.procedural")
typed/builtin//modules/api/engine/renderer/renderer/feature/schema
renderer.feature.schema(ref: any?, settings: { [string]: any }?) -> { [string]: any }
The settings a .renderFeature takes, with each knob's descriptor,
read without running it: what a caller may pass to create / configure.
With settings, it adds the knobs that follow from content those settings
name (its parameters(settings)).
Parameters
refany(optional) — An AssetRefor a renderFeature identity. settings{ [string]: any }(optional) — Optional settings the knobs are read for.
Returns { [string]: any } — { [name]: descriptor }, empty for a feature that declares none.
for name, desc in pairs(renderer.feature.schema("@builtin::systems.reflections.ssr")) do print(name, desc.default) end
typed/builtin//modules/api/engine/renderer/renderer/feature/settings
renderer.feature.settings(handleOrRef: any?) -> { [string]: any }?
A live feature's settings as they stand: every declared knob at its
default or at what create / configure set. A copy — writing to it
changes nothing; configure does.
Parameters
handleOrRefany(optional) — ARenderFeatureHandle, its guid, or the feature's ref.
Returns { [string]: any }? — The settings table, or nil when no such feature is live.
local s = renderer.feature.settings(h); print(s.intensity)
typed/builtin//modules/api/engine/renderer/renderer/feature/shaded
renderer.feature.shaded() -> { [string]: number }
How many pixels each fragment pass a render feature enqueued shaded on
the last drawn frame, keyed by the pass's shader/effect name. A fragment
pass draws one triangle over its target, so it shades the whole screen
whatever its effect actually reaches — unless it declares bounds on the
pass spec, the world-space box its effect stays inside, in which case it
shades the rectangle that box projects into for the camera drawing it and
is skipped for a camera that cannot see the box at all, or unless it
states drawnMargin with whenDrawn, in which case it shades the
rectangle the objects drawn into its whenDrawn target cover, grown by
that many pixels. This is the reading
that says which a pass is: it moves when the effect moves, and a
pass absent from it shaded nothing. Summed over every camera the frame drew.
Returns { [string]: number } — { [shader: string]: number } — pixels shaded, last drawn frame.
local px = renderer.feature.shaded(); for name, n in pairs(px) do print(name, n) end
typed/builtin//modules/api/engine/renderer/renderer/featureTexture/configure
renderer.featureTexture.configure(width: number, height: number, layers: number)
Size the shared feature-texture array — the layers a surface shader reads
through zero_feature_texture(uv, layer), and the layers a SpotLight
projects through its cone via cookieLayer. Layers are rgba16f.
A call for the size the array already has is left alone. One that changes
the size reallocates, and the replacement is zeroed — so it empties every
layer in the array, including the layers other features and other cookies
own. renderer.featureTexture.state() reports the extent and the layers
holding content, which is how a feature re-fills the layer a resize took
from it.
Parameters
widthnumber— Layer width in pixels.heightnumber— Layer height in pixels.layersnumber— How many layers the array holds.
renderer.featureTexture.configure(512, 512, 4)
typed/builtin//modules/api/engine/renderer/renderer/featureTexture/setLayer
renderer.featureTexture.setLayer(layer: number, textureKey: string, x: number, y: number)
Copy a texture already on the GPU into one layer of the shared array,
its top-left corner at (x, y) — GPU to GPU, with no readback. Several
small images pack into one layer by calling this once per image at
different offsets. The source must be rgba16f and fit at that offset.
Parameters
layernumber— Which layer of the array to write into.textureKeystring— The source texture's name — the one it was created under. Acompute.createStorageTexture2Dtarget, acompute.createTextureHistorypair (its current side), and a texture acompute.copyBufferToTexturewrote all answer to the name they were given.xnumber— Left edge of the destination rectangle, in pixels.ynumber— Top edge of the destination rectangle, in pixels.
compute.createStorageTexture2D("gobo", { width = 256, height = 256, format = "rgba16f" })
renderer.featureTexture.setLayer(0, "gobo", 0, 0)
typed/builtin//modules/api/engine/renderer/renderer/featureTexture/state
renderer.featureTexture.state() -> {
What the shared feature-texture array is right now: the extent every
layer carries, and filled, the ascending 0-based indices of the layers a
setLayer has landed in since the array was last sized. One array is
shared by every feature and every light cookie in the scene, and it has no
allocator, so this is the call that tells a feature whether the array it
sized and filled is still the array it is writing into — a configure that
changed the size reallocates and zeroes every layer, and the layer it
emptied leaves filled without it. Measured off the renderer at the end of
the last rendered frame, so a configure or setLayer issued this frame
reads back on a later one.
What this describes is the array a shader samples. The source texture a
setLayer copied FROM is a GPU resource of its own and keeps the bytes it
was written with for as long as it lives, so filled is the reading that
answers whether the layer behind a cookieLayer is live right now.
fills counts, per layer, the setLayers that have landed in it since the
array was last sized: fills[layer + 1] for a 0-based layer. A fill of a
layer that already holds content leaves filled as it was, so the count
moving is how a feature re-filling its own layer reads its fill arriving.
Returns { width, height, layers, filled, fills }
local ft = renderer.featureTexture.state()
print(("feature textures: %dx%d over %d layers"):format(ft.width, ft.height, ft.layers))
-- Re-fill the cookie layer this module owns if anything emptied it.
if ft.width ~= myWidth or table.find(ft.filled, myLayer) == nil then
print("refill the cookie layer", myLayer)
end
typed/builtin//modules/api/engine/renderer/renderer/framePacing
renderer.framePacing() -> FramePacing?
How far the CPU is allowed to run ahead of the GPU, and what holding it there cost the frame just finished. Submitting work to the GPU returns before the GPU has done it, and everything that submission holds — its staging allocations, its bind groups, its command buffer — stays alive until it completes. A frame that asks for more work than the GPU finishes in a frame's time therefore leaves that behind it, and unbounded that is memory growth rather than a lower frame rate.
framesInFlight is how many submitted frames have not reported done
through the queue's completion signal, held under maxFramesInFlight: a
device that keeps up reads under the bound, one that is behind reads at it.
A frame the renderer declines is counted there too when its systems put
work on the queue (a compute batch, a transform compose, an offscreen
render), so a headless engine nothing reads frames from reads the GPU work
it keeps in flight.
It counts submissions, which is its own quantity — how many presented
images the swapchain permits in flight is a separate setting.
mechanism names how that bound is enforced
here: submission-wait waits for the frame that many frames back and
reports the wait in waitMs, so a paced frame costs latency and still
draws; submitted-work-done counts outstanding frames off the queue's
completion signal and declines to start a frame while the bound is met,
counting those in pacedFrames and leaving the last presented image up.
submittedFrames counts the frames that were admitted and submitted, so it
rises for as long as the renderer is producing frames — which is what tells
a renderer running slowly under a tight bound from one that has stopped.
stalled reads true while the pacer has given the bound up rather than
hold the image indefinitely, on either mechanism: the counting one stands
down when the completion signal goes quiet across a whole run of declined
frames, and the waiting one when a wait on a frame reaches its ceiling
with the GPU still holding it. Both clear on the first word the GPU sends
after that. A signal that is merely late — a GPU finishing frames more
slowly than the loop asks for them — keeps the bound, so stalled answers
for a GPU that went silent. standDowns counts those over the session,
which is how a session that lost the signal and got it back
(stalled = false with standDowns above zero) reads apart from one that
never lost it.
producing is whether the renderer drew the last frame. A headless
renderer draws into an offscreen framebuffer that nothing presents, so its
image reaches a reader only through something that copies it out: it draws
while a consumer is asking — a capture, a wait on drawn frames, a queued
texture readback, a recording, a frame-egress session — and declines the frames
between two asks. A renderer presenting to a display draws while what is on
screen changes, and for a short settling run after the last change, and
declines the frames of a still picture, which stays on screen; whatever
else moves (the gameplay clock, a task owed the next frame, held input, a
tool call) keeps running at the display's rate meanwhile, and an engine
with nothing moving waits instead (engineStill, below). Both count the
frames they declined in idleSkippedFrames. Every other
renderer stat answers with the last frame that drew, so producing is what
separates a live reading from a frozen one.
A change of the UI alone (a hover, a tooltip, a panel's text) leaves the
scene's picture as it was. A presenting renderer draws the frame that
carries it, and while a viewport panel holds the scene's last picture it
draws that frame as the UI over the picture without drawing the scene
again: uiOnlyFrames counts those frames, which time.drawnFrameCount()
leaves out.
pictureReady is whether a frame drawn now is the picture a reader comes
for. A headless renderer nothing has read for its interval (10 s) lets go
of what it draws with (its view-sized targets, its shadow page pool, its
cull scratch); while it does, and while it brings them back for a reader
until the shadow pages the view asks for are drawn again, it reads false.
A capture waits for it.
drawPolicy names the rule the last frame was decided under: consumers
(headless), changes (presenting to a display) or every_frame (content
asked for every frame with renderer.setDrawEveryFrame(true), also read as
drawEveryFrame). pictureChanges counts, per source, the frames on which
something changed what the next frame draws: ui (a new UI layout or UI
texture), camera (the viewport camera, the viewport, a frame setting or
a renderer setting a script states: the projection offset, the shadow
configuration, the render path),
scene (a renderable added, removed, moved, shown or re-described),
material (a material created, removed or given new properties,
textures or a new shader), lighting (a light, the ambient term or the
sky), surface (its size, format or present mode),
arrivals (a pipeline,
texture or material row still landing), world (a component written, an
entity spawned or removed), clock (something drawn with a shader that
reads the frame clock, while the clock runs), compute (a compute buffer written or dispatched
over), window (the platform asked for the window to be drawn again),
texture (a texture's contents replaced from the CPU, a video frame among
them) and content (a script's command reached the engine: a
post-process effect, a sky, an environment, a render feature). Every
renderer counts them, a headless one included.
Every change names its owner, what within its source changed the
picture: a ui change the reason its UI pass ran and the screens it laid
out (tree: hud, pointer_motion, repaint_due, viewport ui: ... for
the UI painted into the scene), a world change the component and the
entity it was written on (Transform on crate-1 'Crate'; eight of them a
frame, taken in turn from frame to frame when more changed), a content
change the command it applied or the render pass that differs, a clock
change the program that reads the clock, a camera, scene, surface
or lighting change the part that moved (frame settings, placement,
size, sun), a compute or texture change the buffer or texture
written, an arrivals change the kinds of work still landing, a window
change the platform event. lastPictureChange names the source of the
latest and lastPictureChangeDetail its owner; pictureChangeDetails
holds, per source, the owner its latest change named. redrawReasons
lists the owners that changed the picture, the most changes over the
last 5 to 10 seconds first (recent), each with its source, owner,
recent, its total over the session and agoMs since its last change:
every owner the renderer keeps apart, at most 64, a new one taking the
place of the one with the fewest recent changes. Read it on a renderer
that keeps drawing a picture that looks still: the owner at the top is
what keeps it redrawing. renderer.activity() puts the top of it
beside the frame rate and the CPU the engine spends.
presentMode is what the surface presents with and presentModes what it
offers; both are empty of meaning on a headless renderer, which never
presents. A desktop presents mailbox unless told otherwise, and Android
presents fifo, which shows each frame on a vsync of the panel and makes
no frame the panel never shows.
The rest describe the rate frames run at. displayRefreshHz is the
refresh rate of the display the frames are shown on, where the platform
reads it: the phone's panel, the monitor a desktop window is on, the
cadence of a browser's animation frames. A headless engine presents to no
display and states none. frameRateCap is the cap
renderer.setFrameRateCap set, absent while none is. frameRateMode is
how the rate is chosen (renderer.setFrameRateMode), chosenFps the rate
the frame loop chose and frameRateReason why: cap (the highest rate
the cap delivers), display (the display's highest rate, with no cap),
frame_time (a lower even rate, because frames did not hold the faster
one) or uncapped (no target: a surface that shows a frame the moment
it is ready, immediate or auto_no_vsync, a display whose refresh rate
is not read, or no display, with no cap). On a mailbox surface a
frame that takes longer than a refresh runs as soon as it is ready.
targetFps is the rate the chosen one delivers on the mode the display
runs in now and refreshesPerFrame the refreshes each frame stays on
screen there; these and chosenFps are
absent while no target is in force. frameWorkMs is the 90th percentile
of the time recent drawn frames took, the time the rate is chosen from.
lateFrames counts the drawn frames the loop came back to later than the
vsync each was due for, missedPresents those the compositor showed
later than one interval after the frame before them (a judder; 0 where
the surface reports no present times), and
rateStepsDown / rateRaises the times the chosen rate went down and up,
all since the rates to choose from last changed (a new cap, mode or
display). Each change is also one [frame rate] line in the engine log
naming what decided it.
displayVote names the platform call that tells the display the rate
(none where there is none, and frames are held to the display by
pacing alone) and displayVoteFps the display mode it last asked for.
deliveredFps is the rate the frame loop has run frames at over about
the last twenty frames.
The last describe whether the engine runs frames at all. An engine with
nothing to draw, its gameplay clock stopped, no deferred task or settled
promise to resume, no commands waiting to be applied, no tool call in
flight and no input held is still (a playing sound keeps sounding through
it, the audio output feeding itself on its own clock), and its
loop runs a frame at once when something reaches the engine, else when
the earliest wait a task holds comes due, with frames at least a quarter
of a second and at most a second apart. engineStill is whether the
engine stated itself still at the end of its last frame (a reading taken
inside a tool call reads false, since the call is in flight) and
movingBecause names what kept it moving otherwise: picture,
gameplay, boot, tasks, input, recording, calls or
replay (a physics replay plays).
stillWaits counts the frames the loop held back for a still engine,
framesAfterStill the frames run after such a wait, wokenFrames those
of them an arrival started (a frame a task's wait or the longest gap ran
is in wokenBy and absent from wokenFrames, so wokenBy is the count
that names every still frame), and stillSeconds the seconds spent
waiting.
wokenBy names what ran each frame the loop ran after a frame at whose
end the engine stated itself still, the most frames over the last 5 to 10
seconds first, each with its source, owner, recent, total over
the session and agoMs since it last ran one, and for a task's wait the
site (source:line) the task waits at, each site counted apart and a
frame several tasks' waits owe counted against each of them, and for
a message what it carried (its kind: PropertyBatch, Snapshot,
AvatarState), each kind counted apart. A
frame that ran before
its still wait came due is counted against the first arrival since the
frame before (for a loop whose frames present nothing and reach no
reader, the first other than a picture change, which leaves its wait
held), under its kind: input (keyboard, pointer, touch,
gamepad, file drop, focus lost, remote input, page input),
call (tool call, over any transport, the engine's bridge socket
among them: a reading taken through a tool call is one),
route (route request), reader (frame reader), picture
(picture change, renderer warm-up), promise (a promise,
worker job, http response, file pick, file save,
sign-in answer, tool result or agent result settled on another
thread, or a socket state: a websocket a script waits on opened,
failed to open, closed or failed), request (a script's websocket request, http request,
content request, shell request, tool request, code to run,
av command, window capture, plugin gpu request,
plugin entity request, plugin events or script command queued for
the engine thread), file (file loaded, library loaded,
file transfer), write (file written), message
(stream message, datagram: a message a frame acts on, the relay's
answer to a clock request running none; socket message: a frame
landing on a websocket a script holds), job (off-frame job,
pipeline built) or platform (window, app presence,
motion preference, notification, background work,
page message, world request). A frame whose wait came due is counted against what
set the wait's end, under schedule: task waits on frames (a task
waiting on frames or on a timer already due), task timer,
task waits at its rate (a wait that names the frames a second it asks
for, { wake = 30 }), longest gap (nothing due) or hidden gap (a loop whose frames present
nothing); one the renderer owed with nothing arriving under picture
as draw owed. The cause at the top of a reading taken while an idle
engine keeps running frames is what keeps it running them.
stillFrames counts the frames after which the engine stated itself
still and movingFrames those after which it stated itself moving, per
reason, so the reason a still scene keeps running frames is the count
that grows between two readings.
An engine whose frames reach nobody unless something asks for them (an
agent's sub-client) runs its gameplay at a lower rate while nothing
observes it: no tool call in flight, no input held, nothing reading its
frames. unobservedGapMs is the gap the engine stated its loop may then
leave between two frames (absent while something observes it),
unobservedWaits counts the frames the loop held back for it,
framesAfterUnobserved the frames run after such a wait and
unobservedSeconds the seconds spent waiting.
An editor whose picture alone moves (a material reading the frame clock,
clouds, content moving in editorUpdate) and that nobody has attended
for three seconds (no input, nothing reading its frames, no change of its
UI, window or surface) draws that motion at its preview rate. An agent's
call is not a person attending: a tool call runs its own frames at the
full rate and the preview rate holds again once it is answered.
previewFps is that rate (edit_preview_rate under [render], 15
unless the world states another; absent while it is 0, which draws such
motion at the full rate), previewGapMs the gap the engine stated its
loop may then leave between two frames (absent while something attends
it or anything else moves it), previewWaits counts the frames the loop
held back for it, framesAfterPreview the frames run after such a wait
and previewSeconds the seconds spent waiting. While its window holds no
input focus (another window has it, the browser page is blurred or hidden,
the Android activity lost its window focus) the preview runs at no more
than 2 frames a second (previewFps reads the rate in force and
windowFocused the focus), and the window taking the focus back or any
input runs the next frame at once.
Returns FramePacing? — { framesInFlight, maxFramesInFlight, pacedFrames, submittedFrames, waitMs, mechanism, stalled, standDowns, producing, pictureReady, idleSkippedFrames, uiOnlyFrames, drawPolicy, drawEveryFrame, pictureChanges, pictureChangeDetails, redrawReasons, lastPictureChange?, lastPictureChangeDetail?, presentMode, presentModes, displayRefreshHz?, frameRateCap?, frameRateMode, frameRateReason?, chosenFps?, refreshesPerFrame?, targetFps?, deliveredFps?, frameWorkMs?, lateFrames?, missedPresents?, rateStepsDown?, rateRaises?, displayVote, displayVoteFps?, engineStill, movingBecause?, stillWaits, framesAfterStill, wokenFrames, wokenBy, stillSeconds, stillFrames, movingFrames, unobservedGapMs?, unobservedWaits, framesAfterUnobserved, unobservedSeconds, previewFps?, previewGapMs?, previewWaits, framesAfterPreview, previewSeconds, windowFocused }, or nil before the renderer has drawn a frame
local p = renderer.framePacing()
print(("%d of %d frames in flight, paced by %s"):format(p.framesInFlight, p.maxFramesInFlight, p.mechanism))
typed/builtin//modules/api/engine/renderer/renderer/getRaytrace
renderer.getRaytrace() -> boolean
Whether ray tracing is currently enabled.
Returns boolean
typed/builtin//modules/api/engine/renderer/renderer/gpuMemory
renderer.gpuMemory() -> GpuMemory
Where the renderer's GPU memory went at the last frame the renderer ran — the call to reach for when something is holding memory and you do not know what.
Three figures answer three different questions, and they are meant to be read against each other:
- The categories (
shadow,textures,meshes,geometry,instances,cull,compute, summing tocategorised) are the renderer's own accounting of what it asked for on purpose, each allocation they count standing in exactly one of them. Always present, on every backend.texturesis what the resident textures occupy, and on the texture-array backend also the slack its shared arrays hold beyond them (renderer.materialTable().bucketSlackBytes). allocatoris the device allocator's ledger, with a row per creation label largest first, which is what names an allocation no category claims. A render target's colour texture is reported under what holds it now: the target drawing into it, orreleased_scratch[<width>x<height>].colorwhile it waits for the next target of its size. It exceedscategorisedby the per-frame render targets and the scratch nothing categorises, and on the texture-array backend, for the frame after an array grows or is repacked, by the array it replaced. The allocator hands memory out from blocks it reserves whole from the device and returns a block only once nothing is left in it, soreservedBytesruns aboveallocatedBytesby what those blocks hold unused;blockslists them emptiest first with the labels that keep each one alive, andemptyBytesplusslackBytesis that distance exactly — the pool held in empty blocks, and the room pinned inside blocks something still sits in.driver.deviceLocalBytesis what the graphics driver charges this process, out of the kernel's own accounting. It is the biggest of the three and the one that fills a card, because it also holds the swapchain, the images the driver keeps on the renderer's behalf, and the rounding to whole pages and heap blocks that neither figure above sees. Read it when the question is how much of the machine's GPU this engine is using; read the two above when the question is what the engine spent it on.driver.residentBytesis everything the driver holds, the device's own memory and the host memory (gtt) it moves buffers to when the card is full;driver.regionsnames each. A platform with no per-process accounting reportsavailable = falseand the reason.driver.outsideAllocatorBytesisresidentBytesless everything the allocator reserved: what the driver holds on its own account. Another scene andrenderer.collect()leave it where it is; the compiled program of a dropped pipeline is released once the compiled-pipeline store next renews (renderer.pipelineCache().renewals), and the rest falls when the device is destroyed. Read it when a session's device memory has grown and no ledger row accounts for the growth.
compute is what the compute subsystem holds; compute.observe() names
each of those resources and what it costs. arenas states the part of it
the pages runs stand in hold, and what those pages' bytes are spent on. renderTargets counts the
offscreen render targets the renderer holds at that frame, which is what
says a renderer.destroy has been applied rather than queued.
textureBudgetBytes is the texture budget in force and pressure the
memory pressure level that shapes it: under "critical" the budget reads
half the device's, and renderer.memoryPressure() says what the newest
report released.
Returns GpuMemory — The accounting — see GpuMemory. The category figures are zeroed until the renderer has published its first frame; driver is read as the call runs and answers from the first.
local m = renderer.gpuMemory()
print(("shadows %.1f MiB"):format(m.shadow.total / 1024 / 1024))
-- how much of the card this engine is holding:
if m.driver.available then
print(("driver %.1f MiB"):format(m.driver.deviceLocalBytes / 1024 / 1024))
else
print("no driver figure: " .. m.driver.reason)
end
-- the biggest allocation in the engine:
local top = m.allocator and m.allocator.byLabel[1]
print(top and top.label, top and top.bytes)
-- the block held for the least, and what pins it:
local block = m.allocator and m.allocator.blocks[1]
if block and block.allocationCount > 0 then
print(block.size, block.allocatedBytes, block.byLabel[1].label)
end
typed/builtin//modules/api/engine/renderer/renderer/hold
renderer.hold(handleOrKind: any?, id: string?) -> boolean
Pin a runtime resource for the session. A held texture, material, mesh
or render feature survives every collection — the one a root scene load
runs and a direct renderer.collect() alike — until renderer.release
lets it go or its destroy frees it. It is the way to keep an ad-hoc
resource across the scenes that come and go under it. A hold keeps the
resource in the registry; a mesh's GPU buffers are governed by what draws
it, parked as a CPU definition when the last instance naming it goes and
brought back when one names it again, so renderer.mesh.isResident(guid)
is the separate question about the buffers.
Parameters
handleOrKindany(optional) — The resource's handle, or its kind ("texture","material","mesh","feature") with the guid or key as the second argument.idstring(optional) — The guid or key, when the first argument is a kind.
Returns boolean true when the registry knows the resource.
renderer.hold(tex)
renderer.hold("material", "swatch")
typed/builtin//modules/api/engine/renderer/renderer/instanceData/clear
renderer.instanceData.clear(target: string | entityRef)
Drop every lane of an entity's per-instance shader data, so its draws read zero again — how a feature releases a subject it is still holding. Despawning an entity releases its block too, so this is for a subject that stays. It takes an entity that has already gone, which is when a feature releasing its subjects often runs, and does nothing for an entity holding no block.
Parameters
targetstring | entityRef— The entity — a proxy fromentity(...)/entity.spawn(...), or an entity-id string.
renderer.instanceData.clear(subject)
typed/builtin//modules/api/engine/renderer/renderer/instanceData/laneCount
renderer.instanceData.laneCount() -> number
How many vec4 lanes each entity's per-instance block holds, so a lane
index runs 0 .. laneCount() - 1. The same count a surface shader indexes
input.shader_data against.
Returns number — lanes per entity.
for lane = 0, renderer.instanceData.laneCount() - 1 do
renderer.instanceData.set(subject, lane, 0)
end
typed/builtin//modules/api/engine/renderer/renderer/instanceData/set
renderer.instanceData.set(target: string | entityRef, lane: number, x: number, y: number?, z: number?, w: number?)
Write one vec4 lane of an entity's per-instance shader data — the
channel that lets ONE material serve many entities that differ in a value.
A surface shader reads the lane back as input.shader_data[lane], so a
dissolve at its own progress per subject, an effect at its own age per
firing, or a per-entity mask costs one material rather than one material
per entity.
The engine attaches no meaning to a lane: a feature picks the lane indices it owns and packs whatever its shader agrees they carry. Name those indices in the module that writes them, so the writer and the shader read the block the same way.
A per-instance colour needs no shader of its own: the built-in
@builtin::materials.instance_color (lit) and instance_color_unlit read
lane 2 as (r, g, b, coverage), and instance_color_lane names the lane
on any @builtin::shaders.pbr or unlit material, so a stress colour, a
heat map or a damage flash recoloured every frame is one set per entity.
The write reaches the block where it is called, so the entity it names is the one holding that id at that point in the tick, and the value is on the draw from the next frame. It is held until the lane is written again, the entity's block is cleared, or the entity is despawned — a despawned entity releases its whole block. A lane an entity was never given reads zero.
Parameters
targetstring | entityRef— The entity — a proxy fromentity(...)/entity.spawn(...), or an entity-id string. It must name a live entity.lanenumber— Whichvec4lane to write,0 .. laneCount() - 1.xnumber— The lane's.x.ynumber(optional) — The lane's.y. Defaults to 0.znumber(optional) — The lane's.z. Defaults to 0.wnumber(optional) — The lane's.w. Defaults to 0.
-- One dissolve material, each subject at its own progress.
local DISSOLVE_LANE = 0
for _, subject in ipairs(dying) do
renderer.instanceData.set(subject.entity, DISSOLVE_LANE, subject.progress)
end
typed/builtin//modules/api/engine/renderer/renderer/lighting
renderer.lighting() -> boolean
Whether the scene renders lit: this viewer's switch and what the scene states, both on.
Returns boolean — true while lighting is on.
typed/builtin//modules/api/engine/renderer/renderer/localLayers
renderer.localLayers() -> { [string]: number }
The entities this engine draws on layers of their own, by entity id, with
the layer mask each is drawn on (renderer.setLocalLayers).
Returns { [string]: number } — A table of entity id to render-layer mask.
for id, mask in renderer.localLayers() do print(id, mask) end
typed/builtin//modules/api/engine/renderer/renderer/loseDevice
renderer.loseDevice()
Destroy the render device on the next frame, so the engine meets a real device loss.
This is the one loss that can be caused on purpose, and it travels the same
path a driver reset does: frames draw nothing until the rebuild lands,
GET /engine/status reports the renderer as recovering while it does,
engine.onDeviceRebuilt fires afterwards, and renderer.deviceGeneration()
moves. Use it to prove that a world's content survives a device loss —
anything it holds only on the GPU has to be remade from the rebuild hook, and
this is how you find out whether it is.
renderer.loseDevice()
-- some frames later:
print(renderer.deviceGeneration()) -- one higher than before
typed/builtin//modules/api/engine/renderer/renderer/mainCameraView
renderer.mainCameraView() -> { number }?
The main camera's inverse view-projection (column-major, 16 numbers)
followed by its world position (3 numbers) — {m0..m15, px,py,pz} — for
reconstructing world positions from the depth buffer in a ray-tracing pass.
Nil before the first render.
Returns { number }? 19 numbers, or nil.
typed/builtin//modules/api/engine/renderer/renderer/markBaseline
renderer.markBaseline() -> number
Record which render features are live and how the feature-texture array
is configured, and make that the point renderer.resetToBaseline returns
to.
A caller running work in an engine it shares — a sweep of test suites, a tool driving a session — leaves the renderer holding whatever that work set up: a feature a module created on first use, an array reconfigured to the size one pass wanted. This is how such a caller says where its own changes start. mark above the marks before it.
Returns number — The mark's generation, counting from 1 — what renderer.resetToBaseline takes to restore to this mark.
local mark = renderer.markBaseline() -- then run, then renderer.resetToBaseline(mark)
typed/builtin//modules/api/engine/renderer/renderer/material/animatedTexture
renderer.material.animatedTexture(texture: string | AssetRef, opts: { [string]: any }?) -> MaterialHandle
Build a material that PLAYS a layered texture: its layers bound as the
frames, its timing bound beside them, and the engine's animatedTexture
shader turning the clock into the layer showing now. One call from an
imported animated image to a material an entity can wear.
The layer showing is resolved per pixel against the texture's own schedule,
so frames of unequal length are shown for the lengths they were authored
with, and the sequence loops. speed scales the clock (2 plays twice as
fast, 0 holds the frame startTime lands in) and startTime offsets into
the sequence, so two surfaces sharing one texture can run out of phase.
The clock is the engine's, and it runs in edit mode as much as in play and
through a pause, so two screenshots of one surface taken moments apart are
two different frames of it. speed = 0 holds one frame for as long as it
is set, which is the state to compare two screenshots in.
The returned handle is what a surface wears — Model:applySessionMaterial
takes it, and so does a Model's material field. The handle's guid is
this material's REGISTRY KEY, the currency of setProperty, describe and
destroy; a component field resolves an asset, so a bare key in one leaves
the component waiting for an asset to register under that name.
The builtin plane mesh emits uv = (u, v) with v along its own +Z, so
a quad pitched +90° about X (Transform.eulerToQuat(0, math.pi / 2)) shows
the image upright to a camera on +Z, and -90° shows it first-row-last.
A texture whose layers carry no timing is rejected — there is nothing to
play. renderer.texture.info(bytes).animated is the test.
Parameters
texturestring | AssetRef— The texture — a guid, an identity, a name, a path, or a textureAssetRef.opts{ [string]: any }(optional) —{ key?, speed?, startTime?, alphaCutoff?, baseColor?, uvScale?, uvOffset? }.
Returns MaterialHandle
local mat = renderer.material.animatedTexture("banner.texture")
local id = entity.spawn("billboard", { rotation = { Transform.eulerToQuat(0, math.pi / 2) } })
entity(id).component.add("Model", { model = "plane" })
entity(id).component.get("Model"):applySessionMaterial(mat)
renderer.material.setProperty(mat.guid, "speed", 2)
typed/builtin//modules/api/engine/renderer/renderer/material/create
renderer.material.create(content: MaterialContent, key: string) -> MaterialHandle
Parameters
contentMaterialContentkeystring
Returns MaterialHandle
typed/builtin//modules/api/engine/renderer/renderer/material/describe
renderer.material.describe(key: string | { [string]: any } | AssetRef) -> any
The recoverable definition ({ shader, properties, textures, name, render, features, bindings })
this module registered under key via renderer.material.create, or nil
for keys registered elsewhere (e.g. material assets resolved by the
assetType). properties and textures carry the material's current values:
each setProperty / setTexture write lands on this record, a texture slot
under the GPU key the slot binds by — these are the WRITES, held here
whether or not the renderer took them up. renderer beside them is what the
renderer holds for the same key: the program its prepared bind group was
built against, the texture each slot of its row names (renderer.textures,
the writes the renderer took up), the render state its draws are looked up
under, whether a pipeline exists for that key, and the draws, instances
and binds the last published frame counted for it. A frame counts those
only while something observes the renderer (renderer.materialCost(),
renderer.observe() and renderer.drawDiagnostics() each keep it
observing for the next 120 drawn frames, and describe does not), so
renderer.observed states whether they were counted: true with the
counts, false with draws, instances, placeholderDraws, binds and
bindsElided all nil. renderer is nil when the renderer holds no
material under this key at all, and resident states the same fact as a
boolean. Writes reach the screen through both halves: resident = false
says the renderer holds nothing to put them in, and renderer.draws = 0
on a resident material says it holds them and no renderable is drawing
with it. For a material that is resident AND drawn and still looks wrong,
renderer.drawDiagnostics() names the renderable and the cause. A
material that is not resident carries shaderStatus and reason, where
its shader stands: "absent" when the shader it names resolves to no
shader asset (nothing will compile it, so it stays unprepared until one
arrives), "pending" while that shader has not compiled, "failed" with
the compiler's message, or "compiled" when the shader is ready and the
material has not been prepared yet. A resident material carries neither.
Parameters
keystring | { [string]: any } | AssetRef— The material's registry key, theMaterialHandlefromrenderer.material.create, or anAssetReffromasset.resolve.
Returns any — MaterialContent? with resident: boolean, renderer: MaterialObservation?, shaderStatus: string?, reason: string? and, for a key a .material asset filed, asset (the asset it is) fields
typed/builtin//modules/api/engine/renderer/renderer/material/destroy
renderer.material.destroy(key: string | { [string]: any } | AssetRef) -> boolean
Drop a runtime material registered via renderer.material.create: clears
its recoverable definition, unregisters its runtime-resource stamp so it is no
longer swept into the material freeze/save flow, and frees the GPU record. Use
for transient materials (e.g. a preview swatch) that must not outlive their use.
The on-disk asset, if any, is untouched, and the next handle() of a material
asset files its record again. Each texture the record's slots named is
released with it once nothing else names it, the one the device's cache
loaded for an asset included.
The reach is the registry: after this, describe and list stop answering
for the key. A surface already wearing the handle goes on drawing what it
was given — Model:restoreSessionMaterial is what puts a Model back on its
authored material.
Parameters
keystring | { [string]: any } | AssetRef— The material's registry key (the one passed tocreate), theMaterialHandlecreatereturned, or anAssetReffromasset.resolve.
Returns boolean true when a definition was known under key.
renderer.material.destroy("__preview_swatch_" .. texGuid)
typed/builtin//modules/api/engine/renderer/renderer/material/list
renderer.material.list() -> { any }
Every runtime material currently registered, ordered by registry key.
Each entry carries the key, where it came from, the shader it binds, and
for a key a .material asset filed (guid@checksum) the asset it is.
renderer.references("material", key) says what is still holding a row,
and renderer.collect() releases the rows nothing holds.
Returns { any } — Array of { guid, origin, owner?, shader?, asset? }.
for _, m in ipairs(renderer.material.list()) do print(m.asset or m.guid, m.shader) end
typed/builtin//modules/api/engine/renderer/renderer/material/renderState
renderer.material.renderState(key: string | { [string]: any } | AssetRef) -> MaterialObservation?
What the renderer holds for a material, which is a different document
from the values written to it. index is the material index its row in
the material table is filed under, which an edit rewrites in place, and
textures the texture each slot of that row names, by slot name, under the
key the texture is resident as; a slot drawing its shader's declared
default is absent, so a setTexture the renderer has taken up reads here
as the key it bound. shader is the program its prepared bind
group was built against, renderState the blend / cull / topology / queue /
depth key its draws are looked up under, keyBuilt whether a pipeline
exists for that key, and draws / instances / placeholderDraws /
binds / bindsElided what it cost in the frame the renderer last
published. A frame counts those only while something observes the
renderer, which renderer.materialCost() and renderer.drawDiagnostics()
start, so observed states whether they were counted: true with the
five counts, false with all five nil. nil means the renderer holds no material
under this key at all — the writes landed on a record nothing is drawing
with.
Parameters
keystring | { [string]: any } | AssetRef— The material's registry key, theMaterialHandlefromrenderer.material.create, or anAssetReffromasset.resolve.
Returns MaterialObservation?
local r = renderer.material.renderState("water"); print(r.renderState.blend, r.keyBuilt)
typed/builtin//modules/api/engine/renderer/renderer/material/sessionKeyFor
renderer.material.sessionKeyFor(entityId: string) -> string
The canonical registry key for an entity's SESSION material — the
runtime material a system (e.g. GI baking) shows on an entity in place
of its authored material for the lifetime of the engine session. One
session material per entity: create it under this key, hand the handle
to Model:applySessionMaterial, and the component re-adopts it across
VM reloads by probing this key with describe. The key names the entity
for as long as the entity stands: once it is gone the session store lets
the handle go, and a collection releases the material and whatever its
bindings were the last to hold.
Parameters
entityIdstring— The entity carrying the material.
Returns string — The registry key string.
local key = renderer.material.sessionKeyFor(entityId)
typed/builtin//modules/api/engine/renderer/renderer/material/setClock
renderer.material.setClock(key: string | { [string]: any } | AssetRef, seconds: number?, rate: number?) -> ()
Drive a material's surfaces from a clock of its own: the time its
shader's vertex(), vertex_clip() and fragment() read. The clock reads
seconds now and runs on by itself, rate of its seconds for every second
of the world's gameplay time, so it is stated again only when that changes —
a pause is a rate of 0, a seek is a new seconds, slow motion is a rate
below 1. Every surface drawing the material follows it, motion vectors
included. seconds = nil hands the material back to the world's time. A
procedural graph's Generator drives the materials it realizes from its
playhead this way, so an effect's shaders pause, slow and scrub with it.
Parameters
keystring | { [string]: any } | AssetRef— The material's registry key, theMaterialHandlefromrenderer.material.create, or anAssetReffromasset.resolve.secondsnumber(optional) — The time the material's surfaces read now, or nil to release it.ratenumber(optional) — Seconds of the clock per second of gameplay time (default 1).
Returns ()
renderer.material.setClock(asset.resolve("frost_ice", "material"), 12.5, 0)
typed/builtin//modules/api/engine/renderer/renderer/material/setProperty
renderer.material.setProperty(key: string | { [string]: any } | AssetRef, name: string, value: any?) -> ()
Push one changed uniform property to a registered material's GPU record
(frame-fast incremental update; no re-register). Keyed by the material's
registry key. The value written becomes the material's current one: it is
what describe reports, and — for a property the material's shader
declares, which is what the uniform buffer is packed by — what a material
AssetRef reads back through getProperty / getProperties and what the
surface is drawn with. A write under any other name reaches the record
describe reports, which is where it reads back.
Parameters
keystring | { [string]: any } | AssetRef— The material's registry key, theMaterialHandlefromrenderer.material.create, or anAssetReffromasset.resolve.namestring— Property name.valueany(optional) — New value.
Returns ()
renderer.material.setProperty(asset.resolve("wall", "material"), "roughness", 0.2)
typed/builtin//modules/api/engine/renderer/renderer/material/setTexture
renderer.material.setTexture(key: string | { [string]: any } | AssetRef, slot: string, ref: string | { [string]: any } | AssetRef) -> boolean
Push one changed texture slot to a registered material's GPU record. Keyed by the material's registry key. The slot is one the material's shader declares as a texture: a slot it does not declare is refused with a warning naming the texture slots it does declare, and the material is left as it was. While the shader's vocabulary has not been read (a custom shader that has not loaded) every slot is taken.
Parameters
keystring | { [string]: any } | AssetRef— The material's registry key, theMaterialHandlefromrenderer.material.create, or anAssetReffromasset.resolve.slotstring— Texture slot name ("base_color_texture", …).refstring | { [string]: any } | AssetRef— Texture reference — a.textureguid / identity / name / path, the image path it was imported from, acolor:/default:form, a live GPU handle, or a textureAssetRefcarrying one. An asset reference is materialised (Disk→CPU→GPU) and bound by the key the upload lands under.
Returns boolean — true when the slot was bound, false when the shader declares no texture slot under that name.
renderer.material.setTexture("sky", "sky_texture", "panorama.texture")
typed/builtin//modules/api/engine/renderer/renderer/material/vocabulary
renderer.material.vocabulary(key: string | { [string]: any } | AssetRef) -> MaterialVocabulary?
A material's property names under props and its shader-declared and
assigned texture slots under textureSlots, each a { [name] = true } set —
with byRole beside them, the index a key spelled in another engine's
convention resolves to a declared name through. This is what a write's key
is routed against on the record, in the shape MaterialSchema.route takes.
It is read off the definition this module holds and touches nothing the
renderer holds, so a call costs a table lookup and belongs on a per-frame
write path; describe is the read that carries the renderer's own state.
One frozen table per record, shared by every key that reaches it, rebuilt
on the first read after a write puts a new name on the record.
Parameters
keystring | { [string]: any } | AssetRef— The material's registry key, theMaterialHandlefromrenderer.material.create, or anAssetReffromasset.resolve.
Returns MaterialVocabulary? — nil for a key registered elsewhere, and for a record carrying no property, assigned texture, or declared texture slot.
local MaterialSchema = require("@builtin::modules.material_schema")
local route, name = MaterialSchema.route(assert(renderer.material.vocabulary(handle)), "color", { 1, 0, 0, 1 })
typed/builtin//modules/api/engine/renderer/renderer/materialCost
renderer.materialCost() -> { MaterialObservation }
What each material cost the frame the renderer last drew, and the state
it holds each one under. One row per material the renderer holds a prepared
bind group for — a material an author wrote and the renderer never prepared
is absent, which is itself the answer to "why is nothing I set reaching the
screen". draws and instances cover that one frame; placeholderDraws
is how many of those draws bound the magenta placeholder instead of this
material's own program. Those three count what this material drew itself:
a batch drawing several materials of one group adds to each material the
draws and instances that wore it.
group is the material group the material draws in — the unit a pass
binds a material's textures (group 1) and its shader's storage buffers
(group 2) by — or nil while the material resolves no group, which leaves
its draws nothing to bind. binds is how many group-1 and group-2 binds
the frame's passes issued for draws of this material's shader in that
group, and bindsElided how many times such a draw found the group already
bound, which is what draw-key sorting buys. Those binds belong to the
group, so every material of one group reports the same pair; a material
with no group reports 0 for both, and a draw that fell back to the
placeholder counts in placeholderDraws and in neither bind count.
uniformBytes is the size of the property block in the material's row of
the material table: the shader's declared properties, packed at the offsets
the shader reads them from and padded to a whole 16 bytes. The row also
carries a 64-byte header and a 4-byte handle per texture slot, padded to a
whole 16 bytes. renderer.materialTable().rowBytes is the space the table
reserves for all rows — its row capacity, free rows included — plus its
directories. renderer.drawDiagnostics() names WHICH
renderable is not drawing what its material says, and why.
material is the key the renderer holds the material under; asset
names the .material asset a guid@checksum key is a version of.
Returns { MaterialObservation }
for _, m in renderer.materialCost() do print(m.asset or m.material, m.draws, m.binds, m.bindsElided) end
typed/builtin//modules/api/engine/renderer/renderer/materialIdentity
renderer.materialIdentity() -> MaterialIdentity
Which material each renderable draws with, as a number a shader can
carry. A material is authored and bound by name, and no shader can read a
string — so every renderable's per-instance record holds a material index
instead. slots is the name → index table those indices are drawn from: an
index is assigned the first time the renderer draws with that material and
does not move while the renderer holds the material, so two renderables that
differ only in material read different indices, and one renderable reads the
same index frame after frame. A destroyed material's name leaves the table
once nothing draws with it, and the next material takes its index, so the
table holds a row per name the renderer holds a material under or
something draws with. renderables is
a row per renderable that owns a GPU slot — the entity it belongs to, that
slot, and the index the record at it carries; populations is the same for
an instanced draw, whose whole reserved run of slots carries the one
material its registration named. That index is what a shader reads as
zero_instance(slot).material_index, and the row a ray hit resolves
through zeroMaterial(). A renderable draws with the material its entity
references, so one whose entity names none carries index 0.
Returns MaterialIdentity — { slots: { [string]: number }, renderables: { { entity: string, slot: number, index: number, material: string } }, populations: { { slot: number, count: number, index: number, material: string } } }
local id = renderer.materialIdentity()
for _, r in id.renderables do print(r.entity, r.slot, r.index, r.material) end
typed/builtin//modules/api/engine/renderer/renderer/materialIndex
renderer.materialIndex(name: string) -> number?
The index standing for a material, or nil for a name the renderer
holds no index for: one it has not drawn with yet, or a destroyed material
nothing draws with any more. Pass it to a shader (or compare it against what a shader
read out of zero_instance(slot).material_index) to tell which material a
drawing instance carries.
Parameters
namestring—stringMaterial name, asrenderer.material.createfiled it.
Returns number?
local red = renderer.materialIndex("brick_red")
typed/builtin//modules/api/engine/renderer/renderer/materialTable
renderer.materialTable() -> MaterialTable
How this device resolves material textures, and what that storage
costs. backend is "bindless" (a descriptor array indexed by each
material's texture handles) or "buckets" (exact-size texture arrays, one
per size, format and mip count, bound per material group). Bindless is
taken on a Vulkan adapter that has texture binding arrays with non-uniform
indexing and partially bound arrays, and room for descriptor arrays of at
least 4096 textures; every other device — the browser build, Android,
Metal, DirectX 12, and Vulkan without those — takes buckets.
materials is how many materials have a row, rowBytes the space the
table reserves in the scene buffer (its row capacity, free rows included,
plus the material and texture directories), textures how many distinct
textures the rows name, descriptorCapacity the length of each bindless
array (0 on buckets), and groups how many material groups the materials
form. A group is the unit a pass binds a material's textures (group 1) and
a shader's own storage buffers (group 2) by, and every material of a group
draws under the same binds. On bindless every group binds the one texture
group of the frame, so groups differ only by the set of storage buffers
they bind. On buckets a group also names, per texture slot, the bucket its
members' textures live in and the sampler those textures sample through:
materials of one shader split into one group per distinct combination of
(bucket and sampler per texture slot, storage buffers), and each group is
its own draw.
buckets lists every texture array: its format, size, mip count, the
layers textures occupy, its capacity, what it costs, the slack it holds
beyond its live layers, whether it is frozen (a layer's view is held by
something outside the material system — a UI image, a post-process input
— or a copy out of a layer is taken this frame, such as a readback, so the
array neither grows nor compacts), which shard of its
key it is, and whether it is external (a one-layer bucket over a texture
the GPU writes — a render target, a video frame, a compute output — which
its producer owns). bucketBytes is what the shared buckets occupy
together, and bucketSlackBytes the slack they hold together, which
renderer.setTextureBucketSlack bounds; an external bucket counts in
neither. slackBudgetBytes is the budget the buckets bound growth by. On
bindless buckets is empty, both totals are 0, and slackBudgetBytes is
the budget recorded, which bounds nothing.
Returns MaterialTable
local t = renderer.materialTable(); print(t.backend, t.groups, "groups over", t.materials, "materials")
for _, b in renderer.materialTable().buckets do print(b.format, b.width, b.height, b.layers, "/", b.capacity) end
typed/builtin//modules/api/engine/renderer/renderer/maxAnisotropy
renderer.maxAnisotropy() -> number
The highest anisotropy this device honours: 16 on hardware that filters
anisotropically, 1 on hardware that does not, where a higher request would
be downgraded to trilinear regardless. Read it to report quality honestly —
renderer.setAnisotropy clamps for you, so a request never needs guarding.
Returns number — The device ceiling, 1 or 16.
local best = renderer.maxAnisotropy()
typed/builtin//modules/api/engine/renderer/renderer/maxViewportExtent
renderer.maxViewportExtent() -> number
The largest number of pixels this device draws a surface at, per axis
— the bound renderer.setViewportSize refuses past. 0 before the first
frame has drawn.
Returns number — pixels per axis.
local bound = renderer.maxViewportExtent()
typed/builtin//modules/api/engine/renderer/renderer/memoryPressure
renderer.memoryPressure() -> MemoryPressureReport
What memory pressure is doing to the engine. level is the level in
force: "normal", "moderate", "low" or "critical". A report puts
its level in force, whatever stood before, for holdSeconds after the
last report, and then the level returns to normal. Reports come from the
system (on Android, onTrimMemory: RUNNING_MODERATE is moderate,
RUNNING_LOW and UI_HIDDEN low, RUNNING_CRITICAL, BACKGROUND, MODERATE and
COMPLETE critical; Android 14 and later report only UI_HIDDEN, when the
app leaves the screen, and BACKGROUND) and from
renderer.signalMemoryPressure. On a desktop the memory bound the
engine's process tree runs under is a source too: bound states what the
engine and its sub-clients hold of it, and from 80% of it held the level
stands at moderate, from 90% at low and from 95% at critical for as long
as the tree holds that share, whatever the reports say. signals
counts the reports taken; lastLevel, lastSource and lastAgeSeconds
describe the newest (absent before the first).
Each report releases at once what its level releases, and released says
what the newest one freed: the textures taken to the level the frame
samples and the textureBytes they gave up, and the render targets
whose storage was freed. Moderate frees the mip levels the frame does not
sample; low also frees render-target storage the last frame did not draw
into; critical also halves the texture budget. While a level stands the
residency plan keeps the textures there, and textureBudgetBytes is the
budget the level leaves in force. engine.onMemoryPressure(cb) fires with
each report once its release is done.
Returns MemoryPressureReport — { level, holdSeconds, signals, lastLevel?, lastSource?, lastAgeSeconds?, textureBudgetBytes, released, bound? }
local mp = renderer.memoryPressure()
print(mp.level, mp.released.textureBytes / 1048576, "MiB freed")
typed/builtin//modules/api/engine/renderer/renderer/mesh/bounds
renderer.mesh.bounds(mesh: string | { [string]: any } | AssetRef) -> Aabb?
The mesh's extent in its own space: the box its vertices span, or the
one its author stated (aabbMin / aabbMax) for a mesh whose vertices live
only on the GPU. It is what the mesh is culled against and what framing
reads; place it in the world through whatever draws the mesh — an entity's
transform, or instanceBounds for an instanced population. A mesh asset
nothing has drawn yet answers the box of its stored geometry: read from its
CPU copy when one is resident, else from its stored bytes, which are read
for the call and released again, so the mesh is left as resident as it was.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns Aabb? — The box, or nil for a mesh no registered mesh and no mesh asset answers to, or whose extent nobody knows.
local box = renderer.mesh.bounds(asset.resolve("@builtin::meshes.torus", "mesh"))
typed/builtin//modules/api/engine/renderer/renderer/mesh/boundsSource
renderer.mesh.boundsSource(mesh: string | { [string]: any } | AssetRef) -> string
Where this mesh's culling bounds come from. "compute" once a compute
pass has written its vertices: the engine reduces those vertices to an AABB
every frame, so the mesh is culled against the geometry the pass produced
wherever it puts it. "geometry" otherwise: the AABB of the geometry the
mesh was created with.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns string — "compute" or "geometry".
print(renderer.mesh.boundsSource(mesh))
typed/builtin//modules/api/engine/renderer/renderer/mesh/buildClusters
renderer.mesh.buildClusters(mesh: string | { [string]: any } | AssetRef) -> string?
Build a cluster-LOD DAG (Nanite-style virtualized geometry) for the
static CPU mesh held under guid and return its serialized data.clusters
bytes. Returns nil when the mesh is degenerate, and on an engine whose
renderer.mesh.canBuildClusters reports false. Pair with
renderer.mesh.uploadClusters.
Parameters
meshstring | { [string]: any } | AssetRef— A mesh loaded into the CPU store (renderer.mesh.loadCpu) — theMeshCpuHandle, aMeshHandle, a guid, or a meshAssetRef.
Returns string? — Serialized cluster bytes, or nil.
local cb = renderer.mesh.buildClusters(cpu)
typed/builtin//modules/api/engine/renderer/renderer/mesh/canBuildClusters
renderer.mesh.canBuildClusters() -> boolean
Whether this engine bakes cluster-LOD hierarchies. It reads the binding
the running engine registered: every target the engine ships on carries the
builder, so a mesh loaded in a browser bakes its own clusters the same way
one loaded natively does, and an engine built without it reports false and
answers nil from renderer.mesh.buildClusters.
Returns boolean — True if renderer.mesh.buildClusters can bake on this platform.
if renderer.mesh.canBuildClusters() then ... end
typed/builtin//modules/api/engine/renderer/renderer/mesh/clusterBakeBudget
renderer.mesh.clusterBakeBudget(ms: number?) -> number
The wall time one frame may spend advancing scheduled cluster bakes, in
milliseconds — set first when ms is given. A slice always runs at least
one unit of the build, so the budget bounds what a frame spends by choice
and the largest single unit a mesh imposes sets the floor under it.
Parameters
msnumber(optional) — New per-frame budget in milliseconds, capped at 1000. A value that is not a positive, finite number raises.
Returns number — The budget in force after the call.
renderer.mesh.clusterBakeBudget(2)
typed/builtin//modules/api/engine/renderer/renderer/mesh/clusterBakes
renderer.mesh.clusterBakes() -> { [string]: any }
What the scheduled cluster bakes are costing. budgetMs is the slice a
frame may spend, pending how many bakes are queued, completed how many
have finished since the engine started, dropped how many left the queue
because the geometry they were scheduled over stopped being readable or
cannot be drawn as clusters, and
heldBytes the source geometry the queue is holding across all of them —
the vertex pool and index run the bake at the head is reading.
inFlight is one row per queued bake —
{ guid, cpuMs, frames, slices, bytes, state, levels }: the wall time
spent advancing it, the frames it has been queued for, the slices it has
been advanced by, the geometry it is holding, "baking" for the one being
advanced against "queued" for the ones waiting their turn, and levels
the depth the bake builds, "dag" or "single".
Returns { [string]: any } — { budgetMs, pending, completed, dropped, heldBytes, inFlight }.
print(renderer.mesh.clusterBakes().heldBytes)
typed/builtin//modules/api/engine/renderer/renderer/mesh/clusterComponents
renderer.mesh.clusterComponents(clusterBytes: buffer | string) -> (ClusterComponents?, string?)
Split a cluster blob (from renderer.mesh.buildClusters) into its
GPU-ready component byte pools — the cluster vertex pool, the
geometry-addressing pool (every cluster's local→global vertex map, then
every cluster's triangle bytes), and the per-cluster record array — plus
their counts. A cluster's triangles address positions inside its own vertex
map one byte at a time, and a record's vertexOffset indexes the geometry
pool in u32 elements while its indexOffset indexes it in bytes, so ONE
binding resolves a corner. A pure decode (no GPU work): upload the pools
into buffers a compute shader owns (shaderRef:createBuffer +
buf:writeBytes) to drive a cluster draw from Luau.
Parameters
clusterBytesbuffer | string— Serialized cluster bytes (binary-safe).
Returns (ClusterComponents?, string?) — { vertices, geometry, records, vertexCount, vertexRefCount, triangleBytes, indexCount, clusterCount }, or (nil, err).
local c = renderer.mesh.clusterComponents(cb)
typed/builtin//modules/api/engine/renderer/renderer/mesh/clusterStore
renderer.mesh.clusterStore() -> {
What the geometry heap holds for cluster drawing. heapCapacity and
heapLive are the heap's size and the bytes in use. The heap grows to
place what does not fit, and gives memory back as meshes leave it: once
what it holds has packed into a quarter of its size for 60 frames in a
row, it shrinks to double that, never below the size it started at. A
mesh destroyed and created again inside those frames finds the heap at
the size it left it. vertexBytes and
lightmapBytes are the vertex pools and lightmap-UV runs of the meshes
drawn through clusters. bakedBytes is the cluster sets of meshes drawing a
baked set; unbakedBytes is the sets of meshes still drawing lod0 plus
those meshes' vertex pools — geometry drawn at full detail while its bake is
outstanding. meshes counts meshes drawing any set, unbakedMeshes those
on lod0. scriptSetBytes is CPU memory beside the heap: the sets
scripts installed with renderer.mesh.uploadClusters, held so each mesh
draws its set again after it returns to the device.
Returns { heapCapacity: number, heapLive: number, vertexBytes: number, lightmapBytes: number, bakedBytes: number, unbakedBytes: number, meshes: number, unbakedMeshes: number, scriptSetBytes: number }
local s = renderer.mesh.clusterStore(); print(s.unbakedBytes / 1048576, "MiB drawn at full detail while bakes are outstanding")
typed/builtin//modules/api/engine/renderer/renderer/mesh/clusters
renderer.mesh.clusters(mesh: string | { [string]: any } | AssetRef) -> { [string]: any }?
The cluster set a mesh draws. Every static mesh the geometry heap holds
draws through clusters: kind is "lod0" while it draws the full-detail
set built from its geometry as it uploaded, "single" for one baked level
(clusterLod = false), and "dag" for the baked LOD hierarchy.
clusterCount, levelCount and triangleCount describe that set, nodes
how many node transforms its clusters lie in, and bytes its size in the
heap. A mesh that is not drawn through clusters reads resident = false
with reason: "heapFull" (the heap cannot grow to hold it),
"spansNodes" (a triangle joins two independently moving parts) or
"deformable" (a pass deforms its vertices). Nil for a mesh the renderer
holds no GPU geometry for.
bake is the state of the bake queued for the mesh, "queued" or
"baking" as renderer.mesh.clusterBakes().inFlight reports it, with
bakeLevels the depth it builds; both are nil when no bake is queued.
status reads the two together: "queued" or "baking" while a bake is
in flight; otherwise "adaptive" for a dag set, "singleLevel" for a
single set, "unbaked" for a mesh drawing lod0 with no bake queued
(nothing asked for its hierarchy, or its bake left the queue without
installing one), and "excluded" for a mesh kept out of cluster drawing,
whose reason says why.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh to read — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns { [string]: any }? — { resident: boolean, reason: string?, kind: string?, clusterCount: number, levelCount: number, triangleCount: number, nodes: number, bytes: number, bake: string?, bakeLevels: string?, status: string }?
local c = renderer.mesh.clusters(gpu) ; if c then print(c.status, c.kind, c.bake) end
typed/builtin//modules/api/engine/renderer/renderer/mesh/create
renderer.mesh.create(src: any?, guid: string?) -> MeshHandle
Create (or fetch) a GPU mesh resource and return its MeshHandle. src:
a MeshCpuHandle from meshRef:load() (CPU→GPU upload under the asset's
guid, idempotent — returns the resident handle if already uploaded); raw
geometry {positions, indices, normals?, uvs?, colors?, uvs1?, unwrapUvs?, tangents?, skinning?, skins?} (a new runtime mesh — uvs1 is the lightmap
UV set, unwrapUvs generates one, skinning/skins bind a skeleton);
engine-native ZMSH bytes { zmsh, name?, keepCpu? } (a new runtime mesh
the engine decodes and uploads itself, every stream the bytes carry
included, with no geometry crossing into Luau — the bytes
renderer.mesh.encode and renderer.mesh.encodeCpu answer); GPU
compute buffers {vertexBuffer, indexBuffer, vertexCount, indexCount, aabbMin?, aabbMax?, prevVertexBuffer?} (size the vertex buffer at
vertexCount * engine.vertexStride bytes, the engine's standard Vertex
layout); or a MeshHandle (returned as-is). NEVER takes an AssetRef —
load the CPU first.
prevVertexBuffer is a second buffer of the same size and layout holding
those vertices as they stood on the previous frame. Naming it is what makes
geometry a compute pass moves report a motion vector: the surface
differences the two streams, so every consumer of screen-space velocity —
motion blur, temporal reprojection — sees the movement. Ahead of each
frame's compute dispatches the engine makes it equal to the current
vertices, copying them on a frame after something wrote them, so a frame
in which the pass does not run leaves the two streams equal and the
geometry reports standing still.
morphTargets are the shapes the mesh can blend towards: a list of
{ name?, positions, normals? } records, each holding one offset per vertex
from the base geometry, in the mesh's own vertex order. An entity blends
them with ecs.MorphWeights, weight i scaling target i. A name makes
the shape addressable as itself — renderer.mesh.morphTargets reads the
names back and renderer.mesh.morphWeights drives them by name.
Raw geometry is read against the mesh type's conventions: indices count
vertices from 0, and a triangle's FRONT face is the one whose vertices turn
counter-clockwise as the viewer sees them — cross(v1 - v0, v2 - v0) points
out of it. A material culls its back faces by default, so a triangle wound
the other way draws nothing where it stands; reverse the index triple, or
give the material render = { cull = "none" }, to draw that side. normals
give the surface its outward direction and shade the face; the side that
draws comes from the index order alone. uvs sample (0,0) at the image's
top-left. Model space carries the world's basis: +X right, +Y up, -Z the
direction transform.forward points. guides { path = "types/mesh" } has
the whole table.
A geometry src carrying keepCpu = true also keeps its geometry in the
guid-keyed CPU store, so renderer.mesh.getVertices reads it and
renderer.mesh.setVertices rewrites its positions in place — the per-frame
deformation path, which sends positions alone where renderer.mesh.update
re-sends the whole geometry. renderer.mesh.unloadCpu(mesh) releases that
copy. Without it the geometry lives on the GPU alone and
renderer.mesh.readback(mesh) is what brings it back.
A mesh this call builds lives while the returned handle, or another
handle over the same guid, is reachable from a script, or while something
else holds it (an entity or instanced draw displaying it, its owner, a
renderer.hold). The owner is the component instance or scene load the
create ran in; a mesh a component's task built stops being its owner's
once that task is cancelled. Once nothing holds it and the garbage collector has
taken its last handle, the engine releases it mid-session: its definition,
its buffers and its renderer.mesh.list row go, and its guid names
nothing. A script that displays a mesh again later keeps its handle (or
holds it) for as long as it means to.
A handle a script keeps names its mesh for the rest of the session: a
module table or _SCRATCH holding it carries it across play/edit flips,
scene loads and hot reloads of the components that use it, and a Model
handed it after any of them draws the mesh. While nothing displays the
mesh, the engine holds it off the device (renderer.mesh.heldOffDevice)
and the next display puts it back. Only a destroy ends a mesh a handle
still reaches (renderer.destroy, renderer.mesh.destroy): every handle
a create returned over it then carries released, the verb that released
it, and a point of use (ecs.Mesh, a Model's model field) refuses
such a handle by name until a mesh stands under its guid again, which the
handle then names and holds.
Static geometry draws through an adaptive cluster set by default. The
call that uploads a mesh asks for its cluster bake, which runs off the
frame over the geometry the engine holds, so no CPU copy is needed: the
LOD hierarchy, or one level of clusters when clusterLod is false — the
asset's setting for a MeshCpuHandle (meshRef:load(), whose copy may be
unloaded on the next line), and the src's own clusterLod field for
geometry and zmsh bytes. Geometry carrying keepCpu, morphTargets,
skinning or skins draws the full-detail set it uploaded with. The mesh
draws lod0 until the bake lands, and renderer.mesh.clusters(mesh).status
reads "queued" or "baking" meanwhile. A set asked for the mesh
earlier (renderer.mesh.scheduleClusters, renderer.mesh.uploadClusters,
or lod0 through renderer.mesh.dropClusters) is the one it draws again
when this call uploads it anew. Creating a mesh again while it is on the
device returns the resident mesh and leaves its set and any bake in flight
as they are.
Parameters
srcany(optional) — A MeshCpuHandle, geometry, compute buffers, or a MeshHandle.guidstring(optional) — Optional v4 guid for a NEW runtime mesh (minted Luau-side when absent). Ignored for the CPU-handle path (the asset's guid is used).
Returns MeshHandle
local gpu = renderer.mesh.create(meshRef:load())
local gpu = renderer.mesh.create({ positions = {...}, indices = {...} })
-- a runtime mesh whose positions are rewritten in place each frame
local m = renderer.mesh.create({ positions = P, indices = I, keepCpu = true })
renderer.mesh.setVertices(m, P)
-- a runtime mesh carrying a lightmap UV set (unwrapped at creation)
local gpu = renderer.mesh.create({ positions = {...}, indices = {...}, unwrapUvs = true })
-- a mesh with one shape to blend towards, driven by ecs.MorphWeights
local gpu = renderer.mesh.create({ positions = P, indices = I, morphTargets = { { positions = D } } })
typed/builtin//modules/api/engine/renderer/renderer/mesh/decode
renderer.mesh.decode(zmsh: buffer | string) -> (MeshGeometry?, string?)
Decode engine-native ZMSH bytes back into a MeshGeometry. Inverse of
renderer.mesh.encode; each optional stream is present only when the blob
carries it. Takes the bytes themselves — the geometry of a mesh the engine
is holding comes from renderer.mesh.geometry(mesh).
Parameters
zmshbuffer | string— Engine-native ZMSH bytes (binary-safe).
Returns (MeshGeometry?, string?) the geometry, or (nil, errmsg).
local geom = renderer.mesh.decode(meshRef:getBytes())
typed/builtin//modules/api/engine/renderer/renderer/mesh/destroy
renderer.mesh.destroy(mesh: string | { [string]: any } | AssetRef) -> boolean
Release the GPU mesh mesh names, the release that pairs with
renderer.mesh.create. Takes every form that names a mesh — the
MeshHandle create returned, the guid renderer.mesh.list hands out, a
MeshCpuHandle or a mesh AssetRef — and routes through
renderer.destroy, the verb that releases any renderer resource by its
kind. The CPU copy, if one was loaded, is freed separately by the CPU
handle's :unload().
Parameters
meshstring | { [string]: any } | AssetRef— The mesh to release — aMeshHandle, a guid, aMeshCpuHandleor a meshAssetRef.
Returns boolean true if a GPU mesh was known under the guid.
local m = renderer.mesh.create(cpu); renderer.mesh.destroy(m)
renderer.mesh.destroy(renderer.mesh.list()[1].guid)
typed/builtin//modules/api/engine/renderer/renderer/mesh/drawInstanced
renderer.mesh.drawInstanced(mesh: string | { [string]: any } | AssetRef, opts: any?) -> InstancedDraw
Draw one mesh instanceCount times in a single call, each copy placed by
a world matrix read from a GPU buffer. The population is a renderable in its
own right — it goes through the mesh's ordinary pipeline and the material's
ordinary bind groups, so it appears in the deferred pass, the forward passes
and the shadow maps exactly as an entity-backed draw of that mesh does.
The buffer holds instanceCount column-major 4x4 matrices, 64 bytes
each, tightly packed — the layout a vertex shader reads as
array<mat4x4<f32>>, which puts each matrix's translation in its LAST four
floats (Lua indices 13/14/15 for x/y/z). Packing row-major transposes every
instance.
The matrices are COPIED into the engine's transform slots, which is what
buys that full-pass parity. Rewrite the buffer between frames and the
instances move, with no re-registration and no re-upload. The copy is
made on the frames that follow a write of the buffer (a :write, a compute
pass whose shader binds it read_write, and every frame a material whose
shader binds it read_write is live), so a population whose buffer
nothing writes costs no copy per frame however many instances it holds;
renderer.uploadStats() counts the copies a frame made.
material is what the population draws with, and it is required: a
MaterialHandle (matRef:handle()), an AssetRef, or a registry key.
instanceDataBuffer names a second buffer, holding 64 bytes per instance —
four vec4 lanes, tightly packed, in instance order. Those lanes arrive in
the fragment stage as zero_object_data(in.instance_id, lane), the same
read a per-entity __instancedata block answers, so the members of one
population can differ in whatever their material's shader agrees the lanes
carry. Copied like the transforms, on the frames that follow a write of
the buffer, from a buffer a compute pass writes: the values never touch the
CPU. Omit it and the lanes read zero.
The material's vertex() hook reads the lanes too, as
zero_object_data(v.instance_id, lane), beside v.vertex_index, the
index of the vertex in the mesh: a hook can build each copy's shape from
them, which is how a field of grass blades, kelp, hair cards or debris is
one strip mesh and one call, lit and shadowed like the rest of the scene
(guides { path = "topics/rendering-instance-data" }).
@builtin::materials.instance_color (and instance_color_unlit) colour
each copy from lane 2 of its block, (r, g, b, coverage), given as its
AssetRef: material = asset.resolve("@builtin::materials.instance_color", "material").
reserveCount sizes the reservation above instanceCount so
renderer.mesh.setInstanceCount can raise the drawn count later without
re-registering; both buffers must back the reservation, not just the count.
traced states whether the copies stand in the ray-traced scene, the
geometry probe GI, ray-traced shadows and every other pass that traces rays
hit: a traced copy bounces light, blocks it and is lit by it, and an
untraced one is invisible to all of them. It is true when left out for a
population that casts shadows and false for one that does not, so copies
that cast nothing stay out of the traced scene. The copies are placed from
the matrices the CPU wrote into the transform buffer (buf:write,
buf:writeBytes); a population whose matrices only a compute pass writes
cannot be placed, and renderer.mesh.instanceInfo reports its traced as
"noCpuTransforms". renderer.mesh.setInstanceTraced changes it later.
mobility states whether the copies stand still — "static", or
"movable" when it is left out. It is what a scene gather collecting
geometry for precomputed lighting admits a population on, the same
declaration Model.mobility makes for an entity: the transforms live in a
buffer anything may rewrite between frames, so a population that says
nothing is taken as one that moves.
Every copy draws the mesh's cluster LOD, cut from that copy's own
distance, so a population needs no near/mid/far meshes to thin out with
range. renderer.mesh.clusters(mesh).kind reads "dag" while the mesh
draws its LOD hierarchy and "lod0" while it draws full detail at every
distance; renderer.mesh.scheduleClusters bakes the hierarchy, and
guides { path = "topics/world-detail" } covers which meshes need it.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh the population draws — aMeshHandle, the guidrenderer.mesh.listhands out, aMeshCpuHandleor a meshAssetRef. A registration holds the mesh on the device for as long as it lives, and takes a mesh that is currently held off the device — one nothing displays — back onto it.optsany(optional) —{ transformBuffer, instanceCount, material, instanceDataBuffer?, reserveCount?, renderLayer?, castsShadows?, receivesShadows?, traced?, mobility?, parent? }.castsShadowsandreceivesShadows, both true when left out, state whether the copies cast shadows and whether shadows darken them.tracedstates whether the copies stand in the ray-traced scene; it takes the value ofcastsShadowswhen left out.parentstands the copies in an entity's space, assetInstanceParentdoes.
Returns InstancedDraw — An InstancedDraw handle for instanceInfo / setInstanceCount / dropInstanced.
local m = renderer.mesh.create({ positions = ..., indices = ... })
local buf = substrate.createBuffer({
name = "crowd.xf", type = "mat4", len = 64, kind = "gpu",
})
-- Column-major: translation lives at indices 13/14/15.
local xf = {}
for i = 0, 63 do
local m4 = { 1,0,0,0, 0,1,0,0, 0,0,1,0, i * 2, 0, 0, 1 }
for _, v in ipairs(m4) do xf[#xf + 1] = v end
end
buf:write(xf)
local rock = asset.resolve("rock", "material"):handle()
local draw = renderer.mesh.drawInstanced(m, { transformBuffer = "crowd.xf", instanceCount = 64, material = rock })
typed/builtin//modules/api/engine/renderer/renderer/mesh/dropClusters
renderer.mesh.dropClusters(mesh: string | { [string]: any } | AssetRef) -> boolean
Return a mesh to its lod0 set and cancel a bake still in flight for
it. lod0 stays the set the mesh draws: it draws it again when it
returns to the device and when renderer.mesh.create uploads it again,
until renderer.mesh.scheduleClusters or renderer.mesh.uploadClusters
asks for another. The inverse of renderer.mesh.uploadClusters.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh to return — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns boolean — True if the mesh drew a baked set or a bake was in flight.
renderer.mesh.dropClusters(gpu)
typed/builtin//modules/api/engine/renderer/renderer/mesh/dropInstanced
renderer.mesh.dropInstanced(draw: InstancedDraw) -> boolean
Release an instanced-draw registration and the transform slots it
reserved. The mesh and the transform buffer outlive it — destroy those
through renderer.destroy and the buffer handle's :destroy().
Parameters
drawInstancedDraw— TheInstancedDrawto release.
Returns boolean — True if a registration was live under the handle.
renderer.mesh.dropInstanced(draw)
typed/builtin//modules/api/engine/renderer/renderer/mesh/encode
renderer.mesh.encode(geom: MeshGeometry) -> (string?, string?)
Encode raw geometry into engine-native ZMSH bytes (the on-disk mesh
payload). The CPU codec behind the mesh assetType's onCreate. Every stream
the format carries — including tangents, per-vertex skinning, and the
skeleton — round-trips back through renderer.mesh.decode. This pair moves
DATA the caller is holding; the geometry of a mesh the ENGINE is holding
comes from renderer.mesh.geometry(mesh).
Parameters
geomMeshGeometry—MeshGeometry— flat per-vertex float / u32 arrays plus optionalskinningandskins.
Returns (string?, string?) engine-native ZMSH bytes (binary-safe), or (nil, errmsg) naming what the geometry could not describe.
local bytes = renderer.mesh.encode({ positions = {...}, indices = {...} })
local bytes = renderer.mesh.encode(renderer.mesh.geometry(meshHandle))
typed/builtin//modules/api/engine/renderer/renderer/mesh/encodeCpu
renderer.mesh.encodeCpu(mesh: string | { [string]: any } | AssetRef) -> string
Encode a mesh's resident CPU copy into ZMSH bytes. Reads the ONE
guid-keyed CPU store — meshRef:load() populates it for assets, and
renderer.mesh.readback(mesh) populates it for a runtime mesh. Errors
loudly when the mesh has no resident CPU copy.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns string ZMSH bytes.
local bytes = renderer.mesh.encodeCpu(handle)
typed/builtin//modules/api/engine/renderer/renderer/mesh/geometry
renderer.mesh.geometry(mesh: string | { [string]: any } | AssetRef) -> MeshGeometry
The complete geometry of a mesh the engine is holding, as a
MeshGeometry — the same shape renderer.mesh.create and
renderer.mesh.encode take, carrying every stream the mesh has
(positions, indices, and whichever of normals, uvs, colors,
uvs1, tangents, skinning, skins it was built with). The read that
pairs with create: hand it the MeshHandle create returned and get the
vertex data back. Reads the resident CPU copy when there is one; for a
runtime mesh that lives only on the GPU it reads the geometry back off the
GPU first (yielding a frame or two) and leaves CPU residency as it found it.
An optional stream is present only when the mesh carries one, so uvs1 == nil is the answer to whether it has a second UV set. The drawable mesh
the renderer holds carries the tangent basis its positions, uvs and normals
determine — supplied by the caller, or derived at the ingest that made it
drawable — and that is what the GPU read gives back. The CPU store answers
with the streams the bytes it decoded hold, so a .mesh written without a
tangent stream reads back tangents == nil for as long as a CPU copy of it
is resident.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns MeshGeometry
local geom = renderer.mesh.geometry(renderer.mesh.create({ positions = P, indices = I }))
local tangents = renderer.mesh.geometry(handle).tangents
typed/builtin//modules/api/engine/renderer/renderer/mesh/getVertices
renderer.mesh.getVertices(mesh: string | { [string]: any } | AssetRef) -> { any }
Read the vertices of a mesh's resident CPU copy — one entry per vertex,
{ pos = {x,y,z}, normal = {x,y,z}, uv = {u,v} }. Reads the resident CPU
store directly (no re-decode). Errors when the mesh has no resident CPU copy
— renderer.mesh.geometry(mesh) is the read that works wherever the mesh
lives, and returns the tangent, colour and skinning streams too.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns { any } — { { pos: {x,y,z}, normal: {x,y,z}, uv: {u,v} }, ... } Each record carries pos, normal, uv and uv1 as named channels ({ x = , y = , z = }). Geometry going the other way — into renderer.mesh.create — is parallel flat arrays (positions, normals, uvs), and create accepts this record list under vertices so a mesh read back here can go straight into a new one.
typed/builtin//modules/api/engine/renderer/renderer/mesh/heldOffDevice
renderer.mesh.heldOffDevice(mesh: string | { [string]: any } | AssetRef) -> boolean
True while the engine holds this mesh off the device: nothing displays
it, so its GPU buffers were given back and the engine keeps what rebuilds
them. The next Model or instanced draw that names the mesh puts it back
on the device, where renderer.mesh.isResident reads true again from the
frame that bind lands in. A mesh is one of three things: resident, held off
the device, or gone; a mesh neither this nor isResident answers true for
names nothing the engine can draw.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh: aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns boolean
local named = renderer.mesh.isResident(h) or renderer.mesh.heldOffDevice(h)
typed/builtin//modules/api/engine/renderer/renderer/mesh/instanceBounds
renderer.mesh.instanceBounds(draw: InstancedDraw, opts: { keep: number? }?) -> (Aabb?, string?)
The world box a registration's drawn copies occupy: every copy of the
mesh's extent (renderer.mesh.bounds) where the engine composed it for the
last frame drawn, carried through the entity the copies stand in when
setInstanceParent named one. It reads the copies back from the GPU, so it
waits a few drawn frames. A copy scaled to nothing draws nothing and is
left out. A mesh whose extent nobody knows answers with the box around the
copies' origins, and says so.
Parameters
drawInstancedDraw— TheInstancedDrawto measure.opts{ keep: number? }(optional) —{ keep? }— the share of the copies the box holds along each axis (default 1, all of them). Below 1, the copies reaching furthest out on each side are left out:keep = 0.9is the box around where the body of a spray stands, without the few copies thrown far from it.
Returns (Aabb?, string?) — The box, or nil and the reason there is none; a box around origins alone comes with the note that says so.
local box, note = renderer.mesh.instanceBounds(draw)
local body = renderer.mesh.instanceBounds(draw, { keep = 0.9 })
typed/builtin//modules/api/engine/renderer/renderer/mesh/instanceInfo
renderer.mesh.instanceInfo(draw: InstancedDraw) -> InstancedDrawInfo?
What a live instanced-draw registration is drawing: which mesh, which transform buffer, which per-instance data buffer if it named one, how many instances, and how many slots it reserved. Returns nil once the registration has been dropped.
status is what the renderer did with it. The fields above it are the
request, made a stage before the renderer sees it; status is the answer:
"drawing" for a registration the renderer is drawing, "hidden" for one
it holds but does not draw while its parent entity, or an ancestor of it, is
deactivated or gone, "refused" for one it turned away — error carries
its reason — and "pending" for the frame between the call and the renderer
answering. So a registration whose copies are not being drawn says so here.
Parameters
drawInstancedDraw— TheInstancedDrawto report on.
Returns InstancedDrawInfo? — The registration record, or nil.
print(renderer.mesh.instanceInfo(draw).instanceCount)
local info = renderer.mesh.instanceInfo(draw)
if info.status == "refused" then error(info.error) end
typed/builtin//modules/api/engine/renderer/renderer/mesh/instanceTransforms
renderer.mesh.instanceTransforms(draw: InstancedDraw) -> any
Read back the world matrices a registration's drawn copies are placed
by: instanceCount matrices of 16 floats, column-major and tightly
packed, in the layout the transform buffer holds them. The read is of the
buffer as it stands when it runs, so a population a compute pass rewrites
every frame answers with the placement of the frame the read lands in.
Parameters
drawInstancedDraw— TheInstancedDrawwhose copies to locate.
Returns any — A Readback to poll — :ready() then :result() — or nil for a registration that is no longer live.
local pending = renderer.mesh.instanceTransforms(draw)
while not pending:ready() do task.wait() end
local floats = pending:result()
typed/builtin//modules/api/engine/renderer/renderer/mesh/instanceWorlds
renderer.mesh.instanceWorlds(draw: InstancedDraw) -> any
Read back where a registration's drawn copies stand in the world, as
the engine composed them for the last frame drawn: each copy's matrix from
the transform buffer, carried through the world matrix of the entity the
copies stand in when they have one (setInstanceParent). instanceCount
column-major 4x4 matrices, 16 floats each. Async — poll the handle it
returns the same way as instanceTransforms.
Parameters
drawInstancedDraw— TheInstancedDrawto read.
Returns any — A pending readback: :ready(), then :result() for the floats.
local pending = renderer.mesh.instanceWorlds(draw)
while not pending:ready() do task.wait() end
local x = pending:result()[13]
typed/builtin//modules/api/engine/renderer/renderer/mesh/isCpuResident
renderer.mesh.isCpuResident(mesh: string | { [string]: any } | AssetRef) -> boolean
True if this mesh has a resident CPU copy in the guid-keyed CPU store.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns boolean
if renderer.mesh.isCpuResident(handle) then ... end
typed/builtin//modules/api/engine/renderer/renderer/mesh/isResident
renderer.mesh.isResident(mesh: string | { [string]: any } | AssetRef) -> boolean
True if a GPU mesh is resident under this mesh's guid — the device
holds its buffers, or the upload queued this frame is still going to hand
them over. This is the store the draw paths are gated on, so a mesh this
reports resident is one renderer.mesh.drawInstanced and a Model can
draw — from the frame after the upload commits: a render asked for in the
same tick the upload was queued does not carry the mesh yet.
renderer.mesh.onDevice is the answer that waits for that commit.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns boolean
print(renderer.mesh.isResident(handle))
typed/builtin//modules/api/engine/renderer/renderer/mesh/list
renderer.mesh.list() -> { any }
Every mesh currently registered, ordered by guid — the ones a script
created and the ones that reached the device through an asset alike.
Answers "which mesh is this?" when all that is known is a size: each entry
carries the guid, the vertex/index counts it was created with, where it came
from (origin is "asset" for a mesh the asset path uploaded), whether the
GPU still holds it, and where its culling bounds come from (boundsFrom is
"compute" for a mesh a compute pass writes). A resident entry also carries
the bytes its buffers cost. The buffer columns vertexBytes,
vertexStorageBytes, indexBytes and lightmapBytes are the sizes of
the buffers the mesh holds of its own. A static mesh in the shared
geometry heap draws its vertices and indices out of its regions of the
heap and the shared index buffer (the geometry category of
renderer.gpuMemory() counts them), so its vertex and index columns are
0; a mesh outside the heap holds both of its own, and a mesh a compute
pass writes holds its vertices of its own. The storage column is the
rest copy of the vertices a skinned mesh's deformation pass reads, and 0
for every other mesh; the lightmap
column is 0 for a mesh with no lightmap UV set, which is lit through its
uv0. bytes is what the mesh holds of its own, the four columns summed.
A mesh made from compute buffers (computeOwned) holds none of them, so
its bytes is 0 and the compute category counts them. The bytes
column is what sums to the meshes category of renderer.gpuMemory().
renderer.references("mesh", guid) says what is still holding a row, and
renderer.collect() releases the rows nothing holds.
Returns { any } — Array of { guid, vertexCount?, indexCount?, origin, owner?, resident, boundsFrom, bytes?, vertexBytes?, vertexStorageBytes?, indexBytes?, lightmapBytes?, computeOwned?, primitives?, revision? }.
for _, m in ipairs(renderer.mesh.list()) do print(m.guid, m.bytes) end
typed/builtin//modules/api/engine/renderer/renderer/mesh/listInstanced
renderer.mesh.listInstanced() -> { InstancedDrawInfo }
Every instanced-draw registration this engine is drawing, in
registration order. Each record is what instanceInfo answers with, and
carries a draw handle of its own — so a population whose handle its
caller no longer holds is reached here and released, resized or read like
any other.
Returns { InstancedDrawInfo } — An array of registration records; empty when nothing is registered.
for _, pop in ipairs(renderer.mesh.listInstanced()) do
renderer.mesh.dropInstanced(pop.draw)
end
typed/builtin//modules/api/engine/renderer/renderer/mesh/loadCpu
renderer.mesh.loadCpu(ref: string | AssetRef, into: string?) -> MeshCpuHandle
Load a .mesh asset's geometry into the ONE guid-keyed CPU store (the
Disk→CPU step) and return a CPU handle. The handle holds NO geometry — only
the guid plus counts and the per-handle read/encode/unload ops (which read
the Rust-side store). Called by meshRef:load(). DEFAULT lifecycle: upload
to the GPU then handle:unload(); the store is populated only by this call.
The CPU store is keyed by guid and shared by everything that reads the
mesh, so a copy under the asset's own guid is one any other reader can
drop. into lands the copy under a key of the caller's own instead: the
handle answers for that key, the asset's own entry is left as it was, and
the copy stays resident until the caller unloads it.
Parameters
refstring | AssetRef— A meshAssetRef(carries.guidand reads its primary via getBytes), or any stringasset.refresolves to one — the guidencodeCputakes, an identity, a name or a source path.intostring(optional) — The CPU-store key the geometry lands under. Defaults to the asset's own guid.
Returns MeshCpuHandle
local cpu = meshRef:load(); local gpu = renderer.mesh.create(cpu); cpu:unload()
local cpu = renderer.mesh.loadCpu(gpuMesh.guid)
local own = renderer.mesh.loadCpu(meshRef, "bake:" .. meshRef.guid); own:unload()
typed/builtin//modules/api/engine/renderer/renderer/mesh/morphTargets
renderer.mesh.morphTargets(mesh: string | { [string]: any } | AssetRef) -> { string }
The names of the shapes this mesh blends towards, in the order an
entity's ecs.MorphWeights addresses them — weight i drives the target
named at i. An imported model carries the names its source file gave its
blend shapes, so content drives a face by the shape it means rather than by
the ordinal that shape happened to import at (which moves when the model is
re-exported). A target the source never named reads as an empty string.
Empty for a mesh with no morph targets. Errors when the mesh is neither
GPU- nor CPU-resident — materialise it first (meshRef:handle()).
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns { string } one name per morph target, in target order.
for i, name in renderer.mesh.morphTargets(meshRef) do print(i, name) end
typed/builtin//modules/api/engine/renderer/renderer/mesh/morphWeights
renderer.mesh.morphWeights(mesh: string | { [string]: any } | AssetRef, weights: { [string]: number }) -> { number }
Turn weights named by shape into the ordered weight array
ecs.MorphWeights takes — the drive-a-face-by-name call. Every target the
mesh carries gets a slot; the ones weights names take their value and the
rest are 0, so the returned array always describes the whole mesh and a
shape left out is a shape at rest.
A name the mesh does not carry is an error listing the names it does: a mistyped viseme that silently moved nothing would be indistinguishable from a rig that never had it.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.weights{ [string]: number }—{ [string]: number }— how strongly to blend each named shape.
Returns { number } one weight per morph target, in target order.
local w = renderer.mesh.morphWeights(meshRef, { Eyes_Blink = 1, Mouth_Smile = 0.4 })
ecs.set(face, ecs.MorphWeights { weights = w })
typed/builtin//modules/api/engine/renderer/renderer/mesh/onDevice
renderer.mesh.onDevice(mesh: string | { [string]: any } | AssetRef) -> boolean
True once the device holds this mesh's buffers — the upload queued
for it has committed — so the next render asked for carries the mesh.
renderer.mesh.isResident answers true one frame earlier, while the
upload is still queued; a reader about to render and read the picture
back waits on this one.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
Returns boolean
while not renderer.mesh.onDevice(guid) do task.wait() end
typed/builtin//modules/api/engine/renderer/renderer/mesh/readback
renderer.mesh.readback(mesh: string | { [string]: any } | AssetRef, into: string?) -> MeshCpuHandle
Read a runtime GPU mesh's geometry back to CPU and return a
MeshCpuHandle for it — the GPU→CPU half of the runtime-mesh freeze path. A
mesh made with renderer.mesh.create keeps no CPU copy, so persisting it
(:encode() → asset.create("mesh", …)) reads it back here first. Yields
until the readback completes (a frame or two). After it returns the geometry
is resident in the guid-keyed CPU store: :getTriangles, :getVertices,
:getBounds, :geometry, :encode, :unload all work. Errors if the mesh
never becomes resident in the vertex pool.
The CPU store is keyed by guid and shared by everything that reads the
mesh, and whatever owns the mesh can retire the copy under its own guid:
renderer.mesh.update from compute buffers unloads it, which an ocean
surface does every frame it steps. into lands the copy under a
key of the caller's own instead: the handle answers for that key, and it
stays resident until the caller unloads it, whatever happens to the mesh.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — theMeshHandlerenderer.mesh.createreturned, a guid, or a meshAssetRef.intostring(optional) — The CPU-store key the geometry lands under. Defaults to the mesh's own guid.
Returns MeshCpuHandle
local cpu = renderer.mesh.readback(handle); local zmsh = cpu:encode(); cpu:unload()
local snap = renderer.mesh.readback(handle, "bake:" .. handle.guid); local tris = snap:getTriangles(); snap:unload()
typed/builtin//modules/api/engine/renderer/renderer/mesh/readbackPosed
renderer.mesh.readbackPosed(requests: { { entity: string, mesh: any, into: string? } }) -> { [string]: MeshCpuHandle }
Read the POSED geometry of skinned entities back to CPU: for each request, the vertices the skinning pass wrote for that entity this frame, joined by the indices of the mesh it is posed from. A skinned surface's world-space triangles are produced on the GPU from the entity's joint matrices, so the mesh asset holds the bind pose and only this reads where the surface actually is. The posed vertices are in model space, so the entity's own world transform still places them — the same transform the raster draw uses.
Takes a LIST and answers a map, because the readbacks are queued together
and polled together: a scene's worth of characters costs the frames of one
readback rather than one entity's after another. Each posed mesh lands in
the CPU store under a guid of its own, derived from the entity, so
compute.buildBvh, meshcpu.* and every other guid-keyed reader takes it
like any other mesh. Call handle:unload() when done with it. A request's
into lands that entity's copy under a key of the caller's own, which no
other read of the same entity replaces or drops.
An entity the map omits holds no live pose — nothing skinned it this frame, which is also what makes its draws read the source mesh, so its bind-pose geometry is what stands for it.
The vertices read are ones the skinning pass wrote for the pose the entity is bound to. An entity bound to a pose that pass has not written yet — the frame it was posed, before the pass reached the queue — is asked again on the next frame rather than read from a slice still holding what stood there before.
Parameters
requests{ { entity: string, mesh: any, into: string? } }—{ { entity = <id>, mesh = <mesh>, into = <key>? } }— the entity to read, the mesh it is posed from (a guid,MeshHandleor meshAssetRef), and the CPU-store key its copy lands under (default"posed:" .. entity).
Returns { [string]: MeshCpuHandle } — A map from entity id to the MeshCpuHandle holding that entity's posed geometry.
local posed = renderer.mesh.readbackPosed({ { entity = id, mesh = ecs.get(id, ecs.Mesh).mesh } })
local tris = posed[id]:getTriangles()
typed/builtin//modules/api/engine/renderer/renderer/mesh/scheduleClusters
renderer.mesh.scheduleClusters(mesh: string | { [string]: any } | AssetRef, opts: { levels: string?, defer: boolean? }?) -> boolean
Queue a cluster bake over the mesh's geometry, off the frame loop. The
mesh keeps drawing its current cluster set while the bake runs, and the set
the bake produces replaces it when it lands. opts.levels is "dag" for
the LOD hierarchy or "single" for one level of clusters at full detail;
when omitted, a mesh AssetRef bakes the depth its clusterLod setting asks
for and any other argument bakes "dag". The CPU mesh may be unloaded on
the very next line. Geometry with a triangle joining two independently
moving parts leaves the queue unbaked with a warning; a mesh
renderer.mesh.clusters reports as "deformable" or "heapFull" leaves
it unbaked without one.
One bake is advanced per frame — the one at the head of the queue — and the
geometry is read once a bake gets there and the mesh's GPU upload has
landed, from the definition the engine holds for the mesh. The queue
therefore holds one mesh's geometry rather than one per mesh, whatever its
depth, and the set installs only on the geometry it was read from: a mesh
whose geometry is replaced before its set lands keeps the set of its new
geometry. renderer.mesh.clusterBakes().heldBytes reports what the queue
is holding, and its inFlight rows report which bakes it is holding for.
This is what the .mesh assetType materialisation path uses; reach for
renderer.mesh.buildClusters when you want the bytes in hand instead.
Scheduling the same mesh again replaces the bake already in flight for it.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh to bake — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef, loaded into the CPU store (renderer.mesh.loadCpu).opts{ levels: string?, defer: boolean? }(optional) —{ levels: "dag" | "single", defer: boolean? }?. Withdefer = true, a previously registered off-device mesh remembers this explicit depth for its next upload without loading a CPU copy. An unknown guid returns false. A resident mesh still requires its CPU copy.
Returns boolean — True if a bake was queued or a deferred request remembered; otherwise false for a mesh with no GPU mesh registered or being created under its guid.
renderer.mesh.scheduleClusters(cpu, { levels = "single" }) ; cpu:unload()
typed/builtin//modules/api/engine/renderer/renderer/mesh/setInstanceCount
renderer.mesh.setInstanceCount(draw: InstancedDraw, count: number) -> InstancedDraw
Change how many of a registration's instances draw. Constant time — the
reservation, the transform buffer and the pipeline all stay put, so this is
the verb for a population whose size changes per frame. The new count must
fit the reservation drawInstanced was given.
Parameters
drawInstancedDraw— TheInstancedDrawto reconfigure.countnumber— Instances to draw, at least 1 and within the reservation.
Returns InstancedDraw — The same InstancedDraw.
renderer.mesh.setInstanceCount(draw, visibleCount)
typed/builtin//modules/api/engine/renderer/renderer/mesh/setInstanceParent
renderer.mesh.setInstanceParent(draw: InstancedDraw, parent: any?) -> InstancedDraw
Stand a registration's copies in an entity's space: every copy's matrix
is taken relative to the entity, so the population moves, turns and scales
with it from the next frame on, with its transform buffer untouched. nil
puts the copies back in world space. It is the verb for a population that
belongs to something — a generator's output, an asset stood on an entity.
Parameters
drawInstancedDraw— TheInstancedDrawto reconfigure.parentany(optional) — The entity the copies stand in (a proxy or its id), or nil for world space.
Returns InstancedDraw — The same InstancedDraw.
renderer.mesh.setInstanceParent(draw, entity.find("Forest"))
typed/builtin//modules/api/engine/renderer/renderer/mesh/setInstanceRenderLayer
renderer.mesh.setInstanceRenderLayer(draw: InstancedDraw, renderLayer: number) -> InstancedDraw
Change which render layers a registration's copies belong to. Constant time — the reservation, the transform buffer and the pipeline all stay put, and the next frame drawn tests the copies against the new membership. It is the verb for a population that follows something whose membership moves: a camera or a capture including the layer draws the copies, one excluding it does not.
Parameters
drawInstancedDraw— TheInstancedDrawto reconfigure.renderLayernumber— The membership bitmask, the same valuedrawInstancedtakes asrenderLayer. At least one bit must be set.
Returns InstancedDraw — The same InstancedDraw.
renderer.mesh.setInstanceRenderLayer(draw, mask)
typed/builtin//modules/api/engine/renderer/renderer/mesh/setInstanceTraced
renderer.mesh.setInstanceTraced(draw: InstancedDraw, traced: boolean) -> InstancedDraw
Put a registration's copies into the ray-traced scene, or take them out
of it, from the next frame on. The ray-traced scene is the geometry probe
GI, ray-traced shadows and every other pass that traces rays hit: a traced
copy bounces light, blocks it and is lit by it. drawInstanced takes the
initial value as traced. instanceInfo(draw).traced reads "noCpuTransforms"
for a population whose matrices only a compute pass writes, which cannot be
placed in the traced scene.
Parameters
drawInstancedDraw— TheInstancedDrawto reconfigure.tracedboolean— Whether the copies stand in the ray-traced scene.
Returns InstancedDraw — The same InstancedDraw.
renderer.mesh.setInstanceTraced(draw, false)
typed/builtin//modules/api/engine/renderer/renderer/mesh/setVertices
renderer.mesh.setVertices(mesh: string | { [string]: any } | AssetRef, positions: { number })
Replace a mesh's resident CPU vertex positions (flat { x,y,z, ... })
IN PLACE — indices, normals/uvs, and skinning are preserved, the AABB
recomputes, and the GPU re-fetches the new geometry so it shows on screen.
The positions alone travel, so this is the per-frame deformation path where
renderer.mesh.update re-sends the whole geometry. The mesh must be
CPU-resident: renderer.mesh.create({ ..., keepCpu = true }) keeps a copy
from the start, renderer.mesh.readback(mesh) recovers one from the GPU,
and meshRef:load() loads one for a .mesh asset. Errors with the reason
otherwise, or when the vertex count doesn't match.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.positions{ number }— Flat{ x,y,z, ... }— one xyz per vertex; count must match the mesh.
local m = renderer.mesh.create({ positions = P, indices = I, keepCpu = true })
renderer.mesh.setVertices(m, P) -- P mutated in place each frame
typed/builtin//modules/api/engine/renderer/renderer/mesh/unloadCpu
renderer.mesh.unloadCpu(mesh: string | { [string]: any } | AssetRef)
Drop a mesh's resident CPU copy from the guid-keyed CPU store. The explicit release for a runtime geometry mesh's recoverable definition.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.
typed/builtin//modules/api/engine/renderer/renderer/mesh/update
renderer.mesh.update(mesh: string | { [string]: any } | AssetRef, src: any?) -> MeshHandle
Overwrite the GPU resource mesh names IN PLACE, under the same guid,
from new geometry or compute buffers. Never writes a .mesh file — the
play-mode mutate path. A Model bound to the guid reflects the change with no
re-bind. Takes every form that names a mesh — the MeshHandle create
returned, the guid renderer.mesh.list hands out, a MeshCpuHandle or a
mesh AssetRef. Returns a handle carrying the bounds the new geometry has:
the handle it was given, refreshed, and a handle over the guid otherwise.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh to update — aMeshHandle, a guid, aMeshCpuHandleor a meshAssetRef.srcany(optional) — New geometry{positions, indices, aabbMin?, aabbMax?, ...}or compute buffers{vertexBuffer, indexBuffer, vertexCount, indexCount, prevVertexBuffer?}.aabbMin/aabbMax, given together, state the mesh's extent in place of the box its vertices reach.
Returns MeshHandle — A MeshHandle for the updated mesh.
typed/builtin//modules/api/engine/renderer/renderer/mesh/uploadClusters
renderer.mesh.uploadClusters(mesh: string | { [string]: any } | AssetRef, clusters: string) -> boolean
Replace the cluster set a mesh draws with a serialized set (bytes from
renderer.mesh.buildClusters), built from the geometry the mesh holds as
the call is made. A set whose vertex count, vertex maps or nodes do not
describe the mesh, or one whose mesh's geometry is replaced before it
lands, is refused with a warning, and the mesh keeps its current set and
the set it was asked for. Once the set is installed, a bake still in
flight for the mesh is cancelled, and the engine keeps the bytes on the CPU
(renderer.mesh.clusterStore().scriptSetBytes) so the mesh draws this set
again when it returns to the device after nothing displayed it, or after
the device is rebuilt. The bytes go when the mesh's geometry is redefined,
when renderer.mesh.dropClusters returns it to lod0, and when the mesh
is destroyed.
Parameters
meshstring | { [string]: any } | AssetRef— The mesh the clusters belong to — aMeshHandle, aMeshCpuHandle, a guid, or a meshAssetRef.clustersstring— Serialized cluster bytes (binary-safe).
Returns boolean — True if the upload was queued; false while the mesh's GPU upload has not landed yet.
renderer.mesh.uploadClusters(gpu, cb)
typed/builtin//modules/api/engine/renderer/renderer/minScreenSize
renderer.minScreenSize() -> number
The on-screen radius, in pixels, an object must reach to be drawn. 0
while the cutoff is off.
Returns number
local px = renderer.minScreenSize()
typed/builtin//modules/api/engine/renderer/renderer/morphStats
renderer.morphStats() -> {
The morph state the last frame drew with. A mesh carries the shapes it
can blend towards and an entity carries how strongly each is blended
(ecs.MorphWeights); where both are present, the vertex stage adds the
weighted deltas to the base geometry.
instances is how many render slots that happened at, and blends how
many single-target blends those slots carry between them: a slot
contributes one per target its weights move, or that they moved the frame
before, so the number of targets a mesh can be given is bounded by the
buffer the blends live in. meshes is how
many meshes hold a delta block and targets how many targets those blocks
cover between them; deltaBytes is what the shared buffer they are
appended into holds, and deltaBufferBytes the size of that buffer, which
the vertex stage binds whole.
deltaBudgetBytes is the most that buffer may hold on this device: the
largest storage buffer the device binds at once (128 MiB on many mobile
browsers). A block costs 32 bytes per vertex per target, over every vertex
of the mesh. A mesh whose block would take the resident blocks past the
budget is refused by name in the engine log and draws in its base shape,
and refusedMeshes counts the meshes refused that way; the refusal holds
until the mesh is uploaded again. A morph-target mesh whose weights are all
zero reads a meshes above zero beside an instances and blends of zero.
Returns { instances: number, blends: number, meshes: number, targets: number, deltaBytes: number, deltaBufferBytes: number, deltaBudgetBytes: number, refusedMeshes: number }
local m = renderer.morphStats()
print(("%d instances carrying %d blends over %d meshes"):format(m.instances, m.blends, m.meshes))
typed/builtin//modules/api/engine/renderer/renderer/observe
renderer.observe() -> RenderObservation
Everything the renderer knows about the frame it last drew: what
program it bound for each renderable, the render state it holds each
material under, and what each program has cost in pipeline builds.
renderables is one row per renderable in the renderer's draw list,
carrying the program its material named (requestedProgram) beside the one
that was bound (boundProgram) — __error__ wherever the lookup missed
and the draw went ahead on the magenta placeholder — plus substituted,
the outcome (drew / drewPlaceholder / skipped / notDrawn), the
reason that forced it and the compiler's own detail for a failed
compile. observed says which of two answers a row is: true for a
resolution a geometry pass took as it drew, false for the renderer's own
resolution of a renderable this frame drew nowhere, which is what a
renderable outside every camera's frustum or layer mask reports. Every
notDrawn row says why in notDrawnReason: meshNotResident (the GPU
holds no mesh under the guid it draws), hidden (its Model is hidden),
layer (the main camera leaves out its render layer), culled (outside
the main camera's frustum) or viewCull (the view's own cull kept it out:
distance range, size on screen, occlusion or detail level, which
renderer.cullStats() counts); every other row carries none.
materials is one row per
material the renderer holds a prepared bind group for; shaders is one row
per program pipelines have been built for. frame names the frame every
per-frame count covers; retainedFrames how many frames a resolution a
pass took is kept for after the last frame that drew it; window and
costWindow state both in the document itself. Recording is armed by the
first read, so this waits for the frame that first records rather than
answering empty.
Returns RenderObservation
local o = renderer.observe(); print(o.placeholderDraws, "renderables drew the placeholder in frame", o.frame)
typed/builtin//modules/api/engine/renderer/renderer/occlusionCulling
renderer.occlusionCulling() -> boolean
Whether occlusion culling is currently enabled. True unless
renderer.setOcclusionCulling(false) turned it off.
Returns boolean
typed/builtin//modules/api/engine/renderer/renderer/output/capabilities
renderer.output.capabilities() -> OutputCapabilities
What the presented surface and the display behind it offer: the
colour spaces renderer.output.set takes on this surface ("srgb"
always; "scrgb" and "pq" where a native surface presents HDR;
"extended-srgb" and "extended-display-p3" where a browser canvas
presents an extended range), the display's peak, SDR white and headroom
where it reports them, whether it can show HDR and the gamut it covers
where the display or the platform states them, and hdrUnavailable,
why no HDR colour space is offered, when none is. The same calls answer
on every platform. A renderer with no window offers "srgb" alone.
Returns OutputCapabilities — { hdr, colorSpaces, peakNits?, paperWhiteNits?, headroom?, highDynamicRange?, gamut?, hdrUnavailable? }
local caps = renderer.output.capabilities(); if caps.hdr then renderer.output.set({ colorSpace = caps.colorSpaces[2] }) else print(caps.hdrUnavailable) end
typed/builtin//modules/api/engine/renderer/renderer/output/get
renderer.output.get() -> OutputState
How the frame's output stage writes the presented surface: the
colour space the surface is shown in and the encoding the picture is
written in, the surface's format and bit depth, the luminances an HDR
output shows SDR white and its peak at, and the dither added before the
picture is rounded to that depth. The output stage runs last in every
presented frame (renderer.post.stages() lists it in output), so this
is the one place the frame is quantized; an offscreen capture is written
undithered, in sRGB. On a browser canvas canvas states the
configuration the canvas reads back: { format, colorSpace, toneMapping }.
Returns OutputState — { encoding, colorSpace, hdr, surfaceFormat, bitDepth, paperWhiteNits, peakNits, dither, pending, error?, canvas? }
local out = renderer.output.get(); print(out.colorSpace, out.bitDepth, out.dither)
typed/builtin//modules/api/engine/renderer/renderer/output/set
renderer.output.set(opts: {
dither: string?,
encoding: string?,
colorSpace: string?,
paperWhiteNits: number?,
peakNits: number?,
}) -> OutputState
Change how the output stage writes the presented surface.
colorSpace presents in "srgb" or in an HDR colour space the surface
offers (renderer.output.capabilities().colorSpaces): "pq" (BT.2100
PQ, HDR10), "scrgb" (linear, on a float surface), or on a browser
canvas "extended-srgb" / "extended-display-p3" (the sRGB curve
continued above SDR white on an rgba16float canvas with "extended"
tone mapping). An HDR output shows SDR white, the UI included, at
paperWhiteNits, and the display transform's curves reach peakNits;
each unstated one is the display's, else 203 and 1000 nits. An
extended-range output is shown with SDR white where the system shows it,
so there the two state the headroom the curves reach above it. The surface changes on the next frame (pending
until then). dither is "blueNoiseTpdf" (the default) or "off",
which writes the picture rounded as it stands, for a golden capture
compared byte for byte. encoding names the encoding the surface is
written in, which follows its colour space, so any other is refused
naming it. A colour space the surface does not offer is refused naming
what it offers and why it offers no HDR (hdrUnavailable); a luminance
outside 80 to 10000 nits and a field that is none of these are refused.
Parameters
opts{ dither: string?, encoding: string?, colorSpace: string?, paperWhiteNits: number?, peakNits: number?, }—{ colorSpace: "srgb" | "scrgb" | "pq" | "extended-srgb" | "extended-display-p3"?, paperWhiteNits: number?, peakNits: number?, dither: "blueNoiseTpdf" | "off"?, encoding: string? }
Returns OutputState — The state the output stage takes: { encoding, colorSpace, hdr, surfaceFormat, bitDepth, paperWhiteNits, peakNits, dither, pending, error?, canvas? }.
renderer.output.set({ dither = "off" })
renderer.output.set({ colorSpace = "pq", paperWhiteNits = 203, peakNits = 1000 })
renderer.output.set({ colorSpace = "extended-srgb", paperWhiteNits = 203, peakNits = 812 })
typed/builtin//modules/api/engine/renderer/renderer/passSchedule
renderer.passSchedule() -> {
The schedule check over this frame's enqueued render passes. Passes
declare what they read (inputs) and what they write (output /
outputs / storage), and the frame runs them in phase order and, inside
a phase, in order order. violations holds every input bound to a
resource the frame produces LATER: that read samples the resource as it
stands ahead of that pass, which is the previous frame's contents for a
render target that persists, an empty target for one just created, and the
scene draw's own output for a @scene.* buffer — and the pass renders
either way. The frame's own buffers are checked on the same terms as a
render target: bind @scene.motion at a phase ahead of the pass that
writes it and the read is reported, naming the buffer and its writer.
A pass reading a resource ahead of that write on purpose declares that slot
in its enqueue's readsPrevious and drops out of the list;
unboundPrevious holds declared slots the pass binds no such resource to,
which cover nothing.
A resource no queued pass writes is not reported — a camera rendering to
texture and compute.dispatch both fill targets outside the pass queue,
and the scene draw fills the @scene.* buffers every frame.
A read the frame has only one order for is not reported either: where the
writing pass consumes something the reading pass produces, the reader runs
first or the writer has nothing to write, which is what a pass reading a
buffer into a target of its own and a second pass copying that target back
over the buffer forms.
unreachable holds passes at a phase that does not run their kind: every
phase drains its fragment and compute passes, while afterLighting is the
one that draws geometry, draw and splat passes, so one of those enqueued
elsewhere sits in the queue and never runs.
unmetWhenDrawn holds passes whose whenDrawn names a render target no
geometry or draw pass writes as its output ahead of them: those two
kinds are the ones that record what they drew into their target, so the
wait is never met and the pass never runs.
Each finding is also stated in the engine log the first time it appears.
unread lists the passes the last drawn frame left out because no pass
read what they leave in a channel or render target their enqueue's
whenRead names. A pass states whenRead to be run only for those
readers, so an entry here is that declaration at work, stated apart from
the findings above and kept out of the log.
heldBack lists the passes the last drawn frame held back because a
render target they sample holds no picture and no pass wrote it that
frame, so reading it would read the target's cleared texels; each names
the slot and target, its writer's fate ("skipped", or "waiting" on a
pipeline still being built) and how many drawn frames in a row it has been
held. A pass reading what an earlier frame left in a target names that
slot in its enqueue's readsPrevious, and is not held for it. One held
back 60 drawn frames in a row by a writer that is not waiting is also
stated in the engine log, once.
Returns { violations, unboundPrevious, unreachable, unmetWhenDrawn, unread, heldBack }
local s = renderer.passSchedule()
for _, v in s.violations do print(v.message) end
typed/builtin//modules/api/engine/renderer/renderer/pendingWork
renderer.pendingWork() -> PendingWork?
What the renderer still owes the picture — the work it has taken on and has not yet put in the frame.
A frame draws what the renderer holds at the moment it runs, and several of
the things it holds arrive over more than one frame. A pipeline is built
off the frame thread and bound the frame its result is taken in; a texture
is uploaded under a per-frame time budget; a released texture's GPU object
is freed on the frame the release queue is drained; a streamable texture
climbs toward the level its screen size asks for one level at a time.
pipelineBuilds, textureUploads, textureReleases and
textureResidency are those four. The pipelines a large object takes to
be shaded on the legacy lane, which shades the same surface for less, are
asked for once the renderer owes the picture nothing and are not among
pipelineBuilds: the picture is the same before they land and after.
textureTransfers counts the textures
the texture cache is still moving over several frames: a large upload
written a band at a time, a promotion waiting on its finer levels to be
read or decoded, a demotion waiting on its levels to be read back. Each
lands as a new GPU texture on a frame of its own, and the frames between
two landings replace nothing, so textureResidency alone reads zero on
them. outstanding is the sum of every count.
settled is true when outstanding is zero, and says the renderer owes
this picture nothing: the frames after this one draw the same picture
unless something changes the scene. That is the renderer's own word for
what a test measuring a picture holds for before it reads one.
epoch counts the times the renderer has gone from owing nothing to owing
something since the process started. It is what a pair of readings needs: a
run of work that begins AND ends between two samples leaves both of them
reading settled and leaves epoch higher, so settled at both ends with
the same epoch at both ends is the statement that nothing arrived across
the whole span, rather than at its two endpoints alone. Test.settleReading
is built on exactly that pair of conditions.
frame names the drawn frame the reading was published on. Every count is
published from the frame thread on every frame the renderer runs, so a
headless engine declining frames answers as readily as a windowed one.
deviceRebuild is one while the engine is between render devices: the
picture is owed the device itself, every frame in that window draws
nothing, and what content puts back on the new device lands on the frames
after it. computeCommands counts the compute commands a drain held
over: a dispatch waiting on the program it names and every command over
the buffers it would write queued behind it, each of which runs or drops
on a later drain. clusterSets counts the meshes whose cluster set is
still being built, or is owed again after a device rebuild: each lands as
the set the mesh draws, and the geometry a cut of it draws changes on the
frame it does. materialRows counts the materials the frame does not yet
draw as they ask: one whose raster or resolve pipeline is still building
draws nothing until it lands, one whose shader's resolve gate has not
reached a verdict resolves through the error shader until it does, and one
whose routing changed since the frame last published it is still drawn by
the previous routing. Each changes the picture on the frame it lands.
skippedDraws counts the renderables the last drawn frame left undrawn
because a pipeline or a material group they draw with was not built yet;
each appears on the frame what it waits on lands. shaderCompiles counts
the shader compiles running off the frame thread that no frame has landed:
each lands as the program its keys name, and the materials drawing with
those keys change on the frame it does.
Returns PendingWork? — { settled, outstanding, pipelineBuilds, textureUploads, textureReleases, textureTransfers, textureResidency, deviceRebuild, computeCommands, clusterSets, materialRows, skippedDraws, shaderCompiles, epoch, frame }, or nil on a build with no renderer attached
if renderer.pendingWork().settled then print("the picture is what it is going to be") end
local w = renderer.pendingWork(); print(w.outstanding, "arrivals still owed, over", w.epoch, "runs of work")
typed/builtin//modules/api/engine/renderer/renderer/pictureSize
renderer.pictureSize() -> { width: number, height: number }
The size the game's picture is drawn at, in pixels: the whole
drawing surface where the scene fills the window, and while a Scene
panel presents the scene inside the window (an editor layout), the
picture that panel shows: the panel's own size, or the device screen
size renderer.setPictureSize holds on it. This is the size
renderer.setPictureSize sets on either layout, and ui.screenSize()
times ui.pixelRatio("camera") once the game's UI has laid out over it.
{ width = 0, height = 0 } before the first frame has drawn.
Returns { width: number, height: number } in pixels.
local p = renderer.pictureSize(); print(p.width / p.height)
typed/builtin//modules/api/engine/renderer/renderer/pipelineCache
renderer.pipelineCache() -> PipelineCache?
What the driver's compiled-pipeline store held, built, and wrote back. A pipeline is machine code the GPU driver compiles from the shader bound into it, and that compile is what a launch pays before the first frame drawing with each pipeline can appear. The store keeps that compiled code across runs, so a launch whose shaders have not changed reads back what the previous one compiled.
restoredBytes is what a previous run left for this GPU and this launch
read; pipelinesBuilt counts the pipelines built since startup and
buildMs is what they cost together, which is the number the store lowers.
saves and savedBytes describe writing it back. The file holds the
whole store, so a write costs its full size however few pipelines it
adds: a launch writes once the burst of builds it boots with settles,
then at most once every five minutes while new pipelines keep being
built, and again as it closes, so a crash costs at most the pipelines
compiled since the last write. Reading the store and writing the file
run on a thread of their own, so the frame that starts a write waits for
neither. dirty is true while pipelines have been built that the file
does not hold, including after a write that failed, which lastError then
names. path is the file, named after the GPU it belongs to.
The driver keeps the device memory of every program compiled through the
store for as long as the store holds it, whether or not a pipeline still
uses it. So once 64 pipelines have been built since the last renewal and
the builds pause, the store is renewed on a thread of its own: replaced by
a store seeded with what it held, which keeps every compile for the next
build and the next launch and releases the device memory of every program
no pipeline holds. renewals counts them, and a session that keeps
compiling and dropping programs holds at most the programs compiled since
the last one.
supported is false where the platform holds no store a program can carry:
a browser keeps its own and hands none out, and an adapter can lack the
capability. reason says which, and the build count and timing still read
true there. lastError names a read or write failure; a failed store costs
the saved compile and never the frame, since every pipeline is built from
its source either way.
A pipeline a material, the sky, a depth view, a post-process pass or a
compute program a script registers needs after boot is built off the
frame thread — the shader module behind that compute program with it —
on buildWorkers worker threads on native, behind the browser's
asynchronous entry point on the web, where buildWorkers reads 0. So a
burst of new materials costs a frame nothing beyond drawing the
placeholder until each pipeline lands, and a burst of effects costs it
nothing beyond each effect starting on the frame its pipeline does.
offFrameBuilt and offFrameBuildMs are the pipelines and the
milliseconds that never held a frame; pipelinesBuilt - offFrameBuilt
is what the frame thread built, which is the renderer's own — the set it
stands up before its first frame, and the few it stands up on the frame
a pass first asks for them. buildsSubmitted, buildsFinished,
buildsFailed and buildsInstalled count build requests (shader modules
and pipelines) made, completed, refused and taken back by a frame.
buildsAbandoned counts the requests a renderer still held when a device
rebuild let it go, which no frame will take back. buildsSuperseded
counts the requests a worker set down unbuilt because the shader they
were cut from was saved again before a worker reached them: each is also
among buildsFinished and none is among buildsFailed, pipelinesBuilt
or buildMs, so a burst of saves of a shader, or of a module it
includes, builds what the last save asked for plus what the workers had
already begun. buildsPending is
what the renderer drawing now has yet to take back: asked for and not
yet in use, a finished result included until a frame installs it. So
every request made is installed, abandoned or pending, and a reader
waiting on buildsPending to reach zero reads pipelinesBuilt with every
build it waited for counted, and can tell a queue draining from one that
is stuck. A saved shader, or every shader a saved module reaches,
rebuilds its pipelines this way while its materials keep drawing with the
pipelines of the text they were drawn with before the save: under each
key, the previous program's pipeline draws until the recompiled one
lands there and takes its place. previousPipelines counts the previous
programs' pipelines still held, so it reads zero once every rebuild has
landed. modulesBuilt and moduleBuildMs are
the shader modules compiled off the frame thread, parse and validation
included.
pipelinesBuilt and buildMs are engine-wide totals; renderer.shaderCost()
is the same cost broken down per program, with each one's permutation count.
Returns PipelineCache? — { supported, reason, path, restoredBytes, pipelinesBuilt, buildMs, offFrameBuilt, offFrameBuildMs, buildsSubmitted, buildsFinished, buildsFailed, buildsInstalled, buildsAbandoned, buildsSuperseded, buildsPending, previousPipelines, modulesBuilt, moduleBuildMs, buildWorkers, saves, savedBytes, renewals, dirty, lastError }, or nil before the renderer has drawn a frame
local c = renderer.pipelineCache()
print(("%d pipelines in %.1f ms, %d bytes restored"):format(c.pipelinesBuilt, c.buildMs, c.restoredBytes))
typed/builtin//modules/api/engine/renderer/renderer/post/stages
renderer.post.stages() -> { PostStageReport }
The frame's post stages in frame order — lighting, medium,
preTemporal, temporal, postTemporal, meter, optics, display,
ui, output — each with the colour space an effect there reads and
writes (light, the scene's own light ahead of the display transform,
display, code values, or encoded, the presented surface's own values),
the resolution the picture is held at (raster, output, reduced, or
rasterToOutput for optics, whose render features run on the raster
and whose chain effects run on the picture the frame carried to the
output size), and the effects standing in it, in the order they run. A
render feature stands in the stage it declares (stage = "<name>" in its
module, or on the pass) or, placed by phase and order, in the stage that position falls
in: a phase ahead of afterLighting is lighting, an afterLighting
order the stage whose band holds it, afterScenePost display, and
afterUI and afterPost ui. A post-process chain effect stands in the
stage its layer runs in: scene in optics, display (with the display
transform at its head) in display, all in ui. output holds the
renderer's output stage __output__ alone: the one write of the
presented surface (renderer.output). Each effect says whether its
stage was declared (declared: by the feature, by the pass, or by the
chain registration) or the effect was placed, which is the report of
where a phase and order or a layer and priority put it.
Returns { PostStageReport } — The stages, each { name, space, resolution, single, runs, film, feature?, phases, chain?, effects }.
for _, s in ipairs(renderer.post.stages()) do
print(s.name, s.space, s.resolution, #s.effects)
end
typed/builtin//modules/api/engine/renderer/renderer/presentedFrames
renderer.presentedFrames(opts: { scope: string?, frames: number?, interval: number?, velocity: boolean? }?) -> { PresentedFrame }
Parameters
opts{ scope: string?, frames: number?, interval: number?, velocity: boolean? }(optional)
Returns { PresentedFrame }
typed/builtin//modules/api/engine/renderer/renderer/projectionJitter
renderer.projectionJitter() -> { { number } }
The offsets renderer.setProjectionJitter stated, each {x, y} in
pixels from the pixel centre.
Returns { { number } } — The offsets; empty while every render samples pixel centres.
local offsets = renderer.projectionJitter()
typed/builtin//modules/api/engine/renderer/renderer/projectionOffset
renderer.projectionOffset() -> (number, number)
The sub-pixel projection offset in force for the main camera, in NDC.
Returns (number, number) — The x and y offset, both 0 when the projection samples pixel centres.
local ox, oy = renderer.projectionOffset()
typed/builtin//modules/api/engine/renderer/renderer/qualityTier
renderer.qualityTier() -> QualityTier
The device's quality tier and the renderer defaults it chose. The
engine assigns every device one of "low", "medium" and "high" at
boot, from its GPU family and limits, its memory and its display, so a
world authored on a desktop plays on a phone at the phone's defaults
without knowing it runs on one. A desktop, and a touch screen over a GPU
with memory of its own, is "high": the renderer as a desktop runs it,
one scene pixel per display pixel. A handheld starts at the tier its GPU
affords (an emulator's or a virtual machine's GPU drawing from the
system's memory starts at "high") and is held lower by its memory and
its texture limit, so a 4 GB handheld is "low". A phone renders the
scene below a dense display's resolution with UI and text at full
resolution, and
spends less on shadows, textures and filtering the lower its tier; a
handheld's high tier bounds its shadows to its frame budget
(defaults.shadows). A lower
tier chosen on a desktop renders the scene within that tier's pixel
budget the same way, so renderer.setQualityTier alone is a whole
graphics setting on every platform.
Every default the tier states stands wherever the world's settings name no
value of their own (render.anisotropy, render.shadow_distance), and
the matching renderer call overrides any one of them:
renderer.setResolutionScale, renderer.setTextureBudget,
renderer.setAnisotropy, renderer.setShadowConfig.
renderer.setQualityTier chooses another tier altogether.
Returns QualityTier: { tier, deviceTier, overridden, reason, tiers, device, defaults }
local q = renderer.qualityTier()
print(q.tier, q.reason, q.defaults.resolutionScale)
print(q.defaults.shadows.distance, q.defaults.shadows.updateRate)
typed/builtin//modules/api/engine/renderer/renderer/rasterShading
renderer.rasterShading() -> boolean
Whether raster shading is enabled (renderer.setRasterShading).
Returns boolean
typed/builtin//modules/api/engine/renderer/renderer/rasterSize
renderer.rasterSize() -> { width: number, height: number }
The size the scene rasterized at in the frame just drawn, in pixels:
renderer.viewportSize() taken down by renderer.resolutionScale(). A
pass or a render target sized to the scene's own pixels is this size, and
a render feature's ctx.viewport reads it. Equal to
renderer.viewportSize() at a render scale of 1. { width = 0, height = 0 }
before the first frame has drawn.
Returns { width: number, height: number } in pixels.
local r = renderer.rasterSize(); local v = renderer.viewportSize(); print(r.width / v.width)
typed/builtin//modules/api/engine/renderer/renderer/raycast
renderer.raycast(origin: vec3, direction: vec3, maxDistance: number?, exclude: (string | { string })?) -> RenderRayHit?
Cast a ray against the geometry the renderer DRAWS and return the
nearest surface it meets. Every visible mesh answers, whether or not
anything gave it a rigid body — so a terrain, a procedurally generated
mesh, or any plain Model reports the surface at a point, which is what a
camera station, a prop, a sound source or a scatter standing on the ground
needs to know. The answer is the nearest triangle of the mesh, so a sloped
or terraced surface reports its height where it was asked rather than the
extent of its bounding box.
distance is measured from origin along the direction given, so it is a
world-space distance whenever that direction is a unit vector, and it is
directly comparable to a physics.raycast distance along the same ray.
normal is a unit vector turned to face back along the ray. exact is
true when the answer is a triangle and false when it is the object's
bounding box, which is what a mesh whose vertices live only in GPU buffers
answers with. The triangles are the mesh's own, placed by the entity's
transform and by the mesh's bind pose, so a surface a skinning or morph
pass deforms on the GPU answers as the geometry the mesh holds.
EVERYTHING drawn is in scope — the ground you meant, and equally a
character standing on it, a prop, a placeholder floor. The hit names its
entity in entityId, exclude steps over the ones you do not want, and
renderer.raycastAll hands back the whole column so you can pick the
surface yourself. A height you did not expect is usually a nearer surface
you did not mean to ask about, so read entityId before trusting a number.
Parameters
originvec3—vec3ray start in world spacedirectionvec3—vec3ray direction; any length, the engine normalisesmaxDistancenumber(optional) —number?how far the ray reaches, in world units. Default 1000exclude(string | { string })(optional) —(string | { string })?entity id, or ids, to step over
Returns RenderRayHit?
local hit = renderer.raycast({ x, 100, z }, { 0, -1, 0 }, 200)
if hit then entity(cameraId).position = { x, hit.point.y + 1.7, z } end
typed/builtin//modules/api/engine/renderer/renderer/raycastAll
renderer.raycastAll(origin: vec3, direction: vec3, maxDistance: number?, maxHits: number?, exclude: (string | { string })?) -> { RenderRayHit }
Cast a ray against the geometry the renderer draws and return every
surface along it, nearest first. One entry per renderable the ray crosses —
the nearest intersection with each — so a stack of surfaces reads as the
order they stand in, and a caller after one particular surface finds it by
entityId rather than hoping it is the nearest. Each entry carries the
fields renderer.raycast returns.
Parameters
originvec3—vec3ray start in world spacedirectionvec3—vec3ray direction; any length, the engine normalisesmaxDistancenumber(optional) —number?how far the ray reaches, in world units. Default 1000maxHitsnumber(optional) —number?how many surfaces to return. Default 32exclude(string | { string })(optional) —(string | { string })?entity id, or ids, to step over
Returns { RenderRayHit }
for _, hit in renderer.raycastAll(eye, look, 500) do print(hit.entityId, hit.distance) end
typed/builtin//modules/api/engine/renderer/renderer/raytraceCapability
renderer.raytraceCapability() -> string
The active ray-tracing backend: "hardware" (GPU ray query) or
"compute" (software traversal — the path on devices without hardware ray
query, e.g. the web). The same ray-tracing features work on both.
Returns string "hardware" | "compute"
if renderer.raytraceCapability() == "hardware" then ... end
typed/builtin//modules/api/engine/renderer/renderer/raytraceStats
renderer.raytraceStats() -> { [string]: any }
What the ray-tracing acceleration structure holds, and what this
session's frames have spent building it. A ray walks a structure built over
the scene's geometry, and keeping it current is work a frame pays before it
traces anything. On the "compute" backend geometry that has stood still
long enough is filed under a static partition the frames after it leave
alone: staticTriangles + dynamicTriangles = triangles, nodes is the
hierarchy over them, fullRebuilds / partialRebuilds / reusedFrames
count what the session's frames did, and trianglesRebuilt is what those
rebuilds re-emitted, summed. On the "hardware" backend blas is the
bottom-level structures cached, blasBuilt how many the last frame built,
and tlasInstances what the top-level structure names; tlasBuilds is how
many frames built it, and a frame whose instances all stand where the last
build put them builds nothing. The counters are
cumulative — sample, run the scene, sample again.
Returns { [string]: any } — table {backend, triangles, staticTriangles, dynamicTriangles, nodes, fullRebuilds, partialRebuilds, reusedFrames, trianglesRebuilt, blas, blasBuilt, tlasInstances, tlasBuilds}
local before = renderer.raytraceStats().trianglesRebuilt
typed/builtin//modules/api/engine/renderer/renderer/references
renderer.references(handleOrKind: any?, id: string?) -> RuntimeResourceStatus?
What holds a runtime resource right now — the answer a root scene load
reads before releasing it. references names each live consumer the engine
found: { by = "entity", id } for an entity wearing the material or mesh,
"material" for a material whose slot names the texture (or names a
texture array the device has not assembled from it yet), "instancedDraw",
"camera", "sky", "lightmap", "ui" (a screen drawing it),
"postProcess" (an effect sampling it) and "renderPass" (a pass a
render feature queued drawing into the texture, sampling it or waiting on
it, or running the material; id is the feature). handleHeld says
whether a script still reaches a handle to it, assetBacked whether an
asset stands behind it, ownerLive whether the component instance, scene
load or feature that created it still stands (a live component instance or
scene load holds what it created; a live feature holds it through the
handles it keeps and the passes it queues), ownerComponent and
ownerEntity the component
and the entity of a component instance that created it while that instance
stands, and held whether a hold pins it. origin reads
"device" for a GPU texture or mesh the device holds that no script
created (the texture the cache loaded for an asset, the mesh a .mesh
asset's :handle() uploaded, the atlas the engine built), whose
holders are the references, a handle and the asset. Runs a full garbage
collection first, the same one renderer.collect runs, so a handle nothing
reaches counts as let go and the row says what the next collection does
with the resource. Yields for the frame the census runs on.
Parameters
handleOrKindany(optional) — The resource's handle, or its kind with the id second.idstring(optional) — The guid or key, when the first argument is a kind.
Returns RuntimeResourceStatus? — The resource's status, or nil for a key the registry does not record and the device holds no texture or mesh under.
local s = renderer.references(mat) for _, r in s.references do print(r.by, r.id) end
typed/builtin//modules/api/engine/renderer/renderer/reflectionEnvironment
renderer.reflectionEnvironment() -> {
What a reflective surface is reflecting. probes is how many reflection
probes the shading blends; they are gathered highest priority first, each
rank taking the coverage the ranks above it left, so a small interior probe
ranked above the large exterior one it sits inside wins outright wherever it
reaches full weight. ranks is the priority each of those probe slots was
published with, in slot order. sky is whether the sky fallback is armed:
with it, coverage no probe claims reflects the captured sky, and without it
a surface outside every probe's radius falls back to the nearest probe
alone. skyCaptured is whether the sky slot holds a capture — arming is
refused until it does, since an uncaptured slot reflects black. skyStale
is whether the sky changed after that capture, so the slot still depicts
the sky from before the change until the engine's recapture, or an
explicit environment.captureSky(), retakes it. The engine retakes a sky
swapped for another material on the first frame the new sky can be drawn,
and a sky whose look or sun moved once a pacing window has passed since
the last capture. A scene that stops drawing a sky empties the slot and
disarms the fallback, so sky and skyCaptured read false; a sky drawn
again is captured from where the last one was and arms it, unless the
fallback was switched off. skyPosition is where the capture was taken
from, absent before one, and skySun the sun it was drawn under, as the
direction its light travels (the convention lighting.sun().direction
reads in), absent before one and for a capture of a scene drawing no sky.
skyCaptures counts the sky
captures that have landed since the renderer was built, so one retaken from
the same position reads as new, and skyMaterial names the material the
sky pass draws from, absent when no sky is drawn. skyDiffuse and
skyReflection are the strengths the slot's light is taken at, as
irradiance and as reflection: the ones the member that filled it stated
(environment.captureSky).
slots is how many cube slots the environment array holds right now: the
sky's alone, at index skySlot, until a camera states an environment (an
isolated capture, an asset preview), which adds the slot that environment is
held in, and once a probe is captured into it or placed, those two and one
per probe. maxProbes is how many of them probes may
take, and resident whether the array has grown past the sky's single
slot. Capture the sky with environment.captureSky().
Returns { probes, ranks, sky, skyCaptured, skyStale, skyPosition?, skySun?, skyCaptures, skyDiffuse, skyReflection, skyMaterial?, resident, slots, skySlot, maxProbes }
local env = renderer.reflectionEnvironment()
print(("%d probes, sky fallback %s"):format(env.probes, tostring(env.sky)))
typed/builtin//modules/api/engine/renderer/renderer/release
renderer.release(handleOrKind: any?, id: string?) -> boolean
Let go of the hold renderer.hold placed. The resource stays until
nothing else holds it and a collection releases it — the one a root scene
load runs, or a direct renderer.collect(). A runtime texture, material,
mesh or render feature no script reaches a handle to is judged again once
its hold goes, and released with no collection when nothing else holds it.
Parameters
handleOrKindany(optional) — The resource's handle, or its kind with the id second.idstring(optional) — The guid or key, when the first argument is a kind.
Returns boolean true when the registry knows the resource.
renderer.release(tex)
typed/builtin//modules/api/engine/renderer/renderer/releaseBaseline
renderer.releaseBaseline(generation: number) -> boolean
Drop the mark generation names, and every mark taken after it, once
the caller that took it is done resetting to it. It touches the
marks alone.
Parameters
generationnumber— The mark to drop, asrenderer.markBaselinereturned it.
Returns boolean — True when the mark stood.
renderer.releaseBaseline(mark) -- the run is over
typed/builtin//modules/api/engine/renderer/renderer/renderTargetLimits
renderer.renderTargetLimits() -> {
The size a render target may be on this device. maxDimension is the
device's own maximum 2D texture dimension — the largest either side of a
render target may take. maxPixels is how many pixels one render target
may hold, so the RGBA8 image it reads back as fits in a single buffer on
every platform the engine runs on, and maxSquare is the largest square
that budget buys. A capture, a renderer.texture.create({ width, height })
or a render-to-texture camera past either bound is refused at the call with
the reason, so ask here for the size to request.
Returns { maxDimension, maxPixels, maxSquare }
local lim = renderer.renderTargetLimits()
local w = math.min(want, lim.maxSquare)
typed/builtin//modules/api/engine/renderer/renderer/renderTargets
renderer.renderTargets() -> {
Every render target the renderer owns and what each one costs, measured
from the texture that is allocated. One row per target, each carrying its
name, whether it is resident, the bytes it holds while it is, its
width/height/layers/mipLevels, and onDemand.
An onDemand target exists only while something needs it: a target nothing
writes into reads resident = false and bytes = 0 and appears again the
frame something writes it, and one sized by content (the reflection-probe
cube array) holds the slots content asked for. The scene's occlusion, sun
occlusion and reflection channels and its lit colour history
(scene_occlusion, scene_sun_occlusion, scene_reflection,
scene_color_history) are resident at the scene's
extent while a render-feature pass writes or reads them, and
shadow_page_pool while a light casts into the virtual shadow map, with
shadow_transmittance_pool beside it while a translucent caster casts
into it.
The scratch the draws into
a render target have needed is reported as camera[<handle>].* rows:
depth and motion vectors under any rasterized pass, and the occlusion, sun
occlusion, reflection and colour-history channels, the scene copies and the G-buffer
over them under a camera's scene render. A draw builds what it needs, or
takes the scratch a released target of the same size left. A target
releases its set to the next target of its size when no live camera names
it and when it is destroyed or resized, and frees it once sixty frames
pass without a draw, so a target nothing draws into carries no such row.
Released scratch waits as
released_scratch[<width>x<height>].* rows for the next target of that
size, held newest first within 64 MiB and freed once sixty frames pass
without a target taking it. The colour image drawn into belongs to the
texture cache while its target stands; a destroyed or resized target's
colour texture waits on the same terms as a
released_scratch[<width>x<height>].color row for the next target made at
that size and format, which starts from it cleared to transparent black.
totalBytes is what the resident targets hold together. allocations
counts the render-target allocations the renderer has made since it was
built, the colour textures of the live targets included, each on the first
frame whose report holds it: a target taken back
at a size it held before adds nothing, so the difference between two
readings is what the frames between them allocated. Measured at the end of
the last rendered frame.
Returns { targets, totalBytes, residentCount, allocations }
local rt = renderer.renderTargets()
print(("render targets: %.1f MiB over %d resident"):format(rt.totalBytes / 1048576, rt.residentCount))
for _, t in rt.targets do
if t.onDemand then print(t.name, t.resident, t.bytes) end
end
typed/builtin//modules/api/engine/renderer/renderer/resetToBaseline
renderer.resetToBaseline(generation: number?) -> number
Parameters
generationnumber(optional)
Returns number
typed/builtin//modules/api/engine/renderer/renderer/resolutionScale
renderer.resolutionScale() -> number
The fraction of the display resolution the scene is currently rendered
at. Until something sets it, the scale the device's quality tier chose for
its display (renderer.qualityTier().defaults.resolutionScale): 1 on a
desktop at the high tier, below 1 on a dense handheld display and on a
desktop at a lower tier.
Returns number
local s = renderer.resolutionScale()
typed/builtin//modules/api/engine/renderer/renderer/resolutionScaleMode
renderer.resolutionScaleMode() -> string
Where the render scale resolves: "present" or "reconstruct".
"present" until something sets it.
Returns string
local m = renderer.resolutionScaleMode()
typed/builtin//modules/api/engine/renderer/renderer/sceneLighting
renderer.sceneLighting() -> boolean
Whether the scene states that it renders lit: the newest statement
made with renderer.setSceneLighting, or true when none stands.
Returns boolean — The scene's statement.
if not renderer.sceneLighting() then print("this scene renders unlit") end
typed/builtin//modules/api/engine/renderer/renderer/setAnisotropy
renderer.setAnisotropy(level: number) -> number
Set the maximum anisotropy material textures are sampled with. Takes effect on the next frame for content already on screen — no reload, no texture re-upload. 1 is plain trilinear.
Parameters
levelnumber— One of 1, 2, 4, 8, 16. Any other value is an error.
Returns number — The EFFECTIVE level after clamping to renderer.maxAnisotropy(), so asking for more than the device offers reports what was actually applied.
renderer.setAnisotropy(16)
typed/builtin//modules/api/engine/renderer/renderer/setBlendedBatching
renderer.setBlendedBatching(enabled: boolean) -> ()
Whether neighbours in a view's back-to-front blended order draw
together. On by default: alpha-blended geometry is submitted farthest-first,
and a stretch of neighbours in that order sharing a mesh, a material, a
shader and a pose is submitted as one instanced draw over those neighbours,
which puts the same members on screen in the same order out of a single
submission. A run stops wherever a differently-drawn renderable sorts
between two of its members, and a mesh of several primitives keeps a draw
per renderable — both would otherwise move fragments through each other.
Off, every blended renderable draws on its own at its own slot, so a
transparent crowd costs a draw per member. The image is the same either way,
which is what makes this the comparison a frame suspected of being formed by
the batching is made against; renderer.drawStats().draws counts the
difference.
Parameters
enabledboolean—boolean
Returns ()
renderer.setBlendedBatching(false) -- a draw per blended renderable
typed/builtin//modules/api/engine/renderer/renderer/setDrawEveryFrame
renderer.setDrawEveryFrame(everyFrame: boolean) -> boolean
Draw every frame continuously (true), or redraw only while there
is something new to show (false, the default), so an idle screen whose
picture stands still is not redrawn.
By default a renderer presenting to a display draws while what is on
screen changes (the UI, the camera, a renderable, a material, a light, an
animation, a texture, the window) and for a short settling run after the
last change, then declines the frames of a still picture, which stays on
screen. While anything else moves (the gameplay clock, a task owed the
next frame, held input, a tool call in flight) the frames keep running at
the display's rate while it declines, and an engine that is still waits
for the next arrival or timer instead (renderer.framePacing().engineStill);
the next change is drawn on the frame after it. On a phone that is the GPU work, the heat and the battery
of every frame an idle menu or a paused editor would otherwise redraw. A
headless renderer draws while something reads its frames.
true draws every frame on every renderer, for content whose picture
changes in a way the engine does not see, or that is measured frame by
frame. renderer.framePacing() reports the rule in force (drawPolicy),
whether the last frame was drawn (producing), the frames declined
(idleSkippedFrames) and what woke the renderer (pictureChanges,
lastPictureChange). Takes effect on the next frame. draw_every_frame
under [render] in the world's .world_settings seeds it, so a world
states it once; a call here stays in force until that value changes.
Parameters
everyFrameboolean— boolean true to draw every frame, false to draw only frames that show something new.
Returns boolean — The setting in force.
renderer.setDrawEveryFrame(true) -- a benchmark measures every frame
print(renderer.framePacing().drawPolicy) --> every_frame
renderer.setDrawEveryFrame(false) -- back to drawing changes only
typed/builtin//modules/api/engine/renderer/renderer/setFrameRateCap
renderer.setFrameRateCap(fps: number?) -> number?
Hold the engine to at most fps frames per second, or lift the cap
with 0 or nil. The whole frame waits for its turn: scripts, physics, audio
mixing and networking run once a frame as the drawing does, so a game
capped at 30 runs at 30, and a phone spends no battery on frames past it.
Frames come due on an even grid. Where the display's refresh rate is known
(a phone's panel, a desktop window's monitor, a browser's animation
frames), the grid is a whole number of refreshes, the fewest whose rate
stays inside the cap, so every frame stays on screen for the same number
of vsyncs: on a 120 Hz display a cap of 30 shows each frame for 4
refreshes and 60 for 2, and a cap the refresh rate does not divide evenly
delivers the next rate below it (50 on a 120 Hz display delivers 40). On
Android the system compositor is told the rate as well, so a panel with
more than one refresh rate can run at one the cap divides. On a display
that shows frames on its vsync the cap is the highest rate the engine
chooses (renderer.setFrameRateMode): frames that cannot hold it run at
the next even rate below.
Read renderer.framePacing() for the effect: targetFps is the rate the
cap delivers, refreshesPerFrame the refreshes each frame holds,
displayRefreshHz the display it was worked out against, and
deliveredFps the rate frames actually ran at. Takes effect on the next
frame. frame_rate_cap under [render] in the world's .world_settings
seeds it (0 for no cap), so a world states its cap once and every session
opens under it; a call here stays in force until that value changes.
Parameters
fpsnumber(optional) — number? Frames per second, 1 through 1000; 0 or nil lifts the cap.
Returns number? — The cap in force, or nil when frames are not capped.
renderer.setFrameRateCap(30) -- a steady 30 on any display 30 divides
print(renderer.framePacing().targetFps, "fps delivered under the cap")
renderer.setFrameRateCap(nil) -- every frame the display shows
typed/builtin//modules/api/engine/renderer/renderer/setFrameRateMode
renderer.setFrameRateMode(mode: string) -> string
Choose how the engine picks the frame rate it runs at on a display
that shows each frame on a vsync (presentMode fifo, fifo_relaxed or
auto_vsync: a phone, a browser tab, a desktop window set to fifo).
adaptive, the default, runs at the highest rate the display shows
evenly that the frames sustain, at most the cap
(renderer.setFrameRateCap; the display's highest refresh rate without
one). A frame that cannot hold 120 on a 120 Hz panel runs at an even 60
rather than at 60 to 67, one that cannot hold 60 at 40, never below 30,
and the rate goes back up once the frames hold a faster one again (in one
step after a load). fixed holds the
cap's rate (the display's highest rate without a cap) whatever the frames
take, for content that needs one set rate.
In both modes every frame is due on its own vsync, so the engine makes no
frame the display has no refresh to show. On Android the display is asked
for the lowest of its modes the chosen rate divides into whole refreshes,
so a panel whose frames come at 60 can run at 60 Hz and spend less power;
a desktop window and a browser hold frames to their
display by pacing alone. On a mailbox surface the loop is held to the
cap, or with none to one frame per refresh of the mode the display runs
in now, and a frame that takes longer runs as soon as it is ready; under
immediate or auto_no_vsync, or with no display, the cap alone holds
the loop. renderer.framePacing() reports the mode
(frameRateMode), the rate chosen (chosenFps), why (frameRateReason),
the time frames take (frameWorkMs) and what the display was told
(displayVote, displayVoteFps). Takes effect on the next frame.
frame_rate_mode under [render] in the world's .world_settings seeds
it; a call here stays in force until that value changes.
Parameters
modestring— string "adaptive" or "fixed".
Returns string — The mode in force.
renderer.setFrameRateCap(120) -- a game that wants 120 where frames hold it
renderer.setFrameRateMode("adaptive")
print(renderer.framePacing().chosenFps, renderer.framePacing().frameRateReason)
renderer.setFrameRateMode("fixed") -- hold the cap's rate whatever frames take
typed/builtin//modules/api/engine/renderer/renderer/setGpuMemoryTracking
renderer.setGpuMemoryTracking(frames: number?) -> number
Set how often the GPU allocator sampler reads — one reading every
frames frames the renderer runs, drawn or declined — or turn it off
with 0. It starts at 60, a reading a
second at 60 Hz, so renderer.gpuMemory().allocator answers without
anything arming it. It reads while something reads renderer.gpuMemory()
or the memory report, for ten seconds after the last such read. Building
the ledger walks every live allocation, which is why it is sampled rather
than read every frame; the category figures cost nothing either way, and a
reader between samples sees the most recent ledger, so a slow interval
still answers.
Called with no argument it reports the interval in force and changes nothing, which is how something that retimes the sampler puts it back afterwards instead of restoring a number it assumed was the default.
Parameters
framesnumber(optional) —number?Frames between readings; 0 turns the sampler off. Omit to read the interval without changing it.
Returns number — The interval now in force.
renderer.setGpuMemoryTracking(60)
local was = renderer.setGpuMemoryTracking()
renderer.setGpuMemoryTracking(1)
-- ... take a tight reading ...
renderer.setGpuMemoryTracking(was)
typed/builtin//modules/api/engine/renderer/renderer/setLighting
renderer.setLighting(enabled: boolean) -> ()
Turn the scene's lighting on or off for this viewer. Off, every lit
surface renders as its own colour with no light on it, emissive included:
the editor's lighting toggle, for reading a scene's materials without its
lights. With no light applied there is no shadow either, so the shadow
maps draw nothing while it is off, and the shadow switches apply again once
lighting is back on. The sky and post-processing stay as they are. It is
local to this engine and never saved; lighting is on while this and what
the scene states (renderer.sceneLighting) are both on.
Parameters
enabledboolean—truerenders the scene lit,falseunlit.
Returns ()
renderer.setLighting(false); print(renderer.lighting())
typed/builtin//modules/api/engine/renderer/renderer/setLocalLayers
renderer.setLocalLayers(target: any?, layers: string?)
Draw an entity's meshes on the render layers named in layers, in this
engine only. The entity's own RenderLayer is untouched, so what other
peers draw it on does not change and nothing is saved. The layers replace
the entity's own for every camera of this engine, so a camera draws the
entity when its include set holds one of them. Only the entity's own meshes
are affected, not its descendants'. Pass nil to draw it on its own layers
again.
Parameters
targetany(optional) — The entity, as an id or a proxy.layersstring(optional) — A space-separated list of layer names, or nil.
renderer.setLocalLayers(hat, "xrSelf") -- the hat draws on `xrSelf` here and nowhere else
renderer.setLocalLayers(hat, nil)
typed/builtin//modules/api/engine/renderer/renderer/setMaxFramesInFlight
renderer.setMaxFramesInFlight(frames: number) -> number
Set how many frames of GPU work may be outstanding before the renderer stops running ahead. One is the least overlap this can express — a frame's work is waited for as soon as the next frame has been submitted — which is the lowest latency and the lowest throughput; higher values let a slow frame build a longer backlog, and that backlog is memory. Takes effect on the next frame.
Answers the bound after clamping to [1, 8], so asking for more than the renderer honours reports what you actually got.
Parameters
framesnumber— number Frames of GPU work that may be outstanding, 1 through 8.
Returns number — The bound that took effect, after clamping.
renderer.setMaxFramesInFlight(1) -- lowest latency
print(renderer.setMaxFramesInFlight(99), "was clamped")
typed/builtin//modules/api/engine/renderer/renderer/setMaxTextureSize
renderer.setMaxTextureSize(px: number?) -> { px: number, devicePx: number }
The longest side a texture loaded from an asset may be resident at on this client, in texels. Such a texture larger than the cap is served from the first level of its mip chain that fits, so a 4096² texture under a 1024 cap holds its 1024² level and the levels below it, and the texture budget never takes it finer than that level. A changed cap moves the resident textures over the next frames; a raised one reads their finer levels back from their assets. A texture made from pixels with no asset behind it keeps every level it was made with, because the device holds its only copy. The device's own maximum 2D texture dimension bounds the cap from above. Call with no argument to lift the cap to the device's limit.
Parameters
pxnumber(optional) —number?— texels, a whole number of at least 1; nil for the device's own limit
Returns { px: number, devicePx: number } — { px, devicePx } — the cap in force and the device's limit
renderer.setMaxTextureSize(2048)
renderer.setMaxTextureSize() -- the device's own limit
typed/builtin//modules/api/engine/renderer/renderer/setMinScreenSize
renderer.setMinScreenSize(pixels: number) -> ()
Stop drawing an object once its on-screen radius falls below this many
pixels. A few pixels across, an object carries no detail a viewer can
resolve while still costing a full vertex and submission pass, and the
cutoff drops it from the camera's draws entirely — 0, the default,
keeps every object however small it lands. Measured from the object's own
bounds against the camera's projection, so the same threshold means the
same apparent size at any distance or field of view. Shadow casters have
their own threshold in renderer.setShadowCasterCutoff.
Parameters
pixelsnumber—number— smallest on-screen radius still drawn; 0 disables.
Returns ()
renderer.setMinScreenSize(4) -- drop anything under 4 px of radius
print(renderer.drawStats().compactedDrawn, "instances survived it")
typed/builtin//modules/api/engine/renderer/renderer/setOcclusionCulling
renderer.setOcclusionCulling(enabled: boolean) -> ()
Enable or disable occlusion culling. While enabled the renderer reduces the depth the visibility raster lays into a pyramid each frame and tests every renderable that cleared the frustum against it, dropping the ones another surface entirely covers before their geometry is submitted. The pyramid describes the frame being drawn, so an object that becomes visible this frame is never held back a frame. On by default, so a dense scene (a street, an interior, a forest) draws what is visible with no call; turn it off to submit every renderable that clears the frustum, as a comparison for what the test saves.
Parameters
enabledboolean—boolean
Returns ()
renderer.setOcclusionCulling(false); print(renderer.occlusionCulling()) -- false
typed/builtin//modules/api/engine/renderer/renderer/setPictureSize
renderer.setPictureSize(width: number, height: number) -> { width: number, height: number }
Draw the game's picture at this many pixels for the rest of the
task that asks. While a Scene panel presents the scene inside the window
(an editor layout), the window keeps its size and the picture is drawn
at this size, standing for the screen of a device this many pixels
across: the panel shows it at its shape, scaled to fit, and the camera's
canvas (ui.screenSize(), ui.safeArea(), the canvas the touch
controls draw on) is laid out the way a window of this size lays its UI
out. So the panel shows what that device shows, and with
ui.simulateSafeArea and ui.simulateDisplayScale its notch, bars and
density too. A pointer or a touch over the panel's picture reads in the
picture's own pixels, the space worldToScreen and inputSim with
target "game" speak (camera.viewData().viewport states the scale
the picture is shown at). Where the scene fills the window the picture
is the window, and this resizes the drawing surface as
renderer.setViewportSize does.
Everything measured against the picture follows within a frame:
getViewportSize(), ui.screenSize(), the layout every game screen
rebuilds from it, each camera's aspect, and what a capture taken in that
task encodes; renderer.pictureSize() reads it. The size is held for
the task that asked for it (an execute call is one task): when that
task ends, however it ends, the picture goes back to the panel's own
size. While several tasks hold a size the picture draws at the one asked
for last. Asked for outside any task, the size stands until another is
asked for or until no Scene panel presents the picture. A size larger
than the device draws is refused naming the bound.
Parameters
widthnumber—number— width in pixels, at least 1.heightnumber—number— height in pixels, at least 1.
Returns { width: number, height: number } — the size asked for, in whole pixels.
renderer.setPictureSize(390, 844); task.waitFrames(2); print(ui.screenSize()) -- an upright phone's screen in the Scene panel, for the rest of the call
typed/builtin//modules/api/engine/renderer/renderer/setPresentMode
renderer.setPresentMode(mode: string) -> string
Set how a presented frame reaches the display. fifo queues every frame
and shows it on a vertical blank, which never tears and never drops one;
mailbox replaces the queued frame with the newest, which does not tear
and never blocks the frame loop, which makes its frames at the display's
refresh rate (or the cap) and a frame that takes longer as soon as it is
ready; immediate presents as soon as a frame is ready and can tear;
fifo_relaxed is fifo that tears rather than stall when a frame misses
its blank; auto_vsync and auto_no_vsync leave the choice to the
backend. Under immediate and auto_no_vsync the frame loop runs every
frame it is ready for unless a cap holds it, whichever mode the backend
picks for auto_no_vsync, so they are the modes for measuring how fast
frames can run: a surface that does not offer immediate presents fifo
in its place, and every surface takes auto_no_vsync.
A surface that does not offer the mode presents fifo instead, so read
renderer.framePacing().presentMode for what took effect and
.presentModes for what this surface offers. Takes effect on the next
frame.
Parameters
modestring— string One of "fifo", "fifo_relaxed", "mailbox", "immediate", "auto_vsync", "auto_no_vsync".
Returns string — The canonical spelling of the request — renderer.framePacing().presentMode is what the surface presents with, and differs when the surface does not offer the request.
renderer.setPresentMode("mailbox")
print(renderer.framePacing().presentMode, "is what the surface took")
typed/builtin//modules/api/engine/renderer/renderer/setProjectionJitter
renderer.setProjectionJitter(offsets: { { number } })
State where inside the pixel consecutive renders of a view sample, for
the frames until it is stated again: a list of {x, y} offsets in pixels
from the pixel centre, each within half a pixel. Every view the renderer
draws (the viewport, each render-to-texture camera, each capture) walks the
list by its own count of renders in a row, so a camera drawn beside the
viewport takes nothing out of the viewport's sequence: a view's first
render, and its first after a cut, samples the pixel centre, and its next
renders take the offsets in order, wrapping. Each offset is applied in the
view's own pixels. Velocity (@scene.motion) is measured against the
offset-free projection, and a history target's state buffer carries the
offset each render took. renderer.setProjectionOffset, while it is not
(0, 0), and an upscale backend's own jitter both stand over the list on
the viewport. An empty list samples pixel centres. An offset outside half
a pixel is refused, naming it, and leaves the list in force.
Parameters
offsets{ { number } }— The offsets, each{x, y}in pixels from the pixel centre.
renderer.setProjectionJitter({ { 0.25, -0.25 }, { -0.25, 0.25 } })
typed/builtin//modules/api/engine/renderer/renderer/setProjectionOffset
renderer.setProjectionOffset(x: number, y: number)
Offset the main camera's projection by a sub-pixel amount, in NDC, for
the frames until it is set again. The offset is in NDC because that is the
space it is constant in: one pixel is 2.0 / width across, so half a pixel
is 1.0 / width. Velocity (@scene.motion) is measured against the
offset-free projection, so a still scene reports no motion however the
samples are placed — and picking resolves a click to the same ray either
way. (0, 0) samples pixel centres.
Parameters
xnumber— Horizontal offset in NDC. One pixel is2.0 / width.ynumber— Vertical offset in NDC. One pixel is2.0 / height.
renderer.setProjectionOffset(0.5 * 2 / w, -0.25 * 2 / h)
typed/builtin//modules/api/engine/renderer/renderer/setQualityTier
renderer.setQualityTier(tier: string?) -> QualityTier
Render at another quality tier than the one the device was assigned:
"low", "medium" or "high", or nil / "default" for the device's
own. A change of tier stands the new tier's defaults at once wherever
the world's settings state none, replacing what an earlier renderer call
set for the render scale, the anisotropy and the sun's shadow distance
(the other shadow settings renderer.setShadowConfig states stand until
set back to "default"); choosing the tier already in force changes no
setting. A call
made after it, in the same script or later, overrides that one default
again. A budget renderer.setTextureBudget names stands over the tier's
texture cap until it is returned to the device's own. The choice holds for the
process, across scene loads and restarts of the scene, until it is set
again. A settings screen offering the player a quality choice is this call.
Parameters
tierstring(optional) —string?:"low","medium","high", ornil/"default"for the device's own.
Returns QualityTier: the reading renderer.qualityTier() answers, for the tier now in force.
renderer.setQualityTier("low")
renderer.setQualityTier() -- back to the device's own
typed/builtin//modules/api/engine/renderer/renderer/setRasterShading
renderer.setRasterShading(enabled: boolean) -> ()
Enable or disable raster shading. While enabled, an opaque object whose
triangles the main view shows at a thousand pixels each or more (a ground,
a wall, a near crate) is shaded by rasterizing it again over the depth the
visibility raster laid, instead of through the material resolve, in every
camera view; its shadow is drawn from its clusters either way. The resolve
rebuilds each pixel's surface from its triangle's three corners, which a
raster pays for once a vertex, so a surface of large triangles shades for
less this way, and its pixels come out the same. A surface of many small
triangles stays on the resolve. On by default; renderer.observe reports
an object shaded this way under the legacy lane.
Parameters
enabledboolean—boolean
Returns ()
renderer.setRasterShading(false); print(renderer.drawStats().pixelsResolved)
typed/builtin//modules/api/engine/renderer/renderer/setRaytrace
renderer.setRaytrace(enabled: boolean) -> ()
Enable or disable GPU ray tracing. While enabled the engine builds the scene acceleration structure each frame so ray-tracing render features can trace against it; disabling stops the build (so it costs nothing until a ray-traced effect is active). Required before any ray-traced shadows / AO / reflections render.
Parameters
enabledboolean—boolean
Returns ()
renderer.setRaytrace(true); renderer.feature.create("rt_shadows")
typed/builtin//modules/api/engine/renderer/renderer/setResolutionScale
renderer.setResolutionScale(scale: number) -> number
Render the scene at a fraction of the display's resolution. Shading cost
scales with pixel count and with nothing else, so this trades sharpness for
frame time without taking anything out of the scene: at 0.5 the scene
rasterizes a quarter of the pixels. What the smaller raster MEANS for
everything composed on top of it — the post chain, the UI, every post-scene
pass — is renderer.setResolutionScaleMode. The scene rows in
profiler.gpuFrame() are what move.
Parameters
scalenumber—number— fraction of the display resolution, clamped to [0.25, 1].
Returns number — the scale in force after clamping.
renderer.setResolutionScale(0.7)
typed/builtin//modules/api/engine/renderer/renderer/setResolutionScaleMode
renderer.setResolutionScaleMode(mode: string) -> string
Where in the frame the render scale is resolved — what a smaller raster
MEANS. "present" (the default) composes the whole frame at the raster: the
scene, every post-process layer, the UI and every post-scene pass, carried
up to the size it is shown once it is finished. A smaller raster is then a
smaller picture, so an effect whose output is a function of pixel size — a
dither ladder, a posterize, a pixel grid — resolves at the pitch it was
authored at, and the frame carries one composite resolution throughout.
"reconstruct" carries the scene up to the size it is shown BEFORE the
post-scene phases and composes everything from there, which is what a
temporal upsampler needs: it refines the upscale it is handed and has
nowhere to put the detail it recovers unless the image it accumulates into
is the display's. Either reading is honoured identically whether a viewport
panel or the swapchain shows the frame, so what an editor draws and what a
shipped runtime draws are the same picture of the same scene.
Parameters
modestring—string—"present"or"reconstruct".
Returns string — the mode in force.
renderer.setResolutionScaleMode("present")
typed/builtin//modules/api/engine/renderer/renderer/setSceneLighting
renderer.setSceneLighting(owner: string, enabled: boolean?) -> ()
State, for an owner, whether the scene renders lit: a scene that is
unlit on purpose (a stylised game, a menu) states false. The newest
statement is in force; nil withdraws the owner's statement, and with none
standing the scene renders lit. Composed with this viewer's
renderer.setLighting: lighting is on while both are on.
Parameters
ownerstring— Who states it: a key the caller forms from something only it holds.enabledboolean(optional) —falsefor unlit,truefor lit,nilto withdraw.
Returns ()
renderer.setSceneLighting("menu", false)
typed/builtin//modules/api/engine/renderer/renderer/setShadowCaching
renderer.setShadowCaching(enabled: boolean) -> ()
Whether a shadow page that nothing changed is kept rather than drawn again. On by default: every light's pages — the sun's, and each spot, area and point light's — are drawn again only where a caster that changed reaches them. Off, every requested page is invalidated and drawn on every pass, which is what a shadow suspected of holding a stale image is compared against.
Parameters
enabledboolean—boolean
Returns ()
renderer.setShadowCaching(false) -- draw every requested shadow page, every frame
typed/builtin//modules/api/engine/renderer/renderer/setShadowCasterCutoff
renderer.setShadowCasterCutoff(cfg: {
minRadiusPx: number?,
maxDistance: number?,
}) -> ShadowCasterCutoff
Set the shadow-caster cutoff. An omitted field keeps its current value,
so a call can adjust one threshold without restating the other. Both are
measured against the camera the frame draws from rather than against each
light, so one setting covers every light's pages, and a
caster that stops casting is one whose shadow the viewer could not have
resolved. maxDistance is measured to the near side of the caster's
bounding sphere, so a large object keeps casting while any part of it is in
range. 0 releases a threshold; releasing both draws the casters the frame
drew before either was set.
Parameters
cfg{ minRadiusPx: number?, maxDistance: number?, }— The fields to change —minRadiusPxand/ormaxDistance.
Returns ShadowCasterCutoff — The cutoff now in force.
renderer.setShadowCasterCutoff({ minRadiusPx = 2 })
renderer.setShadowCasterCutoff({ minRadiusPx = 1.5, maxDistance = 120 })
typed/builtin//modules/api/engine/renderer/renderer/setShadowConfig
renderer.setShadowConfig(cfg: {
distance: number?,
fadeFraction: number?,
softness: number?,
punctualMipFloor: number?,
detailBias: (number | string)?,
budgetMegabytes: (number | string)?,
pagesPerUpdate: (number | string)?,
updateRate: (number | string)?,
filter: string?,
localLights: (boolean | string)?,
}) -> ShadowConfig
Set the sun's shadow settings. Any omitted field keeps its current
value, so a call can adjust one knob without restating the rest. Values are
clamped: distance >= 0, fadeFraction [0, 1], softness [0, 1]. A distance
of 0 shadows out to the camera's far plane, and a positive one caps it,
which is what a scene bounding its shadow cost states; the sun's clipmap
holds the levels that reach it. punctualMipFloor (a whole number, 0 to
5) caps how fine a spot, area or point light's map renders; it is refused
outside that range, and every punctual light's map is drawn again under a
new floor. detailBias ([-8, 8] levels) trades
shadow detail for pages: each level coarser asks a quarter as many.
budgetMegabytes (>= 1) bounds the depth the pages hold. Each takes
"default" to return to the quality tier's, and a change to either sizes
the pool again, which draws every page again. pagesPerUpdate (a whole
number, 0 for every page) bounds the pages one run draws, the rest
following on later runs. updateRate (0 to 1000 a second) is the most
times a second the main camera's shadow pages, the sun's and every
local light's, are marked, culled and drawn,
0 drawing them on every frame: a frame that comes sooner than the rate
allows samples the pages the last update left, so a display running
faster than the rate updates its shadows at the rate and one running
slower on every frame. filter is "wide" (four rotated gathers over 4x4
texels) or "narrow" (one gather over 2x2, a quarter of the texture
reads at a harder edge), for the fixed edge a softness of 0 draws; a
softness above 0 widens the penumbra with the wide filter's kernel
under either. localLights is whether spot, area and point
lights that ask to cast shadows draw one. Each of these four also takes
"default" for the quality tier's
(renderer.qualityTier().defaults.shadows).
Parameters
cfg{ distance: number?, fadeFraction: number?, softness: number?, punctualMipFloor: number?, detailBias: (number | string)?, budgetMegabytes: (number | string)?, pagesPerUpdate: (number | string)?, updateRate: (number | string)?, filter: string?, localLights: (boolean | string)?, }— The fields to change — seeShadowConfig.
Returns ShadowConfig — The full config now in force.
renderer.setShadowConfig({ softness = 0.65, fadeFraction = 0.28 })
renderer.setShadowConfig({ distance = 240 })
renderer.setShadowConfig({ detailBias = 1, budgetMegabytes = 8 })
renderer.setShadowConfig({ detailBias = "default", budgetMegabytes = "default" })
renderer.setShadowConfig({ updateRate = 0, filter = "wide" })
typed/builtin//modules/api/engine/renderer/renderer/setShadowHero
renderer.setShadowHero(entity: string, padding: number?) -> ()
Give one caster a finer sun shadow, in a box around its world bounds.
The sun's virtual shadow map resolves every receiver at the level its
screen footprint selects, so a character standing in the view gets the
texel density every surface at its distance gets. A registered hero widens
its bounds by padding into a box, and every receiver inside it requests
and samples a level renderer.shadowHero().levelBias levels finer — each
level halving the world a texel covers — where that level's window holds
it, crossing back to its footprint's level at the box's edge. Nothing else
about the shadow changes: the same casters reach it through the same
filter.
Parameters
entitystring— The entity whose renderables the box is made around.paddingnumber(optional) — How much room the box leaves around those bounds — for a pose that leaves the bind-pose box and for the filter that samples outside a silhouette. 1.0 holds them exactly.
Returns ()
local before = time.drawnFrameCount()
renderer.setShadowHero(player.id)
local h = renderer.shadowHero()
while h.frame <= before do
task.waitDrawnFrames(1)
h = renderer.shadowHero()
end
print(("hero shadow: %d levels finer over %.1f units"):format(h.levelBias, h.worldExtent))
typed/builtin//modules/api/engine/renderer/renderer/setShadowProxy
renderer.setShadowProxy(mesh: string, proxy: string) -> ()
Rasterize proxy in place of mesh in every shadow page. A shadow is a
silhouette resolved at the resolution of a shadow map, so the triangles that
carry a mesh's close-up detail write depth no reader can resolve — a
decimated version of the shape, a level of its own LOD chain, or a
hand-built hull casts the same shadow for a fraction of the geometry.
The registration is keyed by MESH, so one call covers every instance of it — entities and GPU-driven populations alike — and a crowd sharing that mesh stays one draw. The proxy is placed by whatever places the caster, its instance's own transforms, so it stands where the caster stands, at the caster's scale.
An entity caster keeps its own geometry where a stand-in could not be placed
or deformed correctly: it is skinned (it rasterizes the post-skinned
vertices written for its own mesh), it blends morph targets (whose deltas
describe its own mesh and are read by vertex id), or its proxy would be
placed by a different node of its model than the source mesh is. Either
caster keeps it where the renderer holds no geometry under the proxy's
guid. Each of those is counted in renderer.shadowProxies().
Nothing else in the scene draws a proxy, so this call is what brings it onto the GPU, and it raises where it cannot. A proxy already resident there is registered as it stands.
Parameters
meshstring— The mesh a caster draws, as a guid or any mesh reference.proxystring— The mesh it rasterizes into shadow pages instead.
Returns ()
renderer.setShadowProxy(statueMesh, statueHullMesh)
print(renderer.shadowProxies().triangles, "vs", renderer.shadowProxies().sourceTriangles)
typed/builtin//modules/api/engine/renderer/renderer/setSkinnedBatching
renderer.setSkinnedBatching(enabled: boolean) -> ()
Whether skinned instances holding one pose draw together. On by default:
instances of one mesh wearing one material and posed alike read the same
post-skinned vertices, so the camera's colour passes submit them as a single
instanced draw. Off, each
skinned instance draws on its own at its own slot in every pass that
rasterizes it. The image is the same either way, which is what makes this
the comparison a frame suspected of being formed by the batching is made
against — renderer.drawStats().draws counts the difference and
renderer.skinningStats().poses says how many distinct poses it holds.
Parameters
enabledboolean—boolean
Returns ()
renderer.setSkinnedBatching(false) -- a draw per skinned instance
typed/builtin//modules/api/engine/renderer/renderer/setSkinningPoseHold
renderer.setSkinningPoseHold(enabled: boolean) -> ()
Whether a pose the skinning pass already wrote is read as it stands. On
by default: the pass produces an instance's vertices from its joint
matrices, its node transforms, its blend weight and its blend model, so the
slice holding a pose already holds what running the pass over those same
inputs would write. A frame binding a pose whose slice still holds it reads
the slice and dispatches nothing, and skinning costs what the frame's poses
CHANGED — a paused clip, a skeleton nothing drives, a cast standing in one
pose, each cost compute the frame the pose arrived and nothing after it.
Off, every pose a frame binds is dispatched again, which is the comparison a
frame suspected of reading a slice that no longer holds its pose is made
against; the image is the same either way and
renderer.skinningStats() counts the difference as dispatches against
held. A mesh whose vertices a compute pass writes is dispatched every
frame however this stands.
Parameters
enabledboolean—boolean
Returns ()
renderer.setSkinningPoseHold(false) -- dispatch every pose, every frame
typed/builtin//modules/api/engine/renderer/renderer/setSpectatorMode
renderer.setSpectatorMode(mode: string) -> string
Choose what the desktop window shows while an XR session serves
frames. mirror shows the left eye's picture, copied from the target the
headset's frame already drew, so the window costs no second scene render.
off draws nothing to the window: no scene render, no UI layout and no
present. editor draws the desktop editor beside the session, with its
panels and its own viewport camera, which renders the scene a second time.
With no XR session the window is the ordinary desktop window whatever the
mode. The engine boots in mirror; --xr-spectator <mode> names the mode a
boot starts in. Takes effect on the next frame; the mode in force is the
spectator field of /zero/runtime/observations/xr.
Parameters
modestring— string One of "off", "mirror", "editor".
Returns string — The canonical spelling of the mode now requested.
renderer.setSpectatorMode("editor") -- the desktop editor beside the headset
renderer.setSpectatorMode("off") -- the window draws nothing
typed/builtin//modules/api/engine/renderer/renderer/setTextureBucketSlack
renderer.setTextureBucketSlack(bytes: number?) -> TextureBucketSlack
Bound the GPU memory texture-array buckets may hold beyond the
textures in them. A bucket without room doubles while the total slack stays
under this budget, and past it grows to the largest capacity whose slack
the budget still holds, at least by what the arrival needs. A growth copies
every layer the bucket held, so a large one that would gain few layers for
what it copies opens another bucket of the same size instead. The default
follows the device (a sixty-fourth of the system's RAM where the GPU draws
from it, otherwise a sixteenth of the memory scale it reports; between
32 MiB and 512 MiB either way); nil restores it. bytes is a positive number of
bytes, 1 or more — 0, a negative number or a non-finite one raises an error
naming that range. A budget bounds the next growth; slack a bucket already
holds stays until a compaction takes it. On the bindless backend no bucket
exists, so the budget is recorded and reads back but bounds nothing. The
textures themselves are bounded by renderer.setTextureBudget; read what
the buckets hold with renderer.materialTable().
Parameters
bytesnumber(optional) —number?— the slack budget in bytes, or nil for the device's
Returns TextureBucketSlack — { slackBudgetBytes, deviceSlackBudgetBytes } — the budget now in force, and the device's own
renderer.setTextureBucketSlack(16 * 1024 * 1024)
renderer.setTextureBucketSlack(nil) -- the device's budget
typed/builtin//modules/api/engine/renderer/renderer/setTextureBudget
renderer.setTextureBudget(opts: TextureBudgetOpts?) -> TextureBudget
Bound the VRAM textures occupy, by keeping only the mip levels the
frame is actually sampling once the textures outgrow the budget. Every
device starts at its own budget and a bias of 0. Where the GPU draws from
the system's RAM (every Android phone, an integrated GPU, a software
rasterizer) and the system states how much, the budget is an eighth of
that RAM; otherwise it is half the memory scale the adapter reports;
between 256 MiB and 2 GiB either way, and held to 768 MiB on a
medium-tier and 384 MiB on a low-tier device (renderer.qualityTier()).
renderer.textureStreaming() names the rule (budgetRule) and the RAM it
read (deviceMemoryBytes), and memory pressure narrows what the budget
keeps (renderer.memoryPressure()). Pass
{ megabytes = 256 } to override the budget for the process; megabytes
is a positive number, 1 to 65536, and 0 or a negative number is an error.
A field set to the string "default" returns that one value to the
device's own, a field the table leaves out keeps the value it has, and a
field holding anything else — a boolean, another string — is an error
naming what it holds. nil restores the device's budget and bias
together. The budget belongs to the device the world is played on.
Below the budget every texture keeps its whole mip chain, whatever its
surfaces cover. Mips stream down only while the whole chains of the
streamable textures exceed the budget. Then each frame measures how many
screen pixels ONE traversal of a texture's coordinate range covers on the
surface that spans it widest, and asks for the mip level that serves that
span one texel per pixel — the level the GPU picks from the fragment's own
derivatives. A material with uvScale = 8 lays eight copies of its texture
across a surface, so each copy spans an eighth of the surface and asks for
three levels coarser than the surface's own size would. A shader that
declares // @uv_space: world advances its coordinate over world units
rather than over the mesh's UVs, so how many copies a surface carries
follows how large that surface is. The textures whose surfaces cover the
fewest pixels give up levels until the set fits. Detail climbs one level
per frame, from the image already on screen, so a surface the camera
approaches sharpens rather than popping, and no texture is taken below the
level whose longest side is 64 texels.
bias shifts every measurement by whole mip levels either way — negative
for finer than the sampling implies, positive for coarser — over a look
that wants a different trade than one texel per pixel. It is clamped to
[-8, 8].
The plan moves a texture whose demand the frame can measure: one at least 256 texels on its narrowest side, worn by a surface an entity draws. A texture a UI image, a post-process property or a render feature holds a view of stays whole, because nothing measures how much of the screen those cover.
Which textures the budget governs follows the surfaces the frame draws. A
texture whose asset still holds its bytes is enrolled the frame a measured
surface wears it, whenever it loaded, because a level change reads the
levels it needs back from the asset; when the last such surface goes it
leaves the set whole, at the level it uploaded at, and a surface reaching
it again takes it back up. A texture a script uploaded has its pixels on
the device alone, so it holds no copy while it is at its whole chain; the
first time the budget takes it coarser its chain is read back off the
device before any level is freed, and it holds that copy
(renderer.textureMemory().streamSourceBytes) while it stays coarser.
Once a surface has worn it and gone it leaves the set whole and stays out
for the rest of the process.
renderer.textureMemory().pinnedTextures counts those, together with the
textures whose asset could not be read back and the ones a UI image, a
post-process property or a render feature holds a view of.
Parameters
optsTextureBudgetOpts(optional) —{ megabytes: (number | "default")?, bias: (number | "default")? }?— nil for the device's budget and bias
Returns TextureBudget — { megabytes, bias, deviceMegabytes, deviceBias } — the budget and bias now in force, and the device's own
renderer.setTextureBudget({ megabytes = 128 })
renderer.setTextureBudget({ megabytes = 128, bias = -1 }) -- one level finer everywhere
renderer.setTextureBudget({ megabytes = "default" }) -- the device's budget, the bias as it stands
renderer.setTextureBudget() -- back to the device's budget and bias
typed/builtin//modules/api/engine/renderer/renderer/setTransmissionShadows
renderer.setTransmissionShadows(enabled: boolean) -> ()
Let translucent casters tint the sunlight they block instead of blocking
it outright. A shadow map holds one depth per texel and is compared as a
yes-or-no test, so stained glass, water and thin fabric all project the same
black silhouette a wall does. With this on, a caster whose material declares
transmission draws into a light-space transmittance map instead, and the
colour it lets through multiplies into the directional light reaching
whatever stands behind it. Stacked casters compose. A surface whose
material blends writes no depth shadow at all and throws its shadow through
this map alone: a transparent or premultiplied blend lets 1 - alpha of
the light through untouched and its transmission of the rest tinted by
its base colour, so red stained glass throws red light; a multiply blend
lets its base colour through; an additive one blocks nothing. Opaque
casters are unaffected, and a scene with no translucent caster allocates
nothing and records no pass.
Parameters
enabledboolean—boolean
Returns ()
renderer.setTransmissionShadows(true) -- stained glass tints the floor
typed/builtin//modules/api/engine/renderer/renderer/setUpscaleBackend
renderer.setUpscaleBackend(backend: string, quality: string?) -> string
Request a backend for the upscale seam — the step that brings a scene
rendered below display resolution back up to it. "blit" stretches;
"dlss" reconstructs from motion and history through NGX DLSS Super
Resolution on an adapter that has it. The renderer resolves the request
against its own capability and reports the outcome through
renderer.upscaleBackend() — a request for "dlss" on an adapter
renderer.upscaleCapabilities() omits it from resolves to "blit"
there, answered truthfully rather than echoed back here. quality names
the reconstruction quality mode a reconstructing backend derives its
render scale from; the blit keeps whatever renderer.setResolutionScale()
set and reads no value from quality.
@builtin::systems.temporalUpscale.temporalUpscale is the content-facing
surface built on this primitive — it carries the policy this raw setter
carries none of: refusing "dlss" where unavailable, refusing quality
alongside an explicit render scale, and keeping its own reconstruction
from stacking with a reconstructing backend.
Parameters
backendstring—string—"blit"or"dlss".qualitystring(optional) —string?—"quality" | "balanced" | "performance" | "ultraPerformance", read only by a reconstructing backend.
Returns string — the backend now requested, echoed back before the renderer resolves it against this adapter's capability.
renderer.setUpscaleBackend("dlss", "balanced")
typed/builtin//modules/api/engine/renderer/renderer/setViewportSize
renderer.setViewportSize(width: number, height: number) -> { width: number, height: number }
Draw at this many pixels for the rest of the task that asks. The
engine's drawing surface is resized to it, and everything measured
against that surface follows within a frame: getViewportSize(),
ui.screenSize(), the layout every UI screen rebuilds from it, each
camera's aspect, and what a capture taken in that task encodes. This is
how one session checks a responsive layout at a second shape: a HUD
written against ui.screenSize() is re-laid-out at the new size, so an
anchored element is drawn where that shape puts it rather than scaled
from where the boot size put it.
The size is held for the task that asked for it (an execute call is
one task), and when that task ends, however it ends, the surface goes
back to the size it had before. So a check reads what it needs at the
new shape inside the call that set it, and the window or browser canvas
a person is looking at is handed back as it was. While several tasks
hold a size the surface draws at the one asked for last, and when that
task ends it draws at the size the task before it holds. Asked for
outside any task, from a component's lifecycle, the size stands until
another is asked for.
Who honours the size depends on who owns the surface. A headless engine
and a browser canvas own theirs and are resized exactly; a browser page
that lays its canvas out at a new size meanwhile ends every hold, and the
page's size stands. Where an OS window owns it, the window manager is
asked and has the last word: a tiled or maximized window keeps the size
it has. Read renderer.surfaceSize() on a later frame for what was
realized.
The new size is in force from the NEXT frame, so wait a frame before
reading it back: renderer.surfaceSize() read straight after the call
still reports the size the surface had.
The logical UI space is normalised to about 1280 points wide, so a resize
to a size of the same aspect moves ui.pixelRatio() and leaves
ui.screenSize() where it was, while a resize that changes the aspect
changes that shape too. Both resize the surface.
In an editor layout this resizes the whole window, chrome and all;
renderer.setPictureSize draws the game's picture a Scene panel
presents at a device screen's size and leaves the window as it is.
A size larger than the device draws is refused naming the bound, which
renderer.maxViewportExtent() reports.
Parameters
widthnumber—number— width in pixels, at least 1.heightnumber—number— height in pixels, at least 1.
Returns { width: number, height: number } — the size asked for, in whole pixels.
renderer.setViewportSize(390, 844); task.waitFrames(2); print(ui.screenSize()) -- the phone shape, then the surface goes back when the call ends
typed/builtin//modules/api/engine/renderer/renderer/shaderCache
renderer.shaderCache() -> ShaderCache?
What the shader compile gate's store of baked WGSL held, answered and
wrote back. Compiling a .shader wraps the author's body in its framework,
expands every #include, and hands the result to naga to parse and
validate — work that is a pure function of the text going in, and that a
launch would otherwise repeat for every shader it draws with. The store
keeps that baked text across launches.
restoredEntries and restoredBytes are what a previous launch left that
this one read back. hits counts the compiles answered out of the store
and misses those that ran in full; savedMs sums what each hit's own
recorded compile had cost, against compileMs, what the misses spent.
stale counts the misses whose key was held but whose #included modules
had changed underneath — an entry records every module its expansion
consumed, so editing a module invalidates exactly the shaders that included
it and leaves the rest. The store also keeps each resolve gate pass a
surface shader's resolve module earned, so a launch does not validate the
same resolve text again: verdictHits counts the verdicts answered out of
it and verdictMisses the ones whose gate ran, apart from the compile
counts above.
entries and bytes are what the store now holds, and evictions how
many its bounds dropped: the entries whose last use, in wall-clock time,
is longest ago. A write appends the shaders compiled since the last one to
the store's file once a burst of compiles settles, off the frame thread:
saves counts the writes, savedBytes is what the last one wrote,
writtenBytes what all of them wrote, durableBytes the size of the file
as this launch last found it, and compactions the writes that rewrote
it whole to drop what it held that stood for nothing. dirty is true
while shaders are compiled that the file does not hold. persistent is
false where a launch has nowhere to keep artifacts and reason says why;
location is the file they are kept in (a file of the origin's private
file system, or IndexedDB records, in a browser). restoreState is how
the read of what a previous launch left has gone — pending while it is
still out, restored once entries came back, empty when there were none
to come back, failed when what was there could not be read, and none
where a launch keeps nothing. A cold, missing or corrupt store leaves every
shader compiling from source with identical output, and lastError then
names what went wrong.
Returns ShaderCache? — { persistent, reason, restoreState, location, restoredEntries, restoredBytes, hits, misses, stale, verdictHits, verdictMisses, entries, bytes, compileMs, savedMs, saves, savedBytes, writtenBytes, compactions, durableBytes, dirty, evictions, lastError }, or nil on a build with no renderer
local c = renderer.shaderCache()
print(("%d hits, %d misses, %.1f ms saved"):format(c.hits, c.misses, c.savedMs))
typed/builtin//modules/api/engine/renderer/renderer/shaderCost
renderer.shaderCost() -> { ShaderCost }
What each program has cost in pipeline builds, beside the compile
gate's most recent word about it. variants is how many pipelines this
engine has built for it — one per (target format, vertex layout,
render-state key) permutation reached — and buildMs what those builds
cost, both summed since engine start. A pipeline the driver's own store
restored is not built and so is not counted, so a second launch on the same
adapter reports less than the first. status is compiled, failed or
pending, and error carries the compiler's message for a failure.
Ordered by cost, most expensive first. shader is the key the program
is registered under; asset names the .shader asset a guid@checksum
key is a version of.
Returns { ShaderCost }
local top = renderer.shaderCost()[1]; print(top.asset or top.shader, top.variants, top.buildMs)
typed/builtin//modules/api/engine/renderer/renderer/shaderVariants
renderer.shaderVariants() -> { ShaderVariants }
Every shader that declares optional features, and the programs its
materials have made it compile. Each row carries the features the shader
declares, the base program it ships as, and one entry per variant with the
features that variant holds — so the permutation count a scene's materials
are spending is a number to read rather than something to infer from
compile time. A shader whose variants reach budget compiles no more; the
materials asking for further feature sets draw with the base program.
Returns { ShaderVariants } — An array of ShaderVariants, one per feature-declaring shader.
for _, s in renderer.shaderVariants() do print(s.shader, #s.variants, s.budget) end
typed/builtin//modules/api/engine/renderer/renderer/shadingOf
renderer.shadingOf(subject: string | { [string]: any }) -> ShadingReading
What the renderer is shading ONE subject with, taken from the document
the renderer publishes — the call a system holding a handle makes to find
out whether what reaches the screen is its own material or the magenta
placeholder standing in for it, without reading the engine log. subject is
an entity that draws or the registry key of a material. state reads
itsMaterial where the renderer bound the program the material names,
errorMaterial where it bound the placeholder instead, stalePipeline
where the pipeline drawing it was built before that program's most recent
compile, nothingBound where the renderer resolved no pipeline for it,
pending where this call is the one that armed per-draw recording and the
frame after it publishes, and unknown where the renderer holds a
resolution under no such subject. A fault state carries the renderer's own
reason from the closed set renderer.drawDiagnostics() names — plus
materialNotPrepared, which a material subject reads where the renderer
prepared nothing under that key — the compiler's detail, the program
the material asked for and the bound one; means states the reading in a
sentence. A material subject answers from the renderables drawing with it,
and from the renderer's record for the material itself where a draw
registered against the material carries no row of its own; a subject that
several renderables draw answers with a refused one wherever there is one.
The reading follows the renderer, so a program that compiles on a later
edit puts the subject back on itsMaterial from the frame the renderer
draws it with again.
Parameters
subjectstring | { [string]: any }— The entity — a proxy fromentity(...)or an entity-id string — or the material, as its registry key or theMaterialHandlerenderer.material.createreturned.
Returns ShadingReading
local s = renderer.shadingOf(emitter); if s.state ~= "itsMaterial" then print(s.means) end
typed/builtin//modules/api/engine/renderer/renderer/shadowCacheStats
renderer.shadowCacheStats() -> {
What the main camera's newest counted run did with the shadow pages it
asked for, in pages, by the kind of light that owns them. A page is drawn
again only when something it holds changed: its light moved, a caster over
it moved or appeared or vanished, a caster's geometry or material changed,
the caster changed pose or moved the nodes its parts are placed by, or the
camera moved under a caster whose material places its vertices by the
camera's position (a layered Terrain's geomorph).
Anything else keeps the depth already in the pool, so a scene that stops
moving reads rendered 0 while its pages stay cached. A caster moving on
one side of a point light dirties only the pages of the faces it reaches. A
caster a compute pass writes (a population's transforms, a mesh built from
compute buffers such as a Terrain's, a mesh a dispatch over its vertices
writes) re-renders the pages it stands over on each frame a pass writes it,
and keeps them while nothing does.
spot counts spot and single-sided area lights, point point and
two-sided area lights.
These are totals over every light of a kind. renderer.shadowViews() is
the same run one light at a time.
Returns { directionalRendered, directionalCached, spotRendered, spotCached, pointRendered, pointCached, rendered, cached }
local s = renderer.shadowCacheStats()
print(("shadow pages: %d drawn, %d cached"):format(s.rendered, s.cached))
typed/builtin//modules/api/engine/renderer/renderer/shadowCaching
renderer.shadowCaching() -> boolean
Whether a shadow page may keep the depth it already holds.
Returns boolean
typed/builtin//modules/api/engine/renderer/renderer/shadowCasterCutoff
renderer.shadowCasterCutoff() -> ShadowCasterCutoff
How small, and how far away, a caster may get before it stops writing depth into any shadow page. A shadow page rasterizes a caster's whole triangle count whatever the shadow it produces ends up covering, so an object the viewer resolves a fraction of a pixel of, and one past the range the scene cares about, each cost a full depth draw per page it reaches for detail nothing reads. Both thresholds are 0 — released — until something sets them.
Returns ShadowCasterCutoff — The cutoff in force — see ShadowCasterCutoff.
local c = renderer.shadowCasterCutoff(); print(c.minRadiusPx, c.maxDistance)
typed/builtin//modules/api/engine/renderer/renderer/shadowConfig
renderer.shadowConfig() -> ShadowConfig
The sun's shadow settings now in force. distance bounds how far from
the camera the sun shadows (the world's render.shadow_distance, else the
quality tier's, until renderer.setShadowConfig sets it); fadeFraction
and softness shape
how the shadow is sampled. The sun's virtual shadow map follows each
receiver's screen footprint, so its resolution follows the view.
punctualMipFloor is the finest mip a spot, area or point light's map
renders. detailBias, budgetMegabytes, pagesPerUpdate,
updateRate, filter and localLights are what a caller stated, or
"default" where the quality tier's stands
(renderer.qualityTier().defaults.shadows); what the renderer sized the
pages with is renderer.shadowSizing(). The table is one
renderer.setShadowConfig takes back.
Returns ShadowConfig — The full config — see ShadowConfig.
print(renderer.shadowConfig().distance)
typed/builtin//modules/api/engine/renderer/renderer/shadowHero
renderer.shadowHero() -> ShadowHeroReport
The registered hero caster and what the last drawn frame's box was. A
frame that made no box says why in decline.
entity is the live registration; everything else is the box of the
drawn frame frame names, and stands until the renderer draws another.
So a reading taken straight after setShadowHero or clearShadowHero
describes the registration before the call: read the drawn frame count as
the change is made, and take the report once its frame is past it.
Returns ShadowHeroReport — See ShadowHeroReport.
local h = renderer.shadowHero()
print(h.active, h.levelBias, h.decline)
local before = time.drawnFrameCount()
renderer.setShadowHero(player.id)
task.waitDrawnFrames(1)
print(renderer.shadowHero().frame > before)
typed/builtin//modules/api/engine/renderer/renderer/shadowMemory
renderer.shadowMemory() -> {
How much GPU memory the virtual shadow map's pools hold right now, in
bytes. One pool serves every light — the sun, and every spot, area and
point light that casts. pool is the depth page pool with the sun's static
cache laid out as it, held while any light casts; transmittance is the
transmittance pool, held while a translucent caster casts into it
(renderer.renderTargets() names them shadow_page_pool,
shadow_static_cache and shadow_transmittance_pool). Both read 0 while
released.
Returns { pool, transmittance, total } in bytes
local m = renderer.shadowMemory()
print(("shadows: %.1f MiB"):format(m.total / 1024 / 1024))
typed/builtin//modules/api/engine/renderer/renderer/shadowPageBreakdown
renderer.shadowPageBreakdown() -> { { [string]: any } }
The breakdowns renderer.watchShadowPages gathered since the last call,
oldest first, one per run of the main camera. levels has a row per
clipmap level: texelWorld (world units per texel), the pages it
requested, held (resident), drew (rendered) and had dirtied by the
frame's caster changes (invalidated), the pages those changes reach in its
window (reached) and the smallest size a change projects to there
(smallestRecordTexels). records lists each caster change with its
light-space sizeWorld, whether it is a tick (a caster whose shadow
moves every frame, reaching the levels its frame refreshes) and, per
level, the texels it covers and the pages it reaches;
staticRecords counts the changes that reach the static cache.
populationRuns lists each instanced population whose every member
writes a change this frame (firstSlot, count, whether it is static
or a tick, and whether it carries its old and new boxes), and
movedPopulations each population whose placement changed, whose members
that moved write one (firstSlot, count). cull is what the page cull walked (slotsWalked
caster slots, ncMembers casters drawn from their own vertex buffers) and
kept (pairs, casters tested, admitted and cutOff, chunks,
visible clusters, ncPairs, batchPages). pages has a row per batch
page: its level, the casters it drew and how many changed this frame
(dynamicCasters), its chunks, clusters and triangles with the
changed casters' shares, and its pairs of casters drawn from their own
vertex buffers (ncPairs, dynamicNcPairs).
Returns { { [string]: any } } — An array of breakdowns, empty when none was read since the last call.
renderer.watchShadowPages(30)
task.wait(1)
for _, run in renderer.shadowPageBreakdown() do print(run.frame, #run.pages) end
typed/builtin//modules/api/engine/renderer/renderer/shadowPageStats
renderer.shadowPageStats() -> {
What the sun's virtual shadow map did on the main camera's newest run
the GPU counted. The sun's shadow lives in pages around the camera; a run
marks the pages the receivers on screen ask for and draws the ones that
are missing or that a moved caster dirtied. A still camera over a still
scene runs nothing, so ran reads false and runs stands still while
frames climbs. The counts come back from the GPU a few frames after the
run, so frame names the frame they describe.
proxyPairs counts the (caster, page) pairs a shadow proxy stood in for,
proxyTriangles the triangles those pairs drew from the proxy and
sourceTriangles what the casters' own meshes would have drawn there.
castersDropped counts the casters drawn outside the cluster lists (a
deforming mesh, a population whose mesh has no cluster set) that the
newest frame could not list, which cast no shadow that frame.
Returns { frame, ran, runs, frames, requested, rendered, pending, starved, resident, clusters, batchPages, proxyPairs, proxyTriangles, sourceTriangles, invalidated, invalidateOverflow, castersDropped }, or nil before the first run is read back
local s = renderer.shadowPageStats()
if s then print(("%d pages asked for, %d drawn"):format(s.requested, s.rendered)) end
typed/builtin//modules/api/engine/renderer/renderer/shadowProxies
renderer.shadowProxies() -> ShadowProxyReport
The shadow proxies in force and what the shadow pages did with them.
triangles and sourceTriangles are what the main camera's newest counted
run submitted through proxies and what the same (caster, page) pairs would
have submitted from the source meshes — the before/after of every
registration, equal while nothing is proxied.
Returns ShadowProxyReport — See ShadowProxyReport.
local p = renderer.shadowProxies()
print(("shadow triangles: %d of %d"):format(p.triangles, p.sourceTriangles))
typed/builtin//modules/api/engine/renderer/renderer/shadowSizing
renderer.shadowSizing() -> ShadowSizing
What the sun's virtual shadow map was sized with. Its pool of pages
holds about twice the pages a frame asks for at the render resolution of
every camera that draws in it (the main camera, a headset's two eyes,
cameras drawing into textures), within the depth budget (the quality
tier's renderer.qualityTier().defaults.shadows.budgetMegabytes, or the one
renderer.setShadowConfig states). It is sized again when the render
resolution, the detail bias or the budget changes, and when cameras that
were not drawing begin to; cameras that stop leave it as it is. A run of
any camera that finds no slot for a page it asked for grows the pool to
hold the pages the cameras asked for, within the budget. Once the budget
holds no larger pool, the spot, area and point lights the camera sees
smallest give up their detail and then their pages first (each light's
share in renderer.shadowViews()), and a starved page of the sun raises
overflowBias by a level, up to 4, until the pool is sized again.
distance, fadeFraction and softness are the shading the renderer's
lookups of the sun's pages take. What renderer.setShadowConfig states
reaches the renderer ahead of every render drawn after it, an offscreen
capture among them, and these read it once it has: a reading equal to
what was stated says every render from then on draws with it.
Returns ShadowSizing — See ShadowSizing.
print(renderer.shadowSizing().depthMegabytes)
typed/builtin//modules/api/engine/renderer/renderer/shadowViews
renderer.shadowViews() -> ShadowViewReport?
Every shadow-casting spot, area and point light's virtual shadow map on the main camera's newest counted run, one row each.
renderer.shadowCacheStats() and renderer.shadowPageStats() sum these
counts over every light; this is the same run one light at a time. The
sun's pages are reported by renderer.shadowPageStats().
Each row names its light and says what its pages did: how many its
receivers asked for, how many it holds, how many were drawn, dirtied,
starved or left for a later run, and what the page cull did with the
casters it walked for the light. camera carries the main camera's share
of the instanced-compaction counters.
The counts come back from the GPU a few frames after the run, and frame
names the frame they belong to. A light that stops casting leaves views.
The frame names its lights only while something is reading them, so this call asks the frames after it to publish theirs and waits out the first one. Nil on an engine that renders no frame at all.
Returns ShadowViewReport? — See ShadowViewReport.
local report = renderer.shadowViews()
for _, view in report.views do
print(("%s %d (%s): %d of %d pages resident, %d drawn"):format(
view.role, view.index, view.light, view.pagesResident,
view.pagesRequested, view.pagesRendered))
end
typed/builtin//modules/api/engine/renderer/renderer/signalMemoryPressure
renderer.signalMemoryPressure(level: string) -> ()
Report memory pressure the way the system does: the engine releases
what level releases on its next frame, and engine.onMemoryPressure
subscribers hear it with source "script". Content about to need a lot of
memory (a large scene load, a big decode) frees room ahead of it with
this, and "normal" lifts a level a script put in force. level is
"normal", "moderate", "low" or "critical"; anything else is an
error naming the four. Read the outcome with renderer.memoryPressure()
once a frame has passed.
Parameters
levelstring—"normal","moderate","low"or"critical"
Returns ()
renderer.signalMemoryPressure("moderate") -- free unsampled mips before a big load
typed/builtin//modules/api/engine/renderer/renderer/skinnedBatching
renderer.skinnedBatching() -> boolean
Whether skinned instances holding one pose draw together.
Returns boolean
typed/builtin//modules/api/engine/renderer/renderer/skinningPoseHold
renderer.skinningPoseHold() -> boolean
Whether a pose already written into its slice skips its dispatch.
Returns boolean
typed/builtin//modules/api/engine/renderer/renderer/skinningStats
renderer.skinningStats() -> {
What the last frame's skinned instances cost. A skinned instance is
posed by a compute pass that writes its vertices into a shared pool, and
instances holding the same pose read one slice of that pool and the single
dispatch that fills it. instances is how many were posed, poses how
many distinct poses they held, and dispatches how many dispatches those
poses cost this frame — so a crowd whose members move together costs what
its poses cost rather than what its head count does, while members at
different animation times each hold their own pose and pay for it.
held is how many of the frame's poses cost no dispatch at all. The pass
produces a slice from what the pose is made of, so a slice an earlier frame
filled already holds what running it again would write, and a pose still
wearing that slice is read as it stands. Skinning is paid for by the poses
that CHANGED: a cast standing still reads dispatches 0 beside a held
equal to its poses, and the two add up to poses in any frame. A slice
counts as filled once a render carrying its dispatch has been drawn: the
frame's own view, or a render of the scene into a target, such as a
camera drawing into its render texture. A frame whose view the renderer
declines (a headless one nothing is consuming, a browser behind its GPU)
and that renders the scene into no target records nothing, so a pose that
arrives over such frames is counted in dispatches on each of them and
reads as held from the frame after the first one that records it. A
wait for a crowd to settle is therefore counted in drawn frames
(task.waitDrawnFrames).
reusedSlices is how many of the frame's poses took a slice the pool
already held — one a retired pose gave back, or one a pose nothing has
asked for this frame was holding — rather than one cut from pool the
engine had never used. A scene whose poses keep changing reads a non-zero
count beside a poolBytes that stays where it was.
liveBytes is what the slices holding this frame's poses occupy, against
unsharedBytes — what the same instances would occupy with a slice each.
poolBytes is what the pool holds; a previous-position buffer of the same
size rides alongside it so skinned deformation reaches motion vectors.
The same pass draws a soft body's model through the body's elements (its
cage). cages is how many soft bodies it draws that way, cageBytes what
their buffers occupy, and cageUploads how many of them wrote their
elements' maps to the GPU this frame: a soft body at rest writes nothing,
and a removed one takes its cage with it.
Returns { instances: number, poses: number, dispatches: number, held: number, reusedSlices: number, liveBytes: number, unsharedBytes: number, poolBytes: number, cages: number, cageBytes: number, cageUploads: number }
local s = renderer.skinningStats()
print(("%d instances over %d poses"):format(s.instances, s.poses))
print(("%d poses dispatched, %d read as they stood"):format(s.dispatches, s.held))
print(("skinned vertex storage: %d B of an unshared %d B"):format(s.liveBytes, s.unsharedBytes))
typed/builtin//modules/api/engine/renderer/renderer/spectatorMode
renderer.spectatorMode() -> string
The spectator mode that has been asked for: "off", "mirror" or "editor". An XR session applies it to the desktop window; with no session serving frames the window is the ordinary desktop window.
Returns string — The requested mode's canonical spelling.
print(renderer.spectatorMode())
typed/builtin//modules/api/engine/renderer/renderer/splat/components
renderer.splat.components(bytes: any?, convention: string?) -> (SplatComponents?, string?)
Decode a Gaussian splat capture — a Niantic .spz (gzipped or raw) or a
3DGS .ply — into the GPU-ready byte pools a render feature uploads.
records is the packed splat array at recordBytes per splat (position,
log scale, quaternion, DC colour + opacity); sh is the quantized
higher-order spherical-harmonics pool at shStrideWords u32 words per
splat, empty at degree 0. A pure decode (no GPU work): upload the pools with
shaderRef:createBuffer + buf:writeBytes and draw them with a
kind = "splat", channel = "gaussian" pass.
Parameters
bytesany(optional) — Capture bytes —.spzor.ply, as abufferor a binary string.conventionstring(optional) — Source axis convention:"rightDownFront"(the default, what COLMAP-trained captures use) or"engineNative"for a capture already in engine space.
Returns (SplatComponents?, string?) — { records, sh, count, shDegree, shStrideWords, recordBytes, boundsMin?, boundsMax?, antialiased, format }, or (nil, err).
local c = renderer.splat.components(vfs.read("/source/captures/ceramic.spz"))
typed/builtin//modules/api/engine/renderer/renderer/surfaceSize
renderer.surfaceSize() -> { width: number, height: number }
The whole drawing surface in pixels — the window, the browser canvas
or the headless framebuffer. This is the size renderer.setViewportSize
sets and the size the window's UI is laid out over, so it is what says
whether a resize was realized.
An editor layout's Scene panel presents the scene in a smaller rect, at
the size renderer.viewportSize() reports.
{ width = 0, height = 0 } before the first frame has drawn.
Returns { width: number, height: number } in pixels.
local s = renderer.surfaceSize()
typed/builtin//modules/api/engine/renderer/renderer/temporal/held
renderer.temporal.held() -> boolean
Whether a hold is pinning the per-frame clock right now.
Returns boolean — True while at least one renderer.temporal.hold stands.
if renderer.temporal.held() then print("frame is pinned") end
typed/builtin//modules/api/engine/renderer/renderer/temporal/hold
renderer.temporal.hold(at: number?, options: TemporalHoldOptions?) -> () -> ()
Pin the clock every per-frame effect draws itself against, and return
the release. While the hold stands, renderer.temporal.now answers at
instead of the running clock, so film grain and every other field redrawn
each frame is redrawn as the same field. Two renders taken under holds at
the same instant therefore agree pixel for pixel wherever the scene itself
has not moved, which is what makes one frame comparable with another.
Holds nest: the innermost names the instant, and the clock runs again once
the last release is called. Each release takes its own hold off the stack
whatever order the releases come in, so two callers holding at once — two
captures in flight together — each end their own hold and the clock runs
again when both have.
exclusive takes the clock for the owner key the call states: while
that hold stands, a hold is admitted only when it states the same key, and
every other one is refused with an error naming the key and the instant
holding it. That is what lets one caller wind the clock to the second it
means to photograph and keep it there while another agent drives the same
engine. The key is what an owner presents to take a nested hold of its
own, and what renderer.temporal.release hands the clock back by. A
capture taken while the hold stands renders at the held instant, and a
deterministic capture states that key as its own owner option to be
admitted under the hold and photograph the instant it pinned.
Parameters
atnumber(optional) — The instant to pin the clock at, in seconds. Two holds that state the same instant produce the same field; the default 0 is that shared instant.optionsTemporalHoldOptions(optional) —owneris the key this hold is taken under, and an exclusive hold states one. A hold that states no key is labelled with the caller the call is attributed to, which names the calling session where the transport attested one and the ZeroMind account otherwise.exclusivetakes the clock for the stated key until the hold is released.
Returns () -> () — A function that releases this hold. Calling it twice releases once.
local release = renderer.temporal.hold() ; local picture = tools.use("capture", "fromPosition", { position = { 0, 2, 8 } }) ; release()
local release = renderer.temporal.hold(46.0, { exclusive = true, owner = "stage-air" })
typed/builtin//modules/api/engine/renderer/renderer/temporal/now
renderer.temporal.now() -> number
The instant a per-frame effect should draw itself at: the innermost hold's instant while one stands, and seconds since boot otherwise. A system that redraws a field every frame reads this rather than the running clock, and a capture asking for a repeatable frame then gets one.
Returns number — Seconds — pinned while a hold stands, running otherwise.
local params = { grainTime = renderer.temporal.now() }
typed/builtin//modules/api/engine/renderer/renderer/temporal/onChange
renderer.temporal.onChange(listener: (number) -> ()) -> () -> ()
Register a listener called with the pinned instant whenever it changes — a hold taken, a hold released — and return the unsubscribe. A system whose shader reads the clock out of a GPU buffer registers here, so the buffer carries the pinned instant before the frame that hold was taken on is drawn rather than a frame later.
Parameters
listener(number) -> ()— Called with the instant now in force, in seconds.
Returns () -> () — A function that removes this listener.
local stop = renderer.temporal.onChange(function(t) print("temporal clock", t) end)
typed/builtin//modules/api/engine/renderer/renderer/temporal/owner
renderer.temporal.owner() -> { id: string?, name: string?, at: number, exclusive: boolean }?
The hold naming the instant the clock answers right now: who took it,
what instant it pinned, and whether it took the clock exclusively. Several
agents drive one engine at once and a hold any of them takes moves the
clock every registered field is redrawn against, so this is how a caller
sees that another agent holds it before its own instant is quietly
replaced — and, when exclusive is true, id is the key a hold of its
own states to be admitted, and the key renderer.temporal.release hands
the clock back by. id and name are nil for a hold that stated no key
and that the engine attributes to no agent.
Returns { id: string?, name: string?, at: number, exclusive: boolean }? — { id, name, at, exclusive } for the standing hold, or nil when the clock is running.
local who = renderer.temporal.owner()
if who ~= nil and who.exclusive then print(who.name, "holds the clock at", who.at) end
typed/builtin//modules/api/engine/renderer/renderer/temporal/release
renderer.temporal.release(owner: string) -> number
Hand the clock back by the key its holds were taken under, and report how many came off. A hold stands until its release is called, and the release is a closure the call that took the hold holds: a caller that takes a hold in one call and comes back in another, and a task that ends between the two, both leave the clock pinned with nobody holding a release for it. Naming the key is how the clock runs again, and how a caller refused by an exclusive hold takes one over.
Parameters
ownerstring— The key the holds to release were taken under — whatownerstated when they were taken, whichrenderer.temporal.ownerreports.
Returns number — How many holds came off the stack.
renderer.temporal.release("stage-air")
typed/builtin//modules/api/engine/renderer/renderer/texture/capture
renderer.texture.capture(texture: string | { [string]: any } | AssetRef) -> string
Request a CPU readback of the GPU texture texture names (e.g. a
camera's rendered output). Returns a result key to pass to a
TextureCpuHandle's :encode() once the readback completes. Takes every form
that names a texture — the TextureHandle create returned, the guid
renderer.texture.list hands out, a TextureCpuHandle or a texture
AssetRef.
Parameters
texturestring | { [string]: any } | AssetRef— The texture to read back — aTextureHandle, a guid, aTextureCpuHandleor a textureAssetRef.
Returns string The capture result key.
local key = renderer.texture.capture(cameraTarget)
typed/builtin//modules/api/engine/renderer/renderer/texture/cpuCreate
renderer.texture.cpuCreate(width: number, height: number, fill: any?) -> TextureCpuHandle
Allocate a blank CPU image (RGBA8) filled with a solid colour and return a
TextureCpuHandle. Compose into it with canvas:blit(src, x, y, w, h), then
canvas:encodeJpeg() / :encodePng() for the bytes. The canvas stays
while the handle is referenced and leaves memory when it is collected;
:unload() drops it at once.
Parameters
widthnumber— number Canvas width in pixels.heightnumber— number Canvas height in pixels.fillany(optional) — Optional{ r, g, b, a }(0-255) solid fill; defaults to opaque white.
Returns TextureCpuHandle
local c = renderer.texture.cpuCreate(1024, 576, { 255, 255, 255, 255 })
typed/builtin//modules/api/engine/renderer/renderer/texture/cpuFromBytes
renderer.texture.cpuFromBytes(bytes: buffer | string, encodeOpts: any?) -> TextureCpuHandle
Load engine-native ZTEX bytes — or an encoded image (png / jpg / webp)
— into the CPU store under a fresh guid and answer the CPU handle, for
pixels that come from somewhere other than a texture asset: a data.ztex
read as a file, a payload held in memory. The pixels stay at the format
they were encoded in. The pixels stay while the handle is referenced and
leave the store when it is collected; handle:unload() lets them go at once.
Parameters
bytesbuffer | string— The ZTEX or image bytes.encodeOptsany(optional) —{ colorSpace?, compression?, generateMipmaps?, maxDimension?, filter?, textureType?, alpha?, alphaIsTransparency? }— the optsrenderer.texture.encodeFromImagetakes — applied when the bytes are an encoded image and need the engine-native encode.maxDimensionbounds ZTEX bytes too: a payload that stores a mip chain is read from the first level whose longest side is within it, that level alone, so a thumbnail of a 4096² texture decodes a level near the thumbnail's size.
Returns TextureCpuHandle
local cpu = renderer.texture.cpuFromBytes(assert(vfs.read(path))); local png = cpu:encodePng(); cpu:unload()
local thumb = renderer.texture.cpuFromBytes(assert(vfs.read(texPath .. "/data.ztex")), { maxDimension = 256 })
typed/builtin//modules/api/engine/renderer/renderer/texture/create
renderer.texture.create(src: any?, guid: string?) -> TextureHandle
Create (or fetch) a GPU texture resource and return its TextureHandle.
src: a TextureCpuHandle from texRef:load() (CPU→GPU under the asset's
guid, idempotent); raw pixels {rgba, width, height, srgb?, format?} (a
flat widthheight4 byte payload, 0-255, row-major, top-to-bottom, RGBA —
a buffer, a binary string, or a number array; format = "rgba16f"
uploads an HDR texture instead, where rgba carries float channel
values); a TextureHandle (returned as-is);
or render-target dimensions {width, height, name?, format?} with no pixel
source — an empty GPU texture a render pass writes into (camera output,
UI surface) and that samples like any other texture. format names the
colour format the target is allocated in, and the passes drawing into it
are built for that format: "rgba8unorm" / "bgra8unorm" (the two
eight-bit channel orders, either of which a surface may carry),
"rgba16f" / "rgba32f", "rg16f" / "rg32f", "r16f" / "r32f".
Each also answers to its spelled-out width ("rgba16float", "r32float",
and so on), in any case. Omit it and a screen target takes the scene's
own format ("rgba16f") — a screen-sized target holds a picture of the
scene, and that is the format the scene is held in: linear light with
headroom above the display's white and no 256-step floor under a dark
gradient. A target that is not screen-sized and names no format takes the
surface's. "rgba8" is what a mask, a weight or an occlusion term asks
for, where 0..1 is the whole range; hand one back over @scene.color and
the frame loses every highlight above white and bands every gradient, and
the engine says so in the log. A float format carries what eight bits
quantize — positions, velocities, HDR. Any other
format raises an error naming every name that works, so a target is
allocated in the format it was asked for or not at all. A render target
takes filter the way raw pixels do: "nearest" keeps its own pixels square
wherever something draws it larger than it is — a viewport widget, a
magnified capture — which is what an image whose pixels ARE the subject
needs, since a 64x32 panel holds no detail between its pixels to
interpolate; "linear" (the default) smooths between them. It also
takes screen (the engine keeps it the size of the image being drawn),
screenScale (the fraction of that size it takes) and screenSpace
("scene", the default, or "composite" — the image the post-scene
phases draw into, which is the display's own resolution while the renderer
presents the viewport itself and the scene's size while a UI viewport panel
owns the presentation). A scene-space target is resized for every render
target drawn and cleared before an offscreen one; a composite-space target
keeps the presented frame's image: an offscreen render that runs a pass
of a post-scene phase draws in an image of its own at its own size,
cleared before it draws, which is what lets a pass keep an accumulation
across the presented frames in it. One scene-space screen target is
therefore one resource every render target draws through in turn, so its
guid holds the last one's image at the last one's size, and a value read
back from it belongs to whichever render target was drawn last. A
screen target a live Camera draws into is that camera's output instead:
the frame's other render targets neither resize nor clear it, so what the
camera drew there stays for as long as the camera does. A reading that has
to be the viewport's own comes from screenSpace = "composite", or from a
target created without screen. history = true makes a history target
instead, the target an accumulation across frames lives in: it is
screen-sized and keeps one pair of images per view a frame draws (the
viewport, every render-to-texture camera, every capture). For the length
of each view's render, the handle's guid names the image that render
writes and previous.guid the image that view's previous render wrote, so
a pass binds the two like any other targets and reads its own view's
history wherever it runs; no other view resizes, clears or overwrites
them. Before each render of a view the engine writes the compute buffer
named by the handle's state (one vec4<f32>, bound through a pass's
buffers): x is 1 when previous holds that view's previous image and
0 when it does not (the view's first render, its first after a cut or a
change of size, or a render of the view that ran without the target, and
then previous reads transparent black), y how many renders in a row
have carried the history, zw the render's sub-pixel projection offset in
pixels (renderer.setProjectionJitter). A view's images are made by
its first render that runs a pass naming the target, so a target whose
passes the frame leaves out (whenRead) holds no GPU memory; they are
freed when the view stops drawing, and all of them with the handle.
mips = true makes a target of its own size hold its whole mip chain (mips = <n>
holds n levels): a pass draws the first level, and a render feature pass
naming the target in generateMips fills the rest from it; sampled, the
target reads through its chain. NEVER takes an AssetRef — load the CPU
first.
A texture this call makes from pixels or dimensions lives while the
returned handle, or another handle over the same guid, is reachable from a
script, or while something else holds it (a material sampling it, a
camera rendering into it, a UI screen or post-process effect drawing it,
a render feature's pass drawing into it, sampling it or waiting on it,
the component or scene load that created it, a renderer.hold).
Once nothing holds it and the garbage collector has taken its last handle,
the engine releases it mid-session: its GPU memory and its
renderer.texture.list row go, and its guid names nothing. A script that
uses a texture by its guid keeps the handle (or holds it) for as long as
it means to.
Parameters
srcany(optional) — A TextureCpuHandle, raw pixels, a TextureHandle, or render-target dimensions.guidstring(optional) — Optional v4 guid for a NEW runtime texture — the asset identity the texture is filed under, which a material's texture slot resolves through. Minted when absent. Ignored for the CPU-handle and render-target paths.
Returns TextureHandle
local gpu = renderer.texture.create(texRef:load())
local gpu = renderer.texture.create({ rgba = pixels, width = 16, height = 16 })
local px = buffer.create(16 * 16 * 4); local gpu = renderer.texture.create({ rgba = px, width = 16, height = 16 })
local rt = renderer.texture.create({ width = 512, height = 256, name = "panel_rt" })
local hdr = renderer.texture.create({ width = 512, height = 256, name = "cam_rt", format = "rgba16f" })
local led = renderer.texture.create({ width = 64, height = 32, name = "panel", filter = "nearest" })
local hist = renderer.texture.create({ width = 1, height = 1, history = true, name = "accum" })
local water = renderer.texture.create({ width = 512, height = 512, format = "rgba16f", mips = true })
typed/builtin//modules/api/engine/renderer/renderer/texture/createFromAsset
renderer.texture.createFromAsset(ref: string | AssetRef, encodeOpts: any?, keepCpu: boolean?) -> TextureHandle
Put a .texture asset on the GPU under its own guid and answer its
handle at once. The asset's bytes are decoded off the frame and the
texture lands on the device when the decode finishes, a frame or more
later: a material naming the guid draws the shader's default for that
slot until then and rebinds when it arrives, and
renderer.texture.isResident reports the arrival. The decoded pixels are
dropped once uploaded unless keepCpu holds them in the CPU store for
textureRef:load()-style reads. An asset the device already holds is
answered from the shape the device reports, without reading the asset's
bytes and without a second decode. An asset whose bytes have not arrived
here yet, asked for by code that cannot wait for them (onPropertyChanged,
a metamethod, any place coroutine.isyieldable() is false), is answered a
handle sized 0x0 at once: a task reads the bytes and decodes them, the
texture lands under the asset's guid as above, and the handle takes the
decoded size when the decode is scheduled.
Parameters
refstring | AssetRef— A textureAssetRef, or a string naming one (guid, identity, name or source path).encodeOptsany(optional) —{ colorSpace?, compression?, generateMipmaps?, maxDimension?, filter?, textureType?, alpha?, alphaIsTransparency? }— the optsrenderer.texture.encodeFromImagetakes — applied when the primary is an encoded source image and needs the engine-native encode (a.ztexprimary is decoded as-is).keepCpuboolean(optional) — Keep the decoded pixels in the CPU store after the upload.
Returns TextureHandle
local h = renderer.texture.createFromAsset(texRef) -- bind h.guid on a material; it draws once resident
typed/builtin//modules/api/engine/renderer/renderer/texture/decode
renderer.texture.decode(bytes: buffer | string, opts: { straightAlpha: boolean? }?) -> (any, any, any, any)
Decode a texture payload to its pixel buffer. Takes the two shapes the renderer's own texture loader takes, told apart by their leading bytes:
- an engine-native
ZTEXpayload — handed back at the texel format the payload was written in, so a height field read back here keeps every bit it was authored with. AZTEXholding block-compressed or verbatim source-image levels decodes to"rgba8". - source image bytes — png, jpeg, gif or webp, straight off disk or out of
a
capture— decoded to"rgba8"at whatever colour type, bit depth or interlacing the file was written with. This is the call that reads the pixels of a screenshot.
The fourth return names the format the buffer came back in: "rgba8" (4
bytes/texel, channels 0-255), "rgba16" (8 bytes/texel, 16-bit unsigned
normalized channels 0-65535) or "rgba32f" (16 bytes/texel, float
channels).
The pixels are the texels the payload stores. With opts.straightAlpha = true, a payload encoded with alpha = "premultiplied" has its colour
divided back by alpha, in the colour space it was premultiplied in — the
straight-alpha pixels renderer.texture.encode takes. A texel whose alpha
is 0 keeps the black premultiplying left in it.
Parameters
bytesbuffer | string— AZTEXpayload or source image bytes.opts{ straightAlpha: boolean? }(optional) —{ straightAlpha? }
Returns (any, any, any, any) — (string?, number?, number?, string?) pixels, width, height, format — or (nil, errmsg) where errmsg is in the 2nd slot.
local pixels, w, h = renderer.texture.decode(vfs.read("/source/tmp/shot.png"))
local straight = renderer.texture.decode(vfs.read(texPath .. "/data.ztex"), { straightAlpha = true })
typed/builtin//modules/api/engine/renderer/renderer/texture/destroy
renderer.texture.destroy(texture: string | { [string]: any } | AssetRef) -> boolean
Release the GPU texture texture names. For an empty render-into texture
(camera output, UI surface) this also frees its render scratch; for an
uploaded runtime texture it drops the GPU resource (and any CPU shadow).
After this, renderer.texture.list stops answering for the guid. Takes
every form that names a texture — the TextureHandle create returned, the
guid the listing hands out, a TextureCpuHandle or a texture AssetRef.
Parameters
texturestring | { [string]: any } | AssetRef— The texture to release — aTextureHandle, a guid, aTextureCpuHandleor a textureAssetRef.
Returns boolean true when a texture was known under the guid.
renderer.texture.destroy(rt)
renderer.texture.destroy(renderer.texture.list()[1].guid)
typed/builtin//modules/api/engine/renderer/renderer/texture/encode
renderer.texture.encode(rgba: any?, width: number, height: number, opts: any?) -> (string?, string?)
Encode raw pixels into an engine-native ZTEX payload (the on-disk
texture content). The CPU codec behind the texture assetType's onCreate.
Called from a task (an execute chunk, a component hook the engine lets
wait, task.spawn), a "uastc" or "bc7" encode runs where the frame loop keeps
stepping: on a worker where the build has one, and otherwise a bounded
slice of its blocks per frame (__texture.encodeBudget, reported by
__texture.encodeJobs). The call returns on the frame the payload lands.
Code that cannot yield, and a coroutine the script resumes itself
(coroutine.create / coroutine.wrap), encode in place, and every other
compression is encoded on the call. The payload is the same bytes either
way.
opts.compression selects what the texels are stored as: "rgba8"
(default, 8 bits/channel, rgba is widthheight4 bytes), "uastc"
(UASTC 4x4 blocks, a quarter of the RGBA8 size, transcoded on each device
to the block format it holds; rgba is widthheight4 bytes and each
side is resampled to the nearest power of two, halfway rounding up),
"bc7" (BC7 blocks, a quarter of the RGBA8 size; rgba is still
widthheight4 bytes and both sides a multiple of 4) or the high-precision data compressions
"rgba16" (16-bit unsigned normalized, widthheight8 bytes) /
"rgba32f" (32-bit float, widthheight16 bytes) — for height/displacement
fields, baked lightmaps, and other data rasters 8 bits quantize visibly.
The two high-precision compressions store rgba verbatim, reject
opts.generateMipmaps / opts.maxDimension, and take opts.colorSpace = "linear" only. opts.colorSpace is "srgb" (default, colour data) or
"linear" (normal maps, masks, heights). opts.input ("rgba8" /
"rgba16" / "rgba32f") names the texel format rgba arrives in when it
is not the one opts.compression stores — the pixels
renderer.texture.decode hands back at their own width, say — and the
encoder carries each channel across as the same normalized value,
natively, before storing it.
opts.textureType records what the texture holds — "color"
(default), "normalMap" (when the encode generates mips, every level
of the chain, the base included, is renormalised to unit length),
"mask" or "sprite".
opts.alpha is what the encode does to alpha: "input" (default, kept
as given), "premultiplied" (RGB multiplied by alpha — in linear light
under srgb, as stored under linear — the source a material with the
premultiplied blend mode composites) or "none" (every texel opaque, RGB
kept). opts.alphaIsTransparency = true fills each fully transparent
texel with the average colour of its non-transparent neighbours,
spreading outward, alpha kept at 0 — before the alpha mode and the mips,
so filtering never pulls black into an edge. All three are recorded in
the payload and reported by renderer.texture.info.
The sampler opts are recorded the same way: opts.filter ("linear",
the default, or "nearest"), opts.wrapU / opts.wrapV ("repeat", the
default, "clamp" or "mirror" — how the texture is sampled past its
edges) and opts.anisotropy ("world", the default, following the
world's render.anisotropy, or a fixed "1" / "2" / "4" / "8" /
"16", also taken as the number). opts.effort ("fastest", the default,
"fast" or "thorough") is how long a uastc encode searches for each
block: every effort writes a payload the same size on the GPU, and a
higher one lands closer to the source. opts.uastcRdo ("none", the
default, "low", "medium" or "high") is how strongly a uastc encode
trades accuracy for a payload that compresses smaller. A block-compressed
encode (uastc, bc7) called from a task that can yield runs off the frame
and the task waits for it, so the world keeps running while it cooks.
Parameters
rgbaany(optional) — Pixel payload atopts.input's (elseopts.compression's) native byte width — abuffer, a binary string, or a number array.widthnumber— numberheightnumber— numberoptsany(optional) —{ colorSpace?, compression?, uastcRdo?, generateMipmaps?, maxDimension?, filter?, wrapU?, wrapV?, anisotropy?, textureType?, alpha?, alphaIsTransparency?, input? }
Returns (string?, string?) ZTEX bytes, or (nil, errmsg).
typed/builtin//modules/api/engine/renderer/renderer/texture/encodeFromImage
renderer.texture.encodeFromImage(bytes: buffer | string, opts: any?) -> (string?, string?)
Encode source image bytes (png/jpg/webp/…) into an engine-native ZTEX
payload. Used by the texture importer / assetType onChange. A "uastc"
or "bc7" encode called from code that can yield runs where the frame
loop keeps stepping, as renderer.texture.encode describes.
opts.compression is "rgba8" (default), "uastc", "bc7", "rgba16"
or "rgba32f", opts.colorSpace "srgb" (default) or "linear", and
opts.uastcRdo as renderer.texture.encode takes it. "rgba8" with
generateMipmaps = false, a maxDimension the image fits within (or
none), alpha = "input" and no alphaIsTransparency stores the source
image bytes verbatim.
"rgba16" and "rgba32f" decode a still image at its own bit depth and
store one linear level: a 16-bit PNG keeps every bit, an 8-bit channel v
is stored as v * 257 (rgba16) or v / 255 (rgba32f). The frames of an
animated image (GIF, APNG, animated WebP) are decoded at 8 bits, so a
16-bit APNG's frames are stored as v * 257 of their 8-bit values. Like
encode, they
reject opts.generateMipmaps and a maxDimension the image exceeds.
opts.textureType records what the texture holds — "color"
(default), "normalMap" (when the encode generates mips, every level
of the chain, the base included, is renormalised to unit length),
"mask" or "sprite".
opts.alpha is what the encode does to alpha: "input" (default, kept
as given), "premultiplied" (RGB multiplied by alpha — in linear light
under srgb, as stored under linear — the source a material with the
premultiplied blend mode composites) or "none" (every texel opaque, RGB
kept). opts.alphaIsTransparency = true fills each fully transparent
texel with the average colour of its non-transparent neighbours,
spreading outward, alpha kept at 0 — before the alpha mode and the mips,
so filtering never pulls black into an edge. All three are recorded in
the payload and reported by renderer.texture.info, as are the sampler
opts filter, wrapU, wrapV and anisotropy, which take the values
renderer.texture.encode takes.
Parameters
bytesbuffer | string— source image bytes.optsany(optional) —{ colorSpace?, compression?, uastcRdo?, generateMipmaps?, maxDimension?, filter?, wrapU?, wrapV?, anisotropy?, textureType?, alpha?, alphaIsTransparency? }
Returns (string?, string?) ZTEX bytes, or (nil, errmsg).
typed/builtin//modules/api/engine/renderer/renderer/texture/frameSchedule
renderer.texture.frameSchedule(texture: string | AssetRef) -> { number }?
The times at which each layer of a timed texture stops being shown, in seconds from the start of the sequence — the running total of the layer display times, so the last entry is the length of one pass.
This is the form a sampler reads a sequence through: a time is turned into
a layer by finding the first entry it has not passed, whatever the
individual layer times are. It is what the schedule slot of the builtin
animatedTexture shader holds, one entry per layer.
A texture whose layers carry no timing — a still image, a sprite sheet, a LUT stack — has no schedule and answers nil.
Parameters
texturestring | AssetRef— The texture — a guid, an identity, a name, a path, or a textureAssetRef.
Returns { number }? one cumulative end time per layer, or nil.
local ends = renderer.texture.frameSchedule(texRef) -- {0.1, 0.15, 0.35}
typed/builtin//modules/api/engine/renderer/renderer/texture/info
renderer.texture.info(ztex: buffer | string) -> (any, any)
Read the header of an engine-native ZTEX payload without copying the
pixels. Returns its format, its compression ("rgba8", "bc7", "rgba16"
or "rgba32f" — what the texels are stored as) and colorSpace ("srgb" or
"linear" — how they are read when sampled), dimensions, mip count,
the sampler recorded in the payload from the asset's settings — filter
("nearest" or "linear"), wrapU and wrapV ("repeat", "clamp" or
"mirror") and anisotropy ("world", or a fixed "1" / "2" / "4" / "8" /
"16"); a payload written before wrap and anisotropy were recorded reads
repeat / repeat / world — what the payload was encoded as —
textureType ("color", "normalMap", "mask" or "sprite"), alpha
("input", "premultiplied" or "none") and alphaIsTransparency (boolean);
a payload written before these were recorded reads color / input /
false — and the payload's layer shape.
layers counts the array layers the payload carries and isArray is true
past one — the answer to "am I about to sample a texture_2d_array?",
available before anything samples it. animated is true when those layers
are a sequence in time; then frameDelaysMs lists each layer's display
time in milliseconds in display order, and durationMs totals one pass.
An animated image imports as one layer per frame, so layers is its frame
count. A still texture reports layers = 1, isArray = false.
Parameters
ztexbuffer | string— ZTEX bytes.
Returns (any, any) — (table?, string?) { format, compression, colorSpace, textureType, alpha, alphaIsTransparency, width, height, mipCount, filter, wrapU, wrapV, anisotropy, layers, isArray, animated, frameDelaysMs?, durationMs? }, or (nil, errmsg).
local i = renderer.texture.info(bytes); if i.animated then print(i.layers, "frames", i.durationMs, "ms") end
typed/builtin//modules/api/engine/renderer/renderer/texture/isCpuResident
renderer.texture.isCpuResident(texture: string | { [string]: any } | AssetRef) -> boolean
True if this texture has a resident CPU copy in the guid-keyed CPU store.
Parameters
texturestring | { [string]: any } | AssetRef— The texture — aTextureHandle, aTextureCpuHandle, a guid, or a textureAssetRef.
Returns boolean
if renderer.texture.isCpuResident(handle) then ... end
typed/builtin//modules/api/engine/renderer/renderer/texture/isResident
renderer.texture.isResident(texture: string | { [string]: any } | AssetRef) -> boolean
True if a GPU texture is resident under this texture's guid.
Parameters
texturestring | { [string]: any } | AssetRef— The texture — aTextureHandle, aTextureCpuHandle, a guid, or a textureAssetRef.
Returns boolean
print(renderer.texture.isResident(handle))
typed/builtin//modules/api/engine/renderer/renderer/texture/keepCpuOnLanding
renderer.texture.keepCpuOnLanding(texture: string | { [string]: any } | AssetRef, keep: boolean) -> boolean
Set whether the decode on its way to this texture — scheduled by
textureRef:handle() or renderer.texture.createFromAsset and not yet on
the device — keeps its decoded pixels in the CPU store once it lands. A
texture's keepCpu setting changing while its decode is in flight reaches
the texture through this.
Parameters
texturestring | { [string]: any } | AssetRef— The texture — aTextureHandle, aTextureCpuHandle, a guid, or a textureAssetRef.keepboolean— Keep the CPU copy once the decode lands.
Returns boolean — true when a decode was on its way; false changes nothing.
renderer.texture.keepCpuOnLanding(texRef, true)
typed/builtin//modules/api/engine/renderer/renderer/texture/list
renderer.texture.list() -> { any }
Every texture currently registered, ordered by guid — the ones a script
created and the ones that reached the device through an asset alike. Each
entry carries the guid, where it came from (origin is "asset" for a
texture the asset path uploaded), and whether the GPU still holds it. A
resident entry also carries the bytes it costs, its dimensions, its
texel format and the mip levels the device holds (mipLevels), so the
listing sums to renderer.textureMemory(). A streamable one carries
streamOrigin — "asset" when a level change reads the levels it needs
back from the asset, "device" when no asset answers for it and its whole
chain on the device is the only copy, "retained" when it is resident
coarser and holds the levels read back off the device.
A resident entry carries how a material binding it samples it, as the
texture records it: filter ("linear" / "nearest"), wrapU and
wrapV ("repeat" / "clamp" / "mirror") and anisotropy
("world" or a fixed "1".."16"), and samplerAnisotropy, the level
the texture's sampler takes: anisotropy resolved against
renderer.anisotropy() and the device's ceiling, and 1 for a nearest
texture — the entry of the renderer's sampler table the texture's
handle names.
A script-created entry also carries held — whether renderer.hold pins
it for the session — and scene, the load that created it.
renderer.references("texture", guid) says what is still holding a row,
and renderer.collect() releases the rows nothing holds.
Returns { any } — Array of { guid, origin, owner?, scene?, held?, resident, bytes?, width?, height?, mipLevels?, format?, filter?, wrapU?, wrapV?, anisotropy?, samplerAnisotropy?, compressed?, streamable?, streamOrigin? }.
for _, t in ipairs(renderer.texture.list()) do print(t.guid, t.bytes) end
typed/builtin//modules/api/engine/renderer/renderer/texture/loadCpu
renderer.texture.loadCpu(ref: string | AssetRef, encodeOpts: any?) -> TextureCpuHandle
Load a .texture asset's pixels into the ONE guid-keyed CPU store (the
Disk→CPU step) and return a CPU handle for per-pixel access (no GPU
readback). The handle holds NO pixels — only the guid, dims and texel
format plus the read/write/encode/unload ops (which read the Rust store).
The pixels stay at the format they were authored in: handle.format is
"rgba8", "rgba16" or "rgba32f", and :readPixel reports channels in
that format's own units. Called by texRef:load(). DEFAULT: upload to the
GPU then handle:unload().
Parameters
refstring | AssetRef— A textureAssetRef(carries.guid, reads its primary via getBytes), or any stringasset.refresolves to one — a guid, an identity, a name or a source path.encodeOptsany(optional) —{ colorSpace?, compression?, generateMipmaps?, maxDimension?, filter?, textureType?, alpha?, alphaIsTransparency? }— the optsrenderer.texture.encodeFromImagetakes — applied when the primary is an encoded source image and needs the engine-native encode (a.ztexprimary is loaded as-is).
Returns TextureCpuHandle
local cpu = texRef:load(); local r,g,b,a = cpu:readPixel(3, 4); cpu:unload()
typed/builtin//modules/api/engine/renderer/renderer/texture/normalMapTilt
renderer.texture.normalMapTilt(bytes: buffer | string) -> (any, any)
The angle in degrees between +Z and the mean of a normal map's decoded
normals: each texel's RGB is decoded as 2c - 1, the vectors are averaged,
and the answer is the angle of that mean from the surface's own normal. A
map whose relief is centred on the surface reads near 0; a map whose whole
surface leans reads the lean, the angle every surface it covers leans by.
Takes the two shapes renderer.texture.decode takes, an engine-native
ZTEX payload or source image bytes, and reads the base level at the
precision it is stored in.
Parameters
bytesbuffer | string— AZTEXpayload or source image bytes.
Returns (any, any) — (number?, string?) the mean tilt in degrees, or (nil, errmsg).
local tilt = renderer.texture.normalMapTilt(vfs.read(texPath .. "/source.png")); if tilt and tilt > 3 then print("leans", tilt, "degrees") end
typed/builtin//modules/api/engine/renderer/renderer/texture/readback
renderer.texture.readback(texture: string | { [string]: any } | AssetRef, opts: { settled: boolean? }?) -> TextureCpuHandle
Read a runtime GPU texture's pixels back to CPU and return a
TextureCpuHandle for them — the GPU→CPU half of the runtime-texture freeze
path. A texture made with renderer.texture.create keeps no CPU copy, so
persisting it (:encode() → asset.create("texture", …)) reads it back
here first. Yields until the readback completes (a frame or two). After it
returns the pixels are resident in the guid-keyed CPU store: :readPixel,
:writePixel, :getInfo, :encode, :unload all work. Errors if the
texture never becomes GPU-resident.
A SCENE-space screen-sized render target is one resource shared by every
render target drawn — the viewport, an offscreen capture, a camera
rendering into a texture — resized and re-derived for each of them in
turn. The copy is taken ahead of all of them for the frame, so what a
readback of its guid answers is the content of the last frame the renderer
drew: the presented view's own image at the presented resolution, since
the presented view is the sink that draws last. A request made while the
renderer is holding frames back is carried to the next frame it draws
rather than being answered from a target another sink left standing, so a
readback can wait a frame longer than the copy itself takes.
The frames the copy is awaited over are counted the way
task.waitDrawnFrames counts them: by default only frames drawn with
every pipeline the scene asked for in place, so while pipelines build
anywhere in the scene the readback waits for them too. { settled = false }
counts every drawn frame, for a read of a target whose picture is already
decided (a camera's one-shot render the caller has checked), which then
answers while builds it does not draw with are still landing.
Parameters
texturestring | { [string]: any } | AssetRef— The texture — theTextureHandlerenderer.texture.createreturned, a guid, or a textureAssetRef.opts{ settled: boolean? }(optional) —{ settled: boolean? };settled = falsecounts every drawn frame while the copy is awaited (default true).
Returns TextureCpuHandle
local cpu = renderer.texture.readback(handle); local ztex = cpu:encode(); cpu:unload()
local cpu = renderer.texture.readback(captureTarget, { settled = false })
typed/builtin//modules/api/engine/renderer/renderer/texture/reencode
renderer.texture.reencode(ztex: buffer | string, opts: any?) -> (string?, string?)
Re-encode an engine-native ZTEX payload against new opts. A "uastc"
or "bc7" re-encode called from code that can yield runs where the frame
loop keeps stepping, as renderer.texture.encode describes. opts is
the complete encode spec, exactly as for renderer.texture.encode: every
field it leaves out takes its default, so textureType, alpha,
alphaIsTransparency, filter, wrapU, wrapV and anisotropy come
from opts — not from the payload's header — and a payload re-encoded
with { compression = "uastc" } alone loses a nearest filter or a
premultiplied alpha it carried. renderer.texture.withSampler changes
how a payload is sampled without re-encoding it. The
payload's layers and their display times are kept, whatever compression
either side is in. Each layer's texels are read back with straight alpha (a payload
encoded with alpha = "premultiplied" has its colour divided back by
alpha), carried to the width the new compression stores as the same
normalized value, and encoded exactly as renderer.texture.encode would
encode them; a payload that embeds its source image is re-encoded from
that image, read at its own bit depth. What an earlier encode discarded
stays discarded: after alpha = "none" the alpha is opaque. The texture
assetType re-encodes a container that holds no source image through this
call when its settings change. A block-compressed encode called from a
task that can yield runs off the frame while the task waits.
Parameters
ztexbuffer | string— AZTEXpayload — abufferor a binary string.optsany(optional) —{ colorSpace?, compression?, uastcRdo?, generateMipmaps?, maxDimension?, filter?, wrapU?, wrapV?, anisotropy?, textureType?, alpha?, alphaIsTransparency? }
Returns (string?, string?) ZTEX bytes, or (nil, errmsg).
local wide = renderer.texture.reencode(vfs.read(texPath .. "/data.ztex"), { compression = "rgba16", colorSpace = "linear", generateMipmaps = false })
typed/builtin//modules/api/engine/renderer/renderer/texture/tone
renderer.texture.tone(histogram: any?) -> TextureTone
Reduce a histogram to what the picture's tone IS: where its darkest and brightest pixels sit, where the body of it sits, and how much of it is standing on the floor or the ceiling — all in code values on the 0-255 scale the pixels were delivered at.
span (max - min) is the whole range including a single stray pixel;
spread (p95 - p5) is the range the body of the picture occupies, which
is the reading that says whether a shot is legible. A frame whose subject is
modelled and shaded but delivered inside a few code values reads a large
mean and a tiny spread, and no mean alone can tell that apart from a
frame with a subject in it.
crushed and clipped are the shares of the picture at code 0 and at code
255, each 0..1 — what a shot loses to the floor and to the ceiling.
Parameters
histogramany(optional) — A histogram fromcpu:histogram().
Returns TextureTone
local t = cpu:tone(); if t.spread < 24 then error("the shot is flat") end
typed/builtin//modules/api/engine/renderer/renderer/texture/unloadCpu
renderer.texture.unloadCpu(texture: string | { [string]: any } | AssetRef)
Drop this texture's resident CPU copy from the guid-keyed CPU store.
The explicit release for a texture asset's keepCpu setting turning off.
Parameters
texturestring | { [string]: any } | AssetRef— The texture — aTextureHandle, aTextureCpuHandle, a guid, or a textureAssetRef.
renderer.texture.unloadCpu(texRef)
typed/builtin//modules/api/engine/renderer/renderer/texture/update
renderer.texture.update(texture: string | { [string]: any } | AssetRef, src: any?) -> TextureHandle
Overwrite the GPU texture texture names IN PLACE, under the same guid,
from new pixels. Never writes a .texture file — the play-mode mutate
path. Takes every form that names a texture — the TextureHandle create
returned, the guid renderer.texture.list hands out, a TextureCpuHandle
or a texture AssetRef. src is raw pixels, or a TextureCpuHandle
(texRef:load(), renderer.texture.loadCpu, renderer.texture.readback),
whose pixels arrive with everything they carry: texel format, colour
space, mip chain, layers and filter. Every material, UI image and
post-process effect sampling the guid draws the new texture. Returns a
handle carrying the new dimensions: the handle it was given, refreshed,
and a handle over the guid otherwise.
Parameters
texturestring | { [string]: any } | AssetRef— The texture to update — aTextureHandle, a guid, aTextureCpuHandleor a textureAssetRef.srcany(optional) — New raw pixels{rgba, width, height, srgb?, format?}—rgbaas abuffer, a binary string, or a number array — or aTextureCpuHandle.
Returns TextureHandle — A TextureHandle for the updated texture.
typed/builtin//modules/api/engine/renderer/renderer/texture/withSampler
renderer.texture.withSampler(ztex: buffer | string, opts: { filter: string?, wrapU: string?, wrapV: string?, anisotropy: (string | number)? }) -> (string?, string?)
Change how an engine-native ZTEX payload is sampled without
re-encoding it. opts names any of filter ("linear" / "nearest"),
wrapU and wrapV ("repeat" / "clamp" / "mirror") and anisotropy
("world", or "1" / "2" / "4" / "8" / "16", also taken as the
number); a field it omits keeps the payload's value. The result is the
same bytes with only the sampler bits of the header replaced, so every
level is byte-identical to the input — the cheap path the texture
assetType takes when a settings change touches only these four fields.
An unrecognised value raises.
Parameters
ztexbuffer | string— AZTEXpayload — abufferor a binary string.opts{ filter: string?, wrapU: string?, wrapV: string?, anisotropy: (string | number)? }—{ filter?, wrapU?, wrapV?, anisotropy? }
Returns (string?, string?) ZTEX bytes, or (nil, errmsg).
local clamped = renderer.texture.withSampler(vfs.read(texPath .. "/data.ztex"), { wrapU = "clamp", wrapV = "clamp" })
typed/builtin//modules/api/engine/renderer/renderer/textureMemory
renderer.textureMemory() -> {
What the GPU texture cache holds, split by whether the texture is
block-compressed. compressedBytes and uncompressedBytes are what those
textures cost in VRAM, measured from each texture's own format and mip
chain — so a .texture whose settings name compression = "uastc" appears in the
compressed columns at a quarter of what the same image costs as RGBA8.
blockCompressionSupported is whether this adapter samples any
block-compressed format; where it is false a block-compressed payload is
uploaded decoded and lands in the uncompressed columns instead, so the
texture is present everywhere and compressed where the hardware allows it.
blockFormat names the format block-compressed textures are resident in
on this adapter ("bc7" on desktop, "astc4x4" on a phone, "etc2" on
a phone without ASTC) and is nil where it samples none. A texture stored
as UASTC is transcoded to blockFormat; one stored as BC7 keeps its
blocks where the adapter samples BC7 and is re-encoded into blockFormat
where it does not, each at the same one byte per texel.
Measured at the end of the last rendered frame.
streamableTextures is how many of them the texture budget can move the
base mip level of, split by where a level change reads the levels it needs
from: assetStreamedTextures are read back from the asset they came from
and hold nothing in system memory; the rest no asset answers for, so the
device holds their only copy. Such a texture holds no copy of its own while
it is at its whole mip chain; the first time the budget takes it coarser
its chain is read back off the device before any level is freed, and it
holds that copy while it stays coarser. retainedTextures counts the ones
holding a copy, and streamSourceBytes is what those copies occupy in
system memory — bytes that are not VRAM. pinnedTextures counts the
textures big enough to stream that stand at a level nothing can move: no
asset answers for them and they left the streamable set, the asset behind
them could not be read back, or a UI image, a post-process property or a
render feature holds a view of them.
A texture out of the streamable set only because no measured surface wears
it stands in neither count: a surface reaching it takes it back up, so its
level moves again as soon as there is a footprint to move it by.
byFormat names every GPU format a cached texture is held in, keyed by
the format's name (Bc7RgbaUnormSrgb, Astc { block: B4x4, .. },
Rgba8UnormSrgb, ...), with how many textures it holds and their bytes.
heldAboveCap lists the textures resident larger than
renderer.setMaxTextureSize allows: one whose mip chain has no level
within the cap, and one with no asset behind it, which keeps every level
it was made with. decodedFallback lists the
UASTC textures this device holds as texels because it samples no block
format.
Returns { blockCompressionSupported, blockFormat?, compressedTextures, compressedBytes, uncompressedTextures, uncompressedBytes, streamableTextures, assetStreamedTextures, retainedTextures, pinnedTextures, streamSourceBytes, byFormat, heldAboveCap, decodedFallback }
local tm = renderer.textureMemory()
print(("%d compressed textures hold %.1f MiB"):format(tm.compressedTextures, tm.compressedBytes / 1048576))
print(("%d textures stream from their asset, %d hold %.1f MiB of pixels"):format(
tm.assetStreamedTextures, tm.retainedTextures, tm.streamSourceBytes / 1048576))
typed/builtin//modules/api/engine/renderer/renderer/textureStreaming
renderer.textureStreaming() -> TextureStreaming
What the last frame's texture-residency plan decided. budgetBytes is
the budget in force: the device's own, or the one setTextureBudget
names, as much of it as the memory pressure in force leaves (half at
"critical"). deviceBudgetBytes is the device's own budget (what
setTextureBudget names deviceMegabytes): memoryBudgetBytes, held to
the quality tier's cap where the tier states one. memoryBudgetBytes is
what the device's memory affords and budgetRule the rule it came from:
"systemMemory", an eighth of the RAM the system states
(deviceMemoryBytes, nil where it states none), on a GPU that draws from
that RAM, or "bufferSize", half the adapter's max_buffer_size; between
256 MiB and 2 GiB either way. pressure is the memory pressure level in force; from
"moderate" up the plan holds every texture at the level its surfaces
sample, below the budget as well as past it (renderer.memoryPressure()).
streamable is how many textures the plan can move.
residentBytes is what those textures occupy now, measured from the
textures that are allocated; demandedBytes is what the frame asks for
before the sweep — every texture's whole chain while those fit the budget,
and the level each surface asked for once they exceed it — so the two part
exactly where the budget is doing something. starved counts the textures left
coarser than the frame asked for, promoted the ones that climbed a level
this frame, and changed the ones whose GPU texture was replaced. A camera
approaching a surface reads promoted above zero for a few frames and then
zero once it settles. unread is true while the plan holds the set for an
engine nothing reads: one that draws only on request (a headless engine)
and has drawn no frame for a reader for ten seconds keeps every texture an
asset can restore at its floor, and demandedBytes and starved then
count what its surfaces ask for against that. The first frame a reader
asks for (a capture, task.waitDrawnFrames) climbs the set back, reading
promoted above zero while it climbs.
textures is one row per streamable texture, ordered by key, carrying the
level each one was asked for and the measurement that asked. Two byte
totals can agree while a single texture sits several levels off what its
surface samples, so read the row when the question is which level a texture
holds and why.
Returns TextureStreaming — { budgetBytes, deviceBudgetBytes, memoryBudgetBytes, budgetRule, deviceMemoryBytes?, pressure, streamable, residentBytes, plannedBytes, demandedBytes, starved, promoted, changed, unread, textures }
local ts = renderer.textureStreaming()
print(("textures: %.1f MiB resident of %.1f MiB demanded, %d starved"):format(
ts.residentBytes / 1048576, ts.demandedBytes / 1048576, ts.starved))
typed/builtin//modules/api/engine/renderer/renderer/transmissionShadows
renderer.transmissionShadows() -> boolean
Whether translucent casters tint the directional light they block.
Returns boolean
typed/builtin//modules/api/engine/renderer/renderer/uploadStats
renderer.uploadStats() -> {
What the last frame the renderer drew spent re-describing its
renderables to the GPU, counted from the frame it drew before that, so a
read after task.waitDrawnFrames describes the frame waited for even where
the frame pacer declines frames between two drawn ones. Every renderable
owns a slot in the per-instance data a draw reads (its world matrix, the
bounds the culler tests it by, and the flags that decide which passes and
which culling stages see it), and a frame uploads
only the slots whose contents changed. A renderer.mesh.drawInstanced
population's slots are filled by copies from its own buffers, counted the
same way: a frame that copies a population's transforms or shader data
counts one write per copy and the bytes it moved. bytes is what those
uploads and copies carried, fullBytes what re-sending every slot would
have cost, and writes how many buffer writes carried it. The three numbers
cover that per-renderable data alone, so a scene standing still reads
bytes = 0 against a fullBytes that grows with the scene, and the ratio
says how much of it the scene's own churn, rather than its size, is
paying for.
Returns { writes: number, bytes: number, fullBytes: number }
local u = renderer.uploadStats()
print(("instance upload: %d B of %d B in %d writes"):format(u.bytes, u.fullBytes, u.writes))
typed/builtin//modules/api/engine/renderer/renderer/upscaleBackend
renderer.upscaleBackend() -> string
The backend actually filling the upscale seam this frame — "blit"
or "dlss". Reports what the renderer resolved the last
renderer.setUpscaleBackend() request into, which reads "blit" after a
request for "dlss" on an adapter renderer.upscaleCapabilities() omits
it from.
Returns string — "blit" or "dlss".
local backend = renderer.upscaleBackend()
typed/builtin//modules/api/engine/renderer/renderer/upscaleCapabilities
renderer.upscaleCapabilities() -> { string }
The backend names this engine can actually run for the upscale seam,
from a boot-time probe of the adapter. "blit" always answers, since the
stretch needs no adapter capability; "dlss" joins it only where NGX
DLSS Super Resolution is available. Read this before
renderer.setUpscaleBackend("dlss", ...) to know ahead of the request
what it resolves to.
Returns { string } — at least { "blit" }.
local caps = renderer.upscaleCapabilities()
typed/builtin//modules/api/engine/renderer/renderer/variantSource
renderer.variantSource(program: string) -> string?
The WGSL one of the programs renderer.shaderVariants() lists holds,
exactly as the shader compiler received it. program is the program
field of a row's base or of one of its variants. Reading a base
alongside a variant shows what a feature set selected: each program's text
holds the code its own features guard. The variant-report spelling of
renderer.compiledSource, which answers the same for every other shader.
Parameters
programstring— Aprogramname fromrenderer.shaderVariants().
Returns string? — The compiled WGSL, or nil for a name no compile has run under.
local row = renderer.shaderVariants()[1]
local base = renderer.variantSource(row.base.program)
typed/builtin//modules/api/engine/renderer/renderer/viewportSize
renderer.viewportSize() -> { width: number, height: number }
The rect the scene was drawn into in the frame just drawn, in the
window's pixels. That is the whole drawing surface in a runtime window, a
browser canvas and a headless engine, and the editor's viewport panel,
smaller than the surface, in an editor layout, or the device screen size
renderer.setPictureSize draws that panel's picture at. Follows a
renderer.setViewportSize, a window drag and a browser page resize alike,
so it reports what is realized rather than what was asked for. The render
scale leaves it alone: it is the size the scene is shown at, the space
pointer and touch positions, worldToScreen and screenToRay speak, and
getViewportSize() reads the same. renderer.rasterSize() is the size
the scene rasterized at inside it.
Returns { width: number, height: number } in pixels.
local v = renderer.viewportSize()
typed/builtin//modules/api/engine/renderer/renderer/watchShadowPages
renderer.watchShadowPages(runs: number)
Gather a breakdown of what the sun's virtual shadow map does on each of
the main camera's next runs runs. Each run's counts come back from the
GPU a few frames after it, and renderer.shadowPageBreakdown() hands them
over. Nothing is gathered while no reader has asked. 0 stops a
gathering under way.
Parameters
runsnumber— How many of the main camera's runs to gather.
renderer.watchShadowPages(120)
typed/builtin//modules/api/engine/runtime_participation/M/isSaved
M.isSaved(mode: string) -> boolean
Whether an entity with this mode is written to the persisted world. True for WorldEntity, PrototypeOnly, and EditorOnly; false for RuntimeOnly.
Parameters
modestring— A RuntimeParticipation mode string.
Returns boolean — true when the mode is persisted on scene save.
typed/builtin//modules/api/engine/runtime_participation/M/liveInEdit
M.liveInEdit(mode: string) -> boolean
Whether an entity with this mode is live while authoring in edit mode. True for WorldEntity, PrototypeOnly, and EditorOnly; false for RuntimeOnly.
Parameters
modestring— A RuntimeParticipation mode string.
Returns boolean — true when the mode is present in edit mode.
typed/builtin//modules/api/engine/runtime_participation/M/liveInPlay
M.liveInPlay(mode: string) -> boolean
Whether an entity with this mode is live during play. True for WorldEntity and RuntimeOnly; false for PrototypeOnly and EditorOnly.
Parameters
modestring— A RuntimeParticipation mode string.
Returns boolean — true when the mode is present in play mode.
typed/builtin//modules/api/engine/runtime_participation/M/modeOf
M.modeOf(entityId: string) -> string
The entity's RuntimeParticipation mode. Defaults to "WorldEntity".
Parameters
entityIdstring— Entity id to read.
Returns string — One of "WorldEntity" / "PrototypeOnly" / "EditorOnly" / "RuntimeOnly".
typed/builtin//modules/api/engine/runtime_participation/M/set
M.set(entityId: string, mode: string)
Sets the RuntimeParticipation mode on an entity. A mode that is not saved marks the entity temporary so the scene-save exclusion drops it.
Parameters
entityIdstring— Entity id to write.modestring— The mode to store.
typed/builtin//modules/api/engine/runtime_participation/M/standsDown
M.standsDown(mode: string, engineMode: string) -> boolean
Whether an entity with this mode stands down — stops rendering and
ticking — when an EDITOR session is in engineMode. This is the question a
mode flip actually asks, and it is not liveInPlay: that answers which
entities a SHIPPED RUNTIME contains, where there is no authoring surface at
all. A session able to flip modes is an editor session by construction (the
runtime profile forbids mode swaps), so the editor's own cameras, panels and
gizmos are present in both of its modes and stand down in neither. What
stands down in play is a template, whose clones are what runs; what stands
down in edit is a runtime entity.
Parameters
modestring— A RuntimeParticipation mode string.engineModestring— The engine mode the session is in, "play" or "edit".
Returns boolean — true when the mode should not be participating in that mode.
local rp = require("@builtin::modules.api.engine.runtime_participation")
if rp.standsDown(entity(id).participation, tostring(engine.mode)) then ... end
typed/builtin//modules/api/engine/sceneRecords/M/markComponentRestored
M.markComponentRestored(entityId: string, componentType: string)
Mark one component instance restored from a scene record, so the saver records it as authored.
Parameters
entityIdstring— Entity the component is attached to.componentTypestring— The component's registry name.
sceneRecords.markComponentRestored(id, "Light")
typed/builtin//modules/api/engine/sceneRecords/M/markEntityBuilt
M.markEntityBuilt(entityId: string)
Mark one entity placed or changed as scene content, for the overlay writer to record.
Parameters
entityIdstring— The entity.
sceneRecords.markEntityBuilt(id)
typed/builtin//modules/api/engine/sceneRecords/M/markEntityRestored
M.markEntityRestored(entityId: string)
Mark one entity as one a record of the scene put in the world, so the saver records it.
Parameters
entityIdstring— The entity.
sceneRecords.markEntityRestored(id)
typed/builtin//modules/api/engine/service/service/authenticated
service.authenticated() -> boolean
Whether a platform identity (JWT) is available to attach to service calls. Returns only a boolean — never the token.
Returns boolean — True if a caller identity is available.
if not service.authenticated() then error("link ZeroMind") end
typed/builtin//modules/api/engine/service/service/balance
service.balance() -> PromiseHandle?
Read the caller's credit balance from ZeroMind. Returns a
promise handle for task.await() resolving the balance JSON, or nil
when the gateway is unconfigured or no caller identity is available.
Returns PromiseHandle? — Promise handle for task.await(), or nil if not ready.
local h = service.balance(); local raw = h and task.await(h)
typed/builtin//modules/api/engine/service/service/gatewayConfigured
service.gatewayConfigured() -> boolean
Whether the ZeroMind service gateway has been configured.
Service handlers use this to distinguish "gateway not configured"
from "not signed in" when invoke returns nil.
Returns boolean — True if the gateway base URL is set.
if not service.gatewayConfigured() then error("no gateway") end
typed/builtin//modules/api/engine/service/service/invoke
service.invoke(offering: string, endpoint: string, opts: InvokeOpts?) -> PromiseHandle?
Invoke a provider offering's logical endpoint through ZeroMind.
Returns a promise handle for task.await() resolving the
InvokeResponse JSON, or nil when the gateway is unconfigured or no
caller identity is available. The JWT and real upstream URL are
never exposed to Luau.
Parameters
offeringstring— Fully-qualified offering identityprovider/name(e.g. "origozero/mesh_gen").endpointstring— Logical endpoint name (e.g. "create_preview").optsInvokeOpts(optional) —{ params?, headers?, body?, max_credits?, idempotency_key? }.
Returns PromiseHandle? — Promise handle for task.await(), or nil if not ready.
local h = service.invoke("origozero/mesh_gen", "create_preview", { body = { prompt = p } })
typed/builtin//modules/api/engine/service/service/invokeStream
service.invokeStream(offering: string, endpoint: string, opts: StreamOpts) -> ServiceStream?
Invoke a provider offering's logical endpoint as a stream. ZeroMind
relays the upstream's server-sent events as they arrive, then ends with
a zeromind.settled event whose data is {"charged":N,"balance":M}, or
a zeromind.failed event whose data is {"reason":...} when the relay
stopped early. A call it refuses before the stream starts arrives as one
zeromind.refused event carrying the HTTP status and the JSON answer
as data; a call that could not be made, or a stream that broke or went
quiet, arrives as zeromind.failed. Returns a stream at once, or nil
when the gateway is unconfigured or no caller identity is available,
exactly as invoke. Take events with stream:poll() (never waits) or
stream:read() (waits for the next event; nil at the end), and release
the connection with stream:close(). opts takes what invoke takes,
plus a required idempotency_key that is unique to this call (ZeroMind
refuses a key a streamed call already used) and an optional timeout_ms
bounding the wait for the response head and for each next chunk (default
120000). The JWT and the real upstream URL are never exposed to Luau.
require("@builtin::modules.serviceCall").stream makes the same call and
reads it to its end: the answer's text, its events and what it charged,
with a refusal read into a reason.
Parameters
offeringstring— Fully-qualified offering identityprovider/name(e.g. "origozero/llm").endpointstring— Logical endpoint name (e.g. "chat").optsStreamOpts—{ params?, headers?, body?, idempotency_key, timeout_ms? }.
Returns ServiceStream? — A stream, or nil if not ready.
local s = service.invokeStream("origozero/llm", "chat", { body = { messages = msgs }, idempotency_key = id })
while s do local ev = s:read(); if ev == nil then break end; print(ev.event, ev.data) end
typed/builtin//modules/api/engine/service/service/jobStatus
service.jobStatus(jobId: string) -> PromiseHandle?
Poll a submitted service job. Returns a promise handle for
task.await() resolving the JobStatusResponse JSON { job_id, status, result?, error? }: status walks pending/running -> succeeded
(with result, the same InvokeResponse invoke returns) or failed
(with error). nil when the gateway is unconfigured or no caller
identity is available.
Parameters
jobIdstring— Job id returned bysubmitJob.
Returns PromiseHandle? — Promise handle resolving the job status JSON, or nil if not ready.
local h = service.jobStatus(jobId); local raw = h and task.await(h)
typed/builtin//modules/api/engine/service/service/quote
service.quote(offering: string, endpoint: string, opts: InvokeOpts?) -> PromiseHandle?
Read an exact tier price without charging or calling a provider.
Parameters
offeringstringendpointstringoptsInvokeOpts(optional)
Returns PromiseHandle?
typed/builtin//modules/api/engine/service/service/submitJob
service.submitJob(offering: string, endpoint: string, opts: InvokeOpts?) -> PromiseHandle?
Submit a durable async invocation of an offering endpoint. Same
arguments as invoke, but the provider round-trip runs server-side
(off this connection), so a slow synchronous provider or a dropped
link no longer loses the result. Returns a promise handle for
task.await() resolving { job_id, status }; poll it with
jobStatus. nil when the gateway is unconfigured or no caller
identity is available.
Parameters
offeringstring— Fully-qualified offering identityprovider/name(e.g. "origozero/mesh_gen").endpointstring— Logical endpoint name (e.g. "create_preview").optsInvokeOpts(optional) —{ params?, headers?, body?, max_credits?, idempotency_key? }.
Returns PromiseHandle? — Promise handle resolving { job_id, status }, or nil if not ready.
local h = service.submitJob("origozero/mesh_gen", "create_preview", { body = { prompt = p } })
typed/builtin//modules/api/engine/shader/shader/compile
shader.compile(keys: string | { string }, opts: { [string]: any }) -> boolean
Compile a zero-scaffolding SURFACE shader: the author wrote only
vertex() / fragment() and declared its material properties, and the
engine generates the group(1) material interface plus every render-mode
entry point. Compiles once and registers the result under its key.
Parameters
keysstring | { string }— The shader key (guid@checksumof the version compiled), alone or as a one-element array.opts{ [string]: any }—{ source, domain?, properties?, replaces? }— the author's WGSL, its@domain, the declared property schema, and the key this shader compiled under before its source changed, whose materials move to the new key.
Returns boolean — True when the compile was queued.
local m = asset.meta(ref); shader.compile(m.guid .. "@" .. m.checksum, { source = wgsl, properties = props })
typed/builtin//modules/api/engine/shader/shader/forget
shader.forget(keys: string | { string }) -> boolean
Drop what a removed shader registered under its key: its programs and their variants, the composed WGSL, the compile status and the diagnostic. The pipelines built from those programs are evicted and the materials drawing through them re-prepare.
Parameters
keysstring | { string }— The shader key (guid@checksum), alone or in an array.
Returns boolean — True when the removal was queued.
local m = asset.meta(ref); shader.forget(m.guid .. "@" .. m.checksum)
typed/builtin//modules/api/engine/shader/shader/registerModule
shader.registerModule(keys: string | { string }, source: string) -> boolean
Register a block of WGSL other shaders include. Every key names the same source, so a shader includes it by whichever name it holds — its guid, its identity, or an alias. Registering again replaces it, and the shaders that include it recompile.
Parameters
keysstring | { string }— One key, or the array of keys this module answers to.sourcestring— The module's WGSL.
Returns boolean — True when the registration was queued.
shader.registerModule({ ref.guid, ref.identity }, wgsl)
typed/builtin//modules/api/engine/shader/shader/status
shader.status(name: string) -> (string, string?)
A shader's latest compile outcome, without reading the engine log:
"compiled", "failed" (with the compiler error second), or "pending".
Compilation is async, so a "pending" straight after a write means ask
again next frame.
Parameters
namestring— The key it compiled under (guid@checksum), or a reference to a shader asset (identity, path, guid), which reaches the key of the version that reference resolves to now.
Returns (string, string?) — Status, and the compiler error when it failed.
local status, err = shader.status("myShader")
typed/builtin//modules/api/engine/shell/shell/close
shell.close(handle: string)
Release a caller-owned stream handle and terminate any command using it.
Parameters
handlestring— Stream handle returned by shell.start.
typed/builtin//modules/api/engine/shell/shell/interrupt
shell.interrupt(handle: string, signal: number?) -> boolean
Interrupt a command with signal 2 (SIGINT, the default), or terminate its shell with signal 15 (SIGTERM). Interactive SIGINT returns to the prompt; a command reports 128 plus the signal. Drain output afterwards.
Parameters
handlestring— Stream handle returned by shell.start.signalnumber(optional) — 2 or 15.
Returns boolean — Whether the execution was active.
typed/builtin//modules/api/engine/shell/shell/read
shell.read(handle: string) -> ShellStreamRead
Drain up to 64 KiB from each output stream and renew the handle's lease. Output bytes are base64 strings. exitCode is nil while the command runs or output remains buffered; its terminal value accompanies the final bytes.
Parameters
handlestring— Stream handle returned by shell.start.
Returns ShellStreamRead — Separate output bytes and the terminal exit status when available.
typed/builtin//modules/api/engine/shell/shell/run
shell.run(command: string, sessionKey: string?) -> ShellResult
Execute a command in the engine's emulated Unix shell and
return once it has completed. This is the same shell as the MCP
bash tool — 60+ builtins (ls, cat, grep, find, echo, ...)
operating on the virtual scene filesystem. A command that runs
Luau (run, luau, zm, zero) needs the engine's frame loop,
and a command whose work is a wait (sleep) cannot take its
interval while holding it, so from a coroutine the whole line is
queued to run off the frame loop and this yields until it
finishes; everything else runs inline. The queued run starts the
line again from the top, so a line that had already written a
file, sent a request, read input or started a background job
comes back with the explanation in stderr and shell.runAsync
as the way to run it whole. A command reaches the files the code
running it reaches, the jobs it starts and the Luau it runs
included: run for code a world ships, it is refused the home folder
(/zero/home) the way vfs refuses that code.
Parameters
commandstring— Shell command to execute.sessionKeystring(optional) — Which caller's shell session the command runs in. A session holds what a command leaves behind: the directorycdmoved to, exports, shell functions,set -e. It hands that to the next command run under the same key. Omit it and the command runs in the session of the caller this code runs on behalf of, the one that caller'sbashcommands also use; code with no attested caller behind it runs in the session every caller that names none shares. A command run for code a world ships keeps what it leaves behind in a session of that code's own under the key: it reaches that code's next command and never a command of the caller's own.
Returns ShellResult — Command result { stdout, stderr, exitCode, ok }.
local r = shell.run("ls /zero/source")
typed/builtin//modules/api/engine/shell/shell/runAsync
shell.runAsync(command: string, sessionKey: string?) -> string
Asynchronous version of shell.run. Returns a promise ID that
resolves to a JSON-encoded result string. Use with
task.await().
Parameters
commandstring— Shell command to execute.sessionKeystring(optional) — Which caller's shell session the command runs in. A session holds what a command leaves behind: the directorycdmoved to, exports, shell functions,set -e. It hands that to the next command run under the same key. Omit it and the command runs in the session of the caller this code runs on behalf of, the one that caller'sbashcommands also use; code with no attested caller behind it runs in the session every caller that names none shares. A command run for code a world ships keeps what it leaves behind in a session of that code's own under the key: it reaches that code's next command and never a command of the caller's own.
Returns string — Promise ID — pass to task.await() to get the JSON result.
local json = task.await(shell.runAsync("find /zero -name '*.luau'"))
typed/builtin//modules/api/engine/shell/shell/start
shell.start(command: string, interactive: boolean?) -> string
Start a caller-owned command with bounded stdin, stdout and stderr streams. Read the handle at least once every 120 seconds to keep it alive. Close it when finished. An interactive session starts with an empty command and reads complete commands from stdin until exit or EOF.
Parameters
commandstring— Command text, or an empty string for an interactive session.interactiveboolean(optional) — Read commands interactively from stdin.
Returns string — Stream handle belonging to this caller and client.
typed/builtin//modules/api/engine/shell/shell/write
shell.write(handle: string, bytes: string, eof: boolean?) -> boolean
Queue input bytes and optionally close stdin. Each chunk is at most 256 KiB. False means the input queue is full or closed: drain output, check its exit status, and retry the same bytes while execution continues.
Parameters
handlestring— Stream handle returned by shell.start.bytesstring— Input bytes.eofboolean(optional) — Close stdin after these bytes.
Returns boolean — Whether the entire chunk was accepted.
typed/builtin//modules/api/engine/skeleton/skeleton/applyPose
skeleton.applyPose(sinkHandle: number, poseBuffer: Substrate.TypedBuffer) -> boolean
Snapshot the buffer's first layout.total_floats values and
queue a pending apply for the next ECS drain. Returns false on
unknown sink/buffer or buffer too small for the layout. The
Buffer is unchanged.
Parameters
sinkHandlenumber— Sink handle frombindPose.poseBufferSubstrate.TypedBuffer— The pose buffer to apply.
Returns boolean — True on success.
typed/builtin//modules/api/engine/skeleton/skeleton/bindClip
skeleton.bindClip(zanimBytes: buffer | string, boneOrder: { string }, restPose: { number }?, shapes: { ClipShape }?) -> ClipBindInfo?
Decode a zanim payload and bind it to boneOrder,
precomputing which of the clip's channels feed each bone so
per-frame sampleClip is allocation-free. With restPose (the
body's stride-10 rest, one record per bone of boneOrder), every
sampleClip writes the body's complete local pose: a bone the clip
does not name holds its rest record, and a bone it names takes the
clip's rotation, its rest translation plus the clip's displacement
from the clip's start, and its rest scale. With shapes (the
body's blend shapes), every sample writes after the bone records one
weight per shape and then one coverage per shape: a shape one of the
clip's weight tracks names (by any of the shape's names, exactly, else
ignoring case, spaces, _, - and .) takes the track's weight at
coverage 1, every other shape its rest weight at coverage 0.
boneOrder may be empty for a body with shapes and no bones. Returns
{ handle, matched, total, duration, shapesMatched, shapesTotal },
or nil on a malformed payload, a bind with neither bones nor shapes,
or a rest pose short of one record per bone. Check matched: 0 means
the clip drives none of these bones.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).boneOrder{ string }— Output bone names — one stride-10 record per bone.restPose{ number }(optional) — The body's stride-10 rest pose; given, samples are complete local poses over it.shapes{ ClipShape }(optional) — The body's blend shapes, written after the bones.
Returns ClipBindInfo? — { handle, matched, total, duration, shapesMatched, shapesTotal }, or nil.
local info = skeleton.bindClip(bytes, layout.boneOrder, layout.restPose)
local face = skeleton.bindClip(bytes, {}, nil, { "mouthSmileLeft", "eyeBlink" })
typed/builtin//modules/api/engine/skeleton/skeleton/bindPose
skeleton.bindPose(entityId: (string | entityRef)?, opts: SkeletonLayout) -> number?
Register a pose sink targeting entityId. The opts table
carries the layout: boneOrder is the bone-name array
({"hip", "spine", ...}), stride defaults to 10
(translation.xyz + rotation.xyzw + scale.xyz). Pass entityId
as nil to use the current component's owning entity.
Parameters
entityId(string | entityRef)(optional) — Engine entity id or proxy, or nil for the current entity.optsSkeletonLayout—{ boneOrder, stride }.
Returns number? — Sink handle, or nil.
local h = skeleton.bindPose(nil, { boneOrder = bones, stride = 10 })
typed/builtin//modules/api/engine/skeleton/skeleton/clipBones
skeleton.clipBones(zanimBytes: buffer | string) -> { string }?
Decode a zanim payload and return its bone-name array. Pure:
build a bind order or a retarget map from a clip without binding a
sampler. Returns nil on bytes that aren't a valid zanim payload.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns { string }? — Bone names referenced by the clip, or nil.
local names = skeleton.clipBones(assert(vfs.read(path .. "/data.zanim")))
typed/builtin//modules/api/engine/skeleton/skeleton/clipDecode
skeleton.clipDecode(zanimBytes: buffer | string) -> string?
Decode a zanim payload to its readable JSON form
({ name, duration, channels, bone_names }), the clip as text to
read, store or diff. The binary parse is the engine's. Code that
transforms a clip's channels in Luau (e.g. the retarget bake) reads
the same clip as a table with clipToTable, which skips the text.
Returns nil on bytes that aren't a valid zanim payload. Inverse of
clipEncode.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns string? — The clip as a JSON string, or nil.
local json = require("@builtin::modules.json")
local clipJson = skeleton.clipDecode(bytes)
local clip = if clipJson then json.decode(clipJson) else nil
typed/builtin//modules/api/engine/skeleton/skeleton/clipEncode
skeleton.clipEncode(jsonString: string) -> string?
Encode a clip's JSON form (the shape clipDecode returns) back
to a zanim payload — the bytes a .animation stores and
bindClip/sampleClip consume. Inverse of clipDecode. A clip
held as a table encodes with clipFromTable, which skips the text.
Returns nil on invalid JSON.
Parameters
jsonStringstring— A clip JSON document.
Returns string? — The clip's zanim payload bytes, or nil.
local json = require("@builtin::modules.json")
local bytes = skeleton.clipEncode(json.encode(clip))
typed/builtin//modules/api/engine/skeleton/skeleton/clipFromTable
skeleton.clipFromTable(clip: { [string]: any }) -> (string?, string?)
Encode a clip table (the shape clipToTable returns) to a zanim
payload, the bytes a .animation stores and bindClip/sampleClip
consume. Every field is required and every number finite. Inverse of
clipToTable. Returns nil and the reason, naming the field, when the
table is not a clip.
Parameters
clip{ [string]: any }— A clip table:{ name, duration, channels, bone_names }.
Returns (string?, string?) — The clip's zanim payload bytes, or nil and the reason.
local bytes = skeleton.clipFromTable(clip)
typed/builtin//modules/api/engine/skeleton/skeleton/clipPack
skeleton.clipPack(packed: PackedClip) -> (string?, string?)
Encode a clip in packed form (the shape clipUnpack returns) into
zanim bytes. Channels may share one run of times by naming the same
keyOffset; interpolation defaults to Linear; with no boneNames the
clip names its bones in the order its channels first drive them.
times and values take a compute readback's resultBytes()
directly. Returns nil and the reason, naming the channel, when a
channel's keys fall outside the runs or its times run backwards.
Parameters
packedPackedClip— The packed clip.
Returns (string?, string?) — The clip's zanim payload bytes, or nil and the reason.
local bytes = skeleton.clipPack(packed)
typed/builtin//modules/api/engine/skeleton/skeleton/clipShapes
skeleton.clipShapes(zanimBytes: buffer | string) -> { string }?
Decode a zanim payload and return the names of the blend
shapes (morph targets) its weight tracks drive, in the order the
tracks first name them. Returns nil on bytes that aren't a valid
zanim payload.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns { string }? — Blend-shape names the clip drives, or nil.
local shapes = skeleton.clipShapes(assert(vfs.read(path .. "/data.zanim")))
typed/builtin//modules/api/engine/skeleton/skeleton/clipToTable
skeleton.clipToTable(zanimBytes: buffer | string) -> { [string]: any }?
Decode a zanim payload to a table: { name, duration, channels = { { target_bone, path, keyframes_in, keyframes_out, interpolation } }, bone_names }, the shape clipDecode writes as JSON, built by the engine
in place. path is Translation, Rotation, Scale or Weights (a
blend shape's weight, one value a key, target_bone naming the shape);
interpolation is Linear, Step or CubicSpline. Inverse of clipFromTable.
Returns nil on bytes that aren't a valid zanim payload.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns { [string]: any }? — The clip as a table, or nil.
local clip = skeleton.clipToTable(bytes)
typed/builtin//modules/api/engine/skeleton/skeleton/clipUnpack
skeleton.clipUnpack(zanimBytes: buffer | string) -> PackedClip?
Decode a zanim payload into its packed form: a channel table
({ bone, path, interpolation, keyOffset, keyCount, valueOffset },
offsets 0-based element indices) and two buffers of little-endian
f32s, times and values, holding every channel's keys channel after
channel (3 floats a key for Translation and Scale, 4 for Rotation, 1 for
Weights, three times that for CubicSpline). A Weights channel's bone
names the blend shape it drives. The runs go straight into a typed buffer
(buf:writeBytes(packed.values)) for a compute pass. Returns nil on
bytes that aren't a valid zanim payload. Inverse of clipPack.
Parameters
zanimBytesbuffer | string— The clip'sdata.zanimpayload bytes (binary-safe).
Returns PackedClip? — The packed clip, or nil.
local packed = skeleton.clipUnpack(bytes)
typed/builtin//modules/api/engine/skeleton/skeleton/jointTransforms
skeleton.jointTransforms(entityId: string | entityRef) -> table
Read a skinned entity's per-joint world transforms for the current animated pose.
Parameters
entityIdstring | entityRef— Engine entity id or proxy of a skinned entity.
Returns table — Array of joint transforms: { position, matrix, parent, name }.
local joints = skeleton.jointTransforms(meshId)
typed/builtin//modules/api/engine/skeleton/skeleton/sampleClip
skeleton.sampleClip(handle: number, time: number, poseBuffer: Substrate.TypedBuffer) -> boolean
Sample the bound clip at time (clamped to [0, duration])
and write one stride-10 pose record per bound bone into the
Buffer, starting at index 0, then, for a clip bound with shapes,
one weight per shape and one coverage per shape. Bones the clip
does not drive are written as identity, or as their rest record for
a clip bound with a rest pose. Returns false on unknown
handle/buffer or a buffer too small for what the sampler writes.
Parameters
handlenumber— Sampler handle frombindClip.timenumber— Sample time in seconds.poseBufferSubstrate.TypedBuffer— The stride-10 pose buffer written into.
Returns boolean — True on success.
typed/builtin//modules/api/engine/skeleton/skeleton/unbindClip
skeleton.unbindClip(handle: number) -> boolean
Drop the bound clip sampler from the registry.
Parameters
handlenumber— Sampler handle to remove.
Returns boolean — True if the sampler existed.
typed/builtin//modules/api/engine/skeleton/skeleton/unbindPose
skeleton.unbindPose(sinkHandle: number) -> boolean
Remove the sink from the registry.
Parameters
sinkHandlenumber— Sink handle to remove.
Returns boolean — True if the sink was present.
typed/builtin//modules/api/engine/sky/sky/describeDrawn
sky.describeDrawn() -> SkyDescription
The description of the drawn sky from engine state alone: the drawn
material, the hour of a sky that has one, and the direction toward the sun
the scene is lit from. members is empty.
Returns SkyDescription — A SkyDescription.
local d = sky.describeDrawn()
typed/builtin//modules/api/engine/sky/sky/drawn
sky.drawn() -> DrawnSky?
The sky drawn now, as a table of three fields: entity, the id of the
entity whose Sky row is in force; source, the AssetRef<sky> that row
was written for (the outermost registered sky over the application that
wrote it; nil for a hand-placed component's row or a raw row); and
description, { material?, timeOfDay?, sunDirection?, members, notice? }:
the material it draws, the hour it draws, the unit direction toward the sun
the scene is lit from, each top-level member's source by id and what its
members state about their settings (the description that sky registered,
else one built from engine state with members empty). Nil when no row is
in force: the scene has no sky.
Returns DrawnSky? — { entity, source?, description }, or nil.
local drawn = sky.drawn(); if drawn then print(drawn.description.timeOfDay) end
typed/builtin//modules/api/engine/sky/sky/drawnGradient
sky.drawnGradient() -> { [string]: { number } }?
The sky gradient drawn now, as a table of three colours, each a list
of three numbers { r, g, b } from 0 to 1: zenith, the colour straight
up; horizon, the colour at the horizon; ground, the colour below it.
They are the colours the writer of the row in force draws at the hour it
draws (a procedural backdrop's after its night and dawn tints), else the
colours the row states. Nil when no row is in force.
Returns { [string]: { number } }? — { zenith, horizon, ground }, or nil.
local g = sky.drawnGradient(); if g then print(g.zenith[1]) end
typed/builtin//modules/api/engine/sky/sky/forgetRow
sky.forgetRow(entityId: string)
Forget the writer of an entity's row: the row has left with the entity or been removed. On the next frame, once the engine draws the sky that stands after it, every light that follows the sky is oriented by that sky; with no sky drawn, they are left as they are.
Parameters
entityIdstring— The entity that carried the row.
sky.forgetRow(e.id)
typed/builtin//modules/api/engine/sky/sky/get
sky.get() -> { [string]: any }
Get all current sky configuration as a table. Returns the
same fields as sky.set accepts, plus read-only fields like
material_name, type and authored_by (the id of the entity
whose Sky row is in force, nil when no row stands). While a ProceduralSky draws the sky, its fields are
that component's values. Color values are returned as positional
arrays [r, g, b].
Returns { [string]: any } — Full sky configuration table.
local cfg = sky.get(); print(cfg.time_of_day)
typed/builtin//modules/api/engine/sky/sky/getTimeOfDay
sky.getTimeOfDay() -> number
Get the current time of day in hours (0-24): the timeOfDay of
the ProceduralSky drawing the sky while one does.
Returns number — Current time of day.
local t = sky.getTimeOfDay()
typed/builtin//modules/api/engine/sky/sky/orientFollower
sky.orientFollower(entityId: string)
Orient the directional light on entityId from the sky drawn now,
when the row in force was written by a sky that drives the sun. A light
that starts following the sky (lighting.followSky) is oriented here at
once.
Parameters
entityIdstring— The entity carrying the light.
sky.orientFollower(sunId)
typed/builtin//modules/api/engine/sky/sky/preset
sky.preset(name: string)
Apply a named sky preset. Available: clear_day, sunset,
sunrise, overcast, night, studio, none. While a
ProceduralSky draws the sky, clear_day through night are applied
as that component's own preset, which sets its look, its time of day
and the sun under it. Raises a Luau error for unrecognized names —
wrap in pcall if uncertain.
Parameters
namestring— Preset name (case-sensitive).
sky.preset("sunset")
typed/builtin//modules/api/engine/sky/sky/registerSky
sky.registerSky(owner: string, skyAsset: any?, describe: ((owner: string) -> SkyDescription)?)
Register an application that composes a sky, by its owner, so the drawn sky answers with the asset and the description of that application while a row written under its owner is in force.
Parameters
ownerstring— The application's owner.skyAssetany(optional) — The applied asset.describe((owner: string) -> SkyDescription)(optional) — Describes the sky the application puts in force, given its owner; nil describes it from engine state (sky.describeDrawn).
sky.registerSky(owner, self, function(o) return self:describeSky(o) end)
typed/builtin//modules/api/engine/sky/sky/set
sky.set(opts: SkyOpts)
Configure the scene's sky. All fields are optional — only
provided fields are updated. While a ProceduralSky draws the sky,
its fields (time_of_day, auto_cycle, cycle_speed,
sync_sun_to_light, exposure, the colours and the sun, star, moon
and haze parameters) are written onto that component, so the sun, the
sky material and the picture change with them. Color fields accept
both named {x=r, y=g, z=b} and positional {r, g, b} forms.
color is an alias for solid_color.
Parameters
optsSkyOpts— Sky configuration properties.
sky.set({ type = "procedural", time_of_day = 14, sync_sun_to_light = true })
typed/builtin//modules/api/engine/sky/sky/setSunDirection
sky.setSunDirection(dir: SkyColor)
Set an explicit sun direction and disable time-based sun
positioning. When the scene's sun keeps its fields elsewhere
(lighting.setLightWriter), the direction goes to its writer. Otherwise
the sky configuration takes it directly and the directional light is
updated to match.
Parameters
dirSkyColor— Normalized sun direction vector.
sky.setSunDirection({ 0.5, -1, 0.3 })
typed/builtin//modules/api/engine/sky/sky/setTimeOfDay
sky.setTimeOfDay(time: number)
Set the time of day (0-24 hours). 0 = midnight, 6 = sunrise,
12 = noon, 18 = sunset. When the sky drawn now was written by an applied
asset, the hour lands on that asset as appliedSystem.write lands it: on
the owner that states it, else as its live value. While a
ProceduralSky draws the sky, its timeOfDay is set, which places the
sun and, with syncSunToLight on, orients and colours the scene's
directional light. Otherwise the sky configuration takes it directly.
Parameters
timenumber— Time of day in hours.
sky.setTimeOfDay(18.5)
typed/builtin//modules/api/engine/sky/sky/unregisterSky
sky.unregisterSky(owner: string)
Withdraw a sky application's registration.
Parameters
ownerstring— The application's owner.
sky.unregisterSky(owner)
typed/builtin//modules/api/engine/sky/sky/writeRow
sky.writeRow(entityId: string, fields: { [string]: any }, writer: SkyWriter?)
Write the Sky row on an entity and record who wrote it. The row is
the sky the engine draws once it is the row in force; a backdrop states
{ asset } (the asset of its application), a sky type that writes on an
application's entity states { asset, owner }. Nothing is written on the
entity beside the row.
Parameters
entityIdstring— The entity carrying the row.fields{ [string]: any }— The row's fields, asecs.Skytakes them.writerSkyWriter(optional) —{ asset?, owner?, orient? }.
sky.writeRow(e.id, { skyType = "procedural", timeOfDay = 9 }, { asset = ctx.asset.guid })
typed/builtin//modules/api/engine/sky/sky/writerOf
sky.writerOf(entityId: string) -> SkyWriter?
Who wrote the Sky row on an entity, as sky.writeRow recorded it:
{ asset?, owner? }. Nil for a row sky.writeRow did not write (a
hand-placed component's, a raw row).
Parameters
entityIdstring— The entity carrying the row.
Returns SkyWriter? — The writer, or nil.
local w = sky.writerOf(sky.drawn().entity)
typed/builtin//modules/api/engine/sourceEdits/M/candidate
M.candidate(path: string, source: string, priorRefs: string?) -> string
Validate a candidate source's syntax and derive what storing it would state, without writing it.
Parameters
pathstring— Canonical authored source file path.sourcestring— Candidate UTF-8 text, at most 16 MiB.priorRefsstring(optional) — The accepted reference table, in disk or manifest wire form; its recorded identities are kept.
Returns string — JSON {checksum, size, kind, refsJson}.
local checksum = Json.decode(sourceEdits.candidate(path, text)).checksum
typed/builtin//modules/api/engine/sourceEdits/M/checkWrite
M.checkWrite(path: string, materialize: boolean?) -> string
The canonical path a source write may take; raises with editing guidance when the path refuses writes.
Parameters
pathstring— Existing or proposed source path.materializeboolean(optional) — True to write a type-declared computed output.
Returns string — Canonical writable path.
local target = sourceEdits.checkWrite("/zero/source/scenes/a.scene/scene.json", true)
typed/builtin//modules/api/engine/sourceEdits/M/folderChecksum
M.folderChecksum(leavesJson: string) -> string
The storage checksum of a folder asset from every leaf beneath it.
Parameters
leavesJsonstring— JSON object mapping each leaf's path relative to the folder to its storage checksum.
Returns string — The folder's storage checksum.
local sum = sourceEdits.folderChecksum(Json.encode({ ["init.luau"] = leafSum }))
typed/builtin//modules/api/engine/sourceEdits/M/newIdentity
M.newIdentity() -> string
A new UUID for an operation or a new asset.
Returns string — UUID identity.
local guid = sourceEdits.newIdentity()
typed/builtin//modules/api/engine/stream/stream/accept
stream.accept(listener: string) -> string?
Take the connection that has waited longest on the listener, as a
stream handle that reads, writes, and closes exactly like one
stream.open returned. Returns nil when nothing is waiting, so call
it in a loop each tick to take every peer that arrived.
stream.listenerStatus(listener).pending is how many are still
waiting.
Parameters
listenerstring— Listener handle from stream.listen.
Returns string? — The connection's stream handle, or nil when none is waiting.
while true do local h = stream.accept(listener); if not h then break end; table.insert(peers, h) end
typed/builtin//modules/api/engine/stream/stream/close
stream.close(handle: string) -> boolean
Finish whatever handle names — a stream or a listener — and
drop it from the registry.
Closing a stream refuses every later write and carries the bytes
already queued to the peer before the connection ends, so a write and
a close in the same tick deliver — the shape a request answered with
one response has. A peer that has stopped reading altogether holds
that finish for thirty seconds; past that the connection ends and
what is still queued ends with it, so a caller that must know its
bytes went out watches stream.status(handle).pending reach zero
before it closes.
Closing a listener stops it answering new peers and closes the
connections nobody took; the connections stream.accept already
handed over keep running until they are closed themselves.
Parameters
handlestring— Stream handle from stream.open or stream.accept, or listener handle from stream.listen.
Returns boolean — True if a stream or listener was closed, false if handle already named none.
stream.write(peer, response); stream.close(peer)
typed/builtin//modules/api/engine/stream/stream/listen
stream.listen(url: string, opts: StreamListenOpts?) -> PromiseHandle
Hold the address url names and answer the peers that dial it —
the other direction from stream.open, for when the thing you are
talking to starts the conversation and restarts on its own schedule.
Returns a promise handle: task.await() it to get the listener
handle once the address is held, or it raises the reason a malformed
url, a scheme that cannot listen, or a failed bind was refused with.
Take the connections with stream.accept.
The host in the url is the interface bound, and the whole of what
decides who can reach it. tcp://127.0.0.1:9000 answers only
programs on this same machine. tcp://0.0.0.0:9000 answers any host
that can route to this machine on that port — every device on the
wifi, and anything beyond it the network lets through. Write the one
you mean; there is no default, and stream.listenerStatus reports
which of the two you got. A port of 0 asks the operating system to
choose one, which that same status then reports.
opts.inboundCapacity and opts.outboundCapacity bound each
answered connection (65536 bytes each by default);
opts.backlog bounds the connections held for stream.accept
before the listener stops taking them from the operating system,
which leaves the rest queued in the kernel rather than answered and
forgotten (16 by default, and at least 1).
The listener belongs to the chunk that opened it — the chunk whose
own code called stream.listen, which is the module holding that
line even when something else called into it. When that chunk runs
again — a module hot-reload, a cleared require cache — the listener
and the connections it answered are closed, and the new run binds the
address for itself. Peers see the connection close and dial again.
stream.listeners() names that chunk as each entry's owner.
Parameters
urlstring— Listen URL — scheme://host:port.optsStreamListenOpts(optional) — Per-connection capacities and the accept backlog (optional).
Returns PromiseHandle — Promise handle for task.await().
local pending = stream.listen("tcp://127.0.0.1:9000"); local listener = task.await(pending)
typed/builtin//modules/api/engine/stream/stream/listenerStatus
stream.listenerStatus(listener: string) -> ListenerStatus?
Report what the listener holds and has handed over. address is
the address the operating system resolved the bind to, port
included — the one to hand a peer. reach says who can connect to
it: "thisMachine" when it is a loopback address and only programs
on this machine can, "network" when any host that can route here
can. accepted counts the connections stream.accept handed over,
pending the ones still waiting, and capacity the value pending
may reach before the listener stops taking connections from the
operating system. nil when handle names no open listener.
Parameters
listenerstring— Listener handle from stream.listen.
Returns ListenerStatus? — Listener status, or nil when handle names no open listener.
local s = stream.listenerStatus(listener); print(s.address, s.reach, s.pending)
typed/builtin//modules/api/engine/stream/stream/listeners
stream.listeners() -> { OpenListener }
Every listener this engine currently holds an address for, in the
order they were opened. Each entry is what stream.listenerStatus
reports about it, plus the handle it is addressed by and the owner
chunk its life follows.
This is how an address is reached again once nothing holds its handle:
filter on address for the port you want and close the entry by its
handle, rather than guessing at handles.
Returns { OpenListener } — An array of open listeners.
for _, l in stream.listeners() do if l.address == want then stream.close(l.handle) end end
typed/builtin//modules/api/engine/stream/stream/open
stream.open(url: string, opts: StreamOpenOpts?) -> PromiseHandle
Open a byte stream at url (scheme://target[?k=v]). loopback
carries written bytes back out of the same stream and works on
every platform; tcp dials host:port; tty opens a serial
device node — /dev/ttyACM0 or /dev/ttyUSB0 for a USB CDC board
such as an ESP32, /dev/rfcomm0 for a Bluetooth controller paired
over classic SPP (both present as a tty on Linux, so one transport
serves either peer), COM5 on Windows. tty query parameters:
baud (default 115200), dataBits (5-8, default 8), parity
(none | odd | even, default none), stopBits (1 or 2,
default 1).
ble connects to a Bluetooth Low Energy device over GATT, on a
desktop engine and in a browser alike — the wireless transport a
web world reaches a device through:
ble://<device>?service=<uuid>&write=<uuid>¬ify=<uuid>. The
device is the name it advertises, * any device offering the
service, a trailing * a name prefix (Paw*). write is the
characteristic this engine writes to and notify the one it
subscribes to, which on a Nordic UART peripheral are that
peripheral's RX and TX; a module with one bidirectional
characteristic names it for both. UUIDs may be 16-bit (ffe0),
32-bit, or full. Optional: chunk (bytes per packet, 1-512 —
otherwise what the connection carries), writeMode
(withResponse | withoutResponse, default withResponse),
timeout (seconds to find and connect to the device, default
15).
opts bounds the stream's undrained inbound buffer
and in-flight outbound bytes (default 65536 each). Returns a
promise handle: task.await() it
to get the stream handle once the transport is open, or it raises
the reason a malformed url, an unknown or unsupported scheme, or a
failed connect was refused with. A ble stream resolves as soon as
it exists and reports the rest as state — watch
stream.status(handle).state go opening, permissionPending
while the browser asks the person at the machine to pick a device,
then open; writes made meanwhile are queued and go out when it
connects. Check stream.transports() first
to tell a mistyped scheme from one this build does not carry.
Parameters
urlstring— Stream URL — scheme://target[?k=v&k=v].optsStreamOpenOpts(optional) — Buffer capacities (optional).
Returns PromiseHandle — Promise handle for task.await().
local pending = stream.open("loopback://echo"); local handle = task.await(pending)
local paw = task.await(stream.open("ble://Paw*?service=ffe0&write=ffe1¬ify=ffe1"))
typed/builtin//modules/api/engine/stream/stream/read
stream.read(handle: string, max: number?) -> string
Drain up to max buffered inbound bytes from the stream.
Parameters
handlestring— Stream handle from stream.open.maxnumber(optional) — Maximum bytes to drain (optional). Omit to drain everything buffered.
Returns string — Drained bytes, byte-safe. "" when none buffered or handle names no open stream.
local chunk = stream.read(handle)
typed/builtin//modules/api/engine/stream/stream/serialPorts
stream.serialPorts() -> SerialPorts
Every serial device this machine has, for picking the one to open.
ports is an array ordered by path. Each entry carries the path the
device is at (/dev/ttyACM0 on Linux, COM3 on Windows), the url
that opens it, the kind of bus it attaches by, and — for a USB
device — the vendorId, productId, serialNumber, manufacturer
and product it advertises.
A device's path moves with enumeration order: a board that came up at
/dev/ttyACM0 is at /dev/ttyACM1 once something else is plugged in
first, and moves across COM3-COM5 on Windows. What the device
advertises holds still across those moves, so match on
vendorId/productId — or on serialNumber to tell two of the same
board apart — and open the url that entry carries, appending the
port settings stream.open documents.
Three answers are distinct. supported false with a reason means
this platform has no serial bus to enumerate at all. error set means
it has one and the operating system refused this enumeration, so a
later call may answer. An empty ports with neither means the machine
has no serial device attached, which is an ordinary result.
Returns SerialPorts — { supported, reason, error, ports } — the platform's answer, this enumeration's, and the devices it found.
for _, p in stream.serialPorts().ports do if p.vendorId == 0x303A then print(p.url, p.product) end end
typed/builtin//modules/api/engine/stream/stream/status
stream.status(handle: string) -> StreamStatus?
Report what the stream has carried and lost. state is where
the stream is in its life: opening, permissionPending while the
platform asks the person at the machine to allow the connection,
open, denied when that permission was refused, and closed
when it is finished. pending is bytes
accepted and not yet handed to the peer; capacity is the value
pending may reach before a write is refused. error holds the
most recent transport failure and the refusal a denied stream
carries, retained for the life of the
stream. nil when handle names no open stream.
Parameters
handlestring
Returns StreamStatus? — Stream status, or nil when handle names no open stream.
local s = stream.status(handle); print(s.pending, s.capacity)
typed/builtin//modules/api/engine/stream/stream/streams
stream.streams() -> { OpenStream }
Every open stream, dialled or answered, in the order they were
opened. Each entry is what stream.status reports about it, plus the
handle it is addressed by and the owner chunk its life follows —
a connection stream.accept handed over carries the owner of the
listener that answered it.
Returns { OpenStream } — An array of open streams.
for _, s in stream.streams() do print(s.handle, s.transport, s.pending, s.owner) end
typed/builtin//modules/api/engine/stream/stream/transports
stream.transports() -> { [string]: TransportSupport }
Every stream scheme this build knows about — a capability
probe, in both directions. supported answers stream.open and
listen answers stream.listen, since a scheme can carry one and
not the other. Each reason is nil when its direction works,
otherwise it names why not: an unbuilt transport names its own
absence, a transport this platform lacks (tcp and tty on wasm;
ble in a browser without Web Bluetooth or with the radio off,
which the page itself answers) names that, and a loopback stream,
whose peer is itself, names that nothing dials it. A typo'd scheme
is absent from this table entirely, which is what tells it apart
from a real transport this build lacks.
Returns { [string]: TransportSupport } — Map of scheme name to { supported, reason, listen, listenReason }.
local t = stream.transports(); if not t.tcp.listen then warn(t.tcp.listenReason) end
typed/builtin//modules/api/engine/stream/stream/write
stream.write(handle: string, bytes: string) -> WriteOutcome
Queue bytes for the stream's peer. Never blocks. "accepted"
means the bytes were queued. "full" means the outbound queue has
no room right now — backpressure, not failure: the peer is alive
and draining slower than this call is producing, so a retry after
it catches up can succeed. Compare pending against capacity on
stream.status() to see it coming before a write is refused.
"closed" means the stream is finished, or handle names no open
stream — reopen to continue, retrying never succeeds. "tooLarge"
means bytes is bigger than the stream's whole outbound capacity, so
it can never fit at any queue depth — retrying the same write
returns this again.
Parameters
handlestring— Stream handle from stream.open.bytesstring— Bytes to queue, byte-safe.
Returns WriteOutcome — "accepted" | "full" | "closed" | "tooLarge"
local outcome = stream.write(handle, data)
typed/builtin//modules/api/engine/streaming/streaming/cells
streaming.cells() -> { [string]: any }
What the spatial-streaming store has resident: the configured radii and budget, the counters the store keeps, and one row per cell with how many of its groups are standing, what it costs, and whether a release wrote it to a file it now reads back from.
Returns { [string]: any } — { config, stats, sources, cells, proxies }.
local s = streaming.cells()
typed/builtin//modules/api/engine/streaming/streaming/levels
streaming.levels(scene: any?) -> { [string]: any }
Which level the viewport draws every mesh-LOD receiver at, and the
screen fraction that selection was measured from.
A receiver whose entity the scene no longer holds is reported as
standing = false: the chain is registered and there is nothing left for
it to draw.
Parameters
sceneany(optional) — The scene walk to read against. Omitted, the call takes its own.
Returns { [string]: any } — { count, receivers }.
local l = streaming.levels()
typed/builtin//modules/api/engine/streaming/streaming/observe
streaming.observe() -> { [string]: any }
The whole reading in one document: terrain, voxel, streaming cells and mesh LOD, plus the totals those rows sum to.
Built by this call and published as its last act, so
/zero/runtime/observations/streaming serves the same document rather
than a second derivation of it.
Returns { [string]: any } — { terrain, voxel, cells, levels, totals }.
local r = streaming.observe()
typed/builtin//modules/api/engine/streaming/streaming/reasons
streaming.reasons() -> { string }
Every reason whyNotDrawn can answer with, so a caller can enumerate
the set rather than meeting it one failure at a time.
Returns { string } — Sorted array of reason names.
local r = streaming.reasons()
typed/builtin//modules/api/engine/streaming/streaming/terrain
streaming.terrain(scene: any?) -> { [string]: any }
What each terrain entity is drawing: whether a heightfield is bound to it, the LOD cut it settled on, what that cut costs in indices and in the vertex pool, and the eye the cut was refined under: the camera in the entity's own coordinates, where its ground's vertices stand.
Parameters
sceneany(optional) — The scene walk to read against. Omitted, the call takes its own, which is what makes a whole reading one walk rather than four.
Returns { [string]: any } — { count, entities } — one row per entity carrying a Terrain.
local t = streaming.terrain()
typed/builtin//modules/api/engine/streaming/streaming/voxel
streaming.voxel(scene: any?) -> { [string]: any }
What became of every chunk of every voxel world: how many are meshed, queued, failed or empty, and one row per chunk carrying the state, the engine's reason when a build failed, and what the build reserved on the device.
Parameters
sceneany(optional) — The scene walk to read against. Omitted, the call takes its own.
Returns { [string]: any } — { count, worlds } — one entry per entity carrying a VoxelWorld.
local v = streaming.voxel()
typed/builtin//modules/api/engine/streaming/streaming/whyNotDrawn
streaming.whyNotDrawn(subject: any?) -> { [string]: any }
Why a piece of a world's detail is not on screen, as one reason from
the closed set streaming.reasons() enumerates, with a detail line naming
what that reason is about.
The subject picks which system answers:
- an entity ref, id or name — whichever of the four systems holds it
{ entity = ..., chunk = "cx_cy_cz" }— one chunk of a voxel world{ entity = ..., level = n }— one level of a mesh-LOD chain{ cell = "x_z" }— one cell of the spatial-streaming store
Parameters
subjectany(optional) — The entity, chunk, level or cell to answer about.
Returns { [string]: any } — { kind, reason, detail }.
local w = streaming.whyNotDrawn({ entity = "Vox", chunk = "0_0_0" })
typed/builtin//modules/api/engine/stringx/stringx/decodeJson
stringx.decodeJson(s: string) -> (boolean, any)
Decode a JSON document in one call, when the document is one the
engine's Luau JSON decoder reads the same way. ok is true and value
holds the decoded value (nil for a document that is null); ok is false
for text this leaves to that decoder: malformed text, nesting past 96
levels, escapes or control bytes the two could read differently, and text
after the value. modules.json calls this first and falls back to its own
scanners on false.
Parameters
sstring— The JSON text.
Returns (boolean, any) — Whether the text was decoded here, and the value.
local ok, value = stringx.decodeJson('{"a":[1,2,3]}')
typed/builtin//modules/api/engine/stringx/stringx/encodeJson
stringx.encodeJson(value: any?) -> (boolean, string?)
Encode a value as compact JSON in one call, when the value is one the
engine's Luau JSON encoder writes the same way. ok is true and text
holds the JSON; ok is false for a value this leaves to that encoder: a
table with a metatable, a table that contains itself, a number key that is
not finite, and nesting past 192 levels. modules.json calls this first
and falls back to its own walk on false.
Parameters
valueany(optional) — The value to encode.
Returns (boolean, string?) — Whether the value was encoded here, and the text.
local ok, text = stringx.encodeJson({ a = { 1, 2, 3 } })
typed/builtin//modules/api/engine/stringx/stringx/scanNumbers
stringx.scanNumbers(s: string, pos: number?) -> ({ number }, number)
Read the run of numbers starting at pos — separated by commas and/or
whitespace — and report where the run ended.
The run stops at the first character that neither continues a number nor
separates two of them (], }, a quote, a letter), and nextPos is that
character's index, so the caller's own parser resumes exactly there. A
token that is not a valid number also ends the run, with nextPos left ON
it rather than past it, so nothing is skipped without the caller seeing it.
Parameters
sstring— The text to read.posnumber(optional) — 1-based index to start at. Defaults to 1.
Returns ({ number }, number) — The numbers found, and the 1-based position just past them.
-- A JSON array of numbers, in one crossing instead of one per token.
local values, nextPos = stringx.scanNumbers(payload, afterBracket)
-- A whitespace-separated block (OBJ, PLY, a matrix dump).
local m = stringx.scanNumbers("1 0 0 0 0 1 0 0", 1)
typed/builtin//modules/api/engine/subscriptions/subscriptions/cancel
subscriptions.cancel(id: string) -> boolean
Cancel a subscription by id: disconnects the live connection immediately and marks the row cancelled. Returns true when a live subscription was cancelled, false for an unknown or already-disconnected id.
Parameters
idstring— Subscription id to cancel.
Returns boolean — True when a live subscription was disconnected.
subscriptions.cancel(conn.id)
typed/builtin//modules/api/engine/subscriptions/subscriptions/get
subscriptions.get(id: string) -> SubscriptionRow?
One subscription row by id, or nil when the id is unknown (never tracked, or evicted after its publisher was destroyed).
Parameters
idstring— Subscription id (conn.id, or a/zero/runtime/events/subscriptions/entry).
Returns SubscriptionRow? — The subscription row, or nil.
local row = subscriptions.get(conn.id); print(row and row.deliveries)
typed/builtin//modules/api/engine/subscriptions/subscriptions/list
subscriptions.list(filter: SubscriptionFilter?) -> { SubscriptionRow }
Every tracked subscription row, optionally filtered by publisher instance id, publisher entity id, event name, and/or connected state.
Parameters
filterSubscriptionFilter(optional) — Optional filter table.
Returns { SubscriptionRow } — Array of subscription rows.
for _, s in ipairs(subscriptions.list({ connected = true })) do print(s.id, s.event, s.deliveries) end
typed/builtin//modules/api/engine/subscriptions/subscriptions/publishers
subscriptions.publishers() -> { PublisherRow }
Every live event publisher: component instance, entity, and per-event fire stats (fires happen whether or not anyone subscribes) plus current subscriber ids.
Returns { PublisherRow } — Array of publisher rows.
for _, p in ipairs(subscriptions.publishers()) do print(p.component, p.entityName) end
typed/builtin//modules/api/engine/substrate/substrate/bindFrames
substrate.bindFrames(key: string, id: string, slots: { any }) -> (boolean, string?)
Bind the play key to the sequence id through slots, so
showFrame(key, f) places its elements from frame f. slots[s] is
{ kind = "instances", key, transforms, data?, capacity, draw, interval? }
for elements an instanced draw copies from transforms — the scatter
binding key places up to capacity of them there and the draw draw
draws the frame's count — or { kind = "entities", key, binding?, interval? } for elements standing in entities: the scatter binding key,
whose entities scatterTransforms has already set, places them, and the
frame's fields are written across the entity binding binding.
Parameters
keystring— The play's name.idstring— The sequence the play shows.slots{ any }— What each numbered slot places, for this play.
Returns (boolean, string?) — True when the binding was queued, and why it was refused when not.
substrate.bindFrames("spark#1", "spark", { { kind = "instances", key = "spark#1", transforms = "spark#1.xf", capacity = 64, draw = drawId } })
typed/builtin//modules/api/engine/substrate/substrate/bufferSource
substrate.bufferSource(name: string) -> string?
The chunk that created the GPU buffer name holds, as debug.info
names a chunk — a module's identity, a test suite's, an execute body's.
The record is the name's for as long as a buffer holds the name, across a device rebuilt underneath it. A name created again after its buffer went answers for the call that created it again. A buffer the engine made itself, or one made through another surface, has no record.
Parameters
namestring— The name the buffer was created under.
Returns string? — The creating chunk's name, or nil.
if substrate.bufferSource("debug_viz.vtx") then print("made through the substrate") end
typed/builtin//modules/api/engine/substrate/substrate/clearScatterTransforms
substrate.clearScatterTransforms(key: string) -> boolean
Drop the device transform binding under key. Its entities go back to
being placed by whatever writes their Transform. Queued.
Parameters
keystring— The key the binding was made under.
Returns boolean — True when the drop was queued.
substrate.clearScatterTransforms("wave")
typed/builtin//modules/api/engine/substrate/substrate/compactions
substrate.compactions() -> number
How many times a page group has moved runs into a page made for them: a group whose runs stood still for a few frames, with more room in its pages than an eighth of what its runs hold, repacks the runs of its emptiest pages.
A run keeps its name when it moves, and substrate.placement(name) answers the page and offset it stands at
now. Work that recorded where runs stood (a dispatch that bound a page whole and addressed runs by offset) reads
this before it runs: when the count moved, the runs it recorded may stand elsewhere.
Returns number — The count since the engine started; 0 where the engine thread's state is not reachable (a worker thread).
local seen = substrate.compactions()
typed/builtin//modules/api/engine/substrate/substrate/createBuffer
substrate.createBuffer(opts: BufferOpts) -> TypedBuffer?
Allocate a typed buffer and return its handle.
A "gpu" buffer is storage a compute shader binds; usage adds
"vertex", "index", "indirect" or "readback" on top of the storage
it always has. A "cpu" buffer is storage the engine holds outside the
Luau heap, and reads back as a flat array of floats. Reading its bytes into
Luau (:bytes(), :read():resultBytes()) makes a copy in the Luau heap.
The handle's write answers whether the words landed: a payload whose end
falls past the end of the buffer is refused whole on both kinds, so the
buffer keeps what it held and the call answers false. writeU32 and
writeBytes answer the same way, against the same extent.
A "cpu" buffer holds at most 1 GiB of storage: 268435456 f32 words,
16777216 mat4 records. A len past that raises an error naming the
bytes it needs and the limit, and a len within it whose storage the heap
cannot supply raises an error naming the bytes. Neither allocates
anything.
A "gpu" buffer is held by what made it. One created under a name stays
until substrate.destroyBuffer(name) frees it, and a run created for an
owner stays until substrate.releaseOwner(owner). One created with
neither is held by its handles: it goes once Luau collects the last of them,
so the buffers a script made and can no longer reach (it ended, or raised)
go with it. Its bytes pace the collector the way a Luau value of that size
would.
A "gpu" buffer holds at most what the device creates in one buffer, its
max_buffer_size. A len whose bytes pass it raises an error naming the
records, the bytes they need, that limit and the most records of the type
one buffer holds; nothing is allocated and the name stays free.
class makes a "gpu" buffer a run: it stands in a range of a page the
engine's device arenas share among many runs of the class, rather than in
an allocation of its own, so thousands of short-lived buffers cost a
handful of device allocations. "effect" is for runs made and let go of
as an effect plays, "persistent" for runs held until let go of. A run
binds, writes, reads and frees like any "gpu" buffer under the name its
handle carries, which the engine mints, so a run takes no name; a
compute program declared with ranges = true binds any number of runs of
one page through one bind group. A run carries "readback" usage and no
other: a vertex, index or indirect buffer is one of its own. owner names
whom a run is held for, and substrate.releaseOwner(owner) lets go of
every run created with it at once.
A job on a worker thread makes a run the same way. The handle answers at
once, with the type and length asked for and a name the worker mints;
substrate.listBuffers lists the run at once; and the engine thread
places it in its arenas ahead of every write, dispatch and read the job
makes over it afterwards, so one job can make a run, fill it, dispatch
over it and read it back. A class, usage or len the engine thread
refuses raises at the call in the job too. When the engine thread cannot
place the run, the handle's next method call raises why.
substrate.setOwner and substrate.releaseOwner answer in a job as they
do on the engine thread, counting the job's own changes at once.
Parameters
optsBufferOpts—{ type, len, kind?, usage?, name?, class?, group?, owner? }—typeis"f32","vec3","vec4","quat"or"mat4";kindis"cpu"(the default) or"gpu".nameis the name a dispatch binds a"gpu"buffer by, and the namesubstrate.getBufferandsubstrate.destroyBufferreach it under.class("effect"or"persistent") makes a"gpu"buffer a run;ownernames whom the run is held for.
Returns TypedBuffer? — The buffer handle, or nil when the allocation failed — an unknown type or kind, a zero length, or a name that already holds a GPU buffer of another shape. A name holding a buffer of the SAME type and length hands that buffer back, contents and all; substrate.destroyBuffer frees a name whose buffer is the wrong shape.
local pose = substrate.createBuffer({ type = "mat4", len = boneCount })
local field = substrate.createBuffer({ type = "vec3", len = 4096, kind = "gpu" })
local column = substrate.createBuffer({ type = "f32", len = n, kind = "gpu", class = "effect", owner = "burst:" .. id })
local values = pose:read(0, 16):result()
typed/builtin//modules/api/engine/substrate/substrate/defineFrames
substrate.defineFrames(id: string, frames: { any }) -> (boolean, string?)
Hold a sequence of frames on the engine under id, for plays bound to
it (bindFrames) to show by index (showFrame) with no script running
per frame. frames[f] is { scatters = {...}, fields = {...} }. A
scatter { slot, positions, rotations?, scales?, lanes?, identities?, count } names the buffers the slot's elements are placed from in that
frame and how many elements they hold; lanes[k] is a buffer name or
false. A field { slot, component, field, values } gives the value the
field takes on each of the slot's entities, in binding order. Slots are
numbered from 1. The buffers stay the caller's and must stand for as long
as the sequence is held. Defining id again replaces it.
Parameters
idstring— The sequence's name.frames{ any }— The frames, in order.
Returns (boolean, string?) — True when the sequence was queued, and why it was refused when not.
substrate.defineFrames("spark", { { scatters = { { slot = 1, positions = P:bufferName(), count = 64 } } } })
typed/builtin//modules/api/engine/substrate/substrate/destroyBuffer
substrate.destroyBuffer(name: string) -> boolean
Free the GPU buffer name denotes, whatever else still holds a handle
to it.
The allocation goes and the name is free to be created again at any type
and length; every handle that pointed at it answers :alive() false. This
is what releases a name whose creating handle is gone, so a build that
re-runs at a different size gets its name back.
Parameters
namestring— The name the buffer was created under.
Returns boolean — True when a GPU buffer under that name was freed.
substrate.destroyBuffer("env.town.xf")
typed/builtin//modules/api/engine/substrate/substrate/forgetFrames
substrate.forgetFrames(id: string) -> boolean
Drop the sequence held under id. A play still bound to it shows
nothing further.
Parameters
idstring— The sequence's name.
Returns boolean — True when the drop was queued.
substrate.forgetFrames("spark")
typed/builtin//modules/api/engine/substrate/substrate/getBuffer
substrate.getBuffer(name: string) -> TypedBuffer?
The GPU buffer name denotes, as a handle you now hold.
A name is how a dispatch binds a buffer, so the name is what an owner asks
by once the handle it created with has gone out of scope — a .module
that hot-reloaded, a build that ran in an earlier execute. The handle
carries everything createBuffer's does and releases its reference with
:destroy().
Parameters
namestring— The name the buffer was created under.
Returns TypedBuffer? — The buffer handle, or nil when no GPU buffer holds that name.
local xf = substrate.getBuffer("env.town.xf")
local shape = xf and { xf:type(), xf:length() }
typed/builtin//modules/api/engine/substrate/substrate/gpuReadback
substrate.gpuReadback(key: string?) -> Readback?
Wrap the key an FFI read handed back as the Readback that polls it.
Every GPU→CPU read reaches the caller through this, so a texture's read
and a buffer's read answer with the same thing.
Parameters
keystring(optional) — The key the read returned.
Returns Readback? — The Readback, or nil when the read did not start.
local pending = substrate.gpuReadback(compute.readTexture3D(handle))
typed/builtin//modules/api/engine/substrate/substrate/listBuffers
substrate.listBuffers() -> { NamedBuffer }
Every named GPU buffer the engine holds, in name order.
Each record states id, name, type ("F32", "Vec3", "Vec4",
"Quat", "Mat4"), len in records, refs — how many holders it
has — holder, the owner a run is held for when one was named
(createBuffer's owner), class, the lifetime class of a run
("effect" or "persistent"; absent for a buffer of its own), and
bytes, the device bytes it takes: the range a run stands in, or the
extent of a buffer of its own. This is what states which names are taken,
at what shape, and what an owner holds.
Returns { NamedBuffer } — Array of { id, name, type, len, refs, holder?, class?, bytes }.
for _, b in ipairs(substrate.listBuffers()) do print(b.name, b.type, b.len) end
typed/builtin//modules/api/engine/substrate/substrate/losses
substrate.losses() -> number
How many times a buffer has been freed by name or by owner: destroyBuffer, releaseOwner and the reset to
a baseline. A holder that checked that the buffers it names exist at one count knows they still do while the
count is the same, whatever else it asks.
Returns number — The count, which only grows.
local at = substrate.losses()
typed/builtin//modules/api/engine/substrate/substrate/markBaseline
substrate.markBaseline() -> number
Record which named GPU buffers the engine holds right now, and make that
the point substrate.resetToBaseline returns to.
A caller running work in an engine it shares — a sweep of test suites, a tool driving a session — leaves buffers behind under the names the work chose: a view's geometry built on its first capture, a kernel's storage. This is how such a caller says where its own allocations start.
Returns number — The mark's generation, counting from 1 — what substrate.resetToBaseline takes to restore to this mark.
local mark = substrate.markBaseline() -- then run, then substrate.resetToBaseline(mark)
typed/builtin//modules/api/engine/substrate/substrate/mintName
substrate.mintName(prefix: string) -> string
prefix followed by a number no VM of this engine was handed before. The engine thread and every worker VM
draw from one count, so a name minted in one VM is never one another VM minted: what names a buffer, a run's owner
or anything else found by name when several VMs make them at once.
Parameters
prefixstring— What the name starts with.
Returns string — The prefix and a number of its own.
local name = substrate.mintName("cook.points.")
typed/builtin//modules/api/engine/substrate/substrate/placement
substrate.placement(name: string) -> BufferPlacement?
Where the GPU buffer name names stands on the device.
A run stands in a range of an arena page that many runs share: page is
the buffer a dispatch binds to reach it, offset the byte it starts at in
that buffer (a multiple of 256) and bytes the bytes it holds. A buffer of
its own is its own page at offset 0. A kernel that binds a page once and
addresses every run of it by offset reads this to state each run's base.
rangeBytes is the bytes the range takes in the page, pageBytes the bytes the page holds on the device and
pageLiveBytes the bytes standing under the page's live ranges: a set of runs keeps its pages alive by the share
of pageLiveBytes the set holds.
A job on a worker thread is answered by the engine thread, after it has
placed every run the job created before the call.
Parameters
namestring— The name the buffer binds under (its handle'sname).
Returns BufferPlacement? — { page, offset, bytes, rangeBytes, pageBytes, pageLiveBytes }, or nil when no buffer holds the name.
local at = substrate.placement(column.name)
typed/builtin//modules/api/engine/substrate/substrate/releaseBaseline
substrate.releaseBaseline(generation: number) -> boolean
Drop the mark generation names, and every mark taken after it, once
the caller that took it is done resetting to it. It touches the
marks alone.
Parameters
generationnumber— The mark to drop, assubstrate.markBaselinereturned it.
Returns boolean — True when the mark stood.
substrate.releaseBaseline(mark) -- the run is over
typed/builtin//modules/api/engine/substrate/substrate/releaseOwner
substrate.releaseOwner(owner: string) -> number
Let go of every run created with owner (createBuffer's class and
owner), whatever else still holds a handle to it.
Each run's range goes back to its arena and every handle to it answers
:alive() false. This is what something that makes runs as it plays — an
effect, a cook, a cache — calls when it ends, so everything it made goes
with it at once, runs it handed on to others included.
Parameters
ownerstring— The owner the runs were created with.
Returns number — How many runs were let go of.
substrate.releaseOwner("burst:" .. id)
typed/builtin//modules/api/engine/substrate/substrate/resetToBaseline
substrate.resetToBaseline(generation: number?) -> number
Free every named GPU buffer created since substrate.markBaseline,
leaving the ones it recorded and buffers owned by standing render features
where they are. Restore the renderer baseline first to release nonbaseline features.
A module that created one of these holds its own handle to it. Put that
module's state back alongside this (engine.restoreModuleState) or it
goes on addressing storage this freed.
is touched.
Parameters
generationnumber(optional) — The mark to restore to, assubstrate.markBaselinereturned it; the newest mark when omitted. The marks taken after it go with the reset.
Returns number — How many buffers were freed.
local freed = substrate.resetToBaseline(mark)
typed/builtin//modules/api/engine/substrate/substrate/scatterTransforms
substrate.scatterTransforms(key: string, entityIds: { string }?, positions: string, rotations: string?, scales: string?, lanes: { string? }?, interval: number?, identities: string?) -> boolean
Place entities from the buffers that already hold their transform, on
the device, instead of from a Transform written per entity.
entityIds[i] is placed from row i of every named buffer, so the order
is the buffers' own. Pass nil for entityIds to keep the entities a
binding already has and replace only the buffers — what a re-cook does,
since a field chain mints a fresh run each time while its membership stands
still, and sending the element list again each time would put back the
per-element crossing the binding exists to remove.
Re-binding the same key with a list replaces the previous binding.
Queued: it takes effect on the next frame, and an entity whose renderable
has not landed yet is placed on the frame it does.
Parameters
keystring— Stable identity of the binding.entityIds{ string }(optional) — The entities in buffer order, or nil to rebind the buffers alone.positionsstring— Name of a buffer holding three f32 per element.rotationsstring(optional) — Name of a buffer holding four f32 per element.scalesstring(optional) — Name of a buffer holding three f32 per element.lanes{ string? }(optional) — Per-instance shader data, by lane:lanes[k + 1]names a buffer holding one vec4 per element, written into lanekof each element's block — what its material reads back asinput.shader_data[k]. A lane left out is left to whatever else writes it.intervalnumber(optional) — Seconds between the presents of the domain the buffers hold. Given, every frame draws each element between the last two presents — position, rotation, scale and lanes blended — the way a fixed-rate simulation is drawn between its ticks, so its motion is continuous at any frame rate while the domain presents at its own. An element new to a slot starts where it was presented. Omitted or 0, each present is drawn as it lands.identitiesstring(optional) — Name of a buffer holding one f32 per element naming which element stands in that row at each present — for a domain whose rows are taken by different elements over time, as a particle's slot is when it dies and another is born into it. A row whose identity moved since the last present starts where it was presented rather than blending from the element that held it before. -1 names a row no element stands in. Omitted, each row's element is the entity placed from it.
Returns boolean — True when the binding was queued.
substrate.scatterTransforms("wave", ids, positions:bufferName())
substrate.scatterTransforms("wave", nil, positions:bufferName())
substrate.scatterTransforms("wave", nil, positions:bufferName(), nil, nil, { colors:bufferName() })
substrate.scatterTransforms("sparks", ids, positions:bufferName(), nil, nil, nil, 1 / 30)
substrate.scatterTransforms("sparks", nil, positions:bufferName(), nil, scales:bufferName(), nil, 1 / 30, ids:bufferName())
typed/builtin//modules/api/engine/substrate/substrate/scatterTransformsInto
substrate.scatterTransformsInto(key: string, into: { transforms: string, data: string?, count: number }, positions: string, rotations: string?, scales: string?, lanes: { string? }?, interval: number?, identities: string?) -> boolean
Place elements that stand in no entity from the substrate buffers that
hold their transform, on the device: row i of the columns is composed into
matrix i of into.transforms, and lane k of block i of into.data — the
two buffers an instanced draw (renderer.mesh.drawInstanced with
transformBuffer and instanceDataBuffer) copies into its slots every
frame. It is scatterTransforms for a population: the same columns, the
same blend between presents when interval is given, the same
identities. Binding the same key into the same buffers again replaces
only the columns it reads. Queued: it takes effect on the next frame, ahead
of the instanced copies that frame records.
Parameters
keystring— Stable identity of the binding.into{ transforms: string, data: string?, count: number }—{ transforms, data?, count }: a buffer ofcountcolumn-major mat4, a buffer ofcount64-byte blocks of four vec4 lanes when lanes are bound, and how many elements there are.positionsstring— Name of a buffer holding three f32 per element.rotationsstring(optional) — Name of a buffer holding four f32 per element.scalesstring(optional) — Name of a buffer holding three f32 per element.lanes{ string? }(optional) —lanes[k + 1]names a buffer holding one vec4 per element, written into lanekof each element's block ininto.data.intervalnumber(optional) — Seconds between the domain's presents; given, each element is drawn between the last two presents.identitiesstring(optional) — Name of a buffer holding one f32 per element naming which element stands in that row at each present; -1 names a row no element stands in.
Returns boolean — True when the binding was queued.
substrate.scatterTransformsInto("sparks", { transforms = "sparks.xf", count = 4096 }, P:bufferName())
typed/builtin//modules/api/engine/substrate/substrate/scatterWorlds
substrate.scatterWorlds(key: string) -> any
Read back where the device drew the elements of the transform binding
under key in the last frame drawn — the device's own answer, since the
CPU never learns where an element it places stands. 16 floats per placed
element, column-major world matrices, in the binding's element order,
leaving out elements whose renderable has not landed. A binding drawn
between its presents answers the blended pose that frame drew.
Parameters
keystring— The key the binding was made under.
Returns any — A pending readback: :ready(), then :result() for the floats.
local pending = substrate.scatterWorlds("sparks")
while not pending:ready() do task.wait() end
local x = pending:result()[13]
typed/builtin//modules/api/engine/substrate/substrate/setOwner
substrate.setOwner(name: string, owner: string?) -> boolean
Hold the run name names for owner from now on, in place of the
owner it was created with, or for no one when owner is nil.
substrate.releaseOwner(owner) then lets go of it with the rest of what
owner holds, and releasing the owner it was made for leaves it standing.
What hands a run on to whatever keeps it longer than the one that made it
— a cache several makers read from.
Parameters
namestring— The name the run binds under (its handle'sname).ownerstring(optional) — The owner to hold it for, or nil.
Returns boolean — Whether name names a run (a buffer created with a class).
substrate.setOwner(column.name, "cache#3")
typed/builtin//modules/api/engine/substrate/substrate/showFrame
substrate.showFrame(key: string, frame: number) -> boolean
Show frame frame (from 1) of the sequence the play key is bound
to: each slot is placed from that frame's buffers, each instanced draw
draws that frame's count, and that frame's fields are written. Showing the
frame already shown changes nothing. Queued.
Parameters
keystring— The play's name.framenumber— The frame, from 1.
Returns boolean — True when the frame was queued.
substrate.showFrame("spark#1", 12)
typed/builtin//modules/api/engine/substrate/substrate/unbindFrames
substrate.unbindFrames(key: string) -> boolean
Drop the play key's binding to its sequence. What it placed stays as
the last frame shown left it.
Parameters
keystring— The play's name.
Returns boolean — True when the drop was queued.
substrate.unbindFrames("spark#1")
typed/builtin//modules/api/engine/text/text/alive
text.alive(handle: any?) -> boolean
Whether the text system still holds this handle — true between
text.create and the text.destroy that released it.
Parameters
handleany(optional) — Text handle fromtext.create.
Returns boolean — True while the handle is live.
if not text.alive(h) then h = text.create({ content = "again" }) end
typed/builtin//modules/api/engine/text/text/count
text.count() -> number
How many text objects the text system is holding — the number that
moves when text.create and text.destroy are called.
Returns number — The live text-object count.
local before = text.count()
typed/builtin//modules/api/engine/text/text/create
text.create(options: table) -> any
Create a text handle from an initial content + style table. The handle
owns a runtime GPU texture (see text.textureGuid); pass it to every other
call.
Parameters
optionstable— Table ofcontentplus style fields (fontSize, color, alignment, richText, maxWidth, ...).
Returns any — An opaque text handle, or nil if the text system is unavailable.
local h = text.create({ content = "Hello", fontSize = 48 })
typed/builtin//modules/api/engine/text/text/destroy
text.destroy(handle: any?) -> boolean
Destroy a text handle and release its raster + glyph layout.
Parameters
handleany(optional) — Text handle fromtext.create.
Returns boolean — True when the text system held the handle and released it; false for a handle it did not have.
text.destroy(h)
typed/builtin//modules/api/engine/text/text/face
text.face(handle: any?) -> any
Which font face one handle actually shaped with, and whether that is
the family its style selects. requested is the name the style wrote,
selected is the family that name selects — itself for a family the
shaper's own database carries, and the family a font file declares for a
name registered onto it — resolved is the face that answered, matched
says whether the face is the family the name selected and reason
says why when it is not — one of text.faceReasons(). A style that named
no family reports noFamilyRequested: it got the default because it asked
for nothing, so reason rather than matched is what an alert switches
on. faces lists
every face the shaper used, most glyphs first, so a fallback that covered
part of the string is visible alongside the face that covered the rest.
missing lists the characters no face drew (the missing glyph stood in);
a character an on-demand face covers requests it, and the object is shaped
again once the face is installed (font.onDemand()).
Parameters
handleany(optional) — Text handle fromtext.create.
Returns any — { requested, selected, resolved, postScriptName, matched, reason, faces, glyphCount, missing }, or nil for a handle the text system does not hold.
local r = text.face(h).reason; if r == "familyUnknown" or r == "familyNotSelectable" then print(r) end
typed/builtin//modules/api/engine/text/text/faceReasons
text.faceReasons() -> { string }
Every reason the face readings give for a label or a family not being
in the family a style named, nearest cause first. text.face gives them
for one label; font.reconcile() also gives familyCoveredNoGlyph, which
it can only reach by laying the family out under its own weights and over
several scripts.
Returns { string } — Array of reason strings.
for _, r in ipairs(text.faceReasons()) do print(r) end
typed/builtin//modules/api/engine/text/text/isDirty
text.isDirty(handle: any?) -> boolean
Whether the handle was laid out again since it was last rasterised: its content or style changed, or a font arriving, leaving or changing the names it answers to changed the face it draws with. Rasterise it again when this answers true to show what it now says.
Parameters
handleany(optional) — Text handle fromtext.create.
Returns boolean — True when the layout changed since the last text.rasterize.
if text.isDirty(h) then text.rasterize(h, text.textureGuid(h)) end
typed/builtin//modules/api/engine/text/text/listFonts
text.listFonts() -> { string }
List the font families currently available to the text system.
Returns { string } — Array of font-family name strings.
local fonts = text.listFonts()
typed/builtin//modules/api/engine/text/text/loadFont
text.loadFont(ref: any?) -> any
Load a font from an asset reference so it becomes available to
setStyle's fontFamily.
Parameters
refany(optional) — Font asset reference or path.
Returns any — The loaded font-family name, or nil on failure.
text.loadFont(asset.ref("fonts.inter", "font"))
typed/builtin//modules/api/engine/text/text/measure
text.measure(handle: any?) -> any
Measure the rasterised text in pixels without producing a texture.
Parameters
handleany(optional) — Text handle fromtext.create.
Returns any — Table with width and height in pixels.
local size = text.measure(h)
typed/builtin//modules/api/engine/text/text/observe
text.observe() -> any
Everything the text system is holding right now. count is the live
text objects; objects is one row each, carrying its content, the style
it was laid out with, its measured extent, whether it is dirty, the face
the shaper actually used, the owner entity whose component created it
with whether that entity is still there, and the raster texture its last
rasterisation landed in with the bytes it costs. orphans is the subset
whose owning entity is gone, fonts the families the shaper can resolve,
and raster the glyph-raster bytes with the pool they belong to named.
Built when you ask, so it costs nothing per frame and reads the same in
edit mode as in play.
Returns any — { count, objects, orphans, fonts, dirty, raster }.
local live = text.observe().count
typed/builtin//modules/api/engine/text/text/orphans
text.orphans() -> { any }
The text objects whose owning entity no longer exists — a quad the
engine is still holding for something that has been despawned. Each row is
the same shape text.observe().objects carries.
Returns { any } — Array of text-object rows with a dead owner.
print(#text.orphans() .. " labels outlived their entity")
typed/builtin//modules/api/engine/text/text/rasterMemory
text.rasterMemory() -> any
The glyph-raster bytes, broken out of the runtime GPU texture pool.
bytes is summed off the same map renderer.gpuMemory().textures is
totalled from, so shareOfPool is a share of that number rather than a
second count of the same memory.
Returns any — { pool, bytes, textures, poolBytes, shareOfPool }.
local r = text.rasterMemory(); print(r.bytes .. " of " .. r.poolBytes)
typed/builtin//modules/api/engine/text/text/rasterize
text.rasterize(handle: any?, texture: any?, scale: number?) -> any
Rasterise the handle's current text + style into the given runtime GPU
texture. Bind that texture's guid as a material's base_color_texture to
display the text; re-rasterising the same texture overwrites it in place.
Parameters
handleany(optional) — Text handle fromtext.create.textureany(optional) — Destination GPU texture handle (renderer.texture.create) or its guid string — WHERE the raster lands.scalenumber(optional) — World/pixel scale factor for the raster (default 1.0).
Returns any — Table with width and height (in pixels), or nil if nothing rasterised.
local tex = renderer.texture.create({ width = 256, height = 64 })
local r = text.rasterize(h, tex, 1.0)
typed/builtin//modules/api/engine/text/text/setStyle
text.setStyle(handle: any?, style: table) -> boolean
Replace the handle's style. Fields not present keep their current value.
Parameters
handleany(optional) — Text handle fromtext.create.styletable— Style table (fontSize, color, alignment, outline, ...).
Returns boolean — True when the text system held the handle and took the style; false when it did not.
text.setStyle(h, { fontSize = 64, color = "yellow" })
typed/builtin//modules/api/engine/text/text/setText
text.setText(handle: any?, content: string) -> boolean
Replace the handle's text content.
Parameters
handleany(optional) — Text handle fromtext.create.contentstring— New text string.
Returns boolean — True when the text system held the handle and took the content; false when it did not, which is how a caller learns its handle went away.
if not text.setText(h, "HP: 100") then h = text.create({ content = "HP: 100" }) end
typed/builtin//modules/api/engine/text/text/textureGuid
text.textureGuid(handle: any?) -> string?
The runtime GPU texture guid this handle rasterises into — bind it as a
material texture (base_color_texture) to display the text.
Parameters
handleany(optional) — Text handle fromtext.create.
Returns string? — The texture guid string, or nil for a handle the text system does not hold.
entity(id).component.get("Material"):setTexture("base_color_texture", text.textureGuid(h))
typed/builtin//modules/api/engine/ui/ui/blur
ui.blur()
Surrender keyboard focus from whichever widget currently holds it, in the editor's UI and the game's alike.
typed/builtin//modules/api/engine/ui/ui/bringAreaToFront
ui.bringAreaToFront(id: string)
Raise a movable area to the top of the window stacking order —
the programmatic equivalent of clicking it. Areas sharing a stacking
band order by interaction, so this is the call that brings one forward
from code: use it when a taskbar button, focus change, or app launch
should raise a window. Moving a screen to a higher layer band raises
it over the bands below.
Parameters
idstring— Area widget id.
typed/builtin//modules/api/engine/ui/ui/canvas
ui.canvas(space: ("camera" | "window")?) -> Canvas
The canvas one of the two surfaces a screen lays out on spans (see
ui.setScreenSpace), with everything a layout is computed from, in one
reading: width / height in logical points (ui.screenSize(space)),
aspect (width over height), orientation ("portrait" while taller
than wide, "landscape" otherwise: the canvas's own shape, which in the
editor is the Scene panel's picture rather than the window), pixelRatio
(ui.pixelRatio(space)), safeArea (ui.safeArea(space): the insets,
the rect they leave, the cutouts and the on-screen controls) and
revision.
revision advances every time any of those changes: a window resized, a
phone rotated, a Scene panel dragged to a new size, a preview size set
with renderer.setPictureSize, the system bars or the keyboard shown or
hidden, an on-screen control shown or moved, the window carried to a
display of another density. Compare it with the revision a layout was
computed against to tell whether to compute it again, or subscribe with
ui.onCanvasChange.
"camera" (the default) is the camera's picture, where a HUD or any
camera-space screen lays out; "window" is the window, where the
editor's chrome lays out. A layout stated in anchors, % sizes and flex
follows the canvas on its own; one computed in Luau from these numbers
is computed again when the canvas changes.
Parameters
space("camera" | "window")(optional) —"camera"(default) or"window".
Returns Canvas — { space, width, height, aspect, orientation, pixelRatio, safeArea, revision }.
local c = ui.canvas(); if c.orientation == "portrait" then print("stack the HUD down the side") end
local c = ui.canvas(); ui.setAreaPos("hud", c.safeArea.x + 8, c.safeArea.y + 8)
typed/builtin//modules/api/engine/ui/ui/captureWindow
ui.captureWindow(screen: string, window: string, opts: CaptureOpts?) -> CaptureResult?
Render a single Window widget to its own offscreen texture
and write the result as PNG at
/runtime/render_surfaces/<rtHandle>.png. The screen does NOT
need to be visible. Returns { rtHandle, texturePath } or nil
on invalid inputs (width/height clamped to [1, 8192],
defaults 600x400).
Parameters
screenstring— Screen id containing the target Window.windowstring— Widget id of the Window.optsCaptureOpts(optional) —{ width, height }(optional).
Returns CaptureResult? — { rtHandle, texturePath } or nil.
typed/builtin//modules/api/engine/ui/ui/clearMotion
ui.clearMotion(id: string)
Drop the widget id's motion: it is drawn where layout puts it
again, unscaled and at its own opacity, at once. Unregistering a screen
drops the motions of the widgets drawn on it the same way.
Parameters
idstring— The widget'sid.
typed/builtin//modules/api/engine/ui/ui/click
ui.click(callbackId: string, value: any?) -> boolean
Simulate a widget click / interaction by its callback id. The call
carries no screen, so an id that names widgets on several screens reaches
every component that declared it, once each. The callback id is the one
a widget emits: the string its onClick / onChange / other on* prop
names, or its element id where it leaves that prop unnamed (a button
clicked without an onClick, a slider changed without an onChange).
Given the element id of a widget whose interactions emit other ids, it
raises an error naming those ids, and clicks nothing.
Parameters
callbackIdstring— Callback id the widget emits (itsonClick/onChange/on*prop).valueany(optional) — Optional value the callback receives asdata.value: a number, a string, a boolean, or a table with the fields a structured interaction delivers (a code editor's{ token, line, col }, a canvas drag's deltas).
Returns boolean — true when a widget on a registered screen emits the id and the click reaches a handler: an onCallback of a component instance owning the id (its own top-level one, or one of an env its own code registered with ui.registerCallbackEnv), or the broadcast set for an id no component owns. false otherwise: when no widget emits the id (the click then still reaches every ui.registerCallbackEnv env and every component and scene entrypoint that receives callbacks no screen claims), and when the component instances owning the id hold no onCallback to run, which the dispatch logs as a warning naming those instances.
typed/builtin//modules/api/engine/ui/ui/copyText
ui.copyText(text: string)
Put text on the host clipboard — the operating system's clipboard
on a native build, the browser's in a web build. What a "Copy path" or
"Copy reference" action calls.
Parameters
textstring— The text to copy.
ui.copyText("/zero/source/scenes/main.scene")
typed/builtin//modules/api/engine/ui/ui/defineStyle
ui.defineStyle(name: string, style: StyleProps)
Define a named style. Style keys follow
<widgetType>.<className> (e.g. "label.h1", "button.primary")
or bare <className> to apply across widget types. Widgets
reference styles via the classes (or class) prop.
Parameters
namestring— Style name.styleStyleProps— Style properties table.
typed/builtin//modules/api/engine/ui/ui/defineStyles
ui.defineStyles(styles: { [string]: StyleProps })
Define multiple named styles at once.
Parameters
styles{ [string]: StyleProps }— Map of style name to style properties.
typed/builtin//modules/api/engine/ui/ui/defineWidget
ui.defineWidget(name: string, builderFn: (WidgetTree, { WidgetTree }) -> WidgetTree)
Register a custom widget kind. When a tree contains
{ type = name, props = ..., children = ... }, the decoder
calls builderFn(props, children) at register / update time and
substitutes the returned widget table in place. Errors surface
through ui.lastValidation() with codes widget-builder-error
/ widget-builder-bad-return / decode-recursion-depth-exceeded.
Parameters
namestring— Custom widget kind name.builderFn(WidgetTree, { WidgetTree }) -> WidgetTree— Builder closure(props, children) -> widgetTable.
typed/builtin//modules/api/engine/ui/ui/diagnose
ui.diagnose(widgetId: string) -> WidgetPaint?
Why one widget did or did not reach the last frame. Returns that
widget's row from ui.observe() — the same fields, resolved against the
same reading. An id no registered screen carries reads noSuchWidget,
which is how a misspelling separates from a widget whose screen is
hidden and from one the frame laid out no box for.
Parameters
widgetIdstring— The id the widget records layout under.
Returns WidgetPaint? — The widget's row, or nil before the UI has published a frame.
local row = ui.diagnose("hud-healthbar")
typed/builtin//modules/api/engine/ui/ui/displayScale
ui.displayScale() -> DisplayScale
The physical scale the UI is sized at. density is the physical
pixels one density-independent point covers on a handheld display (a
phone, a tablet, a page in a touch browser): a point of the UI covers at
least that many pixels whatever the screen's width or orientation, so
text and buttons keep their physical size. It is nil on a desktop
window, whose UI is sized by its width alone. textScale is the user's
text size setting, which multiplies every font size the UI typesets
(labels, buttons, inputs, editor chrome; canvas text is drawn at the
size it names). touchTarget is the smallest target, in points, a touch
reaches an interactive widget within: 48 on a handheld display, 0 on a
desktop. pixelRatio is ui.pixelRatio() of the same frame.
ui.simulateDisplayScale previews a phone's on any engine.
Returns DisplayScale — { density?, textScale, touchTarget, pixelRatio }.
local scale = ui.displayScale()
local buttonHeight = math.max(32, scale.touchTarget)
typed/builtin//modules/api/engine/ui/ui/dragState
ui.dragState() -> { payload: string, x: number, y: number, label: string?, ghost: boolean }?
The in-flight drag-and-drop payload while a dragPayload widget is
being dragged, else nil. x/y are the pointer's position in the
logical space ui.getLayoutInfo rects live in, so the reading resolves
directly against widget rects. label is the text the drag ghost beside
the pointer reads (dragLabel, else the source's text; nil for an
outline ghost), and ghost whether the engine draws one (dragGhost) —
a capture never shows the ghost, so this is how a drag's name-at-cursor
is checked. Poll during a drag to drive live feedback; the drop itself
still lands through the target's onDrop. Snapshotted each frame.
Returns { payload: string, x: number, y: number, label: string?, ghost: boolean }? — { payload, x, y, label?, ghost } during a drag, nil otherwise.
typed/builtin//modules/api/engine/ui/ui/elementTree
ui.elementTree(screenName: string) -> ElementNode?
Introspect a screen's rendered widget hierarchy with each
element's layout rect. Every node the renderer draws appears, nested
exactly as the widgets nest, under the id it records layout against:
the id set on the node when the author gave it one, otherwise
<screen>/<type>@<path>. bounds is that element's rect — the same
table ui.getLayoutInfo(id) returns — and appears once the element has
been measured. Kinds registered through ui.defineWidget appear
expanded into the primitives they build. Feeds the gui.captureElement
tool: list the tree, pick the ids to frame, capture their region.
Parameters
screenNamestring— Screen id passed toui.registerScreen.
Returns ElementNode? — An ElementNode tree, or nil when no screen is registered under that name.
typed/builtin//modules/api/engine/ui/ui/fling
ui.fling(id: string, velocity: MotionValues, options: FlingOptions?)
Throw the widget id with velocity ({ x, y }, points per
second): it coasts from where it is and slows until it rests, stepped by
the engine each frame. A widget carrying onDrag = "<callback id>" calls
its screen's onCallback every frame of a press-drag with
data.value = { dx, dy, vx, vy, dragStarted, dragStopped, shift, ctrl, alt }: dx, dy the frame's movement, vx, vy the pointer's speed,
which on the frame dragStopped is true is the release velocity to fling
with. Move the widget under the finger meanwhile with ui.setMotion.
Options: decay (seconds for the speed to fall to about a third,
default 0.35; it travels about velocity * decay), bounds
({ minX, maxX, minY, maxY }: offsets it stays inside; reaching one, or
starting beyond it, it springs onto it), stiffness, damping, mass
(that spring, default 300, 1, 1) and onSettle (as ui.spring). Under
reduced motion it moves at once to where the throw would have brought it
to rest, inside its bounds.
Parameters
idstring— The widget'sid.velocityMotionValues—{ x?, y? }in points per second.optionsFlingOptions(optional) —{ decay?, bounds?, stiffness?, damping?, mass?, onSettle? }.
ui.fling("card", { x = 900, y = 0 }, { bounds = { minX = -200, maxX = 200 } })
typed/builtin//modules/api/engine/ui/ui/focus
ui.focus(widgetId: string)
Programmatically request keyboard focus on a widget. Queued
as a one-shot; the next render of the matching widget calls
response.request_focus(). A field, a button and any keyed widget
carrying onClick hold it, and Enter or Space on a focused clickable
widget clicks it.
Parameters
widgetIdstring— Widget id to focus.
typed/builtin//modules/api/engine/ui/ui/focusedTextField
ui.focusedTextField() -> FocusedTextField?
The text field that holds the keys: the field the person last put
the caret in, in the window (place "window"), in the game view's
picture ("camera"), or on a panel standing in a headset's world
("panel", with panel its xr.panels id). widget is the id the
field records layout under when its screen gave it one; kind is
"text", "password", "code" or "number" (an input with a
number prop), and for a number number ("whole" or "decimal") and
signed say which numbers it takes; multiline says whether Enter starts
a new line (in a single-line field Enter submits); text and caret
(in characters) are what it holds; bounds is the field's box as shares
of the picture it is drawn in, 0 at the top left and 1 at the bottom
right. Nil while no field holds the keys. Snapshotted each frame.
ui.typeText and ui.typeKey type into this field.
Returns FocusedTextField? — The field, or nil.
local field = ui.focusedTextField()
typed/builtin//modules/api/engine/ui/ui/focusedWidget
ui.focusedWidget() -> (string?, string?)
Return the widget id of whichever widget currently holds
keyboard focus, or nil, and the space it draws in: "window" for the
editor's UI around the game view, "camera" for the game's own UI in
the game view. Snapshotted post-render each frame.
Returns (string?, string?) — Focused widget id or nil, and its space.
local id, space = ui.focusedWidget()
typed/builtin//modules/api/engine/ui/ui/fromViewport
ui.fromViewport(x: number, y: number, space: ("camera" | "window")?) -> { x: number, y: number }
Carry a point from the scene viewport's physical pixels into the UI's
logical points. The scene viewport's pixels are what
input.snapshot().mouse_position, a touch, every input.events()
position, worldToScreen and capture answer in, measured from the
top-left of the rect the scene is drawn into.
space names the surface the answer is on (see ui.setScreenSpace):
"camera" (the default) is the canvas a camera-space screen (a HUD, a
game menu) states its pos and anchors on, so a widget placed at the
answer sits over the point; "window" is the window, the space
ui.getLayoutInfo, gui.bounds, ui.hitTest and ui.pointerWidget use, so
the answer can be tested against a widget's recorded rect. The two
differ while a Scene panel presents the scene inside the window.
Parameters
xnumber— X in the scene viewport's physical pixels.ynumber— Y in the scene viewport's physical pixels.space("camera" | "window")(optional) —"camera"(default) or"window".
Returns { x: number, y: number } — { x, y } in that surface's logical points.
local m = input.snapshot().mouse_position; local p = ui.fromViewport(m[1], m[2], "window"); local over = ui.hitTest(p.x, p.y)
local s = worldToScreen(0, 2, 0); local at = ui.fromViewport(s.x, s.y); ui.updateScreen("nameTag", { type = "area", id = "nameTag", pos = { at.x, at.y }, children = { { type = "label", props = { text = "NPC" } } } })
typed/builtin//modules/api/engine/ui/ui/getAreaPos
ui.getAreaPos(id: string) -> AreaPos?
Read the current pivot position of an area widget,
including any user drag deltas. Returns { x, y } or nil if
the area didn't render this frame.
Parameters
idstring— Area widget id.
Returns AreaPos? — { x, y } or nil.
typed/builtin//modules/api/engine/ui/ui/getAreaSize
ui.getAreaSize(id: string) -> AreaSize?
Read the measured size of an area widget, including any user
resize-grip drags if the area is resizable. Returns { w, h }
or nil if the area didn't render this frame.
Parameters
idstring— Area widget id.
Returns AreaSize? — { w, h } or nil.
typed/builtin//modules/api/engine/ui/ui/getDockLayout
ui.getDockLayout(id: string) -> string?
Read the current serialized layout (split/tab arrangement) of
a dockArea widget as a JSON string. Returns nil if the dockArea
didn't render this frame. Persist the string and pass it back via
the dockArea's layout prop to restore the arrangement.
Parameters
idstring— DockArea widget id.
Returns string? — Serialized DockState JSON string, or nil.
typed/builtin//modules/api/engine/ui/ui/getLayoutInfo
ui.getLayoutInfo(widgetId: string?) -> LayoutInfo?
Get layout info (position, size, content bounds) for UI
containers: the box each is drawn in, which is where layout put it
moved through any CSS transform it is drawn under (the upright box
a rotated one covers). If widgetId is given, returns info for that
widget only; otherwise returns all.
Parameters
widgetIdstring(optional) — Optional widget id to query.
Returns LayoutInfo? — Layout info table or nil.
typed/builtin//modules/api/engine/ui/ui/getPersistentDockLayout
ui.getPersistentDockLayout(id: string) -> string?
Read a dockArea's arrangement as a JSON string with every tab
whose dockPanel is transient left out — the form to save and
restore across sessions. Returns nil if the dockArea didn't render
this frame.
Parameters
idstring— DockArea widget id.
Returns string? — Serialized DockState JSON string without transient tabs, or nil.
typed/builtin//modules/api/engine/ui/ui/getScreenTree
ui.getScreenTree(screenName: string) -> WidgetTree?
Return the last widget tree table passed to
registerScreen / updateScreen for screenName.
Parameters
screenNamestring— Screen name to query.
Returns WidgetTree? — Widget tree or nil.
typed/builtin//modules/api/engine/ui/ui/getTheme
ui.getTheme() -> string
Get the name of the currently active theme.
Returns string — Active theme name.
typed/builtin//modules/api/engine/ui/ui/getToken
ui.getToken(name: string) -> string?
Look up a single design token value from the active theme.
Parameters
namestring— Token name (without$prefix).
Returns string? — Token value or nil.
typed/builtin//modules/api/engine/ui/ui/getTokens
ui.getTokens() -> { [string]: string }
Get all design tokens from the active theme as a key-value map.
Returns { [string]: string } — Token map.
typed/builtin//modules/api/engine/ui/ui/getWidgetProps
ui.getWidgetProps(typeName: string) -> { WidgetPropDescriptor }?
Get the property definitions for a widget type: its own props,
then the ones every widget takes (onClick, dragPayload, onDrop,
tooltip, ...) marked common = true, then the style keys the type
reads for its own box (pointerEvents) marked style = true, which are
set in the widget's style.
Parameters
typeNamestring— Widget type name.
Returns { WidgetPropDescriptor }? — Array of property descriptors, or nil if type not found.
typed/builtin//modules/api/engine/ui/ui/getWidgetTypes
ui.getWidgetTypes() -> { string }
Get all available widget type names that can be used in widget trees.
Returns { string } — Array of widget type names.
typed/builtin//modules/api/engine/ui/ui/hideScreen
ui.hideScreen(name: string) -> boolean
Hide a registered screen, and report whether a screen by that name
is registered. The engine applies the hide later in the frame;
listScreens reflects it from the next call onwards.
Parameters
namestring— Screen identifier to hide.
Returns boolean — True when a screen by this name is registered.
typed/builtin//modules/api/engine/ui/ui/hitTest
ui.hitTest(x: number, y: number) -> PaintHitTest?
Which widget a pointer at (x, y) reaches, and the stack beneath it.
Coordinates are logical points on the window, the space getLayoutInfo
and gui.bounds rects are in wherever a widget's screen draws (a screen
in the Scene view's picture included). A widget that takes no
pointer is passed over, and the answer is the widget beneath it: one
declaring pointerEvents = "none", and a container that only lays out
its children, filling nothing and answering no pointer. stack lists
the widgets that take the pointer at the point, topmost first, with each
container holding one of them after the widgets it holds.
Parameters
xnumber— Logical X.ynumber— Logical Y.
Returns PaintHitTest? — { widget, screen, stack, x, y } — widget nil when the point is over no UI — or nil before the UI has published a frame.
local hit = ui.hitTest(640, 360)
typed/builtin//modules/api/engine/ui/ui/hitTestRegions
ui.hitTestRegions(regions: { PressRegion }, opts: HitTestRegionsOpts?) -> { RegionHit }?
Which widget answers a press inside each of regions: the region
counterpart of ui.hitTest, for a caller that draws something over the
UI and needs to know whether a press anywhere on it would do something
in the UI beneath. Each region is a rect { x, y, width, height } or a
disc { x, y, radius }, in logical points on the window (the space
ui.hitTest and ui.getLayoutInfo use). The answer holds one
{ widget, screen, takesHold } per region, in the order given. Of the widgets the
last frame drew that take the pointer and whose visible box meets the
region, a press there reaches those of the highest stacking band; of
those, the answer names the smallest that answers a press (a click or a
drag: a button, a slider, a text field, a scroll area, a box with
onClick), the latest paint breaking a tie, so a label inside a button
answers through the button. takesHold is true when holding or
dragging that press does something on the widget: a slider, a text
field, a scroll area, a widget with onDrag, onPointerDown,
onPointerUp, onContextMenu or dragPayload, or one stating
holdsPointer or keepsTouchDrag. widget is nil where nothing takes the
pointer there, and where what the press reaches answers none of it (a
label, a filled box, a full-screen tint). opts.space ("camera" or "window") counts only the screens drawn on
that surface, and opts.except leaves out the screens it names.
Parameters
regions{ PressRegion }— The regions, in logical points on the window.optsHitTestRegionsOpts(optional) —{ space?, except? }. Optional.
Returns { RegionHit }? — One { widget, screen, takesHold } per region, or nil before the UI has published a frame.
local hits = ui.hitTestRegions({ { x = 1200, y = 640, radius = 56 } }, { space = "camera" })
typed/builtin//modules/api/engine/ui/ui/idCollisions
ui.idCollisions() -> { [string]: { string } }
Element ids more than one screen recorded, each mapped to the
screens that recorded it. An id addresses one element: two screens
sharing one leave ui.getLayoutInfo and the gui element tools
answering for whichever painted last, and the gui tools refuse such
an id. Empty while every id is unique.
Returns { [string]: { string } } — Colliding id -> the screens that recorded it.
for id, screens in ui.idCollisions() do print(id, table.concat(screens, ", ")) end
typed/builtin//modules/api/engine/ui/ui/invisibilityReasons
ui.invisibilityReasons() -> { string }
Every verdict ui.diagnose can report, as a closed list.
Returns { string } — The reason names.
typed/builtin//modules/api/engine/ui/ui/lastRegistration
ui.lastRegistration() -> { name: string, layer: number? }?
The name and layer passed to the most recent ui.registerScreen
call, recorded synchronously at call time. A host that mounts a nested
app reads this immediately after the mount to learn which screen the
nested code registered, without intercepting the ui table.
Returns { name: string, layer: number? }? — { name, layer } for the last registration, or nil if none yet.
typed/builtin//modules/api/engine/ui/ui/lastValidation
ui.lastValidation(screenName: string?) -> any
Validation diagnostics produced at the most recent
registerScreen / updateScreen, plus what the render stage
found while painting — unknown-font-family reports a
style.fontFamily that named no registered font family, once
per family per screen, wrap-label-no-width reports a
label with props.wrap whose box came out narrower than its
own longest word, once per label per screen, and
svg-not-as-declared reports an svg widget whose document
declared something the picture does not hold — a <text>
whose font-family selected no registered family, a <text>
the picture holds no glyph of, or a shape whose url(#id)
paint resolved to nothing — once per finding per widget per
screen, and layout-unsettled reports a screen whose layout was
still changing when a frame ran out of layout passes, so that
frame painted it before it settled; widgetId names a tree
still moving, and the finding is withdrawn once a frame paints
the screen settled. With no args
returns a
{ [screen] = entry } map; with a name returns that screen's
entry or nil. Validation gated by world setting
ui.validation = "off" | "warn" | "strict" (default "warn").
Parameters
screenNamestring(optional) — Optional screen name.
Returns any — Validation entry, full map, or nil.
typed/builtin//modules/api/engine/ui/ui/listFonts
ui.listFonts() -> { FontFamilyInfo }
Every font family a style.fontFamily can select. Read from
the registry the UI text renderer resolves a family token
through, so a family this returns is one a label renders in.
family and every name in aliases are accepted as a
fontFamily, case-insensitively; aliases carries the
web-font names, CSS generic families and face names that
select the same group. faces names the concrete face in each
weight/style slot, so a fontWeight = 700 against a family
with no bold face gets a synthesised heavy. more lists the
other faces registered in the family's slots, each drawing the
codepoints the slot's face lacks: the installed chunks of an
on-demand face (font.onDemand() lists them all). system = true
marks a family taken from the host OS — present on this
machine, absent on one without it, and absent on WASM — so a
UI that must look the same everywhere picks a family with
system = false. A fontFamily naming nothing in this list
is reported as an unknown-font-family warning through
ui.lastValidation(screen) once the screen paints, and the
text renders in the default proportional face.
Returns { FontFamilyInfo } — Array of { family, aliases, faces, more, system }, by family.
for _, f in ui.listFonts() do print(f.family) end
typed/builtin//modules/api/engine/ui/ui/listScreens
ui.listScreens() -> { ScreenSummary }
List every registered screen with its current visibility,
z-order layer, renderLayer (the render-layer membership mask it
draws under: the mask setScreenRenderLayer stated, else the one the
surface setScreenSpace named implies, else the ui bit),
editorChrome (whether the mask setScreenRenderLayer stated carries
the EditorUI bit, which makes the screen the editor's own chrome; a
screen placed on the window without stating it is not chrome), whether
the screen has a populated root widget tree, and the space it draws in
("window" for the editor's UI, "camera" for the game's),
including the register / show / hide / unregister calls the running
script has already made. Sorted by layer ascending, then name.
Returns { ScreenSummary } — Array of screen summaries.
typed/builtin//modules/api/engine/ui/ui/listThemes
ui.listThemes() -> { string }
List all registered theme names.
Returns { string } — Array of theme names.
typed/builtin//modules/api/engine/ui/ui/lockOrientation
ui.lockOrientation(lock: OrientationLock)
Hold the display to the orientations lock allows: "landscape"
(both landscape directions, so turning the device over turns the app
with it), "portrait" (both portrait directions) or "any" (the display
follows the device). A world states the orientation it plays in as
world.orientation, which the engine locks to in play mode and releases
in edit mode, so the editor follows the device; call this to change it
while the world runs. Android turns the app at once, a browser grants the
lock only to a page in fullscreen in most cases (the page asks again each
time it enters fullscreen), and a desktop window presents in the shape it
is given. ui.orientation() reports the lock and whether the platform
holds it from the next frame. Any other value is refused by name.
Parameters
lockOrientationLock—"any","landscape"or"portrait".
ui.lockOrientation("portrait")
ui.lockOrientation("any")
typed/builtin//modules/api/engine/ui/ui/matchMedia
ui.matchMedia(query: string) -> boolean
Whether the CSS media query query matches now, as a browser's
matchMedia(query).matches answers. The query takes
(prefers-reduced-motion: reduce), (prefers-reduced-motion: no-preference)
and the bare (prefers-reduced-motion), joined by and, negated by a
leading not, listed as alternatives with ,, with an optional media
type (all and screen match, print does not); a leading @media is
read past. The same text keys a style's @media block. A query the
engine cannot evaluate is refused, naming what it takes.
Parameters
querystring— A CSS media query.
Returns boolean — Whether it matches.
local calm = ui.matchMedia("(prefers-reduced-motion: reduce)")
typed/builtin//modules/api/engine/ui/ui/maxFileBytes
ui.maxFileBytes() -> number
The most bytes one file may bring into the UI through onFileDrop or
onFilePaste. A file past it reaches the handler with
error = "tooLarge" and no bytes.
Returns number — The limit, in bytes.
typed/builtin//modules/api/engine/ui/ui/missingGlyphs
ui.missingGlyphs() -> { string }
The characters the UI is showing without a glyph: each appears in
text a UI surface (the window, the game view, a camera's UI overlay, a
screen drawn into a texture) drew in what it last painted, and no face of
the family it was drawn in has a glyph for it, so it shows as the
replacement box.
Every family falls back glyph by glyph to every face the UI holds, so a
character here is one no installed face covers. A character a declared
on-demand face covers (font.onDemand()) requests that face the frame
it is met, and leaves this list once the face is installed and the next
frame draws it.
Returns { string } — Sorted array of single-character strings; empty when every character drawn had a glyph.
if #ui.missingGlyphs() > 0 then print(table.concat(ui.missingGlyphs(), " ")) end
typed/builtin//modules/api/engine/ui/ui/motion
ui.motion(id: string) -> MotionReading
Where the widget id's motion stands, as the last frame left it:
each channel's value, velocity and target (where it comes to rest),
and whether it is moving. A widget with no motion (never moved, or
back at rest where layout puts it) reads at its layout place: x 0, y 0,
scale 1, opacity 1, not moving. A motion started this frame reads from
the next.
Parameters
idstring— The widget'sid.
Returns MotionReading — { x, y, scale, opacity, velocity, target, moving }.
local m = ui.motion("menu"); if not m.moving then print("rests at", m.y) end
typed/builtin//modules/api/engine/ui/ui/observe
ui.observe(screenName: string?) -> PaintObservation?
What the last UI frame painted. Returns
{ generation, viewport, pointer, pointerOverUi, pointerWidget, widgets }
with one widgets row per widget any registered screen holds — its
layout box, the clip chain it painted under, the part of that box which
reached the frame (visible), the order it painted in (paintIndex),
and its reason from the closed set ui.invisibilityReasons() lists.
Every rect, the reading's viewport (the window) and pointer are in
logical points on the window; a row's viewport is the region the pass
that drew it paints into (the whole window, or the rect a Scene panel
presents the camera's picture in), and offViewport is judged against it.
generation advances once per re-rendered frame, so two calls reporting
the same number describe the same frame.
Parameters
screenNamestring(optional) — Narrow the rows to one screen. Omit for every screen.
Returns PaintObservation? — The reading; nil before the UI has published a frame, and nil for a screenName no registered screen answers to.
local reading = ui.observe("hud")
typed/builtin//modules/api/engine/ui/ui/onCanvasChange
ui.onCanvasChange(callback: (canvas: Canvas, previous: Canvas) -> (), space: ("camera" | "window")?) -> () -> ()
Call callback once for every change of the canvas a screen lays
out on, with the new reading and the one before it, as ui.canvas(space)
returns them: the canvas resized (a window resized, a Scene panel
dragged, a preview size set), turned between portrait and landscape,
carried to another pixel ratio, or its safe area or on-screen controls
changed. It is how a screen whose layout is computed in Luau from the
canvas (a HUD that rearranges between portrait and landscape, boxes
placed by pos, a grid sized to the width) lays itself out again: lay
it out once from ui.canvas(), then again in the callback.
The callback runs on the frame after the change, once however many of the canvas's values changed together, and never for a frame that changed none. It runs in every mode (edit mode, paused play, a time scale of 0), so a screen follows the canvas wherever it is shown. A listener a component registered ends when that component is removed or reloaded, and every other listener goes on hearing changes until the function it returns is called.
Parameters
callback(canvas: Canvas, previous: Canvas) -> ()— Receives(canvas, previous): the new reading and the one it replaces.space("camera" | "window")(optional) —"camera"(default) or"window".
Returns () -> () — A function that removes this listener.
local function layout(c) ui.updateScreen("hud", buildHud(c.width, c.height, c.orientation)) end; layout(ui.canvas()); local off = ui.onCanvasChange(layout)
local off = ui.onCanvasChange(function(c, was) print(was.width .. "x" .. was.height .. " -> " .. c.width .. "x" .. c.height) end)
typed/builtin//modules/api/engine/ui/ui/onOrientationChange
ui.onOrientationChange(callback: (reading: OrientationReading) -> ()) -> () -> ()
Call callback with the new reading every time ui.orientation()
changes: the display turns between landscape and portrait or to another
rotation, the lock changes, or the platform starts or stops holding it.
It is called in every mode (edit mode, paused play, a time scale of 0),
on the frame after the change. A listener a component registered ends
when that component is removed or reloaded, and every other listener
goes on hearing changes until the function it returns is called.
Parameters
callback(reading: OrientationReading) -> ()— Receives the reading, asui.orientation()returns it.
Returns () -> () — A function that removes this listener.
local off = ui.onOrientationChange(function(o) print(o.current, o.rotation) end)
typed/builtin//modules/api/engine/ui/ui/onReducedMotionChange
ui.onReducedMotionChange(callback: (reading: ReducedMotion) -> ()) -> () -> ()
Call callback with the new reading every time ui.reducedMotion()
changes: the person changes the OS setting while the engine runs, or an
in-app preference is stated or withdrawn. It is called in every mode
(edit mode, paused play, a time scale of 0), on the frame after the
change. A listener a component registered ends when that component is
removed or reloaded.
Parameters
callback(reading: ReducedMotion) -> ()— Receives the reading, asui.reducedMotion()returns it.
Returns () -> () — A function that removes this listener.
local off = ui.onReducedMotionChange(function(m) print("reduce motion:", m.reduce) end)
typed/builtin//modules/api/engine/ui/ui/orientation
ui.orientation() -> OrientationReading
The orientation the display presents the app in, and the lock it is
held to. current is "landscape" (wider than tall) or "portrait":
the shape of the window the app presents in. lock is what
ui.lockOrientation last asked, "any" when the display follows the
device. enforced is whether the platform holds the display to it:
Android always does, a browser does once it grants the Screen
Orientation lock, and a desktop window never does, presenting in the
shape it is given; reason names why when it does not. rotation is the
display's rotation from its natural orientation in degrees (0, 90, 180,
270) where the platform states one, and nil on a desktop window.
revision advances every time any of these changes; ui.onOrientationChange
calls back on each change.
Returns OrientationReading — { current, lock, enforced, reason?, rotation?, revision }.
if ui.orientation().current == "portrait" then print("lay the HUD out for a tall screen") end
typed/builtin//modules/api/engine/ui/ui/paintGeneration
ui.paintGeneration() -> number
The generation of the last frame's paint reading (ui.observe()),
read without building the reading. It advances once per re-rendered
frame and stands still otherwise, so something derived from the reading
(a ui.hitTest, a ui.hitTestRegions answer) still holds while this
reads the number it was derived at.
Returns number — The generation, 0 before the UI has published a frame.
local gen = ui.paintGeneration()
typed/builtin//modules/api/engine/ui/ui/paintOrder
ui.paintOrder(a: string, b: string) -> number?
Which of two widgets paints later: -1 when a paints before b,
1 when after, 0 when level. This is what separates two widgets whose
rects are identical.
Parameters
astring— First widget id.bstring— Second widget id.
Returns number? — -1, 0, 1, or nil when the reading holds no row for one of them.
local order = ui.paintOrder("panel-a", "panel-b")
typed/builtin//modules/api/engine/ui/ui/pixelRatio
ui.pixelRatio(space: ("window" | "camera")?) -> number
Physical pixels per logical point of one of the two surfaces a
screen lays out on (see ui.setScreenSpace).
"window" (the default) is the window. ui.getLayoutInfo and
gui.bounds rects, ui.hitTest and ui.pointerWidget answer in its
points, wherever the widget's screen draws; input.simulateMouse*, the
Zin.test pointer primitives and inputSim with target "ui" take its
physical pixels. A rect times this ratio is a window pixel.
"camera" is the camera's picture: the canvas a camera-space screen's
pos and anchors are stated on, laid over the scene viewport's physical
pixels, the space input.snapshot().mouse_position, input.events(),
worldToScreen, screenToRay and capture speak.
The two are one number wherever the scene fills the window. While a
Scene panel presents the scene in a rect of the window, the picture's
canvas is fitted to that rect, so its ratio follows the panel's width
(and is at least the density a display states), and the scene
viewport's pixels are measured from that rect's top-left
(camera.viewData().viewport, whose scaleX / scaleY are its pixels
per window pixel while a device screen's size is shown scaled to fit the
panel) while the window's are measured from the window's.
ui.fromViewport and ui.toViewport carry a point across both steps in
one call.
Parameters
space("window" | "camera")(optional) —"window"(default) or"camera".
Returns number — Physical pixels per logical point of that surface (1.0 when unscaled).
local r = ui.pixelRatio(); local b = tools.use("gui", "bounds", "play"); input.simulateMouseMove(b.centerX * r, b.centerY * r)
typed/builtin//modules/api/engine/ui/ui/pointerWidget
ui.pointerWidget() -> PointerRead?
Whether the UI is consuming the pointer, and which widget holds it —
the pointer counterpart of ui.focusedWidget(). x, y are in logical
points on the window, the space getLayoutInfo rects are in.
Returns PointerRead? — { x, y, overUi, widget, screen }, or nil before the UI has published a frame.
typed/builtin//modules/api/engine/ui/ui/reducedMotion
ui.reducedMotion() -> ReducedMotion
Whether the person asked for less motion, and where that came from.
reduce is true while motion is reduced: animate less (drop drift,
overshoot and travel; prefer a short cross-fade or an immediate change).
platform is the OS setting as the platform states it: Android's Remove
animations, a browser's prefers-reduced-motion, or the animation
settings of Windows, macOS and the desktop Linux portal, as "reduce" or
"no-preference"; "unknown" where the platform states no such setting,
which is not the same as off. platformSource names what it was read
from, or why the platform states none. setting is the in-app
preference ui.setReducedMotion stated, which wins over the platform's
while it stands; a world's ends when the world's scripts end, and while a
world's and a trusted screen's both stand the one stated last is
setting. source says which of
them decided ("setting", "platform" or "none"). revision advances
on every change; ui.onReducedMotionChange calls back on each. A style
follows the same preference with no Luau through an
["@media (prefers-reduced-motion: reduce)"] block (see the styling
guide), and ui.matchMedia tests any media query.
Returns ReducedMotion — { reduce, platform, platformSource?, setting?, source, revision }.
if ui.reducedMotion().reduce then print("show the change at once") end
typed/builtin//modules/api/engine/ui/ui/refreshLiveText
ui.refreshLiveText() -> number
Read again the text of every screen this VM registered whose text
resolves when it is read: a text, title, header, placeholder,
tooltip or dropdown option given as a value with a __tostring
metamethod, such as an i18n.text value, rather than as a string. The
i18n module calls it whenever the player's language, the
pseudo-locale or a catalog changes, so a screen built from i18n.text
values follows them without being built again.
Returns number — How many screens were read again.
local tree = { type = "label", props = { text = i18n.text("hud.title") } }
typed/builtin//modules/api/engine/ui/ui/registerBackgroundShader
ui.registerBackgroundShader(shaderHandle: any?, width: number?, height: number?)
Register a screen-domain .shader as a UI background, drawn
via the backgroundShader style. Takes the shader's asset handle
from asset.resolve. A shader whose compile failed
(shaderHandle:compileStatus() reads failed), or whose program
the compile gate refuses, is not registered: the call raises an
error naming the shader and the compiler's message, the one
compileStatus().error reads. A shader whose compileStatus()
still reads pending raises too: register it once it reads
compiled.
Parameters
shaderHandleany(optional) — The screen.shader's asset handle, fromasset.resolve.widthnumber(optional) — Render target width (default 1280).heightnumber(optional) — Render target height (default 720).
typed/builtin//modules/api/engine/ui/ui/registerCallbackEnv
ui.registerCallbackEnv(key: string, env: { [string]: any })
Register an environment table to receive widget callbacks: its
onCallback(id, value) fires for any widget callback not owned by a
specific component instance — the same broadcast a component's
onCallback receives. Registered from a component instance's own code
(its hooks, methods and the closures they create), the env joins that
instance: every callback the instance owns, the ones on the screens it
registered, reaches the env as well as the instance's own top-level
onCallback. Keyed by key; re-registering the same key replaces the
previous env. Reach for this from a context that hosts a UI surface with
a handler of its own (a scene entrypoint, a module, a component's local
handler). Pair with ui.unregisterCallbackEnv(key) so the ref is
released.
Parameters
keystring— Stable identifier for this registration (re-register replaces).env{ [string]: any }— Environment table whoseonCallbackreceives the broadcasts.
typed/builtin//modules/api/engine/ui/ui/registerScreen
ui.registerScreen(name: string, widgetTree: WidgetTree, layer: number?)
Register a named UI screen with a widget tree. Optional
layer controls z-ordering (higher = on top), in bands: below 0
behind everything, 0-99 ordinary app depth, 100-999 always-on-top
chrome, 1000+ menu and popup depth. A screen in a higher band
covers one in a lower band whatever their roots are; inside a band
a floating area or window root sits over ordinary content, and
a modal root sits over the whole stack. Tag-based
grouping lives in Z.tags (Z.tags.set(name, { "editor" })
after register). A screen belongs to the component instance whose
own code registers it (its hooks and methods, and any closure they
create, such as a listener it subscribes): that instance's
onCallback receives its callbacks, and the screen is unregistered
when the instance ends. Code that is not an instance's own (a scene
entrypoint, a module, a listener either subscribed) registers a
screen no instance owns, which stays until it is unregistered,
whichever component's hook ran that code. topics/ui has the rule.
Parameters
namestring— Unique screen identifier.widgetTreeWidgetTree— Root widget table.layernumber(optional) — Z-order layer (optional).
ui.registerScreen("hud", tree)
typed/builtin//modules/api/engine/ui/ui/registerTheme
ui.registerTheme(name: string, theme: ThemeDefinition)
Register a theme from a flat Luau table. Most callers
should use Z.theme.register(name, table) which runs the
cascade for them.
Parameters
namestring— Theme name to register.themeThemeDefinition— Flat-resolved theme table.
typed/builtin//modules/api/engine/ui/ui/removeScreen
ui.removeScreen(name: string) -> boolean
Alias for ui.unregisterScreen.
Parameters
namestring— Screen identifier to remove.
Returns boolean — True when a screen by this name was registered.
typed/builtin//modules/api/engine/ui/ui/resetAreaSize
ui.resetAreaSize(id: string)
Clear a resizable area's remembered size (from a grip drag or
ui.setAreaSize) so its declared — or content — size takes over again.
Parameters
idstring— Area widget id.
typed/builtin//modules/api/engine/ui/ui/response
ui.response(widgetId: string) -> WidgetResponse?
Per-widget interaction snapshot for the most recent frame.
Returns { clicked, hovered, focused, changed, value } where
clicked / changed mark transitions and hovered / focused
mark current state.
Parameters
widgetIdstring— The widget id (NOT the onClick / onChange callback id).
Returns WidgetResponse? — WidgetResponse or nil.
typed/builtin//modules/api/engine/ui/ui/safeArea
ui.safeArea(space: ("camera" | "window")?) -> SafeArea
The part of one of the two surfaces a screen lays out on (see
ui.setScreenSpace) that no system bar, display cutout or on-screen
keyboard covers, in the logical points ui.screenSize(space) reports.
"camera" (the default) is the camera's picture, where a HUD or any
camera-space screen lays out; "window" is the window, where the
editor's chrome lays out. Each is that surface's own area whether or not
a screen is shown on it, and the two are one wherever the scene fills
the window. top / right / bottom / left are how far in from each edge the
covered band reaches; x / y / width / height are the rect they
leave; cutouts lists each display cutout (a camera hole or a notch) as
{ x, y, width, height }. Screens lay out inside this rect, so anchors,
top-level % sizes and a window's default position already keep clear
of it; read it to place something by absolute pos, or to run a
background under the bars while its controls stay inside.
controls lists each rect an on-screen control drawn over the picture
covers, as { x, y, width, height, owner }: the engine's touch buttons
and its Menu button while the touch controls show (owner
"zin_touch_controls"), and every rect a world states with
ui.setControlRegions. An anchor of any other screen keeps clear of
them on its own; a box placed by pos, padding or flex reads them to
stay out from under a control, where a press would reach the control
instead of the widget.
revision advances every time the area, the size of its surface or the
controls change (a rotation, the system bars shown or hidden, the
keyboard opening, a resize, a control shown, hidden or moved): compare it
with the one you last laid out against, or subscribe with
ui.onCanvasChange, which calls back on each change of the area and of
the canvas it is stated on. All zero on a desktop window;
ui.simulateSafeArea lays the UI out as a phone would on any engine,
on the window and on the picture a Scene panel presents.
Parameters
space("camera" | "window")(optional) —"camera"(default) or"window".
Returns SafeArea — { top, right, bottom, left, x, y, width, height, cutouts, controls, revision } in that surface's logical points.
local safe = ui.safeArea()
ui.setAreaPos("hud", safe.x + 8, safe.y + 8)
for _, c in ipairs(ui.safeArea().controls) do print(c.owner, c.x, c.y, c.width, c.height) end
typed/builtin//modules/api/engine/ui/ui/screen
ui.screen(name: string) -> { [string]: any }?
Get a screen proxy with methods like setResolution and
rasterize.
Parameters
namestring— Screen name.
Returns { [string]: any }? — Screen proxy table, or nil.
typed/builtin//modules/api/engine/ui/ui/screenRefusal
ui.screenRefusal(screenName: string) -> string?
Why the code calling may not reach the screen screenName, or nil
when it may: a private screen (setScreenPrivate) is reached by the
account's own code alone. Code that acts on such a screen on its caller's
behalf, such as an editor panel's exported functions, raises it before it
acts.
Parameters
screenNamestring— The screen name.
Returns string? — The refusal, or nil.
local why = ui.screenRefusal("edui_p_memory"); if why then error(why, 2) end
typed/builtin//modules/api/engine/ui/ui/screenSize
ui.screenSize(space: ("camera" | "window")?) -> { width: number, height: number }
The canvas one of the two surfaces a screen lays out on spans, as
{ width, height } in logical points: the space that surface's area
pos and anchors are stated in (see ui.setScreenSpace).
"camera" (the default) is the camera's picture, where a camera-space
screen lays out: a HUD, a game menu, any content UI that states no other
space. It is the canvas ui.fromViewport(x, y) answers on, so a HUD
clamps a marker to ui.screenSize() and places it at
ui.fromViewport of a worldToScreen projection. "window" is the
window, where the editor's chrome lays out and ui.getLayoutInfo rects
are recorded. Each is that surface's size whether or not a screen is
shown on it, and the two are one size wherever the scene fills the
window; while a Scene panel presents the scene inside the window, the
camera's canvas is fitted to the panel, or laid out as the device screen
renderer.setPictureSize draws the panel's picture at. Neither is the
pixel size of a capture screenshot, which may be downscaled.
It follows the size the engine draws at, and renderer.setViewportSize
changes that size for the task that asks, which is how a layout written
against this is checked at a second shape without rebooting the engine,
read in the call that set the size before the surface goes back;
renderer.setPictureSize does the same for the camera's canvas alone
while a Scene panel presents it. The
pixel size behind the window's points is renderer.surfaceSize(), the
whole drawing surface, which an editor layout makes larger than the rect
renderer.viewportSize() draws the scene into. ui.pixelRatio(space) is
the factor between a surface's points and its pixels.
The size changes while the engine runs (a window resized, a phone
rotated, a Scene panel dragged), and a layout computed from it is
computed again when it does: ui.onCanvasChange(fn, space) calls back
once for each change, and ui.canvas(space) reads the size with the
pixel ratio, the safe area and a revision that advances on each.
Parameters
space("camera" | "window")(optional) —"camera"(default) or"window".
Returns { width: number, height: number } — { width, height } in that surface's logical points.
local w = worldToScreen(0, 2, 0); local p = ui.fromViewport(w.x, w.y); local s = ui.screenSize(); local onCanvas = p.x >= 0 and p.x <= s.width and p.y >= 0 and p.y <= s.height
typed/builtin//modules/api/engine/ui/ui/scroll
ui.scroll(deltaX: number, deltaY: number)
Simulate a mouse-wheel scroll event on the UI.
Parameters
deltaXnumber— Horizontal scroll delta.deltaYnumber— Vertical scroll delta.
typed/builtin//modules/api/engine/ui/ui/setAreaPos
ui.setAreaPos(id: string, x: number, y: number)
Programmatically move a movable area widget to (x, y).
Applied for one frame; subsequent frames let drag tracking
take over.
Parameters
idstring— Area widget id.xnumber— Target pivot x (screen coords).ynumber— Target pivot y (screen coords).
typed/builtin//modules/api/engine/ui/ui/setAreaSize
ui.setAreaSize(id: string, w: number, h: number)
Programmatically set a resizable area's size (the user-size
override) — for maximize / restore / tile. Persists until the area's
declared width/height changes or ui.resetAreaSize(id) clears it.
Parameters
idstring— Area widget id.wnumber— Target width (screen coords).hnumber— Target height (screen coords).
typed/builtin//modules/api/engine/ui/ui/setControlRegions
ui.setControlRegions(owner: string, rects: { SafeAreaRect }?)
State the rects the on-screen controls owner draws over the
camera's picture cover, each { x, y, width, height } in the logical
points ui.screenSize() reports. ui.safeArea().controls lists them
from this call on, its revision advances, and from the next frame an
anchor of any other screen that would land on one moves inward clear
of it (a box pinned to the right edge moves left, one pinned to the top
moves down, along whichever axis is the shorter move), keeping its
margin from the control as it keeps it from the edge. Anchors keep
clear of them while the screen keeps the size ui.screenSize()
reported at the call, so restate them whenever the controls move and
after the screen changes size (a rotation or a window resize advances
ui.safeArea().revision), and call with nil or {} to withdraw them.
The engine's touch controls state theirs under "zin_touch_controls";
a world drawing on-screen controls of its own states them under the
name of the screen it draws them on, so that screen's own anchors stay
where it put them. A negative size or a non-number is refused by name.
Parameters
ownerstring— Who draws the controls: the name of the screen they are drawn on.rects{ SafeAreaRect }(optional) —{ { x, y, width, height } }in logical points; nil or{}withdraws them.
ui.setControlRegions("myTouchPad", { { x = 1100, y = 520, width = 160, height = 160 } })
ui.setControlRegions("myTouchPad", nil)
typed/builtin//modules/api/engine/ui/ui/setDockWindowRect
ui.setDockWindowRect(dockId: string, panelId: string, x: number, y: number, width: number, height: number)
Place the floating window of a dockArea panel at (x, y) with
size (width, height). Applies once the panel occupies a window —
a request made before then waits for it.
Parameters
dockIdstring— DockArea widget id.panelIdstring— Id of the panel held by the window to place.xnumber— Window left edge (screen coords).ynumber— Window top edge (screen coords).widthnumber— Window width (screen coords).heightnumber— Window height (screen coords).
typed/builtin//modules/api/engine/ui/ui/setMotion
ui.setMotion(id: string, values: MotionValues)
Place the widget id at values ({ x?, y?, scale?, opacity? },
as ui.spring takes them) at once, at rest, ending any motion of the
channels it names; a placement that leaves no channel of a spring or
fling moving runs its onSettle, as ui.stopMotion does. Nothing is
laid out anew and no screen tree is sent:
a script running its own simulation states each frame's positions this
way, or many widgets' at once with ui.setMotions.
Parameters
idstring— The widget'sid.valuesMotionValues—{ x?, y?, scale?, opacity? }.
ui.setMotion("cursor_ghost", { x = 12, y = -4 })
typed/builtin//modules/api/engine/ui/ui/setMotions
ui.setMotions(values: { [string]: MotionValues })
Place many widgets at once: values maps each widget id to
{ x?, y?, scale?, opacity? }, as ui.setMotion takes them. One call a
frame moves a whole field of widgets a script simulates (bubbles that
drift and push each other apart) with no screen tree sent again.
Parameters
values{ [string]: MotionValues }—{ [id]: { x?, y?, scale?, opacity? } }.
ui.setMotions({ a = { x = 10, y = 4 }, b = { x = -3, y = 12, scale = 1.1 } })
typed/builtin//modules/api/engine/ui/ui/setReducedMotion
ui.setReducedMotion(reduce: (boolean | MotionPreference)?) -> boolean
State the in-app reduced-motion preference, which wins over the OS
setting while it stands: true (or "reduce") reduces motion, false
(or "no-preference") asks for full motion, and nil withdraws it so the
OS setting stands again. An app's own "Reduce motion" switch calls this.
A world's preference ends when the world's scripts end; a trusted
screen's stands for the life of the engine, and while both stand the one
stated last decides.
ui.reducedMotion(), ui.matchMedia and every style's
@media (prefers-reduced-motion) block follow it from the next frame.
Any other value is refused by name.
Parameters
reduce(boolean | MotionPreference)(optional) —true/"reduce",false/"no-preference", or nil to withdraw it.
Returns boolean — Whether the preference changed.
ui.setReducedMotion(true)
ui.setReducedMotion(nil)
typed/builtin//modules/api/engine/ui/ui/setScreenPrivate
ui.setScreenPrivate(screenName: string)
State that the screen screenName draws what the person keeps for
themselves, whether or not it is registered yet, for as long as the
engine runs. From then on it is reached by the account's own code alone
(the editor, the agent's tools and execute): code a world ships reads
nothing it draws (getScreenTree, elementTree, paintSnapshot,
getLayoutInfo, widgetState, focusedTextField,
/runtime/ui/<name>/), drives none of it (registering, updating,
showing, hiding or unregistering it, click on an id its widgets emit,
focus, typeText into its field, a widget of another screen emitting
an id its widgets emit) and hears none of its callbacks. The account's
own code alone states it; code a world ships is refused. An editor panel
states it with private = true in its spec.
Parameters
screenNamestring— The screen name.
ui.setScreenPrivate("edui_p_memory")
typed/builtin//modules/api/engine/ui/ui/setScreenRenderLayer
ui.setScreenRenderLayer(name: string, mask: number)
Set a screen's render-layer membership bitmask. A screen draws into a
camera or capture only when this mask intersects the camera's include
mask, the same rule geometry follows. Content UI carries the ui bit;
the editor places its chrome on EditorUI so agent captures can drop it,
and a screen carrying that bit is part of the window rather than the
camera's picture. Stating a mask here fixes the membership: a screen left
to itself takes the one the surface it is placed on implies, EditorUI
for the window and ui for the camera's picture. __renderLayers.bit(name)
answers with a layer's bit INDEX, so a mask sets the bit at that index and
__renderLayers.names(mask) reads it back as the names it holds.
Parameters
namestring— Screen identifier.masknumber— Render-layer membership bitmask — the OR ofbit32.lshift(1, __renderLayers.bit(name))over the layers the screen is on.
ui.setScreenRenderLayer("hud", bit32.lshift(1, __renderLayers.bit("ui")))
typed/builtin//modules/api/engine/ui/ui/setScreenSpace
ui.setScreenSpace(name: string, space: string)
Set which surface a screen is part of. "camera" is the picture the
viewport camera produces: the screen lays out over the camera's target
and is drawn into it, so it sits inside the Scene panel presenting the
scene and appears in every capture of the camera — the default for
content UI. "window" is the window itself, whatever presents the scene
— where the editor's chrome lives, and the default for a screen on the
EditorUI layer. The two are one statement made from either end, so a
screen placed on the window takes the EditorUI membership unless
setScreenRenderLayer states another: the window goes on drawing it while
a capture that drops the authoring layers, which is what an agent takes by
default, leaves it out. Where the scene presents on the window, the two
surfaces coincide. A name that is neither raises.
Parameters
namestring— Screen identifier.spacestring—"camera"|"window".
ui.setScreenSpace("agent-banner", "window")
typed/builtin//modules/api/engine/ui/ui/setScrollPosition
ui.setScrollPosition(widgetId: string, offsetY: number)
Set the scroll offset of a scrollArea widget.
Parameters
widgetIdstring— Scroll area widget id.offsetYnumber— Vertical scroll offset in pixels.
typed/builtin//modules/api/engine/ui/ui/setShaderUniforms
ui.setShaderUniforms(name: string, uniforms: { [string]: number })
Set uniform values on a registered background shader.
Parameters
namestring— Shader name identifier.uniforms{ [string]: number }— Map of uniform name to number value.
typed/builtin//modules/api/engine/ui/ui/setTheme
ui.setTheme(name: string)
Switch the active global theme by name.
Parameters
namestring— Theme name to activate.
typed/builtin//modules/api/engine/ui/ui/showScreen
ui.showScreen(name: string) -> boolean
Make a registered screen visible, and report whether a screen by
that name is registered. The engine applies the show later in the
frame; listScreens reflects it from the next call onwards.
Parameters
namestring— Screen identifier to show.
Returns boolean — True when a screen by this name is registered.
typed/builtin//modules/api/engine/ui/ui/simulateDisplayScale
ui.simulateDisplayScale(scale: DisplayScaleSpec?)
Size the UI as a display stating scale would, in place of what the
platform states. A density sizes it as a handheld display of that
many physical pixels per point (omit it for a desktop display sized by
its width), and textScale multiplies every font size the UI typesets
(1 when omitted). Previews a phone's UI on a desktop or headless engine,
and makes a layout test independent of the device it runs on.
ui.displayScale(), ui.screenSize() and ui.pixelRatio() report it
from the next frame. Call it with no argument (or nil) to return to
the platform's own scale. A value that is not a number above 0 and at
most 8 is refused by name.
Parameters
scaleDisplayScaleSpec(optional) —{ density?, textScale? }; nil returns to the platform's scale.
ui.simulateDisplayScale({ density = 2.625, textScale = 1.3 })
ui.simulateDisplayScale()
typed/builtin//modules/api/engine/ui/ui/simulateSafeArea
ui.simulateSafeArea(area: SafeAreaSpec?)
Lay the UI out as if the system covered the screen by
area (logical points) in place of what the platform states: each inset
defaults to 0 and cutouts is a list of { x, y, width, height }.
Previews a phone's status bar, camera cutout and navigation bar on a
desktop or headless engine, and makes a layout test independent of the
device it runs on. It covers the window, and while a Scene panel
presents the scene inside the window it covers the camera's picture
too, stated in that picture's points, so a game's HUD in the panel lays
out inside it in edit and in play as it would on that phone. With
renderer.setPictureSize sizing that picture to a phone's pixels, the
panel shows what that phone shows. ui.safeArea() reports it from the
next frame. Call
it with no argument (or nil) to return to the platform's own safe
area. A negative or non-number inset is refused by name.
Parameters
areaSafeAreaSpec(optional) —{ top?, right?, bottom?, left?, cutouts? }in logical points; nil returns to the platform's safe area.
ui.simulateSafeArea({ top = 40, bottom = 30, cutouts = { { x = 600, y = 0, width = 80, height = 40 } } })
ui.simulateSafeArea()
typed/builtin//modules/api/engine/ui/ui/spring
ui.spring(id: string, target: MotionValues, options: SpringOptions?)
Move the widget id toward target by a spring the engine steps
each frame: no script runs per frame and the screen tree is not sent
again. target names any of x, y (an offset in points from where
layout puts the widget), scale (about its centre, 1 unscaled) and
opacity (multiplying its own, 1 unchanged). The widget is drawn moved
and is pressed where it is drawn; its layout box and its neighbours stay
put. Calling it again mid-motion retargets from where the widget is, with
the speed it has, so it never jumps. Options: stiffness (default 170),
damping (the damping ratio, default 0.8: below 1 overshoots and
settles, 1 arrives without overshooting), mass (default 1),
velocity ({ x, y, scale, opacity } per second: a drag's release
speed, or a kick with no target, which springs back to where the channel
rests) and onSettle (a callback id: once every channel rests, the
screen's onCallback(onSettle, data) runs with
data.value = { id, x, y, scale, opacity }). Under reduced motion an
opacity change is a 0.15 s cross-fade and the widget moves to its target
at once, or, while it fades out, once the fade has ended, so the fade is
seen where it was. A key it does not take is refused by name.
Parameters
idstring— The widget'sid.targetMotionValues—{ x?, y?, scale?, opacity? }: where it springs to.optionsSpringOptions(optional) —{ stiffness?, damping?, mass?, velocity?, onSettle? }.
ui.spring("menu", { y = 0, opacity = 1 }, { stiffness = 400, damping = 0.6 })
ui.spring("card", { scale = 1 }, { velocity = { scale = 4 } }) -- a pop
typed/builtin//modules/api/engine/ui/ui/stopMotion
ui.stopMotion(id: string)
Hold the widget id where it is now, ending its spring or fling (a
finger landing on a moving widget). Its onSettle callback runs, as for
a motion that came to rest.
Parameters
idstring— The widget'sid.
typed/builtin//modules/api/engine/ui/ui/takeDockTearOffs
ui.takeDockTearOffs(id: string) -> { string }
The panel ids of the tabs dragged out of the dockArea id and
released over empty space since the last call. A dock standing in an XR
panel hands such a tab to its owner rather than opening a window inside
itself, and keeps it out of the dock for as long as the dockArea still
lists it; the owner places the panel and stops listing it. Empty for a dock
drawn on the desktop window.
Parameters
idstring— DockArea widget id.
Returns { string } — Array of panel ids.
typed/builtin//modules/api/engine/ui/ui/toViewport
ui.toViewport(x: number, y: number, space: ("camera" | "window")?) -> { x: number, y: number }
Carry a point from the UI's logical points into the scene viewport's
physical pixels: the inverse of ui.fromViewport, and the space
screenToRay, screenToPlanePoint and Physics.raycastScreen take, so a
point read off the UI can be cast into the scene.
space names the surface the point is on: "camera" (the default) for
a camera-space screen's pos / anchor coordinates, "window" for a
ui.getLayoutInfo / gui.bounds rect.
Parameters
xnumber— X in that surface's logical points.ynumber— Y in that surface's logical points.space("camera" | "window")(optional) —"camera"(default) or"window".
Returns { x: number, y: number } — { x, y } in the scene viewport's physical pixels.
local b = tools.use("gui", "bounds", "target"); local v = ui.toViewport(b.centerX, b.centerY, "window"); local hit = Physics.raycastScreen(v.x, v.y)
typed/builtin//modules/api/engine/ui/ui/typeKey
ui.typeKey(key: string, modifiers: { shift: boolean?, ctrl: boolean?, alt: boolean? }?)
Press and release key on the text field that holds the keys
(ui.focusedTextField): Backspace, Delete, Enter (a new line in a
multi-line field, a submit in a single-line one), Tab, Escape, the
arrows, Home, End, or any other KeyboardEvent.code. modifiers
names the modifiers held for it (Shift with an arrow selects). It reaches
the UI alone: the game's input reads no key. Raises on a name that is not
a key code.
Parameters
keystring— The key, as a KeyboardEvent.code.modifiers{ shift: boolean?, ctrl: boolean?, alt: boolean? }(optional) —{ shift?, ctrl?, alt? }.
ui.typeKey("Backspace")
typed/builtin//modules/api/engine/ui/ui/typeText
ui.typeText(text: string)
Type text into the text field that holds the keys
(ui.focusedTextField), the way a keyboard's typed characters reach it:
inserted at the caret, in place of a selection. Control characters other
than a new line and a tab are left out. It reaches the UI alone: the
game's input reads no key.
Parameters
textstring— The characters to type.
ui.typeText("hello")
typed/builtin//modules/api/engine/ui/ui/unregisterCallbackEnv
ui.unregisterCallbackEnv(key: string)
Remove an environment registered with ui.registerCallbackEnv. Its
onCallback stops receiving broadcasts. No-op if key isn't registered.
Parameters
keystring— The key passed toui.registerCallbackEnv.
typed/builtin//modules/api/engine/ui/ui/unregisterScreen
ui.unregisterScreen(name: string) -> boolean
Remove a screen from the registry entirely. Unlike
hideScreen, this deletes the entry so it no longer appears in
listScreens or render iteration.
Parameters
namestring— Screen identifier to unregister.
Returns boolean — True when a screen by this name was registered.
typed/builtin//modules/api/engine/ui/ui/unregisterWidget
ui.unregisterWidget(name: string)
Drop a registered custom widget kind. Subsequent references
produce an unknown-widget-type diagnostic.
Parameters
namestring— Custom widget kind name.
typed/builtin//modules/api/engine/ui/ui/updateScreen
ui.updateScreen(name: string, widgetTree: WidgetTree)
Replace the widget tree of an already-registered screen.
Parameters
namestring— Screen identifier to update.widgetTreeWidgetTree— New root widget table.
typed/builtin//modules/api/engine/ui/ui/useStyles
ui.useStyles(themeName: string)
Apply a registered style file's classes additively without changing the active theme.
Parameters
themeNamestring— Name of the registered style / theme asset.
typed/builtin//modules/api/engine/ui/ui/widgetState
ui.widgetState(widgetId: string, key: string, default: any?) -> any
Read per-widget cross-frame state. Returns the value
previously written via widgetStateSet, or default (or nil).
State is keyed by widget id and persists across re-renders
within a screen's lifetime; cleared automatically when the
owning screen is unregistered.
Parameters
widgetIdstring— Widget id whose state to read.keystring— State key.defaultany(optional) — Value to return when nothing has been written.
Returns any — Stored value, default, or nil.
typed/builtin//modules/api/engine/ui/ui/widgetStateClear
ui.widgetStateClear(widgetId: string, key: string)
Remove a per-widget state entry.
Parameters
widgetIdstring— Widget id whose state to clear.keystring— State key.
typed/builtin//modules/api/engine/ui/ui/widgetStateSet
ui.widgetStateSet(widgetId: string, key: string, value: any?)
Write per-widget cross-frame state. Replaces any existing
value under (widgetId, key). Tables are stored by reference.
Parameters
widgetIdstring— Widget id to scope the state under.keystring— State key.valueany(optional) — Value to store (must be non-nil).
typed/builtin//modules/api/engine/userfile/userfile/pick
userfile.pick(opts: PickOpts?) -> PickResult
Open the user's system file picker and bring the chosen file(s)
into the engine. Yields until the user finishes (call from a coroutine /
task, like any task.await) and returns
{ cancelled, files = {{ name, mime, size, bytes?, vfsPath? }} }.
Without writeTo each file carries bytes (a binary-safe string);
with writeTo each carries vfsPath (read it with vfs.read).
Cancelling returns { cancelled = true, files = {} }; a genuine failure
(e.g. a lost browser user-activation gesture) raises an error.
Parameters
optsPickOpts(optional) — Picker options (optional): multiple, folder, title, filters, writeTo.
Returns PickResult — The decoded result table.
local r = userfile.pick({ filters = {{ name = "Images", extensions = {"png","jpg"} }} })
if not r.cancelled then vfs.write("/source/textures/wall.png", assert(r.files[1].bytes)) end
typed/builtin//modules/api/engine/userfile/userfile/pickFolder
userfile.pickFolder(opts: PickOpts?) -> PickResult
Convenience for userfile.pick({ folder = true }) — pick a whole
directory tree. Yields until the user finishes and returns the same
result table as pick. On the web this degrades to a multi-file selection.
Parameters
optsPickOpts(optional) — Picker options (optional);folderis forced true.
Returns PickResult — The decoded result table.
local r = userfile.pickFolder({ writeTo = "/source/imported/" })
typed/builtin//modules/api/engine/userfile/userfile/save
userfile.save(path: string, opts: SaveOpts?) -> (boolean, string, SaveReport?)
Save a file the engine holds onto the device of the person at the
screen: the way a person keeps a recording, a capture or an export.
The person decides where it lands. In the browser the file downloads at
once when the save rides a click or key press of the person at the
screen (call it from a button's click handler), and otherwise the page
shows them an offer they save with a click of their own, since a
browser starts a download only for a person who just acted. A native
engine opens the host's save dialog in their downloads folder, with the
name filled in, and writes the file where they choose. An Android engine
opens the system's save picker and answers "saved" once the file is
written where they chose, or false when they close the picker. An engine
with no window has no person at its screen and refuses. The call waits
for the first answer, so run it where it can yield (task.spawn from a
callback). Returns true, a sentence saying where the file went, and the
report { state, detail, name, size, path } whose state
is "saved" (the file is on the device) or "offered" (it is in front
of the person, as the page's offer or the save dialog, and lands when
they act); or false and the reason the save was refused: no file at the
path, a folder, a name with a folder in it, no window, or a file too
large for the browser to hold (which the page also shows).
Parameters
pathstring— VFS path of the file to save.optsSaveOpts(optional) —{ name }, the file name the device gets (the file's own when omitted).
Returns (boolean, string, SaveReport?) — Whether the device took the file. Where it went, or why it was refused. The save report, when the device took the file.
local ok, where = userfile.save("/zero/runtime/recordings/take.mp4")
local ok, where, report = userfile.save("/zero/source/export/level.json", { name = "level-3.json" })
typed/builtin//modules/api/engine/values/values/bind
values.bind(target: string | entityRef, name: string, opts: { format: string?, scale: number?, offset: number?, fallback: any? }?) -> ValueBinding
A UI prop that follows a named value, with no script updating the
screen: put it where a widget takes text, value, visible,
checked or enabled, and the widget reads the value every frame.
format is a string.format pattern for text ("%d rpm"; the value
as it reads when absent); scale and offset map a number
(value * scale + offset) before it is shown. A value the entity does
not hold shows fallback (empty text, 0 or false when absent).
Parameters
targetstring | entityRef— The entity: a proxy fromentity(...), or its id.namestring— The value's name.opts{ format: string?, scale: number?, offset: number?, fallback: any? }(optional) —{ format?, scale?, offset?, fallback? }.
Returns ValueBinding — A binding to place in a widget's props.
ui.registerScreen("dash", { type = "vertical", children = {
{ type = "label", props = { text = values.bind(car, "rpm", { format = "%.0f rpm" }) } },
{ type = "slider", props = { min = 0, max = 1, value = values.bind(car, "throttle") } },
} })
typed/builtin//modules/api/engine/values/values/clear
values.clear(target: string | entityRef) -> number
Drop every named value an entity holds. An entity's values also go when the entity leaves the world.
Parameters
targetstring | entityRef— The entity: a proxy fromentity(...), or its id.
Returns number — How many values it held.
values.clear(car)
typed/builtin//modules/api/engine/values/values/declare
values.declare(target: string | entityRef, name: string, declaration: ValueDeclaration?)
State what a named value is: its type ("number", "vector" or
"boolean"), the default it starts at, and whether it replicates. A name
the entity already holds keeps its value. replicate is a rate in Hz (up
to 60): the owner of the entity sends the value to every other peer at
most that often while it changes, and always sends the latest one, and
the other peers read it like any value. A value with no replicate is
never sent anywhere.
Parameters
targetstring | entityRef— The entity: a proxy fromentity(...), or its id.namestring— The value's name.declarationValueDeclaration(optional) —{ type?, default?, replicate? }; givetypeordefaultfor a name the entity does not hold yet.
values.declare(car, "throttle", { type = "number", default = 0, replicate = 10 })
values.declare(car, "brake", { default = false, replicate = 20 })
typed/builtin//modules/api/engine/values/values/describe
values.describe(target: string | entityRef) -> { ValueRow }
Every named value an entity holds, sorted by name, each with its
type, its value, who wrote it last (writer: "script", "engine" or
"remote"), the store revision of its last change, its replicate rate
(absent for a value kept on this engine) and whether a declaration states
it. The same rows /zero/runtime/values/<entityId> and the values
toolbox list.
Parameters
targetstring | entityRef— The entity: a proxy fromentity(...), or its id.
Returns { ValueRow } — The rows.
for _, row in values.describe(car) do print(row.name, row.type, row.value, row.writer) end
typed/builtin//modules/api/engine/values/values/entities
values.entities() -> { string }
Every entity holding at least one named value, sorted by id.
Returns { string } — Entity ids.
for _, id in values.entities() do print(id, #values.describe(id)) end
typed/builtin//modules/api/engine/values/values/get
values.get(target: string | entityRef, name: string) -> Value?
Read a named value an entity holds, or nil when it holds none under
that name. Engine systems write values too: a WheelCollider writes its
own state (wheel.slipRatio, wheel.angularVelocity, ...), so a script
reads it here the way it reads a value a script wrote.
Parameters
targetstring | entityRef— The entity: a proxy fromentity(...), or its id.namestring— The value's name.
Returns Value? — The value, or nil.
local rpm = values.get(car, "rpm") or 0
typed/builtin//modules/api/engine/values/values/list
values.list(target: string | entityRef) -> { [string]: Value }
Every named value an entity holds, by name.
Parameters
targetstring | entityRef— The entity: a proxy fromentity(...), or its id.
Returns { [string]: Value } — { [name] = value }.
for name, v in values.list(car) do print(name, v) end
typed/builtin//modules/api/engine/values/values/onAnyChange
values.onAnyChange(callback: (Value?, string, string) -> ()) -> ValueConnection
Call callback(value, name, entityId) for every change of every named
value on every entity, once per frame in which it changed: what a debug
view or a recorder of a session's values follows.
Parameters
callback(Value?, string, string) -> ()—function(value, name, entityId).
Returns ValueConnection — A connection; :Disconnect() ends it.
local conn = values.onAnyChange(function(v, name, id) print(id, name, v) end)
typed/builtin//modules/api/engine/values/values/remove
values.remove(target: string | entityRef, name: string) -> boolean
Drop a named value from an entity.
Parameters
targetstring | entityRef— The entity: a proxy fromentity(...), or its id.namestring— The value's name.
Returns boolean — Whether the entity held it.
values.remove(car, "rpm")
typed/builtin//modules/api/engine/values/values/set
values.set(target: string | entityRef, name: string, value: Value?)
Write a named value on an entity: a number, a vector or a boolean;
nil removes it. A name takes the kind of its first value and keeps it:
writing another kind raises (remove the value first to change its kind).
The write is a store, with nothing replicated and nothing copied, and
every reader sees it from the next read: values.get, a material
property bound to the name, an Audio voice following it, a UI prop
values.bind made. Only a value values.declare gives a replicate
rate is ever sent to other peers.
Parameters
targetstring | entityRef— The entity: a proxy fromentity(...), or its id.namestring— The value's name.valueValue(optional) — A number, a vector or a boolean;nilremoves the value.
values.set(car, "rpm", 3200)
values.set(car, "headlights", true)
values.set(car, "wheelSpin", vector.create(0, 12.5, 0))
typed/builtin//modules/api/engine/values/values/stats
values.stats() -> { entities: number, values: number, revision: number, replication: ValueReplicationStats }
How many entities hold values, how many values there are, the
store's revision (which advances on every change), and what replication
has carried: a value with no replicate rate adds nothing to it.
Returns { entities: number, values: number, revision: number, replication: ValueReplicationStats } — { entities, values, revision, replication }.
print(values.stats().values, values.stats().replication.sentBytes)
typed/builtin//modules/api/engine/values/values/subscribe
values.subscribe(target: string | entityRef, name: string?, callback: (Value?, string, string) -> ()) -> ValueConnection
Call callback(value, name, entityId) when a named value of an entity
changes, whoever changed it: a script, an engine system or another peer.
Give name to follow one value, or nil to follow every value of the
entity. The callback runs once for the writes a frame made, on the
engine's next pass over its tasks, with the value as it stands then:
three writes in one frame are one call with the last of them. A value
that went (values.remove, its entity left the world) arrives as nil.
A subscription made by a component ends with the component.
Parameters
targetstring | entityRef— The entity: a proxy fromentity(...), or its id.namestring(optional) — The value's name, or nil for every value of the entity.callback(Value?, string, string) -> ()—function(value, name, entityId).
Returns ValueConnection — A connection; :Disconnect() ends it.
local conn = values.subscribe(car, "gear", function(gear) print("now in gear", gear) end)
conn:Disconnect()
typed/builtin//modules/api/engine/vfs/vfs/claimWalks
vfs.claimWalks() -> number
Lifetime count of walks over every asset the world offers: the part of
an enumeration's cost that grows with how many assets exist. asset.list
reads a snapshot of every registered claim, built once for each change to
what the world offers and shared by every list after it;
asset.categories reads the category registry and walks nothing. Read it
around a burst to learn what that burst cost in walks, a number that reads
the same on a loaded machine and a quiet one.
Returns number — Count of claim walks this session. Monotonic.
local at = vfs.claimWalks()
vfs.write("/zero/source/probe.module/init.luau", "return {}")
asset.list("module")
print(vfs.claimWalks() - at)
typed/builtin//modules/api/engine/vfs/vfs/clearPlayShadow
vfs.clearPlayShadow() -> boolean
Forget the entire play-shadow set after a bulk promote or discard. Tracking only — never touches the bytes.
Returns boolean — Always true.
vfs.clearPlayShadow()
typed/builtin//modules/api/engine/vfs/vfs/contentAddress
vfs.contentAddress(path: string, opts: VfsOpts?) -> string?
The content address (sha-256 hex) of the bytes vfs.read(path)
returns, for a path whose bytes the blob store holds, answered
synchronously and without the bytes. Two answers that agree name the
same bytes, and a write that changes them changes it. Nil for a path
whose bytes are held in memory (text under the inline size threshold,
a play shadow, a kept read), which a synchronous vfs.read already
returns, and for a path nothing is stored at. Keep it beside a copy of
a file you read to tell, from a caller that cannot yield, whether the
copy is still what the path holds.
Parameters
pathstring— VFS path.optsVfsOpts(optional) —{ root = "/source/" }.
Returns string? — The sha-256 hex of the blob-held bytes at path, or nil.
local address = vfs.contentAddress("/zero/source/scenes/main.scene/scene.json")
typed/builtin//modules/api/engine/vfs/vfs/contentAddressAsync
vfs.contentAddressAsync(path: string, opts: VfsOpts?) -> PromiseHandle
The content address (sha-256 hex) and length of the bytes
vfs.read(path) returns, for a file held in any layer. Returns a
promise ID: task.await(vfs.contentAddressAsync(path)) answers
{ sha256, size }, or { error } naming why (nothing at the path, a
folder, a read that failed). The file is read a piece at a time off the
frame, so a file of any size (a recorded film) is addressed without
being held whole. The address is the one ZeroMind's content store files
the bytes under.
Parameters
pathstring— VFS path.optsVfsOpts(optional) —{ root = "/source/" }.
Returns PromiseHandle — A promise ID resolving to { sha256, size } or { error }.
local a = task.await(vfs.contentAddressAsync("/zero/source/local/recordings/take.mp4"))
typed/builtin//modules/api/engine/vfs/vfs/contentClock
vfs.contentClock() -> number
A number that moves whenever vfs.contentVersion of any file moves:
every write, move and removal moves it the moment it lands, from every
origin vfs.contentVersion names. While two reads of it are equal, every
vfs.contentVersion reads what it read at the first, so a reader that
holds the versions of many files reads this one number each time, and
reads the files' versions again only once it moved.
Returns number — The content clock.
local at = vfs.contentClock()
if vfs.contentClock() ~= at then --[[ read the versions you hold again ]] end
typed/builtin//modules/api/engine/vfs/vfs/contentVersion
vfs.contentVersion(path: string) -> number
A number that moves every time the file at path changes this
session: each write, and each move onto it, stamps it with a version no
file has held this session, and while nothing is stored at path (before
it is written, after it is removed or moved away) it reads 0. It moves
the moment any change lands, from every origin: a script's write, a
peer's, a dev-mode disk pickup, a world-load or branch-swap write made
before the world's content is ready, a world's unmount, both ends of a
move, and a directory removal. Keep the value you saw when you last read
the file, and read it again only when the number moved.
Parameters
pathstring— The file's path, in any formvfs.readtakes.
Returns number — The path's content version.
local seen = vfs.contentVersion("/zero/source/.world_settings")
typed/builtin//modules/api/engine/vfs/vfs/copy
vfs.copy(src: string, dst: string) -> (boolean, (WriteReport | string)?)
Copy a file OR directory from src to dst, cp -r style. A
directory recurses — every descendant is replicated at the same
relative path under dst, .refs sidecars included. .meta
sidecars are minted fresh, so a copy is a distinct asset with its
own identity, and a copied tree references itself: where a copied
file names the guid of an asset the same copy took, it names the
guid of that asset's copy, and its .refs is derived again from
that text. A guid of an asset outside src stays as written.
Both paths are absolute. The source may live in any
layer (writable, library mount, builtin, runtime-generated); the
destination must be a writable route.
Parameters
srcstring— Source absolute VFS path (file or directory).dststring— Destination absolute VFS path.
Returns (boolean, (WriteReport | string)?) — True and a WriteReport on success. A copy is a write at its destination, so it reports what vfs.write reports for the same bytes at that path: where they went, and what the static passes read in the Luau among them, per landed leaf when the copy took a folder. A module that is advisory where it sat reads as a script error once it sits on a component path, and the copy is what put it there. (false, errmsg) on failure.
vfs.copy("/zero/runtime/recordings/take1.mp4", "/zero/source/clips/take1.mp4")
local ok, report = vfs.copy(mod, "/zero/source/game/Vent.component")
typed/builtin//modules/api/engine/vfs/vfs/currentAuthor
vfs.currentAuthor() -> { id: string, stable: string, connection: string, agent: string?, name: string?, account: string? }?
The caller this call is attributed to: the author a /source write
made right now would be recorded under in the play shadow. id names the
calling session where the transport attested one, so two agent sessions
driving one engine read as two callers even when one linked ZeroMind
account minted both their tokens. stable is the key the caller had
before the world's roster named it, which a rename leaves where it was;
one of several agents sharing a connection, which names itself with the
as argument every tool takes, has a stable of its own. connection
is the key of the connection the caller called over, the one the
caller's staging area and the writer its dirty rows record are kept
under, so the agents of one connection stage and commit one another's
work. agent is the name the world's roster holds for the caller now;
name is its account's username, which every agent of the account
shares; account is that shared account. Nil
when the engine can name no caller at all, which is the case for
engine-authored work and for a caller that presented neither a session
nor a token. Compare its id against vfs.playShadowAuthors() to
separate your own pending edits from a co-author's.
Returns { id: string, stable: string, connection: string, agent: string?, name: string?, account: string? }? — { id, stable, connection, agent, name, account } for the acting caller, or nil when unattributed.
local me = vfs.currentAuthor()
print(if me ~= nil then me.id else "unattributed")
typed/builtin//modules/api/engine/vfs/vfs/dirSink
vfs.dirSink(path: string, opts: DirSinkOpts) -> PluginHandle
A sink for new files under the folder at path, subfolders
included, to pass a plugin in a call. The plugin makes whatever files it
needs within opts.maxFiles files and opts.maxBytes bytes in all.
Only the world's own files take a sink.
Parameters
pathstring— The folder to write under.optsDirSinkOpts—{ maxFiles = <n>, maxBytes = <bytes>, extensions = { "png" }? }.
Returns PluginHandle — The folder sink.
local frames = vfs.dirSink("/source/frames", { maxFiles = 240, maxBytes = 200 * 1024 * 1024, extensions = { "png" } })
typed/builtin//modules/api/engine/vfs/vfs/discardPlayShadow
vfs.discardPlayShadow() -> { discarded: { string }, owed: { { path: string, reason: string } } }
Throw away every play-shadow edit: the discard a play-exit takes when
the play session's work is not kept. Each path reverts to its pre-play
copy, as vfs.revertPlayShadow does. Every path it throws away is
returned in discarded, posted as a notice and logged by name. A path
whose pre-play copy cannot be put back yet (the world's blob, still
being pulled; the world's manifest row, read once the manifest has taken
the update it is applying; or a copy whose write back is refused) leaves
the play shadow all the same and is OWED: it holds the play bytes until
the copy lands and its write is taken, and the copy is put back then,
unless the path has changed in the meantime. Every owed path is returned
in owed, posted as a notice and logged by name. Calling it again asks
for every owed restore again, pulling a copy whose pull failed.
Returns { discarded: { string }, owed: { { path: string, reason: string } } } — discarded: every path the discard took off the play shadow, sorted, owed ones included. owed: every path it left owed, sorted by path, with why its restore has not landed; empty when every path reverted.
local result = vfs.discardPlayShadow()
for _, path in ipairs(result.discarded) do
print("discarded", path)
end
for _, owed in ipairs(result.owed) do
print(owed.path, owed.reason)
end
typed/builtin//modules/api/engine/vfs/vfs/durability
vfs.durability(paths: string | { string }, opts: VfsOpts?) -> Durability
Did that write save to disk, and if not how is it kept? What became of
the bytes just written at paths — one path, or an array of them
answered as ONE write. durable is true when they are where
the call filed them and the next session reads them back, and false when
the play shadow took any of them (live in this session and undone by a
guarded play-exit unless kept) or any of them is in /source/tmp/ scratch
(this session's working space: it reads back while the engine runs and is
gone when it stops or restarts, in edit mode and in play alike).
/source/local/ is durable: the machine keeps it. durable is
present whatever the answer is, so its absence is never a reading. A
non-durable answer carries survivesRestart (false whenever a
restart of this engine ends the bytes, as it does for the play shadow and
for scratch) and
warning (the state and what a restart does with it, for a reader
scanning values rather than checking a field; it opens with PLAY SESSION,
PLAY SHADOW or SCRATCH). When the shadow holds a path the answer also carries
playShadow (the routes to disk and what each costs a session other
people are running in) and shadowed (which of the given paths the shadow
has, or under pending would take); when a path is in scratch it carries
scratch (which of them are in scratch).
This is the answer, off the same shadow set and in the same words, that the
write_file / edit_file / capture tools attach to their own results and
that asset.create reports as its second return value. Ask it here at any
other site that lands files, so every write surface states where the bytes
went in one set of terms.
Parameters
pathsstring | { string }— One VFS path, or an array of paths answered together as one write. A path resolves the wayvfs.writeresolves its own — absolute or@-rooted as it stands, a bare one under/source/— so the answer is about the file that write landed. A value that is not a path — an AssetRef, a record, a number, a string with nothing in it — raises rather than being answered off the empty set it reads as; a list with no entries names nothing and answers durable.optsVfsOpts(optional) —{ root = "/source/", pending = false }.pending = trueasks the same question of a write that has NOT landed yet: where bytes written at these paths would go, read off the same play-lock verdict that will decide it. That is what a surface arranging a write it files later reports from —av.recordopens a take here and the film is written when the take ends — because until those bytes land the shadow is holding nothing under the path and the answer would be durable at the one moment the caller can still act on it. The fields and the words are the same either way; the state names the tense it is true in.
Returns Durability — { durable, survivesRestart?, warning?, playShadow?, shadowed?, scratch? }: survivesRestart and warning present exactly when durable is false, playShadow and shadowed when the play shadow holds a path, scratch when a path is in /source/tmp/, which reads back while the engine runs and is gone when it stops or restarts.
local ok = vfs.write(path, body)
local d = vfs.durability(path)
if not d.durable then log.warn(d.warning) end
local ahead = vfs.durability("/zero/source/clips/take.mp4", { pending = true })
typed/builtin//modules/api/engine/vfs/vfs/evict
vfs.evict(path: string, opts: VfsOpts?) -> boolean
Drop the in-memory bytes for path from the writable
MemFs layer without removing the asset. Use after processing
large binaries to reclaim RAM.
Parameters
pathstring— VFS path whose bytes should be evicted.optsVfsOpts(optional) —{ root = "/source/" }.
Returns boolean — True if MemFs bytes were dropped; false otherwise.
vfs.evict("/zero/source/textures/imported_big.png")
typed/builtin//modules/api/engine/vfs/vfs/exists
vfs.exists(path: string, opts: VfsOpts?) -> boolean
Is the path known to the VFS? Checks the Stage-1 metadata
(.meta sidecar / ManifestView) — NOT "are the bytes locally
cached?". Use vfs.read(path) ~= nil to confirm bytes are
reachable.
Parameters
pathstring— VFS path to check.optsVfsOpts(optional) —{ root = "/source/" }.
Returns boolean — True if the path is known regardless of byte cache state.
assert(vfs.exists("@builtin/models/Cube"))
typed/builtin//modules/api/engine/vfs/vfs/folderHashWalks
vfs.folderHashWalks() -> number
Lifetime count of category-folder checksum walks — the part of a write's cost that grows with how much content already exists. A folder's checksum is the tree hash over the descendants that describe the asset, so deriving one reads every key under it, and a write re-derives it for each enclosing category folder whose bytes that write reaches. Content the checksum is made of therefore moves this once per enclosing folder per write; bytes that reach no checksum — a managed sidecar, a scene's autosave overlay — move it by nothing. Read it around a burst to learn what that burst cost in walks, a number that reads the same on a loaded machine and a quiet one.
Returns number — Count of folder checksum walks this session. Monotonic.
local at = vfs.folderHashWalks()
vfs.write("/zero/source/scenes/probe.scene/scene_dirty/entities/e1.json", "{}")
print(vfs.folderHashWalks() - at)
typed/builtin//modules/api/engine/vfs/vfs/holdContentSync
vfs.holdContentSync(held: boolean)
Hold (true) or release (false) the content sync of the world this
engine binds. While it is held, a take of the world's content (the
initial sync a binding runs, or the one a session that lost its
connection runs when it subscribes again) applies no row: the rows the
backend sends wait unapplied, in order, and are applied the moment the
hold is released. The binding stands and writes to authored source are
taken and uploaded meanwhile, so the engine sits between binding a world
and being shown its content for as long as a test needs it there:
world.syncStatus() reads content_synced = false and
content_sync_held = true, and the world's load waits at its content
step. A take that already finished carries on applying live changes; the
hold stops the next take at its first row. A boot started with
--hold-content-sync (holdContentSync=1 in a browser launch) raises the
hold before the world binds, which is how the initial sync of a fresh
engine is held.
Parameters
heldboolean— True to hold the content sync, false to release it.
vfs.holdContentSync(true)
vfs.holdContentSync(false)
typed/builtin//modules/api/engine/vfs/vfs/holdFetch
vfs.holdFetch(path: string, held: boolean, opts: VfsOpts?) -> (boolean, string?)
Test support. Hold (held = true) the file at path in the state a
fetch of its bytes still on its way leaves it in, or land its bytes
(false), as that fetch completing does. While it is held the world
holds the path (vfs.exists answers true, and its identity and listing
stand) and its bytes have not arrived: vfs.read of it waits where the
reading code can yield and raises VFS_READ_CANNOT_WAIT where it cannot,
a vfs.readAsync of it settles once the bytes land, and an engine loader
that fetches the file receives them as its fetch would. It is the state a
browser engine holds every world file in between learning of the file and
its bytes arriving over the network, reached for a file only this
engine's memory holds (any file on an offline engine, and /source/tmp/
scratch on a world-bound one). A hold lasts until it is landed, until
the file is written, moved or removed (a write lands the bytes it
brings), or until the engine leaves the world it binds, which ends every
hold. Relative paths are resolved under opts.root (default '/source/').
Parameters
pathstring— The file whose bytes are held on their way, or landed.heldboolean— True to hold the bytes on their way, false to land them.optsVfsOpts(optional) — Options:{ root = '/source/' }.
Returns (boolean, string?) — true once the bytes are held (or landed); false and the reason for a sidecar, for a path already held, for a path whose bytes this engine does not hold in memory and for a path this world's content store holds as well, each left as it was; false and a reason when landing a path nothing holds.
local ok, why = vfs.holdFetch("/source/tmp/probe.texture/data.ztex", true)
typed/builtin//modules/api/engine/vfs/vfs/installedFrom
vfs.installedFrom(path: string, opts: VfsOpts?) -> InstalledFrom?
Where the asset holding path comes from, when the library
carries it by reference. The library's source then holds an install
record naming the asset, the world that published it and the commit
its bytes are, and the engine serves the asset's files from those.
path is the asset's own folder or anything inside it. Nil for a
path whose bytes the library or the world holds itself.
Parameters
pathstring— VFS path of the asset or of anything inside it.optsVfsOpts(optional) —{ root = "/source/" }.
Returns InstalledFrom? — The origin, or nil when the path is not inside an asset carried by reference.
local from = vfs.installedFrom(ref.path) if from then print(from.world, from.commit) end
typed/builtin//modules/api/engine/vfs/vfs/isDirectory
vfs.isDirectory(path: string, opts: VfsOpts?) -> boolean
Is ONE path a directory? Answers from reality — the writable
layer's children, a resolver-served folder listing, an explicit
empty-directory marker — so a loose file whose extension collides
with an assetType name (notes.json) reads as the file it is while
a real <name>.<type>/ folder reads as a folder. Costs the same
whatever the containing folder holds; use vfs.list when you want
every entry's kind, this when you hold one path.
Parameters
pathstring— VFS path to classify.optsVfsOpts(optional) —{ root = "/source/" }.
Returns boolean — True if the path is a directory.
if vfs.isDirectory("/zero/source/Goblin.dynamicAsset") then print("folder asset") end
typed/builtin//modules/api/engine/vfs/vfs/isSaveExcluded
vfs.isSaveExcluded(path: string, opts: VfsOpts?) -> boolean
Does this path hold content the machine keeps to itself?
/source/tmp/ is session scratch and /source/local/ is this
machine's own durable content — each directory itself included,
and everything under it. Both are writable, hot-reloadable and
enumerable like the rest of /source/; what separates them is
where they stop. The engine filters them out of every world save
and every peer broadcast, so they reach no world, carry no
manifest row there, and a staging verb handed one refuses it by
name. The match reads a whole path segment, so
/source/tmpfoo/ is ordinary content. Ask here whenever your
code has to agree with what a world can hold.
Parameters
pathstring— VFS path to classify.optsVfsOpts(optional) —{ root = "/source/" }.
Returns boolean — True when the path is held back from world saves and sync.
if not vfs.isSaveExcluded(p) then table.insert(publishable, p) end
typed/builtin//modules/api/engine/vfs/vfs/list
vfs.list(path: string?) -> { VfsListEntry }
List entries in a VFS directory. A directory whose current
listing the next frame assembles (/zero/runtime/sync/entities after a
stretch nothing read the replication surface) is waited for where the
calling code can yield (coroutine.isyieldable()), as vfs.read waits;
where it cannot, the listing raises VFS_READ_CANNOT_WAIT, naming the
path.
Parameters
pathstring(optional) — Directory path (defaults to/zero).
Returns { VfsListEntry } — Array of { name, isDirectory, path } tables; vfs.stat(entry.path) gives an entry's size and modification time.
for _, e in ipairs(vfs.list("/zero/source")) do print(e.name) end
typed/builtin//modules/api/engine/vfs/vfs/memResident
vfs.memResident() -> { { path: string, bytes: number, kind: string } }
List the MemFs entries that are NOT resident-by-default — the writable
in-memory layer's binary blobs and its large text files (text at or above
the inline-text size threshold). These are the bytes vfs.evict can
reclaim: the ones kept in RAM rather than left to fall through to the
on-disk BlobStore cache. Small text (resident by default) is omitted. The
audit counterpart to vfs.evict and to reading with { keep = true } —
use it to see what encoded bytes are held in RAM, and why.
Returns { { path: string, bytes: number, kind: string } } — Array of { path, bytes, kind }; kind is "binary" for non-text content and "large-text" for oversized text. Empty when the VFS isn't up.
for _, e in ipairs(vfs.memResident()) do print(e.path, e.bytes, e.kind) end
typed/builtin//modules/api/engine/vfs/vfs/mkdir
vfs.mkdir(path: string, opts: VfsOpts?) -> boolean
Create a directory. mkdir -p semantics — idempotent.
Errors if a file already exists at the same path. While play is
running an authored /source directory waits for the lock to
lift and the refusal RAISES with the reason; writing a file under
the path creates it as part of that write, and scratch under
/source/tmp/ creates as in edit mode.
Parameters
pathstring— Directory path.optsVfsOpts(optional) —{ root = "/source/" }.
Returns boolean — True if the directory exists after the call. A creation the running play session refuses raises with the whole reason.
vfs.mkdir("/zero/source/scenes/")
typed/builtin//modules/api/engine/vfs/vfs/move
vfs.move(src: string, dst: string, opts: { quiet: boolean? }?) -> (boolean, (WriteReport | string)?)
Move a file from src to dst. By default fires the destination's
write side effects; pass opts.quiet = true to suppress them. A quiet
move still returns the destination's report and still posts the resolve
rule the publish gate reads, which is what vfs.write does with the same
option: a publish takes no override, so the finding is stated at the line
that carries it.
While play is running a move takes the source away, so authored
/source content that predates play is refused and the refusal
RAISES with the reason; content this play session created moves and
stays tracked on the play shadow.
Parameters
srcstring— Source absolute VFS path.dststring— Destination absolute VFS path.opts{ quiet: boolean? }(optional) — Optional{ quiet: boolean? }.
Returns (boolean, (WriteReport | string)?) — True and a WriteReport on success. A move IS a write at its destination, so it reports what vfs.write reports for the same bytes at that path: where they went, and what the static passes read in the Luau among them, per landed leaf when the move took a folder. (false, errmsg) when the paths themselves refuse it. A move the running play session refuses raises with the whole reason instead, and so does a folder's move while another change holds a path inside either folder (a write, a sync applying a row, another folder's move or removal): nothing is moved, and the same call lands once that change completes.
vfs.move("/zero/source/a.luau", "/zero/source/b.luau")
local ok, report = vfs.move(mod .. "/init.luau", comp .. "/init.luau")
typed/builtin//modules/api/engine/vfs/vfs/movedReferenceNames
vfs.movedReferenceNames(path: string?, opts: VfsOpts?) -> { MovedReferenceSource }
The world sources that spell a reference by a name its target no
longer has. A source records, beside each name it uses, the guid of the
asset the name reached; when that asset later sits at another path (it
was moved, or the engine's library files it elsewhere), the reference
keeps resolving through the guid while the text keeps the old name. This
lists those sources and changes nothing. Writing an entry's currentText
back with vfs.write(source, currentText) brings the text up to date
without changing what any reference resolves to.
Only sources the world authors are considered: the engine library and
/source/deps/ keep the text they were published with.
Parameters
pathstring(optional) — One source to ask about; every source the world authors when absent.optsVfsOpts(optional) —{ root = "/source/" }.
Returns { MovedReferenceSource } — One entry per source holding moved names, in path order; empty when none does.
for _, s in ipairs(vfs.movedReferenceNames()) do print(s.source, #s.names) end
typed/builtin//modules/api/engine/vfs/vfs/mutationSeq
vfs.mutationSeq() -> number
Lifetime count of VFS mutations the engine has APPLIED — the drain's
clock. A write queues its side effects (an asset's content reload, the
assetType's onChange, a component or scene registration) and a later
frame runs them; this number advances as each one completes. Read it,
write, then poll for a larger value to learn the queue has moved past the
point you wrote at — instead of waiting a guessed number of frames. It
counts every mutation kind, so it answers about the pipeline rather than
about one file; asset.reloadSeq(ref) is the per-asset reading.
Returns number — Count of applied VFS mutations this session. Monotonic.
local at = vfs.mutationSeq()
vfs.write("/zero/source/tmp/note.txt", "hi")
repeat task.wait() until vfs.mutationSeq() > at
typed/builtin//modules/api/engine/vfs/vfs/open
vfs.open(path: string, opts: VfsOpts?) -> PluginHandle
A reader of the file at path, to pass a plugin in a call. The
plugin reads it by range and reaches nothing else through it; it is
refused, raising the reason, where this script could not read. A
reader whose file leaves its path answers the plugin that the asset
is gone.
Parameters
pathstring— The file to read.optsVfsOpts(optional) —{ root = "/source/" }.
Returns PluginHandle — The reader.
local weights = vfs.open(asset.containing(__FILE__).path .. "/weights.gguf")
typed/builtin//modules/api/engine/vfs/vfs/openDir
vfs.openDir(path: string, opts: VfsOpts?) -> PluginHandle
A reader of the folder at path and everything under it, to pass
a plugin in a call. The plugin lists it and opens readers of its files,
by paths relative to the folder that cannot leave it.
Parameters
pathstring— The folder to read.optsVfsOpts(optional) —{ root = "/source/" }.
Returns PluginHandle — The folder reader.
local model = vfs.openDir(asset.containing(__FILE__).path .. "/model")
typed/builtin//modules/api/engine/vfs/vfs/pendingWriteAuthors
vfs.pendingWriteAuthors() -> { [string]: { id: string, stable: string, connection: string, agent: string?, name: string?, account: string? } }
The caller behind each /source path vfs.pendingWrites lists: the
caller whose call made the newest local write or removal there, in the
shape vfs.currentAuthor answers. A path changed by work no caller was
attested for has no entry. world.vcsStatus reads it to name the writer of
each row it lists before the synced manifest records one.
Returns { [string]: { id: string, stable: string, connection: string, agent: string?, name: string?, account: string? } } — Map from VFS path to { id, stable, connection, agent, name, account }.
for path, by in pairs(vfs.pendingWriteAuthors()) do print(path, by.connection) end
typed/builtin//modules/api/engine/vfs/vfs/pendingWrites
vfs.pendingWrites() -> { string }
List the /source paths with a local write or removal the synced
manifest has not reflected yet: everything this client still owes the
server. A just-written or just-removed file appears here until its
upload round-trips and the synced dirty state catches up;
world.vcsStatus unions these so a fresh edit reads back as dirty
immediately, and world.syncStatus().owed_paths reports the same list.
Empty when fully synced.
Returns { string } — Array of VFS paths with a pending (unconfirmed) local write or removal.
for _, p in ipairs(vfs.pendingWrites()) do print(p) end
typed/builtin//modules/api/engine/vfs/vfs/playDiscardsOwed
vfs.playDiscardsOwed() -> { { path: string, reason: string } }
The play edits a discard threw away whose pre-play copy has not been put back yet. Each of these paths holds the play session's bytes until its restore lands, which happens on its own once the copy arrives and its write is taken. A path that changes first keeps its new content and leaves this list.
Returns { { path: string, reason: string } } — Every owed path, sorted by path, with why its restore has not landed.
for _, owed in ipairs(vfs.playDiscardsOwed()) do
print(owed.path, owed.reason)
end
typed/builtin//modules/api/engine/vfs/vfs/playHoldsInPlace
vfs.playHoldsInPlace(path: string, opts: VfsOpts?) -> boolean
Whether the running play session holds path where it stands:
vfs.move of it, and vfs.remove of it without durable = true, are
refused while play runs, because what they would take away is content
that predates play (or that a durable write made canonical). Content
only the play shadow holds (this play session wrote it) answers false and
moves freely, and so does every path once play ends or pauses, a path in
/source/tmp/ or /source/local/, and a path outside authored source.
Ask it before the first step of a change that ends by taking path
away, so a change the lock would refuse at its last step is not started:
the importers ask it before relocating a source into the asset they
produce, and owe the import until play ends.
Parameters
pathstring— The VFS path: absolute,@-rooted, or bare under/source/.optsVfsOpts(optional) —{ root = "/source/" }.
Returns boolean — True while a move or ambient removal of path would be refused.
if vfs.playHoldsInPlace(src) then log.warn(src .. " moves once play ends") end
typed/builtin//modules/api/engine/vfs/vfs/playShadowAuthors
vfs.playShadowAuthors() -> { [string]: { id: string, stable: string, connection: string, agent: string?, name: string?, account: string? } }
The caller behind each currently-shadowed /source path, in the
shape vfs.currentAuthor() answers in: the id the write was attributed
to, the name the world's roster holds for that caller now (agent, the
one to show), its account's username, and the ZeroMind account it
authenticated as. Several agents drive one engine at once and
every one of their in-play source edits sits in the same shadow set, so
this is how a review, a refusal or a verdict tells one agent's pending
work from another's. id names the calling session where the call
carried one, so two agent sessions on a machine linked to one ZeroMind
account are two authors. A path written by a caller the engine could not
name carries no entry, because it belongs to nobody in particular, and
stays settleable by anyone.
Returns { [string]: { id: string, stable: string, connection: string, agent: string?, name: string?, account: string? } } — Map of shadowed path to { id, stable, connection, agent, name, account }.
local mine = vfs.currentAuthor()
for path, who in pairs(vfs.playShadowAuthors()) do
if mine == nil or who.stable ~= mine.stable then print(path, "belongs to", who.agent or who.name) end
end
typed/builtin//modules/api/engine/vfs/vfs/playShadowPaths
vfs.playShadowPaths() -> { string }
Every source write made during play that is not durable yet — the set
to keep or discard before leaving play. Lists the /source paths edited
during running play that the play shadow holds, each beside the
pre-play copy a guarded discard puts back: the universal play
shadow-copy set. These are the in-play edits persist
promotes over the originals on confirm, or drops on a guarded discard.
Empty outside play or when nothing was edited.
Returns { string } — Array of normalized VFS paths currently shadowed.
for _, p in ipairs(vfs.playShadowPaths()) do print(p) end
typed/builtin//modules/api/engine/vfs/vfs/playShadowReceived
vfs.playShadowReceived() -> { [string]: { client: string, id: string?, stable: string?, connection: string?, agent: string?, name: string?, account: string? } }
The /source paths other clients of the play room sent this client,
each with the client it came from and, when the sender could be named,
its author in the shape vfs.playShadowAuthors() answers in. These edits
run here and the client that made them settles them, so they are in
neither vfs.playShadowPaths() nor vfs.playShadowAuthors(); leaving
play puts the pre-play copy back unless the sender promoted them.
Returns { [string]: { client: string, id: string?, stable: string?, connection: string?, agent: string?, name: string?, account: string? } } — Map of received path to { client, id, stable, connection, agent, name, account }.
for path, from in pairs(vfs.playShadowReceived()) do print(path, "came from", from.client) end
typed/builtin//modules/api/engine/vfs/vfs/promotePlayShadow
vfs.promotePlayShadow(path: string | { string }) -> ((string | { string })?, { string }, { string })
KEEP a source write made while play was running — the call that saves a play-mode edit onto disk and makes it durable. Promotes play-shadow edits into canonical writes: re-asserts the live overlay bytes through the full write pipeline, then unmarks each path. The bytes stay in the engine end to end, so binary content promotes exactly. It answers while play is RUNNING and leaves the mode, the clock and every shadow entry it did not name exactly where they stood. Takes ONE path, or an ARRAY of them — a single folder-asset write shadows the entry file, the README and the metadata together, so a slice is tens of paths, and naming them keeps the call to the caller's own work on an engine other sessions are running in. Every named path is attempted; one that refuses does not stop the ones after it. A path with nothing on the play shadow at it or beneath it settles nothing and raises nothing, since no play edit stands there: the third return value names it. A promotion that cannot happen raises with the reason: the path is a plain folder covering shadowed edits (the refusal names the first five assets and loose files under it by the paths that settle them, and counts the rest), the workspace is read-only, or the write-through failed. A shadow entry whose bytes are gone is dropped as promoted, so the path comes back with nothing written for it.
A folder asset is kept whole: a file of one promotes with every other
shadowed file of the same asset, so the files its type requires reach
source with whichever of them was named, and naming the folder asset's
own path (Gold.material, controls.inputMap) promotes every shadowed
file of it, the assets nested in it included. An asset nested inside another
settles with its own files, and takes the own files of every enclosing
asset the play session made with it, since it stands on source only
inside them. A path an earlier call settled, by name or carried this
way, answers as settled when it is named again, so a walk over a
vfs.playShadowPaths() snapshot one path at a time settles every path
in it.
Parameters
pathstring | { string }— A shadowed VFS path to promote, or an array of them (from vfs.playShadowPaths()).
Returns ((string | { string })?, { string }, { string }) — The path the call settled (nil when nothing was on the play shadow there), or the array of settled paths when an array went in; then the array of every path the call settled, a folder asset's carried files included; then the array of named paths that held nothing on the play shadow. None of the named paths are shadowed any more.
local promoted = vfs.promotePlayShadow("/zero/source/cover.jpg")
local _, settled = vfs.promotePlayShadow("/zero/source/Hero.module/init.luau")
local _, kept = vfs.promotePlayShadow("/zero/source/game/Gold.material")
local named, _, unshadowed = vfs.promotePlayShadow("/zero/source/maybe_written.md")
local mine = {}
for _, p in ipairs(vfs.playShadowPaths()) do
if string.find(p, "/zero/source/mine/", 1, true) == 1 then table.insert(mine, p) end
end
local settled = vfs.promotePlayShadow(mine)
typed/builtin//modules/api/engine/vfs/vfs/read
vfs.read(path: string, opts: VfsOpts?) -> (string?, string?)
Read a file from the virtual filesystem. Binary-safe.
Returns file contents as a string. A read that finds no bytes
returns nil and the reason: one sentence naming the path and why,
the text the read_file tool and the VFS HTTP route give for the
same path (/zero/source/a.txt: not found, a directory's refusal,
a /runtime node's account of what it holds). Handed straight to
another call, the read passes that reason on as the next argument
too; wrap it in parentheses, Json.decode((vfs.read(path))), to
pass the bytes alone. Relative paths resolve under opts.root
(default /source/). When the bytes aren't locally cached and the
calling code can yield (coroutine.isyieldable(): a task,
awake, start, update, onEnable, onOwnerChanged,
onSyncReceived, a replicated event's
handler), the read waits while the lazy fetch runs and answers
the bytes. Code that cannot yield (onDisable, onDestroy,
onPropertyChanged, a received synced-function call, a vfs.watch callback, a
module's top level while require runs it, a metamethod, a
table.sort comparator) cannot wait: a read there of bytes still on their
way (a file vfs.exists knows, a render surface being captured, a
/runtime/sync node whose current reading the next frame assembles)
raises VFS_READ_CANNOT_WAIT, naming the path and where to read it.
Parameters
pathstring— VFS path.optsVfsOpts(optional) —{ root = "/source/" }.
Returns (string?, string?) — File contents (binary-safe); nil and the reason (the path and why it holds no bytes to read) for a read that finds none.
local src, why = vfs.read("/zero/source/notes.txt"); if src == nil then print(why) end
typed/builtin//modules/api/engine/vfs/vfs/readAsync
vfs.readAsync(path: string, opts: VfsOpts?) -> string
Asynchronous binary-safe read. Returns a promise ID that resolves to the file contents. Useful for reading render textures from the main thread without blocking.
Parameters
pathstring— VFS path.optsVfsOpts(optional) —{ root = "/source/" }.
Returns string — Promise ID — pass to task.await().
local data = task.await(vfs.readAsync("/zero/runtime/screenshots/last.png"))
typed/builtin//modules/api/engine/vfs/vfs/readBounded
vfs.readBounded(path: string, maxBytes: number) -> (string?, string?)
Read a file from the virtual filesystem, at most maxBytes
long. Binary-safe, and read the way vfs.read reads it. A file
longer than maxBytes answers nil, "too_large"; where the layer
holding it states its length (a file held in memory, a synced or
staged file) its bytes are never read. Relative paths resolve under
/source/. Where the calling code can yield, a file whose bytes
are not cached is fetched and held to the same bound; where it
cannot, a known file whose bytes have not arrived raises
VFS_READ_CANNOT_WAIT, as vfs.read does. A read that finds no
bytes answers nil and the reason vfs.read gives.
Parameters
pathstring— VFS path.maxBytesnumber— The most bytes the read answers, a whole number 0 or more.
Returns (string?, string?) — File contents (binary-safe); nil and "too_large" for a file longer than maxBytes; nil and the reason vfs.read gives for a read that finds no bytes.
local raw, why = vfs.readBounded("/zero/source/notes.json", 65536)
typed/builtin//modules/api/engine/vfs/vfs/reload
vfs.reload(modulePath: string?) -> boolean
Clear entries from the require() cache so the next
require(name) re-runs the module's source. Pass a single
module identity to drop only that entry; call with no
arguments to drop every cached module of the world's own. A
module of the built-in library runs once for the process — its
body registers into registries that outlive it — and stands
through a reload with no argument.
The next require runs the source the module's file holds
when the reload is called, whichever write brought those bytes
there, a quiet one included.
Parameters
modulePathstring(optional) — Module identity to reload (omit to reload every module of the world's own).
Returns boolean — For a single identity, whether a module was cached under that name and has now been dropped — false says the name matched nothing. The no-arg form returns true.
vfs.reload("@mylib/utils.helpers")
typed/builtin//modules/api/engine/vfs/vfs/remove
vfs.remove(path: string, opts: VfsOpts?) -> (boolean, string?)
Remove a file. Refuses to remove directories unless
opts.recursive = true. Refuses protected system roots. While
play is running, authored /source content that predates play is
refused and the refusal RAISES with the reason; content this play
session created is removable, a folder included. Pass
opts.durable = true to say the removal IS a change to the source:
it takes the route edit mode takes with play still running and the
session still in play, the counterpart of
vfs.write(path, bytes, { durable = true }) for taking a path away
rather than replacing its bytes. Every other refusal stands in
either terms — a protected root, a read-only route, a plain
directory without recursive. A folder's removal (a composite asset,
or recursive = true) waits while another change holds a path inside
the folder (a write, a sync applying a row, another folder's move or
removal), and then removes the folder as that change left it.
Parameters
pathstring— VFS path to remove.optsVfsOpts(optional) —{ root = "/source/", recursive = false, durable = false }.
Returns (boolean, string?) — True on success; (false, errmsg) when the path itself refuses the removal. A removal the running play session refuses raises with the whole reason instead, so a pcall around the call reads it — and the lock answers ahead of whether the path is there, so a locked /source path raises whether or not it holds anything. A folder another change still holds a path inside after 30 seconds raises too, naming it, with nothing removed: the same call lands once that change completes.
vfs.remove("/zero/source/scratch.luau")
typed/builtin//modules/api/engine/vfs/vfs/revertPlayShadow
vfs.revertPlayShadow(path: string | { string }) -> ((string | { string })?, { string }, { string })
DISCARD a source write made while play was running, keeping nothing — the opposite of promoting it. Reverts play-shadow edits: restores the pre-play copy captured at the first play-mode write (the last edit-mode state, unstaged edits included) into the live slot — or remove the file when it did not exist at that moment — then unmark the path. Hot-reload picks the original back up, so the running session actually reverts. It answers while play is RUNNING and takes ONE path or an ARRAY of them, on the same terms as vfs.promotePlayShadow. A revert that cannot happen raises with the reason. A file of a folder asset reverts with every other shadowed file of the same asset, as a promotion carries them, and a file of an asset the play session made reverts with every shadowed file beneath it, the assets nested in it included. Naming the folder asset's own path reverts every shadowed file of it. A path with nothing on the play shadow settles nothing and raises nothing, as for vfs.promotePlayShadow. A path an earlier revert settled answers as settled when it is named again; one an earlier promotion settled raises, naming that promotion.
Parameters
pathstring | { string }— A shadowed VFS path to revert, or an array of them (from vfs.playShadowPaths()).
Returns ((string | { string })?, { string }, { string }) — The path that is now reverted (nil when nothing was on the play shadow there), or the array of reverted paths when an array went in; then the array of every path the call reverted, a folder asset's carried files included; then the array of named paths that held nothing on the play shadow. None of the named paths are shadowed any more.
local reverted = vfs.revertPlayShadow("/zero/source/Foo.component/init.luau")
local dropped = vfs.revertPlayShadow({ "/zero/source/a.md", "/zero/source/b.md" })
typed/builtin//modules/api/engine/vfs/vfs/sessionLost
vfs.sessionLost() -> boolean
Whether the live world session this engine established is lost and
reconnecting. While it is, every write this engine makes to authored
source (/source outside /source/tmp/) is refused, because the backend
of a dropped session can never receive it; the refusal names the
reconnect. It answers false again from the frame the session
re-establishes, and is false on an engine whose session never established
(an offline boot, or a world still binding) unless vfs.simulateSessionLoss
put it in that state. Ask it before, or after a
failure of, work that writes source in steps: the importers do, and owe
such an import until the session is back.
Returns boolean — True while writes to authored source are refused because the live session is lost.
if vfs.sessionLost() then log.warn("writes wait for the live session") end
typed/builtin//modules/api/engine/vfs/vfs/simulateFailedFetch
vfs.simulateFailedFetch(path: string, opts: VfsOpts?) -> (boolean, string?)
Test support. Put the file at path in the state a failed fetch of
its bytes leaves it in: the world holds the path (vfs.exists answers
true, and its identity and listing stand) and its bytes are not on this
engine, so vfs.read of it answers nil and the reason
<path>: this world holds the path, and its bytes are not on this engine.
It is the state a world session lands a file in when the fetch of its
bytes finds none upstream, reached for a file only this engine's memory
holds (any file on an offline engine, and /source/tmp/ scratch on a
world-bound one), so a test drives the readers that meet such a file. A
write of the path puts bytes there again. Relative paths are resolved
under opts.root (default '/source/').
Parameters
pathstring— The file whose bytes this engine stops holding.optsVfsOpts(optional) — Options:{ root = '/source/' }.
Returns (boolean, string?) — true once the bytes are gone; false and the reason for a sidecar, for a path whose bytes this engine does not hold in memory, for a path whose bytes another layer or the world's content store would still serve (a file this session synced to its world), and for a path nothing but its bytes states, each left as it was.
local ok, why = vfs.simulateFailedFetch("/source/tmp/probe.scene/scene.json")
typed/builtin//modules/api/engine/vfs/vfs/simulateSessionLoss
vfs.simulateSessionLoss(lost: boolean)
Put the VFS in the state a lost live session puts it in (true), or
take it out of it (false), without touching the connection:
vfs.sessionLost() answers it, and every write to authored source is
refused exactly as it is while a real session is reconnecting. Once a
live session has established, the engine's connection observer states
the real session every frame, so the simulation holds on an engine whose
live session never established (an offline boot), which is where a test
drives the paths that answer a lost session.
Parameters
lostboolean— True to refuse writes to authored source as a lost session does, false to accept them again.
vfs.simulateSessionLoss(true)
vfs.simulateSessionLoss(false)
typed/builtin//modules/api/engine/vfs/vfs/sink
vfs.sink(path: string, opts: SinkOpts) -> PluginHandle
A sink for the file at path, to pass a plugin in a call. The
plugin writes it from empty, up to opts.maxBytes, and the file lands
when the plugin closes the sink or drops it. Only the world's own files
take a sink.
Parameters
pathstring— The file to write.optsSinkOpts—{ maxBytes = <bytes> }, required.
Returns PluginHandle — The sink.
local out = vfs.sink("/source/imported/sphere.zvol", { maxBytes = 64 * 1024 * 1024 })
typed/builtin//modules/api/engine/vfs/vfs/stat
vfs.stat(path: string, opts: VfsOpts?) -> (VfsStat?, string?)
What is at path, how big it is and when it last changed, without
reading it. size is how many bytes vfs.read(path) returns: the
length the layer holding the file states (a file held in memory, a
synced or staged file), so a large file costs nothing to measure, and
where no layer states one (a runtime node, a built-in library file)
the length of the bytes this engine holds. It is absent for a directory
and for a file whose length nothing states and whose bytes are not on
this engine. modified is when this engine's copy last changed, in
seconds since the Unix epoch (the scale os.time() reads): the write
or arrival that put the current content there, which a move carries
along with the content. The memory layer
records it for every file whose bytes it holds: text up to the inline
size threshold, and everything on an engine with no world bound. It is
absent where no time is recorded: a directory nothing was written into
as such, a runtime node, and a file whose bytes the blob store holds
(binary content, and text past the inline size threshold, on a
world-bound engine). For a file, the shell's stat and ls -l print
the same size and time. A path nothing is at answers nil and the reason, the
sentence a vfs.read of it gives.
To tell whether a file changed without reading it: vfs.contentAddress(path)
names the bytes the blob store holds, and vfs.contentVersion(path)
moves on every change this session to a file the memory layer holds.
Parameters
pathstring— VFS path.optsVfsOpts(optional) —{ root = "/source/" }.
Returns (VfsStat?, string?) — The entry's description, or nil and the reason nothing is at the path.
local s = vfs.stat("/zero/source/scenes/main.scene/scene.json"); if s then print(s.size, s.modified) end
typed/builtin//modules/api/engine/vfs/vfs/unmarkPlayShadow
vfs.unmarkPlayShadow(path: string) -> boolean
Forget a single play-shadow path after it has been promoted (saved over source) or discarded. Tracking only — never touches the bytes.
Parameters
pathstring— VFS path to unmark.
Returns boolean — Always true.
vfs.unmarkPlayShadow("/zero/source/Foo.component/init.luau")
typed/builtin//modules/api/engine/vfs/vfs/unwatch
vfs.unwatch(watcherId: number) -> boolean
Remove a previously registered VFS watcher.
Parameters
watcherIdnumber— Watcher id returned byvfs.watch.
Returns boolean — True if the watcher was found and removed.
vfs.unwatch(id)
typed/builtin//modules/api/engine/vfs/vfs/watch
vfs.watch(path: string, callback: (string, string, string) -> ()) -> number
Register a callback that fires when a VFS path is written or
removed. Two match modes: exact, or folder/prefix (key ends with
/, and fires for any descendant). The callback runs in the VM
that registered it. Returns a watcher id for vfs.unwatch.
Parameters
pathstring— Exact path, or folder path ending in/.callback(string, string, string) -> ()—(mutated_path, kind, origin) -> (), kind"write"or"remove"; origin"local"for a change this engine made (throughvfs.*, the shell or any other surface) and"remote"for one that arrived from another participant in the world.
Returns number — Watcher id.
local id = vfs.watch("/zero/source/", function(path, kind, origin) print(kind, origin, path) end)
typed/builtin//modules/api/engine/vfs/vfs/write
vfs.write(path: string, content: string, opts: VfsOpts?) -> (boolean, (WriteReport | string)?)
Write content to a file. Binary-safe. Overwrites existing
files by default — pass opts.overwrite = false to refuse to
clobber. While play is running a /source write lands on the play
shadow: it succeeds and reads back, live in the session, and is
undone by a guarded play-exit unless accepted; the report's
survivesRestart says whether a restart keeps it. Scratch under /source/tmp/ writes through untouched,
in edit mode and in play, and is gone when the engine stops or restarts, so
its report says durable = false, survivesRestart = false and a warning
opening SCRATCH.
Pass opts.durable = true to say these bytes ARE the source: the
write reaches canonical /source with play still running and the
session still in play, hot-reloading the modules and components that
read it, so the edit is observed running in the same play session
with nothing left to promote. A durable write RAISES with the reason
when the bytes cannot become canonical source. One write carries at
most 256 MiB: longer content RAISES, naming its size and that limit,
and the path keeps what it held.
Parameters
pathstring— VFS path to write to.contentstring— File content (binary-safe).optsVfsOpts(optional) —{ root = "/source/", overwrite = true, quiet = false, durable = false }.
Returns (boolean, (WriteReport | string)?) — True and a WriteReport on success: durable says where the bytes went, with survivesRestart / warning / playShadow / shadowed beside it when the play shadow took them and survivesRestart / warning / scratch when they landed in /source/tmp/ scratch, diagnostics carries what the static passes read in the Luau it landed, and contentRequirements names what the asset it landed in must still say before the world publishes. It is the answer the MCP write_file tool gives for the same bytes at the same path. On failure returns false + error message; a durable write, and content past 256 MiB, raise instead of returning false.
vfs.write("/zero/source/notes.md", body)
local ok, report = vfs.write("/zero/source/game/Vent.component/init.luau", src)
if report.diagnostics then for _, d in report.diagnostics do print(d.severity, d.path, d.line, d.message) end end
if report.contentRequirements then for _, r in report.contentRequirements do print(r.path, r.detail) end end
if not report.durable then log.warn(report.warning) end
vfs.write("/zero/source/game/Vent.component/init.luau", src, { durable = true })
typed/builtin//modules/api/engine/video/video/create
video.create(url: string, options: VideoOptions?) -> string
Create a video player. Returns a texture handle (e.g.
"video_0") usable directly in material.setTexture() — its
frames sample like any other texture.
Parameters
urlstring— URL or asset path to an MP4 video file.optionsVideoOptions(optional) — Playback options:loop(default false),autoplay(default false),rate(default 1.0).
Returns string — Texture handle.
local tex = video.create("http://example.com/clip.mp4", { autoplay = true })
typed/builtin//modules/api/engine/video/video/destroy
video.destroy(handle: string) -> boolean
Destroy a video player and free the render target and all resources.
Parameters
handlestring— Video handle fromvideo.create.
Returns boolean — True if the player was found and destroyed.
video.destroy(rt)
typed/builtin//modules/api/engine/video/video/getInfo
video.getInfo(handle: string) -> VideoInfo?
Get video information and current playback state. codec is the
configuration the stream declares, such as "avc1.64002a", and
codecSupported is this host's answer about decoding it: true where it
has a decoder, false where it has none, and nil while the answer is
still being fetched. state reads "unsupported" for a stream this
host has no decoder for, with error naming the codec and what refused
it, and no frame is produced for it. decoder names what the stream
plays through once a decoder has opened it: "mediacodec" (the
device's own decoder) on Android, "webcodecs" (the browser's
VideoDecoder) in a browser, "mediafoundation" on Windows and
"openh264" (on the CPU) on Linux and macOS. The frame counts describe
playback since create: framesDecoded is how many frames the decoder
produced, framesPresented how many the player handed to its texture,
framesExpected how many frames the playback clock reached (one per
frame interval a tick landed in), and frameThreadDecodes how many
samples were decoded on the engine's frame thread rather than on the
decoder's own.
Parameters
handlestring— Video handle.
Returns VideoInfo? — { width, height, duration, currentTime, state, rate, loop, codec, codecSupported, decoder, error, framesDecoded, framesPresented, framesExpected, frameThreadDecodes } or nil if the handle is invalid.
local i = video.getInfo(rt); print(i.currentTime, "/", i.duration)
typed/builtin//modules/api/engine/video/video/pause
video.pause(handle: string) -> boolean
Pause video playback. Can be resumed with video.play.
Parameters
handlestring— Video handle.
Returns boolean — True if the video was playing and is now paused, or was still loading with a play carried and that play is withdrawn. False for a player that was not playing (ready, paused, ended, error, unsupported) and for a handle that names no player.
video.pause(rt)
typed/builtin//modules/api/engine/video/video/play
video.play(handle: string) -> boolean
Start or resume video playback.
Parameters
handlestring— Video handle fromvideo.create.
Returns boolean — True if the command was accepted: the player is loading (the play is carried until the load lands), ready, playing, paused or ended. False for a handle that names no player and for one in error or unsupported, which never plays.
video.play(rt)
typed/builtin//modules/api/engine/video/video/seek
video.seek(handle: string, time: number) -> boolean
Seek to a specific time (seconds) in the video.
Parameters
handlestring— Video handle.timenumber— Target time in seconds.
Returns boolean — True if the seek was accepted; false for a handle that names no player and for one in error or unsupported.
video.seek(rt, 30.5)
typed/builtin//modules/api/engine/video/video/setLoop
video.setLoop(handle: string, loop: boolean) -> boolean
Enable or disable looping.
Parameters
handlestring— Video handle.loopboolean— Whether to loop playback.
Returns boolean — True if the setting was applied.
video.setLoop(rt, true)
typed/builtin//modules/api/engine/video/video/setRate
video.setRate(handle: string, rate: number) -> boolean
Set the playback speed multiplier. 1.0 = normal, 2.0 = double speed, 0.5 = half speed.
Parameters
handlestring— Video handle.ratenumber— Playback rate.
Returns boolean — True if the rate was set.
video.setRate(rt, 2.0)
typed/builtin//modules/api/engine/video/video/stop
video.stop(handle: string) -> boolean
Stop video playback and reset to the beginning.
Parameters
handlestring— Video handle.
Returns boolean — True if the command was accepted; false for a handle that names no player and for one in error or unsupported.
video.stop(rt)
typed/builtin//modules/api/engine/xr/xr/aim
xr.aim() -> CameraAim
Where the game camera faces in a headset: "head" by default, or
"controller".
Returns CameraAim — The aim source.
print(xr.aim())
typed/builtin//modules/api/engine/xr/xr/body
xr.body() -> Body?
The local player's body and how the engine found it, in order: the
avatar the spawn system bound to the player (avatar), the entity the
game's camera follows (cameraFollow), the entity the player's character
controller moves (controller), whichever the game uses: the game's camera
follows it or a character controller the local player drives moves it. The
eyes sit in this body while the perspective is "embodied". Nil when the
game has no body to find (a game that plays from its own fixed camera, a
strategy or top-down camera over many units), where the game's camera is
the view. Found while a session draws frames in play mode.
Returns Body? — { entity, reason }, or nil at the floor.
local body = xr.body(); if body then print(body.entity, body.reason) end
typed/builtin//modules/api/engine/xr/xr/controller
xr.controller(hand: Hand) -> Controller?
What a hand controller's inputs read as of the frame last drawn. A hand
tracked without a controller is active, and its trigger is its pinch (1
while held). The sticks run -1 to 1 with y positive pushed away from the person;
trigger and squeeze run 0 to 1. primary is A on the right controller
and X on the left, secondary is B and Y, and menu is the left
controller's menu button. Where the controller is comes from
xr.pose(hand).
Parameters
handHand—"left_hand"or"right_hand".
Returns Controller? — The controller's inputs, or nil while no session holds input focus.
local c = xr.controller("right_hand"); if c and c.trigger > 0.8 then fire() end
typed/builtin//modules/api/engine/xr/xr/dominantHand
xr.dominantHand() -> Hand
The role of the hand whose controller points: "right_hand" by default.
Returns Hand — The dominant hand.
print(xr.dominantHand())
typed/builtin//modules/api/engine/xr/xr/enter
xr.enter()
Start a session now, on the active runtime, starting the runtime
when it is not running: what the VR button does. On an engine whose
policy is "off" it does nothing. The person's to do: a call from world
or agent code raises.
xr.enter()
typed/builtin//modules/api/engine/xr/xr/entry
xr.entry() -> Entry
How this engine comes to draw to a headset: its policy ("off",
"auto" or "always"), whether an OpenXR runtime is installed, its
runtime name and kind, whether it is running, and whether the person
left VR (declined).
Returns Entry — The entry.
local e = xr.entry(); if e.installed and e.running ~= "running" then print("the VR button starts", e.runtime) end
typed/builtin//modules/api/engine/xr/xr/exit
xr.exit()
Leave VR: the session ends on the next frame. On an engine with a
flat view to return to (xr.returnsToFlat()) the window or the page is
the view again, and the engine does not enter VR by itself again until
xr.enter() or the runtime starts anew; on a standalone headset app the
runtime ends the app, as the headset's own Quit does. The person's to do:
a call from world or agent code raises.
xr.exit()
typed/builtin//modules/api/engine/xr/xr/fade
xr.fade(opacity: number, seconds: number?, color: { number }?)
Run the veil over the person's whole view toward opacity (0 open, 1
closed) over seconds, in color ({ r, g, b }, 0..1). The world panels
stay readable over it, so a world can be taken down behind a closed view
while a panel says what comes next.
Parameters
opacitynumber— 0 (open) to 1 (closed).secondsnumber(optional) — How long the fade runs; 0 when omitted.color{ number }(optional) —{ r, g, b }; the colour the veil has when omitted.
xr.fade(1, 0.35)
typed/builtin//modules/api/engine/xr/xr/fadeState
xr.fadeState() -> Fade
The veil now: its opacity, the target it runs to, whether it has
arrived (done), its color and how many fades were asked for.
Returns Fade — The fade.
if xr.fadeState().done then print("arrived") end
typed/builtin//modules/api/engine/xr/xr/focused
xr.focused() -> boolean
Whether an XR session holds input focus, which is when the hand controllers drive the game's input. False with no session, while the system menu holds input, and while the headset is not worn.
Returns boolean — True while controller input flows.
if xr.focused() then showHandHints() end
typed/builtin//modules/api/engine/xr/xr/gestures
xr.gestures() -> Gestures
What the gestures of the bare hands read. The left palm facing the
person with a pinch holds the menu button (xr.controller("left_hand").menu),
a right-hand pinch-flick to the left or the right is one snap turn, and the
left hand pointing with a pinch held aims a teleport that lands when the pinch
opens. A pinch with the laser on an object grips it in the editor. Hand
tracking drives the gestures; a hand holding a controller makes none.
Returns Gestures — The gestures.
local g = xr.gestures(); if g.teleport.aiming then print(g.teleport.seconds) end
typed/builtin//modules/api/engine/xr/xr/hand
xr.hand(hand: Hand) -> HandPose?
The pose of a driven hand: its palm in world space and the direction each finger bone points along in the palm's frame, with its pinch and where its aim comes from. A controller's hand is modelled around its grip.
Parameters
handHand—"left_hand"or"right_hand".
Returns HandPose? — The hand's pose, or nil while nothing drives the hand.
local pose = xr.hand("left_hand"); if pose and pose.pinching then grab() end
typed/builtin//modules/api/engine/xr/xr/handSource
xr.handSource(hand: Hand) -> HandSource
What drives a hand now: "controller" while a controller is held in it,
"hand_tracking" while the runtime tracks the bare hand, "none" otherwise
and while no session holds input focus.
Parameters
handHand—"left_hand"or"right_hand".
Returns HandSource — The source.
if xr.handSource("right_hand") == "hand_tracking" then showPinchHint() end
typed/builtin//modules/api/engine/xr/xr/handTracking
xr.handTracking() -> HandTracking
What the runtime offers for tracking bare hands. Where it offers none,
reason says why and the controllers are the only hands.
Returns HandTracking — The hand tracking status.
if not xr.handTracking().available then print(xr.handTracking().reason) end
typed/builtin//modules/api/engine/xr/xr/joints
xr.joints(hand: Hand) -> HandJoints?
The 26 joints of a driven hand in world space, by name. They are the
runtime's wherever it locates the hand (modelled false) and the model's
around the controller's grip otherwise (modelled true).
Parameters
handHand—"left_hand"or"right_hand".
Returns HandJoints? — The joints, or nil while nothing drives the hand.
local tip = xr.joints("right_hand").joints.index_tip.position
typed/builtin//modules/api/engine/xr/xr/panels/autoHud
xr.panels.autoHud(enabled: boolean?) -> boolean
Whether the engine shows the world's HUD on the panel "hud". Pass a
boolean to turn that off or on.
Parameters
enabledboolean(optional) — Choose whether the HUD panel is made.
Returns boolean — Whether it is on.
xr.panels.autoHud(false)
typed/builtin//modules/api/engine/xr/xr/panels/create
xr.panels.create(description: PanelDescription)
Make a panel. screens lists the screens it shows, or space names a
space whose shown screens it shows; width and height are metres;
curve is the radius in metres of the cylinder it is bent around (0 is
flat); pose is where it stands, in the anchor space ("world";
"tracking" for a pose fixed to the room that follows the rig when the
game moves or turns the player; or "view" for a pose in the frame at the
head turned by the head's yaw and pitch and not its roll, so the panel
stands that far in front of where the person looks, easing towards that
place with a time constant of 0.12 seconds and standing there at once on a
recenter, when the session begins and when a script states its pose or
anchor); handle is { left, top, right, bottom }
in the panel's uv (0,0 top left): a press there reaches the panel's UI like
any press, and holds the panel once the laser has turned more than 6 degrees
from where the press began with the trigger held; the panel then follows the
laser until the trigger is released, turning to face the person, and the
stick pulls and pushes it. A press on the handle that is released before
the laser turned that far is a click, counted in the state's taps. resize makes a flat panel resizable: the
trigger pulled on a corner's zone drags that corner with the laser while the
opposite corner stays, within the stated minimum and maximum size, and the
panel keeps its points per metre, so a larger panel lays out more content.
passThrough lets the laser through a panel except over something its UI
can act on. keepsFocus leaves the keys where they are when the panel is
pressed: a text field holding the caret on another panel keeps it while
this panel's UI is used, the way an on-screen keyboard is; a press on any
other panel, or away from every panel, takes the caret from that field.
order stacks panels that overlap: a panel of a higher order is drawn
over one of a lower order and takes the laser wherever it covers it,
whatever their distances, and of panels of one order the nearer takes the
laser. A modal panel stands alone: while it is visible, every panel of a
lower order is neither drawn nor pointed at. Raises when a field is
invalid or the id is taken.
Parameters
descriptionPanelDescription— The panel'sidand fields.
xr.panels.create({ id = "stats", screens = { "stats_hud" }, width = 1.2, height = 0.7, pose = xr.panels.placement({ distance = 1.2 }), anchor = "tracking" })
typed/builtin//modules/api/engine/xr/xr/panels/drag
xr.panels.drag() -> PanelDrag?
The UI drag in flight on the panels: a widget with a dragPayload that
the trigger pulled. It reads the panel whose UI holds the drag, the
payload the source declared, the label its ghost reads, whether the laser
points at a panel now (overPanel) and the pointing hand. The reading
holds for as long as the trigger is held, wherever the laser points, and is
nil after the release, so a script places what the payload names where the
laser points at the world. A drag in the window reads through ui.dragState().
Returns PanelDrag? — The drag, or nil when no panel's UI holds one.
local d = xr.panels.drag(); if d and not d.overPanel then print("carrying", d.payload) end
typed/builtin//modules/api/engine/xr/xr/panels/grab
xr.panels.grab(id: string, options: PanelGrabOptions?)
Hold a panel with the pointing hand, which must be holding its trigger:
the panel follows the laser distance metres along it (default 0.8), its
centre offset from the held point in the panel's own axes, turning to face
the person, until the trigger is released; the stick pulls and pushes it. A
press the hand began on another panel ends there without a click. This is
how a panel made from a press on a widget (an entry in a list) is dragged out
and placed where the trigger is released. Raises when no panel has the id,
the trigger is not held, or a panel is already held.
Parameters
idstring— The panel's id.optionsPanelGrabOptions(optional) —{ distance?, offset? }.
xr.panels.grab("console", { distance = 0.8, offset = { x = 0, y = -0.2, z = 0 } })
typed/builtin//modules/api/engine/xr/xr/panels/hover
xr.panels.hover() -> PanelHover?
The panel the laser points at: its id, the uv on it (0,0 is the top
left), the distance along the laser, whether it is on the panel's grab
handle (onHandle) or a resize corner (onCorner), and the point in the world.
Returns PanelHover? — The hover, or nil when the laser points at no panel.
local h = xr.panels.hover(); if h then print(h.id, h.uv.u) end
typed/builtin//modules/api/engine/xr/xr/panels/list
xr.panels.list() -> { PanelDescription }
Every panel's description, in the order the panels were made.
Returns { PanelDescription } — The descriptions, each with the texture size of its picture in pixels.
for _, panel in xr.panels.list() do print(panel.id, panel.width, panel.height) end
typed/builtin//modules/api/engine/xr/xr/panels/placement
xr.panels.placement(options: PanelPlacementOptions?) -> Pose?
A pose for a "tracking" anchored panel in front of the person:
distance metres ahead (default 1.5), drop metres below eye height
(default 0.15), turned yaw degrees to the left (default 0), facing the
person. from names the head it is measured from: "recenter" (the
default), the head as it stood when the view was last recentered, or
"head", the head as it stands now. With atPointer = true the pose is
distance metres along the laser instead, facing the person.
Parameters
optionsPanelPlacementOptions(optional) —{ distance?, drop?, yaw?, from?, atPointer? }.
Returns Pose? — The pose, or nil until the first frame has been drawn, and with atPointer while nothing points.
local pose = xr.panels.placement({ distance = 1.2, yaw = 25 })
typed/builtin//modules/api/engine/xr/xr/panels/remove
xr.panels.remove(id: string) -> boolean
Remove a panel.
Parameters
idstring— The panel's id.
Returns boolean — Whether a panel was removed.
xr.panels.remove("stats")
typed/builtin//modules/api/engine/xr/xr/panels/state
xr.panels.state(id: string) -> PanelState?
What the laser and the hand are doing with a panel: whether it is
world (the pose the panel is drawn at in the world, nil before the first
frame has been routed and, for a panel anchored to the view, until a frame
that located the head has placed it), hovered (with the uv and distance of the laser on it), whether the
laser is onHandle, whether it is grabbed, how many grabs have ended
(grabs), how many presses on the handle ended as a click (taps), the turn
in degrees that makes a press on the handle a grab (grabAngle), how many
degrees the laser has turned since the press held on the panel began
(pressTurn, nil while none is held), whether the laser is on a resize corner (onCorner) or a resize
is running (resizing, with resizes counting those that ended), the panel
the laser pointed at when the last grab ended
(droppedOn), dropTarget, true while another panel is held and the
laser points at this one, and covered, true while a visible modal panel
of a higher order leaves this one undrawn.
Parameters
idstring— The panel's id.
Returns PanelState? — The state, or nil when no panel has the id.
local s = xr.panels.state("dock"); if s and s.hovered then print(s.uv.u, s.uv.v) end
typed/builtin//modules/api/engine/xr/xr/panels/update
xr.panels.update(id: string, fields: PanelFields)
Change fields of a panel. A field that is invalid raises and leaves the panel as it was.
Parameters
idstring— The panel's id.fieldsPanelFields— The fields to change; those ofxr.panels.create.
xr.panels.update("stats", { visible = false })
typed/builtin//modules/api/engine/xr/xr/perspective
xr.perspective() -> Perspective
What the person sees from in a headset: "embodied" seats the eyes in
the local player's body (at its head height, over its root, the real head
free on top, the body's head hidden from the eyes alone and its arms
following the hands), and "game" shows the game's own camera with the
head free. A world whose camera is first person is embodied; a world with
no body to find shows the game's camera; any other world is embodied
unless the person chose otherwise. The right thumbstick's click switches.
Returns Perspective — The perspective in force.
if xr.perspective() == "embodied" then print("in the body") end
typed/builtin//modules/api/engine/xr/xr/perspectiveStatus
xr.perspectiveStatus() -> PerspectiveStatus
Everything about the perspective: the one in force, the kept choice, whether the person can choose, why it is what it is, the body found, where the eyes stand, and how much of the body is hidden from the eyes or reaching for the hands.
Returns PerspectiveStatus — The status.
print(xr.perspectiveStatus().why)
typed/builtin//modules/api/engine/xr/xr/pointerRay
xr.pointerRay() -> PointerRay?
The ray the person points along, in world space: the aim pose of the
dominant hand, or of the other hand while the dominant one cannot be
located.
The engine's pointer hit (getPointerHitTable(), what a mouse hover resolves on desktop) is cast
along this ray while the session holds input focus, and the game's mouse
(input.snapshot().mouse_position) is the point it rests on, seen from the
game's camera; screenToRay at that position returns this ray.
Returns PointerRay? — { role, origin, direction }, or nil while no session holds input focus.
local ray = xr.pointerRay(); if ray then print(ray.role, ray.origin.x) end
typed/builtin//modules/api/engine/xr/xr/pose
xr.pose(role: Role, kind: PoseKind?) -> Pose?
The pose of the device holding role, in world space, as of the frame
last drawn: position in metres and rotation a quaternion. The pose
passes through the same rig as the eyes, so it moves and turns with the
game's camera. For a hand it is where the hand holds the controller, and
kind "aim" is where the controller points, along its -Z axis.
Parameters
roleRole—"head","left_hand"or"right_hand".kindPoseKind(optional) —"pose"(the default) or"aim".
Returns Pose? — The pose, or nil while the role's device is untracked or has no such pose.
local head = xr.pose("head"); if head then print(head.position.y) end
local aim = xr.pose("right_hand", "aim")
typed/builtin//modules/api/engine/xr/xr/pulse
xr.pulse(hand: Hand, amplitude: number, seconds: number, frequency: number?) -> boolean
Vibrate a hand controller. The pulse plays on the next frame. A request that is not a valid pulse raises; one that cannot play because no session holds input focus (or too many pulses are waiting) returns false and plays nothing.
Parameters
handHand—"left_hand"or"right_hand".amplitudenumber— Strength, 0 to 1.secondsnumber— Length in seconds, above 0 and up to 10.frequencynumber(optional) — Hertz; 0 or nil lets the runtime choose.
Returns boolean — Whether the pulse was accepted.
xr.pulse("right_hand", 0.6, 0.1) -- a short tap on the right hand
typed/builtin//modules/api/engine/xr/xr/recenter
xr.recenter()
Centre the headset's world on where the person stands and faces now,
on the next frame drawn; xr.recenters() rises by one.
xr.recenter()
typed/builtin//modules/api/engine/xr/xr/returnsToFlat
xr.returnsToFlat() -> boolean
Whether this engine has a flat view to return to when its session ends: a desktop window or a browser page. A standalone headset app (the Android engine in a headset) has none, so its menus offer Quit where a desktop offers Exit VR.
Returns boolean — True with a window or a page behind the headset.
if xr.returnsToFlat() then print("Exit VR goes back to the window") end
typed/builtin//modules/api/engine/xr/xr/roles
xr.roles() -> { Role }
The roles whose tracked device the runtime locates now, in the order
"head", "left_hand", "right_hand". The head is listed while a
session draws frames; a hand is listed while the session holds input
focus and its controller is located.
Returns { Role } — Array of role names; empty with no session.
for _, role in xr.roles() do print(role) end
typed/builtin//modules/api/engine/xr/xr/setAim
xr.setAim(aim: CameraAim) -> CameraAim
Choose where the game camera faces in a headset. "head" faces where
the head does; "controller" faces along the dominant hand's aim
direction with the head's up, so a game that aims, picks up or prompts
along its camera's forward does it where the controller points. A setting
of this client (xr.aim in the client settings): it holds across scene
loads and applies on the next frame.
Parameters
aimCameraAim—"head"or"controller".
Returns CameraAim — The canonical spelling of the aim now in force.
xr.setAim("controller")
typed/builtin//modules/api/engine/xr/xr/setDominantHand
xr.setDominantHand(hand: Hand) -> Hand
Choose the hand whose controller points. A setting of this client: it holds across scene loads.
Parameters
handHand—"left_hand"or"right_hand".
Returns Hand — The canonical spelling of the hand now in force.
xr.setDominantHand("left_hand")
typed/builtin//modules/api/engine/xr/xr/setPerspective
xr.setPerspective(perspective: Perspective) -> Perspective
Choose what the person sees from: the person's client setting
xr.perspective, the same in every world. A first-person world stays
embodied and a world with no body stays on the game's camera; the choice
is kept and applies where it can. The choice is the person's, made in the
client settings or by the right thumbstick's click: a call from world code
raises, and a world reads the choice with xr.perspective().
Parameters
perspectivePerspective—"embodied"or"game".
Returns Perspective — The perspective in force after the call.
xr.setPerspective("game")
typed/builtin//modules/api/engine/xr/xr/setPointerReach
xr.setPointerReach(distance: number?)
Say how far along the pointer ray the laser is drawn while a script
carries something to a point the engine's own cast does not know of (an
asset held under the laser): the beam ends distance metres out. The laser
over a panel still ends on the panel. Call it each frame it applies; nil
hands the beam back to the engine's cast.
Parameters
distancenumber(optional) — Metres along the ray, above 0, or nil.
xr.setPointerReach(where.distance)
typed/builtin//modules/api/engine/xr/xr/setSnapTurnDegrees
xr.setSnapTurnDegrees(degrees: number) -> number
Choose the angle one snap-turn step turns the view by, held to 10..180 degrees. The client settings apply the person's snap angle through it.
Parameters
degreesnumber— Degrees per step.
Returns number — The angle now in force.
xr.setSnapTurnDegrees(30)
typed/builtin//modules/api/engine/xr/xr/setTurnMode
xr.setTurnMode(mode: TurnMode) -> TurnMode
Choose how the right stick turns the view in a headset. A comfort setting of this client: it holds across scene loads, and a settings screen offering it is this call.
Parameters
modeTurnMode—"snap"or"smooth".
Returns TurnMode — The canonical spelling of the mode now in force.
xr.setTurnMode("smooth")
typed/builtin//modules/api/engine/xr/xr/setVignette
xr.setVignette(strength: number) -> number
Choose how dark the comfort vignette grows while the game moves the person. A comfort setting of this client.
Parameters
strengthnumber— 0 (none) to 1.
Returns number — The strength now in force.
xr.setVignette(0.5)
typed/builtin//modules/api/engine/xr/xr/snapTurnDegrees
xr.snapTurnDegrees() -> number
The angle one snap-turn step turns the view by, in degrees: the
person's snap angle (client setting xr.snapAngle), 45 by default.
Returns number — Degrees per step.
print(xr.snapTurnDegrees())
typed/builtin//modules/api/engine/xr/xr/tracked
xr.tracked(role: Role) -> boolean
Whether the runtime locates the device holding role now.
Parameters
roleRole—"head","left_hand"or"right_hand".
Returns boolean — True while the role's device is located.
if xr.tracked("left_hand") then showLeftHandHint() end
typed/builtin//modules/api/engine/xr/xr/turnMode
xr.turnMode() -> TurnMode
How the right stick turns the view in a headset. "snap" (the
default) turns by one step of xr.snapTurnDegrees() per flick of the
stick; "smooth" turns continuously in proportion to the stick's
deflection. Either way the game turns its own camera through its look
action and the headset follows the camera's yaw; the stick never tilts
the view, because the head owns pitch.
Returns TurnMode — The turn mode.
print(xr.turnMode())
typed/builtin//modules/api/engine/xr/xr/vignette
xr.vignette() -> number
How dark the comfort vignette grows at the edge of the view while the game moves or turns the person, 0 (none) to 1. How much of it shows follows how fast the person is moved or turned; a snap turn or a cut darkens nothing.
Returns number — The strength.
print(xr.vignette())
typed/builtin//modules/avatarAnimator/M/channelParameters
M.channelParameters(compiled: Compiled) -> { { name: string, type: string } }
The parameters the avatar channel carries for a compiled definition, in order: the
synced declared ones, then the owner-only built-ins the animator or the menu reads. Every
peer opens the channel with this list (multiplayer.setAvatarChannel).
Parameters
compiledCompiled— A compiled definition.
Returns { { name: string, type: string } } — { { name, type } }.
typed/builtin//modules/avatarAnimator/M/coerce
M.coerce(kind: string, value: any?) -> (boolean | number)?
Hold a value to a parameter type's range: a bool is a boolean, an int a whole number 0 to 255, a float a number -1 to 1. Numbers past either end are clamped.
Parameters
kindstring— "bool", "int" or "float".valueany(optional) — The value to hold.
Returns (boolean | number)? — The value the parameter takes, or nil when it is the wrong kind of value.
avatarAnimator.coerce("int", 300) -- 255
typed/builtin//modules/avatarAnimator/M/compile
M.compile(def: any?) -> Compiled
Compile a definition for new, raising with every problem named when it has any.
Parameters
defany(optional) — The avatar definition (avatar.jsonas a table).
Returns Compiled — The compiled definition.
local compiled = avatarAnimator.compile(avatarRef:definition())
typed/builtin//modules/avatarAnimator/M/compileWith
M.compileWith(def: any?, problems: { Problem }) -> Compiled
Compile a definition, appending every problem it finds to problems. The result is
usable as far as it is right; compile is the strict form.
Parameters
defany(optional) — The avatar definition.problems{ Problem }— The list the problems are appended to.
Returns Compiled — The compiled definition.
typed/builtin//modules/avatarAnimator/M/euler
M.euler(q: { number }) -> { number }
The Euler rotation (degrees about X, then Y, then Z) a quaternion { x, y, z, w }
turns by, the inverse of how a motion's rotation reads.
Parameters
q{ number }— The quaternion as an array{ x, y, z, w }.
Returns { number } — { x, y, z } in degrees.
local e = avatarAnimator.euler({ 0, 0.7071, 0, 0.7071 }) -- { 0, 90, 0 }
typed/builtin//modules/avatarAnimator/M/label
M.label(label: any?) -> string
The menu's label in the player's language: the text itself, or from
{ [localeTag] = text } the text for the player's locale, its language, English, then
any.
Parameters
labelany(optional) — A menu item's label.
Returns string — The text to show.
avatarAnimator.label({ en = "Hat", ["pt-BR"] = "Chapéu" })
typed/builtin//modules/avatarAnimator/M/new
M.new(compiled: any?) -> Animator
A running animator for a compiled definition: every parameter at its default, every
layer in its default state. :set a parameter, :step(dt) to advance and evaluate, or
:step(dt, now) to evaluate at now on a clock every peer shares (the session clock).
Parameters
compiledany(optional) — A compiled definition (compile), or the definition itself.
Returns Animator — The animator.
local a = avatarAnimator.new(avatarRef:definition()); a:set("Hat", false); local out = a:step(1/60)
typed/builtin//modules/avatarAnimator/M/quantize
M.quantize(value: number) -> number
The value a synced float carries on the avatar channel: -1 to 1 in steps of 1/127, the value every other peer reads. The owner holds a synced float at this value too, so the owner and every other peer evaluate the animator from the same number.
Parameters
valuenumber— A number -1 to 1.
Returns number — The number the channel carries.
avatarAnimator.quantize(0.5) -- 64/127
typed/builtin//modules/avatarAnimator/M/validate
M.validate(def: any?) -> { ok: boolean, problems: { Problem }, syncedBits: number, summary: { string } }
Check an avatar definition's parameters, animator and menu, naming every
problem by where it is (animator.layers[2].transitions[1].to). The synced parameters,
with every owner-only built-in the animator or the menu reads, fit in 256 bits or the
avatar is refused, the overrun stated.
Parameters
defany(optional) — The avatar definition (avatar.jsonas a table), or just the three blocks.
Returns { ok: boolean, problems: { Problem }, syncedBits: number, summary: { string } } — { ok, problems = { { path, message } }, syncedBits, summary }; summary is one line per problem.
local v = avatarAnimator.validate(avatarRef:definition()); print(v.ok, v.syncedBits)
typed/builtin//modules/bundle_update/M/installInto
M.installInto(bundle: BundleNamespace)
Install update onto the supplied bundle-shaped namespace.
The prelude calls this once at boot with the engine's bundle
global; users reach the result as bundle.update.
Parameters
bundleBundleNamespace— The target namespace table. No-op when given a non-table value.
require("@builtin::modules.bundle_update").installInto(bundle)
typed/builtin//modules/bundle_update/bundle/update
bundle.update(entityId: string, bundleRef: BundleRef?) -> any
Re-compose a bundle from an entity's current hierarchy and write
it back to the bundle's on-disk path. The VFS write triggers the
engine's generic asset hot-reload pipeline, which fires
onAssetReload(field) on every component subscribed to this
bundle's guid via a declared asset field — those components
reconcile per their own policy.
Parameters
entityIdstring— The entity whose hierarchy is captured into the bundle.bundleRefBundleRef(optional) — Optional. When omitted, the ref is inferred from the entity'sAsset.sourcefield. When given, the explicit ref wins.
Returns any — True on success (forwarded from the bundle assetType's :update).
bundle.update(entityId) -- infer from Asset
bundle.update(entityId, { guid = "..." }) -- explicit ref
typed/builtin//modules/colorSequence/M/deserialize
M.deserialize(data: any?) -> ColorSequenceObj
Rebuild a ColorSequence from a {kind = "ColorSequence", keypoints = {...}} payload produced by :serialize(). Used by scene save/load.
Parameters
dataany(optional) — The serialized payload.
Returns ColorSequenceObj — A fresh ColorSequenceObj with the deserialized keypoints.
local c = ColorSequence.deserialize(savedData)
typed/builtin//modules/colorSequence/M/new
M.new(...: any?) -> ColorSequenceObj
Construct a ColorSequence from a constant color (3-array {r,g,b} or {r=,g=,b=} record), a two-point lerp from c0 to c1, or a keypoints array. An entry of that array is a named { time =, value =, envelope? = } record, a { time, {r,g,b}, envelope? } pair, or a bare {r,g,b} colour whose time is its place in the list — so a list of colours is a ramp through them. envelope is optional and may be a single number (broadcast across channels) or a 3-array. Up to 64 keypoints; the first must anchor at time = 0, the last at time = 1. NaN / Inf rejected.
Parameters
...any(optional) —(color),(c0, c1), or({ keypoint, ... })where a keypoint is{time =, value =, envelope? =},{time, {r,g,b}, envelope?}, or{r,g,b}.
Returns ColorSequenceObj — A ColorSequenceObj with :evaluate, :sample, :keypoints, :duration, :serialize, :destroy.
local solid = ColorSequence.new({ 1, 0.5, 0.25 })
local fade = ColorSequence.new({ 1, 1, 1 }, { 0, 0, 0 })
local bow = ColorSequence.new({ { time = 0, value = {1,0,0} }, { time = 0.5, value = {0,1,0} }, { time = 1, value = {0,0,1} } })
local stops = ColorSequence.new({ { 0, {1,0,0} }, { 1, {0,0,1} } })
local ramp = ColorSequence.new({ { 1, 0.85, 0.35 }, { 1, 0.35, 0.05 } })
typed/builtin//modules/component_field_route/M/componentRef
M.componentRef(entityId: string, component: string) -> ComponentRef?
The component ref serving component on entity, or nil when the
entity is gone or does not carry it.
Parameters
entityIdstring— The entity id.componentstring— The component name.
Returns ComponentRef? — The component ref, or nil.
local ref = Route.componentRef(id, "Model")
typed/builtin//modules/component_field_route/M/declaredFields
M.declaredFields(ref: ComponentRef) -> { [string]: boolean }
The public and private field names ref declares, as a set.
Parameters
refComponentRef— A component ref.
Returns { [string]: boolean } — { [fieldName] = true }.
local names = Route.declaredFields(ref)
typed/builtin//modules/component_field_route/M/isReflected
M.isReflected(component: string) -> boolean
Whether component is backed by an engine struct the reflect registry
resolves. A component declared in Luau answers false and is served by
the component ref instead.
Parameters
componentstring— The component name.
Returns boolean — true when the reflect registry holds this component.
if Route.isReflected("Transform") then ... end
typed/builtin//modules/component_field_route/M/readField
M.readField(api: string, entityId: string, component: string, field: string) -> any
Read one component field, through whichever route serves it.
Parameters
apistring— The calling API, named in any diagnostic.entityIdstring— The entity id.componentstring— The component name.fieldstring— The field name.
Returns any — The field value, or nil when the entity, the component or the field is missing.
local blend = Route.readField("Entity.getField", id, "Model", "tintBlend")
typed/builtin//modules/component_field_route/M/reportEntitiesWithoutComponent
M.reportEntitiesWithoutComponent(api: string, component: string, missing: number, total: number, outcome: string)
Report the entities of one call that do not carry the named component, as a single line for the call rather than one per entity.
Parameters
apistring— The calling API, named in the line.componentstring— The component name.missingnumber— How many of the named entities do not carry it.totalnumber— How many entities the call named.outcomestring— What the call did for them, e.g."nothing written".
Route.reportEntitiesWithoutComponent("entity.batchWrite", "Model", 3, 8, "nothing written")
typed/builtin//modules/component_field_route/M/reportEntityWithoutComponent
M.reportEntityWithoutComponent(api: string, entityId: string, component: string, outcome: string)
Report one entity that does not carry the named component, at most
once per interval per (api, component).
Parameters
apistring— The calling API, named in the line.entityIdstring— The entity that does not carry it.componentstring— The component name.outcomestring— What the call did instead, e.g."nothing written".
Route.reportEntityWithoutComponent("Entity.setField", id, "Model", "nothing written")
typed/builtin//modules/component_field_route/M/reportMissingField
M.reportMissingField(api: string, component: string, field: string, outcome: string)
Report a field the component does not declare, at most once per
interval per (api, component, field).
Parameters
apistring— The calling API, named in the line.componentstring— The component name.fieldstring— The field name that resolved to nothing.outcomestring— What the call did instead, e.g."nothing written".
Route.reportMissingField("entity.batchWrite", "Model", "tintBlnd", "nothing written")
typed/builtin//modules/component_field_route/M/requireComponentType
M.requireComponentType(api: string, component: string)
Raise unless component names a component this engine knows — either
an engine struct in the reflect registry or a declared .component.
Parameters
apistring— The calling API, named in the error so the message points at the call.componentstring— The component name to check.
Route.requireComponentType("entity.batchWrite", "Model")
typed/builtin//modules/component_field_route/M/writeField
M.writeField(api: string, entityId: string, component: string, field: string, value: any?) -> boolean
Write one component field, through whichever route serves it.
Parameters
apistring— The calling API, named in any diagnostic.entityIdstring— The entity id.componentstring— The component name.fieldstring— The field name.valueany(optional) — The value to write.
Returns boolean — true when the write landed.
Route.writeField("Entity.setField", id, "Model", "tintBlend", 0.5)
typed/builtin//modules/component_proxy/M/computed
M.computed(fn: (any) -> any) -> string
Mark a function as a computed property. The function takes
self (the proxy) and returns the computed value. Returns a string
sentinel that the Rust-side public_index dispatches through the
registry on every read.
Parameters
fn(any) -> any— The getter — receives the proxy and returns the computed value.
Returns string — The sentinel string to store in the proxy's public table.
public.area = computed(function(self) return self.w * self.h end)
typed/builtin//modules/component_proxy/M/installGlobal
M.installGlobal()
Install computed as a global so component modules can write
public.X = computed(fn) without an explicit require. Called by the
prelude.
require("@builtin::modules.component_proxy").installGlobal()
typed/builtin//modules/component_proxy/M/isComputedSentinel
M.isComputedSentinel(v: any?) -> boolean
True iff v is a computed-property sentinel — the string a
computed(fn) declaration stores in a proxy's public table. Reads
of the property resolve the sentinel to the getter's value, but a raw
pairs() over the backing table yields the sentinel itself. Serializers
call this to skip computed (derived) fields, which are re-derived on load.
Parameters
vany(optional) — The value to test.
Returns boolean — true for a computed sentinel, false otherwise.
typed/builtin//modules/connected_users/connectedUser/agents
connectedUser.agents -> { { name: string, harness: string, since: number, lastCall: number, isLocal: boolean } }
The agents working for this user, since / lastCall in ms since the Unix epoch.
Returns { { name: string, harness: string, since: number, lastCall: number, isLocal: boolean } }
typed/builtin//modules/connected_users/connectedUser/data
connectedUser.data -> { [string]: any }
This user's per-player runtime-data store, bound to their identity.
Returns { [string]: any }
typed/builtin//modules/connected_users/connectedUser/displayName
connectedUser.displayName -> string
This user's human-readable name, falling back to their identity. On an agent's sub-client the local user goes by the agent's name with the person it works for in parentheses.
Returns string
typed/builtin//modules/connected_users/connectedUser/engines
connectedUser.engines -> { { sessionId: string, profile: string, branch: string?, since: number } }
The engines this user is connected through, since in ms since the Unix epoch.
Returns { { sessionId: string, profile: string, branch: string?, since: number } }
typed/builtin//modules/connected_users/connectedUser/entity
connectedUser.entity -> entityRef?
This user's world-presence body: the avatar bound to them in the active scene, resolved on access.
Returns entityRef?
typed/builtin//modules/connected_users/connectedUser/identity
connectedUser.identity -> string
This user's account id, the sub claim of their session JWT.
Returns string
typed/builtin//modules/connected_users/connectedUser/isLocal
connectedUser.isLocal -> boolean
Whether this record is the user signed in on this engine.
Returns boolean
typed/builtin//modules/connected_users/connectedUsers/agents
connectedUsers.agents() -> { { name: string, harness: string, person: string, lastCall: number } }
Every agent on the world, sorted by person then name.
Returns { { name: string, harness: string, person: string, lastCall: number } }
typed/builtin//modules/connected_users/connectedUsers/count
connectedUsers.count() -> number
How many users are connected.
Returns number
typed/builtin//modules/connected_users/connectedUsers/exists
connectedUsers.exists(identity: string) -> boolean
Whether a user carrying an identity is connected.
Parameters
identitystring
Returns boolean
typed/builtin//modules/connected_users/connectedUsers/get
connectedUsers.get(identity: string) -> connectedUser?
The user carrying an identity, or nil when nobody connected carries it.
Parameters
identitystring
Returns connectedUser?
typed/builtin//modules/connected_users/connectedUsers/list
connectedUsers.list() -> { connectedUser }
Every connected user, ordered by identity.
Returns { connectedUser }
typed/builtin//modules/connected_users/connectedUsers/localUser
connectedUsers.localUser -> connectedUser?
The user signed in on this engine, re-read on each access; nil for an anonymous session.
Returns connectedUser?
typed/builtin//modules/connected_users/connectedUsers/offConnect
connectedUsers.offConnect(handle: number) -> boolean
Drop a connect subscription by its handle. True when a live subscription carried it.
Parameters
handlenumber
Returns boolean
typed/builtin//modules/connected_users/connectedUsers/offDisconnect
connectedUsers.offDisconnect(handle: number) -> boolean
Drop a disconnect subscription by its handle. True when a live subscription carried it.
Parameters
handlenumber
Returns boolean
typed/builtin//modules/connected_users/connectedUsers/offLocalConnect
connectedUsers.offLocalConnect(handle: number) -> boolean
Drop a local-connect subscription by its handle. True when a live subscription carried it.
Parameters
handlenumber
Returns boolean
typed/builtin//modules/connected_users/connectedUsers/onConnect
connectedUsers.onConnect(callback: (connectedUser) -> ()) -> number
Run a callback each time a user connects. Answers the handle offConnect takes.
Parameters
callback(connectedUser) -> ()
Returns number
typed/builtin//modules/connected_users/connectedUsers/onDisconnect
connectedUsers.onDisconnect(callback: (connectedUser) -> ()) -> number
Run a callback each time a user disconnects. Answers the handle offDisconnect takes.
Parameters
callback(connectedUser) -> ()
Returns number
typed/builtin//modules/connected_users/connectedUsers/onLocalConnect
connectedUsers.onLocalConnect(callback: (connectedUser) -> ()) -> number
Run a callback once the local user's session is established, firing immediately when it already is.
Parameters
callback(connectedUser) -> ()
Returns number
typed/builtin//modules/content_version/M/bump
M.bump(path: string)
Bump path's version counter, invalidating every reader memoized
against its previous value. Called by the vfs.* write surface and the
asset-change dispatcher; content code rarely calls it directly.
Parameters
pathstring— VFS path whose content changed.
require("@builtin::modules.content_version").bump(p)
typed/builtin//modules/content_version/M/get
M.get(path: string) -> number
The current version counter for path (0 if no VM ever wrote it).
A memoized reader stores the value it saw when it parsed, and treats a
later call as a cache hit exactly while get(path) still returns it.
Parameters
pathstring— Normalized VFS path.
Returns number — The path's current version counter.
local v = require("@builtin::modules.content_version").get(p)
typed/builtin//modules/debris/M/add
M.add(id: any?, lifetime: number?) -> DebrisHandle
Schedule the entity for despawn after lifetime seconds (default 10). Calling again on the same entity replaces the prior deadline. Negative or zero lifetime despawns immediately. Returns a handle for cancel(), or 0 if the entity id couldn't be resolved.
Parameters
idany(optional) — Entity id, name, or proxy table.lifetimenumber(optional) — Seconds before despawn — defaults to 10 when nil.
Returns DebrisHandle — Cancel handle (0 if entity not found).
local bullet = entity.spawn("Bullet"); debris.add(bullet.id, 2.0)
local h = debris.add(target.id, 5); debris.cancel(h)
typed/builtin//modules/debris/M/cancel
M.cancel(handleOrId: any?) -> boolean
Cancel a pending despawn. Accepts either a handle from debris.add or an entity id / proxy. Returns true if a pending record was actually removed.
Parameters
handleOrIdany(optional) — Cancel handle, or entity id / name / proxy.
Returns boolean — Whether a pending record was removed.
debris.cancel(handle); debris.cancel(target.id)
typed/builtin//modules/debris/M/clear
M.clear() -> boolean
Drop every pending entry. Used by the test suite to isolate cases — not part of the user-facing surface.
Returns boolean — Always true.
typed/builtin//modules/debris/M/count
M.count() -> number
Number of currently pending debris entries — handy for diagnostics overlays.
Returns number — Pending count.
print(debris.count(), "pending despawns")
typed/builtin//modules/debris/M/list
M.list() -> { DebrisEntry }
Snapshot every pending entry as a flat array of {id, remainingSecs, handle} records. Order is not stable — don't rely on it.
Returns { DebrisEntry } — Array of pending entries.
for _, e in debris.list() do print(e.id, e.remainingSecs) end
typed/builtin//modules/debris/M/pending
M.pending(id: any?) -> number?
Return the number of seconds remaining before the entity is despawned, or nil if it isn't scheduled.
Parameters
idany(optional) — Entity id, name, or proxy.
Returns number? — Seconds remaining, or nil.
local s = debris.pending(bullet.id); if s then print("dies in", s) end
typed/builtin//modules/deprecated/zui/theme/M/activate
M.activate(name: string) -> boolean
Activate a registered theme. Thin wrapper over ui.setTheme(name)
for symmetry with register / load.
Parameters
namestring— The registered theme name to activate.
Returns boolean — true on success, false when name is invalid or the FFI binding is missing.
Theme.activate("dark")
typed/builtin//modules/deprecated/zui/theme/M/defaults
M.defaults() -> TokenMap
Return the raw fallback token map shipped with this module. Used by tests / introspection; not part of the cascade.
Returns TokenMap — The static DEFAULTS table — same reference each call.
local d = Theme.defaults()
typed/builtin//modules/deprecated/zui/theme/M/load
M.load(name: string) -> (boolean, string?)
Convenience: require("@builtin::themes." .. name) then register.
Built-in themes (dark, light, debug) live at
src/lua/lib/themes/<name>.module/init.luau.
Parameters
namestring— The built-in theme name to require and register.
Returns (boolean, string?) — (true, nil) on success, (false, errMsg) on require / register failure.
Theme.load("dark")
typed/builtin//modules/deprecated/zui/theme/M/register
M.register(name: string, theme: any?) -> (boolean, string?)
Register a theme with the engine under name. Walks the theme's
tokens + styles, resolves every $variable reference (with cycle
detection), and pushes flat values to the active ThemeRegistry.
Parameters
namestring— The name to register the theme under.themeany(optional) — The theme table{ tokens, styles }—nameis overridden by the caller-suppliedname.
Returns (boolean, string?) — (true, nil) on success, or (false, errMsg) on cascade error or missing FFI binding.
local ok, err = Theme.register("dark", themeTable)
typed/builtin//modules/deprecated/zui/theme/M/resolve
M.resolve(theme: any?) -> (ResolvedTheme?, string?)
Resolve $variable references in a theme table and return the
flat { name, tokens, styles } shape the engine consumes. Pure
function — used by register and exposed for tests.
Parameters
themeany(optional) — A theme table withname,tokens,styles.
Returns (ResolvedTheme?, string?) — (resolved, nil) on success or (nil, errMsg) on cascade failure.
local res, err = Theme.resolve({ name = "dark", tokens = {...} })
typed/builtin//modules/deprecated/zui/theme/M/tokenNames
M.tokenNames() -> { string }
Return the sorted list of token names shipped with this module. Useful for theme editors / token pickers.
Returns { string } — Sorted array of token name strings.
for _, n in ipairs(Theme.tokenNames()) do print(n) end
typed/builtin//modules/deprecated/zui/theme/M/with
M.with(overrides: TokenMap?) -> ThemeView
Build a read-only theme view that overlays the given overrides on top of the engine-or-defaults token map. Module functions are exposed alongside tokens so the view doubles as the namespace.
Parameters
overridesTokenMap(optional) — Optional table of{ [tokenName] = value }overrides.
Returns ThemeView — A read-only view — index returns override / function / token.
local view = Theme.with({ accent = "#ff0" })
local view = Theme.with(nil) -- defaults only
typed/builtin//modules/deprecated/zui/theme/cascade/M/resolveStyles
M.resolveStyles(theme: any?, resolvedTokens: any?) -> (StyleMap?, string?)
Walk theme.styles and resolve every $reference inside style
values against resolvedTokens. Returns a { [selector]: { [prop]: value } } map with no remaining $variable strings. Selector and
property keys pass through unchanged (cascade ordering is the
caller's concern).
Parameters
themeany(optional) — A theme-shaped table with astylesfield.resolvedTokensany(optional) — Pre-flattened tokens (output ofresolveTokens).
Returns (StyleMap?, string?) — (flatStyles, nil) on success or (nil, errMsg) on first cycle / unknown reference.
local styles, err = Cascade.resolveStyles({ styles = { ["btn"] = { color = "$accent" } } }, tokens)
typed/builtin//modules/deprecated/zui/theme/cascade/M/resolveTokens
M.resolveTokens(theme: any?) -> (TokenMap?, string?)
Walk theme.tokens and resolve every $reference to a literal.
Tokens that reference other tokens are flattened — after this pass,
every value is a literal string / number / etc.
Parameters
themeany(optional) — A theme-shaped table with atokensfield.
Returns (TokenMap?, string?) — (flatTable, nil) on success or (nil, errMsg) on first cycle / unknown reference. Errors include the offending key for debugging.
local tokens, err = Cascade.resolveTokens({ tokens = { a = "$b", b = "#fff" } })
typed/builtin//modules/deprecated/zui/widget/canvas/canvas
canvas(id: string?, opts: CanvasOpts?) -> any
Build a 2D-paint canvas widget. The widget body is a list of paint commands (line, bezier, polyline, rect, circle, text) drawn in widget-local coords. Pointer/keyboard/scroll handlers are wired through as engine props.
Parameters
idstring(optional) — Widget id used by the engine for event routing and DOM mirror.optsCanvasOpts(optional) — Options table — commands array plus optional width/height, interaction handlers, role/tag overrides, ARIA passthroughs (anyaria*key), and a style table.
Returns any — A widget node consumable by the renderer.
canvas("my-canvas", { commands = { { kind = "circle", center = {50,50}, radius = 20, fill = "#FF8855" } } })
canvas("plot", { commands = {}, onDrag = "plot:drag", style = { width = 400, height = 200 } })
typed/builtin//modules/deprecated/zui/widget/node/node
node(widgetType: string, opts: Opts?, children: any?) -> any
Build a generic widget table with optional id, classes, props,
style, and children. The constructor every zui widget composes on.
Accepts either a single child or an array of children — single
children get wrapped automatically, matching the scroll.module
precedent.
Parameters
widgetTypestring— The widget kind string (e.g."label","panel","canvas").optsOpts(optional) — Optional.id,classes(orclass),props,style.childrenany(optional) — Optional widget table or array of widget tables.
Returns any — The widget table — interoperable with hand-written trees.
local n = node("label", { props = { text = "Hi" } })
local n = node("panel", { id = "p1" }, { childWidget })
typed/builtin//modules/entity_hierarchy/M/swap
M.swap(entityId: string, assetPath: string, opts: SwapOpts?) -> (string?, string?)
Replace a blockout entity with a generated/imported asset, fitting the asset to the source's bounds and inheriting the source's world rotation. The new entity is reparented to the source's parent, optionally inherits the source name, and the original is despawned.
Parameters
entityIdstring— The entity to replace (must exist). Must be a non-empty string.assetPathstring— The asset path to spawn. Must be a non-empty string.optsSwapOpts(optional) — OptionalSwapOpts. Fields:fit("bounds"default |"bounds_xy"|"none"),source_origin("bottom"default |"center"|"top"),asset_origin(same set),keep(e.g.{"name"}),timeout(optional seconds override for the async asset-bounds wait; default is a generous load-scaled poll budget — leave unset).
Returns (string?, string?) — (newEntityId, nil) on success; (nil, errmsg) on failure (invalid args, missing source, asset bounds timeout).
local id, err = EntityHierarchy.swap("blockout", "@builtin::meshes.cube")
local id, err = EntityHierarchy.swap("blockout", asset, { fit = "bounds_xy", keep = { "name" } })
typed/builtin//modules/entity_records/M/addData
M.addData(data: any?, instanceName: string?) -> any
The data table component.add puts a record's instance back with:
data itself for the anonymous instance, and a copy carrying name for a
named one, which is the key component.add reads the instance name from.
Parameters
dataany(optional) — The entry's field values.instanceNamestring(optional) — The entry's instance name, or nil for the anonymous instance.
Returns any — The table to pass to component.add.
entity(id).component.add("Pool", EntityRecords.addData({ amount = 120 }, "mana"))
typed/builtin//modules/entity_records/M/authoredComponentData
M.authoredComponentData(rid: string, componentType: string, instanceName: string?, data: any?) -> any
A component instance's snapshot with the fields the instance wrote about its own runtime removed, leaving what states how it was CONFIGURED. A capture reads it to build the record, and whoever diffs a live entity against that record reads it too, so both sides speak the same fields.
Parameters
ridstring— Runtime entity id carrying the instance.componentTypestring— Component type name as the entity reports it.instanceNamestring(optional) — Name of the instance, or nil for an anonymous one.dataany(optional) — Snapshot of the instance's public data.
Returns any — The snapshot without the instance's own runtime bookkeeping.
local d = EntityRecords.authoredComponentData(id, ty, nil, snapshot)
typed/builtin//modules/entity_records/M/captureRecord
M.captureRecord(rid: string, parentOriginalId: string?, opts: { codeAttached: boolean? }?) -> any
Capture ONE entity into a template record. Reads LIVE component public
state (serialized component snapshots), not init data, so the record
matches what is on screen, and states the fields each instance's
configuration states (configuredFields): a field left to its declared
default stays out, so a later change to that default reaches whatever the
record rebuilds. Each component INSTANCE gets its own entry,
carrying instance_name when the instance has one, so a type the entity
carries several of comes back as the same several. The record also
carries the entity's own
active flag, every attribute it holds, and its lifecycle mode and
replication scope when either is other than the default. The entity's
runtime id IS its record original_id, so cross-entity component
references — which already point at runtime ids — round-trip and get
remapped on the next instantiate. Each component entry names where it
holds such a reference in entity_fields, taken from the component's
declared field kinds: a top-level field by its name, and a reference held
as a list element or struct subfield by its path from the field (an array
such as { "attachments", 1, "target" }), so a rebuild resolves exactly
those.
Parameters
ridstring— Runtime entity id to capture.parentOriginalIdstring(optional) — Parent's original_id, or nil for a root record.opts{ codeAttached: boolean? }(optional) — Optional{ codeAttached }:codeAttached = truecaptures the components another component's lifecycle attached as well, for a record of an entity whose whole content code made (a generator's output), which nothing re-attaches when the record is stood again.
Returns any — One record table.
local rec = EntityRecords.captureRecord(id, nil)
local whole = EntityRecords.captureRecord(id, nil, { codeAttached = true })
typed/builtin//modules/entity_records/M/carriesInstance
M.carriesInstance(rid: string, typeName: string, instanceName: string?) -> boolean
Whether the entity carries the component instance a record entry
names: the instance of typeName under instanceName, or the type's
anonymous instance when instanceName is nil. A loader asks this before
it puts an instance back, so a named instance is never read as already
present because the anonymous one is, and the reverse.
Parameters
ridstring— Runtime entity id.typeNamestring— Component type the entry names.instanceNamestring(optional) — The entry's instance name, or nil for the anonymous instance.
Returns boolean — True when that instance is on the entity.
if not EntityRecords.carriesInstance(id, "Pool", "mana") then entity(id).component.add("Pool", { name = "mana" }) end
typed/builtin//modules/entity_records/M/componentIsCodeAttached
M.componentIsCodeAttached(rid: string, componentType: string) -> boolean
Whether another component's lifecycle attached this component instance, rather than an author putting it there. A composed asset brings its own machinery with it — a humanoid avatar attaches a character controller to the body it expands into — and that machinery comes back on its own wherever the composition does. A record that named it would put a second one beside the one the expansion just produced, and a rebuild that removed every component its records leave unnamed would tear the expansion off the entity it belongs to. Both sides of a rebuild ask this.
Reached through the _G singleton the origin module publishes, which is
the same answer the scene serializer takes for the same question; a load
order that has not published it yet reads every component as authored.
Parameters
ridstring— Runtime entity id carrying the instance.componentTypestring— Component type name as the entity reports it.
Returns boolean — True when a component's lifecycle attached it.
if EntityRecords.componentIsCodeAttached(id, "Humanoid") then continue end
typed/builtin//modules/entity_records/M/compose
M.compose(rootId: string, rank: { [string]: number }?, skip: { [string]: boolean }?, keepTemporary: boolean?) -> { any }
Build the flat record array by walking rootId's hierarchy. Skips
temporary entities and their descendants — scaffolding and editor-only
tooling stay out of a baked result. The explicit root is always captured:
the caller named THAT entity as the thing to serialize, so temporary
pruning applies to descendants.
Parameters
rootIdstring— Runtime entity id to walk from.rank{ [string]: number }(optional) — Optional map of entity id → integer. Each node's children are visited in ascending rank, so a caller holding the order its entities were created in gets that order back. Omitted, the walk orders siblings by name and then by id.skip{ [string]: boolean }(optional) — Optional set of entity ids, keyed by id. An id it names is left out along with everything under it — what another owner produces and puts back itself, which a record here would describe a second time.keepTemporaryboolean(optional) — Optional. True walkstemporarydescendants as well, so the array holds every entity under the root.
Returns { any } — Flat array of records, root first, parents before children.
local records = EntityRecords.compose(rootId)
local every = EntityRecords.compose(rootId, nil, nil, true)
typed/builtin//modules/entity_records/M/composeMany
M.composeMany(rootIds: { string }, rank: { [string]: number }?, skip: { [string]: boolean }?) -> { any }
Compose several roots into one flat record array. A build captures a
SET of roots (a builder may spawn several unparented entities), not the
single root a bundle composes from. The roots are ordered the same way
siblings are — by rank, then name, then id.
Parameters
rootIds{ string }— Array of runtime entity ids.rank{ [string]: number }(optional) — Optional map of entity id → integer, applied to the roots and to every node's children alike.skip{ [string]: boolean }(optional) — Optional set of entity ids, keyed by id, pruned wherever the walk reaches one — same rule ascompose.
Returns { any } — Flat array of records covering every root's hierarchy.
local records = EntityRecords.composeMany({ idA, idB })
typed/builtin//modules/entity_records/M/configuredComponentData
M.configuredComponentData(ref: any?, data: any?) -> any
A live component instance's snapshot limited to the fields its
configuration states (configuredFields). A field the instance leaves to
its declared default is left
out, so whatever is rebuilt from the result takes the component's default
as it stands then, rather than the value it had when this was read.
Parameters
refany(optional) — The live component instance (a component proxy).dataany(optional) — Snapshot of the instance's data.
Returns any — The snapshot without the fields nothing configured.
local ComponentSnapshot = require("@builtin::modules.component_snapshot")
local d = EntityRecords.configuredComponentData(ref, ComponentSnapshot.snapshot(ref))
typed/builtin//modules/entity_records/M/configuredFields
M.configuredFields(ref: any?) -> { [string]: boolean }?
The fields one live component instance's configuration states: the keys of the table it was attached with, and every field written since (through its proxies, or by a replicated or undo write). That is the set a hot reload carries across a source edit; every other field holds the component's declared default, so a record that leaves it out lets a changed default reach the instance. Nil when the engine does not answer, which a caller reads as "every field".
Parameters
refany(optional) — The live component instance (a component proxy).
Returns { [string]: boolean }? — Set of configured field names, or nil.
local set = EntityRecords.configuredFields(entity(id).component("Light"))
typed/builtin//modules/entity_records/M/drawn
M.drawn(record: any?) -> { DrawnBinding }
What one saved entity record draws, read from its data without spawning
it: one binding per drawing component, a Model or SkinnedModel among its
components or the native Mesh and Material among its ecs rows. Each
binding names the component it comes from, the mesh and material as
descriptors { guid, identity, name, path } (nil when the component states
none), castsShadows and receivesShadows, hidden when the component is
switched off or not visible, skinned for a SkinnedModel, and dressing:
the names of the Model fields beyond what is drawn and its shadows
(tint, outline, light channels, mobility) that hold a value other than a
fresh Model's.
Parameters
recordany(optional) — One record of an entity template or a scene's entity list.
Returns { DrawnBinding } — The bindings, in the order the record states them; empty for a record that draws nothing.
for _, b in ipairs(EntityRecords.drawn(rec)) do print(b.component, b.mesh and b.mesh.guid) end
typed/builtin//modules/entity_records/M/drivenFields
M.drivenFields(ref: any?) -> { [string]: { instance: string, entity: string, type: string } }
The fields of one live component instance whose live value ANOTHER component's lifecycle wrote, each naming the instance driving it: a sky orienting the scene's sun light drives that light's direction, colour and intensity. The driver writes them again whenever its own state moves, so what such a field holds is the driver's, in edit mode and in play.
Parameters
refany(optional) — The live component instance (a component proxy).
Returns { [string]: { instance: string, entity: string, type: string } } — Field name to { instance, entity, type } of the driving instance; empty for an instance no other component drives.
local driven = EntityRecords.drivenFields(entity(id).component.get("Light"))
typed/builtin//modules/entity_records/M/instanceNameOf
M.instanceNameOf(entry: any?) -> string?
The instance name a component entry of a record states, or nil for the
type's anonymous instance. Every record shape names a component instance
the same way: a scene entity record, a captured entity record and a build
record each carry instance_name beside type on the entry of a named
instance, so an entity carrying several instances of one type comes back
carrying the same several.
Parameters
entryany(optional) — One entry of a record'scomponentslist.
Returns string? — The instance name, or nil when the entry names the anonymous instance.
local name = EntityRecords.instanceNameOf({ type = "Pool", instance_name = "mana" }) -- "mana"
typed/builtin//modules/entity_records/M/instancesOf
M.instancesOf(rid: string, typeName: string?) -> { ComponentInstance }
The { type, instance?, data } records component.getAll answers for the
entity, normalised: instance is nil for the anonymous instance and the
instance's name otherwise. Narrowed to one type when typeName is given.
Parameters
ridstring— Runtime entity id.typeNamestring(optional) — Component type to narrow to, or nil for every instance.
Returns { ComponentInstance } — The entity's component instances in the order it reports them.
for _, inst in ipairs(EntityRecords.instancesOf(id, "Pool")) do print(inst.type, inst.instance) end
typed/builtin//modules/entity_records/M/markRestored
M.markRestored(entityId: string, componentType: string)
Mark a component restored from a scene record using its attachment registry identity.
Parameters
entityIdstringcomponentTypestring
typed/builtin//modules/entity_records/M/withoutDrivenValues
M.withoutDrivenValues(ref: any?, data: any?) -> any
A live component instance's data with each field another component
drives (drivenFields) put back to what the instance's configuration
states for it: the value the table it was attached with gives the field,
or no value at all where that table names none. A field a driver writes
holds whatever the driver last wrote, which depends on when the driver
ran, so a record that states it states the configuration instead.
Parameters
refany(optional) — The live component instance (a component proxy).dataany(optional) — The instance's data, asconfiguredComponentDatareads it.
Returns any — The data with the driven fields stated as configured; data itself when no field is driven.
local d = EntityRecords.withoutDrivenValues(ref, EntityRecords.configuredComponentData(ref, snapshot))
typed/builtin//modules/entity_reflect/E/allTypes
E.allTypes() -> { string }
List all registered reflectable component types in this engine instance.
Returns { string } — Array of component name strings.
local types = Entity.allTypes()
typed/builtin//modules/entity_reflect/E/distance
E.distance(entityIdA: string, entityIdB: string) -> number?
Compute the straight-line distance between two entities' Transform.position fields.
Parameters
entityIdAstring— First entity id.entityIdBstring— Second entity id.
Returns number? — The distance, or nil when either entity is missing a position.
local d = Entity.distance("player", "enemy")
typed/builtin//modules/entity_reflect/E/getComponents
E.getComponents(entityId: string) -> { string }?
List all reflected component types on an entity.
Parameters
entityIdstring— The entity id.
Returns { string }? — Array of component name strings, or nil when the entity has no reflected components.
local comps = Entity.getComponents("player")
typed/builtin//modules/entity_reflect/E/getField
E.getField(entityId: string, component: string, field: string) -> any
Get a specific component field value. An engine-struct component reads through reflection; a component declared in Luau reads through its component ref, so one call serves both.
Parameters
entityIdstring— The entity id.componentstring— The component name (e.g."Transform","Model").fieldstring— The field name (e.g."position","tintBlend").
Returns any — The field value, or nil when the entity/component/field is missing. A component name this engine does not declare raises.
local pos = Entity.getField("player", "Transform", "position")
typed/builtin//modules/entity_reflect/E/getName
E.getName(entityId: string) -> string?
Get the name of an entity from its Name component.
Parameters
entityIdstring— The entity id.
Returns string? — The name string, or nil when the entity has no Name component.
local name = Entity.getName("player")
typed/builtin//modules/entity_reflect/E/getPosition
E.getPosition(entityId: string) -> Vec3?
Get the position of an entity — shortcut for getField(id, "Transform", "position").
Parameters
entityIdstring— The entity id.
Returns Vec3? — The position { x, y, z }, or nil when the entity has no Transform.
local pos = Entity.getPosition("player")
typed/builtin//modules/entity_reflect/E/getRotation
E.getRotation(entityId: string) -> Quat?
Get the rotation of an entity — shortcut for getField(id, "Transform", "rotation").
Parameters
entityIdstring— The entity id.
Returns Quat? — The rotation quaternion { x, y, z, w }, or nil when the entity has no Transform.
local rot = Entity.getRotation("player")
typed/builtin//modules/entity_reflect/E/getScale
E.getScale(entityId: string) -> Vec3?
Get the scale of an entity — shortcut for getField(id, "Transform", "scale").
Parameters
entityIdstring— The entity id.
Returns Vec3? — The scale { x, y, z }, or nil when the entity has no Transform.
local scale = Entity.getScale("player")
typed/builtin//modules/entity_reflect/E/getSchema
E.getSchema(componentName: string) -> { ComponentFieldSchema }?
Get the full schema of a component type — field names + types.
Parameters
componentNamestring— The component name.
Returns { ComponentFieldSchema }? — Array of { name, type } schema entries, or nil when the component is not registered.
local schema = Entity.getSchema("Transform")
typed/builtin//modules/entity_reflect/E/isVisible
E.isVisible(entityId: string) -> boolean
Check if an entity is visible — reads the Visible component. Missing component is treated as visible.
Parameters
entityIdstring— The entity id.
Returns boolean — true when visible (or no Visible component is present), false when explicitly hidden.
local visible = Entity.isVisible("player")
typed/builtin//modules/entity_reflect/E/patch
E.patch(entityId: string, component: string, fields: { [string]: any }) -> boolean
Patch multiple fields on a single component at once. Serves an engine-struct component and a component declared in Luau alike.
Parameters
entityIdstring— The entity id.componentstring— The component name.fields{ [string]: any }—{ fieldName = value, ... }map of fields to write.
Returns boolean — true when every named field was written. A component name this engine does not declare raises.
Entity.patch("player", "Transform", { position = pos, scale = scl })
typed/builtin//modules/entity_reflect/E/setField
E.setField(entityId: string, component: string, field: string, value: any?) -> boolean
Set a specific component field value. An engine-struct component writes through reflection; a component declared in Luau writes through its component ref, so one call serves both.
Parameters
entityIdstring— The entity id.componentstring— The component name.fieldstring— The field name.valueany(optional) — The new value.
Returns boolean — true when the write succeeded, false otherwise. A component name this engine does not declare raises.
Entity.setField("player", "Transform", "position", { x = 0, y = 1, z = 0 })
typed/builtin//modules/entity_reflect/E/setPosition
E.setPosition(entityId: string, pos: Vec3)
Set the position of an entity — shortcut for setField(id, "Transform", "position", pos).
Parameters
entityIdstring— The entity id.posVec3— The new position{ x, y, z }.
Entity.setPosition("player", { x = 0, y = 1, z = 0 })
typed/builtin//modules/entity_reflect/E/setScale
E.setScale(entityId: string, scale: Vec3)
Set the scale of an entity — shortcut for setField(id, "Transform", "scale", scale).
Parameters
entityIdstring— The entity id.scaleVec3— The new scale{ x, y, z }.
Entity.setScale("player", { x = 1, y = 1, z = 1 })
typed/builtin//modules/entity_reflect/E/snapshot
E.snapshot(entityId: string) -> any
Snapshot all reflected components on an entity into a { ComponentName = { field = value, ... }, ... } map.
Parameters
entityIdstring— The entity id.
Returns any — The snapshot table, or nil when the entity does not exist.
local snap = Entity.snapshot("player")
typed/builtin//modules/entity_signals/M/entityKeyed
M.entityKeyed(records: { [string]: any }) -> { [string]: any }
Make records a table keyed by entity id that keeps only entities
in the world: when an entity is despawned, whatever despawned it (an
entity.despawn, a parent's cascade, a scene rebuild or reload, a mode
flip), its id leaves records. An id a newer entity carries by then stays.
A module holding per-entity state that something reads every frame
declares its table this way, so the reader never meets an entity that is
gone. The table is one of the engine's own records, so a module-state
restore leaves it as it stands and an id that left it stays out.
Returns records.
Parameters
records{ [string]: any }— The table to maintain, keyed by entity id.
Returns { [string]: any } — The same table.
local entries = EntitySignals.entityKeyed({})
typed/builtin//modules/entity_signals/M/get
M.get(entityId: string, phase: string) -> any
Return the onDestroying/onDestroyed signal for an entity,
creating it on first access. phase is "destroying" or "destroyed".
Parameters
entityIdstring— Entity whose signal to fetch.phasestring— Either "destroying" or "destroyed".
Returns any
typed/builtin//modules/field/Field/alias
Field.alias(target: string | { string }, description: string?) -> FieldDesc<any>
Alias for one or more existing fields. An alias is an ACCEPTED key that is not stored itself — it routes the written value to the real field(s) it points at, so a component answers to a caller's natural key without hand-rolling translation code, and both the runtime and the LSP recognise the key.
The key works everywhere the fields it targets do: as a
component.add init key, and as a read and a write on the live
component. Reading it returns what the target(s) hold right now.
Two forms:
Field.alias("radius")— rename. The value is written verbatim to the single target field (running that field's normal coercion, so an alias onto an assetRef field resolves the ref), and reads back as that field's value.Field.alias({ "colorR", "colorG", "colorB" })— fan-out. The value is destructured across the targets: an array{a, b, c}positionally, or a named{r=, g=, b=}/{x=, y=, z=}table by the target's position (r/x, g/y, b/z, a/w). It reads back as an array in target order, soc.color = c.colorround-trips.
An alias never replicates and is never persisted — the fields it targets own their own Sync/NoSync, so no mode argument is taken.
Parameters
targetstring | { string }— A single target field name, or an array of target field names.descriptionstring(optional) — Documents the alias for the LSP; nil to leave it undocumented.
Returns FieldDesc<any> — FieldDesc descriptor with kind = "alias".
type = Field.alias("kind")
color = Field.alias({ "colorR", "colorG", "colorB" })
typed/builtin//modules/field/Field/assetRef
Field.assetRef(category: (C & string) | { string }, default: AssetRef<C> | I | nil?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<AssetRef<C, I>>
Typed asset reference field. C is the asset category — a
singleton string type inferred from the category argument
("material", "mesh", "@user/customCategory", etc.). One
constructor handles every category, including user-registered ones.
Default accepts a resolved AssetRef<C> handle, an identity string
(full @library::path form OR a bare leaf name resolved
category-locally via asset.resolve(identity, category)), or nil.
At registration the engine resolves any string default through the
same category-aware resolver public_newindex uses for runtime
writes, so the first read of public.<field> already returns a
resolved envelope — not a raw string.
Parameters
category(C & string) | { string }— Asset category as a string literal ("material","mesh", etc.),"*"for any category, or a list of categories the field takes any of ({ "importer", "component" }). A string is inferred intoC.defaultAssetRef<C> | I | nil(optional) — AssetRef envelope, identity string, or nil.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc<AssetRef<C, I>> descriptor.
material = Field.assetRef("material", "@my-library::materials.gold", Sync)
source = Field.assetRef("bundle", nil, Sync)
declarer = Field.assetRef({ "importer", "component" }, nil, NoSync)
typed/builtin//modules/field/Field/bitmask
Field.bitmask(bits: number, default: number?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<number>
Bit-mask number field. bits declares the width the consumer can
address; a default or a write that is not a whole number in
0 .. 2^bits - 1 is rejected, naming the width. Use it wherever a numeric
field is read as a set of bits rather than as a quantity — what the field
reads back is then a mask, so a read-back is evidence the value took.
Parameters
bitsnumber— How many bits wide the mask is, 1..53.defaultnumber(optional) — Numeric default forpublic.<field>, or nil to leave it unset.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDescbitmask constraint.
lightChannels = Field.bitmask(32, 0, Sync)
typed/builtin//modules/field/Field/bool
Field.bool(default: boolean?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<boolean>
Boolean field. nil leaves the field unset.
Parameters
defaultboolean(optional) — Boolean default forpublic.<field>, or nil to leave it unset.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc
enabled = Field.bool(true, Sync)
typed/builtin//modules/field/Field/check
Field.check(desc: FieldDesc<any>, value: any?) -> (boolean, { { path: string, message: string } })
Check one value against one Field descriptor: its base kind, its constraint, and every nested subfield or element. Returns whether the value is accepted plus every violation found, each naming the path it sits at and what that field takes. A nil value is accepted — a field the values do not set takes its declared default.
Parameters
descFieldDesc<any>— The Field descriptor to check against.valueany(optional) — The value to check.
Returns (boolean, { { path: string, message: string } }) — (ok, violations) — violations is empty when ok.
local ok, violations = Field.check(Field.number(0, NoSync), "x")
typed/builtin//modules/field/Field/checkSchema
Field.checkSchema(schema: FieldSchema, values: { [string]: any }) -> (boolean, { { path: string, message: string } })
Check a table of values against a schema of Field descriptors. A key the schema does not declare is a violation naming every declared field.
Parameters
schemaFieldSchema— Map of field name to Field descriptor.values{ [string]: any }— The values to check.
Returns (boolean, { { path: string, message: string } }) — (ok, violations) — violations is empty when ok.
local ok, violations = Field.checkSchema(schema, { filter = "nearest" })
typed/builtin//modules/field/Field/color
Field.color(default: color?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<color>
Color field. Default is a color — either
{r = .., g = .., b = .., a = ..?} or {r, g, b, a?}.
Parameters
defaultcolor(optional) — color default forpublic.<field>.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc
tint = Field.color({ 1, 1, 1, 1 }, Sync)
typed/builtin//modules/field/Field/componentRef
Field.componentRef(componentType: T & string, default: ComponentRef<T> | nil?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<ComponentRef<T>>
Typed component reference field. T is the component-type
name — a singleton string type inferred from the componentType
argument ("Camera", "Transform", "@user/Inventory"). The
engine validates the referent exists and is of the declared type
at every write.
Parameters
componentTypeT & string— Component type name as a string literal. Inferred intoT.defaultComponentRef<T> | nil(optional) — ComponentRef envelope or nil.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc<ComponentRef
aimCam = Field.componentRef("Camera", nil, NoSync)
typed/builtin//modules/field/Field/dataRef
Field.dataRef(contract: C & string, default: AssetRef<"data"> | string | nil?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<AssetRef<"data">>
Contract-constrained typed-data reference field. Accepts only
.data assets whose dataType contract chain includes contract.
Rides the assetRef machinery (category "data") — dependency graph,
sync, and rehydration behave exactly like Field.assetRef — with the
contract gate enforced through the generic field-constraint hook on
every write and on the registration-time default.
Parameters
contractC & string— The required dataType contract identity. Inferred intoC.defaultAssetRef<"data"> | string | nil(optional) — AssetRef envelope, identity string, or nil.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc<AssetRef<"data">> descriptor.
weapon = Field.dataRef("weapon", nil, Sync)
typed/builtin//modules/field/Field/entityRef
Field.entityRef(default: EntityRef | string | nil?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<EntityRef>
Entity reference field. Accepts a live entity proxy (EntityRef),
a raw entity-id string, or nil (no target). Writes are normalised to
the plain id string for storage/replication; reads return a live
EntityRef proxy (or nil), so public.<field>:method() and
public.<field>.id work directly without re-resolving. As a
Field.struct subfield or a Field.list element it stores the same
id string and reads back as that id string.
Parameters
defaultEntityRef | string | nil(optional) — Live entity proxy, entity-id string, or nil.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc
target = Field.entityRef(nil, Sync)
typed/builtin//modules/field/Field/enum
Field.enum(values: { string }, default: string?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<string>
Closed-set string field. values declares every member; a default or a
write outside the set is rejected with the whole set named. The editor
renders the members as a choice and the LSP completes them.
Parameters
values{ string }— The members, as an array of non-empty, distinct strings.defaultstring(optional) — The default member, or nil to leave the field unset.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDescenum constraint.
fit = Field.enum({ "exact", "hull" }, "hull", Sync)
typed/builtin//modules/field/Field/instantiableRef
Field.instantiableRef(default: AssetRef<any> | string | nil?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<AssetRef<any>>
Scene-instantiable asset reference field — accepts ANY asset whose
type implements sceneInstantiable, so it can be instantiated into a
scene. It is Field.interfaceRef("sceneInstantiable", ...): a new
scene-instantiable asset type is accepted here the moment it lists the
interface. The uniform ref:as("sceneInstantiable"):instantiate(target?, opts?)
is how a consumer then instantiates the assigned asset (Asset.component,
a viewport drop, a tool argument).
Parameters
defaultAssetRef<any> | string | nil(optional) — AssetRef envelope, identity string, or nil.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc<AssetRef
source = Field.instantiableRef(nil, Sync)
typed/builtin//modules/field/Field/integer
Field.integer(min: number?, max: number?, default: number?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<number>
Whole-number field. min and max declare the interval the count
or index means something in; a default or a write that is not a whole
number inside it is rejected with the interval named. Either bound may be
nil, leaving that side open. Use it for a count, a level or a group number,
where a fraction would be read as some other whole number.
Parameters
minnumber(optional) — Lowest accepted value, or nil to leave the low side open.maxnumber(optional) — Highest accepted value, or nil to leave the high side open.defaultnumber(optional) — Whole-number default forpublic.<field>, or nil to leave it unset.modeSyncMode—SyncorNoSync, required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDescrange constraint.
extraSteps = Field.integer(0, 16, 0, Sync)
typed/builtin//modules/field/Field/interfaceRef
Field.interfaceRef(interface: string | { string }, default: AssetRef<any> | string | nil?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<AssetRef<any>>
Interface-gated asset reference field: accepts ANY asset whose type
implements one of the named interfaces (ref:implements), gated by what
the type guarantees rather than a hardcoded type list. Rides the assetRef
machinery with no category filter (any asset type resolves), and the
generic field-constraint hook rejects, on every write and on the
registration-time default, any asset whose type implements none of them.
The constraint records each interface by guid, the name as written when no
interface answers to it yet. A new type is accepted here the moment it
lists the interface under interfaces: in its type.yaml: no edit to this
field or its consumers. A consumer then calls the assigned asset through
the interface: ref:as("<interface>"):member(...).
Parameters
interfacestring | { string }— An interface name, identity or guid, or a list of them meaning any of.defaultAssetRef<any> | string | nil(optional) — AssetRef envelope, identity string, or nil.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc<AssetRef
source = Field.interfaceRef("sceneInstantiable", nil, Sync)
typed/builtin//modules/field/Field/list
Field.list(element: FieldDesc<any>, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<ListValue>
List field — an array of one repeated element type. The element is the Field constructor descriptor every item conforms to, often a Field.struct for a list of records. The list value is an array of the element's value type. Like Field.struct, the engine descends the element schema to resolve nested asset refs into envelopes, so a stack of structs each holding an asset ref has every ref appear in the asset dependency graph, validates each item, and the LSP type-checks the array. An entity reference element is stored as the entity's id string, whether a proxy or an id was written, so the list saves into a scene and replicates. The default value is an empty list. The element declares its own Sync or NoSync for typing; the list's own mode governs replication of the whole array as a unit.
Parameters
elementFieldDesc<any>— The Field constructor descriptor each item conforms to.modeSyncMode— Sync or NoSync — required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc<ListValue> — FieldDesc whose value is an array of the element's values.
typed/builtin//modules/field/Field/number
Field.number(default: number?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<number>
Number field. nil leaves the field unset, so a component can treat an
absent value as "derive this from somewhere else" without a second field
recording whether the first one was authored.
Parameters
defaultnumber(optional) — Numeric default forpublic.<field>, or nil to leave it unset.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc
positionX = Field.number(0, Sync)
typed/builtin//modules/field/Field/quat
Field.quat(default: quat?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<quat>
Quaternion field. Default is a quat — either
{x = .., y = .., z = .., w = ..} or {x, y, z, w}.
Parameters
defaultquat(optional) — quat default forpublic.<field>.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc
rotation = Field.quat({ 0, 0, 0, 1 }, Sync)
typed/builtin//modules/field/Field/range
Field.range(min: number?, max: number?, default: number?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<number>
Bounded number field. min and max declare the interval the value
means something in; a default or a write outside it is rejected with the
interval named. Either bound may be nil, leaving that side open. The value
the field reads back is one the system consuming it can use, and a number
that lands outside is reported where it was written.
Parameters
minnumber(optional) — Lowest accepted value, or nil to leave the low side open.maxnumber(optional) — Highest accepted value, or nil to leave the high side open.defaultnumber(optional) — Numeric default forpublic.<field>, or nil to leave it unset.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDescrange constraint.
volume = Field.range(0, 1, 1, Sync)
typed/builtin//modules/field/Field/resource
Field.resource(category: C & string, default: AssetRef<C> | Handle<C> | string | nil?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<AssetRef<C> | Handle<C>>
Category-gated RESOURCE field — accepts EITHER a persistent
AssetRef<C> OR a live GPU Handle<C>, gated by category. This is the
renderer-facing field type (e.g. Model.model, Model.material, material
texture slots): content can author a persistent asset OR pass a runtime
handle (renderer.<resource>.create(...)); the component bridges either to
the GPU resource. The category gate still holds — an AssetRef<audio> or a
wrong-category handle (a TextureHandle on a "mesh" slot) is a type error
AND a runtime rejection. Use Field.assetRef instead when the field MUST be
a persistent asset (handles rejected).
With Sync, persistent-asset values replicate to peers; a live GPU
handle value is local by construction and stays local — peers keep the
last replicated asset value.
Parameters
categoryC & string— Resource category string literal ("mesh","texture","material", ...). Inferred intoC.defaultAssetRef<C> | Handle<C> | string | nil(optional) —AssetRef<C>/Handle<C>/ identity string / nil.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc<AssetRef
model = Field.resource("mesh", nil, Sync)
typed/builtin//modules/field/Field/settingsOf
Field.settingsOf(declarer: string, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?, default: StructValue?) -> FieldDesc<StructValue>
A struct field whose schema is another declarer's settings schema — an assetType, an importer, a component. The declarer is named by its asset identity and resolved by guid, so a same-named type in another package is never mistaken for it. The subfields are the declarer's own, so a field embedding them never restates them.
Parameters
declarerstring— The declarer's asset identity, e.g. "@builtin::assetTypes.texture".modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.defaultStructValue(optional) — The group's declared default: a table of the declarer's fields, or nil for none.
Returns FieldDesc<StructValue> — FieldDesc whose value is a table of the declarer's settings.
textureSettings = Field.settingsOf("@builtin::assetTypes.texture", NoSync, "Stamped onto every texture.", { filter = "nearest" })
typed/builtin//modules/field/Field/string
Field.string(default: string?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<string>
String field. nil leaves the field unset.
Parameters
defaultstring(optional) — String default forpublic.<field>, or nil to leave it unset.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc
label = Field.string("hello", Sync)
typed/builtin//modules/field/Field/struct
Field.struct(schema: FieldSchema, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<StructValue>
Struct field — a table whose keys are themselves typed fields. The schema maps each subfield name to its Field constructor descriptor; the struct value is a table holding one value per subfield. Use this instead of Field.table when the table carries asset references or other typed data: the engine descends the schema to resolve nested asset refs into envelopes at registration and at write time, so they appear in the asset dependency graph, validates writes per subfield, and the LSP type-checks the shape. Each subfield declares its own Sync or NoSync for typing; the struct's own mode governs replication of the whole value as a unit.
Parameters
schemaFieldSchema— Map of subfield name to a Field constructor descriptor.modeSyncMode— Sync or NoSync — required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc<StructValue> — FieldDesc whose value is a table of the subfields' values.
typed/builtin//modules/field/Field/table
Field.table(default: T, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<T>
Generic table field. T is the table's shape — usually
inferred from the default value, or supplied explicitly via
an explicit ascription Field.table({} :: MyShape, mode) when the default doesn't cover every
key the runtime will write. The engine accepts any Luau table as
a value at write time; per-shape enforcement is opt-in static
typing only.
Parameters
defaultT— Table value to use as the default forpublic.<field>.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc
idMap = Field.table({} :: { [string]: string }, NoSync)
typed/builtin//modules/field/Field/taggedRef
Field.taggedRef(tag: string, default: AssetRef<any> | string | nil?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<AssetRef<any>>
Tag-constrained asset reference field — accepts any asset carrying
tag in its .metadata.tags, whatever its type. This is how a slot
states the KIND of asset it takes (a camera behavior, a player visual)
without naming the assets themselves: a new asset becomes assignable the
moment it is tagged, with no edit here or in the consumer. Rides the
assetRef machinery with no category filter — dependency graph, sync and
rehydration behave exactly like Field.assetRef — and the generic
field-constraint hook rejects an untagged asset on every write and on the
registration-time default. asset.list({ fields = { tags = tag } })
enumerates what fits the slot.
Parameters
tagstring— The tag an assigned asset must carry.defaultAssetRef<any> | string | nil(optional) — AssetRef envelope, identity string, or nil.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc<AssetRef
behavior = Field.taggedRef("cameraBehavior", nil, Sync)
typed/builtin//modules/field/Field/vec2
Field.vec2(default: vec2?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<vec2>
Parameters
defaultvec2(optional)modeSyncModemarker(SerializedMode | string | FieldOptions)(optional)
Returns FieldDesc<vec2>
typed/builtin//modules/field/Field/vec3
Field.vec3(default: vec3?, mode: SyncMode, marker: (SerializedMode | string | FieldOptions)?) -> FieldDesc<vec3>
Vec3 field. Default is a vec3 — either {x = .., y = .., z = ..}
or the 3-element array form {x, y, z}.
Parameters
defaultvec3(optional) — vec3 default forpublic.<field>.modeSyncMode—SyncorNoSync— required.marker(SerializedMode | string | FieldOptions)(optional) —Serialized, a description string, or a{ serialized, description }options table; omit for neither.
Returns FieldDesc
offset = Field.vec3({ 0, 0, 0 }, Sync)
typed/builtin//modules/fieldEdits/M/compose
M.compose(generated: any?, edits: { Edit }) -> Composition
Compose authored field values over a new generated base, comparing values the way diff does. Value conflicts retain authored values; missing parent/target and root add/add conflicts block composition. Satisfied edits remain represented in the caller's edit list.
Parameters
generatedany(optional) — The current generated value.edits{ Edit }— Durable field intents with the baselines they were made over.
Returns Composition — value, conflicts, satisfied paths and blocked. A blocked result carries its conflict report.
local result = FieldEdits.compose({position={0,0,0},visible=true}, edits)
typed/builtin//modules/fieldEdits/M/copy
M.copy(value: any?) -> any
Copy a structured value after validating its finite numbers, dense arrays, key shapes and nesting.
Parameters
valueany(optional) — The structured value to copy.
Returns any — An independent copy.
local snapshot = FieldEdits.copy(record)
typed/builtin//modules/fieldEdits/M/diff
M.diff(before: any?, after: any?) -> { Edit }
Capture changed fields. String-keyed objects are compared by field; arrays and asset references are atomic values. Values compare exactly, except that a rotation field holding four-number quaternions compares by the orientation it states, so normalization, float rounding and a negated quaternion are no change.
Parameters
beforeany(optional) — The previous structured value, or nil for absence.afterany(optional) — The new structured value, or nil for removal.
Returns { Edit } — Non-overlapping field edits in deterministic path order.
local edits = FieldEdits.diff({ position = {0, 0, 0} }, { position = {2, 0, 0} })
typed/builtin//modules/fieldEdits/M/keep
M.keep(generated: any?, edits: { Edit }, paths: { { string } }?) -> { Edit }
Acknowledge selected field conflicts against the new generated base while retaining their authored values.
Parameters
generatedany(optional) — The generated value whose changes the author reviewed.edits{ Edit }— Existing field intents.paths{ { string } }(optional) — Exact paths to acknowledge; omit to acknowledge every edit.
Returns { Edit } — Updated baselines. Structural conflicts still require their target or parent to exist.
local accepted = FieldEdits.keep(newBase, edits)
typed/builtin//modules/fieldEdits/M/settle
M.settle(generated: any?, edits: { Edit }, dead: ((Edit) -> boolean)?) -> Settled
Sort edits by what a generated value can still receive. An edit whose target, or whose target's parent, the generated value no longer holds is retired: it has nothing to apply to. An edit that adds a whole value the generated value now holds is rebased onto that value, so the authored value stays and the conflict is reported. Every other edit is kept as it is, and compose states its value conflicts.
Parameters
generatedany(optional) — The current generated value.edits{ Edit }— Durable field intents with the baselines they were made over.dead((Edit) -> boolean)(optional) — Optional test for an edit that can never apply whatever the generated value holds; such an edit is retired asunresolved-component.
Returns Settled — The edits to keep, the conflicts of the edits retired (with the authored state each held) and the conflicts of the edits rebased.
local settled = FieldEdits.settle(generated, edits)
typed/builtin//modules/fieldEdits/M/update
M.update(generated: any?, previous: any?, current: any?, edits: { Edit }) -> { Edit }
Record an edit to the visible value while preserving existing field intent and its original baselines. Newly introduced parents are captured as whole values.
Parameters
generatedany(optional) — The current generated base.previousany(optional) — The visible value before the authoring operation.currentany(optional) — The visible value after the authoring operation.edits{ Edit }— The existing durable edits.
Returns { Edit } — The updated field intents; inputs remain unchanged.
local nextEdits = FieldEdits.update(base, previous, current, edits)
typed/builtin//modules/fieldEdits/M/updateChanges
M.updateChanges(generated: any?, current: any?, changes: { Edit }, edits: { Edit }) -> { Edit }
Record observed field changes while retaining satisfied authored intent.
Parameters
generatedany(optional) — The accepted generated value.currentany(optional) — The merged visible value after applying the changes.changes{ Edit }— Original observed field changes.edits{ Edit }— Existing durable field intents.
Returns { Edit } — Updated durable intents; inputs remain unchanged.
local edits = FieldEdits.updateChanges(base, merged.value, changes, held)
typed/builtin//modules/fieldEdits/M/validate
M.validate(edits: { Edit }) -> boolean
Validate structured edits, presence flags and non-overlapping paths while retaining the input order and values.
Parameters
edits{ Edit }— Field edits to validate.
Returns boolean — True for valid edits; malformed edits raise their validation error.
FieldEdits.validate(edits)
typed/builtin//modules/frame_bounds/F/cameraAxes
F.cameraAxes(dx: number, dy: number, dz: number) -> CameraAxes
The camera's own forward / right / up for a view along an orbit direction, with right and up taken from the world up.
Parameters
dxnumber— Orbit direction X (subject toward camera, unit length).dynumber— Orbit direction Y.dznumber— Orbit direction Z.
Returns CameraAxes — { forward = {x,y,z}, right = {x,y,z}, up = {x,y,z} }.
local axes = FrameBounds.cameraAxes(0, 0.34, 0.94)
typed/builtin//modules/frame_bounds/F/fit
F.fit(box: Aabb, opts: FitOpts?) -> Framed
Solve for a camera pose that frames box at the given orbit angle.
Parameters
boxAabb— The AABB to frame.optsFitOpts(optional) —{ fov, aspect, margin, angle = { yawDeg, pitchDeg } }.
Returns Framed — { px, py, pz, cx, cy, cz, distance, radius, fov, near, far, center, size }.
local f = FrameBounds.fit(b, { fov = 60, angle = { 0, 20 } })
typed/builtin//modules/frame_bounds/F/fitDistance
F.fitDistance(hx: number, hy: number, hz: number, dx: number, dy: number, dz: number, tanH: number, tanV: number) -> number
Smallest distance along the orbit direction that keeps all eight corners of a half-extent box inside the frustum.
Parameters
hxnumber— Half-extent on X.hynumber— Half-extent on Y.hznumber— Half-extent on Z.dxnumber— Orbit direction X (subject toward camera, unit length).dynumber— Orbit direction Y.dznumber— Orbit direction Z.tanHnumber— Tangent of the half horizontal FOV.tanVnumber— Tangent of the half vertical FOV.
Returns number — The fitting distance.
local d = FrameBounds.fitDistance(1, 1, 1, 0, 0.34, 0.94, 1.03, 0.58)
typed/builtin//modules/frame_bounds/F/fitDistanceAxes
F.fitDistanceAxes(hx: number, hy: number, hz: number, axes: CameraAxes, tanH: number, tanV: number) -> number
Smallest distance that keeps all eight corners of a half-extent box
inside the frustum, projected onto explicitly-given camera axes. Callers
that aim by a named station rather than an orbit angle pass their own axes;
fitDistance derives them from a direction and calls this.
Parameters
hxnumber— Half-extent on the first extent axis.hynumber— Half-extent on the second.hznumber— Half-extent on the third.axesCameraAxes—{ forward, right, up }, in the SAME frame the half-extents are measured in.tanHnumber— Tangent of the half horizontal FOV.tanVnumber— Tangent of the half vertical FOV.
Returns number — The fitting distance, before any margin.
local d = FrameBounds.fitDistanceAxes(7, 0.25, 7, axes, 1.03, 0.58)
typed/builtin//modules/frame_bounds/F/ofEntity
F.ofEntity(target: any?) -> Aabb?
World-space bounds of an entity and its descendants, falling back to the entity's own mesh bounds.
Parameters
targetany(optional) — An entity proxy.
Returns Aabb? — AABB or nil when the target has no renderable geometry.
local b = FrameBounds.ofEntity(entity.find("player"))
typed/builtin//modules/frame_bounds/F/union
F.union(boxes: { Aabb }) -> Aabb?
Union a list of AABBs into one.
Parameters
boxes{ Aabb }— Array of{ min = vec3, max = vec3 }.
Returns Aabb? — The enclosing AABB, or nil when the list is empty.
local u = FrameBounds.union({ a:hierarchyBounds(), b:hierarchyBounds() })
typed/builtin//modules/highlight/M/dispatch
M.dispatch(language: string, text: string) -> { Segment }
Dispatch a highlighter by language name, with yml and md
aliases matching the engine's pre-Phase-3 parse_editor_language.
Unknown languages return a single default-colored segment so callers
can pass arbitrary user input without crashing.
Parameters
languagestring— Language name ("lua","json","yaml","wgsl","markdown", or aliases"yml"/"md").textstring— Source text to tokenize.
Returns { Segment } — An array of Segment records.
local segs = Z.highlight.dispatch("lua", source)
local segs = Z.highlight.dispatch("md", readme)
typed/builtin//modules/highlight/M/languageOf
M.languageOf(path: string) -> string?
The language a file at path is coloured as, read from its
extension (what follows the last dot that has a name before it, so a
dotfile such as .zmignore has none), or nil for text shown uncoloured.
Parameters
pathstring— A file path or name.
Returns string? — A language name dispatch takes, or nil.
Z.highlight.languageOf("/zero/source/a/init.luau") -- "lua"
typed/builtin//modules/highlight/json/highlightJson
highlightJson(text: string) -> { Segment }
Tokenize a JSON string into colored text segments for the zui
code renderer. Distinguishes object keys (via lookahead for :)
from string values, colors numbers (including scientific notation),
bool/null literals, and structural punctuation.
Parameters
textstring— The JSON source to highlight. Coerced viatostringand defaults to""when nil.
Returns { Segment } — An array of { text, color, monospace } segments suitable for the zui code renderer.
local segments = highlight('{"a": 1, "b": "two"}')
typed/builtin//modules/highlight/lua/highlightLua
highlightLua(text: string) -> { Segment }
Tokenize a Luau source string into colored text segments for the zui code renderer. One walk over the bytes: comments, directives, strings of every shape, numbers, and identifiers read in context — a keyword, a literal, a builtin, a called function, a member, a declared function name, or a type.
Parameters
textstring— The Luau source to highlight. Coerced viatostringand defaults to""when nil.
Returns { Segment } — An array of { text, color, monospace } segments whose texts concatenate back to the source byte for byte.
local segments = highlight("local x = 1 -- pi-ish")
typed/builtin//modules/highlight/markdown/highlightMarkdown
highlightMarkdown(text: string) -> { Segment }
Tokenize a Markdown source string into colored text segments for the zui code renderer. Block-level pass recognises fenced code (```), headings (#), blockquotes (>), bullet and ordered lists; inline pass within each non-block line recognises inline code, bold, and links.
Parameters
textstring— The Markdown source to highlight. Coerced viatostringand defaults to""when nil.
Returns { Segment } — An array of { text, color, monospace } segments suitable for the zui code renderer.
local segments = highlight("# Title\n**bold**\n")
typed/builtin//modules/highlight/wgsl/highlightWgsl
highlightWgsl(text: string) -> { Segment }
Tokenize a WGSL source string into colored text segments for the
zui code renderer. Handles // and /* */ comments, "..."
strings with backslash escapes, @attribute tokens, numeric
literals with suffixes (1u, 0xFF, 1.0_f32), and identifiers
dispatched against the WGSL keyword and built-in type tables.
Parameters
textstring— The WGSL source to highlight. Coerced viatostringand defaults to""when nil.
Returns { Segment } — An array of { text, color, monospace } segments suitable for the zui code renderer.
local segments = highlight("@vertex fn main() -> vec4<f32> {}")
typed/builtin//modules/highlight/yaml/highlightYaml
highlightYaml(text: string) -> { Segment }
Tokenize a YAML source string into colored text segments for
the zui code renderer. Splits each line on a # comment first,
then on the first : to extract a key from its value; the value
is then classified as quoted string / bool / null / numeric / plain.
Parameters
textstring— The YAML source to highlight. Coerced viatostringand defaults to""when nil.
Returns { Segment } — An array of { text, color, monospace } segments suitable for the zui code renderer.
local segments = highlight("name: zero\n# comment\n")
typed/builtin//modules/json/Json/decode
Json.decode(str: string) -> any
Decode a JSON string to a Lua value. Returns the decoded value, or nil + error message on failure.
The text is one JSON value with optional whitespace around it; a text with
anything else after its first value is a parse failure naming the
character and its position.
Parameters
strstring— The JSON string to decode.
Returns any — The decoded Lua value. On failure, returns nil (and the error message in the second return value).
local v = Json.decode('{"a":1,"b":"hi"}') -- → { a = 1, b = "hi" }
local v, err = Json.decode("bad") -- → nil, "Invalid literal..."
local v, err = Json.decode('{"a":1}}') -- → nil, "Unexpected character '}' at position 8"
typed/builtin//modules/json/Json/encode
Json.encode(value: any?, indent: string?, currentIndent: string?) -> string
Encode a Lua value to a compact JSON string. Functions and unknown types serialise to null; NaN/Inf serialise to null (JSON has no representation for them). A table that contains itself raises an error naming where the walk reached it again.
Parameters
valueany(optional) — Any Lua value (nil, boolean, number, string, table).indentstring(optional) — Optional indent string. Reserved: the compact encoder ignores it; useencodePrettyfor indented output.currentIndentstring(optional) — Optional current-depth indent string. Reserved.
Returns string — The encoded JSON string.
local s = Json.encode({ type = "button", text = "Click Me" })
typed/builtin//modules/json/Json/encodeArgs
Json.encodeArgs(...: any?) -> string
Encode a list of arguments as a JSON array string. Useful when forwarding varargs to a JSON-based bridge.
Parameters
...any(optional) — Any number of values to encode.
Returns string — The encoded JSON array string.
local s = Json.encodeArgs("foo", 1, true) -- '["foo",1,true]'
typed/builtin//modules/json/Json/encodePretty
Json.encodePretty(value: any?, indentStr: string?, opts: PrettyOptions?) -> string
Encode a Lua value to a pretty-printed JSON string. Indents nested values and sorts object keys for diff-friendly output. A table that contains itself raises an error naming where the walk reached it again.
opts takes part in the walk: reuse(value, depth) answers the text a table already has at that depth, which is written in its place;
encoded(value, depth, text) is told each table the walk encoded; pace() runs after each array element, where a task may yield.
A table's text depends on the table and its depth alone, so a text kept from encoded serves reuse for as long as the table is unchanged.
Parameters
valueany(optional) — Any Lua value.indentStrstring(optional) — Indent string per level (default" ").optsPrettyOptions(optional) — Optional{ reuse?, encoded?, pace? }.
Returns string — The pretty-printed JSON string.
local s = Json.encodePretty({ a = 1, b = { c = 2 } })
typed/builtin//modules/luau_introspect/M/docstrings
M.docstrings(src: string) -> DocMap
Scans src for --!desc / --!arg / --!return / --!example
/ --!deprecated / --!hidden doc-comment runs and binds each run to
the name of the declaration on the next code line (the identifier after
function, public:, local function, M., public.<name>, or a
<name> = Field.<...> /
<name> = Event(...) field/event declaration). A continuation line
("--! " with no tag word) extends whichever field the run's last tag
opened. Blank and plain -- comment lines between the run and the
declaration are skipped without terminating the run.
Parameters
srcstring— Luau/asset source text.
Returns DocMap — Map of declaration name to its parsed doc entry.
local d = I.docstrings(src); print(d.takeDamage.desc)
typed/builtin//modules/luau_introspect/M/events
M.events(src: string) -> { EventEntry }
Parses events = { name = Event(payloadSchema?, syncMode?), ... }
table-literal entries. The payload schema — a { k = Field.<kind>(...) }
table — is parsed like publicFields and reduced to {name, type}
pairs; a payloadless Event() yields an empty payload. sync is true
only when the SECOND positional Event argument is the literal
identifier Sync. Comments and string literals never register. Folds in
desc from docstrings(src).
Parameters
srcstring— Luau/asset source text.
Returns { EventEntry } — Ordered array of event entries, source order preserved.
local e = I.events(src); print(e[1].name, e[1].sync)
typed/builtin//modules/luau_introspect/M/forSource
M.forSource(src: string, computeFn: (string) -> any) -> any
Memoises computeFn(src) keyed on src itself in a bounded
module-local table. The same source text returns the cached result
without re-invoking computeFn; different source text recomputes. The
cache is capped (oldest key evicted first), so an evicted key
recomputes on its next request.
Parameters
srcstring— Source text — both the memo key and the argument passed tocomputeFn.computeFn(string) -> any— Called ascomputeFn(src)on a cache miss.
Returns any — The (possibly cached) result of computeFn(src).
local detail = I.forSource(src, buildDetail)
typed/builtin//modules/luau_introspect/M/lifecycleHooks
M.lifecycleHooks(src: string, catalog: { string }) -> { string }
Finds top-level function <name>( declarations whose name is in
the caller-supplied catalog. Excludes local function, public:
methods, and M. exports — only a bare top-level function NAME(
declaration matches. Never hardcodes the lifecycle-callback catalog;
the caller passes the list of names to match against. Commented-out
declarations never match.
Parameters
srcstring— Luau/asset source text.catalog{ string }— Array of lifecycle-callback names to match against.
Returns { string } — Array of matched hook names, source order preserved.
local hooks = I.lifecycleHooks(src, { "awake", "update" })
typed/builtin//modules/luau_introspect/M/maskNonCode
M.maskNonCode(src: string) -> string
A same-length copy of src where comment bodies and string-literal
contents are replaced by spaces (delimiters and newlines preserved),
so structural pattern matching over the result never registers a
comment or string body. Index-aligned with src — a match position in
the mask is the same position in src.
Parameters
srcstring— Luau/asset source text.
Returns string — The comment/string-masked copy.
local mask = I.maskNonCode(src); string.find(mask, "operations%s*=%s*{")
typed/builtin//modules/luau_introspect/M/methods
M.methods(src: string) -> { MethodEntry }
Parses function public:<name>(<params>) and typed function public:<name>(<params>) declarations — with an optional : <ret>
return-type annotation immediately after the closing paren — into
{name, params, returns}. Each param is split on top-level commas
into {name, type?}; a ... variadic is captured with name = "...".
Folds in desc from docstrings(src).
Parameters
srcstring— Luau/asset source text.
Returns { MethodEntry } — Ordered array of method entries, source order preserved.
local m = I.methods(src); print(m[1].name, m[1].returns)
typed/builtin//modules/luau_introspect/M/moduleExports
M.moduleExports(src: string) -> { ExportEntry }
Parses M.<name> = function(...) assignments, function M.<name>(...) declarations, and a trailing return { foo = foo, ... }
export table into {name, kind, signature?, desc?}. kind is
"function" for a function assignment/declaration, "value" for any
other M.<name> = <expr> assignment (a == comparison is not an
assignment). A name that appears only in the return { ... } table
infers its kind from whether a same-named function <name>( /
local function <name>( declaration exists. Folds in desc from
docstrings(src).
Parameters
srcstring— Luau/asset source text.
Returns { ExportEntry } — Array of export entries, in source-scan order.
local exports = I.moduleExports(src); print(exports[1].name)
typed/builtin//modules/luau_introspect/M/privateFields
M.privateFields(src: string) -> { FieldEntry }
Parses the private = { name = Field.<kind>(...), ... } table
literal the way publicFields parses public: each entry's kind, its
default and the arguments ahead of it, and its sync. A private field
a component marks Serialized is saved with the scene like a public
one, so a reader comparing saved state against declared defaults needs
both.
Parameters
srcstring— Luau/asset source text.
Returns { FieldEntry } — Ordered array of field entries, source order preserved.
local f = I.privateFields(src); print(f[1].name, f[1].default)
typed/builtin//modules/luau_introspect/M/publicFields
M.publicFields(src: string) -> { FieldEntry }
Parameters
srcstring
Returns { FieldEntry }
typed/builtin//modules/luau_introspect/M/refMethods
M.refMethods(src: string) -> { MethodEntry }
Parses the methods a behavior.luau-style module exposes on a
M.ref = { name = fn, ... } table — the assetType's per-asset behavior
surface (ref:method(...)). Each entry's key maps to its backing
local function <fn>(self, <params>): <ret> (or function <fn>(...))
declaration: the leading self parameter is dropped (it is the ref the
method is called on), the remaining params + return annotation + the
declaration's --!desc are captured, with hidden and deprecated
from its --!hidden / --!deprecated lines, so a listing can leave a
hidden method out while a type shape still carries it. A key whose
value is a table literal or an expression other than a bare function
name is skipped.
Runs over the comment/string-aware mask, so a commented M.ref never
registers.
Parameters
srcstring— Luau/asset source text.
Returns { MethodEntry } — Ordered array of method entries (source order of the M.ref keys).
local api = I.refMethods(behaviorSrc); print(api[1].name, api[1].returns)
typed/builtin//modules/luau_introspect/M/tableLiteral
M.tableLiteral(src: string, assignmentName: string) -> TableNode?
Parses a named table literal assignmentName = { ... } into a nested
TableNode — each top-level key = value becomes an entry whose value is
either a scalar (the trimmed source text of a non-table value, quotes
included) or a nested table (TableNode) when the value is itself a
{ ... }. Runs over the comment/string-aware mask, so a key, {, or
} inside a comment or string never registers. Computed ([expr] =) and
positional entries are skipped. Returns nil when the assignment is absent.
Parameters
srcstring— Luau/asset source text.assignmentNamestring— The table's assignment name (a Lua pattern, e.g. "operations" or "M%.tokens").
Returns TableNode? — The parsed TableNode, or nil.
local ops = I.tableLiteral(src, "operations")
typed/builtin//modules/luau_introspect/M/tableLiteralKeys
M.tableLiteralKeys(src: string, assignmentName: string) -> { string }
Finds <assignmentName> = { ... } in src and returns the top-level
literal-identifier keys of that table (e.g. tableLiteralKeys(src, "operations") on operations = { generate = {...}, from_image = {...} } returns {"generate","from_image"}). Runs over the
comment/string-aware mask, so a -- comment or string literal
mentioning the assignment name never registers. Comment/string/nesting
inside a value never breaks the scan (balanced brace matching, same as
publicFields/events). A computed ["key"] entry is omitted — only
bare identifier keys are recognised. Returns {} when the assignment
is absent.
Parameters
srcstring— Luau/asset source text.assignmentNamestring— The table's assignment name (e.g. "operations").
Returns { string } — Array of top-level key names, source order preserved.
local ops = I.tableLiteralKeys(src, "operations")
typed/builtin//modules/material_utils/M/Apply
M.Apply(entityId: string, materialRef: MaterialRefOrName) -> boolean
PascalCase back-compat alias for apply.
Parameters
entityIdstring— Target entity id.materialRefMaterialRefOrName— Either an AssetRef envelope or a material-name string.
Returns boolean — True on success.
typed/builtin//modules/material_utils/M/Create
M.Create(name: string, opts_or_shader: MaterialOpts | string | nil?, props: MaterialOpts?) -> MaterialRef?
PascalCase back-compat alias for create. Accepts the legacy 3-arg form (name, shader_string, opts_table) by folding shader into opts, and the canonical 2-arg form (name, opts).
Parameters
namestring— Material name.opts_or_shaderMaterialOpts | string | nil(optional) — Either an options table OR a legacy shader string.propsMaterialOpts(optional) — Optional extra options table — only used whenopts_or_shaderis a shader string.
Returns MaterialRef? — The AssetRef envelope, or nil on failure.
Material.Create("gold", "pbr", { color = { 1, 0.85, 0.2 } }) -- legacy 3-arg
Material.Create("gold", { shader = "pbr", color = { 1, 0.85, 0.2 } }) -- canonical
Material.Create("neon", { shader = "pbr", emissive = { 0.1, 0.9, 1 }, emissive_intensity = 5 }) -- cyan glow at 5× intensity
typed/builtin//modules/material_utils/M/Exists
M.Exists(name: MaterialRefOrName) -> boolean
PascalCase back-compat alias for exists.
Parameters
nameMaterialRefOrName— AssetRef envelope or material-name string.
Returns boolean — True when the material is registered.
typed/builtin//modules/material_utils/M/GetProperty
M.GetProperty(materialName: MaterialRefOrName, propertyName: string) -> any
PascalCase back-compat alias for getProperty.
Parameters
materialNameMaterialRefOrName— AssetRef envelope or material-name string.propertyNamestring— Property name.
Returns any — The property value, or nil when not found.
typed/builtin//modules/material_utils/M/GetPropertyNames
M.GetPropertyNames(materialName: MaterialRefOrName) -> { string }?
PascalCase back-compat alias for getPropertyNames.
Parameters
materialNameMaterialRefOrName— AssetRef envelope or material-name string.
Returns { string }? — Array of property names, or nil when the material is not found.
typed/builtin//modules/material_utils/M/SetProperty
M.SetProperty(materialName: MaterialRefOrName, property: string, value: any?) -> any
PascalCase alias. Writes the property on the material ASSET by name/ref (a runtime change every entity using it takes; matRef:saveDefinition() writes it into mat.yaml) — distinct from M.setProperty, which targets the material on one entity's model.
Parameters
materialNameMaterialRefOrName— AssetRef envelope or material-name string.propertystring— Property name.valueany(optional) — New value.
Returns any — True on success.
Material.SetProperty("gold", "roughness", 0.1)
typed/builtin//modules/material_utils/M/SetTexture
M.SetTexture(materialName: MaterialRefOrName, slot: string, textureRef: string) -> boolean
PascalCase back-compat alias for setTexture.
Parameters
materialNameMaterialRefOrName— AssetRef envelope or material-name string.slotstring— Texture slot name ("albedo","normal", etc.).textureRefstring— Texture reference string.
Returns boolean — True on success.
typed/builtin//modules/material_utils/M/Update
M.Update(target: any?, props: { [string]: any }) -> number
PascalCase alias for update.
Parameters
targetany(optional) — Material name / AssetRef, OR an entity — a proxy, an entity-id, or the display name the entity carries.props{ [string]: any }— Table of{ [propertyName] = value }pairs.
Returns number — Number of properties applied.
Material.Update("gold", { base_color = { 1, 0, 0 }, roughness = 0.15 })
typed/builtin//modules/material_utils/M/apply
M.apply(entity: any?, materialRef: MaterialRefOrName) -> boolean
Apply a material to an entity's Model / SkinnedModel component by setting its material field. Accepts either an AssetRef envelope (from Material.create) or a bare material-name string. Errors when the entity has no Model or SkinnedModel — a material only renders where there is a mesh.
Parameters
entityany(optional) — The entity to apply to — an entity proxy (recommended: a validated handle to a real entity), an entity-id string, or the display name the entity carries.materialRefMaterialRefOrName— Either an AssetRef envelope or a material-name string.
Returns boolean — True on success.
Material.apply(entityId, "gold")
local mat = assert(Material.create("gold", { color = { 1, 0.8, 0.3, 1 }, metallic = 1 })); Material.apply(entityId, mat)
typed/builtin//modules/material_utils/M/create
M.create(name: string, opts: MaterialOpts?) -> MaterialRef?
Create a named material in the MaterialRegistry. Returns the canonical AssetRef envelope ({ __ref, type="material", name, guid }) — pass directly to Material.apply, the Model / SkinnedModel material field, or any AssetRef<material> consumer.
Parameters
namestring— Material name. Must be a non-empty string.optsMaterialOpts(optional) — Optional material options.shader?,color?,roughness?,metallic?,emissive?(the glow colour),emissive_intensity?(the HDR multiplier over it),textures?.
Returns MaterialRef? — The AssetRef envelope on success, or nil on failure.
local gold = Material.create("gold", { color = { 1, 0.85, 0.2 }, metallic = 1 })
typed/builtin//modules/material_utils/M/exists
M.exists(name: MaterialRefOrName) -> boolean
Check whether a material exists in the registry. Accepts an AssetRef envelope or a bare material name.
Parameters
nameMaterialRefOrName— AssetRef envelope or material-name string.
Returns boolean — True when the material is registered.
if Material.exists("gold") then ... end
typed/builtin//modules/material_utils/M/getProperty
M.getProperty(materialName: MaterialRefOrName, propertyName: string) -> any
Read the current value of a material property.
Parameters
materialNameMaterialRefOrName— AssetRef envelope or material-name string.propertyNamestring— Property name ("roughness","metallic","base_color", etc.).
Returns any — The property value, or nil when not found.
local r = Material.getProperty("gold", "roughness")
typed/builtin//modules/material_utils/M/getPropertyNames
M.getPropertyNames(materialName: MaterialRefOrName) -> { string }?
List the property names exposed by a registered material.
Parameters
materialNameMaterialRefOrName— AssetRef envelope or material-name string.
Returns { string }? — Array of property names, or nil when the material is not found.
local props = Material.getPropertyNames("gold")
typed/builtin//modules/material_utils/M/setProperties
M.setProperties(target: any?, props: { [string]: any }) -> number
Set many material properties in one call. Addresses the target the same
way setProperty does: a material name / AssetRef writes the material ASSET
(affecting every entity using it), an entity proxy / entity-id / entity name writes the
material bound to that entity's Model / SkinnedModel. Each key resolves
against the shader's declared vocabulary, so the spellings create accepts
reach the same uniforms; a key the shader does not expose is skipped, which
lets one patch table serve materials built on different shaders.
Parameters
targetany(optional) — Material name / AssetRef, OR an entity — a proxy, an entity-id, or the display name the entity carries.props{ [string]: any }— Table of{ [propertyName] = value }pairs.
Returns number — Number of properties applied.
Material.setProperties("gold", { roughness = 0.2, metallic = 0.9 })
Material.setProperties(entityId, { base_color = { 1, 0, 0 } })
typed/builtin//modules/material_utils/M/setProperty
M.setProperty(target: any?, property: string, value: any?)
Set a material property. Addresses the target the same way getProperty does: pass a material name / AssetRef to write the material ASSET (affecting every entity using it), or an entity — a proxy, an id, or a display name — to write the material bound to that entity's Model / SkinnedModel. Errors when an entity target has no Model or SkinnedModel.
Parameters
targetany(optional) — Material name / AssetRef, OR an entity — a proxy, an entity-id, or the display name the entity carries.propertystring— Property name.valueany(optional) — New value (type depends on the property).
Material.setProperty("gold", "roughness", 0.4) -- by material name
Material.setProperty(entityId, "roughness", 0.4) -- by entity
typed/builtin//modules/material_utils/M/setTexture
M.setTexture(materialName: MaterialRefOrName, slot: string, textureRef: any?) -> boolean
Set a texture slot on a named material.
Parameters
materialNameMaterialRefOrName— AssetRef envelope or material-name string.slotstring— Texture slot name ("albedo","normal", etc.).textureRefany(optional) — Texture reference. Formats:"color:r,g,b,a","@builtin::textures.foo", or a render-output guid (camera target, video handle).
Returns boolean — True on success.
Material.setTexture("gold", "albedo", "@builtin::textures.gold")
typed/builtin//modules/material_utils/M/update
M.update(target: any?, props: { [string]: any }) -> number
Change an existing material from a property table — the counterpart to
create, taking the same table shape. Addresses its target and counts its
writes the way setProperties does.
Parameters
targetany(optional) — Material name / AssetRef, OR an entity — a proxy, an entity-id, or the display name the entity carries.props{ [string]: any }— Table of{ [propertyName] = value }pairs.
Returns number — Number of properties applied.
Material.update("gold", { color = { 1, 0.85, 0.2 }, roughness = 0.15 })
typed/builtin//modules/numberSequence/M/deserialize
M.deserialize(data: any?) -> NumberSequenceObj
Rebuild a NumberSequence from a {kind = "NumberSequence", keypoints = {...}} payload produced by :serialize(). Used by scene save/load.
Parameters
dataany(optional) — The serialized payload.
Returns NumberSequenceObj — A fresh NumberSequenceObj with the deserialized keypoints.
local s = NumberSequence.deserialize(savedData)
typed/builtin//modules/numberSequence/M/new
M.new(...: any?) -> NumberSequenceObj
Construct a NumberSequence from one of three signatures: a constant value, a two-point lerp from v0 to v1, or a keypoints array of { time, value, envelope? } records. Envelope defaults to 0 when omitted. Up to 64 keypoints; the first must anchor at time = 0, the last at time = 1. NaN / Inf in time / value / envelope is rejected.
Parameters
...any(optional) —(v),(v0, v1), or({ {time, value, envelope?}, ... }).
Returns NumberSequenceObj — A NumberSequenceObj with :evaluate, :sample, :keypoints, :duration, :serialize, :destroy.
local fade = NumberSequence.new(1.0)
local fadeOut = NumberSequence.new(1.0, 0.0)
local size = NumberSequence.new({{time=0,value=0.5,envelope=0.1},{time=0.5,value=1.5},{time=1,value=0}})
typed/builtin//modules/number_range/M/new
M.new(min: number, max: number?) -> any
Construct a NumberRange. Pass one number for a constant range
(min == max); pass two for a uniform random range. Reversed
arguments are normalized to ascending order.
Parameters
minnumber— Lower bound.maxnumber(optional) — Upper bound; defaults tomin.
Returns any
local lifetime = NumberRange.new(1.0) -- always 1.0
local speed = NumberRange.new(0.5, 2.0) -- random
typed/builtin//modules/nx/gpu/M/fft1d
M.fft1d(opts: Fft1dOpts) -> boolean
1D complex FFT over a power-of-two-sized interleaved complex
GPU buffer. size is the number of complex samples (must be
a power of two ≥ 2). Pass the same input / output handle for
in-place.
Parameters
optsFft1dOpts—{ input, output?, size, inverse? }.input/outputare GPU buffer handles;outputdefaults toinput.inverse=trueruns the inverse transform (scaled by 1/N).
Returns boolean — true on success, false on validation failure (non-pow2 size, missing buffers).
M.fft1d({ input = specIn, output = specOut, size = 1024 })
typed/builtin//modules/nx/gpu/M/fft2d
M.fft2d(opts: Fft2dOpts) -> boolean
2D complex FFT over a power-of-two-sized row-major interleaved complex GPU buffer. Width and height must both be powers of two ≥ 2.
Parameters
optsFft2dOpts—{ input, output?, width, height, inverse? }.input/outputare GPU buffer handles;outputdefaults toinput.inverse=trueruns the inverse (scaled by 1/(width*height)).
Returns boolean — true on success, false on validation failure (non-pow2 dims, missing buffers).
M.fft2d({ input = imgIn, output = imgOut, width = 256, height = 256 })
typed/builtin//modules/nx/gpu/M/ifft1d
M.ifft1d(opts: Fft1dOpts) -> boolean
Convenience: forward 1D FFT with inverse=true — equivalent
to M.fft1d(opts) after stamping opts.inverse = true.
Parameters
optsFft1dOpts— Same asM.fft1d. Mutatesopts.inverse.
Returns boolean — true on success, false on validation failure.
M.ifft1d({ input = specIn, output = specOut, size = 1024 })
typed/builtin//modules/nx/gpu/M/ifft2d
M.ifft2d(opts: Fft2dOpts) -> boolean
Convenience: forward 2D FFT with inverse=true — equivalent
to M.fft2d(opts) after stamping opts.inverse = true.
Parameters
optsFft2dOpts— Same asM.fft2d. Mutatesopts.inverse.
Returns boolean — true on success, false on validation failure.
M.ifft2d({ input = imgIn, output = imgOut, width = 256, height = 256 })
typed/builtin//modules/nx/nx/add
nx.add(dst: NxBuffer, x: NxScalarOrBuffer) -> boolean
b[i] += x (x scalar) or b[i] += x[i] (x buffer).
Dispatches on type(x). For interleaved-stride writes use
nx.addStrided.
Parameters
dstNxBuffer— Target buffer (mutated).xNxScalarOrBuffer— Either a scalar or a same-shaped buffer.
Returns boolean — true on success, false on type / handle errors.
nx.add(b, 1.5)
nx.add(dst, src)
typed/builtin//modules/nx/nx/addStrided
nx.addStrided(b: NxBuffer, scalar: number, stride: number, offset: number?) -> boolean
Strided add: buf[k * stride + offset] += scalar for every
valid k.
Parameters
bNxBuffer— Target buffer (mutated).scalarnumber— Per-element addend.stridenumber— Element stride.offsetnumber(optional) — Optional element offset (default 0).
Returns boolean — true on success, false on unknown handle.
nx.addStrided(buf, 1.0, 3, 1)
typed/builtin//modules/nx/nx/addStridedFrom
nx.addStridedFrom(dst: NxBuffer, src: NxBuffer, scale: number?, dst_stride: number, dst_off: number?, src_stride: number, src_off: number?) -> boolean
Strided BLAS-axpy from src into dst:
dst[k * dst_stride + dst_off] += scale * src[k * src_stride + src_off].
Parameters
dstNxBuffer— Target buffer (mutated).srcNxBuffer— Source buffer.scalenumber(optional) — Optionalsrcscale factor (default 1.0).dst_stridenumber— Destination element stride.dst_offnumber(optional) — Optional destination offset (default 0).src_stridenumber— Source element stride.src_offnumber(optional) — Optional source offset (default 0).
Returns boolean — true on success, false on shape mismatch / unknown handle.
nx.addStridedFrom(dst, src, 1, 3, 0, 3, 0)
typed/builtin//modules/nx/nx/applyAbs
nx.applyAbs(b: NxBuffer) -> boolean
In-place b[i] = abs(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyAbs(b)
typed/builtin//modules/nx/nx/applyCeil
nx.applyCeil(b: NxBuffer) -> boolean
In-place b[i] = ceil(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyCeil(b)
typed/builtin//modules/nx/nx/applyCos
nx.applyCos(b: NxBuffer) -> boolean
In-place b[i] = cos(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyCos(b)
typed/builtin//modules/nx/nx/applyExp
nx.applyExp(b: NxBuffer) -> boolean
In-place b[i] = exp(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyExp(b)
typed/builtin//modules/nx/nx/applyFloor
nx.applyFloor(b: NxBuffer) -> boolean
In-place b[i] = floor(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyFloor(b)
typed/builtin//modules/nx/nx/applyFract
nx.applyFract(b: NxBuffer) -> boolean
In-place b[i] = fract(b[i]) (fractional part).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyFract(b)
typed/builtin//modules/nx/nx/applyLog
nx.applyLog(b: NxBuffer) -> boolean
In-place b[i] = ln(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyLog(b)
typed/builtin//modules/nx/nx/applyLog2
nx.applyLog2(b: NxBuffer) -> boolean
In-place b[i] = log2(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyLog2(b)
typed/builtin//modules/nx/nx/applyNeg
nx.applyNeg(b: NxBuffer) -> boolean
In-place b[i] = -b[i].
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyNeg(b)
typed/builtin//modules/nx/nx/applyRecip
nx.applyRecip(b: NxBuffer) -> boolean
In-place b[i] = 1 / b[i].
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyRecip(b)
typed/builtin//modules/nx/nx/applyRecipSqrt
nx.applyRecipSqrt(b: NxBuffer) -> boolean
In-place b[i] = 1 / sqrt(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyRecipSqrt(b)
typed/builtin//modules/nx/nx/applyRound
nx.applyRound(b: NxBuffer) -> boolean
In-place b[i] = round(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyRound(b)
typed/builtin//modules/nx/nx/applySign
nx.applySign(b: NxBuffer) -> boolean
In-place b[i] = sign(b[i]) (returns -1, 0, or +1).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applySign(b)
typed/builtin//modules/nx/nx/applySin
nx.applySin(b: NxBuffer) -> boolean
In-place b[i] = sin(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applySin(b)
typed/builtin//modules/nx/nx/applySqrt
nx.applySqrt(b: NxBuffer) -> boolean
In-place b[i] = sqrt(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applySqrt(b)
typed/builtin//modules/nx/nx/applySquare
nx.applySquare(b: NxBuffer) -> boolean
In-place b[i] = b[i] * b[i].
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applySquare(b)
typed/builtin//modules/nx/nx/applyTan
nx.applyTan(b: NxBuffer) -> boolean
In-place b[i] = tan(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyTan(b)
typed/builtin//modules/nx/nx/applyTrunc
nx.applyTrunc(b: NxBuffer) -> boolean
In-place b[i] = trunc(b[i]).
Parameters
bNxBuffer— Target buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyTrunc(b)
typed/builtin//modules/nx/nx/applyWindow
nx.applyWindow(signal: NxBuffer, window: NxBuffer) -> boolean
Element-wise signal[i] *= window[i] in place. Operates over
the shorter of the two — passing a longer window to window a
shorter clip is intentional, not an error.
Parameters
signalNxBuffer— Signal buffer (mutated).windowNxBuffer— Window buffer.
Returns boolean — true on success, false on unknown handle.
nx.applyWindow(signal, hann)
typed/builtin//modules/nx/nx/axpby
nx.axpby(dst: NxBuffer, a: number, src: NxBuffer, b: number) -> boolean
BLAS axpby: dst[i] = a*dst[i] + b*src[i].
Parameters
dstNxBuffer— Target buffer (mutated).anumber— Scale applied todst.srcNxBuffer— Source buffer.bnumber— Scale applied tosrc.
Returns boolean — true on success, false on stride mismatch / unknown handle.
nx.axpby(y, 0.5, x, 2.0)
typed/builtin//modules/nx/nx/clamp
nx.clamp(b: NxBuffer, min_v: number, max_v: number) -> boolean
In-place clamp: b[i] = clamp(b[i], min_v, max_v).
Parameters
bNxBuffer— Target buffer (mutated).min_vnumber— Lower bound.max_vnumber— Upper bound.
Returns boolean — true on success, false on unknown handle.
nx.clamp(b, 0.0, 1.0)
typed/builtin//modules/nx/nx/copy
nx.copy(dst: NxBuffer, src: NxBuffer) -> boolean
Copy every record from src into dst (memcpy fast path).
Parameters
dstNxBuffer— Target buffer (mutated).srcNxBuffer— Source buffer.
Returns boolean — true on success, false on shape mismatch or unknown handle.
nx.copy(dst, src)
typed/builtin//modules/nx/nx/copyStridedFrom
nx.copyStridedFrom(dst: NxBuffer, src: NxBuffer, scale: number?, dst_stride: number, dst_off: number?, src_stride: number, src_off: number?) -> boolean
Strided copy from src into dst with optional scaling:
dst[k * dst_stride + dst_off] = scale * src[k * src_stride + src_off].
Parameters
dstNxBuffer— Target buffer (mutated).srcNxBuffer— Source buffer.scalenumber(optional) — Optionalsrcscale factor (default 1.0).dst_stridenumber— Destination element stride.dst_offnumber(optional) — Optional destination offset (default 0).src_stridenumber— Source element stride.src_offnumber(optional) — Optional source offset (default 0).
Returns boolean — true on success, false on shape mismatch / unknown handle.
nx.copyStridedFrom(dst, src, 1, 3, 0, 3, 0)
typed/builtin//modules/nx/nx/create
nx.create(type_: NxType, n: number) -> NxBuffer?
Allocate a CPU buffer of type × len records. Thin alias for
substrate.createBuffer({type=type_, len=n, kind="cpu"}) — kept here so the
public nx library is the canonical entry point and users never
need to import buffer separately.
Parameters
type_NxType— Element layout ("f32","vec3","vec4","quat","mat4").nnumber— Record count.
Returns NxBuffer? — Freshly allocated buffer handle, or nil on failure.
local b = nx.create("vec3", 1024)
typed/builtin//modules/nx/nx/div
nx.div(dst: NxBuffer, x: NxScalarOrBuffer) -> boolean
b[i] /= x (x scalar) or b[i] /= x[i] (x buffer).
Parameters
dstNxBuffer— Target buffer (mutated).xNxScalarOrBuffer— Either a scalar or a same-shaped buffer.
Returns boolean — true on success, false on type / handle errors.
nx.div(b, 2)
nx.div(dst, src)
typed/builtin//modules/nx/nx/dot
nx.dot(a: NxBuffer, b: NxBuffer) -> number?
Reduction: dot product of two same-shaped buffers.
Parameters
aNxBuffer— First buffer.bNxBuffer— Second buffer.
Returns number? — Scalar dot product, or nil on shape mismatch / unknown handle.
local d = nx.dot(a, b)
typed/builtin//modules/nx/nx/fft1d
nx.fft1d(re: NxBuffer, im: NxBuffer, inverse: boolean?) -> boolean
In-place 1D FFT over parallel re / im CPU buffers.
inverse=true runs the inverse transform scaled by 1/N (so
ifft(fft(x)) ≈ x).
Parameters
reNxBuffer— Real-component buffer (mutated).imNxBuffer— Imaginary-component buffer (mutated).inverseboolean(optional) — Whentrueruns the inverse transform.
Returns boolean — true on success, false on length mismatch / invalid handle. Raises an error naming the bytes when the transform's plan or working memory cannot be held.
nx.fft1d(re, im)
nx.fft1d(re, im, true)
typed/builtin//modules/nx/nx/fft2d
nx.fft2d(re: NxBuffer, im: NxBuffer, width: number, height: number, inverse: boolean?) -> boolean
In-place 2D FFT over row-major parallel re / im buffers
of length width*height. inverse=true is scaled by
1 / (width * height).
Parameters
reNxBuffer— Real-component buffer (mutated).imNxBuffer— Imaginary-component buffer (mutated).widthnumber— 2D width in samples.heightnumber— 2D height in samples.inverseboolean(optional) — Whentrueruns the inverse transform.
Returns boolean — true on success, false on length mismatch / invalid handle. Raises an error naming the bytes when the transform's plan or working memory cannot be held.
nx.fft2d(re, im, w, h)
typed/builtin//modules/nx/nx/fill
nx.fill(b: NxBuffer, value: number?) -> boolean
Fill the buffer with value (default 0.0). Equivalent to the
scalar form of nx.add against a zeroed buffer, but skips the
type-dispatch.
Parameters
bNxBuffer— Target buffer (mutated).valuenumber(optional) — Fill value (default 0.0).
Returns boolean — true on success, false on unknown handle.
nx.fill(b, 3.5)
typed/builtin//modules/nx/nx/fillRandomNormal
nx.fillRandomNormal(b: NxBuffer, mean: number?, stddev: number?, seed: NxSeed) -> boolean
Fill the buffer with Gaussian samples (Box-Muller), with the given mean and standard deviation, using a splitmix-keyed PRNG.
Parameters
bNxBuffer— Target buffer (mutated).meannumber(optional) — Optional mean (default 0.0).stddevnumber(optional) — Optional standard deviation (default 1.0).seedNxSeed— Optional seed — number,"frame", ornil(0).
Returns boolean — true on success, false on unknown handle.
nx.fillRandomNormal(b, 0, 1, 42)
typed/builtin//modules/nx/nx/fillRandomUniform
nx.fillRandomUniform(b: NxBuffer, min_v: number?, max_v: number?, seed: NxSeed) -> boolean
Fill the buffer with uniform-random samples in [min, max),
using a splitmix-keyed deterministic PRNG.
Parameters
bNxBuffer— Target buffer (mutated).min_vnumber(optional) — Optional lower bound (default 0.0).max_vnumber(optional) — Optional upper bound (default 1.0).seedNxSeed— Optional seed — number,"frame"(per-frame value), ornil(0).
Returns boolean — true on success, false on unknown handle.
nx.fillRandomUniform(b, -1, 1, "frame")
typed/builtin//modules/nx/nx/fillStrided
nx.fillStrided(b: NxBuffer, value: number, stride: number, offset: number?) -> boolean
Strided fill: buf[k * stride + offset] = value for every
valid k.
Parameters
bNxBuffer— Target buffer (mutated).valuenumber— Per-element value.stridenumber— Element stride.offsetnumber(optional) — Optional element offset (default 0).
Returns boolean — true on success, false on unknown handle.
nx.fillStrided(buf, 0, 3, 2)
typed/builtin//modules/nx/nx/fromTable
nx.fromTable(arr: { number }, type_: NxType?) -> NxBuffer?
Build a CPU buffer from a Lua table of numbers. The table is
written through buf:write in a single FFI crossing — no
per-element Lua loop. For large arrays, prefer one of the
nx.* constructors + a kernel pass over building a Lua array
first.
Parameters
arr{ number }— Lua array of numbers.type_NxType(optional) — Optional element layout (default"f32").
Returns NxBuffer? — Newly allocated buffer holding arr, or nil on failure.
local b = nx.fromTable({ 0.1, 0.2, 0.3 })
typed/builtin//modules/nx/nx/full
nx.full(n: number, type_: NxType?, value: number?) -> NxBuffer?
Allocate a buffer of type × len records and fill with value.
Parameters
nnumber— Record count.type_NxType(optional) — Optional element layout (default"f32").valuenumber(optional) — Fill value (default 0.0).
Returns NxBuffer? — Buffer initialised to value.
local b = nx.full(1024, "f32", -1.0)
typed/builtin//modules/nx/nx/ifft1d
nx.ifft1d(re: NxBuffer, im: NxBuffer) -> boolean
Convenience: nx.fft1d(re, im, true).
Parameters
reNxBuffer— Real-component buffer (mutated).imNxBuffer— Imaginary-component buffer (mutated).
Returns boolean — true on success, false on length mismatch / invalid handle. Raises an error naming the bytes when the transform's plan or working memory cannot be held.
nx.ifft1d(re, im)
typed/builtin//modules/nx/nx/ifft2d
nx.ifft2d(re: NxBuffer, im: NxBuffer, width: number, height: number) -> boolean
Convenience: nx.fft2d(re, im, w, h, true).
Parameters
reNxBuffer— Real-component buffer (mutated).imNxBuffer— Imaginary-component buffer (mutated).widthnumber— 2D width.heightnumber— 2D height.
Returns boolean — true on success, false on length mismatch / invalid handle. Raises an error naming the bytes when the transform's plan or working memory cannot be held.
nx.ifft2d(re, im, w, h)
typed/builtin//modules/nx/nx/integratePosition
nx.integratePosition(pos: NxBuffer, vel: NxBuffer, dt: number) -> boolean
Per-vec3: pos[i] += vel[i] * dt — the position half of an
Euler step. Both buffers must be vec3 (stride 3). The velocity step
is the caller's: update vel BEFORE this call for semi-implicit
Euler; updating it after gives forward Euler, which gains energy on
stiff systems.
Parameters
posNxBuffer— Position buffer (mutated).velNxBuffer— Velocity buffer.dtnumber— Time step.
Returns boolean — true on success, false on shape mismatch / unknown handle.
nx.integratePosition(pos, vel, dt)
typed/builtin//modules/nx/nx/irfft1d
nx.irfft1d(re: NxBuffer, im: NxBuffer) -> NxBuffer?
Real-output inverse 1D FFT. Input re / im are length
N/2 + 1. Returns a fresh CPU f32 buffer of length
2 * (N/2 + 1 - 1) = N real samples.
Parameters
reNxBuffer— Real-component buffer.imNxBuffer— Imaginary-component buffer.
Returns NxBuffer? — Real-valued output buffer on success, nil on failure. Raises an error naming the bytes when the transform's plan or working memory cannot be held. A call that answers nil or raises leaves none of the buffers it created allocated.
local out = nx.irfft1d(re, im)
typed/builtin//modules/nx/nx/irfft2d
nx.irfft2d(re: NxBuffer, im: NxBuffer, width: number, height: number) -> NxBuffer?
Real-output inverse 2D FFT. Input re / im are
(width/2 + 1) * height row-major. Returns a fresh f32 buffer
of length width * height.
Parameters
reNxBuffer— Real-component buffer.imNxBuffer— Imaginary-component buffer.widthnumber— 2D width.heightnumber— 2D height.
Returns NxBuffer? — Real-valued output buffer on success, nil on failure. Raises an error naming the bytes when the transform's plan or working memory cannot be held. A call that answers nil or raises leaves none of the buffers it created allocated.
local out = nx.irfft2d(re, im, w, h)
typed/builtin//modules/nx/nx/lerpTo
nx.lerpTo(dst: NxBuffer, src: NxBuffer, t: number) -> boolean
dst[i] += t * (src[i] - dst[i]) — element-wise lerp toward
src by t.
Parameters
dstNxBuffer— Target buffer (mutated).srcNxBuffer— Source buffer.tnumber— Interpolation factor.
Returns boolean — true on success, false on stride mismatch / unknown handle.
nx.lerpTo(current, target, 0.1)
typed/builtin//modules/nx/nx/max
nx.max(b: NxBuffer) -> number?
Reduction: maximum of all elements.
Parameters
bNxBuffer— Source buffer.
Returns number? — Scalar max, or nil on unknown handle.
local m = nx.max(b)
typed/builtin//modules/nx/nx/maxOp
nx.maxOp(dst: NxBuffer, x: NxScalarOrBuffer) -> boolean
Element-wise b[i] = max(b[i], x) (scalar) or
b[i] = max(b[i], x[i]) (buffer).
Parameters
dstNxBuffer— Target buffer (mutated).xNxScalarOrBuffer— Scalar or same-shaped buffer.
Returns boolean — true on success, false on type / handle errors.
nx.maxOp(b, 0.0)
typed/builtin//modules/nx/nx/mean
nx.mean(b: NxBuffer) -> number?
Reduction: arithmetic mean of all elements.
Parameters
bNxBuffer— Source buffer.
Returns number? — Scalar mean, or nil on unknown handle.
local m = nx.mean(b)
typed/builtin//modules/nx/nx/min
nx.min(b: NxBuffer) -> number?
Reduction: minimum of all elements.
Parameters
bNxBuffer— Source buffer.
Returns number? — Scalar min, or nil on unknown handle.
local m = nx.min(b)
typed/builtin//modules/nx/nx/minOp
nx.minOp(dst: NxBuffer, x: NxScalarOrBuffer) -> boolean
Element-wise b[i] = min(b[i], x) (scalar) or
b[i] = min(b[i], x[i]) (buffer).
Parameters
dstNxBuffer— Target buffer (mutated).xNxScalarOrBuffer— Scalar or same-shaped buffer.
Returns boolean — true on success, false on type / handle errors.
nx.minOp(b, 1.0)
typed/builtin//modules/nx/nx/mul
nx.mul(dst: NxBuffer, x: NxScalarOrBuffer) -> boolean
b[i] *= x (x scalar) or b[i] *= x[i] (x buffer).
Parameters
dstNxBuffer— Target buffer (mutated).xNxScalarOrBuffer— Either a scalar or a same-shaped buffer.
Returns boolean — true on success, false on type / handle errors.
nx.mul(b, 2)
nx.mul(dst, src)
typed/builtin//modules/nx/nx/mulStrided
nx.mulStrided(b: NxBuffer, scalar: number, stride: number, offset: number?) -> boolean
Strided multiply: buf[k * stride + offset] *= scalar for
every valid k.
Parameters
bNxBuffer— Target buffer (mutated).scalarnumber— Per-element multiplier.stridenumber— Element stride.offsetnumber(optional) — Optional element offset (default 0).
Returns boolean — true on success, false on unknown handle.
nx.mulStrided(buf, 2, 4, 0)
typed/builtin//modules/nx/nx/normL1
nx.normL1(b: NxBuffer) -> number?
Reduction: L1 norm — sum(|b[i]|).
Parameters
bNxBuffer— Source buffer.
Returns number? — Scalar L1 norm, or nil on unknown handle.
local n = nx.normL1(b)
typed/builtin//modules/nx/nx/normL2
nx.normL2(b: NxBuffer) -> number?
Reduction: L2 norm — sqrt(sum(b[i]^2)).
Parameters
bNxBuffer— Source buffer.
Returns number? — Scalar L2 norm, or nil on unknown handle.
local n = nx.normL2(b)
typed/builtin//modules/nx/nx/normalizeVec3
nx.normalizeVec3(b: NxBuffer) -> boolean
Normalise each vec3 in-place. Vectors below 1e-8 are left untouched.
Parameters
bNxBuffer— Vec3 buffer (mutated).
Returns boolean — true on success, false on stride mismatch / unknown handle.
nx.normalizeVec3(directions)
typed/builtin//modules/nx/nx/ones
nx.ones(n: number, type_: NxType?) -> NxBuffer?
Allocate a buffer of type × len records and fill with 1.0.
Parameters
nnumber— Record count.type_NxType(optional) — Optional element layout (default"f32").
Returns NxBuffer? — Buffer initialised to one.
local b = nx.ones(1024)
typed/builtin//modules/nx/nx/pow
nx.pow(b: NxBuffer, p: number) -> boolean
In-place b[i] = b[i] ^ p (scalar exponent).
Parameters
bNxBuffer— Target buffer (mutated).pnumber— Scalar exponent.
Returns boolean — true on success, false on unknown handle.
nx.pow(b, 2.2)
typed/builtin//modules/nx/nx/quatFromYaw
nx.quatFromYaw(dst: NxBuffer, yaw: NxBuffer) -> boolean
Per-quat: dst[i] = (0, sin(yaw[i]/2), 0, cos(yaw[i]/2)) —
the pure-Y axis-angle quaternion for each yaw value. dst must
be stride-4 (quat); yaw must be stride-1 (f32).
Parameters
dstNxBuffer— Quaternion buffer (mutated).yawNxBuffer— Source yaw scalars buffer.
Returns boolean — true on success, false on shape mismatch / unknown handle.
nx.quatFromYaw(quats, yaws)
typed/builtin//modules/nx/nx/rfft1d
nx.rfft1d(signal: NxBuffer?) -> (NxBuffer?, NxBuffer?)
Real-input forward 1D FFT. Allocates two new CPU f32 buffers
of length N/2 + 1 holding the (re, im) parts of the
Hermitian-symmetric spectrum (same convention as NumPy
np.fft.rfft).
Parameters
signalNxBuffer(optional) — Real-valued input buffer.
Returns (NxBuffer?, NxBuffer?) — (re_buf, im_buf) on success, nil otherwise. Raises an error naming the bytes when the transform's plan or working memory cannot be held. A call that answers nil or raises leaves none of the buffers it created allocated.
local re, im = nx.rfft1d(signal)
typed/builtin//modules/nx/nx/rfft2d
nx.rfft2d(signal: NxBuffer, width: number, height: number) -> (NxBuffer?, NxBuffer?)
Real-input forward 2D FFT. Input signal is row-major
width*height. Returns (re_buf, im_buf) of length
(width/2 + 1) * height each (matches np.fft.rfft2 layout).
Parameters
signalNxBuffer— Real-valued input buffer (row-major).widthnumber— 2D width.heightnumber— 2D height.
Returns (NxBuffer?, NxBuffer?) — (re_buf, im_buf) on success, nil on failure. Raises an error naming the bytes when the transform's plan or working memory cannot be held. A call that answers nil or raises leaves none of the buffers it created allocated.
local re, im = nx.rfft2d(image, w, h)
typed/builtin//modules/nx/nx/scale
nx.scale(b: NxBuffer, s: number) -> boolean
In-place b[i] *= s.
Parameters
bNxBuffer— Target buffer (mutated).snumber— Scalar multiplier.
Returns boolean — true on success, false on unknown handle.
nx.scale(b, 0.5)
typed/builtin//modules/nx/nx/sinCosTo
nx.sinCosTo(src: NxBuffer, sin_dst: NxBuffer, cos_dst: NxBuffer) -> boolean
Compute sin_dst[i] = sin(src[i]) and cos_dst[i] = cos(src[i])
in one pass using cheaper paired-trig argument reduction.
Parameters
srcNxBuffer— Source angles buffer.sin_dstNxBuffer— Destination buffer for the sine values.cos_dstNxBuffer— Destination buffer for the cosine values.
Returns boolean — true on success, false on stride mismatch / unknown handle.
nx.sinCosTo(angles, s, c)
typed/builtin//modules/nx/nx/sub
nx.sub(dst: NxBuffer, x: NxScalarOrBuffer) -> boolean
b[i] -= x (x scalar) or b[i] -= x[i] (x buffer).
Parameters
dstNxBuffer— Target buffer (mutated).xNxScalarOrBuffer— Either a scalar or a same-shaped buffer.
Returns boolean — true on success, false on type / handle errors.
nx.sub(b, 0.5)
nx.sub(dst, src)
typed/builtin//modules/nx/nx/sum
nx.sum(b: NxBuffer) -> number?
Reduction: sum of all elements.
Parameters
bNxBuffer— Source buffer.
Returns number? — Scalar sum, or nil on unknown handle.
local s = nx.sum(b)
typed/builtin//modules/nx/nx/wanderYaw
nx.wanderYaw(args: NxWanderArgs) -> boolean
Fused per-entity wander step. Each entity's yaw[i] walks by
a uniform random delta in [-yawDelta, +yawDelta], then pos[i]
advances forward in the (sin yaw, cos yaw) direction by step.
Optional rot quat output writes a pure-Y axis-angle rotation.
Replaces the per-entity Luau loop pattern (~12 ms / 5000 in
interpreter) with a single Rust pass (~0.2 ms / 5000).
Buffer requirements: pos vec3 (stride 3), yaw f32 (stride 1),
rot optional quat (stride 4). All counts should match (kernel
walks min(count_i)).
Parameters
argsNxWanderArgs— Table with{ pos, yaw, rot?, step?, yawDelta?, seed }.
Returns boolean — true on success, false on stride / shape failures.
nx.wanderYaw({ pos = pos, yaw = yaw, step = 0.5, yawDelta = 0.2, seed = "frame" })
typed/builtin//modules/nx/nx/window/blackman
nx.window.blackman(n: number) -> NxBuffer?
Allocate a fresh CPU f32 buffer of length n filled with a
symmetric Blackman window (NumPy np.blackman convention).
Parameters
nnumber— Number of samples in the window.
Returns NxBuffer? — Buffer holding the window samples, or nil on failure.
local w = nx.window.blackman(1024)
typed/builtin//modules/nx/nx/window/hamming
nx.window.hamming(n: number) -> NxBuffer?
Allocate a fresh CPU f32 buffer of length n filled with a
symmetric Hamming window (NumPy np.hamming convention).
Parameters
nnumber— Number of samples in the window.
Returns NxBuffer? — Buffer holding the window samples, or nil on failure.
local w = nx.window.hamming(1024)
typed/builtin//modules/nx/nx/window/hann
nx.window.hann(n: number) -> NxBuffer?
Allocate a fresh CPU f32 buffer of length n filled with a
symmetric Hann window (NumPy np.hanning convention).
Parameters
nnumber— Number of samples in the window.
Returns NxBuffer? — Buffer holding the window samples, or nil on failure.
local w = nx.window.hann(1024)
typed/builtin//modules/nx/nx/zeros
nx.zeros(n: number, type_: NxType?) -> NxBuffer?
Allocate a buffer of type × len records and fill with 0.0.
Parameters
nnumber— Record count.type_NxType(optional) — Optional element layout (default"f32").
Returns NxBuffer? — Buffer initialised to zero.
local b = nx.zeros(2048)
typed/builtin//modules/preset/M/addDefault
M.addDefault(source: AssetRef<preset>, opts: { filter: string?, at: number? }?) -> number
Add one Preset Manager row for source, governing the declarer the
preset targets. opts.filter limits it to new things whose path
matches; opts.at places it (1 = first); it goes last otherwise.
Parameters
sourceAssetRef<preset>— The preset.opts{ filter: string?, at: number? }(optional) —{ filter?, at? }.
Returns number — The new row's index.
preset.addDefault("pixel_art")
typed/builtin//modules/preset/M/apply
M.apply(source: AssetRef<preset>, into: AssetRef | ComponentTarget) -> ApplyResult
Write a preset's values into something its target governs: an asset
whose settings the target declares, or a component on an entity, named
{ entity = <id>, component = <name> }, whose component the target is.
Struct groups merge field by field. Only valid fields are written; the
rest are returned in rejected.
Parameters
sourceAssetRef<preset>— The preset.intoAssetRef | ComponentTarget— The asset, or the component on an entity, to write into.
Returns ApplyResult — { applied, rejected, targetChanged }.
preset.apply("pixel_art", "hero_sprite")
preset.apply("red_tint", { entity = id, component = "Model" })
typed/builtin//modules/preset/M/capture
M.capture(from: AssetRef | ComponentTarget, name: string, opts: CaptureOpts?) -> AssetRef<preset>
Save the settings something has now as a new preset targeting the
declarer that governs them: an asset's settings, or the live values of a
component on an entity, named { entity = <id>, component = <name> }.
Parameters
fromAssetRef | ComponentTarget— The asset, or the component on an entity, whose values are captured.namestring— A bare name (lands in/source/presets/) or an absolute.presetpath.optsCaptureOpts(optional) —{ overwrite = true }re-authors an existing preset of that name, keeping its guid.
Returns AssetRef<preset> — The new preset.
local p = preset.capture("hero_sprite", "pixel_art")
local tint = preset.capture({ entity = id, component = "Model" }, "red_tint")
typed/builtin//modules/preset/M/defaultFor
M.defaultFor(declarer: AssetRef | string, path: string) -> ({ [string]: any }?, any?)
The values a new thing declarer governs would take from the
Preset Manager at path, and the row that gives them — the layer
itself, before the creating importer's and the caller's settings. A
path is a /source/... path for an asset or an import, and an entity's
hierarchy path for a component.
Parameters
declarerAssetRef | string— The declarer: an assetType, an importer or a component.pathstring— The new thing's path.
Returns ({ [string]: any }?, any?) — (values, match), or nil when no row matches.
local values, match = preset.defaultFor("@builtin::importers.texture", "/source/sprites/hero.png")
typed/builtin//modules/preset/M/defaults
M.defaults() -> { any }
The world's Preset Manager rows, in order. Each row names the
declarer it governs (target), the preset a new thing takes (preset)
and a glob over the new thing's path (filter), resolved, with every
problem that keeps it from applying.
Returns { any } — { { index, target, preset, filter, targetGuid, presetGuid, targetName, presetName, problems } }.
for _, row in ipairs(preset.defaults()) do print(row.index, row.targetName, row.presetName, row.filter) end
typed/builtin//modules/preset/M/removeDefault
M.removeDefault(index: number)
Remove the Preset Manager row at index. The other rows are kept
exactly as written, so removing succeeds while another row is broken.
Parameters
indexnumber— The row's index, aspreset.defaults()reports it.
preset.removeDefault(1)
typed/builtin//modules/preset/M/setDefaults
M.setDefaults(rows: { DefaultRowInput })
Replace the world's Preset Manager rows. Each row names a preset, optionally its declarer (the preset's own target when omitted) and a filter (empty matches everything). Every row is checked first; any problem refuses the whole write, naming every one. Rows change only what is created afterwards.
Parameters
rows{ DefaultRowInput }— The complete ordered rows.
preset.setDefaults({ { preset = "pixel_art", filter = "sprites/**" } })
typed/builtin//modules/preset/M/setValues
M.setValues(source: AssetRef<preset>, values: { [string]: any })
Replace a preset's values. The whole table is checked against the
target's schema first; any violation refuses the write, naming every one.
A preset in the component-only form is written in the typed form, its
target the component it names and its legacy name moved to the
.metadata title, as a heal moves it.
Parameters
sourceAssetRef<preset>— The preset.values{ [string]: any }— The complete values table the preset holds from now on.
preset.setValues("pixel_art", { filter = "nearest", generateMipmaps = false })
typed/builtin//modules/preset/M/values
M.values(source: AssetRef<preset>) -> ({ [string]: any }, Report)
A preset's values and a report on them. Every value is checked
against the target declarer's current schema: the fields that pass are
returned, every field that fails is listed by path in report.rejected,
report.pinned says the preset's .refs pins the target by guid, and
report.targetChanged says the target differs from the version pinned.
A preset still in the component-only form reads as authored, and
report.rejected lists what its component's schema would refuse.
Parameters
sourceAssetRef<preset>— The preset.
Returns ({ [string]: any }, Report) — (values, report), where report is { format, target, targetGuid, pinned, targetChanged, rejected }.
local values, report = preset.values("pixel_art")
typed/builtin//modules/random/M/fromState
M.fromState(state: string) -> RandomGenerator
Make a generator that continues a sequence from a position
rng:state() recorded. It draws exactly what the recorded generator
drew next, so a save holds the string and a load picks the stream up.
Parameters
statestring— The 32-character hex stringrng:state()returned.
Returns RandomGenerator — A generator at that position.
local resumed = Random.fromState(Random.new(7):state())
typed/builtin//modules/random/M/new
M.new(seed: number?) -> RandomGenerator
Make a generator with its own stream. The same seed gives the same
sequence on every platform and build; any number of generators run side
by side without moving one another or math.random. With no seed it
takes one from the clock, and rng:state() records where it stands.
Parameters
seednumber(optional) — Any finite number; every distinct number is a distinct stream. Omitted, the clock seeds it.
Returns RandomGenerator — A generator answering :nextNumber(), :nextNumber(min, max), :nextInteger(min, max), :clone() and :state().
local roll = Random.new(42):nextInteger(1, 6)
local jitter = Random.new(42):nextNumber(-0.5, 0.5)
local clockSeeded = Random.new()
typed/builtin//modules/render_visibility/Vis/showing
Vis.showing(e: any?) -> boolean?
Whether the entity's own renderable is showing, or nil when the entity
carries no renderable for a frame to reach.
Parameters
eany(optional) — Entity proxy.
Returns boolean? — True while the renderable is drawn, false while it is switched off, nil when the entity holds no renderable.
local showing = Vis.showing(entity.find("chunk_0_0_0"))
typed/builtin//modules/render_visibility/Vis/switchedOff
Vis.switchedOff(e: any?) -> boolean
Whether the frame reaches nothing this entity draws — the entity or an ancestor is inactive, or the mesh it draws through is switched off.
Parameters
eany(optional) — Entity proxy.
Returns boolean — True when nothing this entity draws reaches the frame.
if Vis.switchedOff(entity.find("rock")) then return end
typed/builtin//modules/rigmath/M/axisAngle
M.axisAngle(axis: { number }, angle: number) -> { number }
Quaternion from an axis and an angle in radians. The axis is normalized internally; a degenerate axis yields identity.
Parameters
axis{ number }— Rotation axis.anglenumber— Rotation angle in radians.
Returns { number } — The unit quaternion.
local q = rigmath.axisAngle({ 0, 1, 0 }, math.pi / 2)
typed/builtin//modules/rigmath/M/clamp
M.clamp(v: number, lo: number, hi: number) -> number
Clamp v into [lo, hi].
Parameters
vnumber— The value.lonumber— Lower bound.hinumber— Upper bound.
Returns number — The clamped value.
local w = rigmath.clamp(weight, 0, 1)
typed/builtin//modules/rigmath/M/computeBoneLengths
M.computeBoneLengths(bones: { any }, gPos: { { number } }) -> { number }
Each bone's length, measured as the distance to its farthest child. Retargeting uses this to scale root translation by rig proportion.
Parameters
bones{ any }— Array of{ parent };parentis 0-based, -1 for a root.gPos{ { number } }— Global positions parallel tobones, as returned bycomputeGlobals.
Returns { number } — Bone lengths, 1-based and parallel to bones. A leaf measures zero.
local lengths = rigmath.computeBoneLengths(rig.bones, gPos)
typed/builtin//modules/rigmath/M/computeGlobals
M.computeGlobals(bones: { any }) -> ({ { number } }, { { number } })
Resolve every bone's global rest rotation and position by forward kinematics over the local rest transforms. Handles any bone ordering — a parent may be listed after its child — by iterating until all resolve. A malformed cyclic parent falls back to the bone's local transform.
Parameters
bones{ any }— Array of{ parent, rest = { t, r } };parentis 0-based, -1 for a root.
Returns ({ { number } }, { { number } }) — Global rotations followed by global positions, both 1-based and parallel to bones.
local gRot, gPos = rigmath.computeGlobals(rig.bones)
typed/builtin//modules/rigmath/M/isFinite
M.isFinite(n: number) -> boolean
Whether a number is finite — neither NaN nor an infinity.
Parameters
nnumber— The number to test.
Returns boolean — True when n is finite.
if not rigmath.isFinite(x) then return end
typed/builtin//modules/rigmath/M/qangle
M.qangle(q: { number }) -> number
The rotation angle of a quaternion in radians, in [0, pi].
Parameters
q{ number }— The quaternion.
Returns number — Its rotation magnitude.
local a = rigmath.qangle(delta)
typed/builtin//modules/rigmath/M/qinverse
M.qinverse(q: { number }) -> { number }
Inverse of a unit quaternion, which is its conjugate. Normalizes first so a bind rotation that drifted slightly off unit still inverts cleanly.
Parameters
q{ number }— The quaternion to invert.
Returns { number } — The inverse quaternion.
local inv = rigmath.qinverse(parentGlobalRotation)
typed/builtin//modules/rigmath/M/qmul
M.qmul(a: { number }, b: { number }) -> { number }
Hamilton product a * b — apply b, then a. Matches glam's Quat
multiplication so results agree with the engine's own rig math.
Parameters
a{ number }— Outer rotation.b{ number }— Inner rotation.
Returns { number } — The composed quaternion.
local q = rigmath.qmul(parentGlobal, boneLocal)
typed/builtin//modules/rigmath/M/qnormalize
M.qnormalize(q: { number }) -> { number }
Normalize a quaternion to unit length. A degenerate quaternion returns identity rather than NaN.
Parameters
q{ number }— The quaternion.
Returns { number } — The unit quaternion.
local q = rigmath.qnormalize(accumulated)
typed/builtin//modules/rigmath/M/qrotvec
M.qrotvec(q: { number }, v: { number }) -> { number }
Rotate a 3-vector by a quaternion.
Parameters
q{ number }— The rotation.v{ number }— The vector to rotate.
Returns { number } — The rotated vector.
local forward = rigmath.qrotvec(boneRotation, { 0, 0, 1 })
typed/builtin//modules/rigmath/M/qslerp
M.qslerp(a: { number }, b: { number }, t: number) -> { number }
Spherical linear interpolation along the shortest arc. t = 0 returns
a, t = 1 returns b. Falls back to normalized lerp for nearly parallel
inputs, where the arc formulation loses precision.
Parameters
a{ number }— Start rotation.b{ number }— End rotation.tnumber— Interpolation factor.
Returns { number } — The interpolated unit quaternion.
local blended = rigmath.qslerp(animatedRotation, solvedRotation, weight)
typed/builtin//modules/rigmath/M/shortestArc
M.shortestArc(a: { number }, b: { number }) -> { number }
Shortest-arc quaternion rotating unit vector a onto unit vector b.
The antiparallel case resolves to a half turn about an arbitrary
perpendicular axis instead of producing NaN.
Arbitrarily small rotations are represented rather than rounded away. An iterative solver refines a pose in ever-smaller steps, so a near-parallel cutoff would stall it at whatever residual the cutoff angle spans — the bones needing the finest corrections would be exactly the ones ignored.
Parameters
a{ number }— Source unit vector.b{ number }— Destination unit vector.
Returns { number } — The rotation carrying a to b.
local q = rigmath.shortestArc(currentDir, wantedDir)
typed/builtin//modules/rigmath/M/signedAngle
M.signedAngle(a: { number }, b: { number }, axis: { number }) -> number
Signed angle in radians from a to b measured about axis. Both
vectors are projected onto the plane perpendicular to axis first, so the
result is the roll about that axis.
Parameters
a{ number }— Source vector.b{ number }— Destination vector.axis{ number }— The axis to measure about; normalized internally.
Returns number — The signed angle in radians.
local roll = rigmath.signedAngle(midOffset, poleOffset, chainDirection)
typed/builtin//modules/rigmath/M/swingTwist
M.swingTwist(q: { number }, axis: { number }) -> ({ number }, { number })
Split a rotation into its twist about axis and the remaining swing.
Rotation limits clamp the twist and rebuild, which is what keeps a hinge
joint on its axis.
Parameters
q{ number }— The rotation to decompose.axis{ number }— The twist axis; normalized internally.
Returns ({ number }, { number }) — The twist quaternion followed by the swing quaternion.
local twist, swing = rigmath.swingTwist(localRotation, hingeAxis)
typed/builtin//modules/rigmath/M/vadd
M.vadd(a: { number }, b: { number }) -> { number }
Component-wise sum a + b.
Parameters
a{ number }— First addend.b{ number }— Second addend.
Returns { number } — A new vector.
local p = rigmath.vadd(rootPos, offset)
typed/builtin//modules/rigmath/M/vcross
M.vcross(a: { number }, b: { number }) -> { number }
Cross product of two 3-vectors.
Parameters
a{ number }— First vector.b{ number }— Second vector.
Returns { number } — a cross b as a new vector.
local n = rigmath.vcross({ 1, 0, 0 }, { 0, 1, 0 })
typed/builtin//modules/rigmath/M/vdot
M.vdot(a: { number }, b: { number }) -> number
Dot product of two 3-vectors.
Parameters
a{ number }— First vector.b{ number }— Second vector.
Returns number — The scalar dot product.
local d = rigmath.vdot({ 1, 0, 0 }, { 0, 1, 0 })
typed/builtin//modules/rigmath/M/vlen
M.vlen(v: { number }) -> number
Length of a 3-vector.
Parameters
v{ number }— The vector.
Returns number — Its Euclidean length.
local l = rigmath.vlen({ 3, 4, 0 })
typed/builtin//modules/rigmath/M/vnormalize
M.vnormalize(v: { number }) -> { number }
Normalize a 3-vector. A zero-length vector returns zero rather than NaN.
Parameters
v{ number }— The vector to normalize.
Returns { number } — The unit vector, or { 0, 0, 0 } when v is degenerate.
local dir = rigmath.vnormalize(rigmath.vsub(target, root))
typed/builtin//modules/rigmath/M/vperpendicular
M.vperpendicular(v: { number }) -> { number }
A unit vector perpendicular to v, chosen deterministically. Used as a
bend axis when a chain is perfectly straight and carries no pole target.
Parameters
v{ number }— The reference vector.
Returns { number } — A unit vector at right angles to v.
local axis = rigmath.vperpendicular(chainDirection)
typed/builtin//modules/rigmath/M/vscale
M.vscale(v: { number }, s: number) -> { number }
Scale a 3-vector by a scalar.
Parameters
v{ number }— The vector.snumber— The scalar.
Returns { number } — A new scaled vector.
local half = rigmath.vscale(dir, 0.5)
typed/builtin//modules/rigmath/M/vsub
M.vsub(a: { number }, b: { number }) -> { number }
Component-wise difference a - b.
Parameters
a{ number }— Minuend.b{ number }— Subtrahend.
Returns { number } — A new vector.
local d = rigmath.vsub(tipPos, rootPos)
typed/builtin//modules/scopes/M/current
M.current() -> string?
The scope the calling code registers a resource under right now: the module whose body is running, the task scope its work runs in, the component instance whose lifecycle hook is on the stack, or the chunk of this call. Nil when the caller registers under no context.
Returns string? — The scope tag, or nil.
print("resources I register follow", scopes.current())
typed/builtin//modules/scopes/M/list
M.list() -> { LiveResource }
Every live resource that follows an owning context, across every subsystem holding them. A resource registered with no context above it, the engine's own, is not listed, because no scope reaches it.
Returns { LiveResource } — Array of live resources.
for _, r in scopes.list() do print(r.scope, r.kind, r.detail) end
typed/builtin//modules/scopes/M/open
M.open(options: ScopeOptions?) -> Scope
Open a task scope without waiting for it: start work in it with
s:spawn, end it with s:cancel(), or let what it is lived inside end it
({ entity = id } ties it to an entity). Wait for its work with
s:join() from a task.
Parameters
optionsScopeOptions(optional) —{ entity = id }ties the scope to an entity;{ name = "..." }names it.
Returns Scope — The scope.
local s = scopes.open({ entity = npc }); s:spawn("patrol", patrol)
typed/builtin//modules/scopes/M/release
M.release(scope: string) -> { Released }
End every resource registered under scope, across every subsystem:
tasks are cancelled, jobs dropped, and a task scope whose work this
leaves unfinished takes back what that work made. Reaches contexts no
seam does, such as the chunk of an execute call that started something
and ended without ending it. An execute call runs as a task listed
under its own exec: scope, so releasing that scope from the same call
cancels the call too: release it from a later call.
Parameters
scopestring— A scope tag, as thescopefield of alist()row carries it.
Returns { Released } — One row per subsystem that ended something, with how many it ended.
local ended = scopes.release("exec:__exec_12")
typed/builtin//modules/scopes/M/run
M.run(fn: (Scope) -> ...any, options: ScopeOptions?) -> ...any
Run fn(s) in a new task scope and wait until every piece of work
started in it is finished or cancelled. Returns what fn returned. The
first error raised by fn or by any work in the scope cancels the rest,
and is raised again here, as it was raised, once their cleanup has run.
A run whose work raised takes back what that work made: the entities it
spawned are despawned and the renderer resources it created let go.
Waits, so it must be called from a task: in code that cannot wait (a
component hook called directly, a callback) it raises, naming that.
Parameters
fn(Scope) -> ...any— The function to run; it receives the scope, and starts work withs:spawn.optionsScopeOptions(optional) —{ entity = id }ties the scope to an entity;{ name = "..." }names it.
Returns ...any — What fn returned.
scopes.run(function(s) s:spawn("a", fa); s:spawn("b", fb) end)
typed/builtin//modules/session/Session/get
Session.get(key: string) -> any
The value stored under key this session, or nil.
Parameters
keystring— The session key.
Returns any — The stored value, or nil.
local handle = Session.get("session_material_" .. entityId)
typed/builtin//modules/session/Session/set
Session.set(key: string, value: any?)
Store value under key for the rest of the engine session.
Pass nil to clear the key.
Parameters
keystring— The session key.valueany(optional) — The value to store, or nil to clear.
Session.set("session_material_" .. entityId, handle)
typed/builtin//modules/settings/settings/all
settings.all() -> { [string]: any }
Snapshot of the entire settings document (parsed). Modifying
the returned table does NOT propagate — call set or setMany
to persist. Useful for editors/inspectors that render every
section.
Returns { [string]: any } — A nested table mirroring the TOML document.
for section, keys in pairs(settings.all()) do
typed/builtin//modules/settings/settings/get
settings.get(key: string) -> any
Look up a value by dotted key. Returns whatever the file holds at that path — string / number / boolean / array / table — or nil if missing.
Parameters
keystring— Dotted-path key, e.g."render.culling_mode".
Returns any — The raw value at that key, or nil.
local mode = settings.get("render.culling_mode")
typed/builtin//modules/settings/settings/getBool
settings.getBool(key: string, default: boolean?) -> boolean
Boolean-typed accessor. Returns the value when present and
boolean-typed; falls back to default (or false) on missing key
or type mismatch.
Parameters
keystring— Dotted-path key.defaultboolean(optional) — Optional fallback boolean.
Returns boolean — The boolean value or the fallback.
if settings.getBool("render.shadows", true) then ... end
typed/builtin//modules/settings/settings/getNumber
settings.getNumber(key: string, default: number?) -> number
Number-typed accessor. Returns the value when present and
number-typed; falls back to default (or 0) on missing key or
type mismatch.
Parameters
keystring— Dotted-path key.defaultnumber(optional) — Optional fallback number.
Returns number — The number value or the fallback.
local g = settings.getNumber("physics.gravity", -9.81)
typed/builtin//modules/settings/settings/getString
settings.getString(key: string, default: string?) -> string
String-typed accessor. Returns the value when present and
string-typed; falls back to default (or "" if omitted) on
missing key or type mismatch.
Parameters
keystring— Dotted-path key.defaultstring(optional) — Optional fallback string.
Returns string — The string value or the fallback.
local mode = settings.getString("render.culling_mode", "gpu")
typed/builtin//modules/settings/settings/set
settings.set(key: string, value: any?)
Set a value by dotted key, then serialize and write the
file. In play mode the write fails like any other source-file
write — call wld.edit() first to unlock.
Parameters
keystring— Dotted-path key.valueany(optional) — Replacement value (string / number / boolean / table).
settings.set("render.culling_mode", "cpu")
typed/builtin//modules/settings/settings/setMany
settings.setMany(updates: { [string]: any })
Apply many key/value updates in one batched write — fewer
serialize+write round-trips than calling set per-key. Same
lock semantics as set.
Parameters
updates{ [string]: any }— A table of dotted-key → value pairs.
settings.setMany({
typed/builtin//modules/signal/M/connectionRevision
M.connectionRevision() -> number
A number that moves whenever any signal gains or loses a connection. A count derived from who is connected stays valid while this holds still.
Returns number — The connection revision.
if Signal.connectionRevision() ~= seen then recount() end
typed/builtin//modules/signal/M/disconnectAllFromEntity
M.disconnectAllFromEntity(entityId: string) -> number
Disconnect every connection that was sourced from entityId
(connections made while that entity's script was on the call stack).
Returns the number disconnected. Called by the entity-destroy
dispatch so a destroyed entity's connections never leak.
Parameters
entityIdstring— Entity whose sourced connections to drop.
Returns number
typed/builtin//modules/signal/M/disconnectAllFromInstance
M.disconnectAllFromInstance(instanceId: string) -> number
Disconnect every connection sourced from a specific component instance (connections made while that instance's script was on the call stack). Returns the number disconnected. The engine calls it when the instance is removed from an entity that stays in the world, and before a hot reload or a re-wake starts the instance's next life.
Parameters
instanceIdstring— Component instance whose sourced connections to drop.
Returns number
typed/builtin//modules/signal/M/markBaseline
M.markBaseline() -> number
Record the connections standing right now as the mark
resetToBaseline takes back to. A caller running work in an engine it
shares, such as a sweep of test suites, marks before the work and resets after
it.
Returns number — The mark.
local mark = Signal.markBaseline()
typed/builtin//modules/signal/M/new
M.new() -> any
Construct a new Signal.
Returns any
local hit = Signal.new()
hit:Connect(function(dmg) print("hit for", dmg) end)
hit:Fire(10)
typed/builtin//modules/signal/M/resetToBaseline
M.resetToBaseline(mark: number) -> number
Disconnect every connection made since mark with no component on
the call stack. A component's connections answer to the component and
end with it, or with its entity.
Parameters
marknumber— WhatmarkBaselinereturned.
Returns number — How many connections were disconnected.
Signal.resetToBaseline(mark)
typed/builtin//modules/signal/M/watchConnections
M.watchConnections(fn: () -> ()) -> () -> ()
Call fn every time Signal.connectionRevision() moves: once for
each connection a signal gains and once for each it loses. It runs
inside the call that connected or disconnected, so it does no more than
note that a count derived from who is connected is due again. A watch
made from a component ends with that component.
Parameters
fn() -> ()— Called with no arguments.
Returns () -> () — A function that stops the calls.
local stop = Signal.watchConnections(function() subscribersDirty = true end)
typed/builtin//modules/sourceEditing/M/apply
M.apply(snapshot: Snapshot, edits: { Edit }, opts: { quiet: boolean? }?) -> ApplyResult
Apply a batch to the snapshotted file. Identity and bytes are checked under the file lock; Luau and JSON syntax is checked before writing. The write uses the current session's persistence and play-shadow rules, and the report states where it landed.
Parameters
snapshotSnapshot— The original source snapshot.edits{ Edit }— A dense array of replacements in the original snapshot.opts{ quiet: boolean? }(optional) — quiet suppresses write side effects when the caller performs its own integration.
Returns ApplyResult — applied, path and edit count, plus the normal VFS write report on success or the refusal reason. Invalid edits or syntax raise before writing.
local result = SourceEditing.apply(snapshot, { edit }) assert(result.applied, result.reason)
typed/builtin//modules/sourceEditing/M/bind
M.bind(snapshot: Snapshot, argument: SourceRange, description: {id: string,scope: string,outputs: {string},scopeComplete: boolean}) -> Target
Bind a package-defined editable input to an exact source occurrence and its known output identities.
Parameters
snapshotSnapshot— The source revision containing the argument.argumentSourceRange— An argument returned by calls for this snapshot.description{id: string,scope: string,outputs: {string},scopeComplete: boolean}— Stable input id, scope description, known output identities and whether that scope is complete.
Returns Target — An immutable target a builder can associate with its outputs.
local target = SourceEditing.bind(snapshot, argument, {id="room.asset",scope="this room declaration",outputs={roomId},scopeComplete=true})
typed/builtin//modules/sourceEditing/M/calls
M.calls(snapshot: Snapshot, callee: string) -> { Call }
Find direct calls and pcall invocations spelled with the supplied function name. Each argument carries its original expression and exact byte range.
Parameters
snapshotSnapshot— The source snapshot to inspect.calleestring— A function name, such as asset.resolve, require or place.
Returns { Call } — Calls in source order. Ranges use zero-based UTF-8 byte offsets with an exclusive end; line numbers start at one.
local calls = SourceEditing.calls(snapshot, "asset.resolve")
typed/builtin//modules/sourceEditing/M/jsonRecordValue
M.jsonRecordValue(snapshot: Snapshot, arrayPointer: string, key: string, identity: string, fieldPointer: string) -> SourceRange
Locate a field in a JSON record selected by its unique string identity.
Parameters
snapshotSnapshot— JSON source snapshot.arrayPointerstring— JSON Pointer selecting the record array.keystring— Member holding each record's unique string identity.identitystring— Record identity to select.fieldPointerstring— JSON Pointer relative to the record; empty selects the whole record.
Returns SourceRange — Exact field range in this snapshot; re-resolve against fresh source after reordering.
local value = SourceEditing.jsonRecordValue(snapshot, "/rooms", "id", "east", "/asset")
typed/builtin//modules/sourceEditing/M/jsonValue
M.jsonValue(snapshot: Snapshot, pointer: string) -> SourceRange
Find the exact value selected by a JSON Pointer in the source snapshot.
Parameters
snapshotSnapshot— JSON source snapshot.pointerstring— RFC 6901 pointer. Array indices start at zero; an empty pointer selects the root.
Returns SourceRange — Original value expression, source line and zero-based UTF-8 byte range.
local value = SourceEditing.jsonValue(snapshot, "/rooms/0/asset")
typed/builtin//modules/sourceEditing/M/literal
M.literal(value: (string | number | boolean)?) -> string
Encode a string, finite number, boolean or nil as a Luau literal.
Parameters
value(string | number | boolean)(optional) — The scalar value to encode.
Returns string — Source text that evaluates to the supplied value.
local expression = SourceEditing.literal("props.Chair")
typed/builtin//modules/sourceEditing/M/prepareTarget
M.prepareTarget(target: Target, replacement: string) -> TargetPlan
Prepare a package target's replacement, retaining its scope and original revision for review and checked apply.
Parameters
targetTarget— The bound exact-occurrence target.replacementstring— A Luau expression; use literal for scalar values.
Returns TargetPlan — Immutable target, edits and candidate text. Apply with apply(plan.target.snapshot, plan.edits).
local plan = SourceEditing.prepareTarget(target, SourceEditing.literal("props.Chair"))
typed/builtin//modules/sourceEditing/M/preview
M.preview(snapshot: Snapshot, edits: { Edit }) -> string
Validate the edits' ranges and expected expressions, then return the candidate text for review.
Parameters
snapshotSnapshot— The original source snapshot.edits{ Edit }— Replacements addressed in that snapshot. Overlapping ranges are refused.
Returns string — Candidate source text.
local candidate = SourceEditing.preview(snapshot, { edit })
typed/builtin//modules/sourceEditing/M/read
M.read(path: string, opts: { root: string? }?) -> Snapshot
Read a source file's canonical path, identity and exact bytes. Keep this snapshot while preparing edits.
Parameters
pathstring— A VFS source path or library identity.opts{ root: string? }(optional) — Optional root for relative paths.
Returns Snapshot — A frozen snapshot. An inaccessible file raises with its read failure.
local snapshot = SourceEditing.read("/zero/source/scenes/main.scene/build.luau")
typed/builtin//modules/sourceEditing/M/remove
M.remove(snapshot: Snapshot) -> { removed: boolean, path: string, reason: string? }
Remove the snapshotted file while it is still the file the snapshot read. Identity and bytes are checked under the file lock, and the removal uses the current session's play terms: a removal the running play session refuses raises with the reason, as vfs.remove does.
Parameters
snapshotSnapshot— The source snapshot read before deciding on the removal.
Returns { removed: boolean, path: string, reason: string? } — removed and path, or the refusal reason when the file changed or the path refuses removal.
local result = SourceEditing.remove(SourceEditing.read(path)) assert(result.removed, result.reason)
typed/builtin//modules/sourceEditing/M/replace
M.replace(argument: SourceRange, replacement: string) -> Edit
Prepare a replacement for one discovered argument. Replacement is a Luau expression; literal quotes a scalar value.
Parameters
argumentSourceRange— The argument record from calls.replacementstring— The expression to put at its exact range.
Returns Edit — An edit referencing the argument's original bytes.
local edit = SourceEditing.replace(calls[1].arguments[1], SourceEditing.literal("props.Chair"))
typed/builtin//modules/substrate_batch/M/installInto
M.installInto(entity: EntityNamespace)
Install the polymorphic batchWrite / batchRead wrappers
onto an entity-shaped namespace. The prelude calls this once at
boot with the engine's entity global; users shouldn't call it
directly. Errors if the namespace is missing any of the five
required FFI primitives.
Parameters
entityEntityNamespace— The target entity namespace. Must already carrybatchWrite,batchWriteBound,batchWriteFromBuffer,batchRead, andbatchReadToBufferas functions.
require("@builtin::modules.substrate_batch").installInto(entity)
typed/builtin//modules/text_diff/M/added
M.added(newText: string?, opts: DiffOpts?) -> FileDiff
Pure-add convenience: build a diff representing the full content
of newText as added. Equivalent to M.diff("", newText, opts).
Parameters
newTextstring(optional) — The full added content.optsDiffOpts(optional) — Same shape asM.diff's opts.
Returns FileDiff — The structured FileDiff describing the addition.
local d = TextDiff.added(newBytes, { path = "newfile.luau" })
typed/builtin//modules/text_diff/M/diff
M.diff(oldText: string?, newText: string?, opts: DiffOpts?) -> FileDiff
Diff two strings and return the structured per-file shape. LCS-based;
produces op-tagged hunks rather than unified-diff text so consumers
can pattern-match on op instead of parsing prefixes. Files larger
than M.SIZE_CAP_BYTES return a size-only summary with is_text=false.
Parameters
oldTextstring(optional) — The previous text content.nilis treated as"".newTextstring(optional) — The new text content.nilis treated as"".optsDiffOpts(optional) — Optional.contextoverrides the default 3-line context window;pathandactionare folded into the returned table for caller convenience.
Returns FileDiff — The structured FileDiff table (see module header for shape).
local d = TextDiff.diff(oldBytes, newBytes)
local d = TextDiff.diff(oldBytes, newBytes, { path = "foo.luau", context = 5 })
typed/builtin//modules/text_diff/M/folder
M.folder(opts: DiffOpts?) -> FileDiff
The entry for a folder asset changed by opts.action: a folder holds
no bytes of its own, so the entry carries no hunks and no sizes, and the
files under it are entries of their own.
Parameters
optsDiffOpts(optional) —pathandaction, asM.difftakes them.
Returns FileDiff — The structured FileDiff, is_folder = true.
local d = TextDiff.folder({ path = "/zero/source/door.module", action = "modified" })
typed/builtin//modules/text_diff/M/removed
M.removed(oldText: string?, opts: DiffOpts?) -> FileDiff
Pure-remove convenience: full removal of oldText. Equivalent
to M.diff(oldText, "", opts).
Parameters
oldTextstring(optional) — The full removed content.optsDiffOpts(optional) — Same shape asM.diff's opts.
Returns FileDiff — The structured FileDiff describing the removal.
local d = TextDiff.removed(oldBytes, { path = "gone.luau" })
typed/builtin//modules/text_diff/M/toStatLine
M.toStatLine(fileDiff: FileDiff) -> string
Compact --stat-style summary line for a single file. Mirrors
git diff --stat's per-file row.
Parameters
fileDiffFileDiff— The structuredFileDifftable.
Returns string — One-line summary string. Binary/oversize files report <action> <path> (binary) instead of +/- counts, and a folder asset <action> <path> (folder).
print(TextDiff.toStatLine(d))
typed/builtin//modules/text_diff/M/toUnifiedText
M.toUnifiedText(fileDiff: FileDiff) -> string
Render a single file's structured diff back into unified-diff
text. Used by zm diff / zm show shell commands when the user
wants the conventional +/-/ text output instead of structured
hunks. Pure derivation from the structured shape — no second LCS pass.
Parameters
fileDiffFileDiff— The structuredFileDifftable. Binary / oversize files (is_text == false) render as a single suppression line including the size delta when available, and a folder asset (is_folder) as a line naming it a folder.
Returns string — The unified-diff body as a single string (no trailing newline).
print(TextDiff.toUnifiedText(d))
typed/builtin//modules/toml/toml/encode
toml.encode(root: { [string]: any }) -> string
Encode a Luau table as canonical TOML bytes. Top-level string-keyed sub-tables become section headers ([name]); deeper string-keyed tables become dotted sections ([a.b]). A sequence whose every element is a non-empty string-keyed table becomes one [[a.b]] block per element, after the section's scalars. Other sequence tables are emitted as inline arrays, and string-keyed tables in value position (inside an array or a block) as inline tables ({ k = v }). Section + key order is alphabetical so the same input always produces the same bytes.
Parameters
root{ [string]: any }— The table to encode. Must be string-keyed at the root.
Returns string — A TOML-formatted string suitable for vfs.write.
local body = toml.encode({ render = { culling_mode = "gpu" } })
typed/builtin//modules/toml/toml/parse
toml.parse(src: string) -> { [string]: any }
Parse a TOML document into a nested Luau table. Sections ([a.b]) become nested tables; key/value pairs become entries on the current section (or root if before any section header). Arrays of tables ([[a.b]]) become sequences of tables, one per block, and a section after a block ([a.b.c]) is a sub-table of that block's row. Throws with the line number on syntax errors.
Parameters
srcstring— TOML source bytes as a string.
Returns { [string]: any } — The parsed root table. Sub-tables are plain Luau tables; arrays are 1-indexed sequence tables.
local t = toml.parse('[a]\nx = 1\ny = "hi"\n')
typed/builtin//modules/toml/toml/replaceArrayTables
toml.replaceArrayTables(src: string, name: string, rows: { { [string]: any } }) -> string
Replace every [[name]] block in a TOML document with rows. A block
is its [[name]] header and the lines after it up to the next header
that is neither [name.…] nor [[name.…]] — those sub-tables go with
their row. Comment lines between a block's last key and the header that
ends it stay, with that header; a line inside a multi-line array value
belongs to that value. Every line outside the blocks is kept byte for
byte, including its line ending. When nothing is removed and rows is
empty the document is returned unchanged; otherwise blank lines at the
end are dropped, and each row is appended as a [[name]] block after
one blank line, in the document's own line ending (CRLF when it uses
CRLF).
Parameters
srcstring— The document's text.namestring— The top-level array-of-tables name, e.g. "presets".rows{ { [string]: any } }— The rows, each a string-keyed table.
Returns string — The new document text.
local path = "/zero/source/.world_settings"
typed/builtin//modules/tools/M/bind
M.bind(identity: string, positional: { any }?, named: { [string]: any }?, opts: BindOpts?) -> BindResult
Resolve a call's arguments against a tool's declared parameters,
turning named arguments into the positional call the tool actually
takes. This is the binder behind zero <toolbox> <tool> --name value
and the named args an MCP caller passes, so a name resolves the
same way whichever surface the caller reached for. Reads the schema
from tools.get, matches each name to a parameter (exactly first,
then case-insensitively), and reports the first unresolvable name,
a name that a positional argument already filled, a call longer than
the signature, and a required parameter skipped over while a later
one is filled. Resolves the call only — running it is tools.use.
Parameters
identitystring— Tool identity ("<toolbox>.<name>", with or without the leadingtools.).positional{ any }(optional) — Arguments already given by position, filling slots from 1.named{ [string]: any }(optional) — Arguments given by name,{ [parameterName]: value }.optsBindOpts(optional) —order— the order to visitnamedin, so the first problem reported is the caller's first (defaults to sorted, for a stable answer).prefix— written in front of every argument name in the failure message,"--"for a shell flag.whole— readnamedas ONE table argument when not one of its keys names a parameter and the first parameter can hold a table, as the first argument written inline when only some of them do, and as arguments named against the parameter list when no parameter could hold the table — where an emptynamedthen resolves to a call with no arguments at all.positionalCount— how many slotspositionalfills, for a caller that passed an explicitniland so cannot be measured by length.
Returns BindResult — { ok, call, count, failure? }. Call the tool with table.unpack(call, 1, count); on failure call is empty and failure carries the reason.
tools.bind("camera.lookAt", {}, { target = { 0, 5, 0 } })
tools.bind("MaterialAuthor.fromColor", {}, { color = { 1, 0, 0 } }, { whole = true })
typed/builtin//modules/tools/M/callable
M.callable(toolbox: string, tool: string) -> string?
The identity a registered tool is called by — <toolbox>.<tool>, the
pair tools.use takes — or nil when no toolbox registered under
toolbox carries tool. Reads the bound toolbox proxies, so it answers
for what this engine can call rather than for what the asset tree holds:
a .tool folder whose source never registered a function answers nil.
A name several toolboxes share reaches no one tool and answers nil too;
tools.toolboxesNamed names the toolboxes it reaches.
Parameters
toolboxstring— The toolbox's registered name ("zm", a library toolbox's scoped identity"@lib::ns", or a toolbox's canonical identity"pkg.blender").toolstring— The tool's leaf name ("status").
Returns string? — "<toolbox>.<tool>", or nil when the registry carries no such tool.
local callable = tools.callable("zm", "status") -- "zm.status"
typed/builtin//modules/tools/M/create
M.create(args: { [string]: any }) -> { ok: boolean, path: string?, identity: string?, signature: string?, error: string? }
Create a new tool on disk inside an EXISTING toolbox.
Scaffolds the .tool/ folder via asset.create("tool", …),
then writes the supplied code wrapped in a documented typed
function into init.luau (the --!desc/--!arg/--!return/
--!example doc block + signature built from the structured
metadata), the tags into .metadata, and a brief README.md
— so the authored tool is indistinguishable from a builtin.
Errors cleanly if the parent toolbox doesn't exist — call
tools.createToolbox first so the toolbox starts out with a
real description instead of the placeholder template body.
The engine's normal hot-reload pipeline picks up the new
files and binds the tool's global on the next pass.
Every toolbox created via tools.createToolbox ships a
shared.module/ (fill it via sharedCode at create time or by
editing the module later). The generated init.luau
automatically declares local shared = require(".shared")
before your function body, so the code you pass can
reference whatever the toolbox's shared helpers expose
directly. The tool returns its value, and error(message)
fails it. If a toolbox doesn't have a
shared.module/ for some reason, the require is skipped so
there's no dangling import to fail.
Parameters
args{ [string]: any }— Structured tool definition. Required:name(leaf, e.g."hello"),toolbox(parent toolbox, e.g."mytools"),code(the Luau function body — not a full module, just the statements that will become the function's body),description(one or more sentences describing what the tool does). Optional but recommended:args(array of{name, type, description}argument records),returns({type, description}for the return value),examples(array of call-site code strings),tags(array of strings for search).
Returns { ok: boolean, path: string?, identity: string?, signature: string?, error: string? } — { ok, path?, identity?, signature?, error? }. path — the new .tool/ folder's VFS path. identity — the tool's <toolbox>.<name> identity. signature — the derived name(args) -> ret signature.
tools.create({ name = "hello", toolbox = "mytools", description = "Greet.", code = "return 'hi'" })
typed/builtin//modules/tools/M/createToolbox
M.createToolbox(args: { [string]: any }) -> { ok: boolean, path: string?, identity: string?, error: string? }
Create a new toolbox folder. A toolbox is the namespace
container for tools — .toolbox/ on disk; once tools are authored
inside it they are invoked as tools.use("<name>", "<toolName>", …).
This call scaffolds the .toolbox/ folder via
asset.create("toolbox", …) and overwrites the placeholder
README.md with a real description so the toolbox doesn't ship
the template stub. Optionally seeds shared.module/ if the
caller supplies cross-tool helper code. Authoring a tool inside
this toolbox is the separate tools.create call.
Parameters
args{ [string]: any }— Structured toolbox definition. Required:name(the toolbox's leaf name, e.g."mytools"— becomes<name>.toolbox/on disk and the namespace for tool identities),description(one or more sentences describing the surface this toolbox exposes — what problem space the tools cover and who calls them). Optional:sharedCode— replacement body for the toolbox'sshared.module/init.luau. The toolbox template ALWAYS ships ashared.module/so tools in this toolbox canrequire(".shared")from day one. SupplysharedCodeto fill it with the cross-tool helpers (parsers, registries, …) the toolbox's tools share; the module body is left untouched if you omit it.path— explicit VFS destination (/zero/source/...form). Defaults to/zero/source/tools/<name>if omitted; pass an explicit path to author a library-scoped or package-internal toolbox.
Returns { ok: boolean, path: string?, identity: string?, error: string? } — { ok, path?, identity?, error? }. path — the new .toolbox/ folder's VFS path. identity — the toolbox's registered identity (<name>).
tools.createToolbox({ name = "mytools", description = "Custom tooling for my workflow." })
typed/builtin//modules/tools/M/delete
M.delete(identity: string) -> { ok: boolean, path: string?, error: string? }
Remove a previously-authored tool by identity. Deletes the
.tool/ folder and its contents from the VFS via
vfs.remove(..., { recursive = true }). The engine drops the
tool's global on the next hot-reload pass. Refuses to operate
on a path that doesn't exist, and answers a removal the VFS
refuses the same way ({ ok = false } with an explanatory
error).
Parameters
identitystring— Tool identity ("<toolbox>.<name>").
Returns { ok: boolean, path: string?, error: string? } — Table shaped { ok, path?, error? }.
tools.delete("mytools.hello")
typed/builtin//modules/tools/M/displayType
M.displayType(text: string) -> string
A type or signature as a person reads it: a type written through a
module alias (tools.Path, { tools.Path }) reads as the type's own name
(Path, { Path }). Usage errors and --help print signatures through
this.
Parameters
textstring— A type or a rendered signature.
Returns string — The text with each <alias>.Path written Path.
tools.displayType("add(file: tools.Path)")
typed/builtin//modules/tools/M/get
M.get(identity: string) -> ToolMeta?
Read back a tool's assembled metadata — description, typed
signature, per-argument docs, return, examples, and tags — gathered
from the four canonical sources in its .tool/ folder. Individual
tools aren't entries in the asset index (only their parent toolboxes
are), so this resolves the toolbox via asset.resolve(toolbox, "toolbox") and reads the tool relative to it. Returns nil when the
toolbox or tool is missing.
Parameters
identitystring— Tool identity ("<toolbox>.<name>", with or without the leadingtools.).
Returns ToolMeta? — The assembled metadata { name, signature?, description, args, varargs, returns?, examples, typeDefs, tags }, or nil if not found. Each entry in args is { name, type, description, optional } in signature order, so a caller can tell a required parameter from an optional one without parsing the rendered signature. varargs is true when the tool accepts trailing arguments beyond the named parameters. typeDefs carries { name, definition } for every named type the signature refers to, resolved transitively, so a signature reading spawn(opts: SpawnOpts) can be called without opening the tool's source.
local meta = tools.get("entityOps.modify"); print(meta.signature)
typed/builtin//modules/tools/M/list
M.list(tier: (number | string)?, toolbox: string?) -> { stdout: string, value: any }
Discover registered code-mode tools, grouped by toolbox.
Default tier returns just { <toolbox> = { name, name, … } }
plus a formatted stdout listing every toolbox on one line
with its tools — compact enough that listing the whole
catalogue doesn't flood agent context. Higher tiers enrich
each entry with its one-line description (tier 2) or its full
assembled metadata — signature, args, returns, examples (tier 3).
Pass a toolbox name to restrict the output to one toolbox.
Parameters
tier(number | string)(optional) — Verbosity level:1(default) toolbox summary,2adds one-line descriptions,3adds the full assembled metadata. Pass a string instead to restrict to that toolbox at tier 1.toolboxstring(optional) — Optional toolbox name to restrict the output to (e.g."entityOps"). Passing a string as the first arg also works.
Returns { stdout: string, value: any } — Table shaped { stdout: string, value: <grouped> }. For tier 1, value is { [toolbox] = { toolName, … } }. For tier ≥ 2, value is { [toolbox] = { { name, identity, signature?, description, … }, … } }.
tools.list() -- default: every toolbox, names only
tools.list(2) -- include first-line descriptions
tools.list("entityOps") -- only the `entityOps` toolbox at tier 1
tools.list(2, "entityOps") -- only `entityOps`, with descriptions
typed/builtin//modules/tools/M/miss
M.miss(toolbox: string, tool: string?) -> string
What every tool surface says when a toolbox and tool reach no single
tool: a toolbox name several toolboxes share names each toolbox it
reaches, a toolbox with no tool of that name lists the tools it holds with
the nearest one, a tool's name written as the toolbox names the
toolboxes holding that tool, and any other name reaching no toolbox lists
the nearest toolboxes. tools.use, the describe_tool MCP tool and
zero in the engine shell all refuse with this reason, so the same name
is refused the same way wherever it is written.
Parameters
toolboxstring— The toolbox name the caller wrote.toolstring(optional) — The tool name the caller wrote, when there is one.
Returns string — The reason, as one sentence the caller can act on.
tools.miss("blender", "probe")
typed/builtin//modules/tools/M/parseCommandLine
M.parseCommandLine(identity: string, words: { string }, opts: CommandLineOpts?) -> BindResult
Read a command line against a tool's own schema and bind it. This
is the reader behind zero <toolbox> <tool> <words…>. Words reach the
slots the schema states: a --!flag spelling, a parameter name
(--name), a field of the trailing options table (--dry-run or
--dryRun), or a position. -- makes every later word literal and
fills the --!rest target. Each value is read against the type of the
slot it reaches, a Path slot resolves against the working directory,
and the arguments are bound through tools.bind, whose arity, gap and
unknown-name refusals stand.
Parameters
identitystring— Tool identity ("<toolbox>.<name>").words{ string }— The words after the tool's name.optsCommandLineOpts(optional) —cwd— the absolute VFS directory relative paths resolve against (default/zero);mounts—{ [prefix]: target }, the VFS places a path at or under a prefix lies at instead.
Returns BindResult — { ok, call, count, failure? } as tools.bind returns it. A failure's reason is unknown-flag, missing-value, bad-value, missing-argument, too-many-words, given-twice or one of tools.bind's, and its message is written for a shell.
tools.parseCommandLine("git.commit", { "-m", "fix", "--dry-run" })
typed/builtin//modules/tools/M/registeredToolbox
M.registeredToolbox(name: string) -> string?
The name a drill-in lists a registered toolbox by, or nil when the
registry holds no toolbox under name. Reads the bound toolbox proxies,
the same ones tools.callable reads, so it answers for what this engine
can call rather than for what the asset tree holds. A name several
toolboxes share reaches no one toolbox and answers nil;
tools.toolboxesNamed names the toolboxes it reaches.
Parameters
namestring— The toolbox's registered name ("zm", a library toolbox's scoped identity"@lib::ns", or a toolbox's canonical identity"pkg.blender").
Returns string? — name, or nil when the registry holds no such toolbox.
local box = tools.registeredToolbox("zm") -- "zm"
typed/builtin//modules/tools/M/render
M.render(identity: string, result: any?) -> RenderOut?
Turn a tool's typed result into the text a person reads. A tool
folder may hold render.luau, a module returning one function
(result) -> string | { out, err?, exit? }; this runs it. The module is
required at call time, so an edit of render.luau takes effect on the
next call.
Parameters
identitystring— Tool identity ("<toolbox>.<name>").resultany(optional) — The value the tool returned.
Returns RenderOut? — { out, err?, exit? }, or nil when the tool holds no render.luau. A string return becomes { out = s }. A render that raises, or returns anything but a string or table, makes this raise.
tools.render("git.status", result)
typed/builtin//modules/tools/M/search
M.search(query: string?, opts: { toolbox: string?, limit: number?, mode: string?, from: string? }?) -> { stdout: string, value: any, total: number?, containers: { any }? }
Search registered code-mode tools, the canonical in-engine
tool-discovery entry point — callable from execute Luau so an agent
can find the tool it needs without leaving the engine. A query is
answered by @builtin::modules.discovery (searchTools), the question
search_tools { query } asks. In semantic mode on an engine bound to
a world, the search core ranks the tools, toolboxes and workflows of the
whole published library, then this world's own matches follow; a hit
falls by how closely it means what was asked, so a tool is found by what
it does rather than by the words it happens to use. In keyword mode,
and on an engine bound to no world, the corpus is the files this engine
holds. In keyword mode a hit falls by what the query's words the
asset carried as words of their own weigh, a word weighing more the fewer
of the assets read carry it, then by the most of them it
carried side by side in the query's order, then by how many it carried
anywhere, then by the order its type declares the role that matched, then
by name (discovery.keyword). With an empty query the toolbox
named is listed, or the whole catalogue when none is. Each row's
identity is the tool's <toolbox>.<tool> identity; invoke it with
tools.use("<toolbox>", "<tool>", ...), from Luau or inside a tool_exec
script, the form each row's examples are rendered in, or in the engine
shell as zero <toolbox> <tool> [args].
Parameters
querystring(optional) — Free-text search string, matched against every file each type's indexing recipe names — for a tool, its README and its source. Empty or nil lists the catalogue, or the toolboxopts.toolboxnames.opts{ toolbox: string?, limit: number?, mode: string?, from: string? }(optional) — Optional filters table.toolbox— keep only rows whose owning toolbox exactly matches.limit— maximum rows to return (default10; pass a larger value to return more).mode—"semantic"ranks by what a tool means,"keyword"by the words it carries. Omit it fordiscovery.defaultMode():semanticwherever a world is bound,keywordwhere none is and the only corpus is the files this engine holds.from— WHERE results may come from. 'all' (default) is everything published. 'bound' is the current world and its installed libraries, answered by this engine with no published-library leg;modestill picks how the query is matched: mode='keyword' reads this engine's own files, unpushed ones and a private world's included, and a semantic search lists this world's own files that match by their words after its ranked hits, each marked from: world.
Returns { stdout: string, value: any, total: number?, containers: { any }? } — Table shaped { stdout: string, value: { SearchRow } }. Each row is { identity, name, assetType, description, toolbox?, registered?, signature?, tags?, examples?, matched?, guid?, installed?, workflow?, p?, container_key?, system_key?, from? }. A query row says whether this world holds the hit (installed), and carries the guid installing takes and, on a workflow this world holds, the workflow it starts; it carries no call string, since every surface writes a call in its own syntax; from = "world" marks a match from this world's own content after a semantic ranking. A tool row's identity is the <toolbox>.<tool> a call names; a toolbox row's is the toolbox's name, which toolbox repeats and a drill-in takes. registered says whether the registry holds what identity names: the function a call would run, or the toolbox a drill-in lists. matched is the role and file a query hit matched in and what it ranked on (weight, terms, words, together); a listing carries none. stdout is a one-line summary followed by one line per row. total, on a query naming no toolbox, is how many matched in all, of which value holds the best limit. containers, beside rows the search core ranked, is the tier their container_key and system_key point into: each entry { key, guid, name, assetType, parent_key?, description? } is a container a row ships in, naming the one above it by parent_key, so a tool's container_key is its toolbox and its system_key the package that toolbox ships in.
tools.search("spawn camera")
tools.search("material", { limit = 5 })
tools.search("", { toolbox = "physics" }) -- list a toolbox
tools.search("") -- list everything
tools.search("spawn camera", { mode = "keyword" })
typed/builtin//modules/tools/M/searchStats
M.searchStats() -> { reads: number }
What tools.search has read to assemble its rows. reads is the
number of tools whose files (init.luau, .metadata) were read and
parsed to assemble the row a listing or a query answers with. A tool is
read once for each version of its files, when a listing or a query first
answers with it: a drill-in into one toolbox reads that toolbox's tools,
and repeating it reads none. A tool whose asset states no checksum is
read each time a row answers with it.
Returns { reads: number } — { reads }.
local before = tools.searchStats().reads
typed/builtin//modules/tools/M/toolboxes
M.toolboxes() -> { stdout: string, value: { { toolbox: string, purpose: string, toolCount: number } } }
Discover the registered toolboxes as a grouped overview — one
row per toolbox with its one-line purpose and tool count. The
toolbox-first entry point to tool discovery: an agent navigates by
DOMAIN (which toolbox), then drills into a toolbox's tools with
tools.search("", { toolbox = "<name>" }). purpose is sourced from
the toolbox's README.md (its first descriptive line), falling back
to the .metadata description.
Returns { stdout: string, value: { { toolbox: string, purpose: string, toolCount: number } } } — Table shaped { stdout: string, value: { { toolbox, purpose, toolCount } } }. value is toolbox-name-sorted; each entry is { toolbox = "<name>", purpose = "<one line>", toolCount = <n> }.
tools.toolboxes()
typed/builtin//modules/tools/M/toolboxesNamed
M.toolboxesNamed(name: string) -> { string }
The toolboxes a toolbox name reaches, each spelled the way a call
reaches it alone. A toolbox is bound under its folder's name, so two
toolbox folders with the same name — one in each of two packages, say —
share it: that name reaches both, and each is then reached by its own
canonical identity (pkgA.blender, pkgB.blender) instead. Every tool
surface reads this answer: the listing names each toolbox by it, and a
call or lookup through a name reaching more than one is refused naming
each (tools.miss states the refusal).
Parameters
namestring— A toolbox name ("entityOps"), a library toolbox's scoped key ("@lib::ns"), or any other name the toolbox asset answers to — its canonical identity or its path.
Returns { string } — The names a call reaches each toolbox by, sorted: one entry when the name reaches one toolbox, several when it reaches more, none when it reaches no toolbox holding a tool.
tools.toolboxesNamed("blender") -- { "pkgA.blender", "pkgB.blender" }
typed/builtin//modules/tools/M/tryUse
M.tryUse(toolbox: string, tool: string, ...: any?) -> ToolCall
Invoke one code-mode tool and report the outcome as a value. Takes the
same arguments as tools.use and resolves the toolbox the same way, and
returns { ok, value, error, toolbox, tool } for every outcome — an
unknown toolbox, an unknown tool, a tool that reported failure, and a tool
that raised all arrive as ok = false with the reason in error. The
ok / value / error fields are the ones a tool_exec answer
reports, so a script comparing several calls in one pass reads the same
names it would over MCP, and reads them without wrapping each call in pcall.
Parameters
toolboxstring— The owning toolbox — an ambient toolbox by its name ("entityOps") or a library toolbox by its scoped identity ("@lib::ns").toolstring— The tool's leaf name within that toolbox ("spawn")....any(optional)
Returns ToolCall — { ok, value, error, toolbox, tool }. value carries the tool's own value when ok is true; error carries the reason when it is false.
tools.tryUse("entityOps", "spawn", { Model = { model = "cube" } })
typed/builtin//modules/tools/M/use
M.use(toolbox: string, tool: string, ...: any?) -> ...any
Invoke one code-mode tool by naming its toolbox and tool explicitly.
The same call runs from engine Luau (editor panels, shipped modules,
execute) and inside an MCP tool_exec script
(return await tools.use("<toolbox>", "<tool>", ...)), and
zero <toolbox> <tool> [args] is its engine-shell spelling. Resolves the toolbox
from the runtime store (builtin, library, and user-authored runtime
toolboxes all work), calls the named tool with the remaining args, and
returns the tool's value directly — unwrapping the ZmToolResult
envelope and RAISING a Luau error when the tool fails. Because every call
names both toolbox and tool, it can never read as a tools.<box>
namespace. tools.tryUse takes the same arguments and reports the
outcome as a value instead of raising.
Parameters
toolboxstring— The owning toolbox — an ambient toolbox by its name ("entityOps") or a library toolbox by its scoped identity ("@lib::ns").toolstring— The tool's leaf name within that toolbox ("spawn")....any(optional)
Returns ...any — Everything the tool returned, in the order it returned it — a tool declaring (path, reason, frame) hands back all three, so a second and third value the tool states are read the way the tool's own signature says. Raises on an unknown toolbox / tool or a tool-reported failure. These are the tool's OWN values, not an { ok, value } envelope; reach for tools.tryUse when the call's outcome is what you want.
tools.use("entityOps", "spawn", { Model = { model = "cube" } }, { position = {0, 2, 0} })
typed/builtin//modules/transform/T/direction
T.direction(fromX: number, fromY: number, fromZ: number, toX: number, toY: number, toZ: number) -> (number, number, number)
Normalized direction vector from point A to point B. Returns zeros when the two points coincide (within ~0.001 units).
Parameters
fromXnumber— From x.fromYnumber— From y.fromZnumber— From z.toXnumber— To x.toYnumber— To y.toZnumber— To z.
Returns (number, number, number) — Three numbers dx, dy, dz — the unit direction.
local dx, dy, dz = Transform.direction(0, 0, 0, 1, 0, 0)
typed/builtin//modules/transform/T/directionBetween
T.directionBetween(entityA: string | EntityRef, entityB: string | EntityRef) -> (number, number, number)
Normalized world-space direction from one entity to another, read from their world positions. Returns zeros if either entity can't be resolved.
Parameters
entityAstring | EntityRef— Source entity (id string or proxy).entityBstring | EntityRef— Target entity (id string or proxy).
Returns (number, number, number) — Three numbers dx, dy, dz — the unit direction.
local dx, dy, dz = Transform.directionBetween("cam", "target")
typed/builtin//modules/transform/T/distance
T.distance(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number) -> number
Euclidean distance between two world-space positions.
Parameters
x1number— First point x.y1number— First point y.z1number— First point z.x2number— Second point x.y2number— Second point y.z2number— Second point z.
Returns number — The Euclidean distance.
local d = Transform.distance(0, 0, 0, 1, 1, 1)
typed/builtin//modules/transform/T/distanceBetween
T.distanceBetween(entityA: string | EntityRef, entityB: string | EntityRef) -> number?
Distance between two entities in world space. Each entity's world position is what is measured, so a parent's offset counts toward the distance the way the scene shows it.
Parameters
entityAstring | EntityRef— First entity (id string or proxy).entityBstring | EntityRef— Second entity (id string or proxy).
Returns number? — The Euclidean distance, or nil when either entity can't be resolved.
local d = Transform.distanceBetween("cam", "box")
typed/builtin//modules/transform/T/euler
T.euler(qx: number, qy: number, qz: number, qw: number) -> (number, number, number)
Convert quaternion to euler angles (yaw, pitch, roll) in radians.
Parameters
qxnumber— Quaternion x.qynumber— Quaternion y.qznumber— Quaternion z.qwnumber— Quaternion w.
Returns (number, number, number) — Three numbers yaw, pitch, roll (Y, X, Z rotations).
local yaw, pitch, roll = Transform.euler(0, 0, 0, 1)
typed/builtin//modules/transform/T/eulerToQuat
T.eulerToQuat(yaw: number, pitch: number?, roll: number?) -> (number, number, number, number)
Identity-aware overload of euler-to-quaternion. Uses the negative-yaw
convention shared with quatFromYaw, quatFromYawPitch, lookAtQuat, and
T.euler extraction — so T.euler(T.eulerToQuat(y, p, r)) returns
(y, p, r). Order is yaw (Y) then pitch (X) then roll (Z).
Parameters
yawnumber— Y-axis rotation in radians.pitchnumber(optional) — X-axis rotation in radians. Defaults to 0.rollnumber(optional) — Z-axis rotation in radians. Defaults to 0.
Returns (number, number, number, number) — Four numbers qx, qy, qz, qw.
local qx, qy, qz, qw = Transform.eulerToQuat(math.pi / 2)
typed/builtin//modules/transform/T/lerp
T.lerp(ax: number, ay: number, az: number, bx: number, by: number, bz: number, t: number) -> (number, number, number)
Linearly interpolate between two positions.
Parameters
axnumber— Start x.aynumber— Start y.aznumber— Start z.bxnumber— End x.bynumber— End y.bznumber— End z.tnumber— Interpolation factor[0, 1].
Returns (number, number, number) — Three numbers — the interpolated position.
local x, y, z = Transform.lerp(0, 0, 0, 1, 1, 1, 0.5)
typed/builtin//modules/transform/T/lerp1
T.lerp1(a: number, b: number, t: number) -> number
Linearly interpolate two scalars.
Parameters
anumber— Start value.bnumber— End value.tnumber— Interpolation factor[0, 1].
Returns number — The interpolated scalar.
local v = Transform.lerp1(0, 10, 0.5)
typed/builtin//modules/transform/T/lerpAngle
T.lerpAngle(a: number, b: number, t: number) -> number
Lerp between two angles via the shortest arc; returns a value in [-pi, pi].
Parameters
anumber— Start angle in radians.bnumber— End angle in radians.tnumber— Interpolation factor[0, 1].
Returns number — The interpolated angle, normalized to [-pi, pi].
local a = Transform.lerpAngle(0, math.pi, 0.5)
typed/builtin//modules/transform/T/localToWorld
T.localToWorld(px: number, py: number, pz: number, pqx: number, pqy: number, pqz: number, pqw: number, lx: number, ly: number, lz: number) -> (number, number, number)
Transform a local-space position into world space using a parent pose.
Parameters
pxnumber— Parent position x.pynumber— Parent position y.pznumber— Parent position z.pqxnumber— Parent rotation x.pqynumber— Parent rotation y.pqznumber— Parent rotation z.pqwnumber— Parent rotation w.lxnumber— Local x.lynumber— Local y.lznumber— Local z.
Returns (number, number, number) — Three numbers wx, wy, wz — the world position.
local wx, wy, wz = Transform.localToWorld(px, py, pz, pqx, pqy, pqz, pqw, lx, ly, lz)
typed/builtin//modules/transform/T/lookAt
T.lookAt(entityOrId: string | EntityRef, txOrTarget: any?, ty: any?, tz: number?, up: any?) -> (boolean, string?)
Make an entity face a world position. The target slot accepts three
explicit coordinates, one point as { x, y, z } / { x =, y =, z = } / a
vector, or an entity — an id string, an entity NAME, or a proxy — whose
WORLD position is resolved. A table carrying an entity id reads as that
entity; any other table reads as the point it spells. The subject slot
takes the three entity spellings.
Everything here is world space: the subject and the target are
read as entity(id).position and the aim is written as
entity(id).rotation, so a parent under either one moves the entity and
the aim still lands on the point named.
Returns whether the rotation was written, so a caller that named an entity
the scene does not carry learns the aim did not happen instead of reading
a stale orientation back as the answer.
Parameters
entityOrIdstring | EntityRef— Entity id, name, or proxy for the entity to rotate.txOrTargetany(optional) — A number (world x), a point table, or an entity id / name / proxy whose world position is resolved as the look-at target.tyany(optional) — World y of the target. Omitted whentxOrTargetis a point or an entity.tznumber(optional) — World z of the target. Omitted whentxOrTargetis a point or an entity.upany(optional) — Optional world up hint deciding the roll —{ x, y, z },{ x =, y =, z = }or a vector. World +Y when omitted. It never bends the aim; it only says which way is up around it. When the target slot is an entity or a point this is the third argument, and when it is coordinates the fifth.
Returns (boolean, string?) — True when the entity's world rotation was written, and nil for the second value. The target and up slots take any value, because naming which of the shapes arrived is this call's own job: a value that is none of them comes back as a reason rather than as an error raised out of the argument check. False plus a reason otherwise: "unresolved" when a reference names no entity, "no-transform" when one carries no transform, "incomplete-target" when the target spells no point — coordinates with a y or z missing, or a table carrying neither three numbers nor x/y/z, "incomplete-up" when the up hint spells none either, "degenerate" when the two points coincide so no facing direction exists.
Transform.lookAt("cam", 0, 1, 0)
Transform.lookAt("cam", "box") -- resolve target entity position
Transform.lookAt(cam, box) -- entity proxies for both
Transform.lookAt("cam", { 0, 1, 0 }) -- one point table
Transform.lookAt("cam", "box", { 0, 0, 1 }) -- rolled to a +Z up
typed/builtin//modules/transform/T/lookAtQuat
T.lookAtQuat(fx: number, fy: number, fz: number, tx: number, ty: number, tz: number) -> (number?, number?, number?, number?)
Compute quaternion to look from origin position toward a target.
Returns four components (qx, qy, qz, qw), or nil when the from
and to points are too close to derive a meaningful direction.
Parameters
fxnumber— Origin x.fynumber— Origin y.fznumber— Origin z.txnumber— Target x.tynumber— Target y.tznumber— Target z.
Returns (number?, number?, number?, number?) — Four numbers qx, qy, qz, qw — the look-at quaternion. Nil when degenerate.
local qx, qy, qz, qw = Transform.lookAtQuat(0, 0, 0, 1, 0, 1)
typed/builtin//modules/transform/T/lookRotation
T.lookRotation(fx: number, fy: number, fz: number, tx: number, ty: number, tz: number, ux: number?, uy: number?, uz: number?) -> (number?, number?, number?, number?)
The rotation that aims an entity standing at one world point at another,
with a world up hint deciding the roll. Where lookAtQuat derives the aim
from yaw and pitch alone — clamping the pitch just short of vertical, so a
point directly overhead comes back a twentieth of a degree off — this builds
all three axes, so the aim lands on the point at any elevation and straight
up and straight down are ordinary cases.
The aimed axis is the entity's local -Z, the same forward quatFromBasis,
Transform.lookAt and entity(id):lookAt state and the direction
entity(id).transform.forward reads back.
The up hint is a world direction the entity's own +Y is turned toward as
far as the aim allows; it never bends the forward axis. A hint parallel to
the aim leaves the roll undetermined, and a hint of no length names no
direction — both fall back to a stable roll rather than a NaN.
Parameters
fxnumber— Eye x — where the entity stands.fynumber— Eye y.fznumber— Eye z.txnumber— Target x — the world point it faces.tynumber— Target y.tznumber— Target z.uxnumber(optional) — Up hint x. World +Y when the hint is omitted.uynumber(optional) — Up hint y.uznumber(optional) — Up hint z.
Returns (number?, number?, number?, number?) — Four numbers qx, qy, qz, qw. Nil when the eye and the target coincide, so no facing direction exists.
local qx, qy, qz, qw = Transform.lookRotation(0, 2, 10, 0, 1, 0)
entity("cam").rotation = { Transform.lookRotation(0, 2, 10, 0, 1, 0) }
-- a dutch tilt: the same aim, rolled by leaning the up hint
local q = { Transform.lookRotation(0, 2, 10, 0, 1, 0, 0.2, 1, 0) }
typed/builtin//modules/transform/T/normalizeAngle
T.normalizeAngle(a: number) -> number
Normalize an angle into [-pi, pi].
Parameters
anumber— The angle in radians.
Returns number — The same angle wrapped into [-pi, pi].
local a = Transform.normalizeAngle(3 * math.pi)
typed/builtin//modules/transform/T/orbit
T.orbit(centerX: number, centerY: number, centerZ: number, radius: number, height: number, angle: number) -> (number, number, number, number, number, number, number)
Position + rotation for orbiting around a center point. Returns the world position followed by the orientation that faces the center.
Parameters
centerXnumber— Center x.centerYnumber— Center y.centerZnumber— Center z.radiusnumber— Horizontal distance from the center.heightnumber— Vertical offset fromcenterY.anglenumber— Orbital angle in radians.
Returns (number, number, number, number, number, number, number) — Seven numbers x, y, z, qx, qy, qz, qw.
local x, y, z, qx, qy, qz, qw = Transform.orbit(0, 1, 0, 5, 2, t)
typed/builtin//modules/transform/T/quatFromAxisAngle
T.quatFromAxisAngle(ax: number, ay: number, az: number, angle: number) -> (number, number, number, number)
Create quaternion from axis and angle (radians). Returns the identity quaternion when the axis is degenerate (length < 0.001).
Parameters
axnumber— Axis x.aynumber— Axis y.aznumber— Axis z.anglenumber— Rotation angle in radians.
Returns (number, number, number, number) — Four numbers qx, qy, qz, qw.
local qx, qy, qz, qw = Transform.quatFromAxisAngle(0, 1, 0, math.pi)
typed/builtin//modules/transform/T/quatFromBasis
T.quatFromBasis(rx: number, ry: number, rz: number, ux: number, uy: number, uz: number, fx: number, fy: number, fz: number) -> (number, number, number, number)
Build the rotation whose right, up and forward ARE the given axes. Where
lookAtQuat derives a rotation from a direction alone — yaw and pitch, with
pitch clamped just short of straight up or down and no say in the roll — this
states all three axes, so a view straight down has a defined image-up instead
of whatever the yaw implied. The axes are expected orthonormal and are used as
given: right and up are the entity's local +X and +Y, forward its local
-Z (the direction it faces).
Parameters
rxnumber— Right axis x.rynumber— Right axis y.rznumber— Right axis z.uxnumber— Up axis x.uynumber— Up axis y.uznumber— Up axis z.fxnumber— Forward axis x.fynumber— Forward axis y.fznumber— Forward axis z.
Returns (number, number, number, number) — x, y, z, w of the rotation quaternion.
local qx, qy, qz, qw = Transform.quatFromBasis(1,0,0, 0,1,0, 0,0,-1) -- identity
-- looking straight down with the subject's front toward the top of frame
local qx, qy, qz, qw = Transform.quatFromBasis(1,0,0, 0,0,-1, 0,-1,0)
typed/builtin//modules/transform/T/quatFromYaw
T.quatFromYaw(yaw: number) -> (number, number, number, number)
Create quaternion from yaw (Y-axis rotation) in radians. Uses the
negative-yaw convention shared with quatFromYawPitch, lookAtQuat,
and T.euler extraction — so T.euler(T.quatFromYaw(y)) round-trips
to y.
Parameters
yawnumber— Rotation in radians around the Y axis.
Returns (number, number, number, number) — Four numbers qx, qy, qz, qw.
local qx, qy, qz, qw = Transform.quatFromYaw(math.pi / 2)
typed/builtin//modules/transform/T/quatFromYawPitch
T.quatFromYawPitch(yaw: number, pitch: number) -> (number, number, number, number)
Create quaternion from yaw and pitch in radians.
Parameters
yawnumber— Y-axis rotation in radians.pitchnumber— X-axis rotation in radians.
Returns (number, number, number, number) — Four numbers qx, qy, qz, qw.
local qx, qy, qz, qw = Transform.quatFromYawPitch(0, math.pi / 4)
typed/builtin//modules/transform/T/quatIdentity
T.quatIdentity() -> (number, number, number, number)
Identity quaternion (0, 0, 0, 1).
Returns (number, number, number, number) — Four numbers qx, qy, qz, qw — the identity.
local qx, qy, qz, qw = Transform.quatIdentity()
typed/builtin//modules/transform/T/quatInverse
T.quatInverse(qx: number, qy: number, qz: number, qw: number) -> (number, number, number, number)
Quaternion inverse. Equal to the conjugate for unit quaternions.
Parameters
qxnumber— Quaternion x.qynumber— Quaternion y.qznumber— Quaternion z.qwnumber— Quaternion w.
Returns (number, number, number, number) — Four numbers qx, qy, qz, qw — the inverse.
local ix, iy, iz, iw = Transform.quatInverse(qx, qy, qz, qw)
typed/builtin//modules/transform/T/quatMul
T.quatMul(ax: number, ay: number, az: number, aw: number, bx: number, by: number, bz: number, bw: number) -> (number, number, number, number)
Quaternion multiplication: returns qa * qb (composition: rotate
by qb then qa).
Parameters
axnumber— Left quat x.aynumber— Left quat y.aznumber— Left quat z.awnumber— Left quat w.bxnumber— Right quat x.bynumber— Right quat y.bznumber— Right quat z.bwnumber— Right quat w.
Returns (number, number, number, number) — Four numbers qx, qy, qz, qw — the composed quaternion.
local qx, qy, qz, qw = Transform.quatMul(ax, ay, az, aw, bx, by, bz, bw)
typed/builtin//modules/transform/T/quatRotateVec
T.quatRotateVec(qx: number, qy: number, qz: number, qw: number, vx: number, vy: number, vz: number) -> (number, number, number)
Rotate a 3-vector by a quaternion.
Parameters
qxnumber— Quaternion x.qynumber— Quaternion y.qznumber— Quaternion z.qwnumber— Quaternion w.vxnumber— Vector x.vynumber— Vector y.vznumber— Vector z.
Returns (number, number, number) — Three numbers — the rotated vector.
local rx, ry, rz = Transform.quatRotateVec(qx, qy, qz, qw, 1, 0, 0)
typed/builtin//modules/transform/T/quatToEuler
T.quatToEuler(qx: number, qy: number, qz: number, qw: number) -> (number, number, number)
Convert quaternion to (yaw, pitch, roll). Alias of euler with
the explicit name so callers don't have to remember the order.
Parameters
qxnumber— Quaternion x.qynumber— Quaternion y.qznumber— Quaternion z.qwnumber— Quaternion w.
Returns (number, number, number) — Three numbers yaw, pitch, roll (Y, X, Z rotations).
local yaw, pitch, roll = Transform.quatToEuler(qx, qy, qz, qw)
typed/builtin//modules/transform/T/readVec3
T.readVec3(value: Vec3Input, label: string?) -> { number }
Normalize a vector a caller wrote to a plain { x, y, z } array.
Accepts a positional array {1, 2, 3}, a keyed table
{x =, y =, z =}, or a live vec handle. Missing components read as 0.
Raises when the value is not a vector; label names the caller in
that error.
Parameters
valueVec3Input— The vector to normalize.labelstring(optional) — Name reported in the error when the value is not a vector. Defaults to "Transform".
Returns { number } — A three-element array { x, y, z }.
local v = Transform.readVec3({ x = 1, y = 2, z = 3 })
typed/builtin//modules/transform/T/slerp
T.slerp(ax: number, ay: number, az: number, aw: number, bx: number, by: number, bz: number, bw: number, t: number) -> (number, number, number, number)
Spherical linear interpolation between two quaternions. Picks the shortest path (flips sign if dot < 0). Falls back to lerp+normalize when the two quats are very close (avoids div-by-zero on near-parallel inputs).
Parameters
axnumber— Start quaternion x.aynumber— Start quaternion y.aznumber— Start quaternion z.awnumber— Start quaternion w.bxnumber— End quaternion x.bynumber— End quaternion y.bznumber— End quaternion z.bwnumber— End quaternion w.tnumber— Interpolation factor[0, 1].
Returns (number, number, number, number) — Four numbers qx, qy, qz, qw — the interpolated unit quaternion.
local qx, qy, qz, qw = Transform.slerp(0, 0, 0, 1, 1, 0, 0, 0, 0.5)
typed/builtin//modules/transform/T/snapVec3
T.snapVec3(v: { number }, step: number | Vec3Input) -> { number }
Quantize each component of a vector to the nearest multiple of
step — a number for uniform steps, or a vector for per-axis steps.
A step of 0 on an axis leaves that axis at its exact value.
Parameters
v{ number }— The vector to quantize, as{ x, y, z }.stepnumber | Vec3Input— Uniform step size, or a per-axis vector of step sizes.
Returns { number } — A three-element array { x, y, z } snapped to the step grid.
local v = Transform.snapVec3({ 1.4, 2.6, -0.4 }, 1)
typed/builtin//modules/transform/T/toQuaternion
T.toQuaternion(rotation: any?, label: string?) -> { number }
Normalize a rotation a caller wrote to a { qx, qy, qz, qw }
quaternion. Accepts a quaternion ({x,y,z,w} or {x=,y=,z=,w=}) or
euler DEGREES ({pitch,yaw,roll} or {pitch=,yaw=,roll=}), so one
call site takes whichever form the caller finds natural. This is the
reading every rotation-taking surface in the engine shares, so a
quaternion and euler degrees mean the same thing at all of them.
Raises when the value matches no form; label names the caller in that
error, and a value that is one of the shapes a quaternion helper returns
is named as such along with the packing it goes in as.
Parameters
rotationany(optional) — The rotation to normalize, in any form of theRotationInputunion.labelstring(optional) — Name reported in the error when the value is not a rotation. Defaults to "Transform".
Returns { number } — A four-element array { qx, qy, qz, qw }.
local q = Transform.toQuaternion({ pitch = 0, yaw = 90, roll = 0 })
typed/builtin//modules/transform/T/tryQuaternion
T.tryQuaternion(rotation: any?, label: string?) -> ({ number }?, string?)
Read a rotation a caller wrote WITHOUT raising: returns the
canonical { qx, qy, qz, qw }, or nil and the message describing what
arrived. The forms are the RotationInput union — a quaternion
({x,y,z,w} or {x=,y=,z=,w=}) or euler DEGREES ({pitch,yaw,roll} or
{pitch=,yaw=,roll=}). Takes any value because reporting on a value that
is none of those forms is the whole job; a setter built on this raises the
returned message itself, so the error points at the line that wrote the
value rather than at the reading.
Parameters
rotationany(optional) — The value to read as a rotation.labelstring(optional) — Name reported in the message. Defaults to "Transform".
Returns ({ number }?, string?) — The quaternion { qx, qy, qz, qw }, or nil and the message.
local q, why = Transform.tryQuaternion(value, "myTool")
typed/builtin//modules/transform/T/vec/add
T.vec.add(ax: number, ay: number, az: number, bx: number, by: number, bz: number) -> (number, number, number)
Component-wise vec3 addition.
Parameters
axnumber— First vector x.aynumber— First vector y.aznumber— First vector z.bxnumber— Second vector x.bynumber— Second vector y.bznumber— Second vector z.
Returns (number, number, number) — Three numbers — the sum.
local x, y, z = Transform.vec.add(1, 2, 3, 4, 5, 6)
typed/builtin//modules/transform/T/vec/cross
T.vec.cross(ax: number, ay: number, az: number, bx: number, by: number, bz: number) -> (number, number, number)
Cross product a x b.
Parameters
axnumber— First vector x.aynumber— First vector y.aznumber— First vector z.bxnumber— Second vector x.bynumber— Second vector y.bznumber— Second vector z.
Returns (number, number, number) — Three numbers cx, cy, cz — the cross product.
local cx, cy, cz = Transform.vec.cross(1, 0, 0, 0, 1, 0)
typed/builtin//modules/transform/T/vec/dot
T.vec.dot(ax: number, ay: number, az: number, bx: number, by: number, bz: number) -> number
Dot product of two vec3s.
Parameters
axnumber— First vector x.aynumber— First vector y.aznumber— First vector z.bxnumber— Second vector x.bynumber— Second vector y.bznumber— Second vector z.
Returns number — The scalar dot product.
local d = Transform.vec.dot(1, 0, 0, 0, 1, 0)
typed/builtin//modules/transform/T/vec/length
T.vec.length(x: number, y: number, z: number) -> number
Euclidean length of a vec3.
Parameters
xnumber— Vector x.ynumber— Vector y.znumber— Vector z.
Returns number — The length.
local len = Transform.vec.length(1, 2, 3)
typed/builtin//modules/transform/T/vec/normalize
T.vec.normalize(x: number, y: number, z: number) -> (number, number, number)
Normalize a vec3. Returns zeros when the input is degenerate (length < 1e-8).
Parameters
xnumber— Vector x.ynumber— Vector y.znumber— Vector z.
Returns (number, number, number) — Three numbers — the unit-length vec3.
local nx, ny, nz = Transform.vec.normalize(0, 5, 0)
typed/builtin//modules/transform/T/vec/scale
T.vec.scale(x: number, y: number, z: number, s: number) -> (number, number, number)
Component-wise scalar multiplication of a vec3.
Parameters
xnumber— Vector x.ynumber— Vector y.znumber— Vector z.snumber— Scalar factor.
Returns (number, number, number) — Three numbers — the scaled vec3.
local x, y, z = Transform.vec.scale(1, 2, 3, 2)
typed/builtin//modules/transform/T/vec/sub
T.vec.sub(ax: number, ay: number, az: number, bx: number, by: number, bz: number) -> (number, number, number)
Component-wise vec3 subtraction (a - b).
Parameters
axnumber— First vector x.aynumber— First vector y.aznumber— First vector z.bxnumber— Second vector x.bynumber— Second vector y.bznumber— Second vector z.
Returns (number, number, number) — Three numbers — the difference.
local x, y, z = Transform.vec.sub(4, 5, 6, 1, 2, 3)
typed/builtin//modules/transform/T/worldToLocal
T.worldToLocal(px: number, py: number, pz: number, pqx: number, pqy: number, pqz: number, pqw: number, wx: number, wy: number, wz: number) -> (number, number, number)
Transform a world-space position into a parent's local space.
Parameters
pxnumber— Parent position x.pynumber— Parent position y.pznumber— Parent position z.pqxnumber— Parent rotation x.pqynumber— Parent rotation y.pqznumber— Parent rotation z.pqwnumber— Parent rotation w.wxnumber— World x.wynumber— World y.wznumber— World z.
Returns (number, number, number) — Three numbers lx, ly, lz — the local position.
local lx, ly, lz = Transform.worldToLocal(px, py, pz, pqx, pqy, pqz, pqw, wx, wy, wz)
typed/builtin//modules/tween/easing/E/list
E.list() -> { string }
List every canonical easing name (camelCase form). Useful for pickers / UI.
Returns { string } — Array of names, e.g. { "linear", "inQuad", "outQuad", ... }.
for _, n in ipairs(Easing.list()) do print(n) end
typed/builtin//modules/tween/easing/E/resolve
E.resolve(easing: string | EasingFn) -> EasingFn
Resolve an easing name (string) or function to an easing
function. Pass-through if easing is already a function. Raises
on unknown name or unsupported type.
Parameters
easingstring | EasingFn— Either an easing name (case-insensitive, optionaleaseprefix), or anEasingFn(returned unchanged).
Returns EasingFn — The resolved EasingFn.
local fn = Easing.resolve("easeInOutQuad")
local fn = Easing.resolve(function(t) return t * t end)
typed/builtin//modules/ui_motion_capture/M/register
M.register()
Register the ui_motion (change magnitude) and ui_motion_flow
(directional flow) capture views. Idempotent — safe to call at boot and
again later; re-registering keeps each view's channel.
require("@builtin::modules.ui_motion_capture").register()
typed/builtin//modules/up_frame/M/above
M.above(f: Frame, x: number, y: number, z: number, ly: number) -> { x: number, y: number, z: number }
A point ly along a frame's up from (x, y, z), in world space.
Parameters
fFrame— The frame.xnumber— Point X.ynumber— Point Y.znumber— Point Z.lynumber— How far along up.
Returns { x: number, y: number, z: number } — The point as { x, y, z }.
local head = Frame.above(f, px, py, pz, 1.8)
typed/builtin//modules/up_frame/M/at
M.at(x: number, y: number, z: number, groups: number?) -> Frame
The frame something standing at a point stands in: up against the
gravity there (Physics.upAt), so the world's frame wherever gravity
pulls down -Y, and the frame of a planet's surface where a
GravityField pulls toward it.
Parameters
xnumber— Point X, in world space.ynumber— Point Y.znumber— Point Z.groupsnumber(optional) — The collision membership of what stands there, as a bitmask (defaults to every group).
Returns Frame — The Frame.
local f = Frame.at(px, py, pz)
typed/builtin//modules/up_frame/M/follow
M.follow(f: Frame?, x: number, y: number, z: number, groups: number?, into: Frame?, reading: { [string]: any }?) -> (Frame, any)
The frame something standing at a point keeps as it moves: up
against the gravity there, carried there from f (Frame.transport)
while a GravityField acts, so a walk across a planet holds its heading
all the way round. Where no field acts it is the frame of the world's
gravity alone (Frame.at), the world's own frame wherever gravity pulls
down -Y.
Parameters
fFrame(optional) — The frame it kept until now, or nil for one starting here.xnumber— Point X, in world space.ynumber— Point Y.znumber— Point Z.groupsnumber(optional) — The collision membership of what stands there, as a bitmask (defaults to every group).intoFrame(optional) — Optional frame to write the answer into, kept by the caller (Frame.new); it may befitself. The world's own frame is refused.reading{ [string]: any }(optional) — Optional table the gravity read is written into (Physics.gravityFieldsAt'sinto), kept by the caller. Withintoandreadingboth given, following a frame allocates nothing.
Returns (Frame, any) — The Frame (into when one is given), and the Physics.gravityFieldsAt read at the point (reading when one is given).
frame = Frame.follow(frame, px, py, pz)
Frame.follow(held, px, py, pz, nil, held, heldReading)
typed/builtin//modules/up_frame/M/fromRotation
M.fromRotation(qx: number, qy: number, qz: number, qw: number) -> Frame
The frame a rotation turns the world's onto: its X, up and Z are the
world's +X, +Y and +Z turned by it. The inverse of a frame's rotation.
Parameters
qxnumber— Rotation X.qynumber— Rotation Y.qznumber— Rotation Z.qwnumber— Rotation W.
Returns Frame — The Frame.
local f = Frame.fromRotation(q.x, q.y, q.z, q.w)
typed/builtin//modules/up_frame/M/fromUp
M.fromUp(ux: number, uy: number, uz: number, into: Frame?) -> Frame
The frame whose up is (ux, uy, uz): the world turned the shortest
way that carries +Y onto it. An up of zero length is the world's frame.
Parameters
uxnumber— Up X.uynumber— Up Y.uznumber— Up Z.intoFrame(optional) — Optional frame to write the answer into, kept by the caller (Frame.new). The world's own frame is refused.
Returns Frame — The Frame: into when one is given.
local f = Frame.fromUp(1, 0, 0)
typed/builtin//modules/up_frame/M/isWorld
M.isWorld(f: Frame) -> boolean
Whether a frame is the world's own, to within a hair.
Parameters
fFrame— The frame.
Returns boolean — true when its up is +Y.
if Frame.isWorld(f) then ... end
typed/builtin//modules/up_frame/M/lookAt
M.lookAt(f: Frame, fx: number, fy: number, fz: number, tx: number, ty: number, tz: number) -> (number?, number?, number?, number?)
The rotation that looks from one point at another with the frame's
up as the view's up: a camera kept level with the ground a character
stands on, wherever on a planet that is. In the world's frame it is the
look-at Transform.lookAtQuat gives.
Parameters
fFrame— The frame.fxnumber— From X, in world space.fynumber— From Y.fznumber— From Z.txnumber— To X.tynumber— To Y.tznumber— To Z.
Returns (number?, number?, number?, number?) — qx, qy, qz, qw, or nil when the two points coincide.
local qx, qy, qz, qw = Frame.lookAt(f, cam.x, cam.y, cam.z, target.x, target.y, target.z)
typed/builtin//modules/up_frame/M/new
M.new() -> Frame
A new frame for a caller to keep and hand to Frame.standing as
the frame it writes its answer into, so a reading made every frame
allocates nothing. It starts as the world's own frame.
Returns Frame — The Frame, owned by the caller.
local held = Frame.new()
typed/builtin//modules/up_frame/M/standing
M.standing(e: any?, into: Frame?) -> Frame
The frame an entity stands in: the frame its CharacterController
walks it across (the controller's frame) when it carries one, and the
frame at its position (Frame.at) otherwise. What a reader of the
controller's inputX / inputZ or velocityX / velocityZ measures
them across. Given into, a frame the caller keeps (Frame.new), the
answer is written into it, and reading the frame of an entity carrying a
CharacterController allocates nothing: what a component reading it every
frame passes. The world's own frame (Frame.world()), which every caller
shares, is refused as into.
Parameters
eany(optional) — The entity proxy.intoFrame(optional) — Optional frame to write the answer into, kept by the caller.
Returns Frame — The Frame: into when one is given.
local f = Frame.standing(public.entity)
local held = Frame.new()
local f = Frame.standing(public.entity, held)
typed/builtin//modules/up_frame/M/toLocal
M.toLocal(f: Frame, wx: number, wy: number, wz: number) -> (number, number, number)
A world-space vector along a frame's axes.
Parameters
fFrame— The frame.wxnumber— World X.wynumber— World Y.wznumber— World Z.
Returns (number, number, number) — lx, ly, lz: along the frame's X, its up, and its Z.
local _, ny, _ = Frame.toLocal(f, n.x, n.y, n.z)
typed/builtin//modules/up_frame/M/toWorld
M.toWorld(f: Frame, lx: number, ly: number, lz: number) -> (number, number, number)
A vector given along a frame's axes, in world space.
Parameters
fFrame— The frame.lxnumber— Along the frame's X.lynumber— Along its up.lznumber— Along its Z.
Returns (number, number, number) — wx, wy, wz.
local wx, wy, wz = Frame.toWorld(f, dx, 0, dz)
typed/builtin//modules/up_frame/M/transport
M.transport(f: Frame, ux: number, uy: number, uz: number, into: Frame?) -> Frame
A frame carried onto a new up by the shortest turn from its own:
the frame something walking keeps from one moment to the next. A heading
held across a carried frame walks a straight line over a curved ground (a
great circle round a planet) and turns only where the ground turns it,
wherever on the planet that is. Frame.fromUp gives the same up with no
memory of the way there, and around the far side of a planet its axes
swing a full turn over a few steps.
Parameters
fFrame— The frame as it stood.uxnumber— New up X.uynumber— New up Y.uznumber— New up Z.intoFrame(optional) — Optional frame to write the answer into, kept by the caller (Frame.new); it may befitself. The world's own frame is refused.
Returns Frame — The carried Frame (into when one is given). An up of zero length leaves f as it stood.
frame = Frame.transport(frame, up.x, up.y, up.z)
Frame.transport(held, up.x, up.y, up.z, held)
typed/builtin//modules/up_frame/M/world
M.world() -> Frame
The world's own frame: up is +Y.
Returns Frame — The Frame.
local f = Frame.world()
typed/builtin//modules/vfs_async_read/M/installInto
M.installInto(vfs: VfsNamespace)
Install the yielding read wrapper onto the supplied vfs-shaped
namespace. The vfs API module calls this once on itself as it
loads; users shouldn't call it directly. No-op if the target
doesn't expose both read and readAsync as functions. A miss the
target's read answers nil, "pending" for raises
VFS_READ_CANNOT_WAIT where the reading code cannot yield, and is
waited for where it can. Every read that ends without bytes answers
nil and the reason the target's read gave beside its nil. The
target's list is wrapped the same way: a listing it answers
nil, "pending" for is waited for where the code can yield and
raises VFS_READ_CANNOT_WAIT where it cannot.
Parameters
vfsVfsNamespace— The target namespace table. Must carryreadandreadAsyncfunction fields (the engine'svfsglobal does); otherwise the install is a no-op.
require("@builtin::modules.vfs_async_read").installInto(vfs)
typed/builtin//modules/world_defaults/M/bind
M.bind(worldGuid: string, opts: { profile: string?, mode: string?, branch: string?, commit: string? }?) -> { [string]: any }
Bind a world on an engine that booted with no world and waits for one
(native --await-world, awaitWorld=1 in a browser launch, the Android
world chooser). The world is loaded in this process, the way a boot that
names it loads it, in the profile and mode opts names. The load is
asynchronous; the answer says whether it started. Its progress is
world.syncStatus().binding, and world.guid() names the world once it
is bound. Until a world is bound, a /source write is refused.
Parameters
worldGuidstring— The guid of the world to bind.opts{ profile: string?, mode: string?, branch: string?, commit: string? }(optional) —{ profile?, mode?, branch?, commit? }:profileis"editor"(edit the world) or"runtime"(play it), the engine's own when omitted;modeis"edit"or"play"("edit"for an editor,"play"for a runtime);branchis the branch to open;commitis the ref a runtime plays.
Returns { [string]: any } — { ok = true, worldGuid, profile, mode } or { ok = false, reason }.
world.bind("6b861afe-eb47-458d-89e1-ff0ec832958c", { profile = "editor" })
typed/builtin//modules/world_defaults/M/leave
M.leave() -> { [string]: any }
Leave the world world.bind bound and return the engine to waiting
for one: the world unloads, its content leaves /source, and another
world.bind binds the next. Asynchronous; the answer says whether the
leave started, and world.waitState().waiting reads true once it is done.
A leave made in play ends the play session: while that session holds
unaccepted changes the leave is refused with the accounting
engine.mode = "edit" gives, and engine.discardPlayChanges() arms the
next leave past it.
Returns { [string]: any } — { ok = true, worldGuid } or { ok = false, reason }.
world.leave()
typed/builtin//modules/world_defaults/M/offLoaded
M.offLoaded(handle: number) -> boolean
Stop a callback registered with world.onLoaded from running.
Parameters
handlenumber— The handleworld.onLoadedreturned.
Returns boolean — true when the handle matched a registered callback.
world.offLoaded(h)
typed/builtin//modules/world_defaults/M/offSaved
M.offSaved(handle: number) -> boolean
Stop a callback registered with world.onSaved from running.
Parameters
handlenumber— The handleworld.onSavedreturned.
Returns boolean — true when the handle matched a registered callback.
world.offSaved(h)
typed/builtin//modules/world_defaults/M/offUnloaded
M.offUnloaded(handle: number) -> boolean
Stop a callback registered with world.onUnloaded from running.
Parameters
handlenumber— The handleworld.onUnloadedreturned.
Returns boolean — true when the handle matched a registered callback.
world.offUnloaded(h)
typed/builtin//modules/world_defaults/M/onLoaded
M.onLoaded(cb: (...any) -> ()) -> number
Register a callback to run after a world finishes loading.
Parameters
cb(...any) -> ()— Called when the event fires, with whatever the event supplies.
Returns number — Handle for world.offLoaded.
local h = world.onLoaded(function() log.info("loaded") end)
typed/builtin//modules/world_defaults/M/onSaved
M.onSaved(cb: (...any) -> ()) -> number
Register a callback to run after a world is saved.
Parameters
cb(...any) -> ()— Called when the event fires, with whatever the event supplies.
Returns number — Handle for world.offSaved.
local h = world.onSaved(function() log.info("saved") end)
typed/builtin//modules/world_defaults/M/onUnloaded
M.onUnloaded(cb: (...any) -> ()) -> number
Register a callback to run after a world is unloaded.
Parameters
cb(...any) -> ()— Called when the event fires, with whatever the event supplies.
Returns number — Handle for world.offUnloaded.
local h = world.onUnloaded(function() log.info("unloaded") end)
typed/builtin//modules/world_defaults/M/reload
M.reload() -> { started: boolean?, guid: string?, branch: string?, error: string? }
Run the bound world again from the top, the way a fresh boot into it
would: the world unloads, its content is taken again, its entrypoint and
startup scene run. The load is asynchronous; the answer says whether it
started. An engine with no world bound answers { error }.
Returns { started: boolean?, guid: string?, branch: string?, error: string? } — { started = true, guid, branch } or { error = string }.
world.reload()
typed/builtin//modules/world_defaults/M/waitState
M.waitState() -> { [string]: any }?
Where an engine that booted with no world stands: nil on an engine
booted with its world; otherwise { waiting, source, chooser, next?, bound?, leaving, binds, leaves }, where waiting is true while no world
is bound, source is what asked for the wait (launcher for the world
chooser, await_world for a bare wait), chooser is true while the world
chooser is on screen, next says what binds a world from here while the
engine waits, bound is the bind that holds the engine ({ worldGuid, profile, mode, branch?, commit? }), and binds / leaves count the
binds and leaves made in this process. The state block of every execute
response carries chooser and next as world.waiting while the
engine waits.
Returns { [string]: any }? — The wait's state, or nil.
if world.waitState() and world.waitState().waiting then world.bind(guid) end
typed/builtin//modules/world_sync/M/installInto
M.installInto(world: WorldNamespace)
Graft syncStatus / resolveConflict onto the supplied world
namespace. The prelude calls this once at boot.
Parameters
worldWorldNamespace— The target namespace — typically the engine'sworldglobal.
require("@builtin::modules.world_sync").installInto(world)
typed/builtin//modules/world_sync/world/dropOwedWrites
world.dropOwedWrites(path: string?) -> { string }
Give up the changes this session still owes the world at path
and beneath it: the writes and removals vfs.pendingWrites() lists
there (a write the world never took included), the ones
world.syncStatus() names as conflicts or losses, and every stored
record of them on this machine, so no later boot re-applies one. Each
path then reads as the world's row holds it: the row's content, or
nothing where the world has no row. Returns the paths given up. The
bytes of a given-up change are not kept.
Parameters
pathstring(optional) — Canonical/sourcepath; defaults to the whole source tree.
Returns { string } — The paths given up, sorted.
world.dropOwedWrites()
world.dropOwedWrites("/zero/source/hud")
typed/builtin//modules/world_sync/world/resolveConflict
world.resolveConflict(path: string, mode: string, content: string?) -> ResolveResult
Resolve one /source record this session owes the world, one
path at a time: a conflicted one, or one whose write or removal the
server refused or the queue gave up on (unsaved_writes in
world.syncStatus()), which waiting never carries and which holds a
world.swap or world.checkout away from the world until it is
settled here.
mode is merge | apply | take-local | take-backend |
discard. merge returns { merged, clean } and mutates nothing
— a clean merge can be finalized with apply, and a conflicted one
carries <<<<<<< / ======= / >>>>>>> markers to edit first. apply
writes the finalized content to /source; take-local writes the
retained local bytes; take-backend / discard keep the backend
head. For a removal (deleted in world.syncStatus().conflicts),
take-local removes the path again and merge errors, since a
removal holds no content to merge. A move or a folder row the server
refused or the queue gave up on is settled at either of its paths:
take-backend / discard give it up and show the world's rows at its
paths again, and the other modes error, since it holds no content of
its own; vfs.move makes the move again. Errors when the record is absent,
a merge has no common ancestor, hits binary content or has sides
that differ from the ancestor by more than the line diff's step
bound (the error names the path), or a write fails.
Parameters
pathstring— Canonical/sourcepath of the conflicted record.modestring— One of merge | apply | take-local | take-backend | discard.contentstring(optional) — Finalized bytes forapplymode.
Returns ResolveResult
world.resolveConflict("/zero/source/foo.luau", "take-local")
local r = world.resolveConflict(p, "merge"); if r.clean then world.resolveConflict(p, "apply", r.merged) end
typed/builtin//modules/world_sync/world/syncStatus
world.syncStatus() -> SyncStatus
Read the durable-sync status: { subscribed, content_synced, content_sync_held, world_entry_held, outgoing_synced, uploads_outstanding, uploads_in_flight, progress, pending_writes, unrecorded_writes, owed_paths, unsaved_writes, held_uploads, uploads_abandoned, conflicts, binding }. Content sync runs in two
directions and each has its own answer: content_synced is incoming,
true once the world's content has been applied to this client and so
has every change to it the world's stream delivered since
(progress.unapplied counts the delivered changes still waiting), and
it says nothing about this session's own changes. outgoing_synced is
outgoing, true once every /source change this session made has
reached the world: nothing queued, uploading, held for another
attempt, unreflected by the manifest, kept in a durable record or a
conflict, or refused. Read outgoing_synced to know whether your
work is saved; uploads_outstanding counts the upload jobs it still
waits on, and uploads_in_flight the ones among them a flush has
taken and is carrying to the world. Both booleans read false with no
world subscribed.
content_sync_held is true while vfs.holdContentSync(true) holds
the content sync, which keeps content_synced false until released.
world_entry_held is true while world.holdEntry(true) holds the
world entry: a world load whose content is ready waits before the
world's entrypoint runs and its startup scene loads, with
binding.step reading entryHeld, until it is released.
owed_paths lists the /source paths this session wrote or removed
that the server has not taken yet, the same list vfs.pendingWrites()
returns.
conflicts maps each conflicted /source path to { base_sha, local_sha, backend_sha, isBinary, deleted };
deleted is true when the author's side is a removal of the path.
unsaved_writes lists the /source paths this session wrote,
removed or moved whose change the server never took (a move names
its source and its destination; a move the server refused shows the
world's rows at both again while the world holds its source), and
uploads_abandoned counts the uploads
the queue stopped carrying — read those two to tell a queue working
through a backlog from one that gave content up, which
pending_writes alone reads the same for. held_uploads lists the
owed changes whose upload failed and is being tried again, as
{ path, reason } (a move as { path, from, reason }): a stage or
commit of other content goes ahead past them, one naming such a path
waits on it and reports the reason, and removing a held write's path
ends its hold. unrecorded_writes lists
the owed paths whose durable record this machine could not store,
which a restart loses; pending_writes counts the owed records it
did store. binding names which
world holds /source — bound, unbound, binding,
session_only, waiting (no world, waiting for world.bind), or
unclassified before the boot has decided — and,
when a load attempt is on record,
which attempt is running, the step it is held at and for how long,
what the last one answered, and whether the load stopped. Read
binding to tell a world that is still coming from one that was
never asked for: subscribed answers false for both. Synchronous.
Returns SyncStatus
local s = world.syncStatus(); print(s.outgoing_synced, s.uploads_outstanding)
local s = world.syncStatus(); print(s.pending_writes)
local s = world.syncStatus(); for _, p in ipairs(s.unsaved_writes) do print(p) end
local s = world.syncStatus(); if s.binding.awaiting_world then print(s.binding.state, s.binding.attempt) end
typed/builtin//modules/world_vcs/M/__addAllReport
M.__addAllReport(stagedAfter: { string }, heldBefore: { [string]: boolean }, conflicted: { string }, released: { ReleasedPath }, written: { WrittenPath }) -> AddAllReport
The report world.add_all returns beside its held-back list: the
paths the call added to the staging area, every path it left out with
the reason, the paths it took from other staging areas, and the staged
paths a caller of another account is writing now.
Parameters
stagedAfter{ string }— The paths the staging area holds after the call.heldBefore{ [string]: boolean }— The paths it held before the call, as a set.conflicted{ string }— Paths left out for an unresolved conflict.released{ ReleasedPath }— The paths taken from other staging areas.written{ WrittenPath }— The staged paths a caller of another account is writing now.
Returns AddAllReport — { staged, held = { { path, reason } }, released, written }.
worldVcs.__addAllReport({ "/zero/source/a.luau" }, {}, {}, {}, {})
typed/builtin//modules/world_vcs/M/__answerChangedPathsFrom
M.__answerChangedPathsFrom(paths: any?)
Answer the changed-path read from paths in place of the world's
history and working tree, so a case can state which paths a push carries
on an engine that holds no history. false states that the history
cannot be read, and nil reads the history again.
Parameters
pathsany(optional) — The paths a push carries,false, or nil.
worldVcs.__answerChangedPathsFrom({ "/zero/source/a.module/README.md" })
typed/builtin//modules/world_vcs/M/__answerCommittedAreasFrom
M.__answerCommittedAreasFrom(rows: { CommittedArea }?)
Answer the committed-area read from rows in place of the world's
history, so a case can state which staging area committed an asset
on an engine that holds no history. nil reads the history again.
Parameters
rows{ CommittedArea }(optional) — The rows the read answers with, shaped as__spacetime_vcs.committedAreasreports them, or nil.
worldVcs.__answerCommittedAreasFrom({ { path = p, depth = 0, stage_name = "fauna", answers = true } })
typed/builtin//modules/world_vcs/M/__answerCommittedFrom
M.__answerCommittedFrom(answer: any?)
Answer the committed-content read of the publish gate from answer,
so a case can state what a commit holds on an engine that holds no history.
Parameters
answerany(optional) —{ paths, tree }: the paths the push changes, and the commit's tree as path to entry, each entry holding its text undertext; nil reads the history again.
worldVcs.__answerCommittedFrom({ paths = { "/zero/source/a.scene/scene.json" }, tree = { ["/zero/source/a.scene/scene.json"] = { text = "{}" } } })
typed/builtin//modules/world_vcs/M/__answerPublishedPathsFrom
M.__answerPublishedPathsFrom(paths: any?)
Answer the published-path read from paths in place of the branch
head's tree, so a case can state what a push publishes on an engine that
holds no history. false states that the history cannot be read, and
nil reads the history again.
Parameters
pathsany(optional) — The paths the branch head's tree holds,false, or nil.
worldVcs.__answerPublishedPathsFrom({ "/zero/source/a.bundle/entity_template" })
typed/builtin//modules/world_vcs/M/__appendWorldPlans
M.__appendWorldPlans(plans: { WorldPlanEntry }, more: { WorldPlanEntry })
Append to plans each world plan of more that names a world at a
commit no plan of plans names, so a world the plan reaches through a
kept release and through the installed version is listed once. Changes
plans in place.
Parameters
plans{ WorldPlanEntry }— The world plans listed so far.more{ WorldPlanEntry }— The world plans to add.
worldVcs.__appendWorldPlans({}, {})
typed/builtin//modules/world_vcs/M/__applyUpdates
M.__applyUpdates(units: any?, opts: UpdateOpts?, ops: ApplyUpdateOps) -> UpdateResult
Apply updates one unit at a time: libraries through the pin move,
installed assets through the install pull. A unit that raises is reported
in its entry with the reason and the next unit runs. Each step logs a line
as it starts (the check, then n of m for each unit, and why a unit was
not updated), which the task running the call carries as its output. The
units run in one read session (__withReadMemo), so a published version
several units plan is read from ZeroMind once. Stages, commits and pushes
nothing; the files with uncommitted changes it touched are named in
warnings.
Parameters
unitsany(optional) — Nil for every unit the check lists, a name, or a list of names.optsUpdateOpts(optional) —{ ref }, the ref every unit is updated to, or nil.opsApplyUpdateOps— AnApplyUpdateOps.
Returns UpdateResult — { results, to_commit, skipped, warnings, note }.
worldVcs.__applyUpdates({}, nil, { checkUpdates = function() return {}, {} end, libraries = function() return {} end, roots = function() return {} end, updateLibrary = function() return {} end, pullAsset = function() return {} end, rootVersion = function() return nil end, modifiedPaths = function() return {} end })
typed/builtin//modules/world_vcs/M/__askHeldReleases
M.__askHeldReleases(assets: { any }, held: { any }, moving: MovingPaths?) -> { any }
The plan of an install written again, with each dependency entry at a
release of held stating asked: the releases the install's files run
that the plan names already, which __heldReleasesToKeep lifts no copy
of. __oneReleasePerAsset weighs each as a release named from outside its
asset, so a release the world holds stands though the version names it
only from within its own asset. The dependency at moving (the one the
record is written again to move) is left as it is.
Parameters
assets{ any }— The plan's entries, which are only read.held{ any }— The dependencies the record places, asinstall.summariesstates them (path,asset_guid,checksum).movingMovingPaths(optional) — The path of the dependency the record is written again to move, a list of such paths, or nil.
Returns { any } — The plan, each marked entry a copy of the plan's.
local assets = worldVcs.__askHeldReleases({}, {}, nil)
typed/builtin//modules/world_vcs/M/__assetDepGuids
M.__assetDepGuids(guid: string) -> { string }
The guids of the assets the reference table of the asset guid
names (asset.deps): every link of its own content, each require, asset
reference, component and asset type. Empty when the table does not read.
Parameters
guidstring— The asset.
Returns { string } — The guids, in the table's order.
worldVcs.__assetDepGuids("5a774566-cc5a-4b39-8e23-a1a962937721")
typed/builtin//modules/world_vcs/M/__assetVersionOnLine
M.__assetVersionOnLine(guid: string, versionId: string, readPage: (string, string?) -> any, pages: number) -> any
The version versionId of the asset guid, found on the asset's line
as ZeroMind lists it (GET /v1/assets/{guid}/versions, newest first),
reading at most pages pages.
Parameters
guidstring— The asset.versionIdstring— The version to find.readPage(string, string?) -> any— Reads one page of the asset's versions:(guid, cursor) -> page, the page holdingversionsandnext_cursor.pagesnumber— The most pages read.
Returns any — The version's record (release_version, branch, on_main, ...), or nil when the pages read hold no such version.
worldVcs.__assetVersionOnLine(guid, "01M83VNRWEV9RTV6EANRK3NN54", readPage, 4)
typed/builtin//modules/world_vcs/M/__authoringRestoreScopes
M.__authoringRestoreScopes(dirty: { any }, targets: { string }) -> { scopes: { string }, journals: { string }, files: { string } }
The scenes whose authored state a restore of named paths takes back
with them. A scene's scene.json states the revision of the authored
state under its authoring folder, and a scene loads only while the two
agree, so they go back as one: a target that covers the scene (the scene,
a folder above it), names its scene.json, or lies inside its authoring
folder takes back the whole authoring folder, files no commit holds
included, and the scene.json beside it. The pending operations of the
scene's journal (scene_dirty/operations) are recorded against that
authored state and its revision, so they go back with it.
Parameters
dirty{ any }— The dirty rows of a status read.targets{ string }— The engine-canonical paths the restore names.
Returns { scopes: { string }, journals: { string }, files: { string } } — { scopes, journals, files }: the authoring folders, sorted, each for world.discardAll, the scene_dirty/operations folders beside them, each for world.discardAll where it exists, and the scene.json paths to restore beside them.
worldVcs.__authoringRestoreScopes(world.vcsStatus().dirty, { "/zero/source/scenes/main.scene" })
typed/builtin//modules/world_vcs/M/__awaitRestoreLanded
M.__awaitRestoreLanded(under: string, caller: string) -> { string }
Wait until the working copy holds the content a restore wrote at
under, each path at the version the working tree's row records
(__restoreLandTargets, __awaitWrittenBack).
Parameters
understring— The path the restore wrote, engine-canonical.callerstring— The name a raise is prefixed with.
Returns { string } — The paths the restore wrote, sorted.
worldVcs.__awaitRestoreLanded("/zero/source/a.md", "world.restore")
typed/builtin//modules/world_vcs/M/__awaitWorldLoaded
M.__awaitWorldLoaded(verb: string, seconds: number, read: () -> any, sleep: (number) -> ())
Wait, for at most seconds, while a load of the world is running: a
load attempt is on record (binding.step names the step it is at) and has
not stopped. A world's content and its template are written by the load,
so a commit made before it ends lands ahead of them, and a world whose
first commit landed that way never receives the template the load seeds
for a new world. A load held at entryHeld has written them already, and
is not waited on. Past the bound it raises, naming the step.
Parameters
verbstring— The call waiting, for the refusal.secondsnumber— How long to wait.read() -> any— Readsworld.syncStatus(); the seam a suite replaces.sleep(number) -> ()— Waits the given seconds; the seam a suite replaces.
worldVcs.__awaitWorldLoaded("world.commit", 300, world.syncStatus, task.waitRealtime)
typed/builtin//modules/world_vcs/M/__awaitWrittenAssetsMoved
M.__awaitWrittenAssetsMoved(before: { [string]: WrittenBefore }, caller: string)
Wait, once the content the world wrote back at each path of before
has landed, until the asset index states a version other than the one
before read for every asset the write moved: the asset at the path and
each folder asset enclosing it, for a path whose bytes the blob store now
holds (vfs.contentAddress: binary content, and text past the inline
size threshold) and whose content the write changed. The engine takes
the version of the folder asset holding such a file after the file reads
back, so a table derived before then pins the version the write
replaced; a file held in memory moves them as it lands. Raises naming
the assets still at their earlier version when none moves for the stall
window.
Parameters
before{ [string]: WrittenBefore }— What each written path stood at before the write, by path.callerstring— The name a raise is prefixed with.
worldVcs.__awaitWrittenAssetsMoved({ ["/zero/source/a.md"] = worldVcs.__writtenBefore("/zero/source/a.md") }, "world.restore")
typed/builtin//modules/world_vcs/M/__awaitWrittenBack
M.__awaitWrittenBack(targets: { InstallLandTarget }, caller: string) -> { string }
Wait until the working copy holds each of targets the world wrote
back, at the version it names: a file's bytes hash to it, a folder
asset's sidecar states it. Raises naming the paths still outstanding when
nothing more lands for the stall window.
Parameters
targets{ InstallLandTarget }— The paths written back, each with the version it lands at.callerstring— The name a raise is prefixed with.
Returns { string } — The paths of targets, in their order.
worldVcs.__awaitWrittenBack({ { path = "/zero/source/a.md", leaf = true } }, "world.restore")
typed/builtin//modules/world_vcs/M/__bringHolderReach
M.__bringHolderReach(assets: { any }, citing: { any }, brought: { [any]: boolean }, placedBy: { [any]: { holder: any, depth: number } }, readVersions: ({ { guid: string, checksum: string, depth: number?, commit: string? } }) -> ({ [string]: any }, { [string]: string }?), readHolders: { [string]: number }, wholeDepth: number) -> (number, { string })
Bring the dependencies the entries citing record, at the versions
they record, from the version that ships them: the outermost folder
version holding each citing entry that a completion read brought
(brought), or the version a dependency brought this way was read from
(placedBy). That folder version's closure is what the folder's own
install takes, so it states each dependency at the version the folder's
world holds, its own copy of another world's asset included. It is read
out to one edge past the citing entry's depth beneath it; a folder read
before is read out twice as far as the last time, up to wholeDepth, and
no further once that far. Every entry the read states that assets does
not hold at its version is appended, except the folder's own tree, which
completion places, and noted in placedBy with the folder and its depth
beneath it.
Parameters
assets{ any }— The closure's entries; the brought entries are appended to it.citing{ any }— The entries recording a dependencyassetsdoes not hold (__broughtReach).brought{ [any]: boolean }— The entries a completion read brought, as a set.placedBy{ [any]: { holder: any, depth: number } }— For each entry an earlier call appended,{ holder, depth }; updated.readVersions({ { guid: string, checksum: string, depth: number?, commit: string? } }) -> ({ [string]: any }, { [string]: string }?)— Reads a list of{ guid, checksum, depth, commit? }versions, as__completeFolderVersionstakes it.readHolders{ [string]: number }— The edge count each folder version was last read out to, by<guid>@<checksum>; updated.wholeDepthnumber— The edge count a whole read goes out to.
Returns (number, { string }) — How many entries it appended, and a line for each folder version no read answered for.
local added, problems = worldVcs.__bringHolderReach(assets, reach.citing, brought, {}, readVersions, {}, 1000000)
typed/builtin//modules/world_vcs/M/__broughtReach
M.__broughtReach(assets: { any }, entries: { any }, worlds: { any }, holds: (string, string) -> boolean) -> { deps: { any }, citing: { any }, worlds: { any } }
What the entries entries reach that the closure assets does not
hold: each dependency their reference tables record, at the version
recorded (an entry's entry_guid names the folder whose version the
checksum is), that no entry of assets holds at that version and holds
does not answer for; and each site on a world entry of those tables that
worlds (the closure's world entries) does not state. A folder completed
from its own read (__completeFolderVersions) brings its files without
what they reach, and an install runs them only with it. Engine-surface
dependencies and sites are the engine's, and are left out.
Parameters
assets{ any }— The closure's entries, completion's included.entries{ any }— The entries whose tables are read.worlds{ any }— The world entries the closure states.holds(string, string) -> boolean— Whether this world already holds an asset (guid,checksum).
Returns { deps: { any }, citing: { any }, worlds: { any } } — { deps, citing, worlds }: each missing dependency ({ asset_guid, checksum }, once), each entry recording one, and one world entry (world_guid, name, commit, sites) per world and commit with the sites worlds lacks.
local reach = worldVcs.__broughtReach(assets, brought, closure.worlds, function() return false end)
typed/builtin//modules/world_vcs/M/__builtinBehindNotice
M.__builtinBehindNotice(report: UpdateReport) -> string
The sentence the update check raises for a world pinned to an older
@builtin than the engine runs (a report with behind_engine): the
pinned and the engine's commits, that such a world is hidden from players
and that a package published from it carries copies of engine parts, the
call that moves the pin to the engine's version without asking, and what
to tell the user. It fits the length a notice of the built-in library
is delivered at whole.
Parameters
reportUpdateReport— The@builtinUpdateReport.
Returns string — The sentence.
worldVcs.__builtinBehindNotice({ kind = "library", library = "@builtin", from = "1111111aaa", to = "2222222bbb", behind_engine = true })
typed/builtin//modules/world_vcs/M/__bulkStage
M.__bulkStage(io: BulkStageIo, heldBefore: { [string]: boolean }, before: { [string]: any }) -> BulkStageOutcome
Complete a bulk stage after its one sweep of the dirty set: stage
the rows the sweep left, carry each staged path's asset family, and take
each staged path out of any other staging area holding it. Staging is
advisory, so the stage takes every dirty row whoever wrote it: a row
another caller is writing while its session is open is staged like any
other, and a staged path a caller of another account is writing now is
reported in written. A path is staged in one area at a time, so each
path the stage holds that another area held is taken out of that area,
whichever account opened it and whether or not its session is open, and
reported in released. The backend moves a path out of the area holding
it as it stages it, so the areas holding each path are read before the
sweep (before) as well as after it, and a path an area still holds
after the stage is taken out of it here.
An interior file staged on its own leaves the asset containing it
pinned to what the asset derived before the file changed, so each staged
path brings its asset family: the outermost asset it lies in and every
changed row beneath that asset.
The work is proportional to the dirty set: at most two status reads,
one batch of paths staged and one released per area.
Parameters
ioBulkStageIo— The reads and batches the stage runs on.heldBefore{ [string]: boolean }— The paths the calling area held before the sweep, as a set.before{ [string]: any }— The calling area's status read before the sweep: the areas holding each path, and who wrote each dirty row.
Returns BulkStageOutcome — What the stage took from other areas and from other accounts.
worldVcs.__bulkStage(io, heldBefore, before)
typed/builtin//modules/world_vcs/M/__callerStageNameFrom
M.__callerStageNameFrom(authorId: string?) -> string
The staging area a caller with this identity owns. authorId is the
connection key vfs.currentAuthor().connection answers with: the calling
session where the transport attested one, the ZeroMind account where it
attested only that, whatever name the world's roster gives the caller.
The agents sharing one connection share its area. A caller the transport named has an area of its own under that key;
a caller it did not name acts on the one shared area, because there is
nothing there to tell two such callers apart by.
Parameters
authorIdstring(optional) — The caller key, or nil for a caller the transport did not name.
Returns string — The staging area a call from that caller acts on.
worldVcs.__callerStageNameFrom("client:01M1VW") --> "client:01M1VW"
typed/builtin//modules/world_vcs/M/__carriedDescriptors
M.__carriedDescriptors(rows: { any }, named: (any) -> boolean) -> { [string]: boolean }
The descriptors a contribution carries beside the rows it names. A
change to a file of a folder asset publishes a new version of that folder
asset, under the release version its descriptor states
(__releaseDescriptorOf), so each folder asset holding a named row, up
to the outermost folder this world holds of the row's content
(__heldTopOf), goes with its descriptor as this world holds it: a
descriptor this world changed (a version stated past the one the origin
published) is among rows, and is carried whether or not the call named
it.
Parameters
rows{ any }— The ahead rows of one origin.named(any) -> boolean— Which rows the contribution names.
Returns { [string]: boolean } — Each carried descriptor row's path -> true; named rows are left out.
worldVcs.__carriedDescriptors(rows, function(r) return true end)
typed/builtin//modules/world_vcs/M/__carriedLines
M.__carriedLines(verb: string, carried: { DependencyPath }) -> { string }
The lines a staging call writes to its caller about the referenced assets it staged beside what was named.
Parameters
verbstring— The calling API's name.carried{ DependencyPath }— The referenced assets the call staged beside the named paths.
Returns { string } — One line per asset.
worldVcs.__carriedLines("world.add", report.carried)
typed/builtin//modules/world_vcs/M/__changedPathSet
M.__changedPathSet(workingPaths: () -> { string }, unpushed: { string }?) -> { [string]: boolean }?
The assets a push changes, as the set the description gate counts: every folder a changed path lies in, and the path itself. A path is changed when a commit the remote does not hold yet changed it, and when the working tree or the staging area holds it changed. Answers nil when the world's history cannot be read, which counts every asset as changed.
Parameters
workingPaths() -> { string }— Reads the paths the working tree and the staging area hold.unpushed{ string }(optional) — The paths the unpushed commits changed, when the caller read them.
Returns { [string]: boolean }? — A set keyed by path, or nil.
local changed = worldVcs.__changedPathSet(function() return { "/zero/source/a.module/init.luau" } end)
typed/builtin//modules/world_vcs/M/__changesWithin
M.__changesWithin(changes: { any }, paths: { string }) -> { any }
The file changes of an install's closures that lie at or beneath one of
paths.
Parameters
changes{ any }— The changes (__closureFileChanges).paths{ string }— Origin paths (originPathKeyform).
Returns { any } — Those changes, in the order given.
worldVcs.__changesWithin({}, { "kernel.module" })
typed/builtin//modules/world_vcs/M/__claimsOf
M.__claimsOf(reads: { any }) -> { any }
The rows several status reads list in claimed_by_other_stages,
one list. A staging call reads the areas holding its paths before it
stages them, since the backend moves a path out of the area holding it
as it stages it, and after, for an area that still holds one.
Parameters
reads{ any }— Status reads, each{ claimed_by_other_stages }, nil entries skipped.
Returns { any } — The rows, in the order the reads list them.
worldVcs.__claimsOf({ before, after })
typed/builtin//modules/world_vcs/M/__claimsTakenOut
M.__claimsTakenOut(before: { StageClaim }, after: { StageClaim }, targets: { string }) -> { StageClaim }
The paths another staging area held at or under one of targets
before an operation (before) that it holds no longer after it
(after): the staged rows the operation took out of that area. Each
row of before comes back once, in its order.
Parameters
before{ StageClaim }— Theclaimed_by_other_stagesrows read before the operation.after{ StageClaim }— Theclaimed_by_other_stagesrows read after it.targets{ string }— The engine-canonical paths the operation acted on;.stands for every path.
Returns { StageClaim } — The rows of before the operation took out of their area.
worldVcs.__claimsTakenOut(before.claimed_by_other_stages, after.claimed_by_other_stages, { "/zero/source/scenes/main.scene" })
typed/builtin//modules/world_vcs/M/__claimsTakenOutLines
M.__claimsTakenOutLines(verb: string, taken: { StageClaim }) -> { string }
The lines an operation writes to its caller about the staged rows it took out of other staging areas: one line per area, naming the area, whether the session holding it is open, and each path.
Parameters
verbstring— The calling API's name.taken{ StageClaim }— The rows__claimsTakenOutanswered.
Returns { string } — One line per area, in the order the areas first appear.
worldVcs.__claimsTakenOutLines("zm.restore", taken)
typed/builtin//modules/world_vcs/M/__closureAtAssetCap
M.__closureAtAssetCap(closure: any?) -> boolean
Whether a closure a batch item answered was cut at the server's asset
cap (M.__CLOSURE_ASSET_CAP), which only a read in pages reads past.
Parameters
closureany(optional) — The decoded closure.
Returns boolean — True when the closure is cut short and holds as many assets as the cap.
worldVcs.__closureAtAssetCap({ truncated = true, assets = {} }) --> false
typed/builtin//modules/world_vcs/M/__closureBatchAnswers
M.__closureBatchAnswers(body: string, count: number) -> { { ok: boolean, text: string } }
The answers of one closure batch request (__spacetime_vcs.readClosures),
one per item in request order: each item's answer is led by the group
separator ("\29") and is OK: with the item's closure in parts, or
ERR: with why ZeroMind refused the item. An answer that does not hold
one answer per item answers every item refused, saying so.
Parameters
bodystring— What the request answered.countnumber— How many items the request asked for.
Returns { { ok: boolean, text: string } } — One { ok, text } per item: whether it was read, and its closure in parts or the reason.
worldVcs.__closureBatchAnswers("\29OK:{\"assets\":[]}\29ERR:HTTP 404", 2)
typed/builtin//modules/world_vcs/M/__closureCurrentRecords
M.__closureCurrentRecords(assets: { any }) -> ({ any }, { any })
The entries of a closure that name records their paths hold now. A
closure can list two records of one world at one path: the asset an
author published there under one guid, and the asset published there
later under another. A dependency entry names a record its path no longer
holds when the closure lists a dependency of another guid at the same
path of the same world at a later version_id (a version stating none
ranks below every version that states one), and no reference recorded by
an entry outside its own tree names its guid. Such an entry and every
tree_child landing in it are left out, so one dependency path resolves to
one record; every other entry is kept, in the order the closure lists it.
Parameters
assets{ any }— The closure's entries.
Returns ({ any }, { any }) — The entries kept, and the entries left out.
local kept, left = worldVcs.__closureCurrentRecords(closure.assets)
typed/builtin//modules/world_vcs/M/__closureDependencyReleases
M.__closureDependencyReleases(assets: { any }) -> { [string]: { checksum: string, version_id: string, path: string } }
The newest release of each dependency a closure names, by asset guid:
the entries a dependency edge brought (requires, depends_on,
conforms_to), the later version_id standing for an asset the closure
names at two releases. A library this world mounts arrives by world_pull
and moves with its pin.
Parameters
assets{ any }— The closure's entries.
Returns { [string]: { checksum: string, version_id: string, path: string } } — { [guid] = { checksum, version_id, path } }.
worldVcs.__closureDependencyReleases({})
typed/builtin//modules/world_vcs/M/__closureFileChanges
M.__closureFileChanges(fromAssets: { any }, toAssets: { any }) -> { any }
The leaf files of an install that change between two of its closures, matched by asset guid: a file only the new closure holds is added, one only the old holds is removed, and one both hold at different checksums is changed. Folder assets are left out; their files are listed.
Parameters
fromAssets{ any }— The closure entries at the version the world holds.toAssets{ any }— The closure entries at the version it updates to.
Returns { any } — { guid, change, old, new } per file, sorted by origin path.
worldVcs.__closureFileChanges({}, {})
typed/builtin//modules/world_vcs/M/__closurePlacementKeys
M.__closurePlacementKeys(assets: { any }) -> ((any) -> string, (any) -> string, (any) -> string)
The key each entry of a closure's assets list is placed under, and
the key of the folder each tree_child entry lands in. A closure can name
one asset at more than one version (a file the installed content depends
on at one version, and the same file inside a folder version it depends on
at another), and one file at one version inside more than one folder
version. Each lands at a place of its own, so each is keyed apart: the
first one of an asset (its root or dependency entries first) is keyed by
the asset's guid, and each other by its version and the folder holding it.
A tree_child entry belongs to the entry whose identity its via_identity
names; without one, to the first entry of its via asset whose version
states this file at this version among its children, else to the first
entry of that asset. An entry's identity is its asset at its version, and
for a tree_child the identity of the entry it belongs to.
Parameters
assets{ any }— The closure's entries.
Returns ((any) -> string, (any) -> string, (any) -> string) — keyOf(entry), the key of an entry of assets; parentOf(entry), the key of the folder a tree_child entry lands in; identityOf(entry), the entry's identity.
local keyOf, parentOf = worldVcs.__closurePlacementKeys(closure.assets)
typed/builtin//modules/world_vcs/M/__collectUpdates
M.__collectUpdates(ops: CollectUpdatesOps) -> ({ UpdateReport }, { UpdateSkip }, number)
The units of the world that have an update available. A library is one
unit: its marker's requested_ref (default main) is resolved in the
library's world and reported when it names a commit other than the marker's
resolved_commit. @builtin is compared with the version this engine runs
when the engine names one (engineBuiltin): a pin older than it is
reported with to naming the engine's commit and behind_engine = true
when the move to that commit changes an asset the world's own content
names or one those assets reach through the library's reference tables
(builtinSitesMoving), or when what it changes cannot be read; an
older pin whose move changes none of them, and a pin at it or newer than
it, are current. An installed asset is one unit per marked root: the
root's recorded version is compared with the newest version of that asset at
its origin, one lookup per root. A dependency an install record places is
one unit too (placed_by names that install): the release the record
states is compared with the newest release at the dependency's own origin,
and an origin release older than the one the record states (by version id)
is current, unless the dependency's own line (releaseOrder,
__releaseOrder) places the origin's release after it: another world's
push of a package holding the dependency states a version id of its own,
later than releases the dependency's world made after it; a line that
cannot be read names the dependency in skipped. An install root current
by its own version is compared with
the origin's closure of it (dependencyMovesAtOrigin): the dependencies
the closure names newer are reported on the root as dependencies, with
from and to its unchanged version, and a dependency unit moving to the
release such a report brings is carried by that report. A root current
by its own version whose record places copies of part of another asset
the world holds (__partialCopies) is reported with their paths under
partial_copies, from and to its unchanged version, and those
dependencies are no units of their own.
A root whose origin world is a library's world is part of that
library, and a pulled row no table marks as a root (an install older than the
marks, content forked from another world) is not reported. A root is
compared with the head of the ref its install was asked for (the root's
install_ref: a branch name; resolved in the origin's world, the default
being main, the ref world.installLibrary resolves); a root whose ref
shaped like a fixed version (a commit id, version checksum or version id) the
origin does not hold as a branch is never behind, a branch named like one is
compared like any branch, and one whose row records no version is listed in
skipped as no recorded version. A unit whose origin cannot be reached, or does not answer
within the module's wait bound, is listed in skipped with the reason.
Parameters
opsCollectUpdatesOps— ACollectUpdatesOps.
Returns ({ UpdateReport }, { UpdateSkip }, number) — reports (libraries first, each group by name or path), skipped, and checked, the number of units the check could read.
worldVcs.__collectUpdates({ listMarkers = function() return {}, {} end, resolveRef = function() return "" end, markedRoots = function() return {} end, rootVersionAtOrigin = function() return "" end, refKindAtOrigin = function() return "branch" end })
typed/builtin//modules/world_vcs/M/__commitChain
M.__commitChain(start: string, stopAt: string?, fetchPage: (cursor: string?) -> any, cap: number, maxPages: number?) -> ({ any }, boolean)
The commits from start back along each commit's first parent, read
from an origin's log a page at a time: up to and excluding stopAt when it
is given, else to the end of the history. Holds at most cap commits and
reads at most maxPages pages; past either it stops and says so.
Parameters
startstring— The commit to start from.stopAtstring(optional) — The commit to stop before, or nil.fetchPage(cursor: string?) -> any— Reads the page aftercursor(nil for the newest):{ commits, next_cursor }.capnumber— The most commits listed.maxPagesnumber(optional) — The most pages read, nil forUPDATE_LOG_PAGES.
Returns ({ any }, boolean) — The commits, newest first, and whether the range holds more.
worldVcs.__commitChain("c", nil, function() return { commits = {} } end, 200)
typed/builtin//modules/world_vcs/M/__commitOnceWith
M.__commitOnceWith(held: () -> { string }, rebase: ({ string }) -> (), commit: () -> (boolean, string)) -> (boolean, string)
Materialise a staging area, bringing it onto the branch head there is now if a commit landed under it. An area a caller keeps across another caller's commit was opened against the head of the moment it was opened, and the backend refuses to build a commit on a head that has moved. Rebasing is dropping that area and opening one against the current head, then staging the paths the old one held — so the commit carries the caller's own paths and no one else's. Re-staging reads each path's content as the working tree holds it now, which is what a caller asking to commit them is asking to freeze. Any other refusal travels back as it came, and the rebase is attempted once: a second moved head is another caller committing again, which the caller hears about rather than the call looping on.
Parameters
held() -> { string }— Reads the paths the staging area currently holds.rebase({ string }) -> ()— Drops the area and stagesheld's paths onto a fresh one.commit() -> (boolean, string)— Materialises the area, answering the backend's(ok, message).
Returns (boolean, string) — The (ok, message) pair the surviving attempt produced.
worldVcs.__commitOnceWith(held, rebase, function() return true, "01J" end)
typed/builtin//modules/world_vcs/M/__commitOrder
M.__commitOrder(pinned: string, engine: string, fetchPage: (cursor: string?) -> any, maxPages: number) -> string
Where the commit pinned of a library's world stands against the
commit engine, read from the world's log newest first, a page at a time:
older when engine is listed first (or alone), newer when pinned is
listed first, same when they are one commit, and unknown when the
pages read name neither.
Parameters
pinnedstring— The commit the world pins.enginestring— The commit the engine runs.fetchPage(cursor: string?) -> any— Reads one page of the log:{ commits = { { commit_id } }, next_cursor }after a cursor (nil for the newest page).maxPagesnumber— The most pages read.
Returns string — older, newer, same or unknown.
worldVcs.__commitOrder("a", "b", function() return { commits = { { commit_id = "b" }, { commit_id = "a" } } } end, 10)
typed/builtin//modules/world_vcs/M/__commitRecordsAsset
M.__commitRecordsAsset(asset: string, status: LiveStageStatus) -> boolean
Whether the commit about to be made records the current version of
the asset at asset: its row, a file of it, or its install record
(<asset>.pull) is staged, or none of them is changed in the working
tree, so the head already holds the version the working tree runs.
Parameters
assetstring— The asset's path.statusLiveStageStatus— The working tree and the calling area, read once.
Returns boolean — Whether the commit records the asset's current version.
worldVcs.__commitRecordsAsset("/zero/source/vendor/util.module", status)
typed/builtin//modules/world_vcs/M/__committedAreas
M.__committedAreas(paths: { string }) -> { CommittedArea }
Which staging area committed each path at or under one of
paths, read from the world's history: every commit records the area
it materialised, so the answer is the same from every engine and every
session bound to the world, and survives the engine that made the
commit. Answers no rows when the engine holds no world session, which
leaves every asset the caller's own.
Parameters
paths{ string }— The asset paths to report on.
Returns { CommittedArea } — One row per commit that froze a path inside one of them through a named area, nearest the branch head first.
worldVcs.__committedAreas({ "/zero/source/a.component" })
typed/builtin//modules/world_vcs/M/__committedProblems
M.__committedProblems(paths: { string }, tree: { [string]: any }, host: { [string]: any }) -> { { path: string, typeName: string, problem: any } }
The problems an asset type's validateCommitted hook states for the
assets a push changes, read as the commit the push publishes holds them.
Parameters
paths{ string }— The paths the push changes.tree{ [string]: any }— The commit's tree, as path to entry.host{ [string]: any }—{ hookOf, mine, readText }:hookOf(typeName)is the type's hook or nil,mine(path)whether the path is the world's own content, andreadText(entry)the text of a tree entry or nil.
Returns { { path: string, typeName: string, problem: any } } — One { path, typeName, problem } per problem, in path order.
local rows = worldVcs.__committedProblems({ "/zero/source/a.scene/scene.json" }, {}, { hookOf = function() return nil end, mine = function() return true end, readText = function() return nil end })
typed/builtin//modules/world_vcs/M/__completeFolderVersions
M.__completeFolderVersions(assets: { any }, readVersions: ({ { guid: string, checksum: string, depth: number?, commit: string? } }) -> ({ [string]: any }, { [string]: string }?)) -> (number, { string })
Complete the folder versions of a closure from the reads of the
releases they land with. A folder version states its children
(content.children); a closure that lists the folder without an entry for
one of them gets that child's entry from a read of the folder at its
version, naming the folder's entry as its via_identity, and a folder
child brought that way is completed the same way. A folder the closure
holds beneath another folder version (a module of a package release) is
read through the outermost of them, out to one edge more than the folder
lies beneath it: a file of a release states the reference table that
release records for it, which a read of the file's own folder version
(the table recorded when that version was first published) can differ
from, so each file lands with the table of the release it lands in. A
child that read does not give comes from the folder's own read. The
folders are completed a level at a time: readVersions is handed every
version a level needs at once and answers each one's decoded closure by
its __versionReadKey, whose entries are seated at the paths its folder
versions state (__seatTreeChildren). Each version is read once at each
depth.
A folder held at a version its own asset has no version of (a folder
version holding another world's asset at a version of its own) is read
through the folder version holding it: that version read out to one edge
more than the folder lies beneath it, and then the one holding that, until
a read answers. A folder the plan read through a commit of another world
(read_commit, which __planBoundedPulls states on every entry it brings)
is read with that commit, and a child brought from it carries it too.
A folder no read answers for is named in the problems, and its files stay
out of the install.
Entries the reads answer that are not a missing child of the folder read
are left out. A folder marked container (__narrowToReach) lands
holding the files that declare it, and is not completed.
Parameters
assets{ any }— The closure's entries; the brought entries are appended to it.readVersions({ { guid: string, checksum: string, depth: number?, commit: string? } }) -> ({ [string]: any }, { [string]: string }?)— Reads a list of{ guid, checksum, depth?, commit? }versions (depththe edges read out to, one when absent;committhe one the entry was read through,read_commit, which__readVersionAtreads a version at that its checksum alone does not answer), answering each decoded closure by its__versionReadKey, and the reason each version that cannot be read failed by the same key.
Returns (number, { string }) — How many versions it read, and a line for each folder no read answered for.
local reads, problems = worldVcs.__completeFolderVersions(assets, readVersions)
typed/builtin//modules/world_vcs/M/__completeNewWorld
M.__completeNewWorld(startupScene: any?, holdsScene: (string) -> boolean, complete: () -> { string }) -> { string }
The template files a world's first commit carries when the world is missing them: when its settings name the template's own startup scene and the world holds no such scene (a world written to while its first load was still syncing, which that load left unseeded), every template file the world is missing is written. Answers the template files the world then holds, for the commit to stage; none for a world that holds its startup scene or names a scene of its own.
Parameters
startupSceneany(optional) — The world'sstartup_scenesetting: the scene's reference, or the name it states.holdsScene(string) -> boolean— Whether the world holds a scene of that name, or ever committed one (a scene the author removed stays removed).complete() -> { string }— Writes the missing template files and answers the template files the world holds.
Returns { string } — The template files to stage.
worldVcs.__completeNewWorld("scenes.main", function() return false end, function() return {} end)
typed/builtin//modules/world_vcs/M/__contributedText
M.__contributedText(text: string, mine: string?, base: string?, pathOfGuid: (string) -> string?, targetWorld: string?, holdsOwn: ((string) -> boolean)?, place: { file: string, landsAt: string, pathHere: (string, string?) -> string? }?) -> (string, { string }, any)
A contributed file's text as the world it is sent to reads it. Moving
or renaming an asset in this world rewrites the references that name it,
so a file can name a dependency the way only this world spells it (a path
it was moved to). Each reference the file's table mine states names an
asset: the member its site names when the site sits on a dependency on
the folder asset holding that member, else the dependency itself. A
reference is sent as the file spells it when it names that asset in the
target too: a spelling the version it was installed at (base, the table
it was published with, in either table shape) states for the same asset
at any of its sites, or one that names the asset there by where it stands
(M.__referenceHoldsThere, read with place). Every other reference is
put back the way the target reads the asset: an absolute path to a file
below the asset by the same file below the path the target holds the
asset at, else the way that version spelled the same asset (its site on
the same line, else its first site), and a reference that version did not
make is spelled by the path the target world holds the asset at. A
reference to an asset the target world holds nowhere and the published
version never named is one the contribution cannot carry, and is answered
in unresolved. The file's table is answered beside the text, spelled the
way the text is: each site names the literal sent, and each dependency the
published version named carries the version, version id and origin that
version stated for it (M.__pinContributedTable then states the version the
target holds). An asset this world holds from another world is, in this
world's table, a site on that world's entry. A site naming an asset of the
target world itself, or an asset the target holds as one of its own, is
answered as a dependency on that asset, the way the target's own table
states an asset of its own world; every other world entry is kept.
Parameters
textstring— The file's text in this world.minestring(optional) — The reference table this world holds for the file (JSON), or nil.basestring(optional) — The reference table it was published with (JSON), or nil.pathOfGuid(string) -> string?— Where the target world holds an asset, by guid, relative to its source root.targetWorldstring(optional) — The guid of the world the file is sent to, or nil.holdsOwn((string) -> boolean)(optional) — Whether the target holds an asset, by guid, as one of its own, or nil.place{ file: string, landsAt: string, pathHere: (string, string?) -> string? }(optional) — Where the file stands, or nil:file, its path in this world;landsAt, the path it lands at in the target;pathHere(guid, checksum), the path this world holds an asset at, at the version the file names when it names one (checksum, nil for a member of a dependency).
Returns (string, { string }, any) — The text for the target world, each reference it cannot carry (line N: "literal"), and the table for the text (nil when mine holds none).
worldVcs.__contributedText("return 1", nil, nil, function() return nil end)
typed/builtin//modules/world_vcs/M/__contributionAdds
M.__contributionAdds(rows: { any }, target: any?, folderAt: (string) -> any, rowsUnder: (string) -> { string }) -> { any }
The assets a contribution adds to the world it is sent to, each where
it lands there: every file the world added inside installed content
(added) whose asset the target holds nowhere, and every folder asset
this world holds below the outermost folder it holds of that content
(__heldTopOf) that the target holds nowhere either, at the path its
files land below. A folder asset is stated with the guid this world
holds it by, so a reference that names it names the same asset in the
target once the contribution lands, whether its files go with this
contribution or an earlier one carried them there.
Parameters
rows{ any }— The rows the contribution sends.targetany(optional) — WhatM.__contributionTargetanswers for the world it is sent to.folderAt(string) -> any— The folder asset this world holds at a path:{ asset_guid, kind, refs_json? }, or nil where the path is no folder asset.rowsUnder(string) -> { string }— The paths of the rows of this world's own at and under a folder (install.worldRowsUnder).
Returns { any } — One { path, asset_guid, is_composite, kind, refs_json? } per added asset, its path relative to the target's source root, sorted by path.
worldVcs.__contributionAdds({}, worldVcs.__contributionTarget({}, {}), function() return nil end, function() return {} end)
typed/builtin//modules/world_vcs/M/__contributionFolders
M.__contributionFolders(target: any?, entries: { any }, changedLeaves: { [string]: string }, folderChecksum: (string) -> string?) -> { any }
Adds to a contribution's entries the folder assets that move with the
files it changes. A folder asset of an install the target holds, holding
a changed file, is stated whole as a folder asset of the target's own
(target.installFolders): the folder at the checksum its files add up to
once the change lands, and every unchanged file and folder beneath it at
the version the install lists, replacing any entry the contribution
states at the folder's path. Every other folder asset holding a changed
file, and every folder asset the contribution adds, goes with the table
the target states for it (target.folderEntries).
Parameters
targetany(optional) — The target view (__contributionTarget).entries{ any }— The contribution's entries, each path relative to the target's source root; extended in place.changedLeaves{ [string]: string }— The changed files of installs, path -> new checksum, astarget.folderEntriesreads them.folderChecksum(string) -> string?— The checksum of a folder from its leaves, a JSON object of each leaf's path inside the folder to the hex sha256 of its bytes.
Returns { any } — entries.
worldVcs.__contributionFolders(worldVcs.__contributionTarget({}, {}), {}, {}, function() return nil end)
typed/builtin//modules/world_vcs/M/__contributionOrigin
M.__contributionOrigin(row: any?) -> string
The world each ahead row of rows goes back to: a change to an
install goes to the world the install was published from
(install_origin_world_guid), a change to a dependency it placed
included, and any other row to the world its asset was published from
(origin_world_guid).
Parameters
rowany(optional) — An ahead row.
Returns string — The world's guid.
worldVcs.__contributionOrigin({ origin_world_guid = "w" }) --> "w"
typed/builtin//modules/world_vcs/M/__contributionReleaseRefusal
M.__contributionReleaseRefusal(message: string, rows: { any }, pathOf: (any) -> string) -> string?
What a contribution ZeroMind refused RELEASE_VERSION_TAKEN asks of
this world. The contribution moves each folder asset holding a changed
file to a new version, and the version it states is the one the folder's
descriptor states as sent; a descriptor this world left as the origin
published it restates a version the origin already holds with other
content. Each folder the refusal names (__releaseTakenOf, its path
relative to the origin's source root) is named where this world holds it,
inside the outermost folder this world holds of a sent row's content
(__heldTopOf), with the descriptor to state a new version: in; a
folder of the origin enclosing all of that is named as the origin's.
Parameters
messagestring— The refused push's text, ZeroMind's JSON envelope included.rows{ any }— The rows the contribution sent.pathOf(any) -> string— The path a row lands at in the origin (__contributionTarget'spathOf).
Returns string? — The paragraph, or nil when the message is no such refusal.
worldVcs.__contributionReleaseRefusal(msg, rows, target.pathOf)
typed/builtin//modules/world_vcs/M/__contributionScriptBlock
M.__contributionScriptBlock(rows: { any }) -> any
The push gate's script-error blocker over what a contribution sends:
each Luau file among rows (the diverging leaves it carries) checked at
its path with the text this world holds there, the check a push of this
world holds those files to. A reference the contribution respells for the
origin (__contributedText) names the same asset there, so the text this
world resolves is the one judged. Nil when none carries an error the push
gate refuses, else the __spacetime_vcs.scriptPublishBlock shape over
those files.
Parameters
rows{ any }— The diverging rows the contribution sends.
Returns any — The blocker { count, detail, problems, remedy }, or nil.
worldVcs.__contributionScriptBlock({})
typed/builtin//modules/world_vcs/M/__contributionTablesUnstated
M.__contributionTablesUnstated(entries: { any }, readCommit: () -> (boolean, string)) -> ({ string }, string?)
The entries of a contribution whose table names what they reference
(dependencies, or other worlds) that the commit landing them states none
of: the commit is read back with readCommit (the commit as the world
stores it, its manifest.entries holding each row's deps and worlds),
and each such entry whose row there names neither is answered.
Parameters
entries{ any }— The contribution's entries, each withpathand itsrefs_json.readCommit() -> (boolean, string)— Reads the commit back:(ok, payload).
Returns ({ string }, string?) — The paths, sorted, and the read's failure text when the commit could not be read (every such path is answered then).
worldVcs.__contributionTablesUnstated({}, function() return true, "{}" end)
typed/builtin//modules/world_vcs/M/__contributionTarget
M.__contributionTarget(entries: { any }, records: { any }) -> {
Where a contribution lands each change in the world it is sent to, read
from that world's current content: its manifest entries (paths relative
to its source root) and the installs it holds (records, each { dest, record } with dest relative to its source root). An asset is found by
its guid: where the world holds it as a file of its own, or where one of
its installs places it. A file the world holds no asset of lands below the
root of the asset it belongs to, wherever that world holds that root. A
file of the contributed install itself, or of a dependency sent to the
world it was published from (own_world), lands at its published path,
and a file of a dependency the world holds nowhere lands in the world's
dependency area, deps/<the dependency's world>/<its published path>, the
place an install puts a dependency.
Parameters
entries{ any }— The target world's manifest entries.records{ any }— The installs the target world holds.
Returns { pathOf, theirs, pathOfGuid, holdsOwn, versionOfGuid, tableAt, folderEntries, installFolders, dependents, adds }: pathOf(row) answers the path relative to the target's source root; theirs(path) the checksum the target holds there, or nil; pathOfGuid(guid) where the target holds that asset, or nil; holdsOwn(guid) whether one of the target's own manifest entries holds it (an install's listing places the assets it holds otherwise); versionOfGuid(guid) the version it holds of it, or nil; tableAt(path) the reference table the target states for the asset at a path (the manifest entry's deps / worlds / problems, or the install listing's refs_json), or nil; folderEntries(changed, hash) the entries that move each folder asset holding a changed file to the checksum its files hold once the change lands; installFolders(sent, hash) the entries that state each folder asset of an install the target holds (<dest>.pull) holding a file sent (the contribution's entries) states, and each edited folder asset of an install beneath one, as a folder asset of the target's own, whole, as a push of the target states an edited install (__editedInstallFolders): the folder at the checksum its files add up to once the change lands, then every file and folder beneath it that the target holds through the record alone, at the checksum and identity the record lists, with the table the record lists for it, children deepest first, then the folders, deepest first; dependents(moved, sent) the target's own entries outside sent (path -> true) whose tables pin an asset of moved (guid -> its new version) at another version, each in the shape a contribution sends; adds(added) places the assets a contribution adds (__contributionAdds) where they land, so pathOfGuid and holdsOwn answer for them and folderEntries states each added folder asset over the files below it the target holds once the change lands, whether or not changed holds one of them. A folder asset is placed only where the target holds nothing at its path and a file lands below it: one the target holds, or one added places.
worldVcs.__contributionTarget({}, {})
typed/builtin//modules/world_vcs/M/__contributionTexts
M.__contributionTexts(rows: { any }, target: any?, targetWorld: string?, read: ((string) -> string?)?, held: ((string, string?) -> string?)?) -> { texts: { [string]: string }, tables: { [string]: any }, untranslatable: { string } }
The text and reference table each file of a contribution is sent
with, as the world it is sent to reads them (M.__contributedText over
each text file of an install among rows, each read where it stands in
this world and where it lands in the target).
Parameters
rows{ any }— The rows the contribution sends.targetany(optional) — WhatM.__contributionTargetanswers for the world it is sent to.targetWorldstring(optional) — The guid of that world.read((string) -> string?)(optional) — The text this world holds at a path, or nil (defaultM.__workingRead).held((string, string?) -> string?)(optional) — The path this world holds an asset at (guid, and the version a file names,checksum, or nil), or nil (default:asset.pathHoldingat that version, elseasset.source).
Returns { texts: { [string]: string }, tables: { [string]: any }, untranslatable: { string } } — { texts, tables, untranslatable }: texts the text sent for each path whose text differs from this world's, tables the table sent for each path, untranslatable each reference no text can carry (<path> line N: "literal").
worldVcs.__contributionTexts({}, worldVcs.__contributionTarget({}, {}), nil)
typed/builtin//modules/world_vcs/M/__convertInstallRecord
M.__convertInstallRecord(entry: InstallEntry, rowByPath: { [string]: any }, pace: (() -> ())?) -> { record: { [string]: any }, drop: { string }, kept: { string }, removed: { string } }
The record of an install that stands as pulled rows: built from the rows themselves, with no network read. The root's row names the asset, its version and its origin; the rows beneath the root are its listing; every other row of the install belongs to the dependency whose root it lies in. A file row the user changed (its bytes are no longer the version's) is not listed and stays a row of the world; folder rows and unchanged files are listed and are the rows the conversion takes out. A row that stands for a deletion (the user deleted the file, or an earlier update took the row out) is neither listed nor taken out: the record names its path as removed, and the deletion goes with the next commit.
Parameters
entryInstallEntry— The install, as__groupInstallsstates it.rowByPath{ [string]: any }— The pulled manifest rows by path.pace(() -> ())(optional) — Called between rows; a caller that must not hold a frame yields from it.
Returns { record: { [string]: any }, drop: { string }, kept: { string }, removed: { string } } — { record, drop, kept, removed }: the record document, the paths of the rows to take out, the paths of the changed files that stay and the deleted paths the record names as removed.
worldVcs.__convertInstallRecord(entry, rowByPath)
typed/builtin//modules/world_vcs/M/__convertOverRecordRefusal
M.__convertOverRecordRefusal(entry: InstallEntry, rowByPath: { [string]: any }, records: { InstalledRoot }) -> string?
Why the rows of an install are not converted when an install record already stands at their root: converting them writes the record their version states in place of the one that stands, which takes the install back to the rows' version. Nil when no record stands at the root.
Parameters
entryInstallEntry— The install, as__groupInstallsstates it.rowByPath{ [string]: any }— The pulled manifest rows by path.records{ InstalledRoot }— The installs that stand as one record, as__recordRootsstates them.
Returns string? — The sentence naming the install, both versions and where to read them, or nil.
worldVcs.__convertOverRecordRefusal(entry, rowByPath, {})
typed/builtin//modules/world_vcs/M/__convertRowInstall
M.__convertRowInstall(rootPath: string, plan: { record: { [string]: any }, drop: { string }, kept: { string } }, rows: { [string]: any }, ops: InstallRecordOps, complete: () -> string?) -> { completion: string? }
Convert one install that stands as one pulled row per file (an earlier
engine's install) into one record, whole or not at all. The record the
rows state is written and materialized while the rows still stand, the
rows it states leave (their files stay where they stand), and complete
states the record again from the published version. When complete
raises, the record the rows state is written back and held to the install
gate; when that record does not run either, it is taken out and every row
that left is written back, so the world holds the install as it did, and
the call raises naming why.
Parameters
rootPathstring— The install's root path.plan{ record: { [string]: any }, drop: { string }, kept: { string } }— The conversion, as__convertInstallRecordstates it.rows{ [string]: any }— The pulled rows by path, as the world held them.opsInstallRecordOps— The engine the conversion runs against.complete() -> string?— States the record again from the published version and answers a note about it, or nil; raises when it could not.
Returns { completion: string? } — { completion }: why the record stands as the rows stated it rather than as the published version, or nil when the published version took its place.
worldVcs.__convertRowInstall("/zero/source/a.package", plan, rowByPath, ops, function() return nil end)
typed/builtin//modules/world_vcs/M/__copyNameReaches
M.__copyNameReaches(summaries: any?, footprint: { [string]: boolean }?) -> (guid: string) -> HeldCopy?
The copy of an asset a name reaches in this world (asset.source),
by the asset's guid, as __releasesBesideHeld and __recordsBesideHeld
read it: where it stands, the version it holds now, and the install
record placing it (the root of an install, a dependency it places, or
content beneath either) with the release that record states. A copy
holding another version than its record states was edited where it
stands. A path in footprint (the files of an earlier install of the
root being installed, which the install states again) reaches nothing.
Parameters
summariesany(optional) — Whatinstall.summariesanswers.footprint{ [string]: boolean }(optional) — The paths of the earlier install of the root being installed, or nil.
Returns (guid: string) -> HeldCopy? — reach(guid): the copy, or nil when no copy of the asset stands in the world.
local reach = worldVcs.__copyNameReaches({}, nil)
typed/builtin//modules/world_vcs/M/__decodeClosure
M.__decodeClosure(read: boolean, body: any?) -> any?
A closure read as the backfill uses it: the decoded { assets },
narrowed to the records its paths hold now (__keepCurrentRecords), or nil
when the read failed or its body does not decode to one. Never raises.
Parameters
readboolean— Whether the read was answered.bodyany(optional) — The answer's text.
Returns any? — The closure, or nil.
worldVcs.__decodeClosure(true, "{\"assets\":[]}")
typed/builtin//modules/world_vcs/M/__decodeClosureParts
M.__decodeClosureParts(body: string) -> (boolean, any)
The closure a closure read answered (installAssetClosure,
versionClosure), decoded a part at a time: the answer is JSON objects
separated by the record separator ("\30"), every one but the last holding
assets alone and the last the rest of the assets, the blobs and the
closure's own fields. The assets come back in the order the parts list
them. Between parts it gives the frame back once its slice is spent, when
the caller's thread can yield, so a closure of tens of thousands of assets
never decodes inside one frame. A single JSON object is one part.
Parameters
bodystring— The answer's text.
Returns (boolean, any) — Whether every part decoded, and the closure or the decode error.
worldVcs.__decodeClosureParts("{\"assets\":[{\"asset_guid\":\"a\"}]}\30{\"assets\":[],\"blobs\":[],\"truncated\":false}")
typed/builtin//modules/world_vcs/M/__dependencyFindingNotices
M.__dependencyFindingNotices(findings: { string }?) -> { string }
The install's notices for what a type's validate hook finds in
content that stands as published (the third list __installLoadProblems
answers): one notice per finding, naming the asset, its type and the
finding, and saying it was installed as its publisher published it.
Parameters
findings{ string }(optional) — The finding lines, or nil.
Returns { string } — The notices, in the order given.
worldVcs.__dependencyFindingNotices({ "/zero/source/deps/w/a.scene (scene): This scene has no camera." })
typed/builtin//modules/world_vcs/M/__dependencyMoveOps
M.__dependencyMoveOps() -> DependencyMoveOps
The operations a dependency move runs against this engine.
Returns DependencyMoveOps — A DependencyMoveOps.
worldVcs.__dependencyMoveOps()
typed/builtin//modules/world_vcs/M/__dependencyMoveOwner
M.__dependencyMoveOwner(dep: InstalledRoot, ops: DependencyMoveOps) -> any
The install record summary of the install that places dep
(placed_by); raises when the world no longer installs it.
Parameters
depInstalledRoot— The dependency, as__recordDependencyRootsstates it.opsDependencyMoveOps— What the move reads.
Returns any — The owner's summary, as install.summaries states it.
worldVcs.__dependencyMoveOwner(dep, worldVcs.__dependencyMoveOps())
typed/builtin//modules/world_vcs/M/__dependencyMoves
M.__dependencyMoves(releases: { [string]: { checksum: string, version_id: string, path: string } }, placed: { any }) -> { DependencyMove }
The dependencies an install places at an older release than a closure
of its root names: an asset whose newest placed release (by version_id)
is neither the closure's release nor a later one. An asset placed at two
releases counts as held at each, and a release stating no version_id is
ordered by none, so it differs from the closure's by its checksum alone.
Parameters
releases{ [string]: { checksum: string, version_id: string, path: string } }— The closure's releases (__closureDependencyReleases).placed{ any }— What the install places:{ path, asset_guid, checksum, version_id }.
Returns { DependencyMove } — One DependencyMove per asset, sorted by path.
worldVcs.__dependencyMoves({}, {})
typed/builtin//modules/world_vcs/M/__dependencyOwners
M.__dependencyOwners(assets: { any }) -> (any) -> any
The dependency entry of a closure each entry lands beneath: for a
tree_child, the dependency (requires, depends_on, conforms_to) its
chain of folders (__closurePlacementKeys) starts from; for a dependency,
itself. False for an entry beneath no dependency (the installed root's own
files).
Parameters
assets{ any }— The closure's entries.
Returns (any) -> any — ownerOf(entry).
local ownerOf = worldVcs.__dependencyOwners(closure.assets)
typed/builtin//modules/world_vcs/M/__dependencyPlacementPaths
M.__dependencyPlacementPaths(entry: any?) -> { plain: string, versioned: string }
The two paths an install can place one dependency of a closure at, under
the dependency tree beside the world it belongs to: its install path, where
it lands when the world holds nothing of it and no other version in the
closure holds that path first, and the version's own folder, where it lands
otherwise. computeClosurePlacement places by these and the install-root
backfill looks for a placed dependency there.
Parameters
entryany(optional) — The closure entry of the dependency.
Returns { plain: string, versioned: string } — { plain, versioned }.
worldVcs.__dependencyPlacementPaths({ owning_world = "w", path = "a/b.module", checksum = "c" })
typed/builtin//modules/world_vcs/M/__dependencyPullRefusal
M.__dependencyPullRefusal(rows: { any }, path: string?, guid: string?) -> string?
The refusal for a pull aimed at a pulled row that belongs to an
install without being its root: <path> is a dependency of the install <display name> (<root path>); update the root. A root, a row no install
holds, and an asset guid that has a root row answer nil.
Parameters
rows{ any }— The pulled manifest rows, each with itsrefs_jsontable.pathstring(optional) — The row's path, or nil.guidstring(optional) — The asset guid the pull names, or nil.
Returns string? — The refusal text, nil when the pull may run.
worldVcs.__dependencyPullRefusal({}, "/zero/source/deps/w/a.module", nil)
typed/builtin//modules/world_vcs/M/__dependencyPullResult
M.__dependencyPullResult(dep: InstalledRoot, result: InstallAssetResult) -> PullAssetResult
A dependency move's answer as one unit of world.update: the
dependency and each file of the world's own that took the new release
as merged (nothing when it held that release already), each whose edit
conflicts with it as a conflict, the files outside it it broke, and the
release its path holds (root_version).
Parameters
depInstalledRoot— The dependency, as__recordDependencyRootsstates it.resultInstallAssetResult— The move's answer (__moveRecordDependency).
Returns PullAssetResult — A PullAssetResult.
worldVcs.__dependencyPullResult(dep, result)
typed/builtin//modules/world_vcs/M/__dependencyReleaseRefusal
M.__dependencyReleaseRefusal(dest: string, prior: any?, record: any?, movingTo: MovingReleases?, releaseSplits: { string }?, libraries: { [string]: boolean }?) -> string?
Why a record written again was refused for the releases its
dependencies would land at, or nil when it may be written: each asset
whose newest release the record places is older (by version_id, a
release a move ranks just after the one it held by that move's rank_id)
than the newest the record the world holds places, holding other bytes
(one release stated under two version ids is the same release; a
dependency that record names deleted is one it places no release of),
and, for a record written again to move a dependency (movingTo),
another release of that asset at the dependency's path. A release of it
the record keeps in a recorded
version's folder for the files that name it stands beside the moved
one, and the update check lists it under that path
(__recordDependencyRoots). The reason names each path and release,
the install, the dependencies the install lands at more than one release
(releaseSplits), and the calls that resolve it. A version of a library
this world mounts (libraries, by the origin world the record states for
it) is the version the sites of the files naming it resolve to, so the
comparison leaves the releases of a library's assets out.
Parameters
deststring— Where the install stands.priorany(optional) — The record the world holds for the install, decoded, or nil.recordany(optional) — The record about to be written.movingToMovingReleases(optional) — The release a dependency is moved to, a list of them for dependencies moved in one writing of the record, or nil.releaseSplits{ string }(optional) — The lines naming each dependency the install lands at more than one release.libraries{ [string]: boolean }(optional) — The worlds of the libraries this world mounts, by guid, or nil for none.
Returns string? — The reason, or nil.
worldVcs.__dependencyReleaseRefusal("/zero/source/a.package", nil, { deps = {} }, nil, {}, nil)
typed/builtin//modules/world_vcs/M/__derivesRequiredOutput
M.__derivesRequiredOutput(assetPath: string, typeName: string, file: string) -> boolean
Whether file of the asset at assetPath is the output of a
required derive hook that accepts the asset: an output staging the asset
reserves and its commit waits on.
Parameters
assetPathstring— The asset's path.typeNamestring— The asset's type.filestring— The file, relative to the asset.
Returns boolean — True when a required hook computes it.
worldVcs.__derivesRequiredOutput("/zero/source/a.bundle", "bundle", "preview.png")
typed/builtin//modules/world_vcs/M/__describeReferenceMove
M.__describeReferenceMove(move: ReferenceMove) -> string
The text naming one change that moved references: the pin of a library with its marker, or the asset's path.
Parameters
moveReferenceMove— The change.
Returns string — The text.
worldVcs.__describeReferenceMove({ library = "@builtin" }) --> "the pin of `@builtin` (/source/libs/@builtin)"
typed/builtin//modules/world_vcs/M/__diffChangedPaths
M.__diffChangedPaths(diff: any?) -> { [string]: boolean }
The paths a diff of two commits of one world names as added, modified or removed, each relative to the world's root. A folder asset whose content changed is listed beside the files that changed in it.
Parameters
diffany(optional) — Thediffof a ZeroMind commit diff:{ added, modified, removed }.
Returns { [string]: boolean } — Each path, as a key.
worldVcs.__diffChangedPaths({ added = {}, modified = { "modules/a.module", "modules/a.module/init.luau" }, removed = {} })
typed/builtin//modules/world_vcs/M/__discardAllCalls
M.__discardAllCalls(scope: string, plan: DiscardAllPlan) -> { { path: string, keep: { string }, also: { string } } }
The backend discards that carry out plan under scope: one call
for the whole scope, naming the paths it leaves (keep) and the rows
outside it it takes (also), while those names fit the backend's bound
on a call's arguments. When they do not, one call per path the plan
takes back, each naming only the kept paths beneath that path.
Parameters
scopestring— The engine-canonical path the discard covers.planDiscardAllPlan— TheDiscardAllPlanfor that scope.
Returns { { path: string, keep: { string }, also: { string } } } — { { path, keep, also } }, the calls in order.
worldVcs.__discardAllCalls("/zero/source", plan)
typed/builtin//modules/world_vcs/M/__discardAllPlan
M.__discardAllPlan(status: any?, scope: string) -> DiscardAllPlan
What discarding every change under scope does, decided from one
status read (read with the rows of installs left in): which rows are
taken back, which are left where they are, and which staged paths need
their staged copy written back first. The paths a staging area holds
stay (a staged file is not a change in the Changes list), as do the
ignored rows (a scene's autosave overlay aside: it goes with the rest),
the unmerged paths, the rows another account is changing,
a file listed only because its references moved (its bytes are the
committed ones, so there is nothing to take back), and a dependency
another install records too. An install whose root lies
in the scope goes back whole; an install whose root lies outside it
keeps its rows inside the scope.
Parameters
statusany(optional) — The status read, withinstalls, the install rows and the ignored rows listed.scopestring— The engine-canonical path to discard beneath.
Returns DiscardAllPlan — A DiscardAllPlan.
worldVcs.__discardAllPlan(world.vcsStatus({ ignored = true }), "/zero/source")
typed/builtin//modules/world_vcs/M/__discardInstallWith
M.__discardInstallWith(install: InstallEntry, installs: { InstallEntry }, ops: any?)
Put an install back at the version the branch head holds, through
ops: every row of it that the staging area holds leaves the area, then
every row goes back to its committed version, or away when no commit
holds it. Rows of the install the area does not hold are put back as
they are, so the install goes back whether its rows are unstaged, staged
or both. A row another install records as well stays.
Parameters
installInstallEntry— The install being discarded.installs{ InstallEntry }— Every install the working tree lists.opsany(optional) —{ staged, unstage, discardRows, changed }: the paths the area holds, taking one path out of the area, putting one path back, and the paths the working tree holds a change for.
worldVcs.__discardInstallWith(install, installs, ops)
typed/builtin//modules/world_vcs/M/__discardInstalledContentWith
M.__discardInstalledContentWith(target: string, ops: any?) -> boolean
Carry out a discard of target that reaches installed content
(M.__installedContentDiscard), through ops: the install record goes
back to its staged or committed version, each row of the world's own
standing over an install's file leaves the world so the install's file
stands again, and the changed rows a commit or a staging area holds a
version of at or beneath target go back to that version. Answers false,
touching nothing, when target reaches no installed content.
Parameters
targetstring— The engine-canonical path the discard names.opsany(optional) —{ dirty, changes, facts?, discardRows, takeOut, awaitBack }: the dirty rows (with the install rows left in), whatinstall.changesanswers, theInstalledFileFactsread with those rows, putting a path back to its staged or committed version, taking the world's own row at a path out of the world, and waiting until the given paths read as their installs state them.
Returns boolean — True when the discard reached installed content and was carried out.
worldVcs.__discardInstalledContentWith("/zero/source/kit.package", ops)
typed/builtin//modules/world_vcs/M/__dropMemberRestatements
M.__dropMemberRestatements(assets: { any }) -> ({ any }, { any })
The dependency entries of a closure that restate a member of its root,
each with its own tree. A requires, depends_on or conforms_to entry
naming an asset at the version (checksum) the root states, or a
tree_child entry of the root's own tree states, is that member: a release names
one of its own members as a dependency when a file of it pins the
version a world it was contributed from published, and ZeroMind lists
that version, with its own tree and reference tables, beside the member.
The member is the copy an install places, so the restatement leaves the
closure, and each file and folder of its tree leaves with it, wherever
the closure lists that tree: at the member's own path, where of the two
entries a child slot holds the one at the version the slot names leaves
(the later one where both state that version) and the member's own
stays, or at the path the world it was contributed from holds the
package at, where each entry of the slot leaves but one at the version
the member's own slot names.
Parameters
assets{ any }— The closure's entries.
Returns ({ any }, { any }) — The entries kept, in the closure's order, and the entries left out.
local kept, restated = worldVcs.__dropMemberRestatements(closure.assets)
typed/builtin//modules/world_vcs/M/__dropRestatedSites
M.__dropRestatedSites(closure: any?, restated: { any }) -> number
Narrow a closure's world entries to the sites its kept entries record,
once restated (__dropMemberRestatements) has left it. A site the
closure lists from an asset a restatement is, at a world and commit no
reference table of a kept entry of that asset records it at, was
recorded by the restatement alone, and leaves. A site from an asset no
kept entry states a reference table for stays. Changes closure in place.
Parameters
closureany(optional) — The decoded closure,{ assets, worlds? }, holding the kept entries.restated{ any }— The entries left out as restatements.
Returns number — How many sites left.
worldVcs.__dropRestatedSites(closure, restated)
typed/builtin//modules/world_vcs/M/__editedInstallFolders
M.__editedInstallFolders(entries: { any }, readRecord: (any) -> any?, folderChecksum: (string) -> string?) -> { EditedInstallFolder }
The folder assets of the installs a tree holds that hold a file the
world changed, added or deleted. A tree holds an install by its record
(<dest>.pull), which lists every file and folder asset of the installed
version, at <dest> for the install's own listing and at each dependency's
placed_at for the dependency's. A folder asset of a listing is edited
when the checksum its files add up to as the tree holds them (a row of
the tree at a listed path replacing the listed file, rows beneath the
folder the listing does not state added, paths the record lists as
removed gone) differs from the checksum its listed files add up to; the
one folderChecksum states both, so a folder the world did not change is
never edited. Each edited folder names the children of it the push
carries: the listed files and folders beneath it that the tree holds no row
of and the record does not list as removed, a folder that is itself edited
excluded (it is an edited folder of its own). A folder the tree holds a
row of is the world's own and is not named. Folders are ordered by path.
Parameters
entries{ any }— The tree's entries:pathandchecksum_sha256each, as a__spacetime_vcs.treeread states them.readRecord(any) -> any?— Reads the install record held by a tree entry, as the decoded table, or nil.folderChecksum(string) -> string?— The checksum of a folder from its leaves, a JSON object of each leaf's path inside the folder to the hex sha256 of its bytes.
Returns { EditedInstallFolder } — The edited folders, ordered by path.
worldVcs.__editedInstallFolders(entries, function(row) return nil end, function(json) return nil end)
typed/builtin//modules/world_vcs/M/__editedInstallVersions
M.__editedInstallVersions(entries: { any }, readRecord: (any) -> any?, folderChecksum: (string) -> string?, childVersions: ({ InstallContainerVersion }) -> { [string]: { [string]: string } }, previous: { any }?) -> EditedInstallVersions
What a push carries for the installed folders a world edited
(__editedInstallFolders), so ZeroMind holds each edited folder as a
version of its own beneath the world that edited it. Each edited folder
is a composite row stating the checksum its files add up to and the
reference table the record lists for it. Each child of it the push
carries is a row stating the child by its version: the version its origin
world published, which the version of the child's container states
(childVersions, read at the container's listed checksum). ZeroMind
builds a commit's manifest from the manifest of the commit it follows and
the rows the commit states, so a row the carry of previous (the tree of
that commit) states the same, at the same path, is left out, and only the
containers of the children left in are read. The versions of every
container the push needs are asked for in one call, each container once.
The children go first, deepest first, then the folders, deepest first.
pins maps each edited folder's guid to its checksum, whether or not its
row is left out. removed lists the paths the carry of previous stated
and this one does not, so a folder returned to the version its record
lists leaves ZeroMind's manifest. Raises naming the child when its
container's version states none for it.
Parameters
entries{ any }— The tree's entries (__editedInstallFolders).readRecord(any) -> any?— Reads the install record a tree entry holds.folderChecksum(string) -> string?— The checksum of a folder from its leaves.childVersions({ InstallContainerVersion }) -> { [string]: { [string]: string } }— Reads the children of several versions at once (InstallContainerVersion, each{ guid, checksum }once), answering, under each version'sguid .. "@" .. checksum, a table of each child's guid to the id of its version.previous{ any }(optional) — The entries of the tree of the commit ZeroMind's manifest of the push follows, or nil when the push states the whole manifest.
Returns EditedInstallVersions — { entries, removed, pins }, each empty when the tree holds no edited install.
worldVcs.__editedInstallVersions(entries, readRecord, folderChecksum, childVersions, nil)
typed/builtin//modules/world_vcs/M/__emptiedAreaLine
M.__emptiedAreaLine(verb: string, area: OtherArea) -> string?
The line a call that emptied the staging area area writes when the
area belongs to another account, naming the account and the session
holding it, the way a take from such an area does. Nil for an area of the
caller's own account.
Parameters
verbstring— The calling API's name.areaOtherArea— The area, as__otherAreasNamedanswers it.
Returns string? — The line, or nil.
worldVcs.__emptiedAreaLine("world.reset", area)
typed/builtin//modules/world_vcs/M/__enclosingAssetPath
M.__enclosingAssetPath(path: string) -> string?
The path of the asset whose folder holds the asset at path as one of
its members (a module inside a package), or nil when no asset encloses it.
Parameters
pathstring— The engine-canonical path of an asset.
Returns string? — The enclosing asset's path, or nil.
worldVcs.__enclosingAssetPath("/zero/source/Kit.package/api.module")
typed/builtin//modules/world_vcs/M/__enclosingPackagePath
M.__enclosingPackagePath(path: string) -> string?
The path of the innermost package folder (<name>.package) that holds
the asset at path beneath it, in its world's tree, or nil when no package
encloses it. A package folder itself answers the package around it.
Parameters
pathstring— The asset's path relative to its world's root.
Returns string? — The enclosing package's path, or nil.
worldVcs.__enclosingPackagePath("kits/spawnerKit.package/api.module")
typed/builtin//modules/world_vcs/M/__encodeRecord
M.__encodeRecord(record: { [string]: any }, pace: () -> ()) -> string
The JSON text of an install record, encoded entry by entry so a record listing thousands of files costs the frame one small step per entry rather than one long one.
Parameters
record{ [string]: any }— The record document.pace() -> ()— Called between entries.
Returns string — The JSON text.
worldVcs.__encodeRecord({ ["$schema"] = "zero/asset-pull/v2", listing = {}, deps = {} }, function() end)
typed/builtin//modules/world_vcs/M/__engineBuiltin
M.__engineBuiltin(waitSeconds: number?) -> EngineBuiltin?
The @builtin this engine runs: the library's world and the published
commit of it the engine holds (builtinPin.libraryWorld). While the
engine is still looking that commit up the call waits for it, at most
waitSeconds.
Parameters
waitSecondsnumber(optional) — How long to wait for the commit; 0 or nil reads it once.
Returns EngineBuiltin? — { world, commit }, nil when the engine names no published commit.
worldVcs.__engineBuiltin()
typed/builtin//modules/world_vcs/M/__engineReleaseOrder
M.__engineReleaseOrder(guid: string, held: ReleaseOf, asked: ReleaseOf) -> string
Where the release asked of the asset guid stands against the
release held (__releaseOrder), read from the asset's line through
ZeroMind: up to four pages of fifty versions. Raises with ZeroMind's
reason when a page cannot be read.
Parameters
guidstring— The asset.heldReleaseOf— The release a world holds.askedReleaseOf— The release it is compared with.
Returns string — newer, older, same or unknown.
worldVcs.__engineReleaseOrder("da911599-3bdf-4c1e-a4c3-ce13364692bf", { checksum = "a", version_id = "" }, { checksum = "b", version_id = "" })
typed/builtin//modules/world_vcs/M/__expandUpdatePaths
M.__expandUpdatePaths(paths: { string }, updates: { PinUpdate }) -> { string }
The paths a stage or an unstage of paths acts on: each path that is
part of a pin update (its marker or one of its repins) brings the whole
update, its marker when changed, every repin and every row of the
versions it recorded, and every other path is itself. A file of the update holding edits of its own is acted on alone,
as named.
Parameters
paths{ string }— The paths named, engine-canonical.updates{ PinUpdate }— The pin updates the working tree holds.
Returns { string } — The paths, each once, in the order first reached.
worldVcs.__expandUpdatePaths({ "/zero/source/libs/@builtin" }, {})
typed/builtin//modules/world_vcs/M/__fetchSites
M.__fetchSites(worldGuid: string, commit: string, sites: { any }, reads: SiteReads) -> { any }
The sites of one commit of a world resolved through ZeroMind, one
answer per site in order, each install record an answer names replaced by
the asset it installs (__installedInPlace). Each read is made again
while it fails for a reason a later attempt can outlive (__readRetrying).
Raises naming the world and commit when the resolve cannot be read or
answers no sites, or a record an answer names cannot be read.
Parameters
worldGuidstring— The world the sites are resolved in.commitstring— The commit of that world they are resolved at.sites{ any }— The sites, each{ via, literal, names? }.readsSiteReads— How ZeroMind is read (SiteReads).
Returns { any } — One { assets } per site, in order.
worldVcs.__fetchSites("w", "c1", { { via = "require", literal = "kit" } }, reads)
typed/builtin//modules/world_vcs/M/__fetchedCommitHeld
M.__fetchedCommitHeld(ofSession: boolean, behind: number, walk: () -> boolean) -> boolean
Whether the session branch already holds a fetched commit. For the
session branch's own upstream the fetch's behind count answers it: 0
holds it, more does not. For another branch walk reads the session
branch's history.
Parameters
ofSessionboolean— Whether the branch pulled is the session branch.behindnumber— The commits origin holds that the branch does not, as the fetch counted them.walk() -> boolean— Whether the fetched commit is in the session branch's history.
Returns boolean — True when the session branch holds the fetched commit.
worldVcs.__fetchedCommitHeld(true, 0, function() return false end)
typed/builtin//modules/world_vcs/M/__foldPlan
M.__foldPlan(copyFiles: { [string]: string }, intoFiles: { [string]: string }) -> { write: { string }, paired: { string }, kept: { string } }
What folding a copy into the installed asset it came from writes:
each file of the copy, by its path below the copy, whose bytes differ from
the file at the same path below the installed asset (write), the paths
both hold (paired, whose references are repointed), and the files only
the installed asset holds (kept). Each list sorted.
Parameters
copyFiles{ [string]: string }— The copy's files: path below the copy -> bytes.intoFiles{ [string]: string }— The installed asset's files: path below it -> bytes.
Returns { write: { string }, paired: { string }, kept: { string } } — { write, paired, kept }.
worldVcs.__foldPlan({ ["init.luau"] = "a" }, { ["init.luau"] = "b" })
typed/builtin//modules/world_vcs/M/__foldUpdatesIntoDiff
M.__foldUpdatesIntoDiff(files: { any }, updates: { PinUpdate }) -> { any }
A diff's files with each library update folded into one entry: a
file whose table alone moved with an update, and a file of the versions
its move recorded, leaves the list, and the update's marker entry carries
update = { library, from, to, repins, edited, versions } (counts), added
as an entry of its own (action = "update") when the marker itself is not
in the list.
Parameters
files{ any }— The diff's file entries.updates{ PinUpdate }— The pin updates the live side holds.
Returns { any } — The folded entries.
worldVcs.__foldUpdatesIntoDiff({}, {})
typed/builtin//modules/world_vcs/M/__folderAssetAt
M.__folderAssetAt(path: string) -> any
The folder asset this world holds at a path, as a contribution states
one it adds: its guid, its kind (the name of the type it is an instance
of, lowercase, the kind a push states for a folder asset) and its
reference table: the link to that type (asset_type).
Parameters
pathstring— The folder's VFS path.
Returns any — { asset_guid, kind, refs_json? }, or nil where the path holds no folder asset.
worldVcs.__folderAssetAt("/zero/source/kit.package/helper.module")
typed/builtin//modules/world_vcs/M/__footprintDestination
M.__footprintDestination(summaries: any?, rootGuid: string, at: string?) -> string
The destination of the install whose root an install of rootGuid
asked to land at at writes again (__footprintOf): the install standing
at at (__priorInstallOf), and none when the world holds none there.
Every other copy of the root is content the world holds: an install asked
for a destination moves it there, and an install asked for none lands
where the world holds the root.
Parameters
summariesany(optional) — Whatinstall.summariesanswers.rootGuidstring— The asset the install was asked for.atstring(optional) — The destination the install was asked for, or nil.
Returns string — The install's destination, "" when no install stands at at or none was asked for.
worldVcs.__footprintDestination({}, "g", "/source")
typed/builtin//modules/world_vcs/M/__footprintOf
M.__footprintOf(summaries: any?, rootGuid: string, only: string?) -> { string }
The paths the files of an earlier install of rootGuid stand at: its
destination and the root of each dependency it placed.
Parameters
summariesany(optional) — Whatinstall.summariesanswers.rootGuidstring— The root asset's guid.onlystring(optional) — The destination of the one install whose root copy is the install's own, or nil for every install of the root. An install asked to land at a destination writes again the root of the install standing there alone: the root copy another install stands at is content the world holds, and moves. The dependencies every install of the root placed are written again by the install.
Returns { string } — The paths, empty when the world holds no install of the root.
worldVcs.__footprintOf({}, "g", nil)
typed/builtin//modules/world_vcs/M/__groupInstalls
M.__groupInstalls(input: InstallGroupingInput) -> { InstallEntry }
The installs among the pulled rows whose rows differ from the branch
head. An install is its root, the row whose reference table marks it
install_root; its rows are the root, every row nested beneath a row of
the install, and the rows under /zero/source/deps/ that the tables of
its rows name as dependencies, followed to the end of the chain. A
dependency row holding no table of its own brings the rows beside it, under
the same /zero/source/deps/<world>/versions/<checksum>/ folder. A
dependency two installs share belongs to both, and a root another install
reaches as a dependency belongs to that install and keeps its own entry. An
install none of whose rows has a change is not listed, unless every asks
for each install the rows hold. Each entry names the version its root was
installed at, the files whose content is not that version and how many of
its rows are deletions. The rows are indexed
once by sorted path, so the rows nested beneath a path are found by a
binary search.
Parameters
inputInstallGroupingInput— AnInstallGroupingInput.
Returns { InstallEntry } — One InstallEntry per changed install (per install with every), ordered by root path.
worldVcs.__groupInstalls({ rows = {}, dirty = {}, staged = {}, headChecksum = function() return nil end })
typed/builtin//modules/world_vcs/M/__handOverRecords
M.__handOverRecords(from: string, to: string, at: string, ops: HandOverOps) -> (boolean, string)
Hand the root of the install at from to the install at to, whose
files run it: write to's record taking from over (its root placed at
at), wait until the engine has materialized it, take from's record
out, and wait until the engine holds from's install no more. The copy
stands at its new path before the root it replaces leaves, so every file
that runs it finds one of the two. A step that fails before from's
record left writes to's record back as it stood, so the world holds
both installs as before.
Parameters
fromstring— The install handed over.tostring— The install that takes it over.atstring— Whereto's record places the copy.opsHandOverOps—HandOverOps.
Returns (boolean, string) — Whether it was handed over, and why not when it was not.
worldVcs.__handOverRecords("/zero/source/kit.package", "/zero/source/user.package", "/zero/source/deps/w/kit.package", ops)
typed/builtin//modules/world_vcs/M/__handedOverPlacement
M.__handedOverPlacement(summary: any?, exists: (path: string) -> boolean) -> string
Where an install whose files run the root of another install places
that root once it is handed over (world.uninstall of the root): its
install path under the dependency tree beside the world it was published
from, /zero/source/deps/<world>/<path>, as a fresh install of the
remaining install places it, or the version's own folder when the world
holds something at the install path.
Parameters
summaryany(optional) — The handed-over install, asinstall.summariesstates it.exists(path: string) -> boolean— Whether the world holds something at a path.
Returns string — The path.
worldVcs.__handedOverPlacement({ path = "/zero/source/kit.package", origin_world_guid = "w", origin_path = "/zero/source/kit.package", checksum = "c" }, function() return false end) --> "/zero/source/deps/w/kit.package"
typed/builtin//modules/world_vcs/M/__hasConflictMarkers
M.__hasConflictMarkers(text: string) -> boolean
True if text contains a git-style conflict-marker line
(<<<<<<<, =======, or >>>>>>>) anchored at the start of a
line. The gate's resolution validator: a conflicted row can only
clear once its file has no marker lines left. Anchoring at line
start (not a bare substring search) avoids false-flagging prose
that merely mentions the marker text mid-line.
Parameters
textstring— The file content to scan.
Returns boolean — true when a marker line is present.
worldVcs.__hasConflictMarkers("<<<<<<< ours\nx\n") --> true
typed/builtin//modules/world_vcs/M/__headPin
M.__headPin(library: string) -> string?
The commit the branch head's pin marker of a library pins it at.
Parameters
librarystring— The library, with its@.
Returns string? — The commit, nil when the head holds no marker for the library.
worldVcs.__headPin("@builtin")
typed/builtin//modules/world_vcs/M/__heldMoves
M.__heldMoves(row: DifferingTable, libraries: { string }, holds: (string) -> boolean, ops: ReferenceOps) -> { HeldMove }
What moved the references of row among a set of changes, each change
with the asset and world pins it moved; the rule __referenceMoveCauses
states.
Parameters
rowDifferingTable— The file, with its live and head tables.libraries{ string }— The libraries whose pin marker is among the changes, with their@.holds(string) -> boolean— Whether an asset path is among the changes.opsReferenceOps— What the check reads beyond the working tree.
Returns { HeldMove } — One entry per change, in the order the tables name them.
worldVcs.__heldMoves(row, { "@builtin" }, holds, ops)
typed/builtin//modules/world_vcs/M/__heldOnlyBeside
M.__heldOnlyBeside(held: string, named: string?) -> boolean
Whether a version the world holds at held stands only beside
another release, where a name does not reach it: held lies in a
recorded version's folder (M.__inRecordedVersionFolder), and the copy of
the asset its name reaches (named) is nil or lies in such a folder too.
An install landing that version places it where the name reaches, so a
lookup by name finds the release the installed content runs.
Parameters
heldstring— Where the world holds the version.namedstring(optional) — Where a name reaches the asset in this world, nil when no copy stands there.
Returns boolean — True when the version stands only beside another release.
worldVcs.__heldOnlyBeside("/zero/source/deps/w/versions/c/Kit.package", nil)
typed/builtin//modules/world_vcs/M/__heldOutMarkers
M.__heldOutMarkers(scope: { string }, status: LiveStageStatus) -> { string }
The libraries whose marker (/zero/source/libs/@<name>) is changed in
the working tree, dirty or untracked, and is not part of the commit.
Parameters
scope{ string }— The rows the commit freezes, engine-canonical.statusLiveStageStatus— The working tree and the calling area, read once.
Returns { string } — The library names, with their @, sorted.
worldVcs.__heldOutMarkers(scope, status)
typed/builtin//modules/world_vcs/M/__heldReleasesToKeep
M.__heldReleasesToKeep(assets: { any }, held: { any }, moving: MovingPaths?) -> { DependencyRelease }
The dependency releases the record of an install holds that a version
of its root written again keeps: each dependency of held at a release
newer (by version_id) than every release of the same asset the
install's plan names. A dependency the plan names at the release the
record holds, one the plan names no release of, and the one at moving
(the dependency the record is written again to move) are left out. Each
release is named once. Lifted into the plan (__liftDependency), each
lands in place of the older release the version names
(__oneReleasePerAsset), so writing the record again moves no
dependency back to an older release.
Parameters
assets{ any }— The plan's entries: the version's closure, with the entries it brings from the worlds its files reach into once those are planned.held{ any }— The dependencies the record places, asinstall.summariesstates them (path,asset_guid,checksum,version_id).movingMovingPaths(optional) — The path of the dependency the record is written again to move, a list of such paths, or nil.
Returns { DependencyRelease } — One DependencyRelease per release to keep, in the order of held.
worldVcs.__heldReleasesToKeep({}, {}, nil)
typed/builtin//modules/world_vcs/M/__heldTopOf
M.__heldTopOf(row: any?) -> string?
The outermost folder of a row's content that this world holds from
its origin: the install root (install) when the row lies at or under
it, else the root of the asset the row belongs to (root, a dependency
the install placed elsewhere) when the row lies at or under that.
Parameters
rowany(optional) — An ahead row.
Returns string? — The folder's path, or nil for a row that names neither or lies under neither.
worldVcs.__heldTopOf({ path = "/zero/source/kit.package/a.luau", install = "/zero/source/kit.package" })
typed/builtin//modules/world_vcs/M/__holdsMarkedRoot
M.__holdsMarkedRoot() -> boolean
Whether the world holds a pulled row marked as the root of an install: one read of the marked rows, which answers without any grouping work.
Returns boolean — True when a root is marked.
worldVcs.__holdsMarkedRoot()
typed/builtin//modules/world_vcs/M/__holdsVersionBeneath
M.__holdsVersionBeneath(path: string, headTree: { [string]: any }, staged: { string }) -> boolean
Whether a version of path, or of anything beneath it, is held by the
head commit's tree or by the staging area. A discard whose every reached
change is a file no commit holds takes the path out of the tree only where
this answers false: there the path was absent before its edits. Where it
answers true the path holds committed or staged content (a scene whose only
change is its autosave overlay, a folder holding one new file), and the
path stays.
Parameters
pathstring— The engine-canonical path the discard names.headTree{ [string]: any }— The head commit's tree, path to entry (History.commitTreeMap).staged{ string }— The paths the staging area holds.
Returns boolean — True when the head or the stage holds something at or beneath path.
worldVcs.__holdsVersionBeneath("/zero/source/scenes/main.scene", { ["/zero/source/scenes/main.scene/scene.json"] = {} }, {}) --> true
typed/builtin//modules/world_vcs/M/__holdsWorldVersion
M.__holdsWorldVersion(guid: string, checksum: string, worldGuid: string, path: string?) -> boolean
Whether this world holds what a site naming guid at the version
checksum runs, so an install brings nothing for it: its own copy at
those bytes outside the earlier install of the root being installed, a
copy under /zero/source/deps/<world>/versions/<checksum>/ while a name
reaches a copy of the asset outside that install, or the engine's own
copy of a library asset. A version held only beside another release
(__heldOnlyBeside) answers false, and the install brings it.
Parameters
guidstring— The asset.checksumstring— The version.worldGuidstring— The world the site names it in.pathstring(optional) — The asset's path in that world, or nil.
Returns boolean — True when the world holds what the site runs.
worldVcs.__holdsWorldVersion(guid, checksum, worldGuid, nil)
typed/builtin//modules/world_vcs/M/__ignoredCallerChanges
M.__ignoredCallerChanges(status: { [string]: any }, set: Ignore.IgnoreSet) -> { string }
The paths of a branch's status read (__spacetime_vcs.status) that
the .zmignore / .gitignore rules of set ignore among the reading
caller's local changes: the rows it dirtied that its staging area does
not hold, as Ignore.ruleFor decides it for an ignore file. A branch switch hands them to
the carry, where one untracked on both branches never refuses the switch.
Parameters
status{ [string]: any }— The branch's status read, decoded.setIgnore.IgnoreSet— The ignore set the caller's rules state.
Returns { string } — The ignored paths, sorted.
worldVcs.__ignoredCallerChanges({ local_identity = "me", dirty = {}, staged = {} }, worldVcs.__ignoreSetFrom({}))
typed/builtin//modules/world_vcs/M/__inRecordedVersionFolder
M.__inRecordedVersionFolder(path: string) -> boolean
Whether path lies in the folder of one recorded version of another
world's asset, /zero/source/deps/<world>/versions/<checksum>/. Such a
folder holds that version and no other.
Parameters
pathstring— A VFS path.
Returns boolean — True when the path lies in a recorded version's folder.
worldVcs.__inRecordedVersionFolder("/zero/source/deps/w/versions/c/a.module")
typed/builtin//modules/world_vcs/M/__installChangeRows
M.__installChangeRows(changes: any?) -> { any }
The changes the world made to the content of its record installs, each
in the shape a pulled row ahead of its origin has: an install stands as one
record row, and a file of it the world changed, or added inside it, is a row
of the world's own whose content is not the version the record states. Each
carries the install (install), the asset it belongs to (root: the
install's destination or a dependency the install placed), where that asset
was published (origin_world_guid, origin_path, origin_commit_id) and
the version the record states (origin_checksum, nil for an added path,
which reads added = true).
Parameters
changesany(optional) — Whatinstall.changesanswers.
Returns { any } — One row per change, sorted by path.
worldVcs.__installChangeRows({})
typed/builtin//modules/world_vcs/M/__installChildVersions
M.__installChildVersions(containers: { InstallContainerVersion }, readBatched: ({ VersionAsk }) -> ({ [number]: any }, { [number]: string }), readOne: (string, string) -> any) -> { [string]: { [string]: string } }
The children of several versions of folder assets, each as a table of
the child's guid to the id of its version, under the version's
guid .. "@" .. checksum. A version an earlier call of the session read
is answered from it; the others are read from ZeroMind together
(readBatched, one edge out from each), and a version whose read was cut
at the server's asset cap (M.__closureAtAssetCap) is read on its own
(readOne), which reads past the cap in pages. Raises naming the version
when one cannot be read.
Parameters
containers{ InstallContainerVersion }— The versions (InstallContainerVersion).readBatched({ VersionAsk }) -> ({ [number]: any }, { [number]: string })— Reads versions together, answering each decoded closure and the reason each that cannot be read was refused, both by the version's index (WorldPlan.readBatched).readOne(string, string) -> any— Reads one version one edge out, answering the decoded closure or raising.
Returns { [string]: { [string]: string } } — The children of each version, under its key.
worldVcs.__installChildVersions({ { guid = g, checksum = c } }, readBatched, readOne)
typed/builtin//modules/world_vcs/M/__installClosure
M.__installClosure(reads: InstallClosureReads, rootGuid: string, ref: string) -> (boolean, string, any?, string?)
The install closure of rootGuid at ref, read the way every install,
preview and pull reads one, and the commit of the asset's world a ref
resolved to. An empty ref reads the version the asset's world ships,
and names no commit (__shippedCommit answers the one an install
records). Any other ref is a branch, a tag or a commit id of the world
the asset is published from: it is resolved there to the commit it names,
the closure is read at that commit, and the root the closure answers is held
to the version that commit holds. So a branch pushed and never published
installs as the branch holds it, an asset only that branch holds included.
A ref that world does not resolve, a commit holding no version of the
asset, and a closure answering a version other than the commit's each
answer not ok, naming the ref and why.
Parameters
readsInstallClosureReads— The ZeroMind reads (closure,world,resolve).rootGuidstring— The asset whose closure is read.refstring— The ref it is read at; empty reads the version the asset's world ships.
Returns (boolean, string, any?, string?) — Ok, the closure's JSON, its decoded table when it was decoded here, and the commit ref resolved to (nil for an empty ref); or not ok and the failure text.
worldVcs.__installClosure(reads, "5f6bfcfb-2258-47d9-8f1e-8f684f85e1f3", "release-1.1.0")
typed/builtin//modules/world_vcs/M/__installConflicts
M.__installConflicts(rows: { any }, rootPath: string?, writes: { [string]: string }) -> { string }
The conflicted rows one install's pull writes: a conflicted row at or beneath the install's root, or the row a closure entry of the pull lands in (its asset's guid at the path the pull writes it to). Another install's held version of a shared dependency sits at a path of its own and is another install's row. A row flagged conflicted that holds the bytes it installed carries no local content; the pull clears its flag and lands it, and it does not block.
Parameters
rows{ any }— The world's pulled rows.rootPathstring(optional) — The install root's path, or nil when the install holds no root row.writes{ [string]: string }— The path the pull writes each closure asset to, by asset guid.
Returns { string } — The conflicted paths, sorted.
worldVcs.__installConflicts({}, "/zero/source/Fire.module", {})
typed/builtin//modules/world_vcs/M/__installDestinationRefusal
M.__installDestinationRefusal(at: string?, verb: string) -> string?
Why an install aimed at at cannot land there, or nil when it can:
the refusal of a destination in the library mounts
(__libraryMountRefusal) or of one the world does not save or sync
(__saveExcludedInstallRefusal). Every install surface checks its
destination through this before anything is read or written.
Parameters
atstring(optional) — The destination folder the install was asked for.verbstring— The call the refusal is raised for, e.g.world.installAsset.
Returns string? — The refusal text, or nil.
worldVcs.__installDestinationRefusal("/source/tmp/probe", "world.installAsset")
typed/builtin//modules/world_vcs/M/__installDiscardPlan
M.__installDiscardPlan(install: InstallEntry, installs: { InstallEntry }) -> { discard: { string }, kept: { string } }
The rows discarding an install puts back: every changed row of the install except one another install records too, deepest path first so a file goes before the folder that holds it.
Parameters
installInstallEntry— The install being discarded.installs{ InstallEntry }— Every install the working tree lists.
Returns { discard: { string }, kept: { string } } — { discard, kept }: the paths to put back, and the shared paths left in place.
worldVcs.__installDiscardPlan({ root_path = "/zero/source/A", changed = {}, rows = {} }, {})
typed/builtin//modules/world_vcs/M/__installEditsFor
M.__installEditsFor(release: string, previousRelease: string?) -> string?
The JSON text world.push hands the push for the installed folders
the world edited (__editedInstallVersions), read from the tree the push
releases and the tree of the commit ZeroMind's manifest of the push
follows. The install records the
trees hold are read from the blobs they name, each blob once, and the
version of each child of an edited folder from ZeroMind, one edge out
from the folder's listed version, every folder version together and each
once a session (__installChildVersions). Sets only the keys that hold something,
so the text of a tree holding no edited install is nil.
Parameters
releasestring— The JSON a__spacetime_vcs.treeread of the branch head's commit resolves with.previousReleasestring(optional) — The same of the commit ZeroMind's manifest of the push follows, or nil.
Returns string? — The JSON text, or nil when the push carries nothing for an edited install.
worldVcs.__installEditsFor(release, nil)
typed/builtin//modules/world_vcs/M/__installEditsOfBranch
M.__installEditsOfBranch(commitId: string?) -> string?
The JSON text world.push hands the push for the installed folders
the world edited (__installEditsFor), read from the commit the push
releases and the commit ZeroMind's manifest of the push follows. The
squash push releases the branch head and compares with the nearest commit
ZeroMind holds on its first parents (__pushBasisCommit); the push of one
commit releases that commit and compares with its parent.
Parameters
commitIdstring(optional) — The single commit the push releases, or nil for the branch head.
Returns string? — The JSON text, or nil when the push carries nothing for an edited install.
worldVcs.__installEditsOfBranch(nil)
typed/builtin//modules/world_vcs/M/__installLoadProblems
M.__installLoadProblems(record: { [string]: any }, dest: string, host: { [string]: any }) -> ({ string }, { string }, { string })
The install load check's findings for the assets an install record
places: one line per problem, each naming the asset's path and type. An
installed asset is held to loading as its type, which is what its type's
errors outside the file structure, its type's own validate hook and the
file it loads from (its type's entry_files and primary) say. Any other
file its type requires is a requirement of publishing that type, so an
installed root that lacks one is named in the second list, the files it
lacks, and installs: content published before its type required the file
runs where it lands. A dependency stands as it stands in the world it came
from: the push gate holds content under /zero/source/deps/ and content
an install carries to nothing, since it is its publisher's. So what its
type's own validate hook finds in it is named in the third list, the
published findings, and refuses nothing. A hook problem marked
publishRequirement is a rule a push enforces on what it publishes, so
the same list names it in the installed root's own content: what is
already published installs and its publisher repairs it in a new release.
A dependency whose type has no such hook is not validated, and each type
is asked once.
Parameters
record{ [string]: any }— The install record:{ listing, deps = { { listing, placed_at } } }.deststring— Where the record places its root.host{ [string]: any }—{ validate, typeHasValidateHook, loadsFrom, loaded, pace }:validate(guid)isasset.validate,typeHasValidateHook(kind)whether a type's behavior exportsvalidate,loadsFrom(typeName)the files an asset of that type loads from (itstype.yamlentry_filesandprimary),loadedthe guids that validated on an earlier look (read and extended),pace()gives the frame back between assets.
Returns ({ string }, { string }, { string }) — The problem lines that keep the installed root from loading, in listing order; then the installed root's lines for the files its type requires that it lacks; then the lines its type's validate hook states for a dependency or as a publish requirement of the root's own content.
worldVcs.__installLoadProblems({ listing = {}, deps = {} }, "/zero/source/a", { validate = asset.validate, typeHasValidateHook = function() return false end, loaded = {}, pace = function() end })
typed/builtin//modules/world_vcs/M/__installPathReadable
M.__installPathReadable(path: string, isLeaf: boolean, binaryLeaves: { [string]: string }, version: string?) -> boolean
Whether a path an install wrote reads back: it exists, and a leaf's
bytes read (a binary leaf, which reads only by content address, once its
served bytes arrive; its content address is noted in binaryLeaves, and a
later look at that version answers at once). With version, the path
reads back once a reader gets that version: a leaf's bytes hash to it (the
content address the blob store holds them under, or the sha-256 of the
bytes a read returns), and a folder's sidecar states it as its checksum.
Parameters
pathstring— The path written.isLeafboolean— Whether the path is a file rather than a folder.binaryLeaves{ [string]: string }— The content address of each binary leaf read so far, by path.versionstring(optional) — The version the path reads back at, or nil for any.
Returns boolean — Whether the path reads back.
worldVcs.__installPathReadable("/zero/source/none.luau", true, {}, nil)
typed/builtin//modules/world_vcs/M/__installRecordDocument
M.__installRecordDocument(assets: { any }, rootGuid: string, placement: { [string]: string }, worlds: { any }, installRef: string?, origin: InstallOrigin?) -> ({ [string]: any }, number)
The record of an install: the one document the world holds for it and
every engine materializes the install from. It names the asset and the
version installed, and lists every file and folder of that version with its
guid, checksum, size, kind and published reference table, the listing of
each dependency the install placed beside it, and the versions the commits
its reference sites name hold (worlds). An entry's path in the listing is
relative to where its asset stands.
Parameters
assets{ any }— The closure's entries, the world pulls ofWorldPlanincluded.rootGuidstring— The root asset's guid.placement{ [string]: string }— Where each placed entry stands, keyed the waycomputeClosurePlacementkeys them (__closurePlacementKeys).worlds{ any }— The commit records the install's reference sites resolve against.installRefstring(optional) — The ref the install was asked for, or nil.originInstallOrigin(optional) — What the install read of the root's world (InstallOrigin), or nil when it read nothing of it.
Returns ({ [string]: any }, number) — The record document and the number of rows it states.
worldVcs.__installRecordDocument(assets, guid, placement, {}, nil, { commit = "c1", visibility = "public" })
typed/builtin//modules/world_vcs/M/__installRedirect
M.__installRedirect(installs: { InstallEntry }, path: string) -> (InstallEntry?, string?)
What acting on path means when the working tree holds installs: the
install whose root path names, which the call then acts on as a whole,
or the sentence refusing an act on a single row of an install.
Parameters
installs{ InstallEntry }— TheInstallEntrylist of the status read.pathstring— The engine-canonical path the call names.
Returns (InstallEntry?, string?) — (install, nil) for a root, (nil, refusal) for another row of an install, (nil, nil) for a path that belongs to no install.
worldVcs.__installRedirect({}, "/zero/source/Foo.module")
typed/builtin//modules/world_vcs/M/__installRefOf
M.__installRefOf(row: any?) -> string?
The ref a pulled row's table records its install as asked for.
Parameters
rowany(optional) — A pulled manifest row with itsrefs_jsontable.
Returns string? — The ref, nil when the table records none.
worldVcs.__installRefOf({ refs_json = '{"install_ref":"release"}' })
typed/builtin//modules/world_vcs/M/__installRestoreRows
M.__installRestoreRows(dirty: { any }, changes: { any }?, facts: InstalledFileFacts?) -> { installed: { [string]: boolean }, destinations: { [string]: boolean } }
Which rows a path restore takes back to the installs the world holds
as one record each, read from one status read and install.changes:
installed, each row of the world's own that stands over a file an
install states (M.__rowsOverInstalledFiles: a change with a version to
go back to, the install's, though no commit holds the row), and
destinations, the destination of each install whose record is a changed
row, the path zm status lists that change under.
Parameters
dirty{ any }— The dirty rows of the status read.changes{ any }(optional) — Whatinstall.changesanswers, or nil when it cannot answer.factsInstalledFileFacts(optional) — The record destinations, the staged rows and the folder test (InstalledFileFacts).
Returns { installed: { [string]: boolean }, destinations: { [string]: boolean } } — { installed, destinations }, each a set of engine-canonical paths.
worldVcs.__installRestoreRows(world.vcsStatus().dirty, trusted.call("install.changes"))
typed/builtin//modules/world_vcs/M/__installRootAt
M.__installRootAt(path: string) -> boolean
Whether path is the destination of an install the world holds a
record for: the root of that install, whose files the record states.
Parameters
pathstring— The path.
Returns boolean — True when an install record stands for path.
worldVcs.__installRootAt("/zero/source/kit.package")
typed/builtin//modules/world_vcs/M/__installRootBackfill
M.__installRootBackfill(ops: BackfillOps) -> { marked: { string }, rejected: { string }, skipped: { string } }
Decide, for the pulled rows no table decides yet, which are the roots of an
install, on the evidence an install leaves. A world copied from another
holds every one of that world's assets as a pulled row, so an origin world
whose bootstrap files (.world_settings, .world_entrypoint.luau) this
world holds as pulled rows is a fork source and none of its rows is looked
at. An install places its dependencies under /zero/source/deps/, so a
world holding no pulled row there is looked up for nothing, and a candidate
(a pulled row outside the dependency tree and the libraries, beneath no
other candidate and no marked root, and not a deletion) is looked up only then. One closure per candidate, at the commit its
row records, read a few at a time. A candidate is a root when its closure
answers it as the root entry, no other candidate's closure holds it as a
dependency, and the closure holds a dependency the world holds as a pulled
row at the path an install places it (__dependencyPlacementPaths); a root
whose dependencies the world satisfied from its own content leaves no such
row and cannot be told from forked content. A candidate whose closure was
read and is not proven is recorded as decided not a root, so it is never
looked up again; one whose closure could not be read records nothing, is
logged once, and is tried again at a later open.
Parameters
opsBackfillOps— ABackfillOps.
Returns { marked: { string }, rejected: { string }, skipped: { string } } — { marked, rejected, skipped }: the paths marked as roots, the paths recorded as no root, and the paths whose closure could not be read.
worldVcs.__installRootBackfill({ pulledRows = function() return {} end, closuresOf = function() return {} end, decide = function() return true end, log = print })
typed/builtin//modules/world_vcs/M/__installRootRow
M.__installRootRow(rows: { any }, guid: string, path: string?) -> any
The pulled row that is the root of an install, among the rows the world
holds for the root's asset. A world can hold one asset at several paths: its
install, and recorded versions of it another install brought under
/zero/source/deps/<world>/versions/<checksum>/. The row at path is the
root when the world holds one there; otherwise the row marked as an
install's root, and then any row outside a recorded version's folder.
Parameters
rows{ any }— The world's pulled rows.guidstring— The root asset's guid.pathstring(optional) — The install root's path, or nil.
Returns any — The root's row, or nil when the world holds no install of the asset.
worldVcs.__installRootRow({}, "g", "/zero/source/Fire.module")
typed/builtin//modules/world_vcs/M/__installRowsByGuid
M.__installRowsByGuid(rows: { any }, rootPath: string?, placement: { [string]: string }, satisfied: { [string]: string }) -> { [string]: any }
The pulled row a pull of one install acts on for each asset of its
closure, by asset guid. A world can hold one asset at several paths: the
install's own copy, the copies other installs hold, and recorded versions
placed under /zero/source/deps/<world>/versions/<checksum>/, each holding
exactly its version. An asset the pull places is acted on at the path it
places it at, else at a row at or beneath the install's root. An asset the
world already holds at the recorded version is acted on where it holds it:
the row at that path, or for a file of a held folder, the row beneath that
folder.
Parameters
rows{ any }— The world's pulled rows.rootPathstring(optional) — The install root's path, or nil.placement{ [string]: string }— The path the pull places each asset at, by guid.satisfied{ [string]: string }— The path the world already holds each asset at, by guid: for a file of a held folder, that folder's path.
Returns { [string]: any } — The row for each guid that has one.
worldVcs.__installRowsByGuid({}, "/zero/source/Fire.module", {}, {})
typed/builtin//modules/world_vcs/M/__installUnstageTargets
M.__installUnstageTargets(path: string, ownStaged: { [string]: boolean }, claims: { any }) -> { string }?
The paths unstaging path takes out of the staging areas when path
names the destination of an install whose record (<path>.pull) a
staging area holds: the record, which world.add stages for that path,
and path itself while an area holds it or a path beneath it.
Parameters
pathstring— The engine-canonical path the call names.ownStaged{ [string]: boolean }— The paths the calling area holds, as a set.claims{ any }— The rows other staging areas hold, as a status read reports them.
Returns { string }? — The paths to unstage, or nil when no area holds the record of an install at path.
worldVcs.__installUnstageTargets("/zero/source/kit.package", { ["/zero/source/kit.package.pull"] = true }, {})
typed/builtin//modules/world_vcs/M/__installVerdict
M.__installVerdict(ok: boolean, payload: string, isEngineAsset: ((string) -> boolean)?) -> AssetInstallableReport
Read an installability verdict out of one closure fetch. Pure —
it decides from the fetch outcome and the response body alone, so
the classification is exercisable without a live backend.
world.assetInstallable is this function over a real fetch.
Parameters
okboolean— Whether the closure fetch returned successfully.payloadstring— The response body whenok, the error message otherwise.isEngineAsset((string) -> boolean)(optional) — Whether the engine running the install ships an asset under a guid in its own library; that asset's references are not the installed content's to answer for.
Returns AssetInstallableReport — An AssetInstallableReport with guid left empty for the caller to fill: installable (would installing this guid alone land content), verdict, a one-line detail, and the closure's shape as nodes / tree_children / deps.
worldVcs.__installVerdict(false, "HTTP 404: not found").verdict --> "unpublished"
typed/builtin//modules/world_vcs/M/__installedAssetsOf
M.__installedAssetsOf(rows: { any }, summaries: any?) -> { InstalledAsset }
What the world carries from ZeroMind, as world.installedAssets()
answers it, sorted by path: one entry per pulled row that names the
published guid it was pulled from (an install an earlier engine landed as
one row per file), then one per install record that still installs its
root (__installedSummaries) and one per dependency each record places.
A row that stands for a deletion (its content left the world, and the
next commit removes the path) is carried no longer, so it is none of
them; nor is a record's root or dependency the record names deleted. A
path both forms state is listed once, as its pulled row.
Parameters
rows{ any }— The pulled manifest rows.summariesany(optional) — Whatinstall.summariesanswers; nil lists the pulled rows alone.
Returns { InstalledAsset } — The InstalledAsset entries.
worldVcs.__installedAssetsOf({}, trusted.call("install.summaries"))
typed/builtin//modules/world_vcs/M/__installedContentDiscard
M.__installedContentDiscard(target: string, dirty: { any }, changes: { any }?, facts: InstalledFileFacts?) -> InstalledContentDiscard?
What a discard of target puts back in the content of the installs
the world holds as one record each (<dest>.pull). Taking a row of the
world's own that stands over a file of such an install out of the world
(M.__rowsOverInstalledFiles) puts the install's file back at the path.
The plan names the install record when target is an install's
destination and its record is a changed row a commit or the caller's
staging area holds a version of (record); every such row at or beneath
target (takeOut); and whether a changed row a commit holds is at or
beneath target too (rest). A file the world added inside an install is
a file no commit holds, which a discard of the folder above it leaves
where it is, a row the caller's staging area holds keeps its staged
version, and an install whose record no commit holds stays as its record
states it.
Parameters
targetstring— The engine-canonical path the discard names.dirty{ any }— The dirty rows of a status read taken with the install rows left in.changes{ any }(optional) — Whatinstall.changesanswers: each row of the world inside installed content that diverges from its install, with itsstate; nil when the engine cannot answer.factsInstalledFileFacts(optional) — The record destinations, the staged rows and the folder test (InstalledFileFacts).
Returns InstalledContentDiscard? — The plan, or nil when target reaches no install record and no such row.
worldVcs.__installedContentDiscard("/zero/source/kit.package/notes.md", world.vcsStatus().dirty, trusted.call("install.changes"))
typed/builtin//modules/world_vcs/M/__installedEntriesOf
M.__installedEntriesOf(rows: { any }, rootPath: string, toAssets: { any }, within: { [string]: string }?) -> { any }
The entries an install holds as the world installed them, read from its
pulled rows: every row at or beneath the root, and the row of every asset
the new closure names, one row per asset (a row at or beneath the root
first, a recorded version's row under /zero/source/deps/<world>/versions/
last). A row at or beneath a path of within (where the install holds a
dependency an update moves) is one of the install's too, stated at that
dependency's origin path when the row names none, so a file the
dependency's new release drops is named. Each entry states the asset, its
origin path, the path the world holds it at (world_path), the version
the world installed (origin_checksum) and whether it is a folder asset
(a row holding no blob of its own).
Parameters
rows{ any }— The world's pulled rows.rootPathstring— The install root's path.toAssets{ any }— The closure entries at the version the install updates to.within{ [string]: string }(optional) — The origin path of each dependency the update moves, by the path the install holds it at, or nil for none.
Returns { any } — Closure-shaped entries { asset_guid, path, world_path, checksum, is_composite }.
worldVcs.__installedEntriesOf({}, "/zero/source/Fire.module", {}, nil)
typed/builtin//modules/world_vcs/M/__installedFindingsNotice
M.__installedFindingsNotice(findings: { [string]: { string } }) -> (string?, { [string]: string }?)
The notice for problems inside installed content the world never changed: one line per install naming it and its first findings, and the count of the rest. Nil when there is none.
Parameters
findings{ [string]: { string } }— Findings by install destination, as__noteInstalledFindingrecords them.
Returns (string?, { [string]: string }?) — The notice text and its fields, or nil.
worldVcs.__installedFindingsNotice({ ["/zero/source/kit.package"] = { "/zero/source/kit.package/a.luau:3: unknown global 'x'" } })
typed/builtin//modules/world_vcs/M/__installedInPlace
M.__installedInPlace(answers: { any }, readRecord: (string) -> (boolean, string)) -> { any }
The answers of sites resolved in a world, each install record an answer
names (<dest>.pull) replaced by the asset that record installs. A world
holds what it installed as its record alone, so a name that reaches
installed content (a package its package.yaml depends on, a ~<kit>.
require) resolves there to the record; the record is that world's file,
and what the name runs is the asset it installs, at the version it
installed (asset_guid and checksum of the record, and the kind the
record's listing states for it), standing at the record's destination. An
answer naming no record is kept as it is.
Parameters
answers{ any }— One{ assets }per site, as ZeroMind answers them.readRecord(string) -> (boolean, string)— Reads an install record's text by its checksum, answering whether it read and the text or the reason it did not.
Returns { any } — The answers, in order, with each record replaced; raises naming a record whose text cannot be read, with the reason, or names no installed asset.
worldVcs.__installedInPlace({ { assets = {} } }, function() return false, "unread" end)
typed/builtin//modules/world_vcs/M/__installedSummaries
M.__installedSummaries(summaries: any?) -> { any }
The install records that still install their root, out of what
install.summaries answers. A record that names its own root deleted was
uninstalled and stays only to place the dependencies something else uses,
so it is no install of its asset and is left out.
Parameters
summariesany(optional) — Whatinstall.summariesanswers.
Returns { any } — Those summaries, in the order given.
worldVcs.__installedSummaries({})
typed/builtin//modules/world_vcs/M/__isEngineSurface
M.__isEngineSurface(via: string, path: string?, kind: string?) -> boolean
Whether a site into another world reaches engine surface: what the
running engine provides, which content binds in the engine it runs in, so
a pin never versions it and an install never brings it
(docs/specs/library-versioning.md, "Engine surface is not pinned"). It
is when the site's via is asset_type, tools.use,
plugins.call, settings_of or data_contract, or when the asset it
reaches lies under modules/api/ of its world, or is an assetType,
toolbox, tool or plugin (the leaf of its path, or its manifest kind).
The engine's reference tables and ZeroMind classify by the same rule,
held by the shared vectors tests/fixtures/engine_surface.json states.
Parameters
viastring— The site's provenance.pathstring(optional) — The asset the site reaches, relative to its world's root, when known.kindstring(optional) — That asset's manifest kind, when known.
Returns boolean — True when the site reaches engine surface.
worldVcs.__isEngineSurface("require", "modules/api/scene.module", nil)
typed/builtin//modules/world_vcs/M/__jsonObjectAt
M.__jsonObjectAt(text: string, open: number) -> string?
The JSON object that opens at open in text: from that { to the
} that closes it, braces inside strings left out of the count, so the
text around it (a transport's prefix, a closing parenthesis, a line
after it) stays out.
Parameters
textstring— The text holding the object.opennumber— Where the object's{stands.
Returns string? — The object's text, or nil when it does not close in text.
worldVcs.__jsonObjectAt('failed ({"a":{"b":"}"}})', 9) --> '{"a":{"b":"}"}}'
typed/builtin//modules/world_vcs/M/__keepCurrentRecords
M.__keepCurrentRecords(closure: any?) -> { any }
A decoded closure with each tree_child at the path its folder version
states (__seatTreeChildren), narrowed to the records its paths hold now
(__closureCurrentRecords), without the dependency entries that restate a
member it keeps and the sites they alone record
(__dropMemberRestatements, __dropRestatedSites): assets holds the
entries kept, and worlds the sites recorded by an asset some kept entry
is, so a record left out reaches into no other world. Changes closure in
place.
Parameters
closureany(optional) — The decoded closure,{ assets, worlds? }.
Returns { any } — The entries left out.
worldVcs.__keepCurrentRecords(closure)
typed/builtin//modules/world_vcs/M/__kindOfPath
M.__kindOfPath(path: string) -> string?
The kind of the asset at path, as its name states it: the extension
of its last segment (module for /zero/source/a.module), or nil for a
name with none.
Parameters
pathstring— The asset's path.
Returns string? — The kind, or nil.
worldVcs.__kindOfPath("/zero/source/wood.material") --> "material"
typed/builtin//modules/world_vcs/M/__landDependencyMoves
M.__landDependencyMoves(owner: any?, moves: { PreparedDependencyMove }, allowBreaking: boolean?, ops: DependencyMoveOps) -> { InstallAssetResult }
Land dependency moves inside the install at owner in one writing of
its record (__liftDependency, __oneReleasePerAsset): the install is
planned once with every release asked for lifted beside the ones the
installed version names, every moved dependency's path placed again, and
the record checked and taken back the way __moveRecordDependency
describes. Each move states its release before the install is planned
(__installProgress).
Parameters
ownerany(optional) — The summary of the install that places every move's dependency.moves{ PreparedDependencyMove }— The moves, as__prepareDependencyMoveanswers them; at least one.allowBreakingboolean(optional) — Move them even when files outside the install that require them break against the new releases.opsDependencyMoveOps— What the moves read and run.
Returns { InstallAssetResult } — One InstallAssetResult per move, in the order of moves, each naming its dependency (root_path, root_guid, root_version) and the owner (placed_by): the files of the world's own that took a release beneath the dependency's path, and the conflicts beneath it, are its own; the files outside every moved path, the problems and the files outside the install that broke are the first move's. Raises naming every move the written record does not hold.
worldVcs.__landDependencyMoves(owner, { move }, nil, worldVcs.__dependencyMoveOps())
typed/builtin//modules/world_vcs/M/__leftRowsFailure
M.__leftRowsFailure(dest: string, expected: number, materialized: number, left: { LeftRow }) -> string
Why an install whose files did not all land was refused: each path the engine left to a row the world holds there, what holds it, and what makes the path free for the install.
Parameters
deststring— Where the install stands.expectednumber— How many files and folders the install states.materializednumber— How many of them the engine put in.left{ LeftRow }— The paths left to rows of the world, asinstall.mountStatelists them.
Returns string — The reason, naming each path and its holder, and the remedies that apply to them.
worldVcs.__leftRowsFailure("/zero/source/kit.package", 3, 2, { { path = "/zero/source/kit.package/init.luau", holder = "world", sameContent = false } })
typed/builtin//modules/world_vcs/M/__libraryChangedFiles
M.__libraryChangedFiles(diff: any?) -> { { path: string, change: string } }
The files of a library that change between two of its commits, read
from the diff of the two (zeromind.world diff): every path the diff
names except a folder whose files it names too.
Parameters
diffany(optional) —{ added, modified, removed }, each a list of paths.
Returns { { path: string, change: string } } — { path, change } per file, change being added | changed | removed, sorted by path.
worldVcs.__libraryChangedFiles({ modified = { "a.module", "a.module/init.luau" } })
typed/builtin//modules/world_vcs/M/__libraryEditOutcomes
M.__libraryEditOutcomes(libName: string, edits: { [string]: string }, fromBlobs: { [string]: string }, toBlobs: { [string]: string }) -> ({ string }, { string })
Sort the library's files the world edited by what a move of the
library from the commit from to the commit to does to them: kept, when
to holds the file as from did, and conflicted, when to changed or
removed it. A file to holds with the bytes the world holds is neither:
the library and the world agree on it (the edit was given back). A path
holding no file at either commit is neither.
Parameters
libNamestring— The library, as@<name>.edits{ [string]: string }— The world's edits under/zero/source/libs/<libName>: each path with the checksum the world holds.fromBlobs{ [string]: string }— The checksum of each asset atfrom, by source-relative path.toBlobs{ [string]: string }— The checksum of each asset atto, by source-relative path.
Returns ({ string }, { string }) — The kept paths and the conflicted paths, each sorted.
worldVcs.__libraryEditOutcomes("@scr", { ["/zero/source/libs/@scr/a.luau"] = "z" }, { ["a.luau"] = "x" }, { ["a.luau"] = "y" })
typed/builtin//modules/world_vcs/M/__libraryMarkersIn
M.__libraryMarkersIn(entries: { any }, read: (string) -> any) -> ({ LibraryMarker }, { UpdateSkip })
The library markers among the entries of /zero/source/libs. A library
is listed as a directory because the folder of its files shares the path of
its marker, so an entry's marker is read from its own path whether the
listing calls it a file or a directory. A directory whose path holds no
marker is a mounted library with none and is left out; a file that is no
zero/world-import/v1 marker is skipped with its reason.
Parameters
entries{ any }— The listingvfs.list("/zero/source/libs")answers.read(string) -> any— Reads the bytes at a path, nil when none are held.
Returns ({ LibraryMarker }, { UpdateSkip }) — The markers, and the entries skipped with the reason.
worldVcs.__libraryMarkersIn({ { name = "@lib", isDirectory = true } }, function(path) return nil end)
typed/builtin//modules/world_vcs/M/__libraryMountRefusal
M.__libraryMountRefusal(at: string?, verb: string) -> string?
Why an install aimed at at cannot land there, or nil when it can.
/source/libs/ holds the libraries the world mounts: each
/source/libs/@<name> is another world's content at the commit the world
pins, read-only here. An install lands in the world's own source, so a
destination at or under /source/libs/ is refused before anything is
read or written. The engine's own library (/source/libs/@builtin) takes
an install as a record and is answered nil.
Parameters
atstring(optional) — The destination folder the install was asked for.verbstring— The call the refusal is raised for, e.g.world.installAsset.
Returns string? — The refusal text, or nil.
worldVcs.__libraryMountRefusal("/source/libs", "world.installAsset")
typed/builtin//modules/world_vcs/M/__librarySitesMoving
M.__librarySitesMoving(libName: string, worldGuid: string, from: string, to: string) -> { LibrarySite }
The sites of the world's own content that name an asset of the
library libName lying at a path the commits from and to of its
world worldGuid differ at, or reaching one through the library's
reference tables (__sitesOnChangedPaths, the tables read with
__assetDepGuids), other than through an asset a play of the world runs
at the engine's own version (__playRunsEngineVersion): what a play of
the world runs differently when the library's pin moves between the two
commits. Reads the commits' diff from ZeroMind; a world whose own content
names no asset of the library reads nothing.
Parameters
libNamestring— The library (@builtin).worldGuidstring— The library's world.fromstring— One commit of it.tostring— The other.
Returns { LibrarySite } — The sites, each { source, literal, line?, guid }. Raises when the diff cannot be read.
worldVcs.__librarySitesMoving("@builtin", builtinWorld, pinned, engine)
typed/builtin//modules/world_vcs/M/__liesInComponent
M.__liesInComponent(rel: string) -> boolean
Whether the library path rel (relative to the library's root) is a
component or lies inside one: one of its segments names a component
folder (.component).
Parameters
relstring— The path, relative to the library's root.
Returns boolean — True for a component and every file inside it.
worldVcs.__liesInComponent("components/Light.component/init.luau")
typed/builtin//modules/world_vcs/M/__liftDependency
M.__liftDependency(closure: any?, lifted: any?)
Add one release of a dependency to an install's closure: the entries
of that release's own closure, its root as a dependency of the install
(requires), and the sites its worlds record. Each file of the release
names the folder version it lands in (via_identity), so a file the
release holds unchanged from another release lands in each. An entry the
install's closure holds already (a dependency at the same version, a
file of the same folder version) is not added twice. The plan then holds
that release beside the one the installed version names; its root states
asked (the closure's own entry of that release, when the closure names
it already), and the rank_id the lifted root states, so
__oneReleasePerAsset weighs it as a release named from outside its
asset and lands the newest of them. Changes closure in place.
Parameters
closureany(optional) — The install's decoded closure,{ assets, worlds? }.liftedany(optional) — The decoded closure of the dependency's release, its root atreason = "root".
worldVcs.__liftDependency(closure, lifted)
typed/builtin//modules/world_vcs/M/__liftHeldReleases
M.__liftHeldReleases(assets: { any }, held: { any }, moving: MovingPaths?, label: string, read: (DependencyRelease) -> any) -> ({ any }, { string }, { WorldPlanEntry })
The plan of an install with each newer release of a dependency the
world's records hold (__heldReleasesToKeep) that the plan names read
whole (read) and lifted into it (__liftDependency), the worlds those
releases reach planned and their folders completed; then the same again
for each such release the lifted ones name in turn, until a round lifts
none. A held kit's files can name a dependency at a release older than
the one the world holds, and that dependency lands at the release the
world holds rather than in a version's folder beside it.
Parameters
assets{ any }— The plan's entries.held{ any }— The dependencies the install's files run, as__releasesInstallRunsanswers them.movingMovingPaths(optional) — The path of the dependency the record is written again to move, a list of such paths, or nil.labelstring— The call the plan is made for, named in what it raises.read(DependencyRelease) -> any— The whole closure of one release to keep.
Returns ({ any }, { string }, { WorldPlanEntry }) — The plan, the lines naming each folder no read answered for, and the plan of each world the lifted releases reach.
local assets, unread, plans = worldVcs.__liftHeldReleases({}, {}, nil, "world.installAsset", function(_) return { assets = {} } end)
typed/builtin//modules/world_vcs/M/__listLibraryMarkers
M.__listLibraryMarkers() -> ({ LibraryMarker }, { UpdateSkip })
The library markers the working tree holds under /zero/source/libs:
what the update check and world.installedLibraries read.
Returns ({ LibraryMarker }, { UpdateSkip }) — The markers, and the entries skipped with the reason.
local markers, skipped = worldVcs.__listLibraryMarkers()
typed/builtin//modules/world_vcs/M/__listReferencesMoved
M.__listReferencesMoved(dirty: { any }, staged: { any }, differing: { DifferingTable })
List each file whose reference table differs from the branch head's
while its bytes do not, as a status read reports it: a staged entry for it
gains a reason, and one the area does not hold is added to dirty with
it. The reason is "references moved", or "install recorded" for a
table that differs only in the install record the engine writes. A row
whose bytes changed is listed for them and gains no reason, and a staged
entry holding the row's references alone (references_only) reads
"references moved" whatever its bytes.
Parameters
dirty{ any }— The dirty entries, appended to.staged{ any }— The calling area's staged entries, marked in place.differing{ DifferingTable }— The rows whose live table differs from the head's.
worldVcs.__listReferencesMoved(dirty, staged, differing)
typed/builtin//modules/world_vcs/M/__liveReferenceOps
M.__liveReferenceOps() -> ReferenceOps
The reference checks' reads over the live world: the trusted pin library answers whether a table names a library, and the asset index answers the path of a guid.
Returns ReferenceOps — The ReferenceOps.
worldVcs.__liveReferenceOps()
typed/builtin//modules/world_vcs/M/__liveReferencesToRecord
M.__liveReferencesToRecord(stageName: string, caller: string) -> ({ ReferencesRecord }, LiveStageStatus)
The files the calling area's commit records for their references
alone, over the live world, as __referencesToRecord states them, with
the status read they were decided on. Reads nothing more when the area
holds nothing with its bytes.
Parameters
stageNamestring— The calling staging area.callerstring— The verb asking, named when a read fails.
Returns ({ ReferencesRecord }, LiveStageStatus) — The files, and the status read.
worldVcs.__liveReferencesToRecord("default", "world.commit")
typed/builtin//modules/world_vcs/M/__liveRestateDependents
M.__liveRestateDependents(written: { string }, caller: string) -> { RestateDependent }
The files of the world's own content whose table pins the content at
one of written (the asset at a path or a folder asset holding it), each
with whether the branch head holds a version of it, read from the
engine's reverse reference index and the working tree.
Parameters
written{ string }— The paths an operation wrote, engine-canonical.callerstring— The verb asking, named when a read fails.
Returns { RestateDependent } — The files, sorted by path.
worldVcs.__liveRestateDependents({ "/zero/source/scenes/main.scene/scene.json" }, "world.restore")
typed/builtin//modules/world_vcs/M/__liveStaleReferences
M.__liveStaleReferences(stageName: string, caller: string) -> { StaleReference }
The stale files of the calling area's staged set over the live world,
as __staleReferences states them. Reads nothing more when the area
holds nothing.
Parameters
stageNamestring— The calling staging area.callerstring— The verb asking, named when a read fails.
Returns { StaleReference } — The stale files.
worldVcs.__liveStaleReferences("default", "world.commit")
typed/builtin//modules/world_vcs/M/__localEditVerdict
M.__localEditVerdict(change: string, row: any?, mergeConflicts: boolean?) -> string
Whether the world's edit of one installed file meets the incoming
change: none when the file is added or the world holds it as installed,
conflicts when an edited file is removed or its edit does not merge, and
merges when it merges cleanly.
Parameters
changestring— added | changed | removed.rowany(optional) — The pulled row the world holds for the file, or nil.mergeConflictsboolean(optional) — For an edited changed file: whether a three-way merge of it conflicts, nil when no text merge is possible.
Returns string — none | merges | conflicts.
worldVcs.__localEditVerdict("changed", { checksum = "a", origin_checksum = "a" }, nil)
typed/builtin//modules/world_vcs/M/__luauErrors
M.__luauErrors(paths: { string }) -> { [string]: { string } }
The errors the analyser reports for each Luau file of paths, by
path, each as line: message; a file holding none, and a file that is
not Luau, is absent. The walk spends a slice of each frame.
Parameters
paths{ string }— The files.
Returns { [string]: { string } } — The errors by path.
worldVcs.__luauErrors({ "/zero/source/a.luau" })
typed/builtin//modules/world_vcs/M/__markInstallRoot
M.__markInstallRoot(refsJson: string?, decision: boolean?) -> string
A reference table as its row carries it, with the engine's decision about
its asset being the root of an install recorded: true for the root of an
install, false for an asset the engine looked at and found to be none. The
rest of the table stays as its publisher wrote it.
Parameters
refsJsonstring(optional) — The table's JSON text, or nil for an asset that has none.decisionboolean(optional) —true(the default) orfalse.
Returns string — The table's JSON text with "install_root" set to the decision.
worldVcs.__markInstallRoot('{"deps":[]}')
typed/builtin//modules/world_vcs/M/__markedRootsOf
M.__markedRootsOf(rows: { any }) -> { InstalledRoot }
The marked install roots among pulled rows, each with the version its
row records (origin_checksum). A row whose table
carries no mark, or marks it false, is not a root.
Parameters
rows{ any }— The pulled manifest rows, each with itsrefs_jsontable.
Returns { InstalledRoot } — One InstalledRoot per marked root row.
worldVcs.__markedRootsOf({})
typed/builtin//modules/world_vcs/M/__markerCarries
M.__markerCarries(marker: any?, entry: any?) -> boolean
Whether a pin marker states the pin for a library world entry that
names another commit than the one it pins: the marker carries that commit
for the commit it pins (carried_for), and every site of the entry
reaches engine surface or names an asset the marker carries at it
(carried), which that commit holds at the version the pinned commit
holds. An enumeration site names no single asset and is never carried.
Parameters
markerany(optional) — The decoded marker, or nil.entryany(optional) — The decoded world entry ({ commit, sites }), or nil.
Returns boolean — Whether the marker carries the entry's commit for every site of it.
worldVcs.__markerCarries({ resolved_commit = "c2", carried_for = "c2", carried = { c1 = { "a1" } } }, { commit = "c1", sites = { { names = "a1" } } }) --> true
typed/builtin//modules/world_vcs/M/__markerCarrying
M.__markerCarrying(body: string, commit: string, carried: { [string]: { string } }) -> string?
The marker body carrying carried for the commit commit it pins:
for each commit a table of the world's own names in place of the pinned
one, the assets (by guid) that commit holds at the version the pinned
commit holds. The marker states carried_for as commit once a move has
recorded what it carries, and carried only when it carries something;
a marker that carries nothing and is asked to carry nothing is left as it
is. Every other field of the marker stays as it is.
Parameters
bodystring— The marker's bytes.commitstring— The commit the marker pins.carried{ [string]: { string } }— The assets it carries, by commit.
Returns string? — The marker's new bytes, or nil when it already states them (or body is no marker).
worldVcs.__markerCarrying('{"$schema":"zero/world-import/v1","world_guid":"w","resolved_commit":"c2"}', "c2", { c1 = { "a1" } })
typed/builtin//modules/world_vcs/M/__memoizedWorldProbe
M.__memoizedWorldProbe(probe: (world: string) -> (boolean, string)) -> (world: string) -> (boolean, string)
A probe of an origin world, asked at most once per question however many roots ask it: the first caller runs it, a caller that arrives while it runs waits for that answer, and a later caller reads the kept one. A probe that raises answers not ok with the error.
Parameters
probe(world: string) -> (boolean, string)— Asks one question of a world (whether it answers, named by its guid; the commit a ref resolves to): ok and the answer, or not ok and the failure text.
Returns (world: string) -> (boolean, string) — A function from the question to the kept answer.
worldVcs.__memoizedWorldProbe(function(world) return true, "" end)("w")
typed/builtin//modules/world_vcs/M/__mergeRowsOverRecord
M.__mergeRowsOverRecord(prior: { [string]: any }, record: { [string]: any }, dest: string, ops: any?, done: RowsOverRecordMerge) -> RowsOverRecordMerge
Move the rows of the world's own that stand over the files of the
install record prior to the version record states, once record is
materialized: an install record states every file of the install, so a
row the world holds at the path of one of them stands in place of the
installed file, and a new version of the file reaches the world only
through that row. Each row over a file whose version moves is three-way
merged: the base is the version prior states, ours the row's bytes,
theirs the version record states. A row holding the base or theirs
leaves the world, so the installed file of the new version stands there
(or nothing, when the new version holds no file there). A text row edited
where the new version changed the file too takes the clean merge of both;
a merge that conflicts, a binary file both changed, and an edited file the
new version removes keep the world's bytes and are named conflicted. A
row over a file the new version leaves as it was, and a file the world
added inside the install, stay as they are.
Parameters
prior{ [string]: any }— The record document the world held.record{ [string]: any }— The record document now materialized.deststring— Where the install stands.opsany(optional) —{ worldRowsUnder, readFile, writeFile, dropRows, blobText, fetchBlobs?, clock, wait, deadlineSeconds, pace? }.doneRowsOverRecordMerge— The merge carried out so far; each file changed is added to it as it changes, so a merge that raises part way names what to put back.
Returns RowsOverRecordMerge — done, holding the merged and conflicted paths, sorted.
worldVcs.__mergeRowsOverRecord(prior, record, "/zero/source/kit.package", ops, { merged = {}, conflicted = {}, touched = {} })
typed/builtin//modules/world_vcs/M/__missingAssetsRefusal
M.__missingAssetsRefusal(libName: string, requested: string, from: string, commit: string, sites: { LibrarySite }) -> string
Why a library move is refused when the commit it moves to does not hold assets the world's own sources require: each missing asset by the literal its sites wrote, with every source and line requiring it, where the pin stays, and how to make the move.
Parameters
libNamestring— The library (@builtin).requestedstring— The ref the move was asked for.fromstring— The commit the world pins the library at,""for none.commitstring— The commitrequestedresolved to.sites{ LibrarySite }— The sites naming an assetcommitdoes not hold.
Returns string — The refusal text, without the world.updateLibrary: prefix.
worldVcs.__missingAssetsRefusal("@builtin", "main", "a1", "b2", { { source = "/zero/source/a.luau", literal = "@builtin::modules.x", line = 1, guid = "g" } })
typed/builtin//modules/world_vcs/M/__missingFileNotices
M.__missingFileNotices(missing: { string }?) -> { string }
The install's notices for the files an installed root's type requires
that the published content lacks (the second list
__installLoadProblems answers): one notice per file, naming the asset,
its type and the file, and saying the install landed without it.
Parameters
missing{ string }(optional) — The missing-file lines, or nil.
Returns { string } — The notices, in the order given.
worldVcs.__missingFileNotices({ "/zero/source/a.material (material): required file `preview.png` is missing" })
typed/builtin//modules/world_vcs/M/__modifiedFiles
M.__modifiedFiles(files: { UpdateFile }?, moving: { string }?, modified: { string }) -> { ModifiedFile }
The files with uncommitted changes an update touches, from a review's
files (an install) or its moving sources (a library): a modified file the
update changes reads conflicts when its edit conflicts or it is removed
after the world edited it, and merges otherwise; a file the world holds as
installed carries no edit and is left out; a modified moving source reads
merges.
Parameters
files{ UpdateFile }(optional) — The review's files, or nil.moving{ string }(optional) — The review's moving sources, or nil.modified{ string }— The paths holding uncommitted changes.
Returns { ModifiedFile } — The ModifiedFile list, sorted by path.
worldVcs.__modifiedFiles({}, nil, {})
typed/builtin//modules/world_vcs/M/__moveRecordDependencies
M.__moveRecordDependencies(deps: { InstalledRoot }, ref: string?, allowBreaking: boolean?, ops: DependencyMoveOps?) -> { DependencyMoveOutcome }
Move several dependencies one install record places, each to the
release of its asset that ref names in its own origin world, in one
writing of that record: each is read and checked first
(__prepareDependencyMove), so one that holds the release asked for
answers already_present and one that cannot move (an older release, a
release that cannot be read) answers why with nothing planned; the rest
land in one plan of the install (__landDependencyMoves), so the moves
cost one plan of the install whatever their number. When that writing is
refused, each of them is moved alone, so each answers what became of it.
Dependencies of different installs each move with the others of their
own install.
Parameters
deps{ InstalledRoot }— The dependencies, as__recordDependencyRootsstates them.refstring(optional) — The ref of each dependency's world to move it to, or nil.allowBreakingboolean(optional) — Move them even when files outside the install that require them break against the new releases.opsDependencyMoveOps(optional) — What the moves read and run; this engine's when omitted.
Returns { DependencyMoveOutcome } — One DependencyMoveOutcome per dependency, in the order of deps.
worldVcs.__moveRecordDependencies({ dep }, nil, nil)
typed/builtin//modules/world_vcs/M/__moveRecordDependency
M.__moveRecordDependency(dep: InstalledRoot, ref: string?, allowBreaking: boolean?, ops: DependencyMoveOps?) -> InstallAssetResult
Move a dependency an install record places (__recordDependencyRoots)
to the release of its asset that ref names in the dependency's own
origin world (the release that world ships when ref is nil). The record
of the install that places it is written again at the version it holds,
with that release beside the one the installed version names
(__liftDependency): the newest release lands at the dependency's path,
and each file of the install whose table names the release it held runs
against the new one (__oneReleasePerAsset). A deletion the record names
at or beneath the dependency's path is dropped, so the release lands
there. Every other dependency the record places stays at the release it
holds (__heldReleasesToKeep). The move is checked the way an install
that moves a version is, and taken back the same way when it does not
run. A release older than the one the record holds is refused; the
release it holds already moves nothing. A move whose record would leave
another release at the dependency's path, or place another dependency
at an older release than the one it holds, is refused before anything
is written, naming the install and the releases
(__dependencyReleaseRefusal); a record that, once written, leaves the
dependency without the release asked for is taken back, so the world
holds the install as it did, and the move raises naming the release the
dependency would have held. A dependency in a recorded version's folder whose
install takes the release asked for from the copy the world holds of it
answers that copy's path.
Parameters
depInstalledRoot— The dependency, as__recordDependencyRootsstates it.refstring(optional) — The ref of the dependency's world to move it to, or nil.allowBreakingboolean(optional) — Move it even when files outside the install that require it break against the new release.opsDependencyMoveOps(optional) — What the move reads and runs; this engine's when omitted.
Returns InstallAssetResult — An InstallAssetResult naming the dependency (root_path, the path the release asked for stands at, root_guid, root_version the release it holds now) and the install whose record places it (placed_by).
worldVcs.__moveRecordDependency(dep, nil, nil)
typed/builtin//modules/world_vcs/M/__movedDependencies
M.__movedDependencies(live: string?, head: string?) -> { string }
The dependencies two reference tables, each as a manifest row carries it on the wire, both pin and pin at different versions: every asset guid both tables name whose set of checksums differs between them. A table names an asset once per version it records, so an asset reached at two versions is one guid with two checksums. A dependency only one table names was added or removed by an edit of the file and is not a moved pin.
Parameters
livestring(optional) — The live row's table.headstring(optional) — The branch head's table.
Returns { string } — The asset guids, sorted.
worldVcs.__movedDependencies('{"deps":[{"asset_guid":"g","checksum":"b"}]}', '{"deps":[{"asset_guid":"g","checksum":"a"}]}')
typed/builtin//modules/world_vcs/M/__movedLibraryCommits
M.__movedLibraryCommits(live: string?, head: string?) -> { { name: string, from: string, to: string } }
The library entries two reference tables, each as a manifest row carries it on the wire, hold for one world at different commits: the library's name with the head's commit and the live one.
Parameters
livestring(optional) — The live row's table.headstring(optional) — The branch head's table.
Returns { { name: string, from: string, to: string } } — { name, from, to } per moved library, sorted by name.
worldVcs.__movedLibraryCommits('{"worlds":[{"world_guid":"w","name":"@builtin","commit":"c2"}]}', '{"worlds":[{"world_guid":"w","name":"@builtin","commit":"c1"}]}')
typed/builtin//modules/world_vcs/M/__movedRowsToStage
M.__movedRowsToStage(rows: { DifferingTable }) -> { string }
The rows a bulk stage takes for the files whose references moved: each row whose bytes did not change. A row whose bytes changed is a dirty row the sweep itself stages.
Parameters
rows{ DifferingTable }— The rows whose live table differs from the head's.
Returns { string } — The paths to stage, in the order rows lists them.
worldVcs.__movedRowsToStage(rows)
typed/builtin//modules/world_vcs/M/__movedWorldPins
M.__movedWorldPins(live: string?, head: string?) -> { { guid: string, name: string } }
The world entries two reference tables, each as a manifest row carries it on the wire, both hold for one world guid at different commits: each world's guid and library name.
Parameters
livestring(optional) — The live row's table.headstring(optional) — The branch head's table.
Returns { { guid: string, name: string } } — The worlds, sorted by guid.
worldVcs.__movedWorldPins(live, head)
typed/builtin//modules/world_vcs/M/__movedWorlds
M.__movedWorlds(live: string?, head: string?) -> { string }
The other worlds two reference tables, each as a manifest row carries it on the wire, both name at different commits: the name of every world entry both tables hold for one world guid with different commits. A world only one table names was added or removed by an edit of the file.
Parameters
livestring(optional) — The live row's table.headstring(optional) — The branch head's table.
Returns { string } — The library names (@builtin), sorted.
worldVcs.__movedWorlds('{"worlds":[{"world_guid":"w","name":"@builtin","commit":"c2"}]}', '{"worlds":[{"world_guid":"w","name":"@builtin","commit":"c1"}]}')
typed/builtin//modules/world_vcs/M/__movingPathSet
M.__movingPathSet(moving: MovingPaths?) -> { [string]: boolean }
The paths of the dependencies a record is written again to move, as a set.
Parameters
movingMovingPaths(optional) — One path, a list of paths, or nil for none.
Returns { [string]: boolean } — Each path, mapped to true.
worldVcs.__movingPathSet({ "/zero/source/deps/w/a.package" })
typed/builtin//modules/world_vcs/M/__movingReleaseList
M.__movingReleaseList(movingTo: MovingReleases?) -> { DependencyRelease }
The releases the dependencies a record is written again to move are moved to, as a list.
Parameters
movingToMovingReleases(optional) — One release, a list of releases, or nil for none.
Returns { DependencyRelease } — The releases.
worldVcs.__movingReleaseList(nil)
typed/builtin//modules/world_vcs/M/__namedPaths
M.__namedPaths(paths: { string }) -> string
The text naming the first files of a list and how many more there are.
Parameters
paths{ string }— The files.
Returns string — The text.
worldVcs.__namedPaths({ "/zero/source/a.luau" }) --> "/zero/source/a.luau"
typed/builtin//modules/world_vcs/M/__narrowToReach
M.__narrowToReach(closure: any?) -> { reached: number, containers: number, dropped: number }
Narrow a closure to what its roots reach, the folders that only hold
it standing as the files that declare them. An install brings each root
whole and what the reference tables of the files it brings record
(deps, at the version recorded; an entry's entry_guid names the folder
whose version the checksum is), each of those whole, and what their own
tables record, and so on; an entry the closure states for a reason no
table records (requires, conforms_to) is reached too. A folder of the
root's world that lies around something reached without being reached
itself is a container: it keeps the files the closure gives directly in
it (a package's package.yaml, .metadata, README.md), it is marked
container = true (its version still states where each member sits, and
completion leaves it as it is), and nothing else beneath it is brought. So an
asset installed from inside a package brings itself, what it references,
and the package's own files, while a package installed as the root lands
whole, and so does a folder a table records. A file that declares a
container is marked container_file = true: it lands, and what it names
(its table, the keys its type declares) is not followed. The closure's
world entries keep the sites of the entries reached and of the containers.
Parameters
closureany(optional) — A decoded closure ({ assets, worlds }); itsassetsandworldsare replaced by the narrowed lists.
Returns { reached: number, containers: number, dropped: number } — { reached, containers, dropped }: how many entries are brought for what the roots reach, how many folders stand as containers, and how many entries are left out.
local narrowed = worldVcs.__narrowToReach(closure)
typed/builtin//modules/world_vcs/M/__newErrors
M.__newErrors(before: { [string]: { string } }, after: { [string]: { string } }) -> { UpdateBreak }
The files holding an error after a change that they did not hold before it, each with its first new error, sorted by path.
Parameters
before{ [string]: { string } }— The errors by path before the change.after{ [string]: { string } }— The errors by path after it.
Returns { UpdateBreak } — The breaks.
worldVcs.__newErrors({}, { ["/zero/source/a.luau"] = { "3: unknown global" } })
typed/builtin//modules/world_vcs/M/__newVersionCopies
M.__newVersionCopies(before: { string }, now: { string }) -> { string }
The folders of now that before does not name, sorted.
Parameters
before{ string }— The folders held earlier.now{ string }— The folders held now.
Returns { string } — The folders that came since.
worldVcs.__newVersionCopies({ "a" }, { "a", "b" }) --> { "b" }
typed/builtin//modules/world_vcs/M/__nextPreRelease
M.__nextPreRelease(version: any?) -> string?
The pre-release a branch states after version, while its package
leads to a release main has not made yet. After a release
major.minor.patch it is the first candidate of the next patch release
(-rc.1); after a pre-release major.minor.patch-<label>.<n> it is the
same release's next one (<n> + 1).
Parameters
versionany(optional) — The version a refusal names.
Returns string? — The pre-release, or nil for a version of another form.
worldVcs.__nextPreRelease("1.0.0") --> "1.0.1-rc.1"
typed/builtin//modules/world_vcs/M/__nextVersionReadDepth
M.__nextVersionReadDepth(version: any?, depth: number?) -> number?
The edge count a pulled version is read at next when the read
version (out to depth edges, or with nil out to the depth that holds
its own files, which it names in own_files_depth) left some of its own
files out: the nearest of M.__VERSION_READ_DEPTHS past the read, nil
when none is.
Parameters
versionany(optional) — The read's closure.depthnumber(optional) — The edge count the read went out to, nil for the read out to the depth that holds its own files.
Returns number? — The edge count to read at next, or nil.
worldVcs.__nextVersionReadDepth({ own_files_depth = 3 }, nil) --> 4
typed/builtin//modules/world_vcs/M/__noteInstalledFinding
M.__noteInstalledFinding(install: string, finding: string)
Note one problem the push gate found inside content the install at
install carries and the world never changed. Such a problem holds back
no push of the world; the notice naming it asks for a report to the
publisher and a fix sent upstream.
Parameters
installstring— The install's destination.findingstring— The file and the problem, as one line.
worldVcs.__noteInstalledFinding("/zero/source/kit.package", "/zero/source/kit.package/a.luau:3: unknown global 'x'")
typed/builtin//modules/world_vcs/M/__nothingAheadDetail
M.__nothingAheadDetail(origin: string, byOrigin: { [string]: { any } }) -> string
What a contribution answers for a world it was asked to send to that
none of the changes it names go to: that nothing is ahead of it, and the
worlds those changes go to, when it names any, each with the --target
that sends its changes there.
Parameters
originstring— The world asked for.byOrigin{ [string]: { any } }— The rows the contribution names, by the world each goes to.
Returns string — The detail text.
worldVcs.__nothingAheadDetail("w", {}) --> "nothing ahead of this origin"
typed/builtin//modules/world_vcs/M/__oneReleasePerAsset
M.__oneReleasePerAsset(assets: { any }, rootGuid: string, commitRecords: { [string]: any }) -> ({ any }, { [string]: string })
One release of each asset an install brings as a dependency. Several
files of an install can record one dependency at different releases: two
packages written against two releases of a third, or a package renamed
between them, one guid under two names. The releases of one asset that
land as dependencies are weighed among those a table outside the asset's
own releases names, the release or an asset it holds at the version it
holds: a release named only by files its sibling releases
hold (a file unchanged between two releases, carrying the table recorded
beside the later one) is named from within the asset, so the release the
depending content recorded stands for it. A release the install asks for
(asked: one a dependency move lifts, __liftDependency, or one the
world's record of the install holds, __askHeldReleases) counts as named
from outside. Of those, newest first (the later rank, __releaseRank: the
version_id, or the rank_id a dependency move states; a release
stating none ranking below every one that states one, then the first the
closure lists), and then of the others newest first, the first release
that holds, by guid, every asset of each other release that a file
landing with it names (a file outside the asset's own releases, or one of
the release itself; a table records the asset each site resolves to)
stands; when none does, the newest named from outside stands. Each other
release whose named assets the release standing holds is left out with
the entries beneath it: each
reference table of the install that names one of its assets names the
standing release's version of that asset instead (__redirectRefsTable),
so each module among them loads once and every file that requires it
shares its state. A release holding an asset a file names that the
standing one does not lands beside it, and __releaseSplits names it. A
dependency on an asset another dependency or the installed root holds
beneath it (a module of a package the install lands, or of the root
itself) runs the version that holder holds, when it holds every asset of
it a file outside it names, at a version no older than the one recorded
(by version_id): of the holders, the one holding the most assets, then
the newest. A recorded version newer than the one its holder
holds runs the holder's version too when tables of the closure name it
and every file whose table names it is one the holder holds, or one of
another such version of the same holder: those files are the holder
release's own, whose tables were recorded beside a later release holding
them unchanged, and the release lands as one unit. A newer version any
other file names, or no table of the closure names, lands beside the
holder, and __releaseSplits names it. The installed
asset's own releases stay as they are, and so do the versions of a
library this world mounts (world_pull, @builtin among them): an
installed file's site naming such a library runs the version its
published table names, so a version left out would come back as a copy
the engine fetches, and __releaseSplits names those that land at more
than one version.
Parameters
assets{ any }— The closure's entries, the world pulls included.rootGuidstring— The installed asset's guid.commitRecords{ [string]: any }— The versions each commit the install read holds, byworld@commit, which are only read.
Returns ({ any }, { [string]: string }) — The entries the install places, and the version standing for each left-out one, by guid@checksum.
local kept, redirect = worldVcs.__oneReleasePerAsset(assets, rootGuid, {})
typed/builtin//modules/world_vcs/M/__openOwnLink
M.__openOwnLink(row: any?) -> boolean
Whether the root of the dependency an ahead row belongs to (its
root_guid) keeps a contribution link to a pull request recorded open
in the world the dependency was published from (origin_world_guid),
as world_vcs.engagement keeps it.
Parameters
rowany(optional) — An ahead row.
Returns boolean — True when that link is kept.
worldVcs.__openOwnLink({ root_guid = depGuid, origin_world_guid = depWorld })
typed/builtin//modules/world_vcs/M/__openUpdateCheck
M.__openUpdateCheck(ops: OpenUpdateCheckOps) -> (string?, string?)
The check an editor open makes once the world is ready, and again
while it stays open: raises the notice for a @builtin pin older than the
engine's and the notice for the other units with an update, each finding
(a unit, the version it holds and the version it is behind) once for the
world, writes one log line per notice, and one log line (no notice) when
no unit could be read. A finding raised before is not raised again; the
unit raises again when it holds another version or falls behind a newer
one. Does nothing outside an editor session
whose content is confirmed.
Parameters
opsOpenUpdateCheckOps— AnOpenUpdateCheckOps.
Returns (string?, string?) — The text of the notice for the units with an update, nil when none was raised; then the text of the @builtin notice, nil when none was raised.
worldVcs.__openUpdateCheck({ confirmedEditorOpen = function() return false end, collect = function() return {}, {}, 0 end, notify = print, log = print })
typed/builtin//modules/world_vcs/M/__originRootPath
M.__originRootPath(entry: any?, base: string) -> string?
The path the root of a closure stands at in the world it was published
from, under this world's /zero/source, when that path is one an install
places a root at: the root's own name (base) inside plain folders, so the
root keeps the name its source world and its dependencies give it. Nil for
a root at the top of its world, for a root inside another asset's folder
(a member of a package, whose folder this world does not hold), and for a
root its world holds in its dependency tree or a library.
Parameters
entryany(optional) — The closure entry of the root.basestring— The root's own folder name, category suffix included.
Returns string? — The engine-canonical path, or nil.
worldVcs.__originRootPath({ path = "paintedValley/sky/sky.module" }, "sky.module") --> "/zero/source/paintedValley/sky/sky.module"
typed/builtin//modules/world_vcs/M/__otherAreasHolding
M.__otherAreasHolding(claims: { any }) -> { [string]: { ReleasedPath } }
The other staging areas holding each path, by path, as status reads'
claimed_by_other_stages name them. A path is staged in one area at a
time, so a staging call that stages one of these paths takes it out of
each area listed here, by that area's row id, whichever account opened
the area and whether or not the session holding it is open.
Parameters
claims{ any }— The rows other staging areas hold,{ path, stage_name, stage_row_id, owner_account, same_account, live, session, ... }.
Returns { [string]: { ReleasedPath } } — One ReleasedPath row per area holding each path, in the order claims lists them, each area once per path.
worldVcs.__otherAreasHolding(status.claimed_by_other_stages)["/zero/source/a.luau"][1].stage --> "client:b"
typed/builtin//modules/world_vcs/M/__otherAreasNamed
M.__otherAreasNamed(name: string, claims: { any }, reserved: { any }) -> { OtherArea }
The unsealed staging areas named name that a status read reports
beside the one it reports on: one row per area, with how many paths it
stages and how many outputs it reserves, each named by its row id. A
staging area is one row per account and name, so these are the areas other
accounts hold under the name.
Parameters
namestring— The staging area's name.claims{ any }— The read'sclaimed_by_other_stagesrows.reserved{ any }— The read'sreserved_by_other_stagesrows.
Returns { OtherArea } — The areas, in the order the rows first name them.
worldVcs.__otherAreasNamed("fauna", status.claimed_by_other_stages, status.reserved_by_other_stages)[1].stage_row_id --> "41"
typed/builtin//modules/world_vcs/M/__otherStageHolding
M.__otherStageHolding(assetPath: string, callerStage: string, claims: { any }, committed: { CommittedArea }) -> string?
The staging area holding an asset, for a caller acting on
callerStage. An area holds the asset when it holds the asset's own
path or any path inside it. A staged row another area holds names that
area. Otherwise the commit nearest the branch head that froze a path
inside the asset through a named area decides: that area holds it
while it still answers for what it committed (answers), and a commit
through the one shared area claims nothing. Answers nil when the asset
is the caller's own or when no area holds it, which is the answer a
lone author gets for everything.
Parameters
assetPathstring— The asset's path.callerStagestring— The staging area the calling verb acts on.claims{ any }— Theclaimed_by_other_stagesrows from a status read.committed{ CommittedArea }— The rows__committedAreasreports for the asset.
Returns string? — The name of the other area holding it, or nil.
worldVcs.__otherStageHolding("/zero/source/a.component", "beta", claims, committed)
typed/builtin//modules/world_vcs/M/__outsideBaseline
M.__outsideBaseline(ops: InstallRecordOps, dest: string) -> OutsideBaseline
What the content outside the install at dest that requires it holds
before the install moves its version: the guids of the install's assets,
each requiring source, the sites of those sources that already name a
version the world holds nowhere, the modules whose running code already
differs from their source, and the analyser's errors in each requiring
Luau source.
Parameters
opsInstallRecordOps— The install's operations;requirersanswers what requires the install.deststring— Where the install stands.
Returns OutsideBaseline — An OutsideBaseline.
worldVcs.__outsideBaseline(ops, "/zero/source/kitA.package")
typed/builtin//modules/world_vcs/M/__outsideBreaks
M.__outsideBreaks(ops: InstallRecordOps, dest: string, baseline: OutsideBaseline, step: (() -> ())?) -> { UpdateBreak }
The files outside the install at dest that its new version breaks,
each once with what breaks it, sorted by path: a requiring source with a
site naming a version of the install's assets the world holds nowhere
once the fetches the engine started for them have ended, a module of the
install or of a requiring source whose reload failed since baseline
(named by the requiring source it runs from), and a requiring Luau source
holding an analyser error it did not hold before.
Parameters
opsInstallRecordOps— The install's operations.deststring— Where the install stands.baselineOutsideBaseline— What__outsideBaselineread before the install moved.step(() -> ())(optional) — Called between the waits (the install's cancel check), or nil.
Returns { UpdateBreak } — The breaks.
worldVcs.__outsideBreaks(ops, "/zero/source/kitA.package", baseline, nil)
typed/builtin//modules/world_vcs/M/__outsideRefusal
M.__outsideRefusal(dest: string, breaks: { UpdateBreak }, moving: MovingPaths?) -> string
Why an install that would break content outside it was taken back:
each file with its error, and how to install the version anyway. For a
record written again to move one or more of its dependencies (moving),
the reason names those dependencies as what was not moved, inside the
install at dest.
Parameters
deststring— Where the install stands.breaks{ UpdateBreak }— The files it breaks, as__outsideBreaksanswers them.movingMovingPaths(optional) — The dependency the record was written again to move, a list of them, or nil.
Returns string — The reason.
worldVcs.__outsideRefusal("/zero/source/kitA.package", { { path = "/zero/source/kitB.package/prod.module", error = "does not load: boom" } })
typed/builtin//modules/world_vcs/M/__overlayRestoreScopes
M.__overlayRestoreScopes(ignored: { any }, targets: { string }) -> { string }
The scopes a restore of named paths takes a scene's autosave overlay
back through. The overlay (<scene>/scene_dirty/...) holds the live edits
no save has written into the scene, and its rows are ignored rows of the
status read, so a path restore that walks the dirty rows passes them by.
For each overlay row at or beneath a target the scope is the overlay
folder the row sits in, or the target itself where the target lies inside
that folder: naming a scene, a folder above it, its scene_dirty folder or
one overlay file each reaches the overlay rows that path covers and no
other file. A scope inside another scope of the answer is left out, since
the outer one takes it back with it.
Parameters
ignored{ any }— The ignored rows of a status read taken with{ ignored = true }.targets{ string }— The engine-canonical paths the restore names.
Returns { string } — The scopes, sorted, each for world.discardAll.
worldVcs.__overlayRestoreScopes(world.vcsStatus({ ignored = true }).ignored, { "/zero/source/scenes/main.scene" })
typed/builtin//modules/world_vcs/M/__owedRowsToStage
M.__owedRowsToStage(owed: { string }, ignored: (string) -> boolean) -> { string }
The rows a bulk stage takes beyond the dirty rows it swept: each path
of owed that the call stages, where owed names the files whose
references moved. A path the live ignore set matches publishes nothing,
so it stays out. A path another staging area holds is staged here like
any other, and the staging call takes it out of that area.
Parameters
owed{ string }— The paths to take: the files whose references moved.ignored(string) -> boolean— Whether the live ignore set matches a path.
Returns { string } — The rows to stage, in the order owed lists them.
worldVcs.__owedRowsToStage({ "/zero/source/a.module/init.luau" }, function() return false end)
typed/builtin//modules/world_vcs/M/__ownChangePaths
M.__ownChangePaths(dirty: { any }, staged: { any }) -> { string }
The paths a status read lists as holding changes of their own: every
dirty and staged entry except one listed for its reference table alone
(a reason of references moved or install recorded), which the
engine recorded and nobody edited.
Parameters
dirty{ any }— The dirty entries, each a path or{ path, reason? }.staged{ any }— The staged entries, each{ path, reason? }.
Returns { string } — The paths, in the order listed.
worldVcs.__ownChangePaths({ { path = "/zero/source/a.luau" } }, {})
typed/builtin//modules/world_vcs/M/__ownEditPaths
M.__ownEditPaths(paths: { string }, rows: { any }) -> { string }
The paths among paths that hold an edit of the world's own: a pulled
file whose bytes differ from the version it installed, or any path no
pulled row holds. A pulled folder, and a pulled file holding the bytes it
installed, carry no edit of the world's, whether or not their install has
been committed.
Parameters
paths{ string }— The paths holding uncommitted changes.rows{ any }— The world's pulled rows.
Returns { string } — The paths that hold an edit, in the order given.
worldVcs.__ownEditPaths({ "/zero/source/own.luau" }, {})
typed/builtin//modules/world_vcs/M/__ownSourcesBehind
M.__ownSourcesBehind(name: string, commit: string?, reads: OwnSourcesReads?) -> { string }
The world's own files whose table names the library at a commit other
than commit (the marker's when nil) and that a pin move stages and
waits on (__pinMoveSources).
Parameters
namestring— The library (@builtin).commitstring(optional) — The commit to compare against, nil for the marker's.readsOwnSourcesReads(optional) — The reads, the live engine's when nil.
Returns { string } — The files, sorted.
worldVcs.__ownSourcesBehind("@builtin", nil)
typed/builtin//modules/world_vcs/M/__pacer
M.__pacer() -> () -> ()
A function that gives the frame back once the work has spent its slice
of the frame: called between small steps of a long piece of work, it reads
the frame's slice of cooperative work (FrameBudget.fitMs, the spare time
of the frame, or a share of a long frame's other work) once the steps since
its last reading have run M.__PACE_READ_S, and yields to the next frame
when the slice is spent (FrameBudget.yield). The work is charged to the
slice from the moment the pacer is made. The yield leaves the engine a
continuation of the work, so a still engine runs the next frame at its
frame rate and the work goes on in every frame until it ends.
Returns () -> () — The function to call between steps.
local pace = worldVcs.__pacer(); pace()
typed/builtin//modules/world_vcs/M/__partialCopies
M.__partialCopies(roots: { InstalledRoot }) -> { [string]: { string } }
The dependencies each install record places that are copies of part of another asset the world holds: a dependency whose origin path lies beneath the origin path of an install root, or of a dependency a record places, in the same origin world, standing outside every copy of that asset and outside every recorded version's folder. Such a copy stands with no root of its own around it; writing again the record that places it takes it out, the asset around it standing for it. A dependency its record names deleted is left out.
Parameters
roots{ InstalledRoot }— The world's install roots, as__recordRootsstates them; a dependency unit (placed_by) is passed over.
Returns { [string]: { string } } — The paths of the copies, sorted, by the path of the install whose record places them; an install placing none is absent.
worldVcs.__partialCopies({ { path = "/zero/source/kit.package", guid = "g", display_name = "kit.package", version = "c" } })
typed/builtin//modules/world_vcs/M/__pathBelow
M.__pathBelow(path: string, folder: string) -> string?
The segments of a path below a folder, joined with /, when the path
stands strictly below it. Each is a VFS path or a path relative to a
source root.
Parameters
pathstring— The path.folderstring— The folder.
Returns string? — The part of path below folder, or nil when path stands elsewhere or at folder itself.
worldVcs.__pathBelow("/zero/source/Kit.package/package.yaml", "Kit.package")
typed/builtin//modules/world_vcs/M/__pathIsUnder
M.__pathIsUnder(path: any?, root: string) -> boolean
Whether path is root or lies inside it. A path a neighbouring
folder shares a prefix with is a different path.
Parameters
pathany(optional) — The path to place.rootstring— The asset path it is measured against.
Returns boolean — True when path is root or continues it past a /.
worldVcs.__pathIsUnder("/zero/source/a.component/init.luau", "/zero/source/a.component") --> true
typed/builtin//modules/world_vcs/M/__pathSet
M.__pathSet(paths: { string }) -> { [string]: boolean }
The set of paths: each path keyed to true.
Parameters
paths{ string }— The paths.
Returns { [string]: boolean } — The set.
worldVcs.__pathSet({ "/zero/source/a" })
typed/builtin//modules/world_vcs/M/__pathsTouch
M.__pathsTouch(paths: { string }, watched: { string }, rootPath: string) -> (boolean, boolean)
Whether the paths one commit changed touch an install: a path that is
one of watched (the origin paths of the install's closure) or lies
beneath one touches it, and one that is the root's path or lies beneath it
touches the root.
Parameters
paths{ string }— The paths the commit changed.watched{ string }— The origin paths of the closure.rootPathstring— The origin path of the root.
Returns (boolean, boolean) — Whether the commit touches the install, and whether it touches the root.
worldVcs.__pathsTouch({ "Fire.module/init.luau" }, { "Fire.module" }, "Fire.module")
typed/builtin//modules/world_vcs/M/__pathsWithTheirUpdates
M.__pathsWithTheirUpdates(given: { any }, stageName: string, caller: string) -> { string }
The paths a stage or unstage of given acts on over the live world:
each path that is part of a library pin move brings the whole move
(__expandUpdatePaths), every other path is itself.
Parameters
given{ any }— The paths named.stageNamestring— The calling staging area.callerstring— The verb asking, named when a read fails.
Returns { string } — The paths, engine-canonical.
worldVcs.__pathsWithTheirUpdates({ "/zero/source/libs/@builtin" }, "default", "world.add")
typed/builtin//modules/world_vcs/M/__pendingWriter
M.__pendingWriter(rowCaller: string?, caller: string?) -> string
What a write this engine made and the manifest has not reflected
yet is to the calling caller: "you" when the calling caller made it,
"other" when another caller did, "unattributed" when no caller was
attested for it and the calling caller is a named one. A caller that is
itself unattributed reads an unattributed write as its own. The rule a
status read applies to a manifest row this engine wrote, applied to a
write still on its way to one.
Parameters
rowCallerstring(optional) — The caller key the write was made under, nil when none.callerstring(optional) — The calling caller's key, nil when none.
Returns string — "you", "other" or "unattributed".
worldVcs.__pendingWriter("client:a", "client:b") -- "other"
typed/builtin//modules/world_vcs/M/__pendingWritesNow
M.__pendingWritesNow() -> ({ string }, { [string]: any })
This engine's writes on their way to the manifest, read now: the paths
vfs.pendingWrites() lists and the callers vfs.pendingWriteAuthors()
names for them. Both are empty where the VFS holds no pending-write list.
Returns ({ string }, { [string]: any }) — The paths, and the map from each path to the caller whose call made it.
local paths, authors = worldVcs.__pendingWritesNow()
typed/builtin//modules/world_vcs/M/__pinContributedTable
M.__pinContributedTable(refs: any?, versionOf: (string) -> (string?, boolean?), libraryPin: (string) -> any) -> string?
A contributed asset's reference table as the world it is sent to states
it once the contribution lands: each dependency at the version that world
holds of it then (versionOf, the contribution's own new versions
included; a dependency it holds nowhere keeps the version the table
names), each library world entry at the commit that world's own pin marker
states (libraryPin), and without the dangling-dependency problems those
versions answer. A dependency whose version moves drops the version id
that named the old one, and so does a dependency whose version there the
contribution itself publishes: the version id this world states for it
names the version this world published, and the target's version of it
is the one the contribution's commit records. A world entry every site of
which reaches engine surface states no commit, since the pin versions none
of what it reaches.
Parameters
refsany(optional) — The table: decoded, or its JSON, or nil.versionOf(string) -> (string?, boolean?)— The version the target holds of an asset once the contribution lands, by guid, or nil; and whether the contribution publishes that version there.libraryPin(string) -> any— The pin marker the target holds for a library (@name):{ world_guid, resolved_commit, carried_for?, carried? }, or nil. A world entry naming a commit the marker carries for its pin, every site naming an asset carried at it, keeps it (__markerCarries).
Returns string? — The table's JSON, or nil when refs holds none.
worldVcs.__pinContributedTable(nil, function() return nil end, function() return nil end)
typed/builtin//modules/world_vcs/M/__pinForFirstCommit
M.__pinForFirstCommit(ops: FirstCommitPinOps) -> { [string]: any }
Pin @builtin for a world's first commit: carry out the decision
decide answers, waiting a bounded time for the engine's published commit
and for the pin's version table, then derive the world's own tables at the
pin. Opening a world writes no pin; the first commit is the change that
records one, with the tables it moved.
Parameters
opsFirstCommitPinOps— The engine operations, or fakes standing in for them.
Returns { [string]: any } — { wrote, failed?, commit?, changed, reason? }: changed names the files whose references the pin moved, which the commit takes with the marker; failed says the commit is refused, with reason.
worldVcs.__pinForFirstCommit(ops)
typed/builtin//modules/world_vcs/M/__pinMoveSources
M.__pinMoveSources(paths: { string }, ignored: (string) -> boolean) -> { string }
Of the files of the world's own whose table a library pin move
rewrites, the ones the move stages and waits on: every one but the scene
overlays a session keeps, which no commit records, and the files the
ignore set matches, whose bytes stay out of every commit (the engine's
own service-run records among them). A matched file the branch head
holds goes into the commit that records the pin as its table alone
(__referencesToRecord).
Parameters
paths{ string }— The files whose table the move rewrites.ignored(string) -> boolean— Whether the ignore set matches a path.
Returns { string } — The files, in the order paths lists them.
worldVcs.__pinMoveSources({ "/zero/source/game/a.luau" }, function() return false end) --> { "/zero/source/game/a.luau" }
typed/builtin//modules/world_vcs/M/__pinUpdates
M.__pinUpdates(differing: { DifferingTable }, status: LiveStageStatus, recorded: { [string]: { string } }?) -> { PinUpdate }
The library pin moves the working tree holds, each as one change: a
library whose marker (/zero/source/libs/@<name>) is changed or staged,
or whose name a file's table moved away from the head's commit to
another commit. Each file whose table moved it joins the update: in
repins when its bytes are the head's, in edited when they changed
too. Library content, scene overlays, files the ignore set matches
(__pinMoveSources) and tables that differ only in their install record
take no part, and neither do tables that name no commit
of a library whose marker is the head's: the engine derives those again
at the pin once it reads, and they move no pin.
Parameters
differing{ DifferingTable }— The rows whose live table differs from the head's.statusLiveStageStatus— The working tree and the calling area, read once.recorded{ [string]: { string } }(optional) — The recorded versions' folders each library's last move recorded, by library; the moves this session made when absent.
Returns { PinUpdate } — One PinUpdate per library, sorted by library name.
worldVcs.__pinUpdates({}, { dirty = {}, staged = {}, ignored = function() return false end })
typed/builtin//modules/world_vcs/M/__pinnedSites
M.__pinnedSites(found: InstallRequirers, dest: string) -> { string }
One line for each site of a file outside the install at dest that
runs a copy of one of its assets other than the one the install places:
the file, the version it names, the copy it runs, and how to move it onto
the install's copy.
Parameters
foundInstallRequirers— Whatinstall.requirersanswers for the install.deststring— Where the install stands.
Returns { string } — The lines, sorted.
worldVcs.__pinnedSites({ requirers = {}, guids = {} }, "/zero/source/kitA.package")
typed/builtin//modules/world_vcs/M/__placeMovedDependencies
M.__placeMovedDependencies(placement: { [string]: string }, assets: { any }, moves: { DependencyMove })
Place each closure entry of a moved dependency at the path the install
holds that dependency, its path beneath the dependency's origin path kept.
Changes placement in place.
Parameters
placement{ [string]: string }— The path each asset lands at, by guid.assets{ any }— The closure's entries.moves{ DependencyMove }— The moved dependencies (__dependencyMoves).
worldVcs.__placeMovedDependencies({}, {}, {})
typed/builtin//modules/world_vcs/M/__placeRetiring
M.__placeRetiring(assets: { any }, rootGuid: string, explicitRootPath: string?, retired: { RetiredCopy }) -> ({ [string]: string }, { [string]: string }, { [string]: string }, (any) -> string, { RetiredCopy })
Where an install places its entries when it retires the copies
another install places of assets it lands newer (__retiredCopies): the
plan treats each retired copy as absent (installFootprint), so the
release taking its place lands where the asset's name reaches. A retired
copy whose landing release would still land in a recorded version's
folder is not retired. In a thread planning an install (one holding a
footprint already) the retired paths stay in its footprint for the steps
after placement, which the install clears; any other caller's thread
holds no footprint once this returns.
Parameters
assets{ any }— The entries the install places.rootGuidstring— The installed asset's guid.explicitRootPathstring(optional) — The destination the install was asked for, or nil.retired{ RetiredCopy }— The copies to retire.
Returns ({ [string]: string }, { [string]: string }, { [string]: string }, (any) -> string, { RetiredCopy }) — placement, satisfied, superseded, keyOf as computeClosurePlacement answers them, and the copies retired.
local placement, satisfied, superseded, keyOf, retired = worldVcs.__placeRetiring(assets, "g", nil, {})
typed/builtin//modules/world_vcs/M/__placedAgain
M.__placedAgain(held: any?, record: any?, placeAgain: { string }?) -> { string }
The paths a record written for an install places again although the
record the world held for it names them deleted: each of placeAgain,
and the path of each dependency record places at a release the held
record placed no copy of at that path. A deletion at or beneath one of
them took out a release this record does not hold there, so it is not
carried over and the release the record names lands at its path.
Parameters
heldany(optional) — The record the world held for the install, decoded, or nil.recordany(optional) — The record about to be written.placeAgain{ string }(optional) — The paths the caller places again, or nil.
Returns { string } — The paths, placeAgain first.
worldVcs.__placedAgain(nil, { deps = {} }, nil)
typed/builtin//modules/world_vcs/M/__placedBesideRow
M.__placedBesideRow(rowPath: any?, placement: string?) -> boolean
Whether a closure entry placed at placement lands beside the pulled row
the world holds for the same asset, rather than updating it in place: the
row sits under /zero/source/deps/ and the placement is another path.
Parameters
rowPathany(optional) — The path of the pulled row the world holds for the asset.placementstring(optional) — The path the closure's placement gives the entry, nil when the world already holds it.
Returns boolean — True when the entry lands beside the row.
worldVcs.__placedBesideRow("/zero/source/deps/w/a.module", "/zero/source/deps/w/versions/c/a.module")
typed/builtin//modules/world_vcs/M/__planBoundedPulls
M.__planBoundedPulls(worlds: { ClosureWorld }, libraries: { LibraryHere }, resolveSites: (string, string, { any }) -> { any }, holds: (string, string, string, string?) -> boolean, readVersion: (string, string, number?, string?) -> any, shipped: ((string) -> string?)?, published: ((string) -> string?)?, readAhead: PlanReadAhead?) -> { entries: { any }, worlds: { WorldPlanEntry }, reads: number }
What an install brings from the other worlds its closure reaches into
(docs/specs/library-versioning.md, "Installing content whose pin
differs"). Each world entry is planned by __planWorldPulls. Each asset
it brings is read at its version on its own (readVersion, out to the
depth that holds its own files, then deeper only while its own files reach
past the read, __versionOwnEntries) and lands with its own files alone.
Each dependency those files' reference tables record that is
not engine surface and whose version this world does not hold is brought
the same way, recursively, and each world entry of those files is planned
the same way; nothing else of the asset's world is read or brought. An
asset of a library this world reaches lands by its version
(world_pull); one of a world this world holds no copy of stands as a
dependency of its own, and one inside a package brings the package whole.
Each site of a world commit is resolved once and each version read once
out to the depth that holds its own files and once at each edge count
(__planReads).
Parameters
worlds{ ClosureWorld }— The closure's world entries.libraries{ LibraryHere }— The libraries this world reaches (libraryPin.worlds).resolveSites(string, string, { any }) -> { any }— Answers, for a world, a commit and a list of{ via, literal, names? }, one{ assets }per site in order.holds(string, string, string, string?) -> boolean— Whether this world holds an asset (guid,checksum, world guid, path in its world).readVersion(string, string, number?, string?) -> any— Reads one asset (guid) at one version (checksum) out to a number of edges, or, with nil, out to the depth that holds its own files (the closure names it inown_files_depth), answering the decoded closure; its fourth argument is the commit the plan reached that version through (__readVersionAt).shipped((string) -> string?)(optional) — Answers the commit a world ships (__planWorldPulls).published((string) -> string?)(optional) — Answers the commit an asset was last published at (__planWorldPulls).readAheadPlanReadAhead(optional) — The reads made several at once (PlanReadAhead), or nil: with it, the reads a step of the plan is about to make are made together before it (__planReads), and the plan is the one it is without it.
Returns { entries: { any }, worlds: { WorldPlanEntry }, reads: number } — { entries, worlds, reads }: the entries to land (each asset's own root standing as a dependency), one plan entry per world, and how many version reads it made.
worldVcs.__planBoundedPulls(closure.worlds, libs, resolve, holds, read, shipped, published)
typed/builtin//modules/world_vcs/M/__planReads
M.__planReads(resolveSites: (string, string, { any }) -> { any }, readVersion: (string, string, number?, string?) -> any, ahead: PlanReadAhead?) -> PlanReads
The reads of one install plan (PlanReads) over resolveSites and
readVersion: each site of a world commit is resolved once and each
version read once out to the depth that holds its own files and once at
each edge count, whichever step asks for it, and with
ahead the reads a step is about to make are made together before it asks.
An answer a step asks for is the one ZeroMind gave, read ahead or not, so
the plan decides the same with or without ahead; a read ahead that failed
is made again when a step asks for it, and raises there as it would have.
Parameters
resolveSites(string, string, { any }) -> { any }— Answers, for a world, a commit and a list of{ via, literal, names? }, one{ assets }per site in order.readVersion(string, string, number?, string?) -> any— Reads one asset (guid) at one version (checksum) out to a number of edges, or, with nil, out to the depth that holds its own files (the closure names it inown_files_depth), answering the decoded closure; its fourth argument is the commit the plan reached that version through (__readVersionAt).aheadPlanReadAhead(optional) — The reads made several at once (PlanReadAhead), or nil to make each read when a step asks for it.
Returns PlanReads — The plan's reads (PlanReads).
local reads = worldVcs.__planReads(resolve, readVersion, nil)
typed/builtin//modules/world_vcs/M/__planWorldPulls
M.__planWorldPulls(worlds: { ClosureWorld }, libraries: { LibraryHere }, resolveSites: (string, string, { any }) -> { any }, holds: (string, string, string, string?) -> boolean, shipped: ((string) -> string?)?, published: ((string) -> string?)?, ahead: { sitesAhead: ({ { world: string, commit: string, sites: { any } } }) -> (), peekSites: (string, string, { any }) -> { any } }?) -> { pulls: { WorldPull }, worlds: { WorldPlanEntry } }
What an install brings for the other worlds its closure reaches into
(closure.worlds). A world this world uses at the commit the installed
content recorded brings nothing: every site resolves in this world's own
copy. The commit a world uses is the one it pins, or for a library it pins
none of, the commit of that library the engine opens it with
(libraryPin.worlds, mounted). A world entry that recorded no commit
of a library this world reaches brings nothing either: its sites resolve
against this world's own library. A world entry that recorded no commit
of a world this world reaches no library of (content published before
install records stated the commit they read) is read at the commit another
entry of the same world recorded, or else at the commit that world ships
(shipped), and planned like any other; a naming site that commit answers
with nothing is read at the commit ZeroMind last published its asset at
(published). The version each such site's asset is brought at is the
entry's restated. For any other world, each
recorded site is resolved at the recorded commit — a naming site to the
asset it names, an enumeration site to the members its selector matches
there — and each asset whose version there this world does not hold is
brought, once. A site that reaches engine surface (__isEngineSurface) is
never asked about, and a resolved asset that is engine surface is never
brought. The library itself is never brought whole. From a world this
world holds no copy of (no pin and no library it opens), an asset inside a
package brings that package whole at the same commit
(__wholePackages), and each pull is unreached.
Parameters
worlds{ ClosureWorld }— The closure's world entries.libraries{ LibraryHere }— The libraries this world reaches (libraryPin.worlds).resolveSites(string, string, { any }) -> { any }— Answers, for a world, a commit and a list of{ via, literal, names? }, one{ assets }per site in order.holds(string, string, string, string?) -> boolean— Whether this world holds an asset (guid,checksum, world guid, path in its world).shipped((string) -> string?)(optional) — Answers the commit a world ships (itsmain), or nil.published((string) -> string?)(optional) — Answers the commit of its world ZeroMind last published an asset (guid) at, or nil.ahead{ sitesAhead: ({ { world: string, commit: string, sites: { any } } }) -> (), peekSites: (string, string, { any }) -> { any } }(optional) — The plan's reads (PlanReads), or nil: with them, the sites of every entry are resolved together before the entries are planned, then the packages holding what an entry of a world this world holds no copy of answers, and each entry is planned from those answers.
Returns { pulls: { WorldPull }, worlds: { WorldPlanEntry } } — { pulls, worlds }: the assets to bring, sorted by guid then version, and one entry per world.
worldVcs.__planWorldPulls(closure.worlds, libs, resolve, holds, shipped, published)
typed/builtin//modules/world_vcs/M/__playRunsEngineVersion
M.__playRunsEngineVersion(rel: string, runsItsCopy: boolean) -> boolean
Whether a play of a world runs the engine's own version of the
library asset at rel, whatever version the world's @builtin pin
names. A play installs the version the pin names in place of the
engine's, all but what the engine's own code runs: an asset the engine
runs its own copy of (runsItsCopy, vfs.engineRunsItsCopy) that is no
component. A component is a type the library registers, so a play runs
the component of the version the pin names.
Parameters
relstring— The asset's path, relative to the library's root.runsItsCopyboolean— Whether every site naming the asset runs the engine's copy of it.
Returns boolean — True when the play runs the engine's version of the asset.
worldVcs.__playRunsEngineVersion("modules/prelude.module", true)
typed/builtin//modules/world_vcs/M/__postInstalledFindings
M.__postInstalledFindings(findings: { [string]: { string } })
Post the notice __installedFindingsNotice states for findings, when
there is one, as a community notice of the kind report
(modules.community's post), which the person's community setting
grants or not.
Parameters
findings{ [string]: { string } }— Findings by install destination.
worldVcs.__postInstalledFindings({})
typed/builtin//modules/world_vcs/M/__prepareDependencyMove
M.__prepareDependencyMove(dep: InstalledRoot, ref: string?, owner: any?, ops: DependencyMoveOps) -> (PreparedDependencyMove?, InstallAssetResult?)
Read the release of dep that ref names in the dependency's own
origin world (the release that world ships when ref is nil) and check
it before anything is planned: a release the dependency holds already
answers already_present; a closure that names no release, one that is
truncated, and a release older than the one the dependency holds raise
naming the dependency and the install at owner. Releases are ordered by
version id, and a release asked for whose version id is the earlier is
placed on the dependency's own line (ops.releaseOrder): another world's
push of a package holding the dependency states a version id of its own,
so the release the dependency holds can read later than its own world's
newer releases. One the line places after the held release moves, ranked
just after it (rank_id, __rankAfter).
Parameters
depInstalledRoot— The dependency, as__recordDependencyRootsstates it.refstring(optional) — The ref of the dependency's world to move it to, or nil.ownerany(optional) — The summary of the install that places it (__dependencyMoveOwner).opsDependencyMoveOps— What the move reads.
Returns (PreparedDependencyMove?, InstallAssetResult?) — The move to land, or nil and the already_present answer.
local move, held = worldVcs.__prepareDependencyMove(dep, nil, owner, worldVcs.__dependencyMoveOps())
typed/builtin//modules/world_vcs/M/__priorInstallOf
M.__priorInstallOf(summaries: any?, rootGuid: string, at: string?) -> any
The install the world holds of rootGuid that an install of it
asked to land at at writes again: the record that still installs its
root (__installedSummaries) at at (at itself, or at followed by the
record's own name); with no at, the one record of the asset outside the
dependency tree. With no such record, the record an uninstall of the asset
left there to place the dependencies something else uses: installing the
asset again writes that record again, and the dependencies it still places
are the releases the world runs. Nil when the world holds neither.
Parameters
summariesany(optional) — Whatinstall.summariesanswers.rootGuidstring— The asset the install was asked for.atstring(optional) — The destination the install was asked for, or nil.
Returns any — The summary of the record, or nil.
worldVcs.__priorInstallOf({}, "g", nil)
typed/builtin//modules/world_vcs/M/__publishedPathSet
M.__publishedPathSet() -> { [string]: boolean }?
What a push publishes, as a set of paths: every path the branch head's tree holds, every folder such a path lies in, and the path itself. A world with no commit yet publishes nothing. Answers nil when the history cannot be read.
Returns { [string]: boolean }? — A set keyed by path, or nil.
local published = worldVcs.__publishedPathSet()
typed/builtin//modules/world_vcs/M/__pullMerge
M.__pullMerge(ops: PullMergeOps) -> (string, string)
How git pull merges a fetched commit into the session branch:
nothing when the session branch already holds it (read before anything
is moved, so a tree with uncommitted changes is not refused for it), else
fast-forward when the branch is strictly behind (unless noFf), else a
merge commit (refused under ffOnly).
Parameters
opsPullMergeOps— APullMergeOps.
Returns (string, string) — up_to_date, fast_forward, merged (with the merge commit id) or refused (with the reason).
worldVcs.__pullMerge({ ffOnly = false, noFf = false, fastForward = function() return true, "ok" end, inHistory = function() return false end, merge = function() return true, "ok", "M" end })
typed/builtin//modules/world_vcs/M/__pullPlan
M.__pullPlan(rows: { any }, assets: { any }, rootGuid: string, rootPath: string?) -> PullPlan
How a pull of one install lands its closure: the install's root row
(__installRootRow), where each closure asset is placed and where the world
already holds one (computeClosurePlacement, with the root kept at its
row's path), and the pulled row the pull acts on for each asset
(__installRowsByGuid).
Parameters
rows{ any }— The world's pulled rows.assets{ any }— The closure entries at the version the pull lands.rootGuidstring— The root asset's guid.rootPathstring(optional) — The install root's path the pull was asked for, or nil.
Returns PullPlan — The PullPlan.
worldVcs.__pullPlan({}, {}, "g", nil)
typed/builtin//modules/world_vcs/M/__pulledRowsAhead
M.__pulledRowsAhead(rows: { any }) -> { any }
The pulled rows (an install an earlier engine landed one row per file) whose content left the version they pin. A row that stands for a deletion holds no content, so it is none of them.
Parameters
rows{ any }— The pulled manifest rows.
Returns { any } — The rows ahead of their version, in the order given.
worldVcs.__pulledRowsAhead({})
typed/builtin//modules/world_vcs/M/__pushBasisCommit
M.__pushBasisCommit(rows: { any }, head: string) -> string?
The commit whose ZeroMind manifest the squash push of head builds
on: the nearest commit ZeroMind holds on the walk from head along each
commit's first parent, head itself when ZeroMind holds it. A merged-in
commit is no step of the walk, since the push states its rows against
the first parent's.
Parameters
rows{ any }— The commits a__spacetime_vcs.logread fromheadanswers.headstring— The commit the push releases.
Returns string? — The commit's id, or nil when ZeroMind holds none of the walk.
worldVcs.__pushBasisCommit(rows, head)
typed/builtin//modules/world_vcs/M/__pushRefusal
M.__pushRefusal(msg: string, branch: string?) -> string
A refused push's text as world.push raises it
(M.__pushRefusalOver), over the world's pulled rows, committed or not,
and each asset's line in ZeroMind.
Parameters
msgstring— The refused push's text.branchstring(optional) — The branch the refused push publishes.
Returns string — The text, with the paragraphs for the installs and the branches the refusal reached.
worldVcs.__pushRefusal(msg, world.branch())
typed/builtin//modules/world_vcs/M/__pushRefusalOver
M.__pushRefusalOver(msg: string, branch: string?, readRows: () -> { any }, readPage: (string, string?) -> any, pace: (() -> ())?) -> string
A refused push's text, followed by what the refusal asks of the
installs the world holds as one row per file (M.__withInstallRefusals
over readRows) and of the release versions a branch other than main
holds (M.__withBranchReleaseRefusals over readPage). An asset the
install paragraph names takes no version advice from the branch
paragraph.
Parameters
msgstring— The refused push's text.branchstring(optional) — The branch the refused push publishes, or nil when unknown.readRows() -> { any }— Reads the world's pulled rows.readPage(string, string?) -> any— Reads one page of an asset's versions:(guid, cursor) -> page.pace(() -> ())(optional) — Called between rows; nil runs straight through.
Returns string — The text, with the paragraphs for the installs and the branches the refusal reached.
worldVcs.__pushRefusalOver(msg, "next", function() return {} end, function(guid, cursor) return { versions = {} } end)
typed/builtin//modules/world_vcs/M/__rankAfter
M.__rankAfter(id: string) -> string
The rank a release takes to stand just after the release stated under
id: above it, and below every later version id.
Parameters
idstring— The version id of the release it follows.
Returns string — The rank.
worldVcs.__rankAfter("01M7HAHH1RVEW20880MSGR49HX")
typed/builtin//modules/world_vcs/M/__readAheadRows
M.__readAheadRows() -> { any }
Every row of the world ahead of the content it was installed from: the
pulled rows whose content left the version they pin
(M.__pulledRowsAhead), and the changes to the content of the record
installs (M.__installChangeRows).
Returns { any } — The rows, each in the shape of a pulled row.
worldVcs.__readAheadRows()
typed/builtin//modules/world_vcs/M/__readClosureItems
M.__readClosureItems(items: { any }, keys: { [number]: string }, reads: VersionBatchReads) -> ({ [number]: boolean }, { [number]: string }, { [number]: boolean })
Closure batch items (POST /v1/closures) read through the read
session open now, in as few requests as hold them
(M.__CLOSURE_BATCH_ITEMS to a request) and at least as many as are made
at once (M.__CLOSURE_BATCHES_AT_ONCE), that many requests in flight at a
time: an item a read of the session answered earlier
(keys[i], as M.__memoRead keys it) is answered from it, and each
other item is read from ZeroMind, its answer left to the caller to keep
(ReadMemo.keep). An item refused for a reason a later attempt can
outlive (__transientFailure), or in a request refused for one, is asked
again after each wait of M.__READ_WAITS; the items of a request refused
whole are asked again in requests of at most half as many items, so a
request ZeroMind stopped at its deadline is read in requests that finish
within it. Past the last wait, or once the read session open now has
spent more than M.__READ_RETRY_BOUND_S seconds on such failures
(__countFailedReads), such an item answers its failure at once, naming
how often it was read and for how long (__failedReadReason).
Parameters
items{ any }— The batch items.keys{ [number]: string }— The read session key of each item by its index, nil for one read each time it is asked for.readsVersionBatchReads— How ZeroMind is read (VersionBatchReads).
Returns ({ [number]: boolean }, { [number]: string }, { [number]: boolean }) — Whether each item was read, its closure in parts or the reason, and whether it was read from ZeroMind by this call, all by the item's index.
local oks, bodies, fresh = worldVcs.__readClosureItems(items, keys, reads)
typed/builtin//modules/world_vcs/M/__readDependencyCopy
M.__readDependencyCopy(path: string) -> DependencyCopyRead?
What the world holds at path for __retiredCopies: the version the
asset there holds, whether the world holds rows of its own at or under
it, and every asset at and under it with its version.
Parameters
pathstring— The copy's root.
Returns DependencyCopyRead? — The read, or nil when no asset stands there.
worldVcs.__readDependencyCopy("/zero/source/deps/w/kit.package")
typed/builtin//modules/world_vcs/M/__readDifferingTables
M.__readDifferingTables(caller: string, under: string?) -> { DifferingTable }
The rows of the world's own content whose live reference table differs
from the one the branch head holds, read from the session's kept set:
every one, or the ones at and beneath under. An empty list when the
session holds no such read.
Parameters
callerstring— The verb reading them, named when the read fails.understring(optional) — An engine-canonical path to narrow the read to, nil for the whole branch.
Returns { DifferingTable } — The rows, sorted by path.
worldVcs.__readDifferingTables("world.commit")
typed/builtin//modules/world_vcs/M/__readInstallChanges
M.__readInstallChanges() -> { any }?
What install.changes answers on this engine, or nil when it cannot
answer.
Returns { any }? — The rows, or nil.
worldVcs.__readInstallChanges()
typed/builtin//modules/world_vcs/M/__readInstallClosure
M.__readInstallClosure(rootGuid: string, ref: string) -> (boolean, string, any?, string?)
The install closure of rootGuid at ref (__installClosure), read
from the ZeroMind this engine is connected to.
Parameters
rootGuidstring— The asset whose closure is read.refstring— The ref it is read at; empty reads the version the asset's world ships.
Returns (boolean, string, any?, string?) — As __installClosure.
worldVcs.__readInstallClosure("5f6bfcfb-2258-47d9-8f1e-8f684f85e1f3", "")
typed/builtin//modules/world_vcs/M/__readInstallRecords
M.__readInstallRecords() -> { string }?
The destination of every install the world holds a record row for,
as install.records answers on this engine, or nil when it cannot answer.
Returns { string }? — The destinations, or nil.
worldVcs.__readInstallRecords()
typed/builtin//modules/world_vcs/M/__readLiveStageStatus
M.__readLiveStageStatus(stageName: string) -> LiveStageStatus
The working tree and the calling area, read once: the rows the working
tree holds an edit for, the rows the area holds with their bytes, the rows
it holds the references of alone (referencesOnly), this engine's own
writes on their way to the manifest as __statusWithOwnWrites reads them
with the status (ownWrites), and the live ignore set.
Parameters
stageNamestring— The calling staging area.
Returns LiveStageStatus — The LiveStageStatus the commit's staging decisions read.
worldVcs.__readLiveStageStatus("default")
typed/builtin//modules/world_vcs/M/__readPulledRowsPaged
M.__readPulledRowsPaged(pace: () -> ()) -> { any }
Every pulled manifest row of the working copy, read a page at a time so no read or decode holds a frame for the whole set.
Parameters
pace() -> ()— Called between rows.
Returns { any } — The rows, in path order.
local rows = worldVcs.__readPulledRowsPaged(function() end)
typed/builtin//modules/world_vcs/M/__readRetrying
M.__readRetrying(read: () -> (boolean, string), wait: (number) -> ()) -> (boolean, string)
Make a ZeroMind read, and make it again after each wait of
M.__READ_WAITS while it fails for a reason a later attempt can outlive
(__transientFailure) and the read session open now has not spent more
than M.__READ_RETRY_BOUND_S seconds on such failures
(__countFailedReads). Answers what the last attempt answered; a read
made no more for such a failure answers its reason with how often it was
made and for how long (__failedReadReason).
Parameters
read() -> (boolean, string)— Makes the read once, answering whether it succeeded and its body or reason.wait(number) -> ()— Waits a number of seconds.
Returns (boolean, string) — Whether the read succeeded, and its body or its last reason.
local ok, body = worldVcs.__readRetrying(read, task.waitRealtime)
typed/builtin//modules/world_vcs/M/__readVersionAt
M.__readVersionAt(guid: string, checksum: string, depth: number, commit: string?, reads: VersionReads) -> any
One asset at one version, read from ZeroMind out to depth edges, as
the decoded closure. The version is read by its checksum. ZeroMind serves
a version by its checksum alone when the asset's own world holds it; a
version only another world holds (a copy of the asset that world keeps
under the asset's guid) answers VERSION_NOT_FOUND there, and is read at
commit, the commit the install reached the asset through, which holds
it. The asset that read answers must be at checksum. Raises naming the
asset, the version and why, when neither read answers that version.
Parameters
guidstring— The asset.checksumstring— The version's checksum.depthnumber— The edges from the asset the read reaches.commitstring(optional) — The commit the install reached this version through, or nil.readsVersionReads— How ZeroMind is read (VersionReads).
Returns any — The decoded closure, the asset at checksum among its assets.
worldVcs.__readVersionAt(guid, checksum, 1, commit, reads)
typed/builtin//modules/world_vcs/M/__readVersionsAt
M.__readVersionsAt(asks: { VersionAsk }, reads: VersionBatchReads) -> ({ [number]: any }, { [number]: string })
Several versions of assets read from ZeroMind together, as the
decoded closures, in the closure batch requests M.__readClosureItems
makes: each out to depth edges (one when absent), or with own out to
the depth that holds its own files (own_files; the closure names that
depth in own_files_depth). Each version is read by its checksum; a
version ZeroMind holds no version of by its checksum (VERSION_NOT_FOUND)
is read at commit, the commit the install reached it through, and the
asset that read answers must be at checksum. A version that cannot be
read is refused with the reason __readVersionAt raises for it; a refused
version leaves the others read. The read session keeps each closure read,
under the key the single read of it keeps (M.__memoRead), except a read
out to a number of edges that the server's asset cap cut short
(M.__closureAtAssetCap): the single read of it reads past the cap in
pages.
Parameters
asks{ VersionAsk }— The versions (VersionAsk):{ guid, checksum, depth?, own?, commit? }.readsVersionBatchReads— How ZeroMind is read (VersionBatchReads).
Returns ({ [number]: any }, { [number]: string }) — Each decoded closure, and the reason each version that cannot be read was refused, both by the version's index.
local got, failed = worldVcs.__readVersionsAt({ { guid = g, checksum = c, own = true } }, reads)
typed/builtin//modules/world_vcs/M/__rebaseStageWith
M.__rebaseStageWith(stageId: string, ops: RebaseOps) -> string
Rebase a staging area onto the branch head there is now: the derived outputs it reserves are read, it is closed, an area is opened against the current head, the paths the old one held are staged onto that, and the outputs the old one reserved are reserved on it again and computed from what it holds. The commit of the new area then records every derived output the old one would have, each with the inputs it lands.
Parameters
stageIdstring— The row id of the area being rebased.opsRebaseOps— The calls the rebase makes:reservationsreads the area's reservations,closedrops it,openopens the new one and answers its row id,stagestages the held paths onto it,carryreserves the old reservations on it. Each raises its own refusal.
Returns string — The row id of the area opened.
worldVcs.__rebaseStageWith("41", ops) --> "42"
typed/builtin//modules/world_vcs/M/__reconcileDecision
M.__reconcileDecision(base: string, ours: string, theirs: string) -> string
Decide the three-way reconcile action for one pulled-asset row
from its three content checksums (base = last-known origin checksum,
ours = current local checksum, theirs = latest upstream checksum).
Pure — no I/O, no VCS calls. world.pullAsset drives its reconcile
loop off this decision per row.
Parameters
basestring— The origin checksum recorded the last time this row was pulled or advanced.oursstring— This world's current local checksum for the row.theirsstring— The latest upstream checksum.
Returns string — One of "noop" (upstream unchanged, whatever the local side holds — nothing to do), "fast_forward" (untouched locally and upstream moved — take theirs), "converged" (both sides already match — advance provenance only), or "merge" (all three differ — three-way merge required).
worldVcs.__reconcileDecision("A", "A", "B") --> "fast_forward"
worldVcs.__reconcileDecision("A", "A", "A") --> "noop"
typed/builtin//modules/world_vcs/M/__recordDependencyAt
M.__recordDependencyAt(deps: { InstalledRoot }, guid: string, at: string?) -> InstalledRoot?
The dependency an install record places that an install of guid
asked to land at at stands for: one of deps (__recordDependencyRoots)
of that asset whose path is at, or at followed by the dependency's own
name. Nil when at names none.
Parameters
deps{ InstalledRoot }— The dependencies the install records place.guidstring— The asset the install was asked for.atstring(optional) — The destination the install was asked for, or nil.
Returns InstalledRoot? — The dependency, or nil.
worldVcs.__recordDependencyAt({}, "g", "/zero/source/deps/w")
typed/builtin//modules/world_vcs/M/__recordDependencyRoots
M.__recordDependencyRoots(summaries: any?) -> { InstalledRoot }
The dependencies the install records place, each as one unit the
update check compares with the newest release at the dependency's own
origin world: one InstalledRoot per dependency of each record that
still installs its root (__installedSummaries), at the path the record
places it, with the release the record states for it and the root of the
record (placed_by). A dependency the record keeps in a recorded
version's folder (deps/<world>/versions/<checksum>/<path>) is one
when a record places another release of the same asset at the path that
folder stands beside (deps/<world>/<path>): moving it lifts the newer
release into that record, so the install's files run it. Left out: a
dependency in a recorded version's folder no record places the asset
beside (a version of a library this world mounts, which an install keeps
as its files name it), a dependency the record names deleted, one
placed inside another dependency of the record (a member of a package,
which moves with it), and a path an install root or an earlier record's
dependency stands at.
Parameters
summariesany(optional) — Whatinstall.summariesanswers, each with itsdeps.
Returns { InstalledRoot } — The InstalledRoot list, sorted by path.
worldVcs.__recordDependencyRoots({})
typed/builtin//modules/world_vcs/M/__recordFileCount
M.__recordFileCount(root: string) -> number
How many files and folders the install record at root lists, the
dependencies it placed included; 0 when the world holds no record there.
Parameters
rootstring— The install's destination.
Returns number — The count.
worldVcs.__recordFileCount("/zero/source/none.package")
typed/builtin//modules/world_vcs/M/__recordInstallInfos
M.__recordInstallInfos(summaries: any?, changed: { [string]: number }) -> { InstallInfo }
The installs that stand as one record row, as world.installs() lists
them: one InstallInfo per record that still installs its root
(__installedSummaries).
Parameters
summariesany(optional) — Whatinstall.summariesanswers.changed{ [string]: number }— How many files of each install the world changed or added, by root.
Returns { InstallInfo } — The InstallInfo list, in the order of summaries.
worldVcs.__recordInstallInfos({}, {})
typed/builtin//modules/world_vcs/M/__recordInstallRows
M.__recordInstallRows(record: any?, dest: string, changes: { any }) -> { any }
The files of an install that stands as one record, each in the shape of
the pulled row an install an earlier engine landed holds for it: every file
and folder the record lists for its destination and for each dependency it
places, at the version the record states (origin_checksum), holding the
bytes the world changed it to (checksum) where changes names it, and
marked record_install: an update of a record merges the world's edit
of a file with the new version (M.__mergeRowsOverRecord).
Parameters
recordany(optional) — The record document (zero/asset-pull/v2).deststring— The install's destination.changes{ any }— The install's changes, as__installChangeRowsstates them.
Returns { any } — The rows, in the record's order.
worldVcs.__recordInstallRows({ listing = { { path = "", asset_guid = "g", checksum = "c", is_composite = true } }, deps = {} }, "/zero/source/kit.package", {})
typed/builtin//modules/world_vcs/M/__recordLeaves
M.__recordLeaves(record: { [string]: any }, dest: string) -> { [string]: string }
The leaves an install record states, by the path each stands at: the checksum of every file of the listing beneath the destination and of each placed dependency's listing beneath where it stands, a folder left out.
Parameters
record{ [string]: any }— The record document.deststring— Where the install stands.
Returns { [string]: string } — The checksums, by path.
worldVcs.__recordLeaves({ listing = { { path = "a.luau", checksum = "c", is_composite = false } }, deps = {} }, "/zero/source/a.module")
typed/builtin//modules/world_vcs/M/__recordPaths
M.__recordPaths(record: { [string]: any }, dest: string, pace: (() -> ())?) -> { [string]: boolean }
Every path an install record states its files and folders at: the listing beneath the destination and each placed dependency's listing beneath where it stands, the paths the record names as removed by the user (and everything beneath them) left out.
Parameters
record{ [string]: any }— The record document.deststring— Where the install stands.pace(() -> ())(optional) — Called between entries.
Returns { [string]: boolean } — The paths, as a set.
worldVcs.__recordPaths({ listing = { { path = "" } }, deps = {} }, "/zero/source/a.module")
typed/builtin//modules/world_vcs/M/__recordReviewRows
M.__recordReviewRows(root: InstalledRoot, worldRows: { any }) -> { any }
The rows a review of the install at root, which stands as one
record, reads: the record's files (__recordInstallRows), then the
world's pulled rows. A dependency an install record places
(placed_by) reads the record of that install.
Parameters
rootInstalledRoot— The install, as__recordRootsor__recordDependencyRootsstates it.worldRows{ any }— The world's pulled rows.
Returns { any } — The rows.
worldVcs.__recordReviewRows(root, {})
typed/builtin//modules/world_vcs/M/__recordRoots
M.__recordRoots(summaries: any?) -> { InstalledRoot }
The installs that stand as one record row, as the update check reads an install root: the destination, the asset, the version the record states and the ref it was installed at.
Parameters
summariesany(optional) — Whatinstall.summariesanswers.
Returns { InstalledRoot } — The InstalledRoot list, sorted by path.
worldVcs.__recordRoots({})
typed/builtin//modules/world_vcs/M/__recordTablesByPath
M.__recordTablesByPath(record: { [string]: any }, dest: string, pace: (() -> ())?) -> { [string]: string }
The reference table an install record states for each of its files, by the path the file stands at: the listing beneath the destination and each placed dependency's listing beneath where it stands. A file the record states no table for is left out.
Parameters
record{ [string]: any }— The record document.deststring— Where the install stands.pace(() -> ())(optional) — Called between entries.
Returns { [string]: string } — The tables, by path.
worldVcs.__recordTablesByPath({ listing = { { path = "a.luau", refs_json = "{}" } }, deps = {} }, "/zero/source/a.module")
typed/builtin//modules/world_vcs/M/__recordsBesideHeld
M.__recordsBesideHeld(summaries: any?, reach: (guid: string) -> HeldCopy?) -> { [string]: { string } }
The dependencies each install record keeps in a recorded version's
folder while the world holds another copy of the asset where its name
reaches (reach), as __releasesBesideHeld names them for an install:
a line per dependency, by the root of the install that places it. A
dependency the record names deleted is left out.
Parameters
summariesany(optional) — Whatinstall.summariesanswers, each with itsdeps.reach(guid: string) -> HeldCopy?— The copy of an asset a name reaches in the world, by its guid, or nil when the world holds none.
Returns { [string]: { string } } — The lines of each install, sorted, by the install's root; an install with none is absent.
worldVcs.__recordsBesideHeld({}, function(_) return nil end)
typed/builtin//modules/world_vcs/M/__redirectRefsTable
M.__redirectRefsTable(refsJson: string, redirect: { [string]: string }, moveTo: { [string]: any }, commitRecords: { [string]: any }, versionIds: { [string]: string }) -> string
A reference table with every site that names a release an install left
out naming the release that stands for it. An asset entry naming a version
redirect maps names the version it maps to, with that version's
asset_version_id (none when the closure states none), merged with an
entry the table already holds for that version. A site of a world entry
whose guid the entry's commit holds at a version redirect maps moves to a
world entry at the commit the standing release was planned at (moveTo)
when that commit's record states the guid at the standing version and
every site of the entry moves there, since a table names a world in one
entry; otherwise it moves to an asset entry of the standing version. The
commit records are only read, and the rest of the table stays as written.
Parameters
refsJsonstring— The table's JSON text.redirect{ [string]: string }— The version standing for each release left out, byguid@checksum.moveTo{ [string]: any }— The entry of the standing release, by the same key.commitRecords{ [string]: any }— The versions each commit the install read holds, byworld@commit.versionIds{ [string]: string }— Theasset_version_idof each version the closure lists, byguid@checksum.
Returns string — The table's JSON text, refsJson itself when it names no release left out.
worldVcs.__redirectRefsTable(refs, { ["g@old"] = "new" }, {}, {}, {})
typed/builtin//modules/world_vcs/M/__refHasVersionShape
M.__refHasVersionShape(ref: string?) -> boolean
Whether a recorded install ref has the shape of a fixed version of its
origin (a commit id, a version checksum or a version id). Only the origin
says whether a ref of that shape is a version or a branch named like one
(__refKindAtOrigin).
Parameters
refstring(optional) — The recorded ref, or nil.
Returns boolean — True for a ref shaped like a version.
worldVcs.__refHasVersionShape("0123456789abcdef")
typed/builtin//modules/world_vcs/M/__refKindAtOrigin
M.__refKindAtOrigin(resolve: (ref: string) -> (boolean, string), ref: string, worldReadable: () -> (boolean, string)) -> string
What the origin world says a ref shaped like a fixed version is: branch
when the origin resolves it as a named ref to a commit other than itself,
pin when it names exactly the commit it resolves to, or when the world
answers and holds no such ref (a version checksum or version id). The
origin's answer is read from the phrase returned HTTP 404 in the resolve
failure text; a failure whose text carries no such status, and a 404 from a
world that cannot be read either, raise with the origin's text.
Parameters
resolve(ref: string) -> (boolean, string)— Resolves a ref in the origin world: ok and the response body, or not ok and the failure text.refstring— The recorded ref.worldReadable() -> (boolean, string)— Whether the origin world answers at all: ok, or not ok and the failure text. Asked only after the ref itself came back 404.
Returns string — branch or pin.
worldVcs.__refKindAtOrigin(function(ref) return false, "ZeroMind GET u returned HTTP 404: not found" end, "0123456789abcdef", function() return true, "{}" end)
typed/builtin//modules/world_vcs/M/__referenceHoldsThere
M.__referenceHoldsThere(literal: string, fileHere: string, assetHere: string, fileThere: string, assetThere: string) -> boolean
Whether a reference names, in the world a file is sent to, the asset it
names in this one. A reference by a package's name (~pkg.name, or
<package>.name naming a member of the package whose folder is
<package>.package) names the same asset there when both worlds hold the
asset at the same path below a folder of that name, wherever the file
stands in either: the name reaches the package from every file of a world.
A reference anchored at the file (a path relative to it, .name) or at
its own package (~.name) reads the folder it is anchored at and the path
below it; it names the same asset there when the file and the asset each
stand below that folder's counterpart at the same path, the counterpart
carrying the folder's own name. An absolute path names the same asset
there when the target holds the asset at that path or the path stands
below it (a file of a folder asset). Every other spelling (@root::, an
identity in the world root, a library) is answered false. A name reads a
folder asset's entry file (init.luau) as the folder that holds it, the
identity the entry file carries. Each path is a VFS path or a path
relative to a source root.
Parameters
literalstring— The reference as the file spells it.fileHerestring— The file's path in this world.assetHerestring— The path of the asset it names in this world.fileTherestring— The path the file lands at in the target world.assetTherestring— The path the target world holds the asset at.
Returns boolean — True when the reference names that asset in the target.
worldVcs.__referenceHoldsThere("~.logic", "/source/deps/w/Kit.package/pool.module/init.luau", "/source/deps/w/Kit.package/logic.module", "Kit.package/pool.module/init.luau", "Kit.package/logic.module")
typed/builtin//modules/world_vcs/M/__referenceMoveCauses
M.__referenceMoveCauses(row: DifferingTable, libraries: { string }, holds: (string) -> boolean, ops: ReferenceOps) -> { ReferenceMove }
What moved the references of a file whose reference table differs from
the branch head's, among a set of changes. A world entry both tables hold
at different commits moved with the pin of that library, when its marker
is among the changes. Each asset entry both tables pin at different
versions is followed to its asset: one under
/zero/source/libs/@<name>/ moved with the pin of that library, when its
marker is among the changes; an asset of the world moved itself, when it
is among the changes. A dependency whose asset the world does not hold is
read through the head's table: it moved with the pin of a library among
the changes that the table names.
Parameters
rowDifferingTable— The file, with its live and head tables.libraries{ string }— The libraries whose pin marker is among the changes, with their@.holds(string) -> boolean— Whether an asset path is among the changes.opsReferenceOps— What the check reads beyond the working tree.
Returns { ReferenceMove } — The changes, each named once, libraries first.
worldVcs.__referenceMoveCauses(row, { "@builtin" }, holds, ops)
typed/builtin//modules/world_vcs/M/__referencesMovedDiscardRefusal
M.__referencesMovedDiscardRefusal(path: string, state: DiscardReferenceState, causes: (DifferingTable) -> { ReferenceMove }, headPin: (string) -> (string?)) -> string?
The sentence refusing to discard a path whose only difference from the branch head is reference tables. Its bytes are the head's, so a discard could only put back a table naming versions the world no longer runs; the sentence names what moved the references and the undo, which is undoing that change: the library's pin moved back to the commit the branch head pins, or the moved asset reverted. A path with a dirty row at or beneath it, or a staged row that is not one of the differing rows, holds an authored change and is discarded normally.
Parameters
pathstring— The engine-canonical path the call names.stateDiscardReferenceState— The rows and paths the refusal reads.causes(DifferingTable) -> { ReferenceMove }— What moved one differing row's references.headPin(string) -> (string?)— The commit the branch head's marker pins a library at, nil when it pins none.
Returns string? — The refusal text, nil when the path holds an authored change or no table difference.
worldVcs.__referencesMovedDiscardRefusal("/zero/source/a.luau", state, causes, headPin)
typed/builtin//modules/world_vcs/M/__referencesMovedDiscardRefusalFor
M.__referencesMovedDiscardRefusalFor(path: string, stageName: string) -> string?
__referencesMovedDiscardRefusal over the live world. A dirty row at or
beneath the path is an authored change, so the read of the rows whose
table differs is made only when there is none, and only for the path and
what lies beneath it. What moved a row's references is read among the
library markers and the paths the working tree holds a change of.
Parameters
pathstring— The engine-canonical path the call names.stageNamestring— The staging area the call acts on.
Returns string? — The refusal text, nil when the path holds an authored change or no table difference.
worldVcs.__referencesMovedDiscardRefusalFor("/zero/source/a.luau", "default")
typed/builtin//modules/world_vcs/M/__referencesToRecord
M.__referencesToRecord(scope: { string }, differing: { DifferingTable }, status: LiveStageStatus, ops: ReferenceOps) -> { ReferencesRecord }
The files a commit records for their references alone: each file whose
reference table moved with a change the commit holds (the pin marker of a
library, or an asset of the world it pins at another version) and that
the commit leaves out, its bytes changed or not. The commit records the
version of each that the branch head holds, its pins of what the commit
holds advanced to the versions the live table states; every other edit of
the file, another caller's work in progress among them, stays out.
A file the live ignore set matches is recorded when the branch head
holds it: its bytes stay out of every commit, and its table moves with
the pin the commit records, so the commit's tree names the library at
the commit its marker states. Library content (everything under
/zero/source/libs/) is never recorded, nor is a table that differs only
in its install record. Nothing is staged or changed.
Parameters
scope{ string }— The rows the commit freezes with their bytes, engine-canonical.differing{ DifferingTable }— The rows whose live table differs from the head's.statusLiveStageStatus— The working tree and the calling area, read once.opsReferenceOps— What the check reads beyond the working tree.
Returns { ReferencesRecord } — One entry per file, sorted by path.
worldVcs.__referencesToRecord(scope, differing, status, ops)
typed/builtin//modules/world_vcs/M/__refreshAndStageScope
M.__refreshAndStageScope(scope: { string }, refresh: ({ string }) -> ({ string }, { string }), drain: () -> (), liveStatus: () -> LiveStageStatus, stageRows: ({ string }) -> (), holdBack: (string) -> ())
Re-derive the dependency tables of the rows a commit is about to
freeze, and re-stage the ones whose staging carries just that delta.
scope is the whole of what the commit re-derives — the paths the
calling staging area holds, so a row outside it is neither re-derived
nor staged, whoever
else in the world is editing it and however far its own table has
drifted.
Of the candidates refresh reports, a row is staged when staging it
carries JUST the refreshed table: it is HEAD-clean in the shared
working tree, or the calling area already holds it. A row with an
unstaged byte edit whose table also moved goes to holdBack instead,
so a commit stays git add semantics rather than git commit -a.
A row the live ignore set matches is skipped — an ignored source
publishes nothing, so its table gates nothing.
Parameters
scope{ string }— The rows this commit freezes, engine-canonical.refresh({ string }) -> ({ string }, { string })— Re-derives the tables of the paths it is given, answering the candidates it re-derived and the subset whose table moved. Its answer is narrowed toscopebefore any of it is staged.drain() -> ()— Waits for the re-derived rows to reach the manifest.liveStatus() -> LiveStageStatus— Reads the working tree and the calling area, once, after the drain.stageRows({ string }) -> ()— Stages the rows it is given into the calling area, once for all of them: the staging read and settle a stage makes cost the size of the working set, so the rows go in one call rather than one call per row.holdBack(string) -> ()— Reports a row whose table moved and whose byte edit is the author's to stage.
worldVcs.__refreshAndStageScope(staged, refresh, drain, status, add, warn)
typed/builtin//modules/world_vcs/M/__releaseDescriptorOf
M.__releaseDescriptorOf(folder: string) -> string?
The descriptor a folder asset states its release version in: the file
directly inside the folder named after the folder's suffix, with a .yaml
extension (kit.package states it in kit.package/package.yaml, under
version:), the rule ZeroMind holds a publish's release versions to.
Parameters
folderstring— The folder's path.
Returns string? — The descriptor's path, or nil for a folder whose name has no suffix or no name before it.
worldVcs.__releaseDescriptorOf("/zero/source/kit.package") --> "/zero/source/kit.package/package.yaml"
typed/builtin//modules/world_vcs/M/__releaseOrder
M.__releaseOrder(held: ReleaseOf, asked: ReleaseOf, fetchPage: (cursor: string?) -> any, maxPages: number) -> string
Where the release asked of an asset stands against the release
held on the asset's own line: the versions its owning world published,
read newest first by first appearance, a page at a time. A release is
found by its checksum or its version id, so a release another world's push
stated under a version id of its own is found by its bytes. A release
held whose bytes the line never lists ranks just below the release it
was taken from: the newest the line lists under a version id earlier than
its own. newer when asked ranks above held, older when it ranks
below, same when the two hold the same bytes, and unknown when the
pages read name neither, or name asked below that release while the
line goes on past the last page read (held may be listed further down).
Parameters
heldReleaseOf— The release a world holds.askedReleaseOf— The release it is compared with.fetchPage(cursor: string?) -> any— Reads one page of the line:{ versions = { { version_id, checksum } }, next_cursor }after a cursor (nil for the newest page).maxPagesnumber— The most pages read.
Returns string — newer, older, same or unknown.
worldVcs.__releaseOrder({ checksum = "a", version_id = "02" }, { checksum = "b", version_id = "01" }, function() return { versions = { { version_id = "01", checksum = "b" } } } end, 4)
typed/builtin//modules/world_vcs/M/__releaseRank
M.__releaseRank(entry: any?) -> string
The version id a release ranks at among the releases of its asset an
install weighs: its own (version_id), or, for a release a dependency
move asks for that its owning world's line places after the release the
install held under a later version id, the rank_id the move states,
which ranks it just after that one.
Parameters
entryany(optional) — A closure entry or a placed dependency.
Returns string — The version id it ranks at, "" for none.
worldVcs.__releaseRank({ version_id = "01", rank_id = "02+" })
typed/builtin//modules/world_vcs/M/__releaseSplitFailure
M.__releaseSplitFailure(split: { string }) -> string
The failure an install states for the sources of its content that run two or more releases of one package: state one module of the package registers is invisible to the release its sibling runs, so the install is taken back, naming each source, the package and the copy of each release.
Parameters
split{ string }— The linesinstall.gatelists undersplit.
Returns string — The failure line.
worldVcs.__releaseSplitFailure({ "/zero/source/kit.package/a.luau: package g runs 2 releases: ..." })
typed/builtin//modules/world_vcs/M/__releaseSplits
M.__releaseSplits(assets: { any }, rootGuid: string, commitRecords: { [string]: any }) -> { string }
A line for each asset of another world an install lands at more than
one release, each release loaded on its own: the asset, its world, and for
each release its version and the files of the install whose tables name
it. Empty when every dependency lands at one release
(__oneReleasePerAsset).
Parameters
assets{ any }— The entries the install places.rootGuidstring— The installed asset's guid.commitRecords{ [string]: any }— The versions each commit the install read holds, byworld@commit.
Returns { string } — The lines, sorted.
worldVcs.__releaseSplits(assets, rootGuid, {})
typed/builtin//modules/world_vcs/M/__releaseTakenByBranches
M.__releaseTakenByBranches(message: string, readPage: (string, string?) -> any, branch: string?, installed: { [string]: boolean }?) -> string?
What a publish ZeroMind refused RELEASE_VERSION_TAKEN asks of the
release versions a branch other than main holds. ZeroMind holds a release
version of a package for the first content any branch of its world
publishes under it, a pull request's branch among them, so no other
content takes that number afterwards. Each asset the refusal names
(error.details.taken[]) whose earlier version (earlier_version_id)
the asset's line lists off main (on_main false) is named with the
branch that published it, or as this push's branch's own earlier push.
A push of a branch other than main is named as one whose release numbers
main can no longer release. Either way the paragraph names the
pre-release a branch states next (M.__nextPreRelease of the first
version named), so the release number stays free for main. An entry
whose path is in installed belongs to an install the refusal's
install paragraph names, whose action is no version, and is left out.
Parameters
messagestring— The refused push's text, ZeroMind's JSON envelope included.readPage(string, string?) -> any— Reads one page of an asset's versions:(guid, cursor) -> page.branchstring(optional) — The branch the refused push publishes, or nil when unknown.installed{ [string]: boolean }(optional) — Thepaths of the taken entries placed in an install; nil places none.
Returns string? — The paragraph, or nil when the message is no such refusal, names only installed entries, or names no version published off main for a push of main.
worldVcs.__releaseTakenByBranches(msg, function(guid, cursor) return { versions = {} } end, "next")
typed/builtin//modules/world_vcs/M/__releaseTakenByRowInstalls
M.__releaseTakenByRowInstalls(message: string, rows: { any }, pace: (() -> ())?, placed: { [string]: boolean }?) -> string?
What a publish ZeroMind refused RELEASE_VERSION_TAKEN asks of the
installs it reached. An install an earlier engine landed as one row per
file publishes each change to its files as a new version of the installed
asset (and of each folder asset of it holding the change), which states
the release version the asset's own world wrote in its descriptor, so
ZeroMind refuses the change as a release of that asset at a version it
already published. Brought into one record (world.convertInstalls), the
install publishes the record and the changed files as this world's files,
with no version of the installed asset. Each asset the refusal names
(error.details.taken[], its path relative to /zero/source) is placed
in the install whose rows hold it, grouped as world.convertInstalls
groups them: the root, every row beneath it and the dependencies it placed
under /zero/source/deps/. Each install is named once, with the assets of
it the refusal names and the call that converts it.
Parameters
messagestring— The refused push's text: the transport rendering of ZeroMind's answer, its JSON envelope included.rows{ any }— The world's pulled rows, asM.__readPulledRowsPagedreads them.pace(() -> ())(optional) — Called between rows; nil runs straight through.placed{ [string]: boolean }(optional) — Receives, when the paragraph is returned, thepathof each taken entry it names in an install, asplaced[path] = true; nil receives nothing.
Returns string? — The paragraph naming each install the refusal reached and the call that converts it, or nil when the message is no such refusal or reaches no install held as one row per file.
worldVcs.__releaseTakenByRowInstalls(msg, worldVcs.__readPulledRowsPaged(function() end))
typed/builtin//modules/world_vcs/M/__releaseTakenOf
M.__releaseTakenOf(message: string) -> { any }?
The assets a refusal RELEASE_VERSION_TAKEN names, read from
ZeroMind's JSON envelope in the refused call's text (__jsonObjectAt
from its first {): each entry of error.details.taken (path
relative to the source root of the world that refused, version,
descriptor, asset_guid).
Parameters
messagestring— The refused call's text, its JSON envelope included.
Returns { any }? — The entries, or nil when the text is no such refusal or its envelope names none.
worldVcs.__releaseTakenOf(msg)
typed/builtin//modules/world_vcs/M/__releasesBesideHeld
M.__releasesBesideHeld(assets: { any }, placement: { [string]: string }, satisfied: { [string]: string }, keyOf: (any) -> string, rootGuid: string, commitRecords: { [string]: any }, reach: (guid: string) -> HeldCopy?) -> { string }
A line for each dependency an install lands in a recorded version's
folder (deps/<world>/versions/<checksum>/), or finds held there
already (satisfied), while the world holds
another copy of the asset where its name reaches (reach): the root of
another install, a dependency another install places at its install
path, a copy edited where it stands, or the world's own content. The
install's files then run one release and every file reaching the asset
by name runs the other, each loaded on its own. Each line names the
asset, its world, the release landing with the files of the install
whose tables name it, and the copy its name reaches with its release and
the install placing it. A version of a library the world mounts
(world_pull, or a copy under /zero/source/libs/) is left out.
Parameters
assets{ any }— The entries the install places.placement{ [string]: string }— Where each entry lands, by its placement key (computeClosurePlacement).satisfied{ [string]: string }— Where the world already holds each entry it does not land, by its placement key.keyOf(any) -> string— The placement key of an entry.rootGuidstring— The installed asset's guid.commitRecords{ [string]: any }— The versions each commit the install read holds, byworld@commit.reach(guid: string) -> HeldCopy?— The copy of an asset a name reaches in the world, by its guid, or nil when the world holds none.
Returns { string } — The lines, sorted.
worldVcs.__releasesBesideHeld({}, {}, {}, function(e) return e.asset_guid end, "g", {}, function(_) return nil end)
typed/builtin//modules/world_vcs/M/__releasesInstallRuns
M.__releasesInstallRuns(summaries: any?, prior: any?, holds: ((guid: string, checksum: string, path: string) -> boolean)?, libraries: { [string]: boolean }?) -> { any }
The dependency releases an install's files run, for the install to
keep (__heldReleasesToKeep): every dependency the install's record
still places (one it names deleted is left out); the root of every other
installed record, a release installed at the top level where the asset's
name reaches, that the world holds at the recorded version (holds);
and, for each asset the install's record places no release of, the
dependency another installed record places at that asset's install path
(outside a recorded version's folder). Such a copy is the one a name of
the asset reaches, at the release the world holds, so an install, first
or written again, whose files recorded an older release of it lands no
second copy beside: that copy stands for the older release. A version of
a library this world mounts (libraries, by the origin world a record
states for it) is left out: it lands where the sites of the files naming
it resolve (world_pull), at the version each site names, the way the
first install placed it.
Parameters
summariesany(optional) — Whatinstall.summariesanswers.priorany(optional) — The summary of the install's record (__priorInstallOf), or nil for an install the world holds no record of.holds((guid: string, checksum: string, path: string) -> boolean)(optional) — Whether the world holds an asset at a version at a path, or nil to take every root as held.libraries{ [string]: boolean }(optional) — The worlds of the libraries this world mounts, by guid (WorldPlan.libraryWorlds), or nil for none.
Returns { any } — The dependencies, as install.summaries states them, a root as path, asset_guid, checksum and version_id.
worldVcs.__releasesInstallRuns({}, nil, nil, nil)
typed/builtin//modules/world_vcs/M/__repairNestedRecords
M.__repairNestedRecords(ops: NestedRecordOps) -> { given: { string }, left: { { path: string, reason: string } } }
Give each package back the install record an engine before #21820 wrote as a row of the world's own (#21822). A row standing where a package's install places a record, that is the package's record with an origin commit or visibility stated and nothing else, is written back as the package's record and taken out, so the world reads the files the package carries again. A row holding anything else is the world's own change and is left in place, named with why. The change waits in the working tree for the person to commit. Does nothing outside an editor session whose content is confirmed.
Parameters
opsNestedRecordOps— ANestedRecordOps.
Returns { given: { string }, left: { { path: string, reason: string } } } — { given, left }: the record paths given back, and each row left in place with why.
worldVcs.__repairNestedRecords({ confirmedEditorOpen = function() return false end, rows = function() return {} end, write = function() return true, "" end, settle = function() return true, "" end, handOver = function() end, drop = function() return 0 end, notify = function() end })
typed/builtin//modules/world_vcs/M/__repinAfterMarkers
M.__repinAfterMarkers(paths: { string })
Repin the world's own files against every library marker among
paths once those markers changed (a discard put one back): each file
whose table names the library goes back to the commit the marker states
now, so taking back a pin move takes back its repins with it.
Parameters
paths{ string }— The paths that changed.
worldVcs.__repinAfterMarkers({ "/zero/source/libs/@builtin" })
typed/builtin//modules/world_vcs/M/__repinBehindPins
M.__repinBehindPins(ops: RepinOps) -> { [string]: any }
Bring the world's own files up to the pins the commit records: for each library whose marker the commit records (staged, or as the head holds it), every file whose table names the library at another commit than the marker's is derived again, and every file whose table now names it at another commit than the head's is staged with the commit. A marker the working tree changed and the commit leaves out is the next commit's, and its files are left alone. The commit is refused, naming the files, when a file still names an older commit after the derive, or when one it would stage holds edits the area does not hold.
Parameters
opsRepinOps— The engine operations, or fakes standing in for them.
Returns { [string]: any } — { staged, refused? }: staged lists the files staged, refused the text the commit raises.
worldVcs.__repinBehindPins(ops)
typed/builtin//modules/world_vcs/M/__repinUsers
M.__repinUsers(ops: UpdateLibraryOps, libName: string, commit: string) -> { string }
Repin the files of the world's own behind the library's marker.
Parameters
opsUpdateLibraryOps— The pin move's operations.libNamestring— The library (@builtin).commitstring— The commit the marker states.
Returns { string } — The files whose table moved.
worldVcs.__repinUsers(ops, "@builtin", "c1")
typed/builtin//modules/world_vcs/M/__repinsAheadOfHead
M.__repinsAheadOfHead(name: string, rows: { DifferingTable }, ignored: (string) -> boolean) -> { string }
The world's own files whose table names the library name at another
commit than the table the branch head holds for them, among rows: the
repins the head does not hold yet, the ones a pin move stages
(__pinMoveSources). Library content takes no part.
Parameters
namestring— The library (@builtin).rows{ DifferingTable }— The rows whose live table differs from the head's.ignored(string) -> boolean— Whether the ignore set matches a path.
Returns { string } — The files, sorted.
worldVcs.__repinsAheadOfHead("@builtin", {}, function() return false end) --> {}
typed/builtin//modules/world_vcs/M/__reservedByOtherStages
M.__reservedByOtherStages(rows: any?, nameOf: (key: string?) -> string?) -> { StageReservations }
The reserved_by_other_stages rows of a decoded status payload as
world.vcsStatus answers them: each area with the name the roster gives
the caller it is named after (caller_name, read through nameOf).
Parameters
rowsany(optional) — The payload's rows, or nil.nameOf(key: string?) -> string?— The roster lookup from a caller key to its name.
Returns { StageReservations } — The rows, in the order the payload gives them.
worldVcs.__reservedByOtherStages({ { stage_name = "client:#a", stage_row_id = 4, same_account = true, live = true, total = 2, by_state = { computing = 2 } } }, function() return "a" end)[1].caller_name --> "a"
typed/builtin//modules/world_vcs/M/__resetLeavesRow
M.__resetLeavesRow(row: any?) -> boolean
Whether a hard reset or a Discard All leaves a dirty row as it is: the
row holds a local change of an account other than the calling caller's
(a row whose writer records no account, or acts for the caller's account,
is taken), or it is a bootstrap file of the world (.world_settings,
.world_entrypoint.luau) that no commit holds, which the world needs to
open and so is never removed.
Parameters
rowany(optional) — One dirty row as a status read reports it.
Returns boolean — True for a row the reset leaves in place.
worldVcs.__resetLeavesRow({ path = "/a", same_account = false, dirtied_by_account = "acct-b" }) --> true
typed/builtin//modules/world_vcs/M/__resolveUpdateUnit
M.__resolveUpdateUnit(unit: string, libraries: { string }, roots: { InstalledRoot }) -> UpdateUnit
Which unit a name stands for. @<name> and a /zero/source/libs/@<name>
marker path are libraries; a path is an installed asset, and a path inside
an install stands for its root; a bare name is a library the world pins, an
install root of that name, or else the library @<name>.
Parameters
unitstring— The name a caller gave.libraries{ string }— The library names the world pins (@<name>).roots{ InstalledRoot }— The world's install roots.
Returns UpdateUnit — { kind = "library" | "asset", unit }.
worldVcs.__resolveUpdateUnit("builtin", { "@builtin" }, {})
typed/builtin//modules/world_vcs/M/__restateClearsPath
M.__restateClearsPath(path: string, restated: { string }, dirty: { [string]: boolean }, differing: { string }) -> boolean
Whether deriving the moved tables again took back every change a
discard of path would reach: a table at or beneath the path was derived
again, and nothing at or beneath it is changed or differs from the head
any more.
Parameters
pathstring— The engine-canonical path the discard names.restated{ string }— The paths whose table the restatement changed.dirty{ [string]: boolean }— The paths the working tree holds a change of.differing{ string }— The paths whose table differs from the head's after the restatement.
Returns boolean — Whether the path reads as the head holds it.
worldVcs.__restateClearsPath("/zero/source/.world_settings", restated, dirty, differing)
typed/builtin//modules/world_vcs/M/__restateCommitlessSites
M.__restateCommitlessSites(refsJson: string, restated: { [string]: { [string]: string } }) -> string
A reference table with every site of a world entry that recorded no
commit, whose asset an install brought at a version it chose
(restated, by world guid then asset guid), naming that version as an
asset entry: the version the installed file resolves the site to. A world
entry left with no site is dropped, and the rest of the table stays as
written.
Parameters
refsJsonstring— The table's JSON text.restated{ [string]: { [string]: string } }— The version brought of each asset, by world guid then asset guid.
Returns string — The table's JSON text, refsJson itself when it names no such site.
worldVcs.__restateCommitlessSites(refs, { w = { g = "c" } })
typed/builtin//modules/world_vcs/M/__restateLeftPathClean
M.__restateLeftPathClean(path: string, restated: { string }, stageName: string) -> boolean
__restateClearsPath over the live world.
Parameters
pathstring— The engine-canonical path the discard names.restated{ string }— The paths whose table the restatement changed.stageNamestring— The staging area the call acts on.
Returns boolean — Whether the path reads as the head holds it.
worldVcs.__restateLeftPathClean("/zero/source/.world_settings", restated, "default")
typed/builtin//modules/world_vcs/M/__restateMovedTables
M.__restateMovedTables(caller: string, written: { string }?) -> { string }
__restateMovedTablesWith over the live world: the rows of the
world's own content whose table differs from the branch head's, and the
files whose table pins the content at written, derived again by the
engine and re-published through the outgoing sync.
Parameters
callerstring— The verb asking, named when a read fails.written{ string }(optional) — The paths the operation wrote through the backend, nil when it names none.
Returns { string } — The paths whose table changed, sorted.
worldVcs.__restateMovedTables("world.discardFile")
worldVcs.__restateMovedTables("world.checkoutPaths", { "/zero/source/scenes/main.scene/scene.json" })
typed/builtin//modules/world_vcs/M/__restateMovedTablesWith
M.__restateMovedTablesWith(ops: RestateOps) -> { string }
Derive again the reference table of every file whose table differs
from the branch head's while its bytes do not, and of every file whose
table pins content the operation wrote (ops.dependents), and wait until
the rows of the ones whose table changed read back re-published. A table
records the version of each asset it references as the world held it
when the table was derived; an operation that writes a version of an
asset through the backend (a discard, a hard reset, a checkout of paths
from any revision, a restore from the trash) puts the asset's bytes in
place from the manifest, so the tables that recorded the version it
replaced still name that version. Derived again, each names the version
the world holds now, as it does after a local write of that asset: a
table back at the head's leaves the rows that differ, a tracked file whose
table moves away from the head's joins them, and one whose derive answers
the same table stays as it was.
Parameters
opsRestateOps— The reads and calls the restatement goes through.
Returns { string } — The paths whose table changed, sorted.
worldVcs.__restateMovedTablesWith(ops)
typed/builtin//modules/world_vcs/M/__restoreLandTargets
M.__restoreLandTargets(rows: { any }, under: string) -> { InstallLandTarget }
What a restore that wrote the content at under lands as: each
working-tree row at or beneath it at the version the row records
(checksum_sha256), and under itself standing when the working tree
lists no row there (the restored content is the branch head's).
Parameters
rows{ any }— The working tree's rows, as__spacetime_vcs.statuslists them.understring— The path the restore wrote, engine-canonical.
Returns { InstallLandTarget } — The landing targets, sorted by path.
worldVcs.__restoreLandTargets({ { path = "/zero/source/a.md", checksum_sha256 = string.rep("a", 64) } }, "/zero/source/a.md")
typed/builtin//modules/world_vcs/M/__restoreRows
M.__restoreRows(rows: { any }, write: (row: { [string]: any }) -> (boolean, string)) -> { string }
Write each row back as the world held it (M.__rowRestating), 64
writes in flight at a time.
Parameters
rows{ any }— The rows, as the pulled manifest read them.write(row: { [string]: any }) -> (boolean, string)— Writes one row, answering whether it landed and why not.
Returns { string } — One line per row that could not be written back, naming its path and why.
worldVcs.__restoreRows({}, function() return true, "ok" end)
typed/builtin//modules/world_vcs/M/__retiredCopies
M.__retiredCopies(assets: { any }, rootGuid: string, summaries: any?, priorPath: string?, readCopy: (path: string) -> DependencyCopyRead?) -> { RetiredCopy }
The dependency copies an install takes the place of, so the world
runs one release of each asset whichever order its installs ran in. A
copy another install's record places at its asset's install path
(deps/<world>/<path>, outside a recorded version's folder) is retired
when the install lands that asset, as its root or as a dependency, at a
release newer (by version_id) than the one the copy holds, or as its
root at the release the copy holds, the copy
holds the version its record states with no row of the world's own at or
under it, and the landing release holds every asset of the copy, by
guid. Every record placing the copy is named. The record the install
writes again (priorPath), the record of an install standing inside the
copy (carried by it, it leaves with it) and a version of a library this
world mounts (world_pull) retire nothing.
Parameters
assets{ any }— The entries the install places, after__oneReleasePerAsset.rootGuidstring— The installed asset's guid.summariesany(optional) — Whatinstall.summariesanswers.priorPathstring(optional) — The destination of the record the install writes again, or nil.readCopy(path: string) -> DependencyCopyRead?— What the world holds at a path, or nil when it holds no asset there.
Returns { RetiredCopy } — The copies, sorted by path.
worldVcs.__retiredCopies({}, "g", {}, nil, function(_) return nil end)
typed/builtin//modules/world_vcs/M/__retiredLines
M.__retiredLines(retired: { RetiredCopy }) -> { string }
A line for each copy an install retires (__retiredCopies): the
copy, the release it held, the installs whose records placed it and the
release that takes its place.
Parameters
retired{ RetiredCopy }— The copies.
Returns { string } — The lines, in the order given.
worldVcs.__retiredLines({})
typed/builtin//modules/world_vcs/M/__reviewScope
M.__reviewScope(installed: InstalledRoot, rows: { any }, toAssets: { any }, to: string) -> ReviewScope
What a review of an install lists beside the files of its root. The
dependencies the install places at an older release than the closure the
update moves to names (__dependencyMoves) are moved where the install
holds them, whether or not the root's own version moves too, so the review
names their files there, the ones the new release drops among them. For a
root whose own version stands, the review is held to those dependencies'
origin paths; a row a previous update left conflicted at or beneath the
root opens it to the whole install, and with neither the root is current.
Parameters
installedInstalledRoot— The install root, as__recordRootsstates it.rows{ any }— The rows the review reads.toAssets{ any }— The closure entries at the version the update moves to.tostring— The root's version in that closure.
Returns ReviewScope — { moves, within, current }.
worldVcs.__reviewScope({ path = "/zero/source/a.package", guid = "g", display_name = "a.package", version = "v1" }, {}, {}, "v1")
typed/builtin//modules/world_vcs/M/__reviewUpdate
M.__reviewUpdate(unit: string, opts: ReviewUpdateOpts, ops: ReviewUpdateOps?) -> UpdateReview
Review one unit's update against the open world (world.reviewUpdate).
The unit is resolved over the roots the update check compares
(__updateCheckRoots) by __resolveUpdateUnit, the lookup world.update
takes, so every unit world.checkUpdates lists reviews: a library, an
install an earlier engine landed as one row per file, and an install that
stands as one record.
Parameters
unitstring— The unit's name.optsReviewUpdateOpts—ReviewUpdateOpts.opsReviewUpdateOps(optional) — What the review reads and runs; the open world's when omitted.
Returns UpdateReview — The UpdateReview.
worldVcs.__reviewUpdate("@builtin", {})
typed/builtin//modules/world_vcs/M/__rootDestination
M.__rootDestination(entry: any?, rootGuid: string, at: string?, taken: ((path: string) -> boolean)?) -> string
The path an install places the root of a closure at. at is the
destination directory and the root keeps its own name (its display name,
category suffix included), so at = "/source/combat" lands
sea.material at /zero/source/combat/sea.material. With no at the root
lands where its source world holds it (M.__originRootPath), so
paintedValley/sky/sky.module lands at
/zero/source/paintedValley/sky/sky.module and keeps its name
paintedValley.sky.sky; a root whose source path is no such place, or
whose source path holds another asset in this world (taken), lands in
/zero/source. An at that already ends with the root's own folder name
is the whole destination.
Parameters
entryany(optional) — The closure entry of the root.rootGuidstring— The root's guid, the name of a root whose entry states none.atstring(optional) — The destination directory the install was asked for, or nil.taken((path: string) -> boolean)(optional) — Whether this world holds another asset at a path; nil reads every path as free.
Returns string — The root's engine-canonical destination path.
worldVcs.__rootDestination({ display_name = "sea.material" }, "g", "/source/combat")
typed/builtin//modules/world_vcs/M/__routeToTargets
M.__routeToTargets(rows: { any }, targets: { string }?, openOwn: ((any) -> boolean)?) -> { any }
The ahead rows rows routed to the worlds a contribution names
(targets): a row of a dependency an install placed whose own world
(origin_world_guid, the world the dependency was published from) a
target names goes to that world, in place of the world of the install
that placed it. With no target, such a row goes to its own world while
its dependency's root keeps a pull request open there (openOwn), so
the root keeps its one pull request. A routed row is answered as a copy
carrying own_world = true and no install_origin_world_guid, so
__contributionOrigin names its own world and it belongs to the unit of
its dependency's root (world_vcs.engagement's unitHolds). Every
other row is answered as it is.
Parameters
rows{ any }— The ahead rows (__readAheadRows).targets{ string }(optional) — The world guids the contribution names, or nil.openOwn((any) -> boolean)(optional) — Optional: whether a row's dependency root keeps a pull request open in its own world (__openOwnLink), asked once per root and world. Without it, only a target routes a row.
Returns { any } — The rows, in the order given.
worldVcs.__routeToTargets(worldVcs.__readAheadRows(), { depWorldGuid })
worldVcs.__routeToTargets(worldVcs.__readAheadRows(), nil, worldVcs.__openOwnLink)
typed/builtin//modules/world_vcs/M/__rowDependencies
M.__rowDependencies(rows: { any }) -> { any }
What the pulled rows under /zero/source/deps hold as dependencies, in
the shape an install record states them, for the installs an earlier
engine landed as one row per file.
Parameters
rows{ any }— The pulled manifest rows.
Returns { any } — { path, asset_guid, checksum, version_id } per row with an origin.
worldVcs.__rowDependencies({})
typed/builtin//modules/world_vcs/M/__rowHoldsInstalledVersion
M.__rowHoldsInstalledVersion(row: any?) -> boolean
Whether a pulled row holds the content of the version it was installed at: a folder row, or a file row whose content is its origin's, with no conflict on it and no override over it.
Parameters
rowany(optional) — A pulled manifest row.
Returns boolean — True when the row holds the installed version.
worldVcs.__rowHoldsInstalledVersion({ path = "/zero/source/a.luau", checksum = "c", origin_checksum = "c", blob_sha256 = "c" })
typed/builtin//modules/world_vcs/M/__rowIsDeletion
M.__rowIsDeletion(row: any?) -> boolean
Whether a pulled row stands for a deletion the working tree holds: the content at its path left the world (an update or a conversion took the row out, or the user deleted the file) and the next commit removes the path. Such a row keeps the origin and the reference table its content had, so it reads as the row it was until it is told apart here.
Parameters
rowany(optional) — A pulled manifest row.
Returns boolean — True for a deletion.
worldVcs.__rowIsDeletion({ path = "/zero/source/a.luau", kind = "tombstone" })
typed/builtin//modules/world_vcs/M/__rowRestating
M.__rowRestating(held: { [string]: any }) -> { [string]: any }
The pulled row held restated as the row an install writes, so writing
it puts that row back as it stood.
Parameters
held{ [string]: any }— A pulled row, as the pulled manifest read it.
Returns { [string]: any } — The row an install writes.
worldVcs.__rowRestating({ path = "/zero/source/a.luau", asset_guid = "g", checksum = "c" })
typed/builtin//modules/world_vcs/M/__rowSwapFor
M.__rowSwapFor(entries: { InstallEntry }, rowByPath: { [string]: any }, rootPath: string, pace: (() -> ())?) -> RowSwap?
The rows an install that stands as one pulled row per file (an earlier engine's install) is taken out of the world by when one record takes its place: every row of the install the user did not change, the root's own row last. A file changed since the install stays a row, and so does a row another install shares. A row that stands for a deletion (one an earlier run of the same update took out before it was cut short included) is neither: the record lays the version's file at its path.
Parameters
entries{ InstallEntry }— Every install among the pulled rows, as__groupInstallsstates them.rowByPath{ [string]: any }— The pulled rows by path.rootPathstring— The install's root path.pace(() -> ())(optional) — Called between rows.
Returns RowSwap? — A RowSwap, or nil when no install stands at rootPath as rows.
worldVcs.__rowSwapFor({}, {}, "/zero/source/a.package")
typed/builtin//modules/world_vcs/M/__rowsOverInstalledFiles
M.__rowsOverInstalledFiles(dirty: { any }, changes: { any }?, facts: InstalledFileFacts?) -> { [string]: boolean }
The rows of the world's own that stand over a file an install held as
one record states, each one with a version to go back to: the install's.
The engine materializes such an install's files from its record, so no
commit holds them as rows, and a file of it the world wrote is a row no
commit holds, standing over the install's file. Such a row is one
install.changes lists as changed, or a file beneath the destination of
an install the world holds a record for that install.changes does not
list as added: a file whose bytes were written back to the ones the
install states is a row of the world's own all the same. Each is a row
the caller's staging area holds no entry for: a staged row stands for the
version staged.
Parameters
dirty{ any }— The dirty rows of a status read taken with the install rows left in.changes{ any }(optional) — Whatinstall.changesanswers, or nil when it cannot answer.factsInstalledFileFacts(optional) — The record destinations, the staged rows and the folder test.
Returns { [string]: boolean } — The set of such paths.
worldVcs.__rowsOverInstalledFiles(world.vcsStatus().dirty, trusted.call("install.changes"), { records = trusted.call("install.records") })
typed/builtin//modules/world_vcs/M/__rowsReplacedByRecords
M.__rowsReplacedByRecords(rows: { any }, summaries: any?) -> { ReplacedRows }
The pulled rows that install records took the place of and the working tree still holds as deletions: each deletion at or beneath the destination of an install that stands as one record, or of a dependency that record placed. An update or a conversion of an install an earlier engine landed as one row per file leaves its rows so until the next commit.
Parameters
rows{ any }— The pulled manifest rows.summariesany(optional) — Whatinstall.summariesanswers.
Returns { ReplacedRows } — One entry per record holding any, ordered by root path, each with its rows in path order.
worldVcs.__rowsReplacedByRecords({}, {})
typed/builtin//modules/world_vcs/M/__rowsUnderPrefix
M.__rowsUnderPrefix(dir: string, paths: { string }) -> { string }
The rows of paths that lie beneath the directory dir. dir is
taken in either the /source/… shorthand or the engine-canonical
/zero/source/… form and matched as a whole path segment, so a
directory selects its own contents and never a sibling whose name it is
a prefix of. This is the set a directory stands for when it is staged: a
directory outside any asset carries no manifest row of its own, and the
rows to stage are the ones under it.
Parameters
dirstring— The directory whose contents to select.paths{ string }— The candidate row paths, engine-canonical.
Returns { string } — Those of paths under dir, in the order given.
worldVcs.__rowsUnderPrefix("/source/hud", { "/zero/source/hud/a.luau" })
typed/builtin//modules/world_vcs/M/__runInstallRootBackfill
M.__runInstallRootBackfill() -> { marked: { string }, rejected: { string }, skipped: { string } }?
Run the install-root backfill against the bound world, as world.update
does before it reads the units: the pulled rows and closures come from the
live manifest and ZeroMind, closures are read four at a time, and a
decision lands on the live row at once, to ride in the commit that takes
the update. Does nothing outside an editor session that may write the world.
Returns { marked: { string }, rejected: { string }, skipped: { string } }? — The backfill's result, nil when the session may not write or the pulled rows could not be read.
worldVcs.__runInstallRootBackfill()
typed/builtin//modules/world_vcs/M/__runOpenNestedRecordRepair
M.__runOpenNestedRecordRepair() -> { given: { string }, left: { { path: string, reason: string } } }
Run __repairNestedRecords against the open world, reporting in the
log each record given back (the change zm status then lists) and each
row left in place with why.
Returns { given: { string }, left: { { path: string, reason: string } } } — What __repairNestedRecords answers.
worldVcs.__runOpenNestedRecordRepair()
typed/builtin//modules/world_vcs/M/__runOpenRecordOrigins
M.__runOpenRecordOrigins() -> { { path: string, commit: string?, visibility: string? } }
Run __stateRecordOrigins against the open world: each install record
an earlier engine wrote comes to state the origin commit and visibility
ZeroMind answers for it, and one log line names each record written.
Returns { { path: string, commit: string?, visibility: string? } } — The records written, as __stateRecordOrigins names them.
worldVcs.__runOpenRecordOrigins()
typed/builtin//modules/world_vcs/M/__runOpenUpdateCheck
M.__runOpenUpdateCheck() -> (string?, string?)
Run the editor open's update check against the open world: libraries and
marked install roots are read a few at a time from ZeroMind
(__openUpdateCheck). A @builtin pin older than the engine's whose move
changes an asset the world's own content names or reaches raises an
actionable notice to every caller, which starts a turn of an idle agent:
it asks the agent to upgrade the pin unasked. The other units with an
update raise one actionable notice that asks the agent to ask the user
first; it names the ZeroMind panel's updates view, which the editor's
notification list opens from it. Each finding is raised once for the
world (UPDATE_FINDINGS_PATH). A read-only viewer is told as well.
Returns (string?, string?) — The text of the notice for the units with an update, then the text of the @builtin notice; nil for each not raised.
worldVcs.__runOpenUpdateCheck()
typed/builtin//modules/world_vcs/M/__sameBindings
M.__sameBindings(a: any?, b: any?) -> boolean
Whether two reference-table texts record the same bindings, leaving
out the diagnostics (unresolved_deps, problems) that describe local
resolution.
Parameters
aany(optional) — A reference-table JSON text, or nil.bany(optional) — A reference-table JSON text, or nil.
Returns boolean — true when both record the same bindings.
worldVcs.__sameBindings("{}", "{\"deps\":[]}") --> true
typed/builtin//modules/world_vcs/M/__saveExcludedInstallRefusal
M.__saveExcludedInstallRefusal(at: string?, verb: string) -> string?
Why an install aimed at at cannot land there because the world does
not save or sync that place, or nil when it can. /source/tmp/ is session
scratch and /source/local/ is this machine's own content: the engine holds
both out of every world save and every peer broadcast (vfs.isSaveExcluded),
so the world could hold no row for an install there. A destination at or
under either is refused before anything is read or written.
Parameters
atstring(optional) — The destination folder the install was asked for.verbstring— The call the refusal is raised for, e.g.world.installAsset.
Returns string? — The refusal text, or nil.
worldVcs.__saveExcludedInstallRefusal("/source/tmp/probe", "world.installAsset")
typed/builtin//modules/world_vcs/M/__scopeHolds
M.__scopeHolds(scope: { string }) -> ({ [string]: boolean }, (string) -> boolean, { string })
The rows a commit freezes, read three ways: the set of them, whether an asset is in the commit (the commit holds its row, a file of it, or a folder it lies in), and the libraries whose pin marker it holds.
Parameters
scope{ string }— The rows the commit freezes, engine-canonical.
Returns ({ [string]: boolean }, (string) -> boolean, { string }) — The set, the asset test, and the libraries with their @, sorted.
worldVcs.__scopeHolds({ "/zero/source/libs/@builtin" })
typed/builtin//modules/world_vcs/M/__seatTreeChildren
M.__seatTreeChildren(assets: { any }) -> number
Seat each tree_child of a closure at the path the folder version holding
it states, once every folder entry stating no path has taken the one its
files place it at (__stateFolderPaths). A folder version can hold an
asset another world owns at a version of its own, and ZeroMind names
that entry by the path its owning world gives it. Such an entry, outside
every folder of its via asset, takes the path of the child its folder
version states at the entry's version (the same checksum, and the same
asset_version_id when both state one) that no other entry fills yet,
and every entry of its own tree moves with it. A dependency entry the
closure lists outside a folder version that states it among its
children, or at that child's own path inside it, at the exact version a
child slot no other entry fills names (the same checksum and the same
asset_version_id, both stated), is that folder's member: it becomes
the folder's tree_child, seated at that slot with its own tree, so the
install holds that version once, inside the folder, as installing the
folder itself does. Changes the entries in place.
Parameters
assets{ any }— The closure's entries.
Returns number — How many entries it seated, the trees that moved with them left out.
worldVcs.__seatTreeChildren(closure.assets)
typed/builtin//modules/world_vcs/M/__selectAssetCommits
M.__selectAssetCommits(chain: { any }, changesOf: (index: number) -> ({ string }, { string }?), watched: { string }, rootPath: string, rootAt: (commitId: string) -> (string?), from: string) -> ({ any }, boolean, string?)
The commits of an install's update, from the chain of its origin back from the version it updates to: each commit whose change touches the install is kept, and the walk ends at the commit that moved the root from the installed version (kept), at a commit after which the root has no earlier version (a commit that adds the root's own path is where its history starts, read from the diff with no version read), and at the first commit of the history. When the version of the root at a commit cannot be read the walk stops there, short of the installed version, and says why.
Parameters
chain{ any }— The origin's commits, newest first (__commitChain).changesOf(index: number) -> ({ string }, { string }?)— The paths the commit at an index changed against its parent, and the ones among them it added.watched{ string }— The origin paths of the closure at the new version.rootPathstring— The origin path of the root.rootAt(commitId: string) -> (string?)— The version of the root at a commit, nil when it has none there; raises when it cannot be read.fromstring— The version the world holds.
Returns ({ any }, boolean, string?) — The commits kept, whether the walk reached the commit that left from, and why it stopped short when a version could not be read (nil otherwise).
worldVcs.__selectAssetCommits({}, function() return {} end, {}, "a", function() return nil end, "f")
typed/builtin//modules/world_vcs/M/__setInstallRef
M.__setInstallRef(refsJson: string?, installRef: string?) -> string?
A reference table as its row carries it, with the ref its install was
asked for recorded as "install_ref": a branch, a tag or a commit id of
the origin. The rest of the table stays as written.
Parameters
refsJsonstring(optional) — The table's JSON text, or nil for an asset that has none.installRefstring(optional) — The ref the caller named, nil or empty when it named none.
Returns string? — The table's JSON text, unchanged when no ref was named.
worldVcs.__setInstallRef('{"deps":[]}', "release")
typed/builtin//modules/world_vcs/M/__settleOwedWrites
M.__settleOwedWrites(target: string, stallSeconds: number) -> { string }
Wait until no local write at or beneath target is still owed to the
world, then give up the ones that stay. Progress is a path leaving the
owed set, whatever else joins it meanwhile; once none has left for
stallSeconds what remains is a change the world is not taking, and
world.dropOwedWrites gives it up so the path reads as the world holds
it. Raises naming the paths when one is still owed after that.
Parameters
targetstring— The engine-canonical path to settle beneath.stallSecondsnumber— How long the owed set may go without a path leaving it.
Returns { string } — The paths given up, sorted.
worldVcs.__settleOwedWrites("/zero/source", 15)
typed/builtin//modules/world_vcs/M/__settleStagedPaths
M.__settleStagedPaths(asked: { string }, heldBefore: { [string]: boolean }, before: { [string]: any }, after: { [string]: any }, releaseThere: (ReleasedPath) -> ()) -> AddReport
Hold one staging call to the paths its caller staged. A path is
staged in one area at a time, so each path the call stages that another
staging area held is taken out of that area, whichever account opened
it and whether or not its session is open, and named in released. The
backend also stages, beside a named path, the referenced assets whose
current version no commit holds; each is named in carried and taken
out of any other area the same way, so the commit carries nothing its
caller is not told about. A staged path a caller of another account is
writing now is named in written. Staging is advisory: nothing another
area holds and nothing another caller is writing narrows the stage.
Parameters
asked{ string }— The paths the call named, after asset-family expansion.heldBefore{ [string]: boolean }— The paths the calling area held before the call, as a set.before{ [string]: any }— The calling area's status read before the call: itsclaimed_by_other_stagesnames the areas holding each path, and itsdirtywho wrote each.after{ [string]: any }— The calling area's status read after the call:stagedandclaimed_by_other_stages.releaseThere(ReleasedPath) -> ()— Takes one path out of the other staging area aReleasedPathrow names; called for a path that area still holds after the call.
Returns AddReport — { staged, carried, released, written }.
worldVcs.__settleStagedPaths(asked, held, before, after, release)
typed/builtin//modules/world_vcs/M/__settledStageLines
M.__settledStageLines(verb: string, report: AddReport) -> { string }
The lines a staging call writes to its caller about the paths it
settled: each dependency it carried beside what was named, then the
work of another account it took (M.__takeLines). Empty when the call
staged exactly what it named and took nothing from another account.
Parameters
verbstring— The calling API's name.reportAddReport— What__settleStagedPathsanswered.
Returns { string } — The lines, in that order.
worldVcs.__settledStageLines("world.add", report)
typed/builtin//modules/world_vcs/M/__shippedCommit
M.__shippedCommit(resolve: (string, string) -> (boolean, string), closure: any?, rootGuid: string) -> string?
The commit of the asset's world an install of the version that world
ships reads it at: the commit the world's main names, when that commit
holds the version of rootGuid the closure served. The version a world
ships is the one its main holds, so the two agree unless main moved
between the reads.
Parameters
resolve(string, string) -> (boolean, string)— Resolves a ref of a world to the commit it names, with its manifest (InstallClosureReads.resolve).closureany(optional) — The decoded closure of the version the world ships.rootGuidstring— The installed asset.
Returns string? — The commit, or nil when main names none that holds the version served.
worldVcs.__shippedCommit(reads.resolve, closure, "5f6bfcfb-2258-47d9-8f1e-8f684f85e1f3")
typed/builtin//modules/world_vcs/M/__sitesOnChangedPaths
M.__sitesOnChangedPaths(sites: { LibrarySite }, changed: { [string]: boolean }, home: string, sourceOf: (guid: string) -> string?, runsItsCopy: (guid: string) -> boolean, depsOf: ((guid: string) -> { string })?) -> { LibrarySite }
The sites among sites whose asset a play of the world runs
differently once the pin of a library moves: the asset's path under the
library's root (sourceOf(guid)) is one of changed, or does not lie
under that root, or an asset its reference table names (depsOf),
followed transitively through the library, lies at one of changed. An
asset a play runs at the engine's own version whatever the pin names
(__playRunsEngineVersion) neither counts nor is followed, since a play
reads none of its pinned version. An asset an asset's table names that
lies outside the library neither counts nor is followed. Each asset is
looked up once.
Parameters
sites{ LibrarySite }— The sites, each{ source, literal, line?, guid }.changed{ [string]: boolean }— The paths the move changes, relative to the library's root.homestring— The library's root, ending in/(/zero/source/libs/@builtin/).sourceOf(guid: string) -> string?— The path the assetguidlies at, or nil.runsItsCopy(guid: string) -> boolean— Whether every site naming the assetguidruns the engine's copy.depsOf((guid: string) -> { string })(optional) — The guids of the assets the reference table of the assetguidnames; nil follows none.
Returns { LibrarySite } — Those sites, in the order given.
worldVcs.__sitesOnChangedPaths({ { source = "/zero/source/a.luau", literal = "@builtin::bundles.lamp_post", guid = "g" } }, { ["components/Light.component"] = true }, "/zero/source/libs/@builtin/", function(guid) return if guid == "g" then "/zero/source/libs/@builtin/bundles/lamp_post.bundle" else "/zero/source/libs/@builtin/components/Light.component" end, function() return false end, function(guid) return if guid == "g" then { "light" } else {} end)
typed/builtin//modules/world_vcs/M/__splitIgnored
M.__splitIgnored(rows: { any }, set: Ignore.IgnoreSet, listIgnored: boolean) -> { dirty: { any }, ignored: { any }, summary: { IgnoredGroup } }
The working tree's changed rows split into the ones an author stages
and the ignored ones: a scene's autosave overlay (engine-managed state
that never stages or commits: saving the scene writes it into
scene.json) and the rows a .zmignore / .gitignore rule matches. The
ignored rows are counted by kind, one group per overlay folder and per
ignore rule, in the order each kind first appears.
Parameters
rows{ any }— The changed rows of the status read.setIgnore.IgnoreSet— The ignore set the world's ignore files state.listIgnoredboolean— Whetherignoredlists the ignored rows themselves.
Returns { dirty: { any }, ignored: { any }, summary: { IgnoredGroup } } — { dirty, ignored, summary }: the rows that stay changes, the ignored rows when listIgnored (else an empty list), and the IgnoredGroup per kind.
worldVcs.__splitIgnored(rows, worldVcs.__ignoreSetFrom({}), false)
typed/builtin//modules/world_vcs/M/__stageBaseMoved
M.__stageBaseMoved(msg: string) -> boolean
True when the backend refused to build a commit on a stage whose branch has moved: the area was opened against the commit that was the branch head then, and another caller's commit is the head now.
Parameters
msgstring— The backend's refusal text.
Returns boolean — Whether that text is the moved-head answer.
worldVcs.__stageBaseMoved("ParentCommitMoved: branch \"main\" HEAD is ...") --> true
typed/builtin//modules/world_vcs/M/__stageNameFrom
M.__stageNameFrom(opts: any?, verb: string) -> string
The staging area a staging call acts on. opts.stage names it, and a
call that names none acts on the calling caller's own area, the one
vfs.currentAuthor identifies. Two agents driving one engine therefore
stage into different rows without naming anything, so each commits the
paths it staged and leaves the other's staged where they are. Naming an
area is deliberate and shares it: that is how two callers work one set of
paths together, and how a caller reaches an area it opened under an
earlier session of its own.
Parameters
optsany(optional) — The options table the caller passed, or nil.verbstring— The calling API's name, quoted in a refusal.
Returns string — The name of the staging area this call acts on.
worldVcs.__stageNameFrom({ stage = "fauna" }, "world.add") --> "fauna"
typed/builtin//modules/world_vcs/M/__stageOnceWith
M.__stageOnceWith(open: () -> string, stageInto: (string) -> (boolean, string)) -> (boolean, string)
Run one staging step against the implicit stage, resolving the handle
through open immediately before the step so the row cannot retire while
a barrier or a gate runs ahead of it. stageInto returns the
(ok, message) pair the backend answered with and must carry out the
WHOLE of one step: a retired row takes its entries with it, so when the
backend reports the row is gone a fresh row is opened and stageInto runs
once more, landing every path the step names in the stage that exists now
rather than only the ones after the failure. The second run resolves a
handle rather than repeating a caller's operation — staging a path is
idempotent at (stage, manifest_row), so it reaches exactly the state the
first run was asked for. Any other refusal is returned as it came.
Parameters
open() -> string— Resolves the implicit stage, returning its row id.stageInto(string) -> (boolean, string)— Carries out one whole staging step against a row id.
Returns (boolean, string) — The (ok, message) pair the surviving run produced.
worldVcs.__stageOnceWith(openStage, function(id) return true, "" end)
typed/builtin//modules/world_vcs/M/__stageReferencesRecords
M.__stageReferencesRecords(records: { ReferencesRecord }, held: { [string]: boolean }?, stage: (string, { string }, { string }) -> (boolean, string), unstage: (string) -> (boolean, string)) -> (boolean, string)
Stage, into the area stageId names, the references of every file the
commit records for them alone, and take out of it every references entry
the commit no longer records: the area then holds each file the commit
holds a change that moved, at the branch head's bytes with those pins
advanced. References are staged over the branch head, so an area opened
against an earlier head is answered with the backend's moved-head
refusal (__stageBaseMoved) and nothing more is staged: the caller
brings the area onto the head and stages them again. Any other refusal
raises, naming the file.
Parameters
records{ ReferencesRecord }— The files to record, as__referencesToRecordanswers them.held{ [string]: boolean }(optional) — The paths the area holds the references of alone now.stage(string, { string }, { string }) -> (boolean, string)— Stages one file's references:(path, assetGuids, worldGuids) -> (ok, message).unstage(string) -> (boolean, string)— Takes one path out of the area:(path) -> (ok, message).
Returns (boolean, string) — true, "" once every file is staged and every stale entry taken out; false and the refusal when the area's head moved.
worldVcs.__stageReferencesRecords(records, status.referencesOnly, stage, unstage)
typed/builtin//modules/world_vcs/M/__stageResetRefusal
M.__stageResetRefusal(stage: string, mode: string, atHead: boolean, target: string) -> string?
Why a reset naming the staging area stage is refused, or nil when
it is not: a reset of a named area empties that area and moves nothing
else, so a soft or hard mode and a target other than the branch head
are refused, naming the area.
Parameters
stagestring— The staging area the reset names.modestring— The reset's mode.atHeadboolean— Whether the target names the branch head.targetstring— The target as the caller wrote it.
Returns string? — The refusal, or nil.
worldVcs.__stageResetRefusal("client:#a", "hard", true, "HEAD") --> "a reset of the staging area 'client:#a' empties it and moves nothing else, so it takes no --hard: ..."
typed/builtin//modules/world_vcs/M/__stageRowAbsent
M.__stageRowAbsent(msg: string) -> boolean
True when the backend's reason for refusing to take a path out of a staging area is that the area does not hold it, which is the state the caller asked for.
Parameters
msgstring— The backend's refusal text.
Returns boolean — Whether that text is the not-staged answer.
worldVcs.__stageRowAbsent("path /zero/source/a.luau is not staged in stage 41") --> true
typed/builtin//modules/world_vcs/M/__stageRowRetired
M.__stageRowRetired(msg: string) -> boolean
True when the backend's reason for refusing a stage operation is that
the row the handle names is gone. A stage row is deleted the moment a
commit materializes it, and a staging area is one row per
(world, branch, account, name), so a handle onto an area another caller
is also acting on names a row that a commit of theirs has since retired.
Parameters
msgstring— The backend's refusal text.
Returns boolean — Whether that text is the retired-row answer.
worldVcs.__stageRowRetired("stage_add: stage 41 does not exist") --> true
typed/builtin//modules/world_vcs/M/__stageableSources
M.__stageableSources(paths: { string }) -> { string }
The rows of paths a commit can stage: the candidates narrowed to
the paths the world can hold a manifest row for. A save-excluded path is
local to this machine and has no row anywhere, so stage_add names it
and refuses — which, from inside a commit, aborts over content the
author never staged and cannot unstage.
Parameters
paths{ string }— The candidate paths, engine-canonical.
Returns { string } — Those of paths the world can hold a row for, in the order given.
worldVcs.__stageableSources({ "/zero/source/a.luau" })
typed/builtin//modules/world_vcs/M/__stagedPath
M.__stagedPath(path: string) -> string
The manifest path a staging call names for path: the engine-canonical
/zero/... form, reached by the rule every VFS path argument takes — an
absolute or library path normalized as it stands, a relative one joined
under /source/. world.add("NOTES.md") therefore stages the file
vfs.write("NOTES.md", ...) wrote.
Parameters
pathstring— A VFS path, absolute, library or relative.
Returns string — The canonical path.
worldVcs.__stagedPath("NOTES.md") --> "/zero/source/NOTES.md"
typed/builtin//modules/world_vcs/M/__stagedPathSet
M.__stagedPathSet(entries: { any }?) -> { [string]: boolean }
The set of paths the staged entries of a status read name, each entry
a row ({ path, ... }) or a path.
Parameters
entries{ any }(optional) — The staged entries, or nil.
Returns { [string]: boolean } — The set.
worldVcs.__stagedPathSet(world.vcsStatus().staged)
typed/builtin//modules/world_vcs/M/__stagingSelection
M.__stagingSelection(path: string, root: string?, isDirectory: boolean, dirtyPaths: { string }, rootIsInstall: boolean?) -> StagingSelection
The rows staging path names. A path inside an asset names that
asset's family, as __assetFamilyMembers states. A path outside any
asset names itself and every changed row beneath it, whether the path
is still on disk or not: a directory holds no row of its own, and a
deleted asset folder holds a delete row of its own with a delete row
for each of its files, so staging the folder names every one of them.
A path that names no changed row is named on its own when it is not a
directory, so the backend stages the row there or refuses it by name;
a directory with no changed row beneath it names nothing, and the
selection carries the notice saying so.
A path that names the destination of an install also names the install's
record (<path>.pull) when that record is a changed row: the record is
what the install is in a commit, so staging the installed folder stages
the install, and an uninstall's removed record goes the same way.
Parameters
pathstring— The engine-canonical path the call names.rootstring(optional) — The outermost asset folder that holdspath, nil when no asset holds it.isDirectoryboolean— Whetherpathis a directory on disk.dirtyPaths{ string }— The changed rows of the working set, engine-canonical.rootIsInstallboolean(optional) — Whetherrootstands for content installs place and the world holds no row of its own there (__installContentWithoutRow): the family is thenpathand the changed rows underroot, and namingrootitself with no change under it names nothing and carries the notice saying so.
Returns StagingSelection — { rows, notice }.
worldVcs.__stagingSelection("/zero/source/a.module", nil, false, dirty)
typed/builtin//modules/world_vcs/M/__staleReferences
M.__staleReferences(scope: { string }, differing: { DifferingTable }, status: LiveStageStatus, ops: ReferenceOps) -> { StaleReference }
The files a commit holds whose references do not resolve in what it
holds. Two cases make one rule:
a file the commit holds names a library whose marker is changed and left
out, so its table states that library at the pin the marker moves to;
a file the commit holds pins an asset of the world at bytes that asset
holds in the working tree and the commit leaves out.
Library content (everything under /zero/source/libs/) is never stale,
nor is a file the live ignore set matches, nor a table that differs only
in its install record. A file whose references moved with what the commit
holds and that the commit leaves out is recorded for its references
(__referencesToRecord), and is not stale. Nothing is staged or changed.
Parameters
scope{ string }— The rows the commit freezes with their bytes, engine-canonical.differing{ DifferingTable }— The rows whose live table differs from the head's.statusLiveStageStatus— The working tree and the calling area, read once.opsReferenceOps— What the check reads beyond the working tree.
Returns { StaleReference } — One entry per stale file, sorted by path.
worldVcs.__staleReferences(scope, differing, status, ops)
typed/builtin//modules/world_vcs/M/__staleReferencesRefusal
M.__staleReferencesRefusal(section: PublishBlockerClass) -> string
The text a commit raises over stale files: the class title, each file
with what moved its references, and the remedy. Past
STALE_REFERENCES_LISTED files the rest are counted, and
world.publishBlockers() names every one.
Parameters
sectionPublishBlockerClass— The class__staleReferencesSectionmade.
Returns string — The refusal text.
worldVcs.__staleReferencesRefusal(section)
typed/builtin//modules/world_vcs/M/__staleReferencesSection
M.__staleReferencesSection(stale: { StaleReference }) -> PublishBlockerClass?
The blocker class stale files make, in the shape world.publishBlockers
reports every class, with blocks = "commit": the class blocks the next
commit of the staged set and never a push of what is committed. One item
per file, each detail carrying the dep.stale_references category and
what its references name that the commit leaves out. world.commit
refuses with it.
Parameters
stale{ StaleReference }— The stale files, as__staleReferencesanswers them.
Returns PublishBlockerClass? — The class, or nil when no file is stale.
worldVcs.__staleReferencesSection(stale)
typed/builtin//modules/world_vcs/M/__standForRetired
M.__standForRetired(leftOut: { [string]: string }, retired: { RetiredCopy }) -> { [string]: string }
The versions an install's record stands for because of the copies it
retires (__retiredCopies), merged into leftOut: each asset of a
retired copy at the version it held there, keyed guid@checksum as
__oneReleasePerAsset keys the versions it leaves out, each naming the
release that takes the copy's place. A site naming one runs the copy the
install places of that asset (__standsFor).
Parameters
leftOut{ [string]: string }— The versions the plan left out, byguid@checksum, changed in place.retired{ RetiredCopy }— The copies the install retires.
Returns { [string]: string } — leftOut.
worldVcs.__standForRetired({}, {})
typed/builtin//modules/world_vcs/M/__standsFor
M.__standsFor(prior: { [string]: any }?, record: { [string]: any }, leftOut: { [string]: string }?) -> { { asset_guid: string, checksum: string } }
The versions of its assets that the record record of an install
stands for: each version the install's plan left out for the one that
stands (leftOut, __oneReleasePerAsset) of an asset record places,
and each asset prior (the record the install held at the same
destination) placed, or stood for, at a version record places it at no
longer, while record places that asset at another version of a release
no older than the one prior placed it in (by version_id, a release
stating none ranking with every other). A reference naming one of them
runs the copy record places, so every file the install lands runs one
copy of each asset, content that ran the install's copy before it moved
runs the copy it holds now, and a move to an older release leaves
content written against the newer one on that one.
Parameters
prior{ [string]: any }(optional) — The record the install held, decoded, or nil.record{ [string]: any }— The record that takes its place.leftOut{ [string]: string }(optional) — The version standing for each one the plan left out, byguid@checksum, or nil.
Returns { { asset_guid: string, checksum: string } } — The versions, as { asset_guid, checksum }, sorted.
worldVcs.__standsFor(nil, record, { ["g@old"] = "new" })
typed/builtin//modules/world_vcs/M/__stashApplyOutcome
M.__stashApplyOutcome(entries: { { path: string, kind: string?, text: string?, blob_sha256: string? } }, writtenBack: { string }, left: { [string]: string }) -> StashApplyOutcome
Name each path a stash records by what its apply did with it, in the stash's path order. A path the apply wrote back is restored. A path it left as it is, with the reason it gives, is skipped with that reason. A path the stash records as deleted is skipped. A path the stash holds no content of its own for and other stashed paths sit beneath (a folder asset) is restored when any path beneath it was written back, and is skipped otherwise. Any other path the stash holds no content for is skipped.
Parameters
entries{ { path: string, kind: string?, text: string?, blob_sha256: string? } }— The stash's dirty entries, each{ path, kind?, text?, blob_sha256? }.writtenBack{ string }— The paths the apply wrote back.left{ [string]: string }— The paths the apply left as they are, each with its reason.
Returns StashApplyOutcome — A StashApplyOutcome: restored, skipped and the reasons of each skipped path.
worldVcs.__stashApplyOutcome({ { path = "/zero/source/a.module" }, { path = "/zero/source/a.module/init.luau", text = "" } }, { "/zero/source/a.module/init.luau" }, {})
typed/builtin//modules/world_vcs/M/__stashLandTargets
M.__stashLandTargets(entries: { any }, restored: { string }) -> { InstallLandTarget }
What a stash applied by its stored blobs lands as: each path the
stash wrote back at the version its snapshot records (checksum_sha256),
a folder asset's among them; a path the snapshot records no version of
stands once it exists.
Parameters
entries{ any }— The stashed rows, as the stash snapshot'sdirtylists them.restored{ string }— The paths the stash wrote back, engine-canonical.
Returns { InstallLandTarget } — The landing targets, sorted by path.
worldVcs.__stashLandTargets({ { path = "/zero/source/a.png", checksum_sha256 = string.rep("a", 64) } }, { "/zero/source/a.png" })
typed/builtin//modules/world_vcs/M/__stashPushOutcome
M.__stashPushOutcome(entries: { { path: string, committed: boolean?, text: string?, blob_sha256: string? } }) -> StashPushOutcome
Name each path a stash push records by what the push does with it,
in the stash's path order. A path a commit holds goes back to its
committed version and is listed under revert, its content kept in the
stash, inline or by its stored blob. A path no commit holds has no
version to go back to: it keeps its working content in the tree, as git
leaves an untracked file, and is listed under kept with that reason.
Parameters
entries{ { path: string, committed: boolean?, text: string?, blob_sha256: string? } }— The stash's dirty entries, each{ path, committed?, text?, blob_sha256? }.
Returns StashPushOutcome — A StashPushOutcome: revert, kept and the reasons of each kept path.
worldVcs.__stashPushOutcome({ { path = "/zero/source/a.module", committed = false }, { path = "/zero/source/b.luau", committed = true } })
typed/builtin//modules/world_vcs/M/__stashRevertWith
M.__stashRevertWith(revert: { string }, discard: (string) -> ())
Take a stash's paths back to their committed version through
discard, each folder before the paths beneath it. A folder's discard
takes every path beneath it back with it, so a path beneath a folder
already taken back went with that folder and is not discarded again.
Raises naming the path whose discard failed and every path still holding
its working content, in the order revert gives them.
Parameters
revert{ string }— The stashed paths a commit holds a version of.discard(string) -> ()— Takes one path back to its committed version; raises when it cannot.
worldVcs.__stashRevertWith({ "/zero/source/a.module", "/zero/source/a.module/init.luau" }, world.discardFile)
typed/builtin//modules/world_vcs/M/__stateFolderPaths
M.__stateFolderPaths(assets: { any }) -> number
Give each folder entry of a closure that states no path the path
its own files place it at. A folder version states each of its files at
a path relative to itself, and each tree_child entry of the folder's own
world landing in it (via its asset) states the file's origin path in
that world, so the part of that origin path before the relative one is
the folder's own path: a tree_child at kit.package/locales/en/a.json
holding the version the folder states at locales/en/a.json places the
folder at kit.package. A tree_child another world owns states the path
its own world gives it, and places the folder nowhere. A folder whose
files place it at more than one path takes the one most of them agree on,
the first such in the closure's order on a tie. A folder whose own path a
member folder's derived path gives is derived after it, so folders
nested at any depth take their paths. Changes the entries in place.
Parameters
assets{ any }— The closure's entries.
Returns number — How many entries took a path.
worldVcs.__stateFolderPaths(closure.assets)
typed/builtin//modules/world_vcs/M/__stateRecordOrigins
M.__stateRecordOrigins(ops: RecordOriginOps) -> { { path: string, commit: string?, visibility: string? } }
State, on each install record that names its origin world and leaves
its commit or that world's visibility unstated (a record an earlier engine
wrote), what a current install records: the commit of the origin world
the record's version is read at (the one the record's ref resolves to,
or main for a record naming no ref, when that commit holds the record's
version of the asset) and the visibility ZeroMind states for the world.
A field ZeroMind does not answer stays unstated. Each record that comes to
state something is written again, and the world's references into the
content it carries are recorded the way a current install's are. Does
nothing outside an editor session whose content is confirmed.
Parameters
opsRecordOriginOps— ARecordOriginOps.
Returns { { path: string, commit: string?, visibility: string? } } — One { path, commit?, visibility? } per record written, naming what it came to state.
worldVcs.__stateRecordOrigins({ confirmedEditorOpen = function() return false end, summaries = function() return {} end, resolve = function() return false, "" end, visibility = function() return nil end, restated = function() return nil end, write = function() return true, "" end, log = print })
typed/builtin//modules/world_vcs/M/__statusSets
M.__statusSets(dirty: { any }, staged: { any }, ignored: ((string) -> boolean)?) -> LiveStageStatus
The dirty and staged sets of a status read's rows, in the shape the
update grouping reads: a staged entry holding references alone is in
referencesOnly, and ignored answers whether the ignore set matches a
path.
Parameters
dirty{ any }— The dirty entries.staged{ any }— The staged entries.ignored((string) -> boolean)(optional) — Whether the ignore set matches a path; nil matches none.
Returns LiveStageStatus — The sets.
worldVcs.__statusSets({}, {})
typed/builtin//modules/world_vcs/M/__statusWithOwnWrites
M.__statusWithOwnWrites(readStatus: () -> (boolean, string), readPending: () -> ({ string }, { [string]: any })) -> (boolean, string, { paths: { string }, authors: { [string]: any } })
A status read with this engine's own writes on their way to the manifest beside its answer: the paths the pending-write read lists right before the status read and right after it, each with the caller whose call made it (the newer read's when both name one). The manifest's status index takes a written row before the write leaves the pending list, so a write that left it while the status was read is in the list read before, whether or not the answer holds its row: every write that returned before the read began is among the answer's rows or among these paths.
Parameters
readStatus() -> (boolean, string)— Reads the status: returns whether it answered, and the answer.readPending() -> ({ string }, { [string]: any })— Reads the pending writes: returns the paths and the map from each path to its caller, as__pendingWritesNowdoes.
Returns (boolean, string, { paths: { string }, authors: { [string]: any } }) — Whether the status answered, the answer, and { paths, authors }: the own writes in the order first listed, and each one's caller.
local ok, payload, own = worldVcs.__statusWithOwnWrites(readStatus, worldVcs.__pendingWritesNow)
typed/builtin//modules/world_vcs/M/__stillMissing
M.__stillMissing(problems: { string }, holds: (string) -> boolean) -> { string }
The problems an install reports, less the files of a folder version the
closure gave no entry for that the materialized install holds anyway (a
folder that shares its content with a sibling stands whole). Each line
__unplacedFolderFiles states names its path before : the version.
Parameters
problems{ string }— The problem lines the install found.holds(string) -> boolean— Whether the world holds a file at a path.
Returns { string } — The lines that still stand, in their order.
worldVcs.__stillMissing({ "/zero/source/a.package/x: the version v of a holds this file at c, and the closure names no entry for it, so the install did not place it" }, function(path) return true end)
typed/builtin//modules/world_vcs/M/__tagUpdateRows
M.__tagUpdateRows(updates: { PinUpdate }, dirty: { any }, staged: { any })
Mark each status row that is part of a pin update with the update's
library (update = "@builtin"): the marker's row and every repin's.
Parameters
updates{ PinUpdate }— The pin updates.dirty{ any }— The dirty entries, marked in place.staged{ any }— The staged entries, marked in place.
worldVcs.__tagUpdateRows({}, {}, {})
typed/builtin//modules/world_vcs/M/__takeInstalledSide
M.__takeInstalledSide(path: string, side: string, ops: any?) -> boolean
Take one side of a file of an install the world holds as one record
where the world holds a row of its own over the file the record states:
the file an update names among an install's conflicts when the world's
edit of it conflicts with the version the install moved to. theirs
takes the world's row out, so the install's file stands at the path, and
answers once the path reads the bytes the record states. ours keeps the
world's file as it stands.
Parameters
pathstring— The engine-canonical path of the file.sidestring—oursortheirs.opsany(optional) —{ records, mountState, readRecord, worldRowsUnder, dropRows, readFile, clock, wait, deadlineSeconds }:recordsanswers the destination of every install the world holds as one record, the rest asInstallRecordOpsstates them.
Returns boolean — Whether path is such a file. False touches nothing.
worldVcs.__takeInstalledSide("/zero/source/kit.package/README.md", "theirs", ops)
typed/builtin//modules/world_vcs/M/__takeLines
M.__takeLines(verb: string, released: { ReleasedPath }, written: { WrittenPath }, unstaged: boolean?) -> { string }
The lines a staging call writes to its caller about the work of another account it staged. Staging is advisory, so the call took each path; these say from whom. One line per staging area of another account it took paths from, naming the account, the area and the session holding it, and saying that account is working on them now when that session is open, or that the session has ended. One line per caller of another account writing paths the call staged. A take from an area of the caller's own account (another of its agents or engines) is in the report and writes no line.
Parameters
verbstring— The calling API's name.released{ ReleasedPath }— The paths the call took from other staging areas.written{ WrittenPath }— The staged paths a caller of another account is writing now.unstagedboolean(optional) — True when the call unstaged the paths it took rather than staging them into its own area.
Returns { string } — The lines, areas first, in the order the paths were taken.
worldVcs.__takeLines("world.add_all", report.released, report.written)
typed/builtin//modules/world_vcs/M/__takenFromOtherAreas
M.__takenFromOtherAreas(paths: { string }, claims: { any }) -> { ReleasedPath }
The ReleasedPath rows a staging call takes from other staging
areas when it stages paths: one row per path and per other area that
holds it, in the order paths lists them.
Parameters
paths{ string }— The paths the call stages.claims{ any }— The rows other staging areas hold, as status reads report them.
Returns { ReleasedPath } — The rows, each naming the path and the area holding it.
worldVcs.__takenFromOtherAreas({ "/zero/source/a.luau" }, status.claimed_by_other_stages)
typed/builtin//modules/world_vcs/M/__transientFailure
M.__transientFailure(reason: string) -> boolean
Whether a ZeroMind read failed for a reason a later attempt can
outlive: a paged read the server no longer holds (410, a server that
restarted mid-read), a rate limit (429), a server error (5xx), or a
request that never reached an answer.
Parameters
reasonstring— The failed read's reason.
Returns boolean — True when the read is worth making again.
worldVcs.__transientFailure("ZeroMind GET … returned HTTP 410: …") --> true
typed/builtin//modules/world_vcs/M/__trashEntryRestoresPath
M.__trashEntryRestoresPath(entry: TrashRow) -> string?
The path whose content restoring the trash entry entry writes back
into the working tree: the path of a discarded edit, or of a removed file
or folder. nil for an entry whose restore writes no content (a dropped
stash, a commit a reset left behind).
Parameters
entryTrashRow— A trash row, asworld.trashlists it.
Returns string? — The path, engine-canonical, or nil.
worldVcs.__trashEntryRestoresPath({ row_id = 1, op_kind = "discard_unstaged", path = "/zero/source/a.md" })
typed/builtin//modules/world_vcs/M/__underAnyOf
M.__underAnyOf(path: string, roots: { [string]: any }) -> string?
The deepest of the folders keyed in roots that path is, or lies
under: path itself and then each folder above it, nearest first. Costs
one lookup per level of path, however many folders roots holds.
Parameters
pathstring— A path.roots{ [string]: any }— The folders, as the keys of a table.
Returns string? — The folder, or nil when path lies under none of them.
worldVcs.__underAnyOf("/zero/source/deps/w/a/b.luau", { ["/zero/source/deps/w/a"] = true })
typed/builtin//modules/world_vcs/M/__undoRowsOverRecord
M.__undoRowsOverRecord(done: RowsOverRecordMerge, ops: any?) -> { string }
Put back the world's bytes of each file M.__mergeRowsOverRecord
changed, as rows of the world's own over the install's files.
Parameters
doneRowsOverRecordMerge— What the merge carried out.opsany(optional) —{ writeFile }.
Returns { string } — The paths that could not be written back, each with why.
worldVcs.__undoRowsOverRecord({ merged = {}, conflicted = {}, touched = {} }, { writeFile = function() end })
typed/builtin//modules/world_vcs/M/__unlandedUnder
M.__unlandedUnder(rows: { any }) -> { [string]: number }
How many rows lie at or beneath each marked install root while flagged conflicted and holding the bytes they installed (a flag a previous update left behind, which a pull clears and lands).
Parameters
rows{ any }— The world's pulled rows.
Returns { [string]: number } — The count by root path, for the roots with at least one.
worldVcs.__unlandedUnder({})
typed/builtin//modules/world_vcs/M/__unplacedFolderFiles
M.__unplacedFolderFiles(assets: { any }, placement: { [string]: string }) -> { string }
The files a folder version an install writes states among its children
and the closure gives no entry for, so the install places none of them. A
folder marked container (__narrowToReach) holds only the files that
declare it, and names none.
Each is named by the path it would land at, with the folder's version and
the file's.
Parameters
assets{ any }— The closure's entries.placement{ [string]: string }— Where the install writes each entry, by the closure's keys.
Returns { string } — One line per file left out, sorted; empty when every written folder holds every file of its version.
worldVcs.__unplacedFolderFiles(assets, placement)
typed/builtin//modules/world_vcs/M/__unrecordedDeclaredSites
M.__unrecordedDeclaredSites(assets: { any }, world: string, host: { [string]: any }) -> ({ { via: string, literal: string } }, { string })
The reference sites the files of an install closure hold in the keys
their types declare as naming assets, which the table each file was
published with records nowhere. A table states what the publisher's engine
derived when it pushed; a key its type came to declare after that push
names assets the table never recorded, so the closure carries none of
them. Each such site is resolved in the world the file was published from,
at the commit the install reads, as a site the closure records into
another world is. A file no declared key applies to is not read, and
neither is a file that only declares a container the install brings
(container_file, __narrowToReach).
Parameters
assets{ any }— The closure's entries.worldstring— The world the files were published from; an entry of another world is left to that world's own sites.host{ [string]: any }—{ keysOf, readText, declared }:keysOf(path)the declared keys that apply to a file (__asset.declaredReferenceKeys),readText(sha)a file's text by its checksum, nil when it cannot be read,declared(path, text)the names a file holds in its type's declared keys (__asset.declaredReferences).
Returns ({ { via: string, literal: string } }, { string }) — The sites { via, literal }, each once, in the order the files list them, then one line per file whose text could not be read.
worldVcs.__unrecordedDeclaredSites({}, "7a929166-3552-492e-bba7-06810f7d15b0", { keysOf = function() return {} end, readText = function() return nil end, declared = function() return {} end })
typed/builtin//modules/world_vcs/M/__unstageTakes
M.__unstageTakes(target: string, ownStaged: { [string]: boolean }, claims: { any }) -> { ReleasedPath }?
What unstaging target takes from other staging areas: nil when
the calling area holds the path or anything beneath it (it is unstaged
there), otherwise one ReleasedPath row per other area holding the path
or a path beneath it. A path is staged in one area at a time, so
unstaging a path another area holds takes it out of that area, whichever
account opened it; the working tree keeps its bytes.
Parameters
targetstring— The path to unstage.ownStaged{ [string]: boolean }— The paths the calling area holds, as a set.claims{ any }— The rows other staging areas hold, as a status read reports them.
Returns { ReleasedPath }? — The rows, or nil.
worldVcs.__unstageTakes("/zero/source/a.luau", {}, status.claimed_by_other_stages)
typed/builtin//modules/world_vcs/M/__unstagedUnder
M.__unstagedUnder(root: string, dirty: { [string]: any }, staged: { [string]: any }, replaced: { [string]: boolean }, held: { [string]: boolean }?) -> { string }
The unstaged edits at or beneath an update's root that keep it from
running: each dirty path the staging area holds no entry for, other than a
row an install record took the place of. Beneath an install that stands
as one record (held given), a dirty path where the world holds no row
of its own is a row taken out so the installed file stands there, and
holds no edit for the update to change.
Parameters
rootstring— The update's root.dirty{ [string]: any }— The dirty paths, as a set.staged{ [string]: any }— The staged paths, as a set.replaced{ [string]: boolean }— The rows install records took the place of, as a set.held{ [string]: boolean }(optional) — For an install that stands as one record: the paths beneath it the world holds rows of its own at, as a set; nil for any other unit.
Returns { string } — The paths, sorted.
worldVcs.__unstagedUnder("/zero/source/a.package", {}, {}, {}, nil)
typed/builtin//modules/world_vcs/M/__updateCheckRoots
M.__updateCheckRoots(rows: { any }, summaries: any?) -> { InstalledRoot }
The install roots the update check compares with their origins: the
roots of the installs an earlier engine landed as one row per file, then
every install record that still installs its root
(__installedSummaries), then every dependency those records place
(__recordDependencyRoots), so the check reports, and world.update()
moves, only the installs the world holds and the dependencies they place.
Parameters
rows{ any }— The pulled manifest rows.summariesany(optional) — Whatinstall.summariesanswers.
Returns { InstalledRoot } — The InstalledRoot list: the row installs first, then the records sorted by path, then their dependencies sorted by path.
worldVcs.__updateCheckRoots({}, {})
typed/builtin//modules/world_vcs/M/__updateCommitOf
M.__updateCommitOf(commit: any?) -> UpdateCommit
One commit of an origin's log (zeromind.world commits) as a review
lists it.
Parameters
commitany(optional) — A commit of the log.
Returns UpdateCommit — { id, message, author, date }.
worldVcs.__updateCommitOf({ commit_id = "c", message = "m", author_username = "a", created_at = "2026-10-08T00:00:00Z" })
typed/builtin//modules/world_vcs/M/__updateCommitPaths
M.__updateCommitPaths(results: { UpdateUnitResult }) -> { string }
The paths an update changed or moved, which the caller stages and commits next: a library's marker when its pin moved, every file whose references moved with it and every recorded version's folder the move recorded, and every path an install's pull merged, flagged conflicted, added or removed. A unit that failed contributes nothing.
Parameters
results{ UpdateUnitResult }— The per-unit results of an update.
Returns { string } — The paths, sorted, each once.
worldVcs.__updateCommitPaths({})
typed/builtin//modules/world_vcs/M/__updateFindingKey
M.__updateFindingKey(report: UpdateReport) -> string
The key a finding of the update check is raised under once: the unit (a library name or a root path), the version it holds, the version it is behind and the release each moved dependency reaches.
Parameters
reportUpdateReport— AnUpdateReport.
Returns string — <unit>@<from>..<to>.
worldVcs.__updateFindingKey({ kind = "library", library = "@combat", from = "a", to = "b" })
typed/builtin//modules/world_vcs/M/__updateNotice
M.__updateNotice(reports: { UpdateReport }) -> string?
The sentence the update check raises for the units with an update
(the open check gives a @builtin behind the engine its own,
__builtinBehindNotice): N updates available: @<lib> <from7>→<to7>, …, <display name> <from7>→<to7>, …. Ask the user …, naming the call that
shows what an update changes, the call that applies it, and the ZeroMind
panel. Libraries come first, at most five units are listed and the rest
read … and K more. Three units of ordinary names fit the length a
notice of the built-in library is delivered at whole.
Parameters
reports{ UpdateReport }— TheUpdateReportlistworld.checkUpdatesreturned.
Returns string? — The sentence, nil when there is no update.
worldVcs.__updateNotice({})
typed/builtin//modules/world_vcs/M/__updateRecordDependencies
M.__updateRecordDependencies(deps: { InstalledRoot }, ref: string?, allowBreaking: boolean?, ops: DependencyMoveOps?) -> { DependencyPullOutcome }
Move several dependencies install records place, each to the release
ref names in its own origin world, as units of world.update: the
dependencies one install places move in one writing of its record
(__moveRecordDependencies).
Parameters
deps{ InstalledRoot }— The dependencies, as__recordDependencyRootsstates them.refstring(optional) — The ref of each dependency's world, or nil for the release it ships.allowBreakingboolean(optional) — Move them even when files outside the install that require them break against the new releases.opsDependencyMoveOps(optional) — What the moves read and run; this engine's when omitted.
Returns { DependencyPullOutcome } — One DependencyPullOutcome per dependency, in the order of deps.
worldVcs.__updateRecordDependencies({ dep }, nil, nil)
typed/builtin//modules/world_vcs/M/__updateRecordDependency
M.__updateRecordDependency(dep: InstalledRoot, ref: string?, allowBreaking: boolean?, move: ((dep: InstalledRoot, ref: string?, allowBreaking: boolean?) -> InstallAssetResult)?) -> PullAssetResult
Move a dependency an install record places to the release ref names
in its own origin world (__moveRecordDependency), as one unit of
world.update.
Parameters
depInstalledRoot— The dependency, as__recordDependencyRootsstates it.refstring(optional) — The ref of the dependency's world, or nil for the release it ships.allowBreakingboolean(optional) — Move it even when files outside the install that require it break against the new release.move((dep: InstalledRoot, ref: string?, allowBreaking: boolean?) -> InstallAssetResult)(optional) — The move,__moveRecordDependencywhen nil.
Returns PullAssetResult — A PullAssetResult naming the dependency and each file of the world's own that took the new release as merged (nothing when it held that release already), each whose edit conflicts with it as a conflict, the files outside it it broke, and the release its path holds (root_version).
worldVcs.__updateRecordDependency(dep, nil, nil)
typed/builtin//modules/world_vcs/M/__updateRecordInstall
M.__updateRecordInstall(root: InstalledRoot, ref: string?, allowBreaking: boolean?, install: ((opts: InstallAssetOpts) -> InstallAssetResult)?) -> PullAssetResult
Move an install that stands as one record row to the version of ref
(the ref it was installed at when nil): the record is written again, and
each file of the world's own over a file of the install whose version
moved takes the new version, merged with the world's edit
(M.__mergeRowsOverRecord).
Parameters
rootInstalledRoot— The install, as__recordRootsstates it.refstring(optional) — The ref to install, or nil.allowBreakingboolean(optional) — Move it even when files outside it that require it break against the new version.install((opts: InstallAssetOpts) -> InstallAssetResult)(optional) — The install call, nil forworld.installAsset.
Returns PullAssetResult — A PullAssetResult naming the install and each file of the world's own that took the new version as merged, each whose edit conflicts with it as a conflict, and the files outside it it broke.
worldVcs.__updateRecordInstall(root, nil, nil)
typed/builtin//modules/world_vcs/M/__updateRowInstall
M.__updateRowInstall(rootPath: string, ref: string?, read: { any }?, allowBreaking: boolean?) -> PullAssetResult
Update an install that stands as one pulled row per file (an earlier
engine's install) to the version of ref: one record of the new version
takes the place of the rows. The record is written and materialized, then
the rows leave; a file changed since the install stays a row of the world
over the record's file (an override). An update that does not finish (it
fails, or the call is cancelled) writes the rows back and takes the record
out, so the world holds the install as it did.
Parameters
rootPathstring— The install's root path.refstring(optional) — The ref to update to, or nil for the ref it was installed at.read{ any }(optional) — The pulled rows as the caller just read them, or nil to read them here.allowBreakingboolean(optional) — Move it even when files outside it that require it break against the new version.
Returns PullAssetResult — A PullAssetResult: the root as merged, the overrides as kept, the files outside it it broke.
worldVcs.__updateRowInstall("/zero/source/a.package", nil, nil, nil)
typed/builtin//modules/world_vcs/M/__updateRowPlan
M.__updateRowPlan(assets: { any }, localByGuid: { [string]: any }, placement: { [string]: string }, installRef: string?) -> UpdateRowPlan
What one pull of an install does to each asset of the closure it lands.
An asset the world holds no row for lands at its placement. A folder moves
to the closure's version, and takes its reference table, when either
differs. A file the world never edited (its bytes equal the version it
installed) lands, bytes and table together, whenever its version, its
table or a stale conflict flag says it differs from the closure, and a flag
it carries is cleared first. A file the world edited is reconciled by
__reconcileDecision: upstream unmoved leaves it alone (its reference table
is recorded when that differs), the world's bytes already equal to the
incoming ones advance the version, and a divergence merges. A row an
asset's placement lies beside, as a dependency version, is not the asset's
row. Lists are sorted by path.
Parameters
assets{ any }— The closure entries at the version the pull lands.localByGuid{ [string]: any }— The pulled row the pull acts on for each closure asset, by guid.placement{ [string]: string }— The path each closure asset is written to, by guid.installRefstring(optional) — The ref the pull was asked for, nil or empty when it named none.
Returns UpdateRowPlan — The UpdateRowPlan.
worldVcs.__updateRowPlan({}, {}, {}, nil)
typed/builtin//modules/world_vcs/M/__updateSummary
M.__updateSummary(files: { UpdateFile }) -> UpdateSummary
A review's counts over its files: per change kind, and the local edits that merge and that conflict.
Parameters
files{ UpdateFile }— The review's files.
Returns UpdateSummary — The summary.
worldVcs.__updateSummary({})
typed/builtin//modules/world_vcs/M/__updateSummaryLines
M.__updateSummaryLines(results: { UpdateUnitResult }) -> { string }
One line per unit an update ran: what moved and how many files it repinned, then one line per file it broke with the error and one per problem its install reported, or why the unit did not move.
Parameters
results{ UpdateUnitResult }— The per-unit results.
Returns { string } — The lines.
worldVcs.__updateSummaryLines({ { unit = "@builtin", kind = "library", from = "2836c81aa", to = "6865af4bb", ok = true, moving = { "/zero/source/a.luau" } } })
typed/builtin//modules/world_vcs/M/__updateUnitsFor
M.__updateUnitsFor(units: any?, reports: { UpdateReport }, libraries: { string }, roots: { InstalledRoot }) -> { UpdateUnit }
The units an update acts on: every unit the check reported when units
is nil, else the unit each name stands for (__resolveUpdateUnit), each
unit once, in the order given.
Parameters
unitsany(optional) — Nil, a name, or a list of names.reports{ UpdateReport }— What the update check reported.libraries{ string }— The library names the world pins.roots{ InstalledRoot }— The world's install roots.
Returns { UpdateUnit } — The units.
worldVcs.__updateUnitsFor(nil, {}, {}, {})
typed/builtin//modules/world_vcs/M/__updateWarnings
M.__updateWarnings(results: { UpdateUnitResult }, modified: { string }) -> { UpdateWarning }
The files with uncommitted changes an update touched, from what each
unit did and the paths that held such changes before it ran: a path a pull
merged reads merged and one it flagged conflicted reads conflicted; a
file whose references a library's pin move re-derived reads merged, and
a library file the world edited that the move's commit changed too reads
conflicted. A
folder whose files are listed is left out for them.
Parameters
results{ UpdateUnitResult }— The per-unit results of an update.modified{ string }— The paths holding uncommitted changes before the update.
Returns { UpdateWarning } — One { unit, path, outcome } per touched file, in result order.
worldVcs.__updateWarnings({}, {})
typed/builtin//modules/world_vcs/M/__verdictReach
M.__verdictReach(changed: { string }?) -> { touches: (string) -> boolean, any: boolean }?
Which asset verdicts a content walk reads again, from the paths the
asset index changed since the walk that drew them (__asset.changedSince).
A verdict of an asset no changed path lies in or above holds; a type's
validate hook may read any asset, so a hooked type's verdict holds only
while nothing changed at all. A change to an asset type, or a change the
index cannot name, holds no verdict.
Parameters
changed{ string }(optional) — The changed paths, or nil when the index cannot say which.
Returns { touches: (string) -> boolean, any: boolean }? — { touches(path): boolean, any: boolean }, or nil when no verdict holds.
local reach = worldVcs.__verdictReach({ "/zero/source/a.material/mat.yaml" })
typed/builtin//modules/world_vcs/M/__versionCopies
M.__versionCopies(list: (string) -> { any }) -> { string }
The recorded-version folders this world's dependency tree holds:
each /zero/source/deps/<world>/versions/<checksum>, sorted.
Parameters
list(string) -> { any }— Lists a folder, answering its entries (name,isDirectory).
Returns { string } — The folders' paths.
worldVcs.__versionCopies(function(path) return vfs.list(path) end)
typed/builtin//modules/world_vcs/M/__versionHoldsNoFile
M.__versionHoldsNoFile(entry: any?) -> boolean
Whether a closure entry states a version of a folder asset that holds no file: a folder asset at the checksum of a folder with nothing beneath it (the sha256 of zero bytes). Such a version has nothing to land, and a table recording it names no version to run against, so the copy the world holds answers for it.
Parameters
entryany(optional) — The closure entry.
Returns boolean — True when the entry's version holds no file.
worldVcs.__versionHoldsNoFile({ is_composite = true, checksum = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" })
typed/builtin//modules/world_vcs/M/__versionNamers
M.__versionNamers(assets: { any }, commitRecords: { [string]: any }) -> { [string]: { any } }
The entries of a closure whose reference tables name each version, by
guid@checksum: a dependency of a table names its version, and a site of
a world entry names the version the record of that world at that commit
states for the asset the site names.
Parameters
assets{ any }— The closure's entries.commitRecords{ [string]: any }— The versions each commit the install read holds, byworld@commit, which are only read.
Returns { [string]: { any } } — The naming entries of each version, in the order the closure lists them.
local namers = worldVcs.__versionNamers(closure.assets, {})
typed/builtin//modules/world_vcs/M/__versionOwnEntries
M.__versionOwnEntries(version: any?, guid: string, maxDepth: number?) -> { root: any?, entries: { any }, complete: boolean }
The files one version of an asset of another world owns, from a read
of that version's closure (GET /v1/assets/{guid}/closure?checksum=, out
to maxDepth edges): the asset itself and every entry at or beneath its
path. A read that ZeroMind cut short (truncated) is complete when every
folder among those files states its children and every child is present.
Parameters
versionany(optional) — The closure read.guidstring— The asset read.maxDepthnumber(optional) — The edge count the read was bounded at, nil for an unbounded read.
Returns { root: any?, entries: { any }, complete: boolean } — { root, entries, complete }: the asset's own entry, its files in the read's order, and whether the read holds all of them.
worldVcs.__versionOwnEntries(version, guid, 2)
typed/builtin//modules/world_vcs/M/__versionReadAnswer
M.__versionReadAnswer(guid: string, checksum: string, commit: string?, body: string) -> any
One version of an asset, from the closure a read of it answered
(body, in parts): by its checksum, or at commit, where the asset the
read answers must be at checksum. Raises naming the asset and the
version when the closure does not decode, or the commit holds another
version of it (__readVersionAt).
Parameters
guidstring— The asset.checksumstring— The version's checksum.commitstring(optional) — The commit the version was read at, or nil for a read by its checksum.bodystring— The closure the read answered, in parts.
Returns any — The decoded closure.
worldVcs.__versionReadAnswer(guid, checksum, nil, body)
typed/builtin//modules/world_vcs/M/__versionReadKey
M.__versionReadKey(version: { guid: string, checksum: string, depth: number?, own: boolean? }) -> string
The key a version read answers under: <guid>@<checksum> for a
version read out to one edge, <guid>@<checksum>#<depth> for one read
out to more, and <guid>@<checksum>#own for one read out to the depth
that holds its own files (own).
Parameters
version{ guid: string, checksum: string, depth: number?, own: boolean? }— The version read: itsguid, itschecksumand the edges it is read out to (depth, one when absent), orown.
Returns string — The key its answer is found under.
worldVcs.__versionReadKey({ guid = g, checksum = c, depth = 2 })
typed/builtin//modules/world_vcs/M/__versionReadRefusal
M.__versionReadRefusal(guid: string, checksum: string, commit: string?, reason: string) -> string
The reason a read of one version of an asset failed, as the install
reports it (__readVersionAt): the read by its checksum's reason, or,
with commit, the reason the read at the commit that reached it failed.
Parameters
guidstring— The asset.checksumstring— The version's checksum.commitstring(optional) — The commit the version was read at after its checksum named no version, or nil.reasonstring— Why the read failed.
Returns string — The text the install raises.
worldVcs.__versionReadRefusal(guid, checksum, nil, "HTTP 403")
typed/builtin//modules/world_vcs/M/__versionReadsAtCommit
M.__versionReadsAtCommit(commit: string?, reason: string) -> boolean
Whether a version whose read by its checksum was refused with
reason is read at commit, the commit the install reached it through:
when ZeroMind holds no version of the asset by that checksum
(VERSION_NOT_FOUND) and the install names a commit (__readVersionAt).
Parameters
commitstring(optional) — The commit the install reached the version through, or nil.reasonstring— Why the read by its checksum was refused.
Returns boolean — True when the version is read at commit.
worldVcs.__versionReadsAtCommit(commit, "... VERSION_NOT_FOUND ...")
typed/builtin//modules/world_vcs/M/__wholePackages
M.__wholePackages(worldGuid: string, commit: string, assets: { any }, resolveSites: (string, string, { any }) -> { any }) -> { any }
The pulls of assets of a world this world holds no copy of, each asset
inside a package replaced by that package at the same commit: a package of
another world lands whole, with its package.yaml, so its name answers a
require from this world's own scripts. One package pull stands for every
member the list named and lists them in covers. An asset no package
encloses, and one whose package the commit does not resolve, stays itself.
Parameters
worldGuidstring— The world the assets are of.commitstring— The commit they were resolved at.assets{ any }— The resolved assets, each{ asset_guid, checksum, path? }.resolveSites(string, string, { any }) -> { any }— Answers, for a world, a commit and a list of{ via, literal, names? }, one{ assets }per site in order.
Returns { any } — The assets to pull, packages in place of their members, in first-named order.
worldVcs.__wholePackages("w", "c1", { { asset_guid = "a", checksum = "x", path = "kit.package/api.module" } }, resolve)
typed/builtin//modules/world_vcs/M/__wholeReleasesToRead
M.__wholeReleasesToRead(assets: { any }, rootGuid: string, commitRecords: { [string]: any }) -> { DependencyRelease }
The releases of a dependency an install's plan holds only in part
that the install reads whole before it lands one release of each asset
(__oneReleasePerAsset): of each asset the plan brings at two or more
releases, each release weighed there that is newer than the newest one
holding every asset a file names of the others (every weighed release,
when none holds them all) that the install asks for (asked) or a file
outside it names, and whose entry, or a folder beneath it, stands as a
container (__narrowToReach: the plan holds what the install reaches of
it). Read whole and lifted into the plan (__liftDependency),
such a release is weighed by every asset it holds, so the newest release
holding what the files name stands, and an older one stands only when no
newer release holds it.
Parameters
assets{ any }— The plan's entries, each release the install asks for marked (__askHeldReleases), which are only read.rootGuidstring— The installed asset's guid.commitRecords{ [string]: any }— The versions each commit the install read holds, byworld@commit, which are only read.
Returns { DependencyRelease } — One DependencyRelease per release to read, in the order the plan lists the assets, newest first within one asset.
local reads = worldVcs.__wholeReleasesToRead(assets, rootGuid, {})
typed/builtin//modules/world_vcs/M/__withBranchReleaseRefusals
M.__withBranchReleaseRefusals(msg: string, readPage: (string, string?) -> any, branch: string?, installed: { [string]: boolean }?) -> string
A refused push's text, followed by what the refusal asks of the
release versions a branch other than main holds
(M.__releaseTakenByBranches) when it names any. The asset's line is
read only for a RELEASE_VERSION_TAKEN refusal, and a read that fails
leaves out the line of that asset.
Parameters
msgstring— The refused push's text.readPage(string, string?) -> any— Reads one page of an asset's versions:(guid, cursor) -> page.branchstring(optional) — The branch the refused push publishes, or nil when unknown.installed{ [string]: boolean }(optional) — Thepaths of the taken entries placed in an install; nil places none.
Returns string — The text, with the paragraph for the versions branches other than main hold.
worldVcs.__withBranchReleaseRefusals(msg, function(guid, cursor) return { versions = {} } end, "next")
typed/builtin//modules/world_vcs/M/__withInstallRefusals
M.__withInstallRefusals(msg: string, readRows: () -> { any }, pace: (() -> ())?, placed: { [string]: boolean }?) -> string
A refused push's text, followed by what the refusal asks of the installs
it reached (M.__releaseTakenByRowInstalls) when it names any. The
world's rows are read only for a RELEASE_VERSION_TAKEN refusal, and a
read that fails leaves the text as it is.
Parameters
msgstring— The refused push's text.readRows() -> { any }— Reads the world's pulled rows.pace(() -> ())(optional) — Called between rows; nil runs straight through.placed{ [string]: boolean }(optional) — Receives thepathof each taken entry the paragraph names in an install (M.__releaseTakenByRowInstalls); nil receives nothing.
Returns string — The text, with the paragraph for the installs the refusal reached.
worldVcs.__withInstallRefusals(msg, function() return {} end)
typed/builtin//modules/world_vcs/M/__withStoodFor
M.__withStoodFor(stands: { { asset_guid: string, checksum: string } }?, more: { { asset_guid: string, checksum: string } }) -> { { asset_guid: string, checksum: string } }
stands with each version of more it does not name yet appended, in
order, as a record's stands_for lists them.
Parameters
stands{ { asset_guid: string, checksum: string } }(optional) — The versions a record stands for, or nil.more{ { asset_guid: string, checksum: string } }— The versions to add.
Returns { { asset_guid: string, checksum: string } } — The versions.
worldVcs.__withStoodFor(nil, { { asset_guid = "g", checksum = "c" } })
typed/builtin//modules/world_vcs/M/__withTopLevelValues
M.__withTopLevelValues(json: string, values: { [string]: string }) -> string
A JSON object's text with the values of some of its top-level keys
replaced: each key values names takes the JSON text given for it, a key
the object lacks is added before its closing brace, and every other byte
of the object stays as it was written.
Parameters
jsonstring— The object's JSON text.values{ [string]: string }— The JSON text of each value to set, by key.
Returns string — The object's text with those values; json itself when it does not read as an object.
worldVcs.__withTopLevelValues('{"deps":[],"install_root":true}', { deps = '[{"asset_guid":"a"}]' })
typed/builtin//modules/world_vcs/M/__withoutInstallRows
M.__withoutInstallRows(status: any?) -> any
A status read without the rows of the installs it lists: an install is
one entry of installs, so none of its rows (its root, the files beneath
it, its dependencies) stands in dirty, staged or untracked as well.
Nor does a row an install record took the place of (replaced).
Parameters
statusany(optional) — The status read, carryinginstalls.
Returns any — The status with those rows left out.
worldVcs.__withoutInstallRows({ dirty = {}, staged = {}, untracked = {}, installs = {} })
typed/builtin//modules/world_vcs/M/__workingVersion
M.__workingVersion(path: string) -> string?
The version the working copy holds of the file at path: the content
address the blob store holds its bytes under, or the sha-256 of the bytes
a read returns. nil for a path holding no file the working copy reads.
Parameters
pathstring— The path, engine-canonical.
Returns string? — The version, or nil.
worldVcs.__workingVersion("/zero/source/a.md")
typed/builtin//modules/world_vcs/M/__worldRowsUnder
M.__worldRowsUnder(top: string) -> { string }
The paths of the rows of this world's own at and under a folder: what it added inside installed content, folder assets included, and every file it changed there.
Parameters
topstring— The folder's VFS path.
Returns { string } — The paths, empty where the world holds no row of its own there.
worldVcs.__worldRowsUnder("/zero/source/vendor/kit.package")
typed/builtin//modules/world_vcs/M/__worldVisibility
M.__worldVisibility(read: (req: { [string]: any }) -> any, worldGuid: string) -> string?
The visibility ZeroMind states for the world worldGuid: public,
unlisted or private. A reference to content installed from a public
world names that world at the commit the install read; content of a
world that is not public is pinned by an asset entry, whose version
ZeroMind ships with the content that pins it.
Parameters
read(req: { [string]: any }) -> any— Reads one ZeroMind record (zeromindWorldRead); it is asked forgetWorld.worldGuidstring— The world.
Returns string? — The visibility, or nil when the read fails or states none.
worldVcs.__worldVisibility(read, "5f6bfcfb-2258-47d9-8f1e-8f684f85e1f3")
typed/builtin//modules/world_vcs/M/__writeLibraryMarker
M.__writeLibraryMarker(path: string, bytes: string)
Write a library's marker to the world's source: the bytes the commit records as the pin. Raises with the reason the write was refused.
Parameters
pathstring— The library pin path,/zero/source/libs/@<name>.bytesstring— Thezero/world-import/v1marker bytes.
worldVcs.__writeLibraryMarker("/zero/source/libs/@builtin", marker)
typed/builtin//modules/world_vcs/M/__writtenAmong
M.__writtenAmong(paths: { string }, dirtyReads: { { any } }) -> { WrittenPath }
The paths among paths a caller of another account is writing now,
read off the dirty rows the status reads list. A read lists a row only
while the area it asks about does not hold the row's current bytes, so
the read taken before a staging call is the one that names who wrote
what it staged.
Parameters
paths{ string }— The paths a staging call staged.dirtyReads{ { any } }— Lists of dirty rows, earliest read first.
Returns { WrittenPath } — One { path, by, account } row per such path, in the order paths lists them.
worldVcs.__writtenAmong({ "/zero/source/a.luau" }, { before.dirty })
typed/builtin//modules/world_vcs/M/__writtenBefore
M.__writtenBefore(path: string) -> WrittenBefore
What path stands at before the world writes content back at it: the
version the working copy holds of the file (__workingVersion), and the
version the asset index states of the asset at the path and of every
folder asset enclosing it below the world root, the assets a write that
changes the file moves.
Parameters
pathstring— The path the world is about to write, engine-canonical.
Returns WrittenBefore — The versions before the write.
worldVcs.__writtenBefore("/zero/source/Big.module/init.luau")
typed/builtin//modules/world_vcs/M/__writtenByAnotherAccount
M.__writtenByAnotherAccount(row: any?) -> boolean
Whether a dirty row is the work in progress of a caller of another
account: a caller whose session is open wrote it (writer is
"other") and acts for an account other than the calling caller's. The
rows the account's other engines and agents write are the account's own.
Parameters
rowany(optional) — One dirty row as a status read reports it,{ path, writer, same_account }.
Returns boolean — True for a row a caller of another account is writing now.
worldVcs.__writtenByAnotherAccount({ writer = "other", same_account = false }) --> true
typed/builtin//modules/world_vcs/M/installInto
M.installInto(world: WorldNamespace)
Parameters
worldWorldNamespace
typed/builtin//modules/world_vcs/M/installOpenBackfill
M.installOpenBackfill()
Subscribe the open's read-only work to the world becoming ready: the
derived outputs a closed engine left computing are resumed, the update
check tells the person what has newer versions, and the publish reminders
(world_vcs.publishReminders) start telling the agents at work what keeps
the world unpublished. Each runs as its own task,
off the open's critical path, and writes nothing into the world. Called once
from prelude.luau after the engine global is set.
worldVcs.installOpenBackfill()
typed/builtin//modules/world_vcs/dependencies/M/canonical
M.canonical(path: string) -> string
A path in the /zero/source/... spelling: /source/... and a path
relative to /zero/source are taken there, a trailing / dropped.
Parameters
pathstring— A path.
Returns string — The path.
dependencies.canonical("/source/deps/w/a.module") --> "/zero/source/deps/w/a.module"
typed/builtin//modules/world_vcs/dependencies/M/installHolding
M.installHolding(summaries: { any }, source: string, skip: string?) -> string?
The install whose files source is one of: the install at or above
it (one still installed), or the install whose record places the
dependency holding it. An install another install's record places
(carried_by) answers that install. Nil for a file of the world's own.
Parameters
summaries{ any }— Whatinstall.summariesanswers.sourcestring— A source path.skipstring(optional) — An install to leave out, or nil.
Returns string? — The destination of the install, or nil.
dependencies.installHolding({ { path = "/zero/source/b.package" } }, "/zero/source/b.package/init.luau", nil) --> "/zero/source/b.package"
typed/builtin//modules/world_vcs/dependencies/M/installInto
M.installInto(world: WorldNamespace, opsOf: () -> DependencyOps)
Graft uninstall and removeUnusedDeps onto the supplied world
namespace and, in the engine, start the unused-dependency notice.
world_vcs.installInto calls this once at boot.
Parameters
worldWorldNamespace— The target namespace.opsOf() -> DependencyOps— Answers the operations to run through.
require("modules.world_vcs.dependencies").installInto(world, opsOf)
typed/builtin//modules/world_vcs/dependencies/M/installsRunning
M.installsRunning(summaries: { any }, requirers: { InstallRequirer }, dest: string) -> ({ string }, { string })
The installs whose files run the root of the install at dest, and
those files: each requirer with a site running the install's own copy at
or under its root, sorted by path, and the installs holding them, sorted,
the install itself left out. A site running a dependency the install
placed counts toward the dependency's use (DependencyUse), which keeps
that dependency with the install's record.
Parameters
summaries{ any }— Whatinstall.summariesanswers.requirers{ InstallRequirer }— What the engine answers for the install's requirers.deststring— The install's root.
Returns ({ string }, { string }) — The installs and the files.
dependencies.installsRunning({}, {}, "/zero/source/a.package")
typed/builtin//modules/world_vcs/dependencies/M/isRecordedVersion
M.isRecordedVersion(path: string) -> boolean
Whether path stands in a recorded version's folder
(/zero/source/deps/<world>/versions/<checksum>/...): a copy of one
version of an asset the engine landed for the content that runs it.
Parameters
pathstring— A canonical path.
Returns boolean — True inside a recorded version's folder.
dependencies.isRecordedVersion("/zero/source/deps/w/versions/c1/kit.package") --> true
typed/builtin//modules/world_vcs/dependencies/M/isUninstalled
M.isUninstalled(summary: { path: string, removed_paths: { string }? }) -> boolean
Whether the install record summary describes was uninstalled: the
record names its root, or a folder holding it, among the paths deleted
from it. Such a record installs nothing at its root; it stays in the world
only to place the dependencies something else uses.
Parameters
summary{ path: string, removed_paths: { string }? }— One entry of whatinstall.summariesanswers:{ path, removed_paths? }.
Returns boolean — True when the record's root is deleted.
dependencies.isUninstalled({ path = "/zero/source/kit.package", removed_paths = { "/zero/source/kit.package" } }) --> true
typed/builtin//modules/world_vcs/dependencies/M/noticeFor
M.noticeFor(unused: { UnusedDependency }, lastKey: string?) -> (string, boolean, { [string]: any })
The notice state for one look at the world: the unused paths, and whether they are a change from the last notice posted.
Parameters
unused{ UnusedDependency }— The unused dependencies.lastKeystring(optional) — The key of the last notice posted, or nil.
Returns (string, boolean, { [string]: any }) — The key of this set, whether to post, and the notice's params.
dependencies.noticeFor({}, nil)
typed/builtin//modules/world_vcs/dependencies/M/onlyPaths
M.onlyPaths(only: any?, fn: string) -> { string }?
The only option as a list of canonical paths: nil, one path, or a list.
Parameters
onlyany(optional) — What the caller passed.fnstring— The calling function's name, for the error.
Returns { string }? — The paths, or nil when every dependency is meant.
dependencies.onlyPaths("/source/deps/w", "world.removeUnusedDeps")
typed/builtin//modules/world_vcs/dependencies/M/placersOf
M.placersOf(summaries: { any }, path: string, placedBy: string?) -> { string }
The installs whose records place the dependency at path: placedBy
(the record the engine names for it) first, then every other record that
states the path among its dependencies and does not name it deleted. Two
installs that hold one copy of a dependency release each place it, and the
copy leaves the world only once no record places it.
Parameters
summaries{ any }— Whatinstall.summariesanswers.pathstring— The dependency's root.placedBystring(optional) — The install the engine names as placing it, or nil.
Returns { string } — The destinations of the installs placing it, without repeats.
dependencies.placersOf({ { path = "/zero/source/b.package", deps = { { path = "/zero/source/deps/w/a.module" } } } }, "/zero/source/deps/w/a.module", "/zero/source/a.package")
typed/builtin//modules/world_vcs/dependencies/M/removeUnused
M.removeUnused(opts: { dryRun: boolean?, only: any? }?, ops: DependencyOps) -> RemoveUnusedReport
Remove the dependencies under /zero/source/deps/ that nothing in the
world uses, or with dryRun list them. A dependency an install placed is
deleted from that install's record (the record is taken out once it holds
nothing); one the world holds as rows of its own is removed as files.
Parameters
opts{ dryRun: boolean?, only: any? }(optional) —{ dryRun?, only? }.opsDependencyOps— The operations to run through.
Returns RemoveUnusedReport — A RemoveUnusedReport.
dependencies.removeUnused({ dryRun = true }, ops)
typed/builtin//modules/world_vcs/dependencies/M/uninstall
M.uninstall(path: string, opts: { dryRun: boolean? }?, ops: DependencyOps) -> UninstallReport
Remove the install at path with the dependencies only it used. A
dependency something else in the world uses stays and is named with what
uses it, and the install's record then stays only to place it: the record
names the install's root deleted, and world.installs() no longer lists
it. A recorded version's copy (deps/<world>/versions/<checksum>/) that
only the install's content ran leaves with it, removed as files. When
another install's files run the install's root, the root is
handed to that install (handed_to, the first by path when several run
it): its record places the copy at moved_to, where a fresh install of it
places it, with every dependency the uninstalled install placed, and the
uninstalled install's record leaves the world; nothing is removed. A file of the install or of a dependency this world changed or wrote
itself stays where it stands as a file of the world. An install whose
record another install's record places (carried_by) leaves through
that record: it is written again naming the record deleted, and the
world's own row at the record, when it holds one, is taken out.
Parameters
pathstring— The install's root.opts{ dryRun: boolean? }(optional) —{ dryRun? }.opsDependencyOps— The operations to run through.
Returns UninstallReport — An UninstallReport.
dependencies.uninstall("/zero/source/skate_physics.package", { dryRun = true }, ops)
typed/builtin//modules/world_vcs/dependencies/M/unused
M.unused(ops: DependencyOps, only: { string }?) -> { UnusedDependency }
The dependencies nothing in the world uses, as the engine answers it,
held to only when given: a dependency is kept when its root is one of
those paths or lies under one.
Parameters
opsDependencyOps— The operations to read through.only{ string }(optional) — The paths to hold the answer to, or nil.
Returns { UnusedDependency } — The unused dependencies, sorted by path.
dependencies.unused(ops, nil)
typed/builtin//modules/world_vcs/dependencies/M/watch
M.watch(ops: DependencyOps, ready: () -> boolean)
Watch the world for unused dependencies and post a notice when the set of them changes. Reads only: it writes nothing to the world. Looks again only when the engine's dependency stamp moved, every install is materialized and the world's content has arrived. Started once.
Parameters
opsDependencyOps— The operations to read through.ready() -> boolean— Whether the world's content has arrived.
dependencies.watch(ops, function() return true end)
typed/builtin//modules/world_vcs/dependencies/world/removeUnusedDeps
world.removeUnusedDeps(opts: { dryRun: boolean?, only: any? }?) -> RemoveUnusedReport
Remove the dependency copies under /zero/source/deps/ that
nothing in this world uses, or with dryRun only list them. A
dependency is used when an install record lists it, when a source of
the world (its own content or an install's) has a reference site that
runs a copy in it, or when a used dependency has such a site. A site
runs one copy of what it names, so a recorded version's copy under
versions/ is used only by the sites that run that version. A
dependency an install placed is deleted from that install's record;
one the world holds as files of its own (written by hand, or left by
an earlier engine's install) is removed as files. Nothing is
committed: removed files leave as deletions in the next commit, and a
changed install record is a change the next commit carries. The
engine posts a notice whenever the world comes to hold unused
dependencies, naming them.
Parameters
opts{ dryRun: boolean?, only: any? }(optional) —{ dryRun?: boolean, only?: string | { string } }:onlyholds the call to the dependencies at or under those paths.
Returns RemoveUnusedReport — { dry_run, removed = { { path, guid?, files, placed_by?, modified } }, failed = { { path, reason } }, note }: removed lists what went (with dryRun, what a call without it removes), and modified the files in a dependency this world changed or wrote.
world.removeUnusedDeps({ dryRun = true })
world.removeUnusedDeps()
world.removeUnusedDeps({ only = "/zero/source/deps/0d6c9a2e-4b1f-4c3e-9a7d-2f5e8b1c4d6a" })
typed/builtin//modules/world_vcs/dependencies/world/uninstall
world.uninstall(path: string, opts: { dryRun: boolean? }?) -> UninstallReport
Remove the install whose root is path (one entry of the world)
together with the dependencies
it placed or used that nothing else in the world uses. A dependency
something else uses stays, and kept names what uses it; the install's
record then stays only to place it, and world.installs() no longer
lists the install. Installing the asset again puts its files back. A file of
the install or of a dependency this world changed or wrote itself
stays where it stands as a file of the world, listed in
kept_modified. Library content (/zero/source/libs, @builtin) is
never touched. Nothing is committed: the install's removal (or its new
state) is the change the next commit carries. world.installs() lists
the installs. An install whose record another install's record places
(carried_by names that install) leaves through that install's
record, which is written again naming the record deleted. When the
files of another install run the install's root (that install was
installed while the root stood, so its own install placed no copy),
the root's copy is handed to it: the uninstalled install stops being an
install of its own, its copy moves to
/zero/source/deps/<world>/<name>, where a fresh install of the
remaining install places it, the remaining install's record places it
there with every dependency the uninstalled install placed, and
handed_to names the remaining install while kept names the root
with the files that run it. The world then stands as if only the
remaining install had been installed, and nothing it runs goes missing.
Parameters
pathstring— The install's root, e.g./zero/source/skate_physics.package.opts{ dryRun: boolean? }(optional) —{ dryRun?: boolean }: list what would go and stay, change nothing.
Returns UninstallReport — { root, dry_run, removed = { { path, reason } }, kept = { { path, reason, users } }, kept_modified = { path }, carried_by?, handed_to?, moved_to?, note }.
world.uninstall("/zero/source/skate_physics.package", { dryRun = true })
world.uninstall("/zero/source/skate_physics.package")
typed/builtin//modules/world_vcs/world/add
world.add(paths: string | { string }, opts: AddOpts?) -> AddReport
Stage one path's manifest row, or each of a list of paths,
expanding to the full asset family if a path lives inside a composite
asset. Idempotent at (stage, manifest_row). A list stages every row
its paths select once, so naming several files of one asset stages
that asset's family once, as git add a b c does. Pass { force = true } to bypass
the .zmignore / .gitignore gate — same intent as
git add -f. Without force, attempts to stage an ignored
path (or a path whose .refs points at an ignored dep)
error.
{ stage = "<name>" } stages into the named area, shared with
whoever else names it, instead of the caller's own, so a commit
naming that area freezes these paths and leaves every other area's
staged.
Staging is advisory, and a path is staged in one area at a time.
Naming a path another staging area holds takes it from that area,
whichever account opened it and whether or not its session is open,
and the report names the area, its account and whether that session
is working now in released. A take from an area of another account
warns, naming that account, the area and its session; a take from
another agent or engine of the caller's own account does not. A
staged path a caller of another account is writing now is named in
written and warned about the same way.
A staged source that references an asset whose current version no
commit holds needs that version committed with it. The asset is
staged beside the source, taken from any other area holding it, and
named in carried.
A .scene stages as its files on disk hold it, in edit and in play
alike; live entity edits nobody saved stay in the session, and a
notice names them with the calls that keep or drop them.
An installed asset is staged by its root path: every row of the install
(its files, its dependencies under /zero/source/deps/) is staged with
it, as world.vcsStatus().installs lists it. A path that is one of the
other rows of an install raises, naming the install and its root. A
file the world changed inside an install held as one record (under the
install's root, or under a dependency it places in
/zero/source/deps/) stages with the changed rows beneath that root,
and the root itself is left out: the record is the row that versions
it. Naming the destination of such an install stages its record
(<root>.pull) when the record changed, so an install, an update and
an uninstall each reach a commit by the path world.vcsStatus lists
them under. A file
world.vcsStatus lists with the reason references moved stages like
any change: its row carries its live reference table and its bytes are
the ones the branch head already holds.
Parameters
pathsstring | { string }— The path to stage, or a non-empty list of paths. Each must be a non-empty string; a gate refusing any of them refuses the call before anything is staged.{ renormalize = true }first restates every folder asset's row at or beneath the named paths from the files beneath it, asgit add --renormalizedoes: a folder whose stated version is not the folder hash of its files is staged at the hash its files hold, and a folder that already states it is left out.optsAddOpts(optional) — Optional{ force: boolean?, renormalize: boolean?, stage: string? }. Defaults to{ force = false }on the calling caller's own staging area.
Returns AddReport — What the call staged: staged lists the rows the paths name (the asset family of a path inside an asset; otherwise the path and every changed row beneath it, deletions included, so a deleted asset folder stages the deletion of each of its files), leaving out with a warning naming it each path no row at or beneath which holds a change, carried the referenced assets staged beside them because no commit holds their current version, released each path taken from another staging area (stage, its account, same_account, its session and whether that session is live), and written each staged path a caller of another account is writing now (by, account). Each carried row, and each released and written row of another account, is also written to the caller as a warning.
world.add("/source/foo.luau")
world.add({ "/source/a.luau", "/source/b.luau" })
world.add("/source/scene_dirty/entities/42.json", { force = true })
world.add("/source/fauna.module", { stage = "fauna" })
world.add("/source/fauna.module", { renormalize = true })
typed/builtin//modules/world_vcs/world/add_all
world.add_all(opts: AddAllOpts?) -> ({ string }, AddAllReport)
Stage every dirty manifest row, whoever wrote it, skipping any
path that matches .zmignore / .gitignore. Paths that match an
ignore pattern are skipped; world.add(path, { force = true }) is the
explicit way to override the gate for an individual path.
Rows still flagged conflicted by world.pullAsset are held back
too: resolve them (edit + world.add(path), or
world.resolvePullConflict) and re-run.
Staging is advisory. The working tree is one per branch and staging
areas are not, and a path is staged in one area at a time: a path
another staging area holds is taken from that area, whichever account
opened it and whether or not its session is open, and named in
released with the area, its account, its session and whether that
session is live. A row another caller is writing is staged like any
other. The calling account's own agents and engines never warn each
other: their areas and their writes are the account's own. A take
from another account's area warns once per area, naming the account,
the area and its session, and saying that account is working on the
paths now when its session is open; a staged path a caller of another
account is writing now warns once per caller and is named in
written.
Each staged path brings its asset family. A file world.vcsStatus
lists with the reason references moved is staged too. The call reads the
working tree a fixed number of times and stages and releases in
batches, so its cost follows the size of the dirty set.
A scene stages as its files on disk hold it, in edit and in play
alike: live entity edits nobody saved stay in the session, and a
notice names each scene holding some, with the calls that write
them into scene.json (sceneAuthoring acceptChanges,
layers.active:save()) or drop them.
Parameters
optsAddAllOpts(optional) — Optional{ stage: string? }.stagenames the staging area to stage into; omitted, the call stages into the calling caller's own area.
Returns ({ string }, AddAllReport) — The paths that were held back: the conflicted ones. Empty when none were. The second value reports the call in full: staged lists the paths it added to the staging area, held lists every held-back path with its reason ("conflicted"), released lists each path taken from another staging area (stage, account, same_account, session, live), and written each staged path a caller of another account is writing now (by, account).
world.add_all()
world.add_all({ stage = "fauna" })
local held, report = world.add_all()
typed/builtin//modules/world_vcs/world/affirm
world.affirm(token: string)
Consume an XXX-XXX-XXX-style affirmation token returned by
a destructive op surface (e.g. vfs.remove). The destruction
commits atomically with the pending-row delete; the token is
one-shot. Errors verbatim on expiry / wrong-user.
Parameters
tokenstring— The affirmation token.
world.affirm("ABC-DEF-GHI")
typed/builtin//modules/world_vcs/world/assetInstallable
world.assetInstallable(opts: AssetInstallableOpts) -> AssetInstallableReport
Report whether one published asset can be installed on its own,
without raising. world.previewInstall plans a real install and
raises when the closure will not resolve; this answers the prior
question — does this guid name something ZeroMind will hand over by
itself — as a verdict a caller can branch on. Content that ships
inside a larger library (a module inside a package, a material
inside a system) carries its own published identity, so the answer
is per asset rather than per library. Reads only.
Parameters
optsAssetInstallableOpts—{ guid }names the asset;refasks about it as a branch, a tag or a commit id of the world it is published from holds it.
Returns AssetInstallableReport — An AssetInstallableReport — installable, a verdict, a one-line detail, and the closure's nodes / tree_children / deps shape when one resolved.
world.assetInstallable({ guid = asset.guid("@builtin::materials.neon") })
typed/builtin//modules/world_vcs/world/awaitCommit
world.awaitCommit(commitId: string, seconds: number?) -> { state: string, landed: boolean, lines: { string } }
Wait, for at most seconds (default 90), until the commit
world.commit returned is on the branch, and say where it stands.
state is landed once it is a commit of the world, sealed while it
is sealed behind its derived outputs, and absent when it was
unsealed. A sealed answer ends the wait early when a required output
failed or the commit's landing was refused, since neither moves on its
own. lines states it the way zm commit prints it: that the commit is
sealed and not on the branch, what it waits on, and the commands that
move it (zm derived retry, zm derived provide, zm unseal).
Parameters
commitIdstring— The idworld.commitreturned.secondsnumber(optional) — How long to wait for it to land; 0 reads where it stands now.
Returns { state: string, landed: boolean, lines: { string } } — { state, landed, lines }.
local id = world.commit("add the rock"); local where = world.awaitCommit(id); if not where.landed then print(table.concat(where.lines, "\n")) end
typed/builtin//modules/world_vcs/world/awaitOutgoingSync
world.awaitOutgoingSync()
Wait until every /source write this session made has reached
the branch it was written against. Raises naming the paths that did
not land. add / commit / push / checkout / merge / pull
already wait on their own; call this before rebinding after a burst
of writes, which world.checkout and world.swap refuse over.
Returns Nothing. Raises when a write did not land.
world.awaitOutgoingSync() ; world.checkout("main")
typed/builtin//modules/world_vcs/world/beforeCommit
world.beforeCommit(name: string, fn: ((any) -> ())?)
Open-or-resume a staging area, set the message, and materialise
the commit. Commits ONLY what's already staged via world.add /
world.add_all — git semantics, not git commit -a. The reducer
auto-deletes the stage row on success so a subsequent
world.commit opens a fresh one.
Where derive hooks compute outputs for the staged content, the commit
is sealed under its id first and lands once every required output is
computed. The id this returns can name a commit that has not landed
yet: world.vcsStatus().sealed lists the sealed commits with what each
waits on, and world.unseal returns one to the staging area. When an
older sealed commit holds a refusal, this commit queues behind it and
the call says so.
{ stage = "<name>" } materialises one of the caller's own staging
areas, so the commit carries the paths staged under that name and
leaves every other caller's staged. When a commit from another
caller has landed since the area was opened, this brings the area
onto the branch head there is now and commits it there.
A staged scene is frozen as staged. Live entity edits its overlay holds that nobody saved stay in the session, and a notice names them once the commit lands.
Pre-flight .zmignore refs gate: every staged source's
aggregated deps (via asset.deps, which recurses composite
asset folders) are checked against the live ignore set. If
any dep target's path is currently ignored AND the dep target
is not itself in the stage, the commit is refused. This
mirrors the closure invariant — a commit whose deps can't
resolve cleanly shouldn't land. Force-staging the dep
alongside (world.add(dep, { force = true })) makes the
ignored dep satisfy the gate.
Run fn at the start of every world.commit, before the commit
reads what is staged — the moment to write content that belongs in
the commit being made, and stage it. fn receives { stage }, the
staging area the commit materialises (nil for the caller's own), to
pass to world.add. Registering a name again replaces what it held,
and fn = nil removes it. A hook that raises refuses the commit,
naming the hook.
Parameters
namestring— What identifies the hook.fn((any) -> ())(optional) — The hook, or nil to remove it.
Returns The newly-allocated commit id (ULID string).
local id = world.commit("feat: ship widget")
local id = world.commit("fauna: the swallow colony", { stage = "fauna" })
world.beforeCommit("procgen.diskcache", function(ctx) ... end)
typed/builtin//modules/world_vcs/world/branches
world.branches() -> { { branch: string, commit_id: string, current: boolean } }
Every branch this world has, with the commit each one's head
names and which one this session is on — git branch --list. Sorted
by name. A branch exists for everyone in the world; which one you are
on is yours alone, so current is true for at most one row here and
says nothing about where anybody else is.
Returns { { branch: string, commit_id: string, current: boolean } } — Array of { branch, commit_id, current }.
for _, b in ipairs(world.branches()) do print(b.branch, b.commit_id) end
typed/builtin//modules/world_vcs/world/checkUpdates
world.checkUpdates() -> ({ UpdateReport }, { UpdateSkip })
Discover which units of this world have an update available. Read-only — makes no local mutation and no VCS write. A unit is one of:
- a library: a marker (
/source/libs/@<name>,@builtinincluded) whoserequested_ref(defaultmain) now resolves in the library's world to a commit other than the marker'sresolved_commit.@builtinis compared with the published commit of it this engine runs instead, when the engine names one: a pin older than it is reported withbehind_engine = trueandtonaming that commit when moving it there changes an asset the world's own content names, or one such an asset reaches through the library's reference tables (other than an engine-owned part a play of the world runs at the engine's own version whatever the pin names; a component counts, since a play runs the pinned version of it); an older pin whose move changes none of them, and a pin at it or newer than it, are current. A world on an older@builtinis hidden from players. Apply withworld.updateLibrary(name). - an installed asset: an install root (the asset that was installed;
its reference table marks it) whose recorded version differs from the
newest version of that asset at its origin, one lookup per root.
Apply with
world.update(<root path>)(zeromind.update), which installs the root's new closure with each dependency at the version the new root records. - a dependency an install record places (under
/source/deps/): the release the record states for it differs from the newest release of that asset in the dependency's own origin world. The entry names the dependency's path asroot_pathand the install that places it asplaced_by. Apply withworld.update(<dependency path>), which writes that install's record again at the version it holds with the dependency at the new release, and each file of the install written against the old release runs against the new one.
Installed assets whose origin world is a library's world are part of that library's unit. A pulled row that no table marks as an install root (an install older than the marks, content forked from another world) is not reported.
Returns ({ UpdateReport }, { UpdateSkip }) — Two values: an array of UpdateReport (libraries first), each { kind = "library", library, from, to, behind_engine? } or { kind = "asset", root_path, root_guid, display_name, from, to }, empty when everything is current; and an array of { name, reason } for the units whose origin could not be reached, which never fail the whole call.
local reports, skipped = world.checkUpdates()
typed/builtin//modules/world_vcs/world/checkout
world.checkout(branch: string, opts: { follow: boolean? }?) -> string
Switch this session to another branch — git checkout <branch>.
The branch must already exist (create one with world.createBranch).
The tree is replaced by the branch's own content. Which branch this
session is on is this session's alone; the branch itself is shared,
so others may be on the one you move onto.
Your uncommitted changes and staged entries come with you, as git
keeps them across a switch: each lands on branch as it read
before. When the switch would replace a path you changed with a
different version, the call refuses with git's message naming the
paths and nothing moves — commit or stash them first. A file your
.zmignore / .gitignore rules ignore that neither branch tracks
never refuses the switch: it comes with you where branch holds no
copy of its own, and otherwise each branch keeps its own copy. An
ignored path a branch tracks is a tracked file like any other.
Another caller's uncommitted changes stay on the branch they were
made on.
The switch is all or nothing: a write of yours still on its way to
the branch you leave is waited for, and one that does not arrive
refuses the switch before anything moves; a switch refused after
your changes moved puts them back, and names each path that does not
read as it did.
A switch made in play takes down the running world and ends its play
session: while that session holds unaccepted changes the switch is
refused before anything moves, with the accounting
engine.mode = "edit" gives, and engine.discardPlayChanges() arms
the next switch past it.
Returns only once the branch's content has landed, so world.head,
world.log, world.commit and the VFS all target the new branch
immediately afterwards.
In an agent's own client the user's client switches to the branch
once this one has, unless opts.follow is false (its play/edit mode
stays its own); it switches on its own time, and a switch it could
not make is told to you as a notice. A switch to the branch this
client is already on moves nothing.
Parameters
branchstring— The branch to switch to.opts{ follow: boolean? }(optional) — Optional{ follow: boolean? }.
Returns string — The branch now checked out.
world.checkout("feature")
world.checkout("feature", { follow = false })
typed/builtin//modules/world_vcs/world/checkoutPaths
world.checkoutPaths(rev: string, paths: { string }, opts: CheckoutPathsOpts?) -> { string }
Write paths as a revision holds them, and stage them: git checkout <rev> -- <path>.... rev is any revision world.revParse
reads. Each path comes back as the asset the revision records: its
asset guid, its bytes and its kind, so what refers to it by guid keeps
resolving, and restoring it again gives the same asset again. A folder,
a composite asset's or a plain directory, brings back every file the
revision holds beneath it, so a deleted component, module or package
comes back whole; a file beneath it the revision does not hold stays.
A file whose folder asset was deleted brings the folder back with it.
Binary files come back by their content. A path whose version is the
branch head's reads clean afterwards and leaves the staging area; any
other is staged. The paths that name nothing the
revision holds are refused together, naming each, and nothing is
written. Returns once the working copy holds every written path as the
revision records it, and every file whose reference table pins a
written path is derived again, so it names the version the working
copy holds and world.vcsStatus lists it as references moved when
that differs from the head's.
Parameters
revstring— The revision to read.paths{ string }— The paths to write: files, composite asset folders or directories.optsCheckoutPathsOpts(optional) — OptionalCheckoutPathsOpts:stage = falsewrites the working tree and leaves the staging area as it was (git restore --source <rev> -- <path>).
Returns { string } — The paths written, as the revision names them.
world.checkoutPaths("HEAD~1", { "/source/foo.luau" })
world.checkoutPaths("HEAD", { "/source/Doom.component", "/source/notes.md" })
world.checkoutPaths("HEAD~2", { "/source/levels" }, { stage = false })
typed/builtin//modules/world_vcs/world/checkoutSide
world.checkoutSide(path: string, side: string)
Take one side of an unmerged path — git checkout --ours|--theirs <path>. The path holds the side's whole content afterwards; a merge
conflict's side is the session branch (ours) or the branch merged
in (theirs), an installed asset's update conflict's side is your
local version (ours) or the upstream one (theirs). Record the
resolution with world.add and commit.
A merge conflict's side is that branch's committed version: its
bytes, its asset guid, its kind and its references, so what refers
to the asset by guid keeps resolving. Text, binary and composite
assets alike: a composite asset (a .scene, .package,
.component … folder) is taken whole — name its folder and the
folder and every file in it come from that side. A side that deleted
the path leaves it a pending delete. Taking a side again replaces
the earlier choice.
A file of an install the world holds as one record (<dest>.pull)
that the world wrote over, the file an update lists under
conflicted when the world's edit of it conflicts with the version
the install moved to: theirs takes the world's file out, so the
install's file of that version stands at the path, and ours keeps
the world's file.
Parameters
pathstring— The unmerged path, or the composite asset folder holding one.sidestring—oursortheirs.
world.checkoutSide("/source/foo.luau", "theirs")
typed/builtin//modules/world_vcs/world/commit
world.commit(message: string, opts: CommitOpts?) -> string
Parameters
messagestringoptsCommitOpts(optional)
Returns string
typed/builtin//modules/world_vcs/world/conflicts
world.conflicts() -> { ConflictEntry }
List every locally-pulled row currently flagged conflicted —
the findable surface world.pullAsset leaves behind on an
unresolved merge. Read-only.
Returns { ConflictEntry } — An array of ConflictEntry, one per conflicted row. Empty when nothing is conflicted.
local list = world.conflicts()
typed/builtin//modules/world_vcs/world/contentRequirements
world.contentRequirements(scope: { string }?) -> { ContentRequirement }
List the world's unmet content requirements: user-authored assets
whose type-declared content constraints are not yet satisfied (an
empty README, a .metadata with no description or tags — the
empty-skeleton state a fresh create emits for the author to fill, and
a description the type asks for that still starts with the
[[describe]] placeholder, which describes = true marks on the
row; world.push asks for a description only of the assets the push
changes).
The same walk world.push gates on, over the whole world: the
push refuses over every row whose asset it publishes, and
world.publishBlockers reports those rows as the content class
beside the other two. Empty list = every checked asset meets its type's
contract. A write into an asset reports the rows its type's
type.yaml requirements give for that asset as it lands:
contentRequirements on the vfs.write report and on the MCP
write_file / edit_file result.
Parameters
scope{ string }(optional) — Asset paths to restrict the check to — pass a status read's dirty + staged paths to check only content that would actually publish (a per-file path matches its containing asset; each path resolves directly, with no world enumeration). Omit for the full-world walk the push gate performs.
Returns { ContentRequirement } — Array of ContentRequirement rows — { asset, typeName, detail, path, describes?, file?, remedy? }, where path is the asset the row is about and remedy the action its type's validate hook names for it.
for _, r in ipairs(world.contentRequirements()) do print(r.asset, r.detail) end
typed/builtin//modules/world_vcs/world/contribute
world.contribute(opts: ContributeOpts?) -> { ContributeOutcome }
Send improvements to installed content back upstream — git subtree push ending in a pull request. For each targeted origin
world: the diverging subtree is remapped to the origin's canonical
paths, three-way merged against the origin's CURRENT content
(regions the origin also changed become local conflicts to
resolve first), pushed as a contrib-<id> branch and opened as a
pull request on the origin, which stays open: merge is opt-in, and
zm.prMerge merges. A change inside a folder asset (an asset inside
an installed package) publishes a new version of that folder under
the version its descriptor states (package.yaml of a .package),
so a root inside a package sends the package's descriptor with it
when this world changed it, and a refusal of a version the origin
already published (RELEASE_VERSION_TAKEN) names the descriptor in
this world to state a new version: in. An account holding a role
on the origin that pushes a branch there pushes the branch into the
origin; any other
account proposes from its own fork of the origin: the branch goes to
its public or unlisted fork (made the first time, then reused; the
world this engine is bound to is never that fork), and the pull
request is opened on the origin from <fork>:<branch>, so the origin
is written to only when its maintainer merges. Such an outcome names
the fork as source_world, forked when this call made it, and a
fork that is private or a draft is refused (SOURCE_PRIVATE) with
nothing sent. Each refusal ZeroMind answers a proposal from outside
with reaches the outcome's detail by its code (SOURCE_PRIVATE,
SOURCE_NOT_A_FORK, CONTRIBUTOR_BLOCKED, PROPOSAL_LIMIT_REACHED,
PROPOSAL_TOO_LARGE, RATE_LIMITED) with what to do. Each install
root the pull request covers keeps it as its contribution link, and
while that pull request reads open it stays the root's one pull
request: a later call sends the root's files as they stand now to
that pull request, advancing its branch by one commit whose tree is
the main of the world holding the branch (the origin, or the fork)
with the contribution laid over it (a file an earlier push changed
that the root no longer changes is put back as that main holds it,
and a main that moved since is merged in), in an outcome of its own (status = "open", its pr_number and branch, the root's paths, updated = true, or updated = false when the pull request already held the
files as they stand and nothing was pushed; roots sharing one pull
request share the outcome), while the origin's other roots go as one
new pull request; a merged or closed one, or one whose state cannot be
read, leaves the root to contribute afresh, and a root whose pull
request is found merged is first pulled again, so the call sends only
what its origin still lacks. dryRun answers the same way,
with plan for the roots it would send (naming the pull request a
root would be added to), and writes nothing. The Luau
a call sends is held to the script check a push of this world holds
the same files to: a root carrying an error a push would refuse is not
sent, and its outcome reads error naming each site. With merge = true the pull request is merged as it opens
when authorized — a refusal leaves it open and reported, never a
failure, its detail naming what the merge answered and the state and
mergeability the pull request reads after it; a merge whose answer is
not merged while the pull request reads merged goes on as merged — and
after a merge the local fork re-pulls so its origin pins advance and the
asset no longer reads as ahead.
Parameters
optsContributeOpts(optional) — OptionalContributeOpts—targets(origin world guids; default all ahead; one naming the world a dependency an install placed was published from, the guid of itsdeps/<guid>/folder, takes that dependency's changes, which with no target go to a pull request the dependency's root keeps open there and otherwise to the install's world),roots(install roots; default every installed asset ahead),merge(default false),title,description,dryRun.
Returns { ContributeOutcome } — Array of ContributeOutcome: for each targeted origin, one for the roots sent as a new pull request, and one per distinct open pull request some of its roots were added to (each names its pull request and only its own paths); status is open unless merged.
local r = world.contribute({})
typed/builtin//modules/world_vcs/world/convertInstalls
world.convertInstalls(opts: { only: string?, dryRun: boolean? }?) -> { { root_path: string, rows_removed: number, overrides_kept: number, files_added: number, completion: string? } }
Bring installs that stand as pulled rows (an earlier engine landed each
file as a row of the world) into one record row each, the form
world.installAsset writes now. The record is built from the rows
themselves, written, and once this engine has materialized the install
from it the unchanged rows are taken out of the world; a file changed
since the install stays a row of the world. Nothing is committed: rows
that were committed leave as deletions in the next commit. Returns one
entry per install, and with dryRun writes nothing. Once the rows are
taken out the record is stated again from the published version it
names, so an install the old engine cut short holds every file of the
version: files_added counts the files that added, and completion
says why the record stayed as the rows stated it (the published
version unreachable, or an asset of it that does not load as its type).
Each install converts whole or not at all: when neither the published
version nor the record the rows state runs, the record is taken out and
the rows are written back, and once every other install is converted
the call raises naming each install that stands as it did and why.
The files stay where they stand and the call yields between its steps, so
it never holds a frame: a run that outlasts the execute budget continues
as a task.
Parameters
opts{ only: string?, dryRun: boolean? }(optional) —{ only?: string, dryRun?: boolean }:onlynames one install by its root path.
Returns { { root_path: string, rows_removed: number, overrides_kept: number, files_added: number, completion: string? } } — { { root_path, rows_removed, overrides_kept, files_added, completion? } }.
world.convertInstalls({ dryRun = true })
typed/builtin//modules/world_vcs/world/createBranch
world.createBranch(name: string, fromCommit: string?, opts: { force: boolean? }?)
Create a branch — git branch <name> [<start>]. The branch
starts at fromCommit (defaults to the session branch's HEAD)
and gets its own working tree, materialized from that commit.
The session stays on its current branch; move onto it with
world.checkout("<branch>") (git checkout). With
{ force = true } (git branch -f) an existing branch is pointed
at fromCommit and its working tree rewritten to it, in one
transaction; that refuses only when the branch's working tree holds
uncommitted changes, which the rewrite would lose.
Parameters
namestring— The new branch name.fromCommitstring(optional) — Commit id to start at. Defaults toworld.head().opts{ force: boolean? }(optional) — Optional{ force: boolean? }.
world.createBranch("feature")
world.createBranch("feature", world.revParse("HEAD~1"), { force = true })
typed/builtin//modules/world_vcs/world/deleteBranch
world.deleteBranch(branch: string, opts: DeleteBranchOpts?)
Delete a branch — git branch -d|-D <name>. Drops the branch and
the working tree it owns; its commits are left alone, since deleting
a branch is dropping the name and the tree under it, not rewriting
history. Without opts.force (-d) it refuses a branch whose
commits the session's branch does not hold, and one whose working
tree holds uncommitted changes, naming them, since those go with the
tree; { force = true } (-D) deletes it regardless. Refuses the
branch this session is on (check out another first) and the world's
last branch.
Parameters
branchstring— The branch to delete.optsDeleteBranchOpts(optional) — OptionalDeleteBranchOpts—force.
world.deleteBranch("feature")
world.deleteBranch("experiment", { force = true })
typed/builtin//modules/world_vcs/world/derive
world.derive(name: string, spec: any?)
Register a computation whose output lands in the commit with the
content it is computed from. The hook (scope = "asset")
computes output inside each staged asset matches accepts, from the
asset as staged. Its fingerprint and compute are entries of
module, run on a worker.
Staging starts the work, and a required output that is not computed
holds the commit that carries it: world.commit seals the commit and
returns its id at once, and the commit lands with the outputs once
they are computed. When every required output is computed already,
world.commit returns after the commit landed. spec = nil removes it.
Parameters
namestring— What identifies the hook.specany(optional) — The hook, or nil to remove it.
world.derive("thumbs", { scope = "asset", output = "thumb.png", matches = function(ref) return ref.type == "texture" end, module = "@root::thumbs", fingerprint = "fingerprint", compute = "compute" })
typed/builtin//modules/world_vcs/world/diff
world.diff(...: string) -> any
Mirror git diff's CLI arg shape. Returns per-file diffs
by default; pass --stat for summary stats, --name-only for
just paths. Positional commit ids drive the two sources;
--staged pivots to staged-vs-HEAD. ---separated args
scope the diff to specific paths, each read as world.add reads a
path: a relative one names the file under /zero/source, and both
sides of the diff compare the file at that one path. An absolute path
before -- scopes the diff the same way. --stage=<name> reads the named
staging area in place of the calling caller's own. A working-tree
file a .zmignore / .gitignore rule matches is left out, as
world.vcsStatus() leaves it out of dirty; --ignored diffs those
files too. A file the staging area holds and a path named after --
are diffed whatever rule matches them.
Parameters
...string— Variadic string args: flags, commit ids,--, path filters.
Returns any — Array of DiffFile tables (or string-list for --name-only).
local files = world.diff()
local files = world.diff("--staged")
local files = world.diff("abc", "def")
local names = world.diff("--name-only")
local files = world.diff("--staged", "--stage=fauna")
local names = world.diff("--name-only", "--ignored")
typed/builtin//modules/world_vcs/world/diffUpstream
world.diffUpstream(root: string) -> { UpdateFile }
What your copy of an installed asset changed against the version
it was installed from — the diff zm diff <root> upstream prints.
One UpdateFile per file under root whose content differs from
its origin version (for an install's root, the files of the
dependencies it placed too, wherever they were moved), with the unified diff from the origin version
to yours for a text file (diff and hunks are nil for a binary
one). Empty when the installed asset holds no change of yours.
Parameters
rootstring— The installed asset's root path (or any path inside it).
Returns { UpdateFile } — Array of UpdateFile, sorted by path.
for _, f in ipairs(world.diffUpstream("/source/Doom.component")) do print(f.diff) end
typed/builtin//modules/world_vcs/world/discard
world.discard(opts: StageOpts?)
Drop a staging area without committing. Live manifest dirty flags are preserved so the user can re-stage later. No-op if the area doesn't exist.
Parameters
optsStageOpts(optional) — Optional{ stage: string? }naming the staging area to drop. Omitted, the call drops the calling caller's own area.
world.discard()
world.discard({ stage = "fauna" })
typed/builtin//modules/world_vcs/world/discardAll
world.discardAll(scope: string?) -> DiscardAllResult
Discard every change under a path in one operation — the whole
working tree by default. Every file edited since its commit goes back
to the committed version, every deletion comes back, and every file
no commit holds, an uncommitted install included, leaves the tree.
Each goes to trash first, where world.restore(<handle>) brings it
back. The paths a staging area holds stay, a staged file edited since
it was staged goes back to its staged copy, and a change another
account is making, a dependency another install records, and a file
listed only because its references moved (its bytes are the committed
ones) stay as well: they are named in kept. One backend operation takes the whole
scope back, and the call returns once the working copy reads as the
committed content. Every reference table that records a version taken
back, by this discard or an earlier operation, is derived again, so a
file whose table that leaves at the head's reads as the head holds it
and is neither discarded nor kept.
Parameters
scopestring(optional) — The VFS path to discard beneath; omitted, every path.
Returns DiscardAllResult — { discarded, paths, kept } — how many rows went back, which, and which rows under the scope stayed: another account or another install holds them, or only their references moved.
world.discardAll()
world.discardAll("/source/hud")
typed/builtin//modules/world_vcs/world/discardFile
world.discardFile(path: string)
Discard a path's unstaged working edits, taking it back to what
it was staged or committed as — the git restore <path> shape. A
folder takes every file beneath it back with it, and a deleted
path comes back as its committed version. The stage is the
baseline when the path is staged, the last commit when it is not,
and where neither holds anything at or beneath the path there is
nothing to come back to, so the path goes away. A path that does hold
committed or staged content stays: the files no commit holds beneath
it (a new file in a folder, a scene's autosave overlay) are left where
they are, and where they are its only change the call raises naming
them and world.discardAll, which takes them out. Staging is left
exactly as it was; world.unstage
is the verb that changes it. One shot: edited bytes that revert to
a committed version are snapshotted to trash first, so that case is
recoverable via world.restore(<handle>); a deletion taken back
throws nothing away and leaves no trash entry. Returns once the
working copy reads as the reverted content: text reads back as
committed, and binary bytes are served at the committed version on
the next read. Errors when nothing at or beneath the path is dirty
(nothing to discard).
An installed asset is discarded by its root path, which puts the whole
install back at the version the branch head holds as one unit: its rows
leave the staging area and then return to their committed version, or go
away when no commit holds them. A dependency another install records too
stays. Another row of an install raises, naming the install and its
root. An install the world holds as one record (<dest>.pull) goes
back to what that record states: a file of it the world wrote comes
back as the install's file, the record staying as it is, and its
destination puts the record back at its staged or committed version
with every file of it the world wrote. A file of it the staging area
holds keeps its staged version. A file whose only difference from the
head is its reference table
(listed with the reason references moved) raises too, naming what
moved its references and the undo: moving the library pin back
(world.updateLibrary, or discarding the pin marker) or reverting the
moved asset. Every reference table that records a version the discard
takes back is derived again once it lands, so a file that references
the discarded asset reads as the head holds it when the asset does; a
file listed only for a table recording a version taken back earlier
is derived again the same way, and its discard is done when that
leaves it as the head holds it.
Parameters
pathstring— The VFS path whose unstaged edits to discard.
world.discardFile("/source/foo.luau")
world.discardFile("/source/Doom.component")
typed/builtin//modules/world_vcs/world/dropDerived
world.dropDerived(outputPath: string, opts: { stage: string? }?) -> number
Leave the derived output at outputPath out of the commit. Only
an output whose hook is best-effort can be dropped; a required one is
refused, naming the other ways out (retry, provide, unseal), except
one whose asset holds no input file in the tree the commit lands on
nor in the working tree: the commit removes that asset, and its
output settles empty.
Parameters
outputPathstring— The output's VFS path.opts{ stage: string? }(optional) — Optional{ stage: string? }naming the staging area.
Returns number — How many reservations were dropped.
world.dropDerived("/zero/source/gold.material/extra.json")
typed/builtin//modules/world_vcs/world/fetch
world.fetch(branch: string?) -> FetchResult
Update the origin/<branch> remote-tracking ref — git fetch.
Mirrors the world's ZeroMind branch head into the local commit
history (no working-tree change) and reports how the session
branch relates to it: behind origin commits to pull, ahead
local commits to push, diverged when both, and sealed the
caller's sealed commits, which join the branch once their outputs
land and are ahead of origin beside ahead. A stale installed
pin or out-of-band ZeroMind change shows up here as behind —
reconcile with world.pull().
Parameters
branchstring(optional) — Remote branch to fetch. Defaults to the session branch.
Returns FetchResult — A FetchResult table.
local f = world.fetch()
typed/builtin//modules/world_vcs/world/foldCopy
world.foldCopy(opts: { copy: string, into: string, dryRun: boolean? }) -> FoldCopyReport
Recovery for installed content that was copied by accident instead
of edited in place: fold the copy back into the installed asset it was
copied from. Editing installed content in place is the normal flow
(the install becomes a modified install zm pr create offers back);
a copy is a new asset with its own guid, disconnected from the
install, and nothing reconnects it on its own. This call does, when
asked: each file of copy is written over the file at the same path
inside into (the installed asset keeps its guid and becomes a
modified install), every reference this world authors that names the
copy or a file in it is rewritten to name the installed asset, and
the copy is removed. Nothing is committed. into must be installed
content (an install's root or a dependency it placed, as
world.installs() lists them, or an asset inside one); copy must not
be.
Parameters
opts{ copy: string, into: string, dryRun: boolean? }—{ copy: string, into: string, dryRun: boolean? };dryRunreports what would be written and changes nothing.
Returns FoldCopyReport — A FoldCopyReport.
world.foldCopy({ copy = "/source/vendor/pythonParser.module", into = "/source/deps/240544fe-7bcf-4c3f-b866-ffb7be8c55a9/Toolkit.package/modules/pythonParser.module", dryRun = true })
typed/builtin//modules/world_vcs/world/forkLive
world.forkLive(opts: { source: string, sourceBranch: string?, maxBatches: number? }) -> number
Seed THIS (empty) world's live content from another world by
copying its whole manifest as clean Pulled rows — the
in-engine half of "fork a world". Provenance is preserved: each
row points at the content's ORIGINAL owner (a fork of a
fork-of-A still points at A), so the fork never claims to have
authored what it pulled. The copy runs server-side in bounded
batches (idempotent + resumable), looping until the source is
fully mirrored. Pair with world.add_all() + world.commit() +
world.push() to publish the fork.
Parameters
opts{ source: string, sourceBranch: string?, maxBatches: number? }—{ source, sourceBranch?, maxBatches? }—sourceis the source world GUID; branches default to"main";maxBatchescaps the batch loop (default 60 ⇒ up to ~120k entries).
Returns number — The number of pulled (dirty) rows now staged-pending on the fork.
world.forkLive({ source = "e89aa92e-4c1f-460e-acd8-73859dd3a346" })
typed/builtin//modules/world_vcs/world/forkStatus
world.forkStatus() -> { ForkStatus }
Per-asset "ahead of origin" report — the fork analogue of git
status against an upstream. Every file of installed content whose
content diverges from the version it was installed at is listed: a
file of an install the world changed or added inside it, and a row
an earlier engine pulled whose content left its pinned version. The
list is partitioned by the world each change goes back to, as
world.contribute with no target sends it: a change to an install, a
change to a dependency it placed included, goes to the world the
install was published from, a change to a dependency whose root keeps
a pull request open in the world the dependency was published from
goes to that world (its entries name the dependency's root), and a
pulled row to the world that authored it. This is information for
judgment: decide whether a change belongs upstream, then
world.contribute.
Returns { ForkStatus } — Array of ForkStatus partitions.
for _, f in ipairs(world.forkStatus()) do print(f.origin_world, #f.entries) end
typed/builtin//modules/world_vcs/world/head
world.head() -> string?
Return the current branch HEAD commit id, or nil if the branch has no commits yet.
Returns string? — The commit id string, or nil.
local id = world.head()
typed/builtin//modules/world_vcs/world/installAsset
world.installAsset(opts: InstallAssetOpts) -> InstallAssetResult
Install a published asset into this world, pulling the asset and
every dependency it closes over and writing them into the source tree.
The world holds the install as ONE entry, the asset at its root path,
which stands for every file of the version and every dependency placed
beside it; every engine materializes the install's files from it, so a
file of the install is a change of the world only once it is edited.
The installed files are ordinary files: edit, move and rename them with
the usual tools, and zm status lists the install as ahead of its
upstream, which zm pr create <root> offers back to the world it came
from.
Returns once this engine has materialized the install and it runs.
Installing an asset where the world already holds it is safe to repeat:
rows at this version are left as they are, and rows of an earlier
version are moved to this one. A file of the world's own over a file of
the install whose version moves takes the new version: one holding the
installed bytes or the new ones leaves, so the new version's file
stands, and an edited text file takes the three-way merge of its edit
with the new version; a merge that conflicts keeps the world's file
and is named in conflicted. The root lands at at, else where the
world already installed it, else at /source/<name>; a copy of it the
world holds at this version anywhere else (another install's
dependency under /source/deps/) moves there, so the world holds the
asset once and everything that depends on it resolves to the moved
copy. A path holding another asset, or local
edits to this one, refuses the install. An install that does not
materialize, or does not run, puts the world's record back as it was:
a record it wrote where the world held none comes out again, so the
world holds nothing of it, and the record the world held for the
install is written back as it stood, so the world holds the install it
held. Either way the same install can simply be run again.
Parameters
optsInstallAssetOpts—{ guid }names the root asset to install;refinstalls it as a branch, a tag or a commit id of the world it is published from holds it, in place of the version that world ships. A ref that world does not resolve, or whose commit holds no version of the asset, refuses the install, naming the ref and why.
Returns InstallAssetResult — { assets_written, blobs_downloaded, root_guid, root_path, root_version, requires, deps, pending, problems, notices, releases, outcome, moved_from, record, files, merged_files, conflicted, timings }. requires lists the name require loads each installed module by: the root's own when the root is a module, else each module directly in it (require("modules.ringLayout") for a module installed at /zero/source/modules/ringLayout.module). releases names each dependency that runs as more than one copy, each loaded on its own: one the install lands at two releases, and one it lands in a recorded version's folder beside the copy the world's name reaches, with the release each runs and the files running it. For an install that moved the version the world held, merged_files names each file of the world's own that took the new version or its merge, and conflicted each whose edit conflicts with it. notices, when present, names each file the installed root's type requires that the published content lacks, and each finding a dependency's type's validate hook states for it; the install lands with either. record is the path of the install's row, files the number of files and folders it states, assets_written the number of them the install placed (the files the user deleted from the install stay deleted and are not counted; 0 when the asset was already present), timings the seconds each step took. outcome is installed, updated or already_present; moved_from names the copy the root moved from, nil when it moved from nowhere. blobs_downloaded counts the blobs the install fetched (bytes already cached cost none); pending lists the written paths still unreadable when the wait for them stalled, and is empty when every one reads back; problems names each reference site in the installed content that resolved to nothing in the world it was published from, and each file a folder version the install wrote holds at its version that ZeroMind gave no entry for, and is empty when every site resolves and every written folder holds all of its files. A folder version lands holding every file its version states: a file the closure leaves out of it is read from that version of the folder, and, when that version cannot be read, from the version of the folder holding it. A folder no read answers for is a line in problems naming it, its version and why the read failed.
local r = world.installAsset({ guid = assetGuid })
typed/builtin//modules/world_vcs/world/installLibrary
world.installLibrary(opts: InstallLibraryOpts) -> InstallLibraryResult
Declarative cross-world dependency. Writes a single marker
file at /source/libs/@<name> whose body is the
zero/world-import/v1 JSON. The next commit ships it as one
regular manifest entry; ZM's import-derivation pass at
finalize-time decodes the marker and stamps the new commit's
imports[]. Unmodified library content never ships in the
importing world's tree: the engine fetches the pinned commit
from ZeroMind and mounts it as @<name>::<path>. The call
returns once the library is mounted (require("@<name>::…")
resolves and library.list() lists it), and raises naming why
when it does not mount, leaving the marker as it was before the
call. A marker already there whose library is mounted is
refused (move it with world.updateLibrary); one whose library
never mounted is replaced, so running the install again repairs it.
Parameters
optsInstallLibraryOpts— SeeInstallLibraryOpts.opts.worldis the upstream world's guid (required).opts.commitis the upstream commit_id to pin (optional; resolvesopts.reformainif omitted).opts.asis the local library name (defaults to the upstream world's slug).opts.refis the human-meaningful ref recorded in the marker.
Returns InstallLibraryResult summarising the install.
world.installLibrary({ world = "guid", as = "combat" })
typed/builtin//modules/world_vcs/world/installedAssets
world.installedAssets() -> { InstalledAsset }
Every asset this world carries from ZeroMind, keyed by the
published guid it was pulled from. The read that answers "what is
actually in this world" by identity rather than by path — an
installed asset's local name can be chosen by the installer, so a
path is not the thing to check a pull against.
Every install is in it, whichever form it is stored in: each install
world.installs() lists and each dependency it placed, committed or
not, from the moment world.installAsset returns.
Returns { InstalledAsset } — An array of InstalledAsset sorted by local path, one per installed asset and dependency whose content the world holds (a deletion the next commit carries is none of them).
for _, a in ipairs(world.installedAssets()) do print(a.asset_guid, a.path) end
typed/builtin//modules/world_vcs/world/installedLibraries
world.installedLibraries() -> { LibraryMarker }
The libraries this world has installed: one row per library marker
under /zero/source/libs, @builtin among them, sorted by name.
Returns { LibraryMarker } — { name, world_guid, requested_ref?, resolved_commit } per library: its name with the @, the world it comes from, the ref that was asked for and the commit it is pinned at.
for _, lib in ipairs(world.installedLibraries()) do print(lib.name, lib.resolved_commit) end
typed/builtin//modules/world_vcs/world/installs
world.installs(opts: { rows: boolean? }?) -> { InstallInfo }
The installs this world holds, one entry each, committed or not,
whichever form each is stored in: record (one row, every engine
materializes the files from it) or rows (an earlier engine landed one
row per file, and world.convertInstalls brings it into one record).
Each names the version it was installed at (version, and version_id,
the id ZeroMind gives that asset version) and how many of its files
the world changed or added. An asset installed at more than one place
names the other places in also_at. A dependency the install keeps in
a recorded version's folder while the world holds another copy of the
asset where its name reaches (two releases running, each loaded on its
own) is named under releases. An install world.uninstall
removed is not listed, though its record stays while it places a
dependency something else uses.
Parameters
opts{ rows: boolean? }(optional) —{ rows: boolean? }:rows = falseleaves the row installs out, which reads no row of the world.
Returns { InstallInfo } — An array of InstallInfo sorted by path.
for _, i in ipairs(world.installs()) do print(i.root_path, i.form, i.files) end
typed/builtin//modules/world_vcs/world/list
world.list() -> { WorldEntry }
List every world the authenticated user has access to.
Reads ZeroMind's GET /v1/me/worlds through the trusted ZeroMind
bridge, which answers without the world's live session, so an engine
bound to a world, an engine waiting for one and an offline engine
answer it alike. Flattens each entry to one record per world with
the role promoted to a top-level field.
Returns { WorldEntry } — Array of WorldEntry records.
local worlds = world.list()
typed/builtin//modules/world_vcs/world/log
world.log(opts: LogOpts?) -> { CommitRow }
The history of the session branch, newest first — git log:
every commit reachable from HEAD through both parent edges, so a
merged branch's commits and a pulled commit appear along with the
commits recorded on this branch. opts.rev starts the history at
another revision (git log <rev>). Pass opts.path to get the
per-path history (git log -- <path>): only the commits that
touched that file, newest-first.
Parameters
optsLogOpts(optional) — Optional.opts.limitcaps the number of commits (default 50, 0 = all).opts.revnames where the history starts.opts.pathscopes the log to one file.
Returns { CommitRow } — Array of CommitRow tables.
local commits = world.log({ limit = 20 })
local merged = world.log({ rev = "feature" })
local touched = world.log({ path = "/source/foo.luau" })
typed/builtin//modules/world_vcs/world/merge
world.merge(sourceBranch: string, opts: MergeOpts?) -> MergeResult
Merge another branch into the session branch — git merge <source>. The merge runs locally in the world's SpacetimeDB clone
and is abortable with world.mergeAbort; nothing reaches ZeroMind
until the result is pushed. When the session branch's head is in
the source's history the head fast-forwards onto it (unless
opts.noFf); otherwise a two-parent merge commit lands
(opts.ffOnly refuses that). Local changes follow git's rule: one
on a path the merge does not rewrite stays in the working tree, and
one on a path it does rewrite refuses the merge with git's message
naming the paths. A scene's unsaved live edits are a local change
to its scene.json: a fast-forward refuses over a scene whose
scene.json it rewrites, naming the scene and how to save or
discard the edits, and a merge commit refuses over any scene holding
them. A staged entry refuses a merge commit. Conflicts →
git-style markers are projected into each conflicting text file,
the cleanly-merged remainder is applied as working-tree changes, and
world.vcsStatus().unmerged lists what needs attention: resolve
each path (edit out the markers, or take one side whole), then
world.add + world.commit — that commit records the merge
(second parent = the source head) and clears the unmerged set.
Parameters
sourceBranchstring— The branch to merge in.optsMergeOpts(optional) — OptionalMergeOpts—ffOnly,noFf.
Returns MergeResult — A MergeResult — status is fast_forward or clean (with commit), conflicts (with conflicts), or up_to_date.
local r = world.merge("feature")
local r = world.merge("feature", { noFf = true })
typed/builtin//modules/world_vcs/world/mergeAbort
world.mergeAbort()
Abort the in-progress merge — git merge --abort. Clears the
unmerged set and restores the working tree to the pre-merge state
(the target head's committed content; the branch head never moved
during a conflicted merge). Errors when no merge is in progress.
world.mergeAbort()
typed/builtin//modules/world_vcs/world/prCheck
world.prCheck(worldGuid: string?, number: number, opts: { suites: { string }?, name: string? }?) -> any
Run test suites against a pull request's head in this engine and
post the result on it as a check. The engine holds the head when it is
bound to the request's source world, on its source branch, at the
commit the request stands at, with nothing uncommitted and nothing
untracked: for a branch of this world,
world.checkout(<source branch>); for a proposal from a fork, an
engine on the fork. Anything else is refused, naming what
differs. The suites run as tests.run({ suites }) runs them (left
out, every suite the world holds). The check is failure when a test
failed, success when the tests that ran all passed, and error when
the run reached no verdict (a suite asked for that matched none, or
every test skipped); its summary is the counts, the runner's note and
the failing tests.
Parameters
worldGuidstring(optional) — The world the pull request lives in. Defaults to the session world.numbernumber— The pull request number.opts{ suites: { string }?, name: string? }(optional) — Optional{ suites, name }: the suite names to run, and the check's name (defaulttests).
Returns any — { check, head, stats, failures }: the check as ZeroMind stored it, the commit it ran on, the run's counts and its failing tests.
world.prCheck(originGuid, 3, { suites = { "door" } })
typed/builtin//modules/world_vcs/world/prChecks
world.prChecks(worldGuid: string?, number: number) -> any
The checks on a pull request — gh pr checks: each test result
posted on its head (head), then those posted on heads it has moved
past (outdated). Each names its poster and poster_relation
(author, member of the world, or outside); one another account
posted carries untrusted = true.
Parameters
worldGuidstring(optional) — The world the pull request lives in. Defaults to the session world.numbernumber— The pull request number.
Returns any — { head, checks, warning }.
local c = world.prChecks(originGuid, 3)
typed/builtin//modules/world_vcs/world/prClose
world.prClose(worldGuid: string?, number: number, opts: { reason: string?, comment: string? }?) -> any
Close a pull request without merging it — gh pr close. reason
is not_planned, duplicate, superseded or withdrawn; left out,
ZeroMind records withdrawn for a close by its author and
not_planned for one by the world's owner. comment is posted on
its thread first, so the author reads why. An open or draft request
closes; a closed or merged one is refused, naming its state, before
anything is posted. A closed request is reopened with
world.prReopen.
Parameters
worldGuidstring(optional) — The world the pull request lives in. Defaults to the session world.numbernumber— The pull request number.opts{ reason: string?, comment: string? }(optional) — Optional{ reason, comment }.
Returns any — The pull request as ZeroMind then states it (state, close_reason, closed_by), marked by who opened it, with closing_comment when a comment was posted.
world.prClose(originGuid, 3, { reason = "superseded", comment = "Landed in #4 instead." })
world.prClose(nil, 3)
typed/builtin//modules/world_vcs/world/prComment
world.prComment(worldGuid: string?, number: number, body: string, opts: { path: string?, parent: string? }?) -> any
Comment on a pull request's thread — gh pr comment. The author
and the world's owner read it in world.prView. The world this
engine is bound to is kept as the one the thread was written in from,
so a reply in it reaches the agents working there.
Parameters
worldGuidstring(optional) — The world the pull request lives in. Defaults to the session world.numbernumber— The pull request number.bodystring— The comment, 1 to 10000 characters.opts{ path: string?, parent: string? }(optional) — Optional{ path, parent }:paththe file the comment is about (relative to the world's root),parentthe id of the comment it replies to.
Returns any — The comment as ZeroMind stored it.
world.prComment(originGuid, 3, "The hinge reads well; the door mesh is still the old one.")
world.prComment(nil, 3, "This table is unused.", { path = "door.component/init.luau" })
typed/builtin//modules/world_vcs/world/prConflicts
world.prConflicts(worldGuid: string?, number: number) -> any
Read a pull request's conflicts — what stands between it and a
merge. Returns the mergeability verdict, the merge base, both
heads, and one entry per conflicting path. A conflicting TEXT path
carries marked_text: the same <<<<<<< / ======= / >>>>>>>
rendering a merge leaves in the working tree, with the source and
target sides laid against their common ancestor. Resolve a path by
writing the settled bytes back to it and committing on the source
branch; the pull request re-analyses on the next read. A binary
path carries the two sides' hashes and no text — pick a side.
A mergeable pull request returns an empty conflict list.
Parameters
worldGuidstring(optional) — The world the pull request lives in. Defaults to the bound world.numbernumber— The pull request number.
Returns any — Decoded ZeroMind conflicts response.
local c = world.prConflicts(nil, 3)
for _, m in ipairs(world.prConflicts(originGuid, 3).markers) do print(m.path, m.marked_text) end
typed/builtin//modules/world_vcs/world/prList
world.prList(worldGuid: string?, number: number?) -> any
List a world's pull requests, or fetch one. The list is
{ pulls, total, warning }, and one pull request is its record with
warning. A pull request's title and description are its
author's: each one another account opened carries untrusted = true,
each this engine's own account opened untrusted = false. One pull
request's reviews (each reviewing account's latest verdict) and
checks are marked the same way, by reviewer and by poster.
Parameters
worldGuidstring(optional) — The world whose pull requests to read. Defaults to the session world.numbernumber(optional) — A specific pull request number. Omit for the list.
Returns any — Decoded ZeroMind response, marked.
local prs = world.prList()
typed/builtin//modules/world_vcs/world/prMerge
world.prMerge(worldGuid: string, number: number, strategy: string?) -> any
Merge a pull request — the agent-side merge button. The answer
carries the merged pull_request record with warning: its title
and description are its author's, and the record carries
untrusted = true when another account opened it. The merge waits
for ZeroMind's own answer. A merge that does not answer merged is read
back: a pull request that reads merged then answers { pull_request }
as read, and any other raises naming what the merge answered and the
state and mergeability the pull request reads.
Parameters
worldGuidstring— The world the pull request lives in.numbernumber— The pull request number.strategystring(optional) —merge(default),squash, orfast_forward.
Returns any — Decoded ZeroMind merge response, its pull request marked.
world.prMerge(originGuid, 3)
typed/builtin//modules/world_vcs/world/prOpen
world.prOpen(opts: PrOpenOpts) -> any
Open a pull request — gh pr create. Proposes the work on one
(world, branch) pair to another. Defaults make the common cases one
argument: from a fork, the target is the world it was forked from, so
world.prOpen({ title = "..." }) proposes your work upstream. In an
ordinary world the target is the same world, so you get a
branch → main pull request.
The PR lives in — and is numbered by — the world it targets, exactly
as a forge numbers pull requests on the upstream repository. That is
also where world.prList finds it.
Parameters
optsPrOpenOpts—title(required), plusdescription,sourceWorld,sourceBranch,targetWorld,targetBranchto address any leg explicitly.
Returns any — The decoded ZeroMind pull request.
world.prOpen({ title = "fix the door hinge" })
world.prOpen({ title = "port the fix", targetWorld = otherGuid })
typed/builtin//modules/world_vcs/world/prReopen
world.prReopen(worldGuid: string?, number: number) -> any
Reopen a closed pull request — gh pr reopen. The world's
contributors reopen any; its author's account reopens one its own
account closed. A pull request that is open, draft or merged is
refused, naming its state.
Parameters
worldGuidstring(optional) — The world the pull request lives in. Defaults to the session world.numbernumber— The pull request number.
Returns any — The pull request as ZeroMind then states it, marked by who opened it.
world.prReopen(originGuid, 3)
typed/builtin//modules/world_vcs/world/prReview
world.prReview(worldGuid: string?, number: number, verdict: string, body: string?, opts: { expectedHead: string? }?) -> any
Review a pull request — gh pr review. verdict is approve
(ready to merge as it stands), request_changes (needs changes first)
or comment (a remark with no verdict). The review is pinned to the
head the pull request stands at; a later push leaves it outdated. A
review never merges or closes the request, and its author's own
account is refused (OWN_CONTENT).
Parameters
worldGuidstring(optional) — The world the pull request lives in. Defaults to the session world.numbernumber— The pull request number.verdictstring—approve|request_changes|comment.bodystring(optional) — Optional text, at most 16 KiB.opts{ expectedHead: string? }(optional) — Optional{ expectedHead }: the head you read (world.prView'sanalyzed_source_head); ZeroMind refuses the review (CONFLICT) when the request has moved past it.
Returns any — The review as ZeroMind stored it, version naming the head it judged.
world.prReview(originGuid, 3, "approve", "Ran the door suite; it passes.")
world.prReview(nil, 3, "request_changes", "The hinge angle is clamped twice.")
typed/builtin//modules/world_vcs/world/prView
world.prView(worldGuid: string?, number: number, opts: { after: string?, limit: number? }?) -> any
Read one pull request in full — gh pr view. Returns the record
plus a LIVE re-analysis against the current branch heads: mergeability
(clean / conflicts / fast_forwardable / up_to_date /
unrelated), conflict_count, and diff — every path the request
adds, modifies or deletes with its checksums. Read this before merging:
it is what tells you WHAT the request changes. Its title and
description are the author's: the record carries untrusted = true
when another account opened it, and warning says what that means.
The review rides with it: comments (a page of the thread, oldest
first, each with the path it is about and the parent it replies
to; comments_next_cursor while more follow), reviews (every
reviewing account's verdict on every head it judged, newest first:
verdict, body, version the head, outdated once the request
moved past it) and checks (each test result posted on its head,
checks_head, then those on heads it moved past, outdated). Each
comment, review and check another account wrote carries untrusted = true. When the review cannot be read, thread_error says why, and
reviews and checks are the record's own: each reviewing account's
latest verdict (reviewer, verdict, head, outdated) and the
checks on its head, each marked the same way.
Parameters
worldGuidstring(optional) — The world the pull request lives in (its target world). Defaults to the session world.numbernumber— The pull request number.opts{ after: string?, limit: number? }(optional) — Optional{ after, limit }:afteracomments_next_cursorto read the thread after,limitthe page's size (1 to 200).
Returns any — The decoded pull request view, with its review.
world.prView(nil, 1)
world.prView(originGuid, 3, { after = view.comments_next_cursor })
typed/builtin//modules/world_vcs/world/previewInstall
world.previewInstall(opts: InstallAssetOpts) -> PreviewResult
Preview what installing an asset WOULD write, without writing
anything. Fetches + decodes the closure and plans placement (the
same helpers world.installAsset uses), returning a flat node
list plus rollup totals. A truncated closure is reported (not
raised) so a caller can surface it and block import.
Parameters
optsInstallAssetOpts—{ guid, at?, ref? }— same shape as installAsset.
Returns PreviewResult: nodes, totals, a truncated flag, the other worlds the content reaches into, and a line for each folder version whose files no read gave.
world.previewInstall({ guid = "..." })
typed/builtin//modules/world_vcs/world/provideDerived
world.provideDerived(outputPath: string, opts: { stage: string? }?) -> number
Take the file at outputPath as the derived output: the file you
wrote is staged as it stands, and the reservation is settled done
with the fingerprint authored, which no recomputation replaces.
Parameters
outputPathstring— The output's VFS path; the file must exist.opts{ stage: string? }(optional) — Optional{ stage: string? }naming the staging area.
Returns number — How many reservations the file filled.
world.provideDerived("/zero/source/gold.material/preview.png")
typed/builtin//modules/world_vcs/world/publishBlockers
world.publishBlockers(opts: StageOpts?) -> { PublishBlockerClass }
List every reason world.push would refuse to publish this
world, as one entry per blocker class: script errors in user
content (script), assets that don't meet their type's content
requirements (content), guids two of the world's own assets state
between them, each path named (sharedGuid), computed asset references a component or
scene entrypoint reaches (staticPin), and the conditions the
publish gate refuses on: a component or scene entrypoint reaching a
dynamic resolve over require/tools.use (gameplayPath), a reference
pinned to an asset the world no longer holds (references), a
reference that names nothing a published world holds, with the file
and line carrying it (unresolvedReferences), a
reference of the world's own file recorded before the world pinned
the library it names (pinPending, which the commit that takes the
file clears by deriving its table at the pin), an error-severity
problem recorded on published content (problems), and an installed
package that content the push publishes requires while the commit
holds no install record of it, so a copy of the published world opens
without it (installs, cleared by staging the package's folder). The
publish gate's classes (gameplayPath, references,
unresolvedReferences, pinPending, problems, installs) are read
over the tree the push releases:
the branch head's commit, each file with the reference table that
commit froze for it, so a file the commit holds and the working tree
no longer does is named, and its class's remedy names the zm add of
its path that stages its removal. A world with no commit yet is read
as the engine holds it, the tree its first commit freezes.
Each class
carries the same title the refusal prints, one items entry per
offending subject (an asset identity, or a <path>:<line> site),
and the single remedy covering that class. This is the account
world.push composes its refusal from, so it names the same
blockers with no push attempted — and in full, where a refusal
bounds how many of a class it prints. zm status prints this list.
One more class blocks the next commit rather than the publish, and
carries blocks = "commit": staleReferences, the files the caller's
staged set holds or leaves out whose references do not resolve in it
(a file whose references moved with a staged change and is left out, or
a staged file stating a version the staged set leaves out). It is the
class world.commit refuses with; world.push never reads it, since
a push publishes what is committed. Empty list = the caller commits
and publishes.
Parameters
optsStageOpts(optional) — Optional{ stage: string? }naming the staging area the read acts on, so acontentitem another area holds names that area in itsstage. Omitted, the read acts on the calling caller's own area.
Returns { PublishBlockerClass } — Array of PublishBlockerClass entries, empty when nothing blocks.
for _, c in ipairs(world.publishBlockers()) do
for _, i in ipairs(c.items) do print(c.kind, i.subject, i.detail) end
end
typed/builtin//modules/world_vcs/world/pull
world.pull(branch: string?, opts: PullOpts?) -> PullResult
git pull: fetch origin/<branch> (default the session branch)
and merge it into the session branch. When the session branch is
strictly behind, its head fast-forwards to the fetched commit; when both
sides moved, a two-parent merge commit lands with the same
conflict/marker/resolve flow as world.merge (resolve the unmerged
paths, then world.add + world.commit; abortable with
world.mergeAbort); when the fetched commit is already in the session
branch's history nothing changes. opts.ffOnly refuses anything but a
fast-forward; opts.noFf always makes a merge commit. Local changes
follow git's rule, as world.merge's do, unsaved scene edits
included. A branch origin does not
hold raises.
Parameters
branchstring(optional) — The origin branch to pull. Defaults to the session branch.optsPullOpts(optional) —{ ffOnly?, noFf? }.
Returns PullResult — A PullResult table: status is up_to_date, fast_forward (commit the new head), clean (commit the merge commit) or conflicts (conflicts).
local r = world.pull()
local r = world.pull("feature")
local r = world.pull("main", { ffOnly = true })
typed/builtin//modules/world_vcs/world/pullAsset
world.pullAsset(opts: PullAssetOpts?) -> PullAssetResult
Pull upstream changes into a previously-installed asset. Re-resolves
the root's transitive closure at opts.ref (default latest) and lands
only what differs from what the world holds (M.__updateRowPlan):
- A file the world never edited (its bytes equal the version it installed) lands whole when its version, its reference table or a stale conflict flag differs from the closure's: bytes and table are written to the pulled row in one step, text and binary alike, and the write reaches source whatever the engine's mode.
- A file the world edited is reconciled from
(row.origin_checksum, row.checksum, entry.checksum)(M.__reconcileDecision):noop(upstream unmoved) leaves it alone,convergedadvances its origin pointer, andmergeruns a three-wayvcs.merge3over (base, local, theirs): a clean result is written and the origin pointer advances, a conflicted result is written WITH markers and the row is flagged conflicted (base + theirs checksums recorded forworld.resolvePullConflict). A binary file the world edited that upstream changed too is flagged conflicted with the structured base/theirs checksums (no marker write). - A folder moves to the closure's version and takes its table.
- A row flagged conflicted that holds the bytes it installed carries no local content: it does not block the pull, and the pull clears it.
Closure drift: an entry the original install never landed is pulled fresh (added). A locally-pulled row nested under the root's own directory whose origin entry disappeared from the closure is removed when it holds the bytes it installed (pruned), or flagged conflicted when it carries edits.
Parameters
optsPullAssetOpts(optional) — SeePullAssetOpts.opts.guidoropts.pathis required;opts.refpins the re-resolve to a branch, a tag or a commit id of the world the asset is published from (defaults to the version that world ships).
Returns PullAssetResult summarising what merged, conflicted, was pruned, and was newly added, the version of the root it landed (root_version), and the reference sites in the pulled content that resolved to nothing where it was published (problems).
world.pullAsset({ guid = "..." })
typed/builtin//modules/world_vcs/world/push
world.push(commitId: string?, opts: PushOpts?) -> (string? | PushQueued, string)
Publish the current branch to ZeroMind. The no-argument form
is a git merge --squash push: EVERY unpushed commit on the
branch collapses into a SINGLE ZeroMind commit (latest content
per path, parented on the branch's current remote HEAD). Because
only the merged final state's bytes are uploaded, a superseded or
lost intermediate-commit blob can never break the push — this is
what makes a churn-heavy world publishable. The local commit
history is preserved as the editing journal; on success every
squashed commit shares the one remote commit id. The explicit
commitId form still pushes that single commit verbatim via
publish_commit (advanced / chain-replay use; its parent must
already be on the remote). While commits are sealed behind derived
outputs, the ready ones land first and the push is queued on the
newest one left that can land. A sealed commit the backend refuses to
land holds only the commits sealed after it that stage a path it
stages; the push publishes the branch without them, and when none of
the sealed commits can land it publishes at once. A push that leaves
sealed commits out warns naming each, with its refusal or the refused
commit it is queued behind, and the zm unseal that returns a commit
to the staging area. With
opts.wait the call waits for the queued push to run and answers
what it answered: the commit id and verdict when it published, a
raise carrying ZeroMind's refusal when it was refused or a sealed
commit it waits for could not land, and a raise saying the push is
still queued, with what it waits on, or still being sent, with its
outcome not known, when the wait ended first. The queued push runs
whatever the wait answers, and zm status states a refused one.
A folder asset of an install that holds a file the world edited,
added or deleted is published as a version of its own under this
world: the checksum its files add up to, each unedited file of it
carried at the version its origin world published
(worldVcs.__installEditsFor). Content of the world that references
the edited asset names that version.
Parameters
commitIdstring(optional) — Optional. A single commit to push verbatim. Omit for the squash push of the whole unpushed stack (the normal path). A push only moves the remote branch forward, as git's does: a remote head no local commit holds raises git's! [rejected] <branch> -> <branch> (fetch first), and one the local head does not descend from raises(non-fast-forward);world.pull()first.opts.forceisgit push --force: a branch whose head is already published moves the remote branch there regardless (a Maintainer's call). A branch with commits not yet published is refused with force, nothing sent (pull first), and so is force withcommitId: force moves the session branch.optsPushOpts(optional) — OptionalPushOpts:stagenames a staging area, the way every other staging verb takes it,forceforces the move, andwait(seconds, ortruefor 120) waits for a queued push to run. The pre-push content gate refuses over every asset the push publishes that falls short of its type's contract, whichever area staged it, and names beside each one the other area holding it, when one does. Omitted, the call acts on the calling caller's own area.
Returns (string? | PushQueued, string) — Two values: the ZeroMind-allocated commit id, and the verdict. "published" with the new commit id when this call published; "already-published" when ZeroMind already carries what this call would have published — the state a push asks for, so it returns rather than raising. That verdict carries the commit's existing ZeroMind id when the publish names one (the single-commit form), and a nil id when it names none (the whole-stack form, which reports a chain). A squash whose merged final state carries dep.unresolved problems takes the slow path inside the same call: the engine re-resolves each pending literal against its live asset index and submits the resolutions to the publish procedure, which completes the push. A reference literal that still resolves to nothing is published with the asset holding it and stays a problem recorded on that asset, while a dep pin the squash severed raises instead; either way the engine names each one with its path, line, reference and reason. A publish ZeroMind refuses raises with ZeroMind's code and message and the action that clears it, chosen by the code: a branch that moved under this push names world.pull(), and a release version already taken names a new version, or, for an asset this world installed from another world as one row per file, the world.convertInstalls call that publishes its changes as this world's.
local zmId = world.push()
local zmId, verdict = world.push()
local queue, verdict = world.push() -- verdict "queued" while commits are sealed
local zmId, verdict = world.push(nil, { wait = 120 }) -- waits for a queued push to run
world.push("01HABC...")
typed/builtin//modules/world_vcs/world/reidentify
world.reidentify(path: string) -> { path: string, previousGuid: string, guid: string, rederived: { string } }
Give the asset at path a guid of its own when another asset of
this world states the same guid (the sharedGuid class
world.publishBlockers and zm status report). The asset keeps its
path and its bytes and takes a freshly minted guid (its files are
removed and written back); the other asset
keeps the guid they shared. Every reference table the world authored is
then derived again, so each reference resolves the asset its literal
names at the version that asset holds: a reference that means this
asset follows it to its new guid, and one that means the other keeps
the shared guid.
Parameters
pathstring— The asset to give its own guid: the copy of the pair.
Returns { path: string, previousGuid: string, guid: string, rederived: { string } } — { path, previousGuid, guid, rederived }, where rederived lists the files whose reference table changed.
local r = world.reidentify("/source/systems/movement/CapsuleWalker.component")
typed/builtin//modules/world_vcs/world/remoteBranches
world.remoteBranches() -> { { branch: string, commit_id: string, origin_head: string } }
Origin's branches as the last fetch of each recorded them — git branch -r. One row per branch of this world that world.fetch has
fetched: branch is origin/<name>, commit_id the local commit
that names origin's head, origin_head that head's ZeroMind id.
Returns { { branch: string, commit_id: string, origin_head: string } } — Array of { branch, commit_id, origin_head }, sorted by branch.
for _, r in ipairs(world.remoteBranches()) do print(r.branch) end
typed/builtin//modules/world_vcs/world/renameBranch
world.renameBranch(oldName: string, newName: string, opts: { force: boolean? }?)
Rename a branch — git branch -m <old> <new>. The branch's
head and history, and your uncommitted changes on it, go to
newName; when oldName is the branch this session is on, the
session moves with it. Another caller's uncommitted changes on
oldName keep that branch in place beside the renamed one.
Parameters
oldNamestring— The branch to rename.newNamestring— Its new name.opts{ force: boolean? }(optional)
world.renameBranch("feature", "feature-2")
typed/builtin//modules/world_vcs/world/reset
world.reset(target: string, opts: ResetOpts?) -> ResetResult
Move the session branch's head to target — git reset [--soft|--mixed|--hard] <commit>. target is any revision
world.revParse reads (a commit id, HEAD~1, a branch, ...).
opts.mode: soft keeps the staged entries and the working tree
and stages every path whose committed version the move changed;
mixed (the default) empties your staging area and keeps the
working tree, so a path the move changed reads as a local change;
hard empties your staging area and brings the working tree to
the new head: every path the move changed, every path your account
changed, and every file of your account's that no commit holds
(an uncommitted install and a scene's autosave overlay included),
each to trash first. A write this session owes the world and the
world is not taking is given up (world.dropOwedWrites). The local
changes of another account stay and are listed in kept. A target equal to HEAD moves nothing, so
world.reset("HEAD") unstages everything and world.reset("HEAD", { mode = "hard" }) discards your local changes. Non-destructive
for history: every commit the head leaves behind becomes a trash
entry that re-attaches it (in chain order).
opts.stage names a staging area, any caller's: world.reset("HEAD", { stage = name }) empties that area, its staged changes and the
outputs it reserves for them, and moves nothing else; the working
tree keeps every edit. emptied says what it held. The name reaches
the area of your account, and when that holds nothing the areas other
accounts hold under it, each named in a warning. A sealed commit of
that name stays sealed (world.unseal returns it to the emptied
name). With a stage named, a target other than HEAD and the soft
and hard modes are refused: they move the branch or the tree, which
a staging area does not hold.
Parameters
targetstring— The revision to move the head to.optsResetOpts(optional) — OptionalResetOpts:mode,stage.
Returns ResetResult — A ResetResult — the new head, its subject line, and the commits left behind.
world.reset("HEAD~1")
world.reset("01HABC...", { mode = "hard" })
world.reset("HEAD", { stage = "client:#chapter4" })
typed/builtin//modules/world_vcs/world/resolvePullConflict
world.resolvePullConflict(path: string, choice: string)
Resolve a conflicted row. A TEXT conflict is one where the file
currently contains conflict markers (world.pullAsset writes
markers only for a text three-way merge that didn't resolve
cleanly); a BINARY/composite conflict has no markers — the local
bytes were left untouched.
choice = "theirs" fetches clean upstream text by content hash
(conflict_theirs_blob_sha256 — path/rename-independent, since
blobs are content-addressed) and overwrites the local file with it
before clearing the flag. It errors, refusing to guess, when the
row records no theirs blob (a binary/composite conflict — a text
blob read can't address theirs for those; keep "ours" or
re-install the asset instead).
choice = "ours" keeps the local side. When the file carries
conflict markers, the local side is reconstructed from them (the
marker writers put ours first, so dropping each block's base and
theirs sections restores your bytes exactly) and written back;
a marker-free file is kept as-is. Either way the flag clears.
Either way, staging the resolved file (world.add) is the normal
git-add path once this returns — this call only clears the
manifest-level flag and (for "theirs") the file content.
Parameters
pathstring— The conflicted row's local VFS path.choicestring—"ours"or"theirs".
world.resolvePullConflict("/source/combat/rules.luau", "theirs")
typed/builtin//modules/world_vcs/world/restore
world.restore(handle: any?)
Restore one trash entry by row_id. Errors verbatim on
handler-not-yet-implemented / world-mismatch. An entry holding content
(a discarded edit, a removed file or folder) returns once the working
copy holds that content again, and every file whose reference table
pins it is derived again, so it names the version the world now holds
and world.vcsStatus lists it as references moved, as after a local
write of that content.
Parameters
handleany(optional) — The trash row id. May be a number or a numeric string.
world.restore(42)
typed/builtin//modules/world_vcs/world/retryDerived
world.retryDerived(outputPath: string, opts: { stage: string? }?) -> number
Compute the derived output at outputPath again, on the staging
area or on a sealed commit that reserves it. A reservation that
failed, was dropped or is done is reserved anew and computed from
the inputs as they stand; a sealed commit waiting on it lands when
it is done.
Parameters
outputPathstring— The output's VFS path, aszm statusnames it.opts{ stage: string? }(optional) — Optional{ stage: string? }naming the staging area.
Returns number — How many reservations were computed again.
world.retryDerived("/zero/source/gold.material/preview.png")
typed/builtin//modules/world_vcs/world/revParse
world.revParse(rev: string) -> string
The commit a revision names — git rev-parse <rev>. A revision
is HEAD, a branch, origin/<branch> (as the last fetch of that
branch recorded it), the name of a branch only origin holds once it
is fetched (world.fetch(branch), such as a pull request's source
branch), a commit id, a ZeroMind commit id (the published commit a
fetch, a push or a pull request names) or a unique prefix of either,
each optionally followed by ~N (N first parents back), ^ (the
first parent) or ^2 (a merge commit's second parent). Raises git's
message for a revision that names nothing, HEAD on a branch with no
commit included.
Parameters
revstring— The revision.
Returns string — The commit id.
local id = world.revParse("HEAD~1")
typed/builtin//modules/world_vcs/world/revertUpdate
world.revertUpdate(library: string)
Revert a library update the working tree holds, as one change: the
pin marker goes back to the version the branch head holds, every
file whose table moved with it is derived again against that pin, and
the versions the move recorded leave, so the tree reads as the head does. The update leaves the staging area
first. A file you edited after the update keeps your edit; only its
table goes back. world.vcsStatus().updates lists the updates.
Parameters
librarystring— The library whose update to revert ("@builtin").
world.revertUpdate("@builtin")
typed/builtin//modules/world_vcs/world/reviewUpdate
world.reviewUpdate(unit: string, opts: ReviewUpdateOpts?) -> UpdateReview
Review what updating one unit changes, writing nothing: the update
itself, never a preview of the asset. Answers the versions the unit
moves from (what the world holds) and to (what its origin holds at
opts.ref, default the ref world.checkUpdates compares it with), then
commits: the commits of the origin world in between, newest first, each
{ id, message, author, date } (more is true past 200), then the files.
modified names up front each file the world holds uncommitted changes
to (a dirty or staged row) that the update touches, { path, outcome }
with outcome merges or conflicts.
- An installed asset (
unitis its root path, asworld.checkUpdatesreports it; a path inside the install stands for its root): the commits that change the install's files, back to the one that moved the root from the version the world holds;fileslists each file the update adds, changes or removes,{ path, change, diff, hunks, local_edit }, wherelocal_editisnone, ormerges/conflictsfor a file the world edited since it was installed. An install that stands as one record keeps the world's edit of a file when it updates, so each edited file the update changes or removes readsconflicts. - A library (
@builtin,@combat, with or without the@): the commits from the pinned commit to the new one andsummarycounts of the library files that change and of this world's files whose references move with the pin (they readreferences movedin status and are committed with the marker).opts.files = trueaddsfiles(each changed library file with its diff) andmoving(those paths).
opts.commits = false reads no commits, and opts.files = false for an
install leaves out files and its diffs: { commits = false, files = false } is the check before an update, answering modified and the
counts alone. When a version of the install's root cannot be read the
commit list stops there, more is true and commits_error says why.
Parameters
unitstring— A library name or an install root path.optsReviewUpdateOpts(optional) —{ ref?, files?, commits? }.
Returns UpdateReview: { kind, unit, from, to, commits, more, commits_error?, files?, moving?, modified, summary }; modified is one { path, outcome = "merges" | "conflicts" } per file holding uncommitted changes of its own that the update touches; summary counts added, changed, removed, modified, and merges / conflicts for an install or moving for a library.
local r = world.reviewUpdate("@builtin")
local r = world.reviewUpdate("/zero/source/Fire.module")
local r = world.reviewUpdate("/zero/source/Fire.module", { commits = false, files = false })
typed/builtin//modules/world_vcs/world/show
world.show(...: string) -> any
Mirror git show's CLI arg shape. Default returns commit
metadata + full diff vs parent. world.show("commit:/path")
returns just the bytes. Flags: --stat, --name-only.
Parameters
...string— Variadic string args: commit id, optional path, optional flags.
Returns any — Either a ShowResult table or a string (for commit:/path).
local r = world.show("abc123")
local r = world.show("--stat", "abc123")
local bytes = world.show("abc123:/foo.luau")
typed/builtin//modules/world_vcs/world/stageVersion
world.stageVersion(rev: string, path: string, opts: StageOpts?) -> boolean
Make the staging area's entry for path the version revision
rev holds — git reset <rev> -- <path> (zm restore --staged --source <rev>). When that version is the one the branch head
holds (both lacking the path included), the path is unstaged, as
the index then matches HEAD there; otherwise a revision that lacks
the path stages its deletion. The working tree is untouched.
Parameters
revstring— Any revisionworld.revParsereads.pathstring— The path to stage.optsStageOpts(optional) — OptionalStageOpts—stage, the staging area.
Returns boolean — true when the staging area holds an entry for the path afterwards, false when the path ended unstaged.
world.stageVersion("HEAD~1", "/source/foo.luau")
typed/builtin//modules/world_vcs/world/stash
world.stash(label: string?) -> StashPushResult
Stash the caller's uncommitted changes — git stash push. The
caller's dirty + staged state on the session branch is saved into
a stash row (label names it), and each stashed path goes back to
its committed version, unstaged. Binary and large content is saved
by its stored blob, so applying the stash brings it back
byte-identical. A path no commit holds keeps its working content in
the tree, as git leaves an untracked file, and is listed under
kept, with its reason in reasons. A folder asset goes back together with the committed paths
beneath it, and those paths are listed under stashed with it. A
path that cannot be taken back raises, naming it and every path
still holding its working content; the stash is saved either way.
Parameters
labelstring(optional) — Optional. Free-form text label for the stash.
Returns StashPushResult — A StashPushResult.
local r = world.stash("wip widget refactor")
typed/builtin//modules/world_vcs/world/stashApply
world.stashApply(ref: any?) -> StashApplyResult
Apply a stash and keep it — git stash apply [<stash>].
Author-only. ref is a row id, stash@{n}, or nil for the
caller's newest stash. Stashed content is written back and staged
entries are staged again. Every file whose reference table pins
content the apply wrote back is derived again, so it names the version
the working copy holds, as after a local write of that content. Each
stashed path is listed by what the apply did with it: under
restored a file written back and a folder
asset a file beneath it came back with, under skipped a path left
as it is, with its reason in reasons. Refuses, writing nothing,
when a path the stash restores holds a different local change.
Parameters
refany(optional) — Optional stash reference.
Returns StashApplyResult — A StashApplyResult.
local r = world.stashApply()
typed/builtin//modules/world_vcs/world/stashDrop
world.stashDrop(ref: any?) -> number
Drop a stash — git stash drop [<stash>]. Author-only. ref
is a row id, stash@{n}, or nil for the caller's newest stash.
The dropped stash goes to trash, where world.restore brings it
back under a new row id.
Parameters
refany(optional) — Optional stash reference.
Returns number — The row id of the dropped stash.
world.stashDrop()
typed/builtin//modules/world_vcs/world/stashPop
world.stashPop(ref: any?) -> StashApplyResult
Apply a stash and drop it — git stash pop [<stash>].
Author-only. ref is a row id, stash@{n}, or nil for the
caller's newest stash. Applies as world.stashApply does; a
refused apply keeps the stash. The dropped stash goes to trash.
Parameters
refany(optional) — Optional stash reference.
Returns StashApplyResult — A StashApplyResult.
local r = world.stashPop()
typed/builtin//modules/world_vcs/world/stashes
world.stashes() -> { StashRow }
List every stash row in the world. Anyone with read access
sees every stash; the per-row author_hex makes it clear
which entries the caller can pop / drop themselves.
Returns { StashRow } — Array of StashRow tables.
local rows = world.stashes()
typed/builtin//modules/world_vcs/world/trash
world.trash() -> { TrashRow }
List trash entries for the world. Anyone with read access
to the world can list trash — recovery is a shared safety net,
not a privacy boundary. The handle (row_id) feeds back into
world.restore. A whole world deleted from ZeroMind is held in
ZeroMind's own trash, which zeromind.trashedWorlds lists and
zeromind.restoreWorld restores from.
Returns { TrashRow } — Array of TrashRow tables.
local rows = world.trash()
typed/builtin//modules/world_vcs/world/trashEmpty
world.trashEmpty() -> number
Permanently delete the trash entries your own operations put
there — zm trash empty — in one transaction. Entries other
callers' operations trashed stay restorable. An emptied entry cannot
be restored.
Returns number — The number of entries deleted.
local n = world.trashEmpty()
typed/builtin//modules/world_vcs/world/uninstallLibrary
world.uninstallLibrary(name: string) -> string
Delete the library marker file. name accepts "@combat"
or "combat" (the leading @ is the convention carried by
the on-disk path).
Parameters
namestring— The library name, with or without the leading@.
Returns string — The marker path that was removed.
world.uninstallLibrary("@combat")
typed/builtin//modules/world_vcs/world/unseal
world.unseal(commitId: string?) -> string
Return a sealed commit to the staging area it was sealed from, with
its message kept, so its paths can be changed and committed again. A
commit world.commit sealed lands by itself once its required derived
outputs are computed; this is the way out of one that cannot land.
Parameters
commitIdstring(optional) — The sealed commit's id. Omitted, the oldest sealed commit holding a failure, else the newest.
Returns string — The id of the commit returned.
world.unseal()
typed/builtin//modules/world_vcs/world/unstage
world.unstage(path: string, opts: StageOpts?) -> UnstageReport
Remove a path from the staging area. Live manifest dirty
state is untouched. A path is staged in one area at a time: a path the
calling area does not hold that another staging area does is taken
out of that area, whichever account opened it, and named in the
report; a take from an area of another account warns, naming that
account, the area and its session. An installed asset is unstaged by
its root path, which takes every row of the install out of the area;
another row of an install raises, naming the install and its root.
The destination of an install held as one record unstages that
record (<path>.pull), the row world.add stages for the same path.
Parameters
pathstring— The path to unstage.optsStageOpts(optional) — Optional{ stage: string? }naming the staging area the path was staged into. Omitted, the call acts on the calling caller's own area.
Returns UnstageReport — { released }: each path taken out of another staging area (stage, account, same_account, session, live). Empty when the calling area held the path.
world.unstage("/source/foo.luau")
world.unstage("/source/foo.luau", { stage = "fauna" })
typed/builtin//modules/world_vcs/world/update
world.update(units: (string | { string })?, opts: UpdateOpts?) -> UpdateResult
Apply updates. With no units, every unit world.checkUpdates
lists; a name or a list of names (library names and install root
paths, mixed) updates those. A library moves its pin
(world.updateLibrary), an installed asset pulls its new closure
(world.pullAsset), one unit at a time: a unit that fails is reported in
its entry and the rest still run, and an install whose local edits
conflict lists the conflicted paths. Each unit is checked against the
files of the world that require it: a library's repinned files, and for
an installed asset every file outside it whose references name it (the
world's own and other installs alike). An installed asset whose new
version leaves such a file not loading (its reload fails, or a site of
it names a version the world holds nowhere) or holding a new analyser
error is not updated, and its error names each file and why;
allowBreaking moves it anyway and names them in broken. Nothing is
staged, committed or
pushed: the updated files wait in world.status(), to_commit lists
every path the updates changed or moved, and warnings names each file
holding uncommitted changes that an update merged into or conflicted.
A dependency an install record places moves inside that record, every
other dependency the record places staying at its release; a unit
answers ok only for a move it made, and a move the record cannot make
is reported in its entry naming the install and the releases.
Parameters
units(string | { string })(optional) — Nil, a unit name, or a list of names.optsUpdateOpts(optional) —{ ref?, allowBreaking? }: a branch name or commit id every unit is updated to, and whether an installed asset moves even when files that require it break.
Returns UpdateResult — { results, to_commit, skipped, warnings, note, summary }: results holds one { unit, kind, from, to, ok, error?, merged?, conflicted?, added?, pruned?, moving?, broken?, problems? } per unit, skipped the units the check could not read, warnings one { unit, path, outcome = "merged" | "conflicted" } per modified file an update touched, and note says nothing was committed.
local r = world.update()
local r = world.update("@combat")
local r = world.update({ "@builtin", "/zero/source/Fire.module" })
typed/builtin//modules/world_vcs/world/updateLibrary
world.updateLibrary(name: string, ref: string?) -> UpdateLibraryResult
Move an installed library to the newest commit of a ref. Resolves
ref in the world the library's marker at /source/libs/@<name>
names; with no ref, @builtin moves to the published commit of it
this engine runs (main when the engine names none), a pin newer than
that commit staying where it is, and every other
library to main. When that is the commit the marker
already holds nothing is written, even when requested_ref differs;
an imported library the engine does not hold at that commit is
mounted and waited for, and a mount that fails raises naming why.
A commit that does not hold an asset the world's own sources require
is refused before anything moves: the error names each such asset with
every source and line requiring it, and the pin stays where it was
until those sources require what the commit holds.
Otherwise the marker is rewritten with the new commit (other marker
fields are kept), the call waits until the engine holds the library at
that commit (@builtin: its pin table is read; another library: its
content is mounted), and the reference tables of the world's own
sources that name the library are derived again. Each source whose table
moved is listed by world.vcsStatus with the reason references moved
and is committed with the marker: a commit holding the marker and
leaving one of them out is refused, naming each. Discarding the marker
puts the pin and its tables back. Works for @builtin
and for every library world.installLibrary wrote. A failed wait puts
the old marker back, waits for the library at the old commit and
raises, saying where it ended. One move per library runs at a time, and
none runs while play is running or in a runtime-profile session.
Parameters
namestring— The library name, with or without the leading@.refstring(optional) — A branch name or commit id of the library's world; defaults to the engine's own commit for@builtinand tomainfor every other library.
Returns UpdateLibraryResult — { name, from, to, changed, rederived, broken, kept, conflicts }: the commits the pin moved between, whether it moved, the source paths whose reference table was derived again (each one to commit with the marker), the repinned files left holding a new error, and the library's files the world edited: kept where the new commit left the file as it was, conflicts where the new commit changed or removed it too. The world's edit stays at its path in both cases.
local r = world.updateLibrary("@builtin")
typed/builtin//modules/world_vcs/world/vcsStatus
world.vcsStatus(opts: StatusOpts?) -> StatusResult
Return the working-tree VCS status: dirty paths, staged
entries, untracked paths, any unmerged ones, and the ignored rows
counted by kind. ignored_summary holds one entry per kind: each
scene's autosave overlay (kind = "overlay", root its scene_dirty
folder) and each .zmignore / .gitignore line that ignores rows
(kind = "rule", file and rule naming it), with its count.
ignored lists those rows one by one when the read is made with
{ ignored = true } (git status --ignored), and is empty otherwise.
A file whose bytes are the ones the branch head holds and whose
reference table is not (a library pin moved, or an asset it references
was renamed, moved or got new bytes) is listed like any change, with
reason = "references moved": in staged when the area holds it, in
dirty otherwise. world.add / world.add_all stage it and it is
committed with the change that moved it. A table that differs only in
the install record the engine writes (an installed asset marked as the
root of its install) is listed the same way with
reason = "install recorded".
An untracked path is one with no committed version behind it, and
it appears in dirty as well — git add . picks up new files too.
Named vcsStatus (not status) because world.status() is the
runtime-snapshot accessor owned by world_status.module; the
source-control surface keeps its own VCS-specific name so the
two never shadow each other.
Each dirty[i].dirtied_by is the identity the row was written
under, which every session of one account shares;
dirtied_by_caller is the stable caller key of the call that wrote
it, dirtied_by_name the name that caller goes by on the world's
roster now,
and writer says what the row is to the calling caller: "you",
"other" (a caller whose session is open), "ended" (a caller
whose session has ended) or "unattributed". dirty_since_micros is the
microsecond timestamp of the first write of the current dirty run.
dirtied_by_account is the account the row's writer acts for and
same_account whether that is the calling caller's account.
local_identity is this connection's identity and
local_caller the calling caller's own stable key, local_name
the name it goes by now, local_account the account it acts for.
claimed_by_other_stages names the paths some other staging area
holds and who holds each: the area, its owner_account, whether
that is the caller's (same_account), the session holding it and
whether that session is open now (live). Staging is advisory: a
staging call that stages one of them takes it out of that area.
reserved_by_other_stages names each other unsealed staging area that
holds reservations (the derived outputs, such as previews, it waits on
for the changes it stages): the area, caller_name, its account and
session, total and the count in each state (by_state). A
reservation leaves its area with the change it was reserved for, and
world.reset("HEAD", { stage = name }) empties an area, its
reservations with it. stage_exists says whether the reported area
exists.
writer_accounts_refusal is set when the world's backend module
predates the record of writers' accounts. stage names the area
staged is the set of, so a caller reads which name reaches its own
staged rows.
Parameters
optsStatusOpts(optional) — Optional{ stage: string?, ignored: boolean? }.stagenames the staging area whose staged set to report; omitted, the read reports the calling caller's own area. The dirty, ignored and untracked sets are the world's working tree and read the same whichever area is named.ignored = truelists every ignored row inignored.
Returns StatusResult — A StatusResult table.
local s = world.vcsStatus()
local s = world.vcsStatus({ stage = "fauna" })
local rows = world.vcsStatus({ ignored = true }).ignored
typed/builtin//modules/yaml/M/decode
M.decode(text: string) -> any
Decode a YAML document into a Luau value. Raises (with the line number) on malformed input or constructs outside the supported subset — never misparses silently.
Parameters
textstring— The YAML document text.
Returns any — The decoded value (table / scalar / nil for an empty document).
local doc = Yaml.decode(vfs.read(path))
typed/builtin//modules/yaml/M/decodeWithComments
M.decodeWithComments(text: string) -> (any, boolean)
Decode a YAML document and report whether it carries a comment — by
the decoder's own rule: a # at a line's start or after whitespace,
outside a quoted scalar (a quote opens one only where a scalar can begin,
so a plain scalar may carry an apostrophe) and outside a block scalar.
What re-encoding the value would drop.
Parameters
textstring— The YAML document text.
Returns (any, boolean) — The decoded value, and whether the text carries a comment.
local doc, commented = Yaml.decodeWithComments(vfs.read(path))
typed/builtin//modules/yaml/M/encode
M.encode(value: { [any]: any }) -> string
Encode a Luau table as a YAML document (block style, two-space indent, sorted keys). Raises on values YAML can't represent (functions, userdata, non-string mapping keys).
Parameters
value{ [any]: any }— The table to encode.
Returns string — The YAML text.
vfs.write(path, Yaml.encode({ contract = "weapon", values = v }))
typed/builtin//modules/yaml/M/flowEntries
M.flowEntries(text: string) -> ({ FlowEntry }, string)
Split a flow collection written on one line, { a: 1, b: [2, 3] } or
[x, { y: 2 }], into its top-level entries as written: each entry's key
(unquoted; nil for a sequence item) and its value text, trimmed, with
nested collections, quoted scalars and the literal spelling of every value
kept. Raises with the decoder's own message on text that is not one
well-formed flow collection, so it accepts exactly what decode reads as a
flow value.
Parameters
textstring— The flow collection's text.
Returns ({ FlowEntry }, string) — An array of { key?, value }, in written order, and the text that follows the collection (a trailing comment with the spaces before it), as written; empty when nothing follows it.
for _, e in Yaml.flowEntries("{ exposure: 1.5, tint: [1, 0, 0] }") do print(e.key, e.value) end
local entries, trailing = Yaml.flowEntries("{ exposure: 1.5 } # brighter")
typed/builtin//modules/zinput/M/_resetLiveArmed
M._resetLiveArmed()
Test-only: reset the liveness auto-arm guard so a suite can exercise the arming decision from a cold state.
Zin._resetLiveArmed()
typed/builtin//modules/zinput/M/_resetTickGuard
M._resetTickGuard()
Test-only: reset the idempotency guard so the next tick()
call runs unconditionally. Suite isolation; not part of the
public contract for production code.
Zin._resetTickGuard()
typed/builtin//modules/zinput/M/atRest
M.atRest() -> boolean
Whether the input layer is at rest: this frame brought no device
event, no mapping-layer change is pending, nothing observes the layer,
and every stateful part of it (axes smoothing, chord windows, gestures,
rebinds, virtual controls, held input, the touch overlay's layout and
routing) has settled. A tick at rest produces no observable effect, and
the next one stays at rest until the input layer states a change. The
touch overlay on screen is drawn from the canvases, the language shown
and the controls code subscribes to as well, and each change of those
while it is on screen is stated as a change of the input layer. Used by
Zin.autoTick's worker to wait for that change instead of ticking every
frame.
Returns boolean — true while a tick would produce no observable effect until the input layer states a change.
if Zin.atRest() then ... end
typed/builtin//modules/zinput/M/disconnect
M.disconnect(handle: number) -> boolean
Disconnect any Zin handle (from Zin.input.on* or
Zin.actions.bind). Returns true if a handler/subscription was
removed; false on miss.
Parameters
handlenumber— The numeric handle.
Returns boolean — Whether a handler was actually removed.
Zin.disconnect(h)
typed/builtin//modules/zinput/M/lastTickAt
M.lastTickAt() -> number
Test/debug: wall-clock timestamp of the most recent tick,
or -1 if Zin.tick has never been called.
Returns number — The wall-clock seconds value of the most recent tick, or -1.
local t = Zin.lastTickAt()
typed/builtin//modules/zinput/M/lastTickFrameId
M.lastTickFrameId() -> number
Test/debug: engine frame id of the most recent tick, or -1 if
Zin.tick has never been called (or __zero_input.frameId() is
unavailable). Used by Zin.autoTick's worker loop to dedup
against explicit ticks.
Returns number — The engine frame id of the most recent tick, or -1.
local f = Zin.lastTickFrameId()
typed/builtin//modules/zinput/M/tick
M.tick(dt: number?)
Advance every stateful zinput subsystem by dt seconds.
dt is the frame delta. Pass the value your host already computes
for animation. If omitted, computed from elapsed wall time since the
last tick() call (first call defaults to 1/60). Order each tick:
- clear chord per-tick fire flags, Gestures per-tick deltas, Surface per-frame device-class flags, Virtual button edges + drag deltas
- route this tick's raw touches into Zin.virtual (Zin.touchControls._advance() — auto-mounts, writes stick/button/drag), then run the key-emulation floor over that fresh state (Zin.emulation._advance()). Both PRODUCE the Zin.virtual state the binding/axis/action evaluators below consume THIS tick, so they run before any of them.
- advance Axes smoothing, Chords window aging, Rebind timeouts, Gestures time-based recognition (long-press) + pinch/pan deltas
- drain
__zero_input.events()once (first tick of the frame only) - feed each event into State (held-time), Chords (state machines), Input (lastInputType tracking), Gestures (contact tracks + discrete recognition), Surface (device-class flags)
- resolve Surface's device class for this frame, then dispatch event subscribers (Zin.events.on / Zin.input.on* callbacks — priority + sink/pass + gpe)
- dispatch action handlers (Zin.actions.bind / onPressed / onReleased / onChanged / onHeld)
- dispatch chord onFire callbacks and Gestures discrete-gesture callbacks for anything that fired this tick
Parameters
dtnumber(optional) — Optional frame delta in seconds (defaults to elapsed wall time).
Zin.tick(dt)
typed/builtin//modules/zinput/actions/M/_clearHandlers
M._clearHandlers()
Test-only: clear every handler (does NOT touch action definitions).
Zin.actions._clearHandlers()
typed/builtin//modules/zinput/actions/M/_dispatchHandlers
M._dispatchHandlers(firstTickThisFrame: boolean?)
Internal: dispatch action handlers. Called by Zin.tick after
axes/chords advance. Fires Begin/End/Change/Held handlers
based on each action's polling state this tick.
firstTickThisFrame is false on a same-engine-frame re-tick (e.g.
the autoTick worker and an explicit Zin.tick both land in one
frame): edge fires (Begin/End/Change) are per-frame events and
must not fire twice, so they are gated to the first tick of the
frame. Held is a per-tick redeliver and still fires every call.
A nil argument is treated as the first tick (edges fire).
Parameters
firstTickThisFrameboolean(optional) — Whether this is the frame's first dispatch pass.
Zin.actions._dispatchHandlers()
typed/builtin//modules/zinput/actions/M/_owns
M._owns(handle: number) -> boolean
Internal: cross-API ownership probe. Used by Zin.disconnect to
route handles to the right disconnect implementation, since
Zin.input.on* and Zin.actions.bind share a handle namespace.
Parameters
handlenumber— The numeric handle to probe.
Returns boolean — Whether this module owns the handle.
if Zin.actions._owns(h) then Zin.actions.disconnect(h) end
typed/builtin//modules/zinput/actions/M/_resetUnknownWarnings
M._resetUnknownWarnings()
Test-only: forget which names have already been reported as unregistered, so a fresh suite sees the warning again.
Zin.actions._resetUnknownWarnings()
typed/builtin//modules/zinput/actions/M/_setAllocator
M._setAllocator(fn: () -> number)
Internal: wire a shared id allocator, so handles from this module
and from Zin.input.on* never collide. Called once at module-load
time from zinput/init.luau.
Parameters
fn() -> number— The allocator function that returns the next handle id.
M._setAllocator(allocateZinHandle)
typed/builtin//modules/zinput/actions/M/_setEnsureBindingsFn
M._setEnsureBindingsFn(fn: () -> ())
Internal: wire the lazy-default-map hook. Called once at module-
load time from zinput/init.luau.
Parameters
fn() -> ()— The hook invoked on a cold read (name not in the registry).
M._setEnsureBindingsFn(ensureDefaultBindings)
typed/builtin//modules/zinput/actions/M/_setEnsureLiveFn
M._setEnsureLiveFn(fn: () -> ())
Internal: wire the liveness hook. Called once at module-load
time from zinput/init.luau.
Parameters
fn() -> ()— The hook invoked on every cold-checked read below.
M._setEnsureLiveFn(ensureInputLive)
typed/builtin//modules/zinput/actions/M/_settled
M._settled() -> boolean
Internal: whether the most recent dispatch pass delivered nothing and saw nothing held. The tick's quiescence gate reads it.
Returns boolean — true when no bound action is doing anything.
if Zin.actions._settled() then ... end
typed/builtin//modules/zinput/actions/M/active
M.active(name: string) -> boolean
True if an action is currently active in the input context
stack. An action is "active" iff its declared context matches the
top of the context stack (so push("ui") suppresses every
non-"ui" action).
Parameters
namestring— The action name.
Returns boolean — Whether the action is currently active.
if Zin.actions.active("jump") then ... end
typed/builtin//modules/zinput/actions/M/bind
M.bind(name: string, fn: any?, opts: BindOpts?) -> ActionHandle?
Register a handler. Returns a numeric handle (also accepted by
Zin.input.disconnect). Returns nil if name is not a defined
action. The handler ends with the context that bound it as well: a
component's with that component instance, a module body's with the
module's next run.
Parameters
namestring— The action name.fnany(optional) — Handlerfn(name, state, io, gpe) -> "sink" | any.optsBindOpts(optional) — Optional{ priority, fire, once }.
Returns ActionHandle? — The numeric handle, or nil when the action isn't defined.
local h = Zin.actions.bind("jump", function() print("jump") end)
typed/builtin//modules/zinput/actions/M/clear
M.clear()
Wipe every defined action AND every registered handler. Primarily for tests.
Zin.actions.clear()
typed/builtin//modules/zinput/actions/M/define
M.define(spec: ActionSpec)
Define one or more actions. Each entry replaces any existing action under the same name; other actions are preserved.
Parameters
specActionSpec— Map ofname -> binding | { binding... } | { context, binding(s) }.
Zin.actions.define({ jump = Zin.bindings.key("Space") })
typed/builtin//modules/zinput/actions/M/disconnect
M.disconnect(handle: ActionHandle) -> boolean
Tear down a handler returned by bind. Idempotent.
Parameters
handleActionHandle— The handle frombind(oronPressed/onReleased/etc).
Returns boolean — Whether the handler was actually removed.
Zin.actions.disconnect(h)
typed/builtin//modules/zinput/actions/M/get
M.get(name: string) -> ActionEntry?
Internal: the registry record behind a name, for profile capture and conflict indexing. Returns nil if the action is not defined.
Parameters
namestring— The action name.
Returns ActionEntry? — The internal { context, bindings } record, or nil.
local entry = Zin.actions.get("jump")
typed/builtin//modules/zinput/actions/M/handlerCount
M.handlerCount(name: string) -> number
Number of registered handlers for an action (0 if none / unknown).
Parameters
namestring— The action name.
Returns number — The handler count for this action.
assert(Zin.actions.handlerCount("jump") == 1)
typed/builtin//modules/zinput/actions/M/has
M.has(name: string) -> boolean
True if an action with this name is defined.
Parameters
namestring— The action name to test.
Returns boolean — Whether the action exists in the registry.
if Zin.actions.has("jump") then ... end
typed/builtin//modules/zinput/actions/M/held
M.held(name: string) -> boolean
True if any binding on the action is currently delivering input. For boolean bindings: any held. For axis/vector bindings: non-zero magnitude. Suppressed by context gating.
Parameters
namestring— The action name.
Returns boolean — Whether the action is held this frame.
if Zin.actions.held("attack") then print("swing") end
typed/builtin//modules/zinput/actions/M/heldTime
M.heldTime(name: string) -> number?
Seconds the action has been held, taken as the MAX held-time
across the action's boolean bindings. Returns nil if no binding
is held or if the action is gated off by the current input
context. Vector / axis bindings are skipped — use a held-time
threshold against Zin.axes.value for held-direction analogs.
Parameters
namestring— The action name.
Returns number? — The longest held-time (seconds) across the action's boolean bindings, or nil.
local t = Zin.actions.heldTime("interact")
typed/builtin//modules/zinput/actions/M/names
M.names() -> { string }
All defined action names, in arbitrary order.
Returns { string } — A fresh array of action names.
for _, n in ipairs(Zin.actions.names()) do print(n) end
typed/builtin//modules/zinput/actions/M/onChanged
M.onChanged(name: string, fn: any?, opts: BindOpts?) -> ActionHandle?
Fire on axis/vector value delta (state = "Change"). For boolean
actions Change fires on every press AND release transition — use
onPressed / onReleased instead if you only want edges.
Parameters
namestring— The action name.fnany(optional) — Handlerfn(name, state, io, gpe).optsBindOpts(optional) — Optional{ priority, once }.
Returns ActionHandle? — The numeric handle, or nil when the action isn't defined.
Zin.actions.onChanged("move", function(_, _, io) print(io.value) end)
typed/builtin//modules/zinput/actions/M/onHeld
M.onHeld(name: string, fn: any?, opts: BindOpts?) -> ActionHandle?
Fire every tick while held (state = "Held"). Fires whenever
held() is true at dispatch time, regardless of value change.
Inherits the action's context constraint (no per-handler context
filter).
Parameters
namestring— The action name.fnany(optional) — Handlerfn(name, state, io, gpe).optsBindOpts(optional) — Optional{ priority, once }.
Returns ActionHandle? — The numeric handle, or nil when the action isn't defined.
Zin.actions.onHeld("interact", function(_, _, io) print("charge", io.value) end)
typed/builtin//modules/zinput/actions/M/onPressed
M.onPressed(name: string, fn: any?, opts: BindOpts?) -> ActionHandle?
Fire on rising edge (state = "Begin"). Sugar for bind with
fire = {"Begin"}.
Parameters
namestring— The action name.fnany(optional) — Handlerfn(name, state, io, gpe).optsBindOpts(optional) — Optional{ priority, once }.
Returns ActionHandle? — The numeric handle, or nil when the action isn't defined.
Zin.actions.onPressed("jump", function() ... end)
typed/builtin//modules/zinput/actions/M/onReleased
M.onReleased(name: string, fn: any?, opts: BindOpts?) -> ActionHandle?
Fire on falling edge (state = "End"). Sugar for bind with
fire = {"End"}.
Parameters
namestring— The action name.fnany(optional) — Handlerfn(name, state, io, gpe).optsBindOpts(optional) — Optional{ priority, once }.
Returns ActionHandle? — The numeric handle, or nil when the action isn't defined.
Zin.actions.onReleased("attack", function() ... end)
typed/builtin//modules/zinput/actions/M/pressed
M.pressed(name: string) -> boolean
True if any boolean binding on the action was just pressed
this frame — the press EDGE, so it fires once per press no matter
how long the input is held. Use it for one-shot input: fire, jump,
pause, undo. For continuous input that should repeat every frame
the input is down, read the level instead with
Zin.state.keyDown(key). Axis/vector bindings do not contribute to
press edges. Suppressed by context gating.
Parameters
namestring— The action name.
Returns boolean — Whether the action's press edge fired this frame.
if Zin.actions.pressed("jump") then ... end
typed/builtin//modules/zinput/actions/M/reason
M.reason(name: string) -> string
Why a named action is not delivering, from the closed set this
registry can distinguish: unknownControl (no action is registered
under the name — the value readers answer their neutral value, which is
not a reading), contextInactive (registered, but its context is not
on top of the stack), pointerTakenByUi (it binds the mouse and the UI
is using the pointer, so the mouse reaches it with nothing),
keyboardTakenByUi (the widget holding keyboard focus takes keys it
binds: every key for a field with the caret, Space and Enter for a
focused button), padTakenByUi (a game menu on screen takes pad
controls it binds: the d-pad, south, east and the left stick),
atRest (live, and the devices it binds are not being driven), or
delivering.
Parameters
namestring— The action name.
Returns string — One of unknownControl / contextInactive / pointerTakenByUi / keyboardTakenByUi / padTakenByUi / atRest / delivering.
if Zin.actions.reason("jump") == "unknownControl" then ... end
typed/builtin//modules/zinput/actions/M/released
M.released(name: string) -> boolean
True if any boolean binding on the action was just released this frame. Suppressed by context gating.
Parameters
namestring— The action name.
Returns boolean — Whether the action's release edge fired this frame.
if Zin.actions.released("attack") then ... end
typed/builtin//modules/zinput/actions/M/remove
M.remove(name: string)
Remove an action by name. Also tears down every handler that was bound to it. No-op when the action isn't defined.
Parameters
namestring— The action name to remove.
Zin.actions.remove("jump")
typed/builtin//modules/zinput/actions/M/repeated
M.repeated(name: string, opts: { delay: number?, period: number? }?) -> boolean
Should a synthetic repeat fire this frame for the action?
Returns true if any of the action's boolean key bindings reports
State.keyRepeatFired. Mouse bindings are skipped (use a hold-
time threshold for press-and-hold UX). Suppressed by context
gating.
Parameters
namestring— The action name.opts{ delay: number?, period: number? }(optional) — Optional{ delay, period }override of the global repeat defaults.
Returns boolean — Whether a synthetic repeat should fire this frame.
if Zin.actions.repeated("scrollLeft") then ... end
typed/builtin//modules/zinput/actions/M/value
M.value(name: string) -> any
Read the action's current value.
- Axis binding → number in [-1, 1]
- Vector binding →
{ x, y }numbers in [-1, 1] - Boolean binding → 1 when held, 0 when not (consumers usually use
held()instead; this exists so a single API works for any kind) When multiple bindings exist, the first one whose kind matches the caller's expectation wins (axis > vector > boolean in declaration order). When suppressed by context, returns the identity value for the first binding's kind: 0 for axis/boolean,{ x = 0, y = 0 }for vector.
Parameters
namestring— The action name.
Returns any — The action's current value (shape depends on first binding kind).
local mv = Zin.actions.value("move") -- { x, y }
typed/builtin//modules/zinput/arming/M/_resetPress
M._resetPress()
Test-only: forget the claim decided for the press in progress, so the next read searches again. Suite isolation for a simulated press that never had a release.
Zin.arming._resetPress()
typed/builtin//modules/zinput/arming/M/describe
M.describe(gate: any?) -> Steering?
The gestures a control's gate arms on, when Zin.arming.gate
built it: what a legend or a help page states beside the control's
bindings, such as the right mouse button a "held" gate waits for.
Parameters
gateany(optional) — A control'sgatevalue.
Returns Steering? — A copy of the Steering the predicate was built from, with rightButton always set, or nil for a gate Zin.arming.gate did not build.
local s = Zin.arming.describe(record.gate); if s and s.rightButton == "held" then ... end
typed/builtin//modules/zinput/arming/M/gate
M.gate(opts: Steering?) -> (record: any?) -> boolean
Build the predicate a look-style control uses as its gate: the
test for "the player is steering", assembled from the gestures this
scheme means by it.
A locked pointer always arms — a cursor the scheme took is one the
player gave to the camera. Everything else is named in opts.
The scheme asks the predicate with the control's own record, and a
stick gesture reads the stick through that control's gamepad binding
of it, so the gate opens at the dead zone that binding states.
Parameters
optsSteering(optional) — Which gestures arm this control. Every field is optional; an empty table reads pointer lock and the right button alone.
Returns (record: any?) -> boolean — A predicate to assign to a control's gate, taking the control's record.
gate = Zin.arming.gate({ dragZone = "right", stick = "right" })
typed/builtin//modules/zinput/arming/M/rightButtonArms
M.rightButtonArms(mode: string?) -> boolean
Whether the right mouse button is arming a camera gesture right
now, on the terms mode names ("free" / "held" / "off").
Under "free" the claim search runs on the frame the button goes
down and its answer holds for that whole press.
Parameters
modestring(optional) — How the button is read;"free"when omitted.
Returns boolean — True while the button is arming.
if Zin.arming.rightButtonArms("held") then ... end
typed/builtin//modules/zinput/arming/M/rightButtonClaimants
M.rightButtonClaimants() -> { string }
Every control that declares the right mouse button and could
answer on it this frame, other than the engine's own arming gesture —
the controls a "free" gate stands down for.
Both layers a world can bind through are searched: the controls of
every live .inputMap, and the Zin.actions / Zin.axes
compatibility registry. A control whose map is standing down for a
suppressor, or whose context is not the one on top, is one the player
cannot reach, and the button is free of it for as long as that holds.
Returns { string } — Control names, scheme controls first, each prefixed by the layer it was found in (map: / action: / axis:).
if #Zin.arming.rightButtonClaimants() > 0 then ... end
typed/builtin//modules/zinput/autoTick/M/_setAtRestFn
M._setAtRestFn(fn: () -> boolean)
Internal: register the predicate that says the input layer is at
rest, so the worker waits for its next change instead of ticking.
Wired by init.luau at module load. Optional — when nil, the worker
ticks every frame.
Parameters
fn() -> boolean— The predicate (typicallyZin.atRest).
AutoTick._setAtRestFn(M.atRest)
typed/builtin//modules/zinput/autoTick/M/_setLastTickFrameIdFn
M._setLastTickFrameIdFn(fn: () -> number)
Internal: register the accessor that returns the engine frame
id of the most recent M.tick. Wired by init.luau so the
worker can dedup itself against explicit ticks within the same
engine frame. Optional — when nil, the worker ticks
unconditionally.
Parameters
fn() -> number— The accessor returning the engine frame id of the last tick.
AutoTick._setLastTickFrameIdFn(M.lastTickFrameId)
typed/builtin//modules/zinput/autoTick/M/_setTickFn
M._setTickFn(fn: (number?) -> ())
Internal: register the function that the auto-tick loop should
call each frame. Wired by init.luau at module load.
Parameters
fn(number?) -> ()— The tick function (typicallyZin.tick).
AutoTick._setTickFn(M.tick)
typed/builtin//modules/zinput/autoTick/M/isRunning
M.isRunning() -> boolean
True while the auto-tick worker's task is live: from start()
until the worker has ended, whether stop() ended it on its next
yield, it raised, or the code that started it was torn down.
Returns boolean — Whether the worker task is live.
if Zin.autoTick.isRunning() then ... end
typed/builtin//modules/zinput/autoTick/M/start
M.start() -> boolean
Start the auto-tick loop. No-op while a worker runs that stop()
has not been asked of; after a stop(), or once the last worker has
ended, a new worker starts at once.
Returns boolean — true when a new loop was started, false when it was already up.
Zin.autoTick.start()
typed/builtin//modules/zinput/autoTick/M/stop
M.stop()
Stop the auto-tick loop on its next yield. No-op if not running.
Zin.autoTick.stop()
typed/builtin//modules/zinput/axes/M/_resetGateWarnings
M._resetGateWarnings()
Test-only: reset the once-per-axis gate-error warning state so a fresh suite can verify warning behavior again.
Zin.axes._resetGateWarnings()
typed/builtin//modules/zinput/axes/M/_resetUnknownWarnings
M._resetUnknownWarnings()
Test-only: forget which names have already been reported as unregistered, so a fresh suite sees the warning again.
Zin.axes._resetUnknownWarnings()
typed/builtin//modules/zinput/axes/M/_setEnsureBindingsFn
M._setEnsureBindingsFn(fn: () -> ())
Internal: wire the lazy-default-map hook. Called once at module-
load time from zinput/init.luau.
Parameters
fn() -> ()— The hook invoked on a cold read (name not in the registry).
M._setEnsureBindingsFn(ensureDefaultBindings)
typed/builtin//modules/zinput/axes/M/_setEnsureLiveFn
M._setEnsureLiveFn(fn: () -> ())
Internal: wire the liveness hook. Called once at module-load
time from zinput/init.luau.
Parameters
fn() -> ()— The hook invoked on every cold-checked read below.
M._setEnsureLiveFn(ensureInputLive)
typed/builtin//modules/zinput/axes/M/_settled
M._settled() -> boolean
Internal: whether every axis sits at zero, current and target alike. The tick's quiescence gate reads it: the axes are read again after an evaluation or a change to the registry, and every call between those answers from the last read.
Returns boolean — true when no axis is moving or being driven.
if Zin.axes._settled() then ... end
typed/builtin//modules/zinput/axes/M/advance
M.advance(dt: number)
Parameters
dtnumber
typed/builtin//modules/zinput/axes/M/clear
M.clear()
Wipe every axis and its state. Primarily for tests.
Zin.axes.clear()
typed/builtin//modules/zinput/axes/M/define
M.define(spec: AxisSpec)
Define one or more axes. Each entry replaces any existing axis of the same name; other axes are preserved.
Parameters
specAxisSpec— Map ofname -> { binding, deadzone?, smoothing?, curve?, invert?, context?, gate? }.
Zin.axes.define({ aim_x = { binding = ..., deadzone = 0.05 } })
typed/builtin//modules/zinput/axes/M/get
M.get(name: string) -> AxisDef?
Internal introspection: definition record (or nil).
Parameters
namestring— The axis name.
Returns AxisDef? — The internal AxisDef record, or nil if not defined.
local def = Zin.axes.get("aim_x")
typed/builtin//modules/zinput/axes/M/has
M.has(name: string) -> boolean
True if an axis with this name is defined.
Parameters
namestring— The axis name.
Returns boolean — Whether the axis exists in the registry.
if Zin.axes.has("aim_x") then ... end
typed/builtin//modules/zinput/axes/M/names
M.names() -> { string }
All defined axis names, in arbitrary order.
Returns { string } — A fresh array of axis names.
for _, n in ipairs(Zin.axes.names()) do print(n) end
typed/builtin//modules/zinput/axes/M/raw
M.raw(name: string) -> any
Read the raw, unsmoothed, unshaped value of the underlying
binding. For vector bindings returns {x,y}; for everything else
returns a number in [-1, 1]. Useful for debugging or comparing
pre/post processing.
Parameters
namestring— The axis name.
Returns any — The raw value (scalar or vector depending on axis kind).
print(Zin.axes.raw("aim_x"))
typed/builtin//modules/zinput/axes/M/reason
M.reason(name: string) -> string
Why a named axis is not delivering, from the closed set this
registry can distinguish: unknownControl (no axis is registered under
the name — the value readers answer zero, which is not a reading),
contextInactive (registered, but its context is not on top of the
stack), pointerTakenByUi (it binds the mouse and the UI is using the
pointer, so the mouse reaches it with nothing), keyboardTakenByUi (the
widget holding keyboard focus takes keys it binds: every key for a field
with the caret, the arrows for a focused slider), padTakenByUi (a game
menu on screen takes pad controls it binds, the left stick among them),
gateRefused (its own gate answered no), atRest (live, and the binding
it reads is not being driven), or delivering.
Parameters
namestring— The axis name.
Returns string — One of unknownControl / contextInactive / pointerTakenByUi / keyboardTakenByUi / padTakenByUi / gateRefused / atRest / delivering.
if Zin.axes.reason("look") == "gateRefused" then ... end
typed/builtin//modules/zinput/axes/M/remove
M.remove(name: string)
Remove an axis. No-op if not defined.
Parameters
namestring— The axis name.
Zin.axes.remove("aim_x")
typed/builtin//modules/zinput/axes/M/value
M.value(name: string) -> any
Read the smoothed, shaped, context-gated value.
Scalar axes return a number in [-1, 1].
Vector axes return {x, y} numbers in [-1, 1].
Returns 0 / {x=0,y=0} if the axis isn't defined.
Parameters
namestring— The axis name.
Returns any — The smoothed, shaped value (scalar or {x, y}).
local mv = Zin.axes.value("move") -- { x, y }
typed/builtin//modules/zinput/back/M/_observeEvent
M._observeEvent(ev: any?)
Internal: per-event observer called by the Zin.tick coordinator. A
back event the engine routed to a claim runs the handler of the claim
that takes it (for a pad's east, the last claim that is the world's
own); with no claim held any more, the press goes to the platform's own
default, and a pad's press goes nowhere.
Parameters
evany(optional) — The raw input event record.
Back._observeEvent(ev)
typed/builtin//modules/zinput/back/M/_reset
M._reset()
Test-only: release every claim, so each case of a suite begins with none held.
Zin.back._reset()
typed/builtin//modules/zinput/back/M/_setEnsureLiveFn
M._setEnsureLiveFn(fn: () -> ())
Internal: register the function that arms the input tick, which
delivers a press to the claim that takes it. Wired by init.luau.
Parameters
fn() -> ()— Arms the tick.
Back._setEnsureLiveFn(ensureInputLive)
typed/builtin//modules/zinput/back/M/claim
M.claim(handler: () -> (), options: { priority: number?, platform: boolean? }?) -> Claim
Take Back: while the claim is held, a Back press that no dismissible
overlay takes runs handler. The claim of highest priority takes a
press, and among claims of equal priority the most recent.
Hold a claim while Back means something to the world (a menu to close,
a pause screen to bring up) and release it when Back should leave, so
the platform's own Back (the app moving to the background on Android)
answers once nothing holds it. A claim a component makes is released
when its entity is destroyed.
Parameters
handler() -> ()— Runs once per Back press this claim takes. A pad'seastbutton on a game menu is Back as well, and reaches every claim but one statingplatform = true.options{ priority: number?, platform: boolean? }(optional) —{ priority: number?, platform: boolean? }. Priority 0 when omitted; the editor holds its claim that leaves play at -1, under every claim a played world makes.platform = truemakes the claim stand for the platform's own Back (the editor's claim that leaves play is one): a pad'seaston a game menu passes it by, since a pad press leaves nothing on any platform.
Returns Claim — The claim: claim:release() gives Back up, claim:held() says whether it is still held.
local claim = Zin.back.claim(function() ui.showScreen("pause") end)
claim:release()
typed/builtin//modules/zinput/back/M/claims
M.claims() -> number
The number of claims held.
Returns number — How many claims on Back are held now.
if Zin.back.claims() == 0 then ... end
typed/builtin//modules/zinput/back/M/press
M.press()
Press Back, routed the way the platform's own Back is: the topmost dismissible overlay is dismissed, else the most recent claim's handler runs, else the platform's own default answers it (on Android the app moves to the background). Bind a world's own control to it to make Escape or a pad's button Back as well.
controls.pause:onPressed(Zin.back.press)
typed/builtin//modules/zinput/bindings/M/_keyboardTakenBy
M._keyboardTakenBy() -> string?
Internal: whose a person's keyboard is this frame, when the UI takes
any of it — "ui" while a widget taking every key holds focus (a text
field with the caret, a terminal, a widget with its own onKey),
"shared" while a focused widget takes some keys (Space and Enter for a
button, the stepping keys as well for a slider) and the scene reads the
rest — and nil while the scene reads every key.
Returns string? — "ui", "shared", or nil.
local owner = Zin.bindings._keyboardTakenBy()
typed/builtin//modules/zinput/bindings/M/_keysTakenByUi
M._keysTakenByUi(bindings: { any }) -> { string }
Internal: the keys these bindings read that the UI takes from a person's keyboard this frame: every key they read while a widget taking every key holds focus, the ones the focused widget takes while the keyboard is shared, none while the scene reads every key. A key the UI takes reaches the bindings with nothing until the widget lets go.
Parameters
bindings{ any }— The binding descriptors to test.
Returns { string } — The key codes, in the order the bindings name them.
local taken = Zin.bindings._keysTakenByUi({ Zin.bindings.key("Space") })
typed/builtin//modules/zinput/bindings/M/_padTakenByUi
M._padTakenByUi(bindings: { any }) -> { string }
Internal: the pad controls these bindings read that a game menu on
screen takes this frame, on any connected pad: the d-pad, south and
east while the menu moves and presses with them, and the left stick
while a menu is up. A control the menu takes reaches the bindings
released and centred until the menu lets go.
Parameters
bindings{ any }— The binding descriptors to test.
Returns { string } — The control names, in the order the bindings name them.
local taken = Zin.bindings._padTakenByUi({ Zin.bindings.padButton("south") })
typed/builtin//modules/zinput/bindings/M/_pointerTakenBy
M._pointerTakenBy() -> string?
Internal: who a person's pointer belongs to this frame, when it is
not the scene's — "ui" while the UI is using it (a widget that answers
for the pointer stands under it or holds the press, or a shown screen
holds the pointer), "undecided" while a finger's press waits for the UI
to say whose it is — and nil while the scene reads it.
Returns string? — "ui", "undecided", or nil.
local owner = Zin.bindings._pointerTakenBy()
typed/builtin//modules/zinput/bindings/M/_readMouse
M._readMouse(bindings: { any }) -> boolean
Internal: whether any of these bindings reads a person's mouse — a
button, its motion or its wheel — directly or through an axis /
vector arm.
Parameters
bindings{ any }— The binding descriptors to test.
Returns boolean — Whether one of them reads the mouse.
if Zin.bindings._readMouse({ Zin.bindings.mouseDelta() }) then ... end
typed/builtin//modules/zinput/bindings/M/arrowKeys
M.arrowKeys() -> Binding
Convenience: arrow keys as a vector binding. Identical to
vector(key("ArrowRight"), key("ArrowLeft"), key("ArrowUp"), key("ArrowDown")).
Returns Binding — A vector binding for the arrow keys.
local move = Zin.bindings.arrowKeys()
typed/builtin//modules/zinput/bindings/M/axis
M.axis(plus: Binding, minus: Binding, opts: StickOpts?) -> Binding
Bind to a 1-D axis composed of two opposing bindings. Each arm contributes how far it is pushed, 0..1, so a key gives 1 while held and a trigger gives its travel — which is what separates easing a car forward from flooring it. Value = plus travel - minus travel.
Parameters
plusBinding— The binding whose travel contributes positively.minusBinding— The binding whose travel contributes negatively.optsStickOpts(optional)
Returns Binding — An axis binding descriptor.
local b = Zin.bindings.axis(B.key("KeyD"), B.key("KeyA"))
typed/builtin//modules/zinput/bindings/M/controlLabel
M.controlLabel(name: string) -> any?
The catalog label of a control named name, when a catalog the
caller reads holds controls.control.<name>: an i18n.text value,
else nil. The built-in library's catalog names the engine's own
controls (jump, sprint, crouch, ...), and a world's
locales/<tag>/controls.json can name its own, so a control that came
without a label (a touch button synthesized from a keyboard binding, a
map baked from a registry) still reads in the player's language.
Parameters
namestring— The control's name.
Returns any? — The label, or nil.
local label = Zin.bindings.controlLabel("jump") or "Jump"
typed/builtin//modules/zinput/bindings/M/evalAxis
M.evalAxis(b: any?, surface: string?) -> number
Resolve a 1-D axis binding to a scalar.
For axis bindings the result is in [-1, 1]. For mouseDelta /
scroll bindings the result is a raw physical delta (pixels,
wheel clicks) and may exceed that range — shape it with Zin.axes.
Parameters
bany(optional) — The binding to evaluate.surfacestring(optional) — Whose keys a key binding reads:"scene"(the default) or"editor". An input map declared for the editor surface evaluates with"editor".
Returns number — The axis value this frame (0 when the binding is not scalar).
local x = Zin.bindings.evalAxis(Zin.bindings.mouseDelta("x"))
typed/builtin//modules/zinput/bindings/M/evalHeld
M.evalHeld(b: any?, surface: string?) -> boolean
Is this binding currently delivering a held signal? key/mouse/modKey/pointerLocked → boolean held. axis/vector/mouseDelta/scroll → magnitude non-zero.
Parameters
bany(optional) — The binding to evaluate.surfacestring(optional) — Whose keys a key binding reads:"scene"(the default) or"editor". An input map declared for the editor surface evaluates with"editor".
Returns boolean — Whether the binding is held this frame.
if Zin.bindings.evalHeld(b) then ... end
typed/builtin//modules/zinput/bindings/M/evalPressed
M.evalPressed(b: any?, surface: string?) -> boolean
Did this binding's press edge fire this frame? Boolean bindings only. Axis/vector return false (use evalAxis/evalVector with a held-time threshold for edge tracking).
Parameters
bany(optional) — The binding to evaluate.surfacestring(optional) — Whose keys a key binding reads:"scene"(the default) or"editor". An input map declared for the editor surface evaluates with"editor".
Returns boolean — Whether the press edge fired this frame.
if Zin.bindings.evalPressed(b) then print("jump") end
typed/builtin//modules/zinput/bindings/M/evalReleased
M.evalReleased(b: any?, surface: string?) -> boolean
Did this binding's release edge fire this frame?
Parameters
bany(optional) — The binding to evaluate.surfacestring(optional) — Whose keys a key binding reads:"scene"(the default) or"editor". An input map declared for the editor surface evaluates with"editor".
Returns boolean — Whether the release edge fired this frame.
if Zin.bindings.evalReleased(b) then ... end
typed/builtin//modules/zinput/bindings/M/evalVector
M.evalVector(b: any?, surface: string?) -> Vec2
Resolve a 2-D vector binding to { x, y }.
For vector bindings the result is in [-1, 1]. For mouseDelta
/ scroll bindings (with no axis set) the result is the raw
frame delta — mouseDelta = { x = dx, y = dy }, scroll =
{ x = 0, y = wheel_delta } (x reserved for future h-scroll).
Parameters
bany(optional) — The binding to evaluate.surfacestring(optional) — Whose keys a key binding reads:"scene"(the default) or"editor". An input map declared for the editor surface evaluates with"editor".
Returns Vec2 — A { x, y } vector.
local mv = Zin.bindings.evalVector(Zin.bindings.wasd())
typed/builtin//modules/zinput/bindings/M/format
M.format(b: any?) -> string
Render a single binding descriptor as a user-readable string, in
the player's language: the words come from the controls catalog,
and in English they read Space, Left Ctrl, Ctrl+S,
Right mouse button, Mouse movement, Mouse wheel, E / Q, WASD,
Pad-A. A pad binding is named for the pad the person holds
(Zin.gamepad.label): on a headset's hand controllers it reads as the
controls printed on them, X, Right grip, Left thumbstick,
Right thumbstick up/down. The rebinding UI shows it verbatim.
Returns "<invalid>" for malformed input (does not throw).
Parameters
bany(optional) — The binding to format.
Returns string — A short, human-recognizable string.
local s = Zin.bindings.format(B.modKey("Ctrl+S")) -- "Ctrl+S"
typed/builtin//modules/zinput/bindings/M/formatAll
M.formatAll(bindings: any?, sep: string?) -> string
Render an array of bindings joined by sep (default ", ").
Returns "<no bindings>" if the argument isn't a table, "<empty>"
for an empty array, each in the player's language. What a summary row
listing one control's bindings for a device class shows.
Parameters
bindingsany(optional) — The bindings to format.sepstring(optional) — Optional join separator (default", ").
Returns string — A composite string description.
Zin.bindings.formatAll({ B.key("Space"), B.modKey("Ctrl+S") })
typed/builtin//modules/zinput/bindings/M/headsetLook
M.headsetLook(binding: any?, v: Vec2, dt: number, signal: any?) -> (number?, number?)
What a stick binding reads in a headset, when the look action is the
control it drives: the frame units of the binding's control and nothing
on the vertical axis. Applies to a right-stick padStick declared
as = "delta" while an XR session holds input focus. Under snap
turning the horizontal axis is the steps flicked this frame, each worth
the signal's snapDegrees; under smooth turning it is the stick's
deflection integrated as the binding states.
Parameters
bindingany(optional) — The binding being read.vVec2— The binding's reading in its own frame, fromevalVector.dtnumber— Seconds the frame covers.signalany(optional) — What the headset reports:{ turnMode, turnSteps, snapDegrees }, or nil outside a session.
Returns (number?, number?) — The x, y the control reads, or nil when the headset does not shape this binding.
local x, y = Zin.bindings.headsetLook(b, v, dt, { turnMode = "snap", turnSteps = 1, snapDegrees = 45 })
typed/builtin//modules/zinput/bindings/M/isAxis
M.isAxis(binding: any?) -> boolean
True for the binding descriptors evalAxis resolves to a scalar:
axis, touchPinch and padAxis, plus a mouseDelta, scroll,
touchDrag or touchStick naming one axis of its two-axis surface.
Parameters
bindingany(optional) — The binding to test.
Returns boolean — Whether the binding resolves to a scalar.
assert(Zin.bindings.isAxis(Zin.bindings.mouseDelta("x")))
typed/builtin//modules/zinput/bindings/M/isBoolean
M.isBoolean(binding: any?) -> boolean
True for binding descriptors that resolve to a boolean (key, mouse, modKey, pointerLocked, touchButton).
Parameters
bindingany(optional) — The binding to test.
Returns boolean — Whether the binding resolves to a boolean.
assert(Zin.bindings.isBoolean(Zin.bindings.key("Space")))
typed/builtin//modules/zinput/bindings/M/isLabel
M.isLabel(label: any?) -> boolean
Whether label is something a control can be labelled with: a
non-empty string or an i18n.text value.
Parameters
labelany(optional) — Any value.
Returns boolean — True for a usable label.
Zin.bindings.isLabel(i18n.text("controls.control.jump")) -- true
typed/builtin//modules/zinput/bindings/M/isVector
M.isVector(binding: any?) -> boolean
True for the binding descriptors that resolve to a 2-D vector:
vector and padStick, plus a mouseDelta, scroll, touchDrag
or touchStick reporting its whole surface. Naming one axis of those
four makes the binding a scalar, which isAxis answers for, so no
binding answers both.
Parameters
bindingany(optional) — The binding to test.
Returns boolean — Whether the binding resolves to a 2-D vector.
assert(Zin.bindings.isVector(Zin.bindings.wasd()))
typed/builtin//modules/zinput/bindings/M/key
M.key(code: string) -> Binding
Bind to a single key. Code is a web-style identifier (e.g.
"KeyW", "Space", "ShiftLeft", "ArrowUp") — same vocabulary as
Zin.state.keyDown(code).
Parameters
codestring— The key code identifier.
Returns Binding — A key binding descriptor.
local b = Zin.bindings.key("Space")
typed/builtin//modules/zinput/bindings/M/labelSource
M.labelSource(label: any?) -> string
The Luau source that evaluates to label where it is written into
a .inputBinding: "Horn" for a string, i18n.text("controls.control.jump")
for an i18n.text value, so a control written by a tool reads in the
player's language the way the one it was written from did.
Parameters
labelany(optional) — A string or ani18n.textvalue.
Returns string — The source text.
Zin.bindings.labelSource(i18n.text("controls.control.jump")) -- 'i18n.text("controls.control.jump")'
typed/builtin//modules/zinput/bindings/M/labelText
M.labelText(label: any?) -> string
The words label reads as now: a string as written, an
i18n.text value in the player's language at this moment, "" for
anything else. Every listing that hands a label to a caller (a scheme
row, the touch layout, inputMap:controls()) gives it this way.
Parameters
labelany(optional) — A string or ani18n.textvalue.
Returns string — The text.
print(Zin.bindings.labelText(record.label))
typed/builtin//modules/zinput/bindings/M/modKey
M.modKey(spec: string) -> Binding
Parse a modifier-decorated key spec like "Ctrl+S", "Shift+Alt+P", or just "Escape". Recognized modifier tokens (case-insensitive): "Ctrl", "Control", "Shift", "Alt". Anything else is treated as the base key code. The last segment is the base key.
Parameters
specstring— The modifier-decorated key spec.
Returns Binding — A modKey binding descriptor.
local b = Zin.bindings.modKey("Ctrl+S")
typed/builtin//modules/zinput/bindings/M/mouse
M.mouse(button: string) -> Binding
Bind to a single mouse button by name ("left", "right", or "middle").
Parameters
buttonstring— The mouse-button name.
Returns Binding — A mouse binding descriptor.
local b = Zin.bindings.mouse("right")
typed/builtin//modules/zinput/bindings/M/mouseDelta
M.mouseDelta(axis: string?) -> Binding
Bind to the mouse delta this frame.
axis = nil→ vector binding returning{ x = dx, y = dy }axis = "x"→ scalar binding returningdxaxis = "y"→ scalar binding returningdyValues are not normalised to[-1, 1]— mouse delta is a physical pixel count. A control carrying this beside a stick declaresas = "delta"withunitsPerSecondon the stick class, so both classes reach the consumer measured in these pixels.
Parameters
axisstring(optional) — Optional."x"/"y"for a scalar binding; omit for a vector.
Returns Binding — A mouseDelta binding descriptor.
local look = Zin.bindings.mouseDelta()
local lookX = Zin.bindings.mouseDelta("x")
typed/builtin//modules/zinput/bindings/M/padAxis
M.padAxis(axis: string | number, opts: PadAxisOpts?) -> Binding
Gamepad axis binding, one axis as a scalar: a canonical axis, or
the device's own axis by its 0-based index (Zin.gamepad.device(slot) .axes), a wheel, a pedal, a throttle, a rudder. Canonical stick axes
run -1..1 in the frame the binding declares — forward positive by
default, matching the touch stick and B.wasd(), and screen-down
positive under as = "delta", matching the mouse and the dragging
finger it is measured against. Trigger axes run 0..1. A device axis
reads -1..1 across its native range.
rest and full calibrate the reading: the binding reports
(reading - rest) / (full - rest), clamped to -1..1, so rest reads
0 and full reads 1. A pedal that reads -1 released and 1 floored
binds with { rest = -1 } and reports 0..1; one wired the other way
with { rest = 1, full = -1 }; a wheel whose centre sits off zero
with { rest = 0.02 }. With no connected device reporting the
axis the binding reads 0, so a pedal map stays quiet until the pedals
are plugged in. One axis carrying a throttle and a brake
splits with B.axis(B.padAxis(i), B.padAxis(i, { full = -1 })), each
arm counting its own side.
A canonical stick axis reads through the stick dead zone (the person's
Stick dead zone setting, camera.stickDeadzone, 0.15 of its travel by
default, scaled so the reading starts at 0 at its edge) unless
deadzone states another; curve bends the travel past it. Any other axis is
shaped only when the binding states deadzone or curve.
Parameters
axisstring | number— Canonical name: left_stick_x, left_stick_y, right_stick_x, right_stick_y, left_trigger, right_trigger; or a 0-based device axis index.optsPadAxisOpts(optional) —slot(a pad slot, or a piece of a device's name),rest/full(calibration, each -1..1;rest0 andfull1 when omitted),deadzone(0..1, the deflection that reads as rest) /curve("linear","quadratic"or"cubic"), andas/unitsPerSecond/scaleas for any stick binding.
Returns Binding — The binding descriptor.
B.padAxis("right_stick_x")
B.padAxis(2, { slot = "pedals", rest = -1 })
typed/builtin//modules/zinput/bindings/M/padButton
M.padButton(button: string | number, slot: (number | string)?) -> Binding
Gamepad button binding, addressed by canonical position rather
than by any vendor's letter — south is the lower face button on
every pad, whatever it is printed with, or by the device's own button
index (0-based, Zin.gamepad.device(slot).buttons), which binds every
button a wheel, a shifter, a flight stick or a button board reports.
With no slot, ANY connected pad drives it, which is what a
single-player scheme wants; name a slot for local multiplayer, or a
piece of a device's name to bind that device whatever slot it took.
Parameters
buttonstring | number— Canonical name: south, east, west, north, left_shoulder, right_shoulder, left_trigger, right_trigger, left_stick, right_stick, select, start, guide, dpad_up, dpad_down, dpad_left, dpad_right; or a 0-based device button index.slot(number | string)(optional) — Pad slot, a device name to match, or nil for any pad.
Returns Binding — The binding descriptor.
B.padButton("south")
B.padButton(12, "shifter")
typed/builtin//modules/zinput/bindings/M/padStick
M.padStick(stick: string, opts: StickOpts?) -> Binding
Gamepad stick binding: the 2-D vector of one thumbstick. The vector shape a movement or look axis wants, without naming its two components separately.
The stick reads through a radial dead zone, the person's Stick dead
zone setting (camera.stickDeadzone, 0.15 of its travel by default)
unless deadzone states another, so a stick at rest (and the few percent a
worn one reports there) reads {0, 0}. The travel past it is
stretched back over 0..1, so the reading starts at 0 at the dead
zone's edge, and curve bends it on the stick's magnitude, keeping the
direction it points in. Both act on the deflection, before
as = "delta" integrates it.
Parameters
stickstring— "left" or "right".optsStickOpts(optional) —slot(a pad slot, or a piece of a device's name),deadzone(0..1; 0 reads the stick as the device reports it),curve("linear"the default,"quadratic","cubic"), andas/unitsPerSecond/scale.
Returns Binding — The binding descriptor.
B.padStick("left")
B.padStick("right", { as = "delta", unitsPerSecond = 700, curve = "quadratic" })
typed/builtin//modules/zinput/bindings/M/padTrigger
M.padTrigger(trigger: string, slot: number?) -> Binding
Gamepad trigger binding: one trigger's analog travel, 0..1. The
same trigger also latches a digital padButton at half throw, so a
scheme binds whichever of the two it means.
Parameters
triggerstring— "left" or "right".slotnumber(optional) — Pad slot, or nil for any pad.
Returns Binding — The binding descriptor.
B.padTrigger("right")
typed/builtin//modules/zinput/bindings/M/pointerLocked
M.pointerLocked() -> Binding
Bind to pointer-lock state. evalHeld is true while the
pointer is locked. evalPressed / evalReleased always return
false (use Zin.events.on for edge events).
Returns Binding — A pointerLocked binding descriptor.
local locked = Zin.bindings.pointerLocked()
typed/builtin//modules/zinput/bindings/M/scroll
M.scroll(axis: string?) -> Binding
Bind to the scrollwheel delta this frame.
axis = nil→ vector binding returning{ x = 0, y = scroll_delta }axis = "y"→ scalar binding returning the wheel deltaaxis = "x"→ scalar binding returning0(no horizontal-scroll surface today; reserved for future hardware support)
Parameters
axisstring(optional) — Optional."x"/"y"for a scalar binding; omit for a vector.
Returns Binding — A scroll binding descriptor.
local zoom = Zin.bindings.scroll("y")
typed/builtin//modules/zinput/bindings/M/surfacesOf
M.surfacesOf(binding: any?) -> { string }
Which device surface a binding reads from: pointer (mouse, wheel
or finger), keyboard (keys and composed text), or gamepad. A
composite binding (axis, vector) answers with the surfaces of every
binding it combines.
Parameters
bindingany(optional) — The binding to classify.
Returns { string } — Array of surface names, without repeats.
local s = Zin.bindings.surfacesOf(Zin.bindings.wasd())
typed/builtin//modules/zinput/bindings/M/touchButton
M.touchButton(opts: TouchButtonOpts) -> Binding
Virtual-button binding: a boolean fed by the on-screen button
whose identity in Zin.virtual is opts.id. A button of a button
control in an activated .inputMap takes the control's name as its id
when it states none; otherwise the id falls back to a string
opts.label, then to the catalog key of an i18n.text label, then to
opts.zone (Zin.bindings.touchButtonId). Code that presses, tests or gates on
a button (Zin.virtual.button, Zin.arming.gate { virtualButtons },
Zin.test.tapTouchButton) names it by that id.
priority (lower renders first/more prominent on the touch overlay;
defaults to 50 when omitted), size ("small"|"medium"|"large",
defaults to "medium" - this button's own circle radius, whatever
else the overlay is drawing), group (buttons sharing a group
render adjacently) and place shape the overlay's layout - see
Zin.touchControls. place is "column" (the default: the action
column growing inward from the bottom-right corner, where a game's
actions go) or "corner" (the top-right corner of the safe area, rows
along the top edge over the look area, for a control that works the
app around the game rather than the game, such as the app menu's
pause action). A corner button keeps its place whatever the column
holds, so the controls a game draws in the column's place stay clear
of it.
label is what the circle reads: text, or an i18n.text value that
reads in the player's language (Zin.bindings.labelText). A control
in an .inputMap shows its own label on its buttons. icon is a
glyph drawn in its place - modules.icons names the phosphor set the default
iconFont selects, and any string the face holds a glyph for draws.
fill, stroke, strokeWidth, textColor, fontFamily,
fontScale, iconFont and iconScale state THIS button's
appearance over whatever Zin.touchControls.setAppearance set for
the overlay. A colour takes the CSS forms the canvas accepts; a
family takes the list style.fontFamily takes (ui.listFonts()
names them); a scale is the share of the button's radius the glyph
is set at.
Parameters
optsTouchButtonOpts— { id: string?, zone: string?, label: (string | i18n.text)?, icon: string?, priority: number?, size: string?, group: string?, place: string?, fill: string?, stroke: string?, strokeWidth: number?, textColor: string?, fontFamily: string?, fontScale: number?, iconFont: string?, iconScale: number? } - at least one of id, zone or label.
Returns Binding — The binding descriptor.
B.touchButton({ zone = "right-lower", label = "Jump", priority = 10 })
B.touchButton({ id = "up", zone = "right-lower", label = i18n.text("controls.button.up") })
B.touchButton({ zone = "right-lower", label = "Fire", icon = Icon.Bomb, fill = "#7d1d1d", stroke = "#e8b33a" })
B.touchButton({ id = "pause", label = "Pause", place = "corner", size = "small" })
typed/builtin//modules/zinput/bindings/M/touchButtonId
M.touchButtonId(b: any?) -> string
A touch button's identity in Zin.virtual: its id, else a
string label, else the catalog key of an i18n.text label, else its
zone. A button of a button control takes the control's name as its
id when its map activates, so two controls whose buttons share a
zone stay distinct. A label read from a catalog names the button by
its key, which is the same in every language, and two buttons in one
zone whose labels read from different messages stay two buttons.
Parameters
bany(optional) — AtouchButtonbinding.
Returns string — The identity, "" when the binding carries none.
Zin.virtual.button(Zin.bindings.touchButtonId(binding))
typed/builtin//modules/zinput/bindings/M/touchDrag
M.touchDrag(opts: { zone: string, axis: string? }) -> Binding
Touch-drag binding: a per-frame delta vector fed by drags in
opts.zone (mouseDelta semantics — px this frame).
Parameters
opts{ zone: string, axis: string? }— { zone: string } — the drag zone id (e.g. "right").
Returns Binding — The binding descriptor.
B.touchDrag({ zone = "right" })
typed/builtin//modules/zinput/bindings/M/touchPinch
M.touchPinch(opts: StickOpts?) -> Binding
Pinch binding: a scalar axis fed by the two-finger pinch delta (px this tick; positive = spreading).
Parameters
optsStickOpts(optional)
Returns Binding — The binding descriptor.
B.touchPinch()
typed/builtin//modules/zinput/bindings/M/touchStick
M.touchStick(opts: { zone: string, axis: string? }) -> Binding
Virtual-stick binding: a vector fed by the on-screen stick in
opts.zone (components -1..1). Evaluates {x=0,y=0} while no
control writes the zone.
Parameters
opts{ zone: string, axis: string? }— { zone: string } — the stick's zone id (e.g. "left").
Returns Binding — The binding descriptor.
B.touchStick({ zone = "left" })
typed/builtin//modules/zinput/bindings/M/vector
M.vector(right: Binding, left: Binding, up: Binding, down: Binding) -> Binding
Bind to a 2-D vector. Each arm is a binding that contributes to
one axis when held. The returned vector is
{ x = right - left, y = up - down }.
Parameters
rightBinding— The binding that drives+x.leftBinding— The binding that drives-x.upBinding— The binding that drives+y.downBinding— The binding that drives-y.
Returns Binding — A vector binding descriptor.
local b = Zin.bindings.vector(B.key("KeyD"), B.key("KeyA"), B.key("KeyW"), B.key("KeyS"))
typed/builtin//modules/zinput/bindings/M/wasd
M.wasd() -> Binding
Convenience: WASD as a vector binding. Identical to
vector(key("KeyD"), key("KeyA"), key("KeyW"), key("KeyS")).
Returns Binding — A vector binding for WASD.
local move = Zin.bindings.wasd()
typed/builtin//modules/zinput/chords/M/_advanceTime
M._advanceTime(_dt: number)
Internal: age out stale recognizers. Called once per tick.
Parameters
_dtnumber— Frame delta in seconds (currently unused; recognizers age off wall-clock time).
Zin.chords._advanceTime(0.016)
typed/builtin//modules/zinput/chords/M/_beginTick
M._beginTick()
Internal: clear per-frame firedThisTick flags. Called at the
start of each Zin.tick.
Zin.chords._beginTick()
typed/builtin//modules/zinput/chords/M/_dispatchFires
M._dispatchFires()
Internal: dispatch onFire callbacks for chords that fired
this tick. Called at the end of Zin.tick.
Zin.chords._dispatchFires()
typed/builtin//modules/zinput/chords/M/_observeEvent
M._observeEvent(ev: any?)
Internal: feed one event into each defined chord's state
machine. Called by Zin.tick for every event in this frame's
__zero_input.events().
Parameters
evany(optional) — One input event from the frame log.
Zin.chords._observeEvent(ev)
typed/builtin//modules/zinput/chords/M/_setEnsureLiveFn
M._setEnsureLiveFn(fn: () -> ())
Internal: wire the liveness hook. Called once at module-load
time from zinput/init.luau.
Parameters
fn() -> ()— The hook invoked on every subscription below.
M._setEnsureLiveFn(ensureInputLive)
typed/builtin//modules/zinput/chords/M/_settled
M._settled() -> boolean
Internal: whether every recognizer sits idle -- no sequence mid-entry, no simultaneous press collecting, no fire pending dispatch. The tick's quiescence gate reads it.
Returns boolean — true when no recognizer holds in-flight state.
if Zin.chords._settled() then ... end
typed/builtin//modules/zinput/chords/M/cancel
M.cancel(name: string)
Manually reset the chord's progress (e.g. on context switch).
Parameters
namestring— The chord name.
Zin.chords.cancel("konami")
typed/builtin//modules/zinput/chords/M/clear
M.clear()
Wipe every chord, state, and subscriber. Primarily for tests.
Zin.chords.clear()
typed/builtin//modules/zinput/chords/M/define
M.define(spec: ChordSpec)
Define one or more chords. Each entry replaces any existing chord under the same name; other chords are preserved.
Parameters
specChordSpec— Map ofname -> { kind = "sequence"|"simultaneous", ... }.
Zin.chords.define({ konami = { kind = "sequence", steps = {...} } })
typed/builtin//modules/zinput/chords/M/fired
M.fired(name: string) -> boolean
True on exactly one frame: the frame the chord completed its pattern.
Parameters
namestring— The chord name.
Returns boolean — Whether the chord fired this frame.
if Zin.chords.fired("konami") then print("bonus unlocked") end
typed/builtin//modules/zinput/chords/M/get
M.get(name: string) -> ChordDef?
Internal introspection: definition record (or nil).
Parameters
namestring— The chord name.
Returns ChordDef? — The internal ChordDef record, or nil if not defined.
local def = Zin.chords.get("konami")
typed/builtin//modules/zinput/chords/M/has
M.has(name: string) -> boolean
True if a chord with this name is defined.
Parameters
namestring— The chord name.
Returns boolean — Whether the chord exists in the registry.
if Zin.chords.has("konami") then ... end
typed/builtin//modules/zinput/chords/M/names
M.names() -> { string }
All defined chord names, in arbitrary order.
Returns { string } — A fresh array of chord names.
for _, n in ipairs(Zin.chords.names()) do print(n) end
typed/builtin//modules/zinput/chords/M/off
M.off(handle: OnFireHandle)
Cancel an onFire subscription.
Parameters
handleOnFireHandle— The handle returned byonFire.
Zin.chords.off(h)
typed/builtin//modules/zinput/chords/M/onFire
M.onFire(name: string, callback: () -> (), opts: OnFireOpts?) -> OnFireHandle
Register a callback fired when the named chord completes.
Returns a handle for off(). Multiple callbacks per chord
dispatch in insertion order.
Parameters
namestring— The chord name.callback() -> ()— Invoked when the chord fires.optsOnFireOpts(optional) — Optional{ context, once }.
Returns OnFireHandle — A handle whose off() cancels the subscription.
local h = Zin.chords.onFire("konami", function() ... end)
typed/builtin//modules/zinput/chords/M/progress
M.progress(name: string) -> number
Progress through the chord, 0..1. For sequences: matched- steps / total. For simultaneous: matched / total. Always 0 when not in flight.
Parameters
namestring— The chord name.
Returns number — Progress as a number in [0, 1].
local p = Zin.chords.progress("konami")
typed/builtin//modules/zinput/chords/M/remove
M.remove(name: string)
Remove a chord. No-op if not defined. Subscribers on the same name are dropped along with it.
Parameters
namestring— The chord name.
Zin.chords.remove("konami")
typed/builtin//modules/zinput/clock/M/_setClock
M._setClock(fn: (() -> number)?)
Internal: override the input clock with fn (returns seconds), or pass
nil to restore the engine clock. Exposed for deterministic timing —
fixed-step replay and tests that need a controllable clock.
Parameters
fn(() -> number)(optional) — A clock returning seconds, ornilto restore the default source.
require("@builtin::modules.zinput.clock")._setClock(function() return t end)
typed/builtin//modules/zinput/clock/M/nowSeconds
M.nowSeconds() -> number
Current wall-clock seconds for input timing. Reads the engine's
per-frame getTime(), falling back to os.clock() where no engine time
surface exists. Honors a clock injected via _setClock.
Returns number — Seconds of wall time.
local t = require("@builtin::modules.zinput.clock").nowSeconds()
typed/builtin//modules/zinput/conflicts/M/_loadIntentionalPairs
M._loadIntentionalPairs(pairs_: any?)
Internal: seed the working set from a saved profile's
intentional_pairs field. Called on Zin.profile.activate. The
input shape is { ["a"] = "b", ... } or { {a, b}, ... } —
the JSON encoder lays it out as the array shape, but a hand-
edited profile may use either. Silently ignores malformed
entries.
Parameters
pairs_any(optional) — The raw saved pair list.
Conflicts._loadIntentionalPairs(profileJson.intentional_pairs)
typed/builtin//modules/zinput/conflicts/M/_resetIntentional
M._resetIntentional()
Test-only: wipe the working set. Suite isolation; not part of the public contract.
Zin.conflicts._resetIntentional()
typed/builtin//modules/zinput/conflicts/M/_serializeIntentional
M._serializeIntentional() -> { { string } }
Serialize the working set for Zin.profile.save / export.
Output is an array of { "a", "b" } pairs in canonical order —
matches the shape _loadIntentionalPairs consumes on activate,
so the round-trip is lossless.
Returns { { string } } — The serialized intentional-pair list.
local rows = Zin.conflicts._serializeIntentional()
typed/builtin//modules/zinput/conflicts/M/_setPersistFn
M._setPersistFn(fn: () -> ())
Internal: register the closure that writes the current
intentional-pair list back to the active profile. Wired by
zinput.init so the profile module doesn't have to depend on
conflicts (one-way edge).
Parameters
fn() -> ()— The persist closure.
local Profile = require("@builtin::modules.zinput.profile")
Conflicts._setPersistFn(function() Profile.save(...) end)
typed/builtin//modules/zinput/conflicts/M/bindingKey
M.bindingKey(b: any?) -> string?
Canonical leaf key for a single discrete binding, or nil if
the binding has no single discrete identity (axis, vector,
mouseDelta, scroll, pointerLocked).
Outputs:
key:Space — { kind = "key", code = "Space" }
modKey:Ctrl+Shift+KeyS — { kind = "modKey", code = "KeyS", mods = { ctrl, shift } }
mouse:left — { kind = "mouse", button = "left" }
Parameters
bany(optional) — The binding to canonicalise.
Returns string? — The canonical leaf-key string, or nil when the binding has no single identity.
local k = Zin.conflicts.bindingKey(B.key("Space")) -- "key:Space"
typed/builtin//modules/zinput/conflicts/M/find
M.find(binding: any?) -> { Owner }
Find every action/axis whose binding shares a leaf key with
the probe. Returns an array of { target, name, slot?, context? }
owners. Empty on no conflict. Decomposes axis/vector bindings on both
sides — a probe key:Space matches an axis whose plus = Space.
Parameters
bindingany(optional) — The binding to look up.
Returns { Owner } — An array of conflict owners.
local owners = Zin.conflicts.find(B.key("Space"))
typed/builtin//modules/zinput/conflicts/M/forActiveProfile
M.forActiveProfile() -> { ConflictRow }
Enumerate every leaf key shared by two or more owners across
the active action + axis registries. Returns an array sorted by
key for deterministic UI rendering; empty when there are no
conflicts. Each row carries a kind = "real" | "intentional"
field — see module about-block for the classification rule.
Returns { ConflictRow } — An array of ConflictRow records.
for _, row in ipairs(Zin.conflicts.forActiveProfile()) do ... end
typed/builtin//modules/zinput/conflicts/M/isIntentional
M.isIntentional(actionA: string, actionB: string) -> boolean
True when (actionA, actionB) is currently marked
intentional. Symmetric: (a, b) and (b, a) produce the same
answer.
Parameters
actionAstring— The first action name.actionBstring— The second action name.
Returns boolean — Whether the pair is currently marked.
if Zin.conflicts.isIntentional("a", "b") then ... end
typed/builtin//modules/zinput/conflicts/M/leafKeys
M.leafKeys(binding: any?) -> { string }
Every leaf key a binding decomposes into: one for a discrete
binding, one per arm for an axis or vector, and none for a
continuous source (mouseDelta, scroll) which has no discrete
identity to share.
This is the canonical form two bindings are compared in — what makes
Shift+Ctrl+KeyS and Ctrl+Shift+KeyS the same key, and what lets a
caller outside this module ask whether a control declares an input
without writing a second comparison of its own.
Parameters
bindingany(optional) — The binding to decompose.
Returns { string } — The leaf keys, possibly empty.
local keys = Zin.conflicts.leafKeys(B.mouse("right"))
typed/builtin//modules/zinput/conflicts/M/listIntentional
M.listIntentional() -> { { string } }
All currently-marked pairs, sorted lexicographically for deterministic UI rendering. Each pair is returned in canonical order (lexicographic ascending).
Returns { { string } } — An array of { a, b } pairs.
for _, p in ipairs(Zin.conflicts.listIntentional()) do ... end
typed/builtin//modules/zinput/conflicts/M/markIntentional
M.markIntentional(actionA: string, actionB: string) -> (boolean, string?)
Mark a pair of actions as intentionally sharing a binding. The
pair is suppressed from realOnly() until unmarkIntentional
reverses it. Stored in the active user profile's JSON so the mark
survives restart. Built-in profiles (Luau modules) hold marks in
memory only for the session — the natural flow is "mark → save
as user profile" if you want them to persist.
Parameters
actionAstring— The first action name.actionBstring— The second action name.
Returns (boolean, string?) — (true) on success, (false, err) when either action is unknown or both names are equal.
local ok, err = Zin.conflicts.markIntentional("crouch", "slide")
typed/builtin//modules/zinput/conflicts/M/realOnly
M.realOnly() -> { ConflictRow }
Subset of forActiveProfile() filtered to kind == "real"
rows only — the noise-filtered view the Input tab uses by
default.
Returns { ConflictRow } — The real conflicts only.
for _, row in ipairs(Zin.conflicts.realOnly()) do ... end
typed/builtin//modules/zinput/conflicts/M/unmarkIntentional
M.unmarkIntentional(actionA: string, actionB: string) -> boolean
Remove a previously-marked intentional pair. Idempotent: unmarking an absent pair is a no-op success.
Parameters
actionAstring— The first action name.actionBstring— The second action name.
Returns boolean — Whether the inputs were accepted (true unless either name was non-string).
Zin.conflicts.unmarkIntentional("crouch", "slide")
typed/builtin//modules/zinput/context/M/contains
M.contains(name: string) -> boolean
True if name is anywhere in the active stack (not just the
top). Useful for "is UI open?" checks regardless of further pushes.
Parameters
namestring— The context name to look for.
Returns boolean — Whether name appears anywhere in the stack.
if Zin.context.contains("ui") then engine.paused = true end
typed/builtin//modules/zinput/context/M/current
M.current() -> string
Current (top-of-stack) context name. Always at least default.
Returns string — The name at the top of the stack.
if Zin.context.current() == "ui" then ... end
typed/builtin//modules/zinput/context/M/default
M.default() -> string
The always-on context name. Anything declared without an explicit
context belongs here. The bottom of the stack is permanently this
value; pop cannot remove it.
Returns string — The default context name (the string "default").
local d = Zin.context.default() -- "default"
typed/builtin//modules/zinput/context/M/pop
M.pop() -> string?
Pop the top context. No-op when only default remains (so
unbalanced pop is safe and never leaves the stack empty).
Returns string? — The popped context name, or nil when the stack already held only default.
local prev = Zin.context.pop()
typed/builtin//modules/zinput/context/M/push
M.push(name: any?)
Push a context onto the stack. Becomes the new "current" context. Pushing the same context twice requires two pops to fully remove (matches typical UI nesting).
Parameters
nameany(optional) — The context name to push. Ignored when not a non-empty string.
Zin.context.push("ui")
typed/builtin//modules/zinput/context/M/reset
M.reset()
Pop everything except default. Useful for "exit all menus"
flows and for test setup/teardown.
Zin.context.reset()
typed/builtin//modules/zinput/context/M/stack
M.stack() -> { string }
Snapshot of the full stack, bottom→top. Returned table is a copy; mutating it does not affect the live stack.
Returns { string } — A copy of the active context stack.
local snap = Zin.context.stack()
typed/builtin//modules/zinput/context/M/with
M.with(name: string, fn: () -> T...) -> T...
Run fn with name pushed onto the stack; pop guaranteed on
return or error. Returns whatever fn returns.
Parameters
namestring— The context to push during the call.fn() -> T...— The thunk to run withnameon top of the stack.
Returns T... — Whatever fn returns.
Zin.context.with("ui", function() ... end)
typed/builtin//modules/zinput/controllers/M/fps
M.fps(opts: FpsOpts) -> FpsController
Construct a first-person walker controller.
Parameters
optsFpsOpts— FpsOpts table.
Returns FpsController — An FpsController object with :start/:stop/:update plus motion-intent readers (getDesiredVelocity, consumeJumpRequest, isSprinting, isCrouching).
local c = Zin.controllers.fps({ entity = playerId })
typed/builtin//modules/zinput/controllers/M/free
M.free(opts: FreeOpts) -> FreeController
Construct a free-fly designer/debug camera controller.
WASD plane motion + Q/E vertical + ShiftLeft sprint multiplier +
raw mouse-look (always reads the per-frame mouse delta — gating
is via Zin.context, not via pointer-lock). Mandatory: opts.entity
(entity ID string from entity.spawn(...).id). All other fields
default; pass actionPrefix to namespace if two free controllers
must coexist.
Parameters
optsFreeOpts— FreeOpts table.
Returns FreeController — A FreeController object with :start/:stop/:update.
local c = Zin.controllers.free({ entity = id })
typed/builtin//modules/zinput/controllers/M/orbit
M.orbit(opts: OrbitOpts) -> OrbitController
Construct an orbit camera controller around opts.target.
target is either an entity ID string (the orbit center tracks
that entity each frame) or a fixed { x, y, z } table.
Parameters
optsOrbitOpts— OrbitOpts table.
Returns OrbitController — An OrbitController object with :start/:stop/:update.
local c = Zin.controllers.orbit({ entity = cam, target = pivot })
typed/builtin//modules/zinput/controllers/M/vehicle
M.vehicle(opts: VehicleOpts?) -> VehicleController
Construct a driving controller: the throttle, steering, brake,
handbrake, boost, recover and zoom a player gives a ground vehicle,
read from an input map that binds each one on keyboard, gamepad and
touch. opts.inputMap defaults to @builtin::inputMaps.vehicle
(W/S throttle, A/D steer, Space brake, Ctrl handbrake, Shift boost,
R recover, scroll zoom). :start() takes the controls, which stands
the walking scheme down while somebody drives; :stop() gives them
back. The VehicleController component drives a car's
WheelColliders from this intent.
Parameters
optsVehicleOpts(optional) — VehicleOpts table, optional:inputMap(asset ref or path),label.
Returns VehicleController — A VehicleController object with :start/:stop/:update/:isActive and the intent readers getThrottle (-1..1, positive forward), getSteer (-1..1, positive right), getBrake (0..1), isHandbrakeHeld, isBoosting, consumeRecoverRequest and consumeZoom.
local drive = Zin.controllers.vehicle(); drive:start(); print(drive:getThrottle())
typed/builtin//modules/zinput/emulation/M/_advance
M._advance()
Internal: advance the emulation floor one tick. Releases every
emitted key when the active map or the input context changed since
the previous tick, then re-derives button / stick / drag emulation
from the current effective map's touch/kbm binding pairs — active-
context entries only. No-op when no map is active. Wired into
Zin.tick.
Zin.emulation._advance()
typed/builtin//modules/zinput/emulation/M/_reset
M._reset()
Test-only: release everything emitted and clear tracked state.
Zin.emulation._reset()
typed/builtin//modules/zinput/emulation/M/_settled
M._settled() -> boolean
Internal: whether the emulation floor is producing nothing -- no synthesized pointer motion, no emulated key held. The tick's quiescence gate reads it.
Returns boolean — true when the floor is at rest.
if Zin.emulation._settled() then ... end
typed/builtin//modules/zinput/emulation/M/getSensitivity
M.getSensitivity() -> number
The current touchDrag -> emulated mouse-delta multiplier.
Returns number — The sensitivity multiplier.
local s = Zin.emulation.getSensitivity()
typed/builtin//modules/zinput/emulation/M/setSensitivity
M.setSensitivity(n: number)
Set the touchDrag -> emulated mouse-delta multiplier (default 1.0).
Parameters
nnumber— The sensitivity multiplier.
Zin.emulation.setSensitivity(1.5)
typed/builtin//modules/zinput/emulation/M/synthesizedDelta
M.synthesizedDelta() -> (boolean, number, number)
The mouse delta this floor synthesized on the current tick, and whether it synthesized one at all. A drag the floor converted for a control the scheme does not cover is a delta the evaluators should read, where the platform's projection of the same contact is not.
Returns (boolean, number, number) — (active, dx, dy)
local ok, dx, dy = Zin.emulation.synthesizedDelta()
typed/builtin//modules/zinput/events/M/_dispatch
M._dispatch(events: any?)
Internal: dispatch a batch of events to every registered
subscriber. Called once per Zin.tick from the events stage of
the tick pipeline.
Parameters
eventsany(optional) — The frame's events as returned byM.frame().
M._dispatch(Zin.events.frame())
typed/builtin//modules/zinput/events/M/_onHeldByCaller
M._onHeldByCaller(filter: EventFilter, callback: (any) -> (), opts: SubOpts?) -> SubHandle
Internal: on for a caller that holds the subscription itself,
such as a composite handle over several subscriptions that ends with
the context which made it. Registers nothing under the calling context.
Parameters
filterEventFilter— Asontakes it.callback(any) -> ()— Asontakes it.optsSubOpts(optional) — Asontakes it.
Returns SubHandle — A handle whose off() cancels the subscription.
local h = Events._onHeldByCaller("key.down", fn)
typed/builtin//modules/zinput/events/M/_setEnsureLiveFn
M._setEnsureLiveFn(fn: () -> ())
Internal: wire the liveness hook. Called once at module-load
time from zinput/init.luau.
Parameters
fn() -> ()— The hook invoked on every subscription below.
M._setEnsureLiveFn(ensureInputLive)
typed/builtin//modules/zinput/events/M/clearSubscribers
M.clearSubscribers()
Cancel every subscription. Primarily for test isolation.
Zin.events.clearSubscribers()
typed/builtin//modules/zinput/events/M/frame
M.frame() -> { InputEvent }
Get this frame's events as an array of records, in dispatch
order. Every x, y is in the scene viewport's physical pixels,
measured from the top-left of the rect the scene is drawn into: the
space Zin.state.get().mouse_position and Zin.touch.slots() read
in. A mouse.* event the primary touch contact drove carries that
contact's id as touch; a mouse's own carries none. An event a
script's simulated input produced carries simulated = true; a
device's carries none. Returns an empty
table if __zero_input.events is missing or returns a non-table
value.
Returns { InputEvent } — The current frame's events (a fresh array each call).
for _, ev in ipairs(Zin.events.frame()) do ... end
typed/builtin//modules/zinput/events/M/iter
M.iter()
Iterate this frame's events. Identical to
ipairs(Zin.events.frame()) but the explicit name reads better
at call sites.
Returns An ipairs-style iterator over this frame's events.
for i, ev in Zin.events.iter() do ... end
typed/builtin//modules/zinput/events/M/keysDown
M.keysDown() -> { InputEvent }
All key.down events this frame.
Returns { InputEvent } — The frame's key.down events in dispatch order.
for _, ev in ipairs(Zin.events.keysDown()) do print(ev.code) end
typed/builtin//modules/zinput/events/M/keysUp
M.keysUp() -> { InputEvent }
All key.up events this frame.
Returns { InputEvent } — The frame's key.up events in dispatch order.
for _, ev in ipairs(Zin.events.keysUp()) do ... end
typed/builtin//modules/zinput/events/M/mouseDowns
M.mouseDowns() -> { InputEvent }
All mouse.down events this frame.
Returns { InputEvent } — The frame's mouse.down events in dispatch order.
for _, ev in ipairs(Zin.events.mouseDowns()) do ... end
typed/builtin//modules/zinput/events/M/mouseMoves
M.mouseMoves() -> { InputEvent }
All mouse.move events this frame.
Returns { InputEvent } — The frame's mouse.move events in dispatch order.
for _, ev in ipairs(Zin.events.mouseMoves()) do ... end
typed/builtin//modules/zinput/events/M/mouseUps
M.mouseUps() -> { InputEvent }
All mouse.up events this frame.
Returns { InputEvent } — The frame's mouse.up events in dispatch order.
for _, ev in ipairs(Zin.events.mouseUps()) do ... end
typed/builtin//modules/zinput/events/M/mouseWheels
M.mouseWheels() -> { InputEvent }
All mouse.wheel events this frame.
Returns { InputEvent } — The frame's mouse.wheel events in dispatch order.
for _, ev in ipairs(Zin.events.mouseWheels()) do ... end
typed/builtin//modules/zinput/events/M/off
M.off(handle: SubHandle | number)
Cancel a subscription. Accepts a Handle returned from on or
a numeric id.
Parameters
handleSubHandle | number— Handle or numeric subscription id.
Zin.events.off(h)
typed/builtin//modules/zinput/events/M/on
M.on(filter: EventFilter, callback: (any) -> (), opts: SubOpts?) -> SubHandle
Register a callback fired when matching events arrive on
Zin.tick. Returns a handle for off(). The subscription ends with
the context that made it as well: a component's with that component
instance, a module body's with the module's next run.
Parameters
filterEventFilter— Either a kind string ("key.down"), a table of field matches ({ kind = "key.down", code = "Space" }), or a predicate functionfunction(ev) return ... end.callback(any) -> ()— Invoked ascallback(event, gpe)wheregpeis whether the UI layer took THIS event: the event's ownconsumed_by_uimarker, stamped against the focus the UI holds over the surface it arrived on. Returning"sink"halts further (lower-priority) dispatch for that event.optsSubOpts(optional) — Optional{ context, once, priority }.
Returns SubHandle — A handle whose off() cancels the subscription.
local h = Zin.events.on("key.down", function(ev) ... end)
typed/builtin//modules/zinput/events/M/subscriberCount
M.subscriberCount() -> number
Test/introspection: number of active subscribers.
Returns number — The current subscriber count.
assert(Zin.events.subscriberCount() == 0)
typed/builtin//modules/zinput/events/M/texts
M.texts() -> { InputEvent }
All text events this frame (composed text commits).
Returns { InputEvent } — The frame's text events in dispatch order.
for _, ev in ipairs(Zin.events.texts()) do print(ev.text) end
typed/builtin//modules/zinput/gamepad/M/available
M.available() -> boolean
Whether this session has ever seen a pad device. Latched by a
device pad's first connection, so unplugging one does not flip a
scheme's prompts back to keyboard glyphs on a cable knock. A pad the
inputSim toolbox connects reads as one only while it is connected.
Returns boolean — True once a device pad has connected, or while a simulated pad is connected.
if Zin.gamepad.available() then print("show the pad prompts") end
typed/builtin//modules/zinput/gamepad/M/capabilities
M.capabilities(slot: number | string) -> Capabilities?
Which haptic outputs reach the pad in slot on this platform and
device, each { supported, reason? }: rumble (the two body motors),
triggerRumble (the motors behind the triggers), and the
force-feedback effects a wheel or stick plays on its own axes:
constant (a force pushing one way), spring (pulling back toward a
centre), damper (resisting speed) and friction (resisting any
movement). An unsupported output carries the reason (the browser
Gamepad API has no force effects, a device reports no motors or no
such effect, the platform's backend drives the rumble motors only),
and Zin.gamepad.rumble / Zin.gamepad.force refuse an output the
pad does not offer with that reason.
Parameters
slotnumber | string— The pad slot, or a piece of a device's name.
Returns Capabilities? — The capability record, or nil when nothing holds the slot.
if Zin.gamepad.capabilities(0).rumble.supported then ... end
typed/builtin//modules/zinput/gamepad/M/count
M.count() -> number
How many pads are connected.
Returns number — The count.
if Zin.gamepad.count() >= 2 then print("two pads: start co-op") end
typed/builtin//modules/zinput/gamepad/M/device
M.device(slot: number | string) -> Device?
What the device in slot is and every element it reports: its
name, a stable id for the model (the SDL-style GUID on the
desktop, the browser's description on the web), vendor / product
where the platform states them, mapping (which layout assigned the
canonical names: standard, sdl, driver or none), and every
axis and button in the device's own order. Each axis carries its
0-based index, the native range min..max the device reports it in
(read as -1..1 by Zin.state.padAxis(index)), and the canonical
name it also drives when the mapping names one; each button its
index and name. A binding screen offers these, and
Zin.bindings.padAxis(index) / padButton(index) bind them.
Parameters
slotnumber | string— The pad slot, or a piece of a device's name.
Returns Device? — The device record, or nil when nothing holds the slot.
local d = Zin.gamepad.device(0); print(d.name, d.axisCount, d.buttonCount)
local pedals = Zin.gamepad.device("pedals")
typed/builtin//modules/zinput/gamepad/M/family
M.family(slot: (number | string)?) -> string
Which controller family a pad belongs to, read from the device
name the platform reported: "xbox", "playstation", "nintendo",
or "xr" for a headset's hand controllers, which present as one pad
while the session holds input focus. Xbox is the answer for anything
unrecognised, because the standard mapping every backend normalises to
is the Xbox layout. With no slot it answers for the pad the person
holds: the hand controllers while a headset session holds input focus,
else the first connected pad. A device selector that names a family
("xr-touch-controllers") answers that family whether or not the pad
is connected now.
Parameters
slot(number | string)(optional) — Pad slot, a piece of a device's name, or nil for the pad held.
Returns string — The family name.
if Zin.gamepad.family() == "playstation" then ... end
typed/builtin//modules/zinput/gamepad/M/force
M.force(slot: number | string, effects: ForceEffects)
Hold force-feedback effects on a wheel or stick: constant (a
force -1..1 along the device's first axis, a wheel's rotation, a
positive and a negative level pushing it opposite ways), and spring,
damper and friction, each a strength -1..1 or { strength, saturation?, center?, deadband? } (saturation 0..1 caps the force,
center -1..1 places a
spring's rest point, deadband 0..1 widens the band around it where the
effect does not act). Each effect named holds until the next call and
each one left out stops, so a game calling it every tick with the
forces of the moment, the tyres' aligning torque as a constant, a
centring spring scaled by speed, drives the device continuously. It
refuses, naming the reason Zin.gamepad.capabilities states, an effect
the device or platform does not offer (the browser offers none). The
pad's record (Zin.gamepad.get(slot).force) carries what holds, with
error when the device itself refused it. Leaving play releases every
effect, along with every rumble.
Parameters
slotnumber | string— The pad slot, or a piece of a device's name.effectsForceEffects—{ constant?, spring?, damper?, friction? }.
Zin.gamepad.force("wheel", { constant = -0.3, spring = { strength = 0.5 } })
Zin.gamepad.force(0, { damper = 0.2, friction = { strength = 0.1, saturation = 0.5 } })
typed/builtin//modules/zinput/gamepad/M/get
M.get(slot: number | string) -> Pad?
The pad a selector names, or nil when none does: a slot number,
or a piece of a device's name or id (case folded), the same selector
Zin.bindings.padAxis / padButton take, so a wheel and its separate
pedals are each found by name whatever slot they took. A name several
pads carry names the one in the lowest slot.
Parameters
slotnumber | string— The pad slot, or a piece of a device's name.
Returns Pad? — The pad record, or nil.
local pad = Zin.gamepad.get(0)
local wheel = Zin.gamepad.get("wheel")
typed/builtin//modules/zinput/gamepad/M/label
M.label(button: string, slot: (number | string)?) -> string
What a legend should call a canonical button on the connected
pad, in the player's language: "south" reads as A on an Xbox
pad, Cross on a PlayStation one, B on a Nintendo one, and on a
headset's hand controllers as the button's own name (A, X, Right grip, Left trigger, Menu button). Falls back to the canonical
name for anything the family tables do not cover.
Parameters
buttonstring— Canonical button name.slot(number | string)(optional) — Pad slot, a piece of a device's name, or nil for the pad held.
Returns string — The label to draw.
print("Press " .. Zin.gamepad.label("south") .. " to jump")
typed/builtin//modules/zinput/gamepad/M/list
M.list() -> { Pad }
Every connected pad, in slot order. Each entry carries slot,
name, the three canonical button-name arrays, an axes map, and
whether it came from inputSim rather than a device.
Returns { Pad } — Array of pad records; empty when nothing is connected.
for _, pad in ipairs(Zin.gamepad.list()) do print(pad.slot, pad.name) end
typed/builtin//modules/zinput/gamepad/M/namesBare
M.namesBare(slot: (number | string)?) -> boolean
Whether a pad legend names the button bare (A, Right grip)
rather than as a pad button (Pad-A): true for a headset's hand
controllers, whose buttons a person knows by those names.
Parameters
slot(number | string)(optional) — Pad slot, a piece of a device's name, or nil for the pad held.
Returns boolean — Whether the legend is the bare name.
local bare = Zin.gamepad.namesBare()
typed/builtin//modules/zinput/gamepad/M/rumble
M.rumble(slot: (number | string)?, opts: RumbleOpts) -> { number }
Rumble a pad: strong (the low-frequency body motor), weak (the
high-frequency one), leftTrigger / rightTrigger (the trigger
motors), each 0..1 and 0 when omitted, for seconds. It replaces
whatever the pad was playing, so a game calling it every tick with
the strength of the moment drives the motors continuously. With a
slot it plays on that pad and refuses, naming the reason
Zin.gamepad.capabilities states, a motor the pad does not offer;
with no slot it plays on every connected pad that offers the motors
asked for, and refuses only when none does. The pad's record
(Zin.gamepad.get(slot).rumble) carries what plays and how long is
left, with error when the device itself refused it.
Parameters
slot(number | string)(optional) — The pad slot, a piece of a device's name, or nil for every pad that can.optsRumbleOpts—{ strong?, weak?, leftTrigger?, rightTrigger?, seconds }.
Returns { number } — The slots it plays on.
Zin.gamepad.rumble(0, { strong = 0.8, weak = 0.3, seconds = 0.25 })
Zin.gamepad.rumble(nil, { weak = 0.4, seconds = 0.1 })
typed/builtin//modules/zinput/gamepad/M/stickLabel
M.stickLabel(stick: string, axis: string?, slot: (number | string)?) -> string
What a legend should call a thumbstick, or one axis of it, on the
pad, in the player's language: Left thumbstick, Right thumbstick up/down on a headset's hand controllers, LS on a pad.
Parameters
stickstring—"left"or"right".axisstring(optional) —"x","y", or nil for the whole stick.slot(number | string)(optional) — Pad slot, a piece of a device's name, or nil for the pad held.
Returns string — The label to draw.
print(Zin.gamepad.stickLabel("left") .. ": move")
typed/builtin//modules/zinput/gamepad/M/stopForce
M.stopForce(slot: number | string)
Release every force-feedback effect a pad holds.
Parameters
slotnumber | string— The pad slot, or a piece of a device's name.
Zin.gamepad.stopForce(0)
typed/builtin//modules/zinput/gamepad/M/stopRumble
M.stopRumble(slot: (number | string)?)
Stop the rumble playing on a pad, or on every pad with no slot.
Parameters
slot(number | string)(optional) — The pad slot, a piece of a device's name, or nil for every pad.
Zin.gamepad.stopRumble(0)
typed/builtin//modules/zinput/gestures/M/_advanceTime
M._advanceTime(_dt: number)
Internal: time-based recognition (long-press) + continuous two-finger deltas (pinch, pan). Runs every tick.
Parameters
_dtnumber
Zin.gestures._advanceTime(dt)
typed/builtin//modules/zinput/gestures/M/_beginTick
M._beginTick()
Internal: clear per-tick continuous deltas. First tick of each engine frame.
Zin.gestures._beginTick()
typed/builtin//modules/zinput/gestures/M/_dispatchFires
M._dispatchFires()
Internal: deliver this tick's discrete gesture fires. Handler errors are caught and logged.
Zin.gestures._dispatchFires()
typed/builtin//modules/zinput/gestures/M/_now
M._now() -> number
Internal: the clock gesture timing reads, in seconds.
Returns number — Seconds of wall time.
local t = Zin.gestures._now()
typed/builtin//modules/zinput/gestures/M/_observeEvent
M._observeEvent(ev: any?)
Internal: per-event observer — builds contact tracks and classifies discrete gestures on release.
Parameters
evany(optional) — The raw input event record.
Zin.gestures._observeEvent(ev)
typed/builtin//modules/zinput/gestures/M/_pairDown
M._pairDown() -> boolean
Internal: whether a two-finger gesture is being made right now: exactly two contacts are down that no on-screen widget is working. The overlay reads it to leave that pair to the gesture rather than routing it as one-finger drag motion, so the two agree on which gesture is happening.
Returns boolean — true while the pair is down.
if Zin.gestures._pairDown() then ... end
typed/builtin//modules/zinput/gestures/M/_reset
M._reset()
Test-only: clear all tracks, fires, deltas, and subscriptions.
Zin.gestures._reset()
typed/builtin//modules/zinput/gestures/M/_setWidgetContacts
M._setWidgetContacts(ids: { [number]: boolean })
Internal: name the contacts an on-screen widget is working, so the pair a two-finger gesture reads leaves them out. Published each tick by the overlay that routes touches, before the recognizers run.
Parameters
ids{ [number]: boolean }— A set keyed by contact id.
Zin.gestures._setWidgetContacts({ [3] = true })
typed/builtin//modules/zinput/gestures/M/_settled
M._settled() -> boolean
Internal: whether the recognizers sit idle -- no touch tracks live, no fire pending dispatch, no pinch or pan delta carried. The tick's quiescence gate reads it.
Returns boolean — true when nothing gestural is in flight.
if Zin.gestures._settled() then ... end
typed/builtin//modules/zinput/gestures/M/configure
M.configure(opts: { [string]: number })
Override recognition thresholds. Unspecified fields keep their current values.
Parameters
opts{ [string]: number }— Partial GestureConfig.
Zin.gestures.configure({ longPressDuration = 0.8 })
typed/builtin//modules/zinput/gestures/M/getConfig
M.getConfig() -> GestureConfig
Current recognition thresholds (a copy).
Returns GestureConfig — The GestureConfig table.
local c = Zin.gestures.getConfig()
typed/builtin//modules/zinput/gestures/M/off
M.off(handle: number) -> boolean
Unsubscribe a handle returned by any Zin.gestures.on* function.
Parameters
handlenumber— The numeric handle.
Returns boolean — Whether a subscription was removed.
Zin.gestures.off(h)
typed/builtin//modules/zinput/gestures/M/onDoubleTap
M.onDoubleTap(fn: (any) -> ()) -> number
Subscribe to double-taps. fn(ev) with ev = { x, y, id }. The
release that completes a double-tap also emits a tap on the same
tick (each qualifying release taps; the second one additionally
double-taps).
Parameters
fn(any) -> ()— The callback.
Returns number — A numeric handle for Zin.gestures.off.
Zin.gestures.onDoubleTap(function(ev) ... end)
typed/builtin//modules/zinput/gestures/M/onLongPress
M.onLongPress(fn: (any) -> ()) -> number
Subscribe to long-presses (fires once per contact, while the
finger is still down). fn(ev) with ev = { x, y, id }.
Parameters
fn(any) -> ()— The callback.
Returns number — A numeric handle for Zin.gestures.off.
Zin.gestures.onLongPress(function(ev) print("long press", ev.x, ev.y) end)
typed/builtin//modules/zinput/gestures/M/onSwipe
M.onSwipe(fn: (any) -> ()) -> number
Subscribe to swipes (fires on release). fn(ev) with ev =
{ direction = "left"|"right"|"up"|"down", dx, dy, velocity, id }.
Parameters
fn(any) -> ()— The callback.
Returns number — A numeric handle for Zin.gestures.off.
Zin.gestures.onSwipe(function(ev) if ev.direction == "left" then ... end end)
typed/builtin//modules/zinput/gestures/M/onTap
M.onTap(fn: (any) -> ()) -> number
Subscribe to taps. fn(ev) with ev = { x, y, id, duration }.
Parameters
fn(any) -> ()— The callback.
Returns number — A numeric handle for Zin.gestures.off.
Zin.gestures.onTap(function(ev) select(ev.x, ev.y) end)
typed/builtin//modules/zinput/gestures/M/panDelta
M.panDelta() -> (number, number)
This tick's two-finger pan delta: movement of the contacts' centroid, in px. Zeros unless exactly two contacts are down that no on-screen widget is working.
Returns (number, number) — dx, dy.
local dx, dy = Zin.gestures.panDelta()
typed/builtin//modules/zinput/gestures/M/pinchDelta
M.pinchDelta() -> number
This tick's two-finger pinch delta: change in the distance between the two contacts, in px (positive = spreading). 0 unless exactly two contacts are down that no on-screen widget is working. A thumb on a movement stick or a button is operating that control, and the gesture reads the contacts left over.
Returns number — The pinch delta.
cam.zoom += Zin.gestures.pinchDelta() * 0.01
typed/builtin//modules/zinput/input/M/_disconnectAll
M._disconnectAll()
Test-only: tear down every Zin.input subscription installed
this session.
Zin.input._disconnectAll()
typed/builtin//modules/zinput/input/M/_observeEvent
M._observeEvent(ev: any?)
Internal observer driven by Zin.tick. Receives every event in
the same drain loop as State / Chords and updates _lastInputType.
Parameters
evany(optional) — The raw input event record.
Zin.input._observeEvent(ev)
typed/builtin//modules/zinput/input/M/_owns
M._owns(handle: number) -> boolean
Internal: reports whether handle was issued by this module.
Used by the unified Zin.disconnect to route ownership.
Parameters
handlenumber— Candidate handle id.
Returns boolean — true when this module owns the handle.
if Zin.input._owns(h) then ... end
typed/builtin//modules/zinput/input/M/_reset
M._reset()
Test-only: clear lastInputType. Public so test suites can
isolate cases.
Zin.input._reset()
typed/builtin//modules/zinput/input/M/_setAllocator
M._setAllocator(fn: () -> number)
Internal: wire a shared id allocator. Called once at
module-load time from zinput/init.luau.
Parameters
fn() -> number— A() -> numberallocator that returns fresh handle ids.
Zin.input._setAllocator(zin._allocateHandle)
typed/builtin//modules/zinput/input/M/disconnect
M.disconnect(handle: Handle) -> boolean
Tear down a subscription returned by Zin.input.on*. Idempotent.
Parameters
handleHandle— The composite handle returned by anon*call.
Returns boolean — true if a subscription was disconnected, false if the handle was unknown or already disconnected.
Zin.input.disconnect(h)
typed/builtin//modules/zinput/input/M/lastInputType
M.lastInputType() -> string?
Returns the userInputType of the most recent input event this session.
"Keyboard" | "Mouse" | "Touch" | nil.
Returns string? — The userInputType string, or nil if no events seen yet.
local t = Zin.input.lastInputType()
typed/builtin//modules/zinput/input/M/onBegan
M.onBegan(fn: (any, boolean) -> any, opts: SubOpts?) -> Handle
Fires on press / mouse-button-down. Handler: fn(io, gpe) -> "sink"?.
Parameters
fn(any, boolean) -> any— Handler(io, gpe) -> "sink"?.optsSubOpts(optional) — Optional{ priority, context, once }forwarded toZin.events.on.
Returns Handle — A composite handle usable with disconnect / Zin.actions.disconnect.
Zin.input.onBegan(function(io, gpe) print(io.kind) end)
typed/builtin//modules/zinput/input/M/onChanged
M.onChanged(fn: (any, boolean) -> any, opts: SubOpts?) -> Handle
Fires on mouse motion / scroll. Handler: fn(io, gpe) -> "sink"?.
Parameters
fn(any, boolean) -> any— Handler(io, gpe) -> "sink"?.optsSubOpts(optional) — Optional{ priority, context, once }.
Returns Handle — A composite handle.
Zin.input.onChanged(function(io, gpe) ... end)
typed/builtin//modules/zinput/input/M/onEnded
M.onEnded(fn: (any, boolean) -> any, opts: SubOpts?) -> Handle
Fires on release / mouse-button-up. Handler: fn(io, gpe) -> "sink"?.
Parameters
fn(any, boolean) -> any— Handler(io, gpe) -> "sink"?.optsSubOpts(optional) — Optional{ priority, context, once }.
Returns Handle — A composite handle.
Zin.input.onEnded(function(io, gpe) ... end)
typed/builtin//modules/zinput/input/M/onTextInput
M.onTextInput(fn: (string, boolean) -> any, opts: SubOpts?) -> Handle
Fires on committed text input. Handler: fn(text, gpe) -> "sink"?.
Parameters
fn(string, boolean) -> any— Handler(text, gpe) -> "sink"?wheretextis the committed string.optsSubOpts(optional) — Optional{ priority, context, once }.
Returns Handle — A composite handle.
Zin.input.onTextInput(function(text, gpe) ... end)
typed/builtin//modules/zinput/input/M/subscriberCount
M.subscriberCount() -> number
Test/introspection: number of active Zin.input.* subscriptions
(composite handles, not the underlying per-kind Events subscribers).
Returns number — Subscriber count.
local n = Zin.input.subscriberCount()
typed/builtin//modules/zinput/map/M/_reactivate
M._reactivate(record: any?) -> any
Re-apply the active map from a changed record — the edit-in-place
path an .inputMap asset takes when its source is written while it is
live. Who asked for the map is carried across: a write to its source
is the same map with new bindings, not a caller taking it up.
Parameters
recordany(optional) — The map record, freshly read from its source.
Returns any — The effective map that was applied.
Zin.map._reactivate(record)
typed/builtin//modules/zinput/map/M/_reset
M._reset()
Test-only: clear active-map state (the profile registry keeps whatever was applied).
Zin.map._reset()
typed/builtin//modules/zinput/map/M/activate
M.activate(record: any?) -> any
Activate a map record: materialize it and apply the flattened
result as the live binding set (through the profile registry, so
persistence and conflict surfaces keep working). Per-class axis
bindings beyond the primary register as <axis>@<class> sibling
axes; consumers that combine device values read both (e.g.
look + look@touch).
Parameters
recordany(optional) — The map (or profile) record, or an inputMap asset ref.
Returns any — The effective map that was activated.
Zin.map.activate(require("@builtin::inputMaps.default"))
typed/builtin//modules/zinput/map/M/activeName
M.activeName() -> string?
The active map's name, or nil.
Returns string? — The name string, or nil.
if Zin.map.activeName() == "default" then ... end
typed/builtin//modules/zinput/map/M/addTouchButton
M.addTouchButton(actionName: string, buttonOpts: Bindings.TouchButtonOpts, emitKey: string?) -> any
Add a touchButton binding to an action's touch class on the
active effective map, then re-flatten and re-activate so it takes
effect immediately. Creates the action entry if actionName
doesn't exist yet (the overlay's synthetic emit:<code> buttons).
The slot records the button in its attached set, keyed by the
binding, so a reader tells a caller's button from the map's own.
Parameters
actionNamestring— The action to attach the button to.buttonOptsBindings.TouchButtonOpts— The optionsZin.bindings.touchButtontakes - the button's zone, label, icon glyph, layout and appearance.emitKeystring(optional) — Optional key code — when set and the action has no kbm class yet, seeds it withB.key(emitKey)so a synthetic action is self-contained from the moment it's created.
Returns any — The added touchButton binding descriptor.
Zin.map.addTouchButton("emit:KeyF", { label = "Cast" }, "KeyF")
typed/builtin//modules/zinput/map/M/bake
M.bake(name: string) -> any
Write the active effective map as a new inputMap asset —
synthesis made explicit and editable. The snapshot includes every
live entry, overlay-registered emit:<code> actions included.
Returns the created ref.
Parameters
namestring— The new asset's name.
Returns any — The created asset ref.
Zin.map.bake("my_scheme")
typed/builtin//modules/zinput/map/M/bindingsFor
M.bindingsFor(eff: any?, name: string, class: string) -> any
The effective bindings for one action or axis and device class.
Parameters
effany(optional) — An effective map (from materialize/effective).namestring— The action or axis name.classstring— "kbm" | "gamepad" | "touch".
Returns any — The bindings array (actions) or binding (axes), or nil.
local touch = Zin.map.bindingsFor(eff, "jump", "touch")
typed/builtin//modules/zinput/map/M/effective
M.effective() -> any
The active map's effective form, or nil before any activation.
Returns any — The effective map, or nil.
local eff = Zin.map.effective()
typed/builtin//modules/zinput/map/M/ensureActive
M.ensureActive() -> any
Ensure a map is active: keeps the current one, else activates the builtin default map. The bootstrap the on-screen controls and controllers call.
Returns any — The active effective map.
Zin.map.ensureActive()
typed/builtin//modules/zinput/map/M/floorReleased
M.floorReleased() -> boolean
Whether a release made through Zin.map.releaseFloor stands, so
the overlay draws none of the floor's own controls. True from that
call until the context that made it ends, a caller activates a map,
or the floor is armed again.
Returns boolean — True while the floor's controls are stood down.
if Zin.map.floorReleased() then print("the floor draws nothing") end
typed/builtin//modules/zinput/map/M/isFallback
M.isFallback() -> boolean
Whether the active map is the fallback ensureActive armed on
its own, rather than one a caller activated. A reader that presents
the map to a player — the on-screen controls — asks this to tell a
scheme a world offered from the keyboard floor under a name that was
read.
Returns boolean — True while the active map is the arming fallback.
if not Zin.map.isFallback() then print(Zin.map.effective()) end
typed/builtin//modules/zinput/map/M/materialize
M.materialize(record: any?) -> any
Materialize a map record into its effective form: extends chain resolved (child wins per action/axis/class), then the touch class synthesized from the kbm shape wherever absent. Returns { name, description, actions = { [name] = { context, classes, synthesized = { touch = true? } } }, axes = { ... } }.
Parameters
recordany(optional) — The map (or profile) record.
Returns any — The effective map.
local eff = Zin.map.materialize(require("@builtin::inputMaps.default"))
typed/builtin//modules/zinput/map/M/releaseFloor
M.releaseFloor(mapRef: any?) -> boolean
Stand the floor's on-screen controls down through the map asset it
was armed from. The keyboard floor stays applied, so Zin.actions /
Zin.axes reads keep their bindings, and the overlay draws none of the
floor's own controls while the release stands (a button a caller
attached with Zin.touchControls.button still draws). The release
follows the context that made it, the way an activation does: a
component's ends with that component instance, and the floor's
controls draw again once no release stands. An .inputMap asset's
deactivate reaches this when the live scheme held no claim of it to
release.
Parameters
mapRefany(optional) — The inputMap asset ref being released.
Returns boolean — True when the active map is the floor armed from that asset and its controls were standing until this call.
Zin.map.releaseFloor(asset.resolve("@builtin::inputMaps.default"))
typed/builtin//modules/zinput/map/M/removeTouchButton
M.removeTouchButton(actionName: string, binding: any?) -> boolean
Remove a touchButton binding previously added via
addTouchButton, then re-flatten and re-activate. Drops the
action entry entirely once every class is empty — cleanup for
synthetic emit:<code> actions the overlay created.
Parameters
actionNamestring— The action the binding was added to.bindingany(optional) — The binding table returned byaddTouchButton.
Returns boolean — Whether a binding was actually removed.
Zin.map.removeTouchButton("emit:KeyF", binding)
typed/builtin//modules/zinput/observe/M/_publish
M._publish()
Internal: publish this layer's half of the engine's input
observation for the current frame. Called once per frame from
Zin.tick while Zin.observe.wanted() holds.
Zin.observe._publish()
typed/builtin//modules/zinput/observe/M/arm
M.arm(on: boolean?)
Hold the engine's input observation open, so /runtime/input and
input.observe() carry this layer's half of the document every frame.
A read of either arms it for a window of frames on its own; this is for
a test or a tool that wants it building continuously.
Parameters
onboolean(optional) — Arm (the default) or disarm.
Zin.observe.arm(true)
typed/builtin//modules/zinput/observe/M/armedFrames
M.armedFrames() -> number
How many more frames the arming window has left. A read of
Zin.observe.frame(), input.observe() or /runtime/input sets it
back to the full window; every frame that passes takes one off it, and
0 means nothing is observing.
Returns number — Frames left in the arming window.
print(Zin.observe.armedFrames())
typed/builtin//modules/zinput/observe/M/control
M.control(name: string) -> any
Everything known about one named control in a single call: which maps contribute it, its bindings per device class, its subscriber count, the value it reported on the most recent tick, whether that reached a subscriber, and — when it is live and silent — why.
Parameters
namestring— The control name.
Returns any — { name, carriedBy, live, entries, lastTick, why }. lastTick carries its own window: the tick's own record once the tick is keeping one, and the same answers resolved live before then.
local c = Zin.observe.control("move")
typed/builtin//modules/zinput/observe/M/frame
M.frame() -> any
The mapping layer's account of the most recent tick: every live map, every live control with what it did and why, and what the tick cost.
The window is ONE tick — the most recent one. Reading consumes nothing, so any number of observers in the same frame all get the same answers.
Returns any — { frameId, window, maps, controls, cost }.
local f = Zin.observe.frame()
typed/builtin//modules/zinput/observe/M/means
M.means(reason: string) -> string?
What one reason name means, or nil for a name outside the set.
Parameters
reasonstring— The reason name.
Returns string? — The sentence describing it, or nil.
print(Zin.observe.means("gateRefused"))
typed/builtin//modules/zinput/observe/M/reasons
M.reasons() -> { any }
The closed set of reasons a control resolves to, each with what it means and what to do about it. The resolver answers with exactly one of these names.
Returns { any } — Array of { name, means }, in the order the resolver considers them.
for _, r in ipairs(Zin.observe.reasons()) do print(r.name, r.means) end
typed/builtin//modules/zinput/observe/M/wanted
M.wanted() -> boolean
Whether the engine wants this layer's half of the input observation
built this frame — true while something has read input.observe() or
/runtime/input recently enough.
Returns boolean — Whether a report is wanted.
if Zin.observe.wanted() then ... end
typed/builtin//modules/zinput/observe/M/whySilent
M.whySilent(name: string) -> any
Why a named control is not reaching the game right now, as one
reason from the closed set Zin.observe.reasons() lists, with the
particulars behind it.
Resolves against the devices as they are at the moment of the call, so
it answers for a control the tick has never reached and for one that
does not exist. The layer field says which of the three naming layers
answered — the live maps' controls, the action registry, or the axis
registry — since a name can be live in one and unknown in the others.
Parameters
namestring— The control name.
Returns any — { name, reason, means, layer, carriedBy, ... } — the extra fields depend on the reason: suppressedBy / suppressedByHolders, needsContext / currentContext, pointerOwner / uiHolders, keyboardOwner / uiKeys, gateError, declaredClasses / presentClasses, deadzone, subscribers, value, rawReading. On groupSuppressed, suppressedBy names the map standing this control down and suppressedByHolders names the activations holding that map up — each as Zin.scheme.live() reports it, with the chunk:line it was opened at. One of those holders is where the change that gives this control back belongs.
local why = Zin.observe.whySilent("look")
typed/builtin//modules/zinput/pointer/M/holders
M.holders() -> { Holder }
Who is asking for the pointer lock, in the order they first asked:
{ holder, reason } each. Empty when nothing asks. An ask written
around Zin.pointer (a simulated device event) is the engine's alone,
so requested() can stand with this list empty, and status() says so.
Returns { Holder } — An array of { holder: string, reason: string? }.
for _, h in Zin.pointer.holders() do print(h.holder, h.reason) end
typed/builtin//modules/zinput/pointer/M/holds
M.holds(holder: string) -> boolean
Whether holder is holding the pointer-lock ask.
Parameters
holderstring— The holder name.
Returns boolean — true while that holder asks.
if Zin.pointer.holds("myGame.aim") then ... end
typed/builtin//modules/zinput/pointer/M/lock
M.lock(holder: string?, reason: string?)
Ask for pointer lock (cursor grab + hide) under holder. The
engine's request stands while any holder does. Asking again under a
name already holding states the request again and replaces its reason.
The ask records intent; the cursor is captured once the surface is
active — native: window focused + clicked; WASM: on the next user
gesture (browser policy).
Parameters
holderstring(optional) — Who is asking, asZin.pointer.holders()names it. Optional; an ask that names none is held under"Zin.pointer.lock".reasonstring(optional) — Why it asks, in a sentence. Optional.
Zin.pointer.lock("myGame.aim", "the aiming camera steers with the mouse")
typed/builtin//modules/zinput/pointer/M/locked
M.locked() -> boolean
Convenience: query the current pointer-lock state. Identical to
Zin.state.pointerLocked().
Returns boolean — true when the pointer is currently locked.
if Zin.pointer.locked() then ... end
typed/builtin//modules/zinput/pointer/M/requested
M.requested() -> boolean
Whether the engine's pointer-lock request stands: the intent the platform layer and the browser bridge read. Reads the input snapshot, so an ask taken this frame reads here from the next one.
Returns boolean — true while the request stands.
if Zin.pointer.requested() and not Zin.pointer.locked() then ... end
typed/builtin//modules/zinput/pointer/M/status
M.status() -> Status
The pointer lock in one read: who asks, whether the engine's
request stands, whether it is granted, and what decides it.
suppressed is true while the cursor belongs to the person (gameplay
paused, a shown screen holding the pointer, or the editor sharing the
window with no scene picture on it), which holds a standing request
ungranted; uiHolders names the shown screens holding the pointer (an
open modal, a widget stating holdsPointer = true); armed is
whether a click on the focused surface has armed the capture. why
says which of them answers. It reads the input snapshot and leaves the
input observation as it stands.
Returns Status — { requested, locked, suppressed, armed, holders, uiHolders, why }.
local s = Zin.pointer.status(); print(s.why)
typed/builtin//modules/zinput/pointer/M/unlock
M.unlock(holder: string?)
Give back pointer lock. Naming a holder withdraws that holder's
ask, and the cursor is released once no holder is left. Naming none
hands the cursor back to the person: every holder's ask goes and the
lock is released.
Parameters
holderstring(optional) — The holder whose ask goes. Optional; omitted, every ask goes.
Zin.pointer.unlock("myGame.aim")
typed/builtin//modules/zinput/profile/M/_reset
M._reset()
Test-only: clear all in-memory state. Suite isolation; not part of the public contract.
Zin.profile._reset()
typed/builtin//modules/zinput/profile/M/_resetApplied
M._resetApplied()
Test-only: clear the applied/active markers so suites can simulate a cold session without touching the registered profiles. Not part of the public contract.
Zin.profile._resetApplied()
typed/builtin//modules/zinput/profile/M/_setMapEnsureFn
M._setMapEnsureFn(fn: (string) -> boolean)
Internal: wire the map-delegation hook. Called once at module-
load time from zinput/init.luau.
Parameters
fn(string) -> boolean— The hook invoked with the resolved scheme name; returnstruewhen it handled activation (routing through the map).
Profile._setMapEnsureFn(mapEnsureDefault)
typed/builtin//modules/zinput/profile/M/activate
M.activate(name: string, opts: ActivateOpts?) -> (boolean, string?)
Activate a registered profile: clear current actions/axes/chords,
then apply the profile's definitions. Sets the active name and
notifies subscribers. Activating the already-active profile is a
no-op unless opts.reactivate = true.
Parameters
namestring— Profile name to activate.optsActivateOpts(optional) — Optional{ reactivate }— forces re-apply when already active.
Returns (boolean, string?) — (true) on success or (false, err) on failure.
Zin.profile.activate("wasd-arrows")
Zin.profile.activate("wasd-arrows", { reactivate = true })
typed/builtin//modules/zinput/profile/M/appliedName
M.appliedName() -> string?
The name of the profile whose sections are currently applied to the actions/axes/chords registries, or nil when nothing has been applied this session.
Returns string? — The applied profile name, or nil.
local n = Zin.profile.appliedName()
typed/builtin//modules/zinput/profile/M/current
M.current() -> string?
Active profile name for this session, or nil if none has been
activated yet.
Returns string? — The active profile name, or nil.
local n = Zin.profile.current()
typed/builtin//modules/zinput/profile/M/delete
M.delete(name: string) -> (boolean, string?)
Remove a user profile's JSON file. Refuses to delete built-ins.
The in-memory registry entry is also dropped. If the deleted profile
was active, current() keeps the name until a different profile is
activated — but the registry no longer has the descriptor.
Parameters
namestring— Non-empty profile name.
Returns (boolean, string?) — (true) on success or (false, err).
Zin.profile.delete("my-bindings")
typed/builtin//modules/zinput/profile/M/ensureActive
M.ensureActive(fallback: string?) -> (boolean, string?)
Bootstrap helper for controllers. If no profile is active,
activates the session-active profile or fallback if there is none.
Idempotent — if a profile is already active this is a no-op. A
camera/locomotion controller calls this on awake() so a scene with
no explicit Zin.profile.activate still has working bindings.
When the resolved scheme is the builtin "default", activation
routes through Zin.map so every device class (kbm, gamepad,
touch) comes along, not just kbm.
Parameters
fallbackstring(optional) — Optional fallback name (defaults to"default").
Returns (boolean, string?) — (true) on success or (false, err).
Zin.profile.ensureActive("wasd-arrows")
typed/builtin//modules/zinput/profile/M/export
M.export(name: string, vfsPath: string) -> (boolean, string?)
Write a named profile's serializable JSON to an arbitrary VFS path.
Same shape as save() — round-trips through import() losslessly.
Built-in profiles can be exported; their function fields (gate,
curve closure form) are stripped from the exported JSON.
Parameters
namestring— Profile name to export.vfsPathstring— Destination VFS path.
Returns (boolean, string?) — (true) on success or (false, err).
Zin.profile.export("wasd-arrows", "/source/profiles/backup.json")
typed/builtin//modules/zinput/profile/M/get
M.get(name: string?) -> any?
Active profile descriptor (no arg) or the named profile (with arg).
Returns nil if missing.
Parameters
namestring(optional) — Optional profile name; omit to query the active profile.
Returns any? — The profile descriptor, or nil.
local p = Zin.profile.get()
local p = Zin.profile.get("wasd-arrows")
typed/builtin//modules/zinput/profile/M/import
M.import(vfsPath: string, opts: ImportOpts?) -> (boolean, string)
Read a profile JSON from a VFS path and register() it. Does
NOT activate it — pass opts.activate = true (or call
activate(name) separately) to make it current.
Parameters
vfsPathstring— Source VFS path.optsImportOpts(optional) — Optional{ overrideName, activate }.
Returns (boolean, string) — (true, registeredName) on success or (false, err).
Zin.profile.import("/source/profiles/backup.json")
Zin.profile.import(path, { overrideName = "v2", activate = true })
typed/builtin//modules/zinput/profile/M/list
M.list() -> { string }
Built-in and user profile names, sorted and deduplicated.
Returns { string } — Sorted array of profile names.
local names = Zin.profile.list()
typed/builtin//modules/zinput/profile/M/load
M.load(name: string) -> (boolean, any?)
Load and register a profile. Tries @builtin::profiles.<name>
first (Luau module), then falls back to /zero/profiles/<name>.json.
Parameters
namestring— Profile name to load.
Returns (boolean, any?) — (true, profile) on success, (false, err) on failure.
local ok, p = Zin.profile.load("wasd-arrows")
typed/builtin//modules/zinput/profile/M/off
M.off(handle: number)
Drop a subscription registered via onChange. No-op if the
handle is unknown.
Parameters
handlenumber— Subscription handle returned byonChange.
Zin.profile.off(h)
typed/builtin//modules/zinput/profile/M/onChange
M.onChange(cb: ChangeCallback) -> number
Subscribe to active-profile changes. Callback fires with
(profileName, profileDescriptor) on activate and on register
of the currently active profile.
Parameters
cbChangeCallback— Callback(name: string, profile: any) -> ().
Returns number — A handle for off.
local h = Zin.profile.onChange(function(name, p) ... end)
typed/builtin//modules/zinput/profile/M/register
M.register(name: string, profile: any?) -> (boolean, string?)
Register a profile table. Validates the shape; replaces any prior registration under the same name. If the registered name is currently active, subscribers are notified (so editor UIs refresh).
Parameters
namestring— Non-empty profile name.profileany(optional) — Profile descriptor.
Returns (boolean, string?) — (ok, err) — (true) on success, (false, err) on validation failure.
Zin.profile.register("wasd-arrows", profile)
typed/builtin//modules/zinput/profile/M/save
M.save(name: string, opts: SaveOpts?) -> (boolean, string?)
Capture the current Zin.actions / Zin.axes / Zin.chords state to
a JSON file under /zero/profiles/<name>.json. Refuses to overwrite
a built-in profile name or an existing user profile (unless
opts.overwrite = true). Functions (axis gate, function-valued
curve) are dropped — only data-typed fields persist.
Parameters
namestring— Non-empty profile name.optsSaveOpts(optional) — Optional{ description, overwrite }.
Returns (boolean, string?) — (true) on success or (false, err).
Zin.profile.save("my-bindings", { description = "..." })
typed/builtin//modules/zinput/rebind/M/_advanceTime
M._advanceTime(dt: number)
Internal: per-frame timeout sweep. Called by Zin.tick after the event pump so timed-out sessions retire on the same frame their budget runs out, before the next observed event.
Parameters
dtnumber— Frame delta in seconds.
Zin.rebind._advanceTime(1 / 60)
typed/builtin//modules/zinput/rebind/M/_settled
M._settled() -> boolean
Internal: whether no rebind capture session is live. The tick's quiescence gate reads it.
Returns boolean — true when nothing is listening for a binding.
if Zin.rebind._settled() then ... end
typed/builtin//modules/zinput/rebind/M/begin
M.begin(opts: BeginOpts?) -> Session
Start a new capture session. Returns the session table. The
session auto-subscribes to Zin.events.on so once Zin.tick runs
the first matching event commits the capture without the caller
having to pump consume manually.
Parameters
optsBeginOpts(optional) — Capture options —target("action"(default) /"axis"),name(required),slot,mode("replace"(default) /"append"),timeoutSec,filter,applyOnCommit,onCommit.
Returns Session — The session table — read status and result() after a tick or call cancel() / apply() / conflicts().
local s = Zin.rebind.begin({ target = "action", name = "jump" })
typed/builtin//modules/zinput/rebind/M/cancelAll
M.cancelAll()
Cancel every live session. Test-only / shutdown.
Zin.rebind.cancelAll()
typed/builtin//modules/zinput/rebind/M/liveCount
M.liveCount() -> number
Live sessions count; primarily for test introspection.
Returns number — Number of capturing sessions still active.
local n = Zin.rebind.liveCount()
typed/builtin//modules/zinput/scheme/M/_advance
M._advance(dt: number)
One tick of binding dispatch: evaluate every live binding and fire
what changed. Wired into Zin.tick.
input fires every frame a binding is active, and once more on the
frame it goes inactive carrying the neutral value and active = false
— so one handler both starts and stops the motion it drives.
A button already held when its map comes up reads held from the first
tick, so input reports it active. Its press came before the control
did, so neither the press nor the release of that hold fires
pressed or released; the next press is the control's own. A
control whose group was suppressed, or whose context was off top,
comes back the same way: a hold begun while it stood down, and a
press made in a frame it stood down in, are not its own. A hold it
answered before it stood down is still its own when it comes back,
and the release that ends it fires released. A menu map
that lets go of a suppression from its own handler of a press keeps
that press to itself, and the control it stood down answers from the
next press.
Evaluation is per tick, so smoothing keeps converging when a host runs
several ticks inside one engine frame, and changed reports each step
of it. input, pressed and released are per engine frame: one
active call and one of each edge, whatever the tick cadence above it.
Parameters
dtnumber— Seconds since the previous tick.
Zin.scheme._advance(1 / 60)
typed/builtin//modules/zinput/scheme/M/_childBindings
M._childBindings(mapRef: any?) -> { any }
Internal: the <name>.inputBinding/ children of a map asset, as
resolved refs in name order.
Parameters
mapRefany(optional) — The inputMap asset ref.
Returns { any } — Array of inputBinding refs.
local kids = Zin.scheme._childBindings(mapRef)
typed/builtin//modules/zinput/scheme/M/_gateAllows
M._gateAllows(record: any?) -> (boolean, string?, string?)
Internal: run a control's own gate. Returns whether it allows the
control to read, and when it does not, which of gateRefused /
gateErrored happened and the error text if one was raised.
Parameters
recordany(optional) — The binding record.
Returns (boolean, string?, string?) — (allowed, reason?, error?).
local ok, why = Zin.scheme._gateAllows(record)
typed/builtin//modules/zinput/scheme/M/_readClasses
M._readClasses(record: any?, dt: number, surface: string?) -> any
Internal: read every device class a control's record carries, in the control's own unit, WITHOUT its gate and without its deadzone / curve / invert shaping. What the devices produced before the control decided what to do with it.
Parameters
recordany(optional) — The binding record.dtnumber— Seconds since the previous tick.surfacestring(optional) — Whose keys to read:"scene"(the default) or"editor".
Returns any — The unshaped reading, in the record's kind.
local raw = Zin.scheme._readClasses(record, 1 / 60)
typed/builtin//modules/zinput/scheme/M/_reset
M._reset()
Test-only: drop every live map without firing anything.
Zin.scheme._reset()
typed/builtin//modules/zinput/scheme/M/_setEnsureLiveFn
M._setEnsureLiveFn(fn: () -> ())
Internal: wire the liveness hook. Called once at module-load
time from zinput/init.luau.
Parameters
fn() -> ()— The hook invoked on every activation below.
M._setEnsureLiveFn(ensureInputLive)
typed/builtin//modules/zinput/scheme/M/_settled
M._settled() -> boolean
Internal: whether every live control sits at rest -- nothing active, nothing waiting for its holder to release, every smoothed reading at neutral. The tick's quiescence gate reads it: the scan runs again after an evaluation or a change to the live set, and every call between those answers from the last one.
Returns boolean — true when no control could change without new input.
if Zin.scheme._settled() then ... end
typed/builtin//modules/zinput/scheme/M/activate
M.activate(mapRef: any?, label: string?) -> { [string]: Handle }
Activate an inputMap asset: load every <name>.inputBinding/ child
it contains, validate them, add them to the live binding set, and
return the handles a controller subscribes through — one per binding,
keyed by the binding's name.
Every fault across every child is reported in one error, so a map with three broken bindings names all three rather than one per attempt.
Activating a map already live adds a holder rather than registering
the map twice, so two components sharing one map read one set of
controls. Each holder gets its OWN handles: every subscription made
through them belongs to that activation, and passing them back to
deactivate releases exactly those.
Every activation reads the map's children again, so a binding added, edited or removed since the map came up reaches the running set here — and reaches the holders already standing on it, whose handles and subscriptions carry on across the edit.
label names this activation in Zin.scheme.live(), beside where it
was opened. A probe that takes a map to look at it says so, and the
agent whose controls the map suppresses can read who is holding it.
Parameters
mapRefany(optional) — The inputMap asset ref.labelstring(optional) — What to call this activation. Optional.
Returns { [string]: Handle } — A table of handles keyed by binding name — this holder's claim.
local map = public.inputMap:activate(); map.jump:onPressed(fn)
typed/builtin//modules/zinput/scheme/M/advanceCost
M.advanceCost() -> any
What the most recent tick of binding dispatch cost, and how much it
covered: { frameId, maps, controls, ms }. ms is ONE tick's own
milliseconds — the same number profiler.stats("*zin.scheme.advance*")
reports as script.zin.scheme.advance, where it also carries the average
and the peak across every tick since the engine started.
Returns any — { frameId, maps, controls, ms }.
local cost = Zin.scheme.advanceCost()
typed/builtin//modules/zinput/scheme/M/advances
M.advances() -> number
How many evaluations of the live controls have run since the module loaded. A caller that drove a control waits for it to advance to know an evaluation has read the driven value.
Returns number — The evaluation count.
local before = Zin.scheme.advances()
typed/builtin//modules/zinput/scheme/M/bindings
M.bindings() -> { any }
Every live binding, in activation order, as
{ map, group, library, name, label, kind, context, suppressedBy, subscribers }.
name is the control's identity; label the words a player reads for
it, in their language now; library is true when the control's map
comes from the engine's built-in library rather than from the world.
The touch overlay builds its buttons from this, so what is on screen is
exactly what some awake component asked for and nothing is standing
down.
Returns { any } — Array of binding descriptors.
for _, b in ipairs(Zin.scheme.bindings()) do print(b.label) end
typed/builtin//modules/zinput/scheme/M/classBindings
M.classBindings(record: any?, class: string) -> { any }
Every binding a control declares for one device class, as the tick reads them.
Parameters
recordany(optional) — The binding record.classstring— One ofkbm/gamepad/touch.
Returns { any } — Array of binding descriptors.
local kbm = Zin.scheme.classBindings(record, "kbm")
typed/builtin//modules/zinput/scheme/M/deactivate
M.deactivate(mapRef: any?, claim: any?) -> boolean
Release one holder's claim on a map, disconnecting every subscription that claim made. The other holders keep theirs, and the map stays live while any of them remains; the last one out also takes the map's controls out of the live set.
A claim is the handle table activate returned. Hand it back and that
activation is what goes. Name none and the caller's own most recent
claim goes — a component releases what IT activated, whatever else has
taken the map since. A component holding none of them releases nothing;
an execute holding none of them releases the map's most recent claim.
An asset ref is shared by every holder of the same map, so the handles
are what say which of them is releasing.
Parameters
mapRefany(optional) — The inputMap asset ref.claimany(optional) — The handles this holder'sactivatereturned. Optional.
Returns boolean — True when a claim was released.
public.inputMap:deactivate(controls)
typed/builtin//modules/zinput/scheme/M/declaredClasses
M.declaredClasses(record: any?) -> { string }
Which device classes a control declares bindings for, in the order the tick consults them. A control with no binding for the class a player is driving reads nothing from that class no matter what they do.
Parameters
recordany(optional) — The binding record.
Returns { string } — Array of class names from kbm / gamepad / touch.
local classes = Zin.scheme.declaredClasses(record)
typed/builtin//modules/zinput/scheme/M/drive
M.drive(name: string, value: any?)
Drive a live control directly with the value the game should read —
the gameplay intent a game is authored in, rather than the key a map
happens to bind. true holds a button (false lets it go), a number
drives a 1-D axis, { x, y } a 2-D one. The value joins the control's
device classes like another device: shaping and smoothing apply, press
and release edges fire, and a context or suppression that stands the
control down stands it down too. It reaches every live map declaring a
control of that name, and stays until Zin.scheme.undrive lets it go.
It touches no device, so a person at the window — a focused panel, the
pointer — neither reaches it nor is reached by it. Raises for a name no
live map declares, listing the live controls, and for a value the
control's kind cannot take.
Parameters
namestring— The control's name, asZin.scheme.bindings()lists it.valueany(optional) —true/falsefor a button, a number for a 1-D axis,{ x, y }for a 2-D axis.
Zin.scheme.drive("move", { 0, 1 }) -- walk forward
Zin.scheme.drive("jump", true); Zin.scheme.undrive("jump")
typed/builtin//modules/zinput/scheme/M/drivenControls
M.drivenControls() -> { [string]: any }
The controls being driven now, each with its driven value.
Returns { [string]: any } — { [name] = value }.
for name, v in Zin.scheme.drivenControls() do print(name, v) end
typed/builtin//modules/zinput/scheme/M/drivingClass
M.drivingClass(record: any?, surface: string?) -> string?
Which device class is currently satisfying a binding, or nil when
nothing is. Used to tag what fired reports.
Parameters
recordany(optional) — The binding record.surfacestring(optional) — Whose keys to read:"scene"(the default) or"editor".
Returns string? — The class name, or nil.
local class = Zin.scheme.drivingClass(record)
typed/builtin//modules/zinput/scheme/M/entriesFor
M.entriesFor(name: string) -> { any }
Every live map that declares a named control, with the map's own record and the control's dispatch state. The lookup behind per-control questions: a name can be declared by more than one live map, and this answers with all of them in activation order.
Parameters
namestring— The control name.
Returns { any } — Array of { map, group, guid, record, state, suppressedBy }.
local entries = Zin.scheme.entriesFor("look")
typed/builtin//modules/zinput/scheme/M/fired
M.fired(peek: boolean?) -> { any }
Every control that fired since this last cleared, with how many
engine frames it was active for, which device classes drove it, and
what received it. Reading CLEARS the record unless peek is true, so
two calls around an action answer "did that input reach the game"
without a previous test's results bleeding in.
One row per LIVE MAP that fired the control, so a name two maps both declare reports each of them under its own map with its own count.
Parameters
peekboolean(optional) — Read without clearing.
Returns { any } — Array of { name, map, guid, count, classes, subscribers, delivered }, sorted by name and then by map. map is the map's name and guid is that map's own guid, which is what tells two live maps sharing a name apart. count is the number of engine frames the control was active, so a button held across two frames reads 2 for one press. The pressed / released subscriptions are what count edges. subscribers is how many the control had on its most recent firing frame and delivered says one of those frames reached a subscriber, so a press that landed reads apart from one that reached nothing.
local fired = Zin.scheme.fired()
typed/builtin//modules/zinput/scheme/M/generation
M.generation() -> number
A counter that changes whenever the live set of maps changes. Cache a view of the live bindings against it rather than rebuilding one every frame.
Returns number — The current generation.
if gen ~= Zin.scheme.generation() then print("the input scheme changed") end
typed/builtin//modules/zinput/scheme/M/has
M.has(name: string) -> boolean
Whether a named control is live in any activated map.
Parameters
namestring— The binding name.
Returns boolean — True when some live map declares it.
if Zin.scheme.has("jump") then ... end
typed/builtin//modules/zinput/scheme/M/lastFrame
M.lastFrame() -> { any }
What every live control did on the most recent tick: its value, whether it was active, whether that reached a subscriber, how many subscribers it has, and the tick's own answers about context, suppression and its gate.
Rebuilt whole each tick and read without consuming, so any number of observers in the same frame all see the same answers. The window is ONE tick — the most recent one — rather than a sum since anything last read.
Returns { any } — Array of { name, map, group, kind, label, context, value, active, delivered, subscribers, suppressedBy, inContext, heldOnArrival, gateReason, gateError }, in evaluation order.
for _, c in ipairs(Zin.scheme.lastFrame()) do print(c.name, c.active) end
typed/builtin//modules/zinput/scheme/M/legend
M.legend(name: string, class: string?) -> string?
What to press for a live control on the device the person is using,
in their language: every binding the live maps declaring name hold for
that device class, each as Zin.bindings.format names it, joined by
" / ". The class is Zin.surface.current() unless one is named, so in a
headset it names the hand controllers (X / A), at a keyboard the keys
(F4). A hint built from it follows the device and the bindings as they
stand. A map standing down (suppressedBy) is left out.
Parameters
namestring— The control's name.classstring(optional) —"kbm"/"gamepad"/"touch", or nil for the class in use.
Returns string? — The legend, or nil when no live map binds the control for that class.
local talk = Zin.scheme.legend("pushToTalk") -- "F4", or "X / A" in a headset
typed/builtin//modules/zinput/scheme/M/live
M.live() -> { any }
Every live map, in activation order:
{ guid, name, group, suppresses, suppressedBy, pointerLock, surface, library, holders, heldBy, bindings } where bindings names the controls it
contributes, holders counts the activations still standing on it,
suppressedBy names the map standing this one down, if any,
pointerLock says whether it takes the cursor while the world runs, and
surface is whose keys its controls read: "scene", the keys pressed
while the scene was the active input context, or "editor".
library is true for a map from the engine's built-in library and false
for one the world brought: its own, or one from a package it installed.
What a debug surface lists, and what tells an author why two sticks
are on screen — or why the controls they activated answer to nothing.
heldBy is one record per activation still standing:
{ kind, entity, instance, source, label, holder, subscriptions }.
kind is "component" for an activation a component script made and
"execute" for one made from a bare call, source is the
chunk:line it was opened at, and holder says the same thing in a
sentence. A map that suppresses a group is somebody's activation, and
this is whose — the reading an agent whose controls went silent takes
to find the activation standing them down.
Returns { any } — Array of live-map records.
for _, m in ipairs(Zin.scheme.live()) do print(m.name) end
typed/builtin//modules/zinput/scheme/M/liveCount
M.liveCount() -> number
How many maps are live right now.
Returns number — The count of activated maps.
if Zin.scheme.liveCount() == 0 then ... end
typed/builtin//modules/zinput/scheme/M/markBaseline
M.markBaseline() -> number
Record the claims standing on every live map right now, as the mark
Zin.scheme.resetToBaseline takes back to. A caller running work in an
engine it shares, such as a sweep of test suites, marks before the work and
resets after it.
Returns number — The mark.
local mark = Zin.scheme.markBaseline()
typed/builtin//modules/zinput/scheme/M/neutralFor
M.neutralFor(kind: string) -> any
The neutral value for a control kind: false for a button, 0 for
an axis1, { x = 0, y = 0 } for an axis2. What a control reports
when it is not delivering.
Parameters
kindstring— The control kind.
Returns any — The kind's neutral value.
local rest = Zin.scheme.neutralFor("axis2")
typed/builtin//modules/zinput/scheme/M/recording
M.recording() -> boolean
Whether the tick is keeping a per-control record of what it did.
Zin.tick turns it on while something is observing the input layer and
off again when nothing is.
Returns boolean — Whether the record is being built.
if Zin.scheme.recording() then ... end
typed/builtin//modules/zinput/scheme/M/resetToBaseline
M.resetToBaseline(mark: number) -> number
Release every execute claim opened since mark. A component's
claim answers to the component: it goes when the component releases it
or when that component instance ends (removed, hot-reloaded, or its
entity despawned), whichever comes first.
Parameters
marknumber— WhatZin.scheme.markBaselinereturned.
Returns number — How many claims were released.
Zin.scheme.resetToBaseline(mark)
typed/builtin//modules/zinput/scheme/M/setRecording
M.setRecording(on: boolean?)
Keep — or stop keeping — a per-control record of what each tick did.
A tick that is not recording still dispatches and still reports its
cost; it only stops writing down each control's outcome, which
Zin.observe can resolve again from live state.
Parameters
onboolean(optional) — Record (the default) or stop recording.
Zin.scheme.setRecording(true)
typed/builtin//modules/zinput/scheme/M/subscriberCount
M.subscriberCount(name: string) -> number
How many subscribers a named control currently holds, summed over every live map that declares it.
A control can be live, valid and firing with nobody listening. Drawing a button for one offers a player something that cannot do anything — which is the shape of every on-screen control that has ever been reported as doing nothing.
Parameters
namestring— The binding name.
Returns number — The number of live subscribers.
if Zin.scheme.subscriberCount("jump") == 0 then ... end
typed/builtin//modules/zinput/scheme/M/subscriberEpoch
M.subscriberEpoch() -> number
Total subscribers across every live control.
Which controls are HEARD changes without the live set changing at all —
a component activates a map and subscribes a moment later, or drops its
last listener while staying awake. A consumer that caches a view of the
live set by generation alone never sees either, so this is the second
half of that cache key.
Returns number — The summed subscriber count.
if gen ~= Zin.scheme.generation() or subs ~= Zin.scheme.subscriberEpoch() then print("the input scheme changed") end
typed/builtin//modules/zinput/scheme/M/suppressed
M.suppressed() -> { [string]: string }
Which groups are currently standing down, and the map that put each
one down: { [group] = mapName }.
The answer to "the button is gone and the control is live" — a control in a suppressed group reads nothing and draws nothing until whatever suppressed it releases.
Returns { [string]: string } — A table of group name → the name of the map suppressing it.
local down = Zin.scheme.suppressed()
typed/builtin//modules/zinput/scheme/M/undrive
M.undrive(name: string?)
Let go of a driven control — or of every driven control when no name is given. The control reads its devices alone again; a driven button fires its release edge on the next evaluation.
Parameters
namestring(optional) — The control to let go; nil for all of them.
Zin.scheme.undrive("move")
Zin.scheme.undrive()
typed/builtin//modules/zinput/scheme/M/valueIsActive
M.valueIsActive(kind: string, value: any?) -> boolean
Whether a value of the given kind is anything other than that kind's neutral — a held button, an axis off centre.
Parameters
kindstring— The control kind.valueany(optional) — The value to test.
Returns boolean — Whether the value counts as active.
if Zin.scheme.valueIsActive("axis1", v) then ... end
typed/builtin//modules/zinput/state/M/_idle
M._idle() -> boolean
Internal: whether the devices are at rest this frame — nothing held, nothing moving, locked pointer or not. The tick's quiescence gate reads it: a held key drives controls without producing an event, so a frame with live raw input is evaluated whatever the event count says.
Returns boolean — true when no device carries live input this frame.
if Zin.state._idle() then ... end
typed/builtin//modules/zinput/state/M/_observeEvent
M._observeEvent(ev: any?)
Internal: per-event observer called by the Zin.tick coordinator.
Updates held-time state for keys and mouse buttons. Not part of the
public contract — exposed on M so the tick coordinator can wire it.
Parameters
evany(optional) — The raw input event record (kind, code, button, repeat, …).
Zin.state._observeEvent(ev)
typed/builtin//modules/zinput/state/M/_pointerLockState
M._pointerLockState() -> { requested: boolean, locked: boolean, suppressed: boolean, armed: boolean, uiHolders: { string } }
Internal: the pointer lock as the snapshot carries it, for
Zin.pointer.status(): { requested, locked, suppressed, armed, uiHolders }, uiHolders naming the shown screens holding the pointer.
Returns { requested: boolean, locked: boolean, suppressed: boolean, armed: boolean, uiHolders: { string } } — The four booleans and the screen names.
local p = Zin.state._pointerLockState()
typed/builtin//modules/zinput/state/M/_reset
M._reset()
Test-only: clear all held-time / repeat state. Public so test suites can isolate cases.
Zin.state._reset()
typed/builtin//modules/zinput/state/M/_setEnsureLiveFn
M._setEnsureLiveFn(fn: () -> ())
Internal: wire the liveness hook. Called once at module-load
time from zinput/init.luau.
Parameters
fn() -> ()— The hook invoked on every read below.
M._setEnsureLiveFn(ensureInputLive)
typed/builtin//modules/zinput/state/M/gamepadCapable
M.gamepadCapable() -> boolean
Has this session ever seen a gamepad device? Latched by a device pad's first connection, so unplugging a pad does not flip a scheme's prompts back to keyboard glyphs on a cable knock. A simulated pad reads as one only while it is connected.
Returns boolean — True once a device pad has connected, or while a simulated pad is connected.
if Zin.state.gamepadCapable() then ... end
typed/builtin//modules/zinput/state/M/gamepads
M.gamepads() -> { any }
Every connected gamepad this frame, in slot order. Each entry is
{ slot, name, buttons, buttons_pressed, buttons_released, axes, simulated, device, device_axes, device_buttons, device_held, device_pressed, device_released, haptics, rumble }, the button fields
are arrays of canonical names, axes a map of canonical axis name to
number; device describes every axis and button the device reports in
its own order (see Zin.gamepad.device), device_axes /
device_buttons hold their readings by index + 1 and the device_*
button lists hold 0-based indices. Empty when nothing is connected.
Returns { any } — Array of pad records.
for _, pad in ipairs(Zin.state.gamepads()) do print(pad.name) end
typed/builtin//modules/zinput/state/M/get
M.get() -> Snapshot
Get the full snapshot table for this frame. Empty table if
__zero_input.snapshot is missing or returns non-table.
Returns Snapshot — The snapshot table.
local snap = Zin.state.get()
typed/builtin//modules/zinput/state/M/getRepeatDefaults
M.getRepeatDefaults() -> RepeatDefaults
Read the current synthetic-repeat defaults. Returned table is a copy.
Returns RepeatDefaults — A fresh { delay, period } table.
local d = Zin.state.getRepeatDefaults()
typed/builtin//modules/zinput/state/M/keyDown
M.keyDown(key: string, surface: string?) -> boolean
Is key currently held? True on EVERY frame the key is down —
the level, not the edge. Use it for continuous input: thrust while
W is held, hold-to-charge, camera pan. For an action that should
happen once per press (fire, jump, pause, undo) bind it and read
Zin.actions.pressed(name), which fires on the press edge only.
A key belongs to the surface it was pressed on: the scene holds the
keys pressed while it was the active input context, so a key pressed
after a click on an editor panel is not the scene's. Editor code
passes "editor" to read every key no focused widget took.
Parameters
keystring— Web-style key code (e.g."KeyW","Space").surfacestring(optional) — Whose keys to read:"scene"(the default) or"editor".
Returns boolean — true when the key is held this frame.
if Zin.state.keyDown("KeyW") then ... end -- thrust while held
typed/builtin//modules/zinput/state/M/keyDownReal
M.keyDownReal(key: string) -> boolean
Is key held by a real press — held, and NOT (also) held by the
input-emulation floor? The floor merges emulated holds into keys
so keyDown can't tell them apart; this checks keys minus
keys_emulated.
Parameters
keystring— Web-style key code (e.g."KeyW","Space").
Returns boolean — true when the key is held this frame by a real press only.
if Zin.state.keyDownReal("KeyW") then ... end
typed/builtin//modules/zinput/state/M/keyHeldTime
M.keyHeldTime(code: string) -> number?
Seconds the given key has been held since its most recent press,
or nil if the key isn't currently held. Wall-clock based,
updated as events arrive via the tick.
Parameters
codestring— Web-style key code.
Returns number? — Held duration in seconds, or nil.
local t = Zin.state.keyHeldTime("KeyW")
typed/builtin//modules/zinput/state/M/keyPressed
M.keyPressed(key: string, surface: string?) -> boolean
Was key just pressed this frame?
Parameters
keystring— Web-style key code.surfacestring(optional) — Whose keys to read:"scene"(the default) or"editor".
Returns boolean — true on the press frame only.
if Zin.state.keyPressed("Space") then ... end
typed/builtin//modules/zinput/state/M/keyReleased
M.keyReleased(key: string, surface: string?) -> boolean
Was key just released this frame?
Parameters
keystring— Web-style key code.surfacestring(optional) — Whose keys to read:"scene"(the default) or"editor".
Returns boolean — true on the release frame only.
if Zin.state.keyReleased("KeyW") then ... end
typed/builtin//modules/zinput/state/M/keyRepeatFired
M.keyRepeatFired(code: string, opts: RepeatOpts?) -> boolean
Should a synthetic key-repeat fire this frame for code?
Returns true once per period, beginning delay seconds after the
initial press. Distinct from the repeat field on OS-level key.down
events (which surfaces hardware autorepeat — see Zin.events.on).
Each call advances per-key state, so call once per frame per logical
consumer to avoid "consuming" the repeat early.
Parameters
codestring— Web-style key code.optsRepeatOpts(optional) — Optional per-call{ delay, period }overrides; falls back togetRepeatDefaults().
Returns boolean — true on each synthetic-repeat tick.
if Zin.state.keyRepeatFired("KeyW") then ... end
typed/builtin//modules/zinput/state/M/mouseButtonDown
M.mouseButtonDown(button: (number | string)?) -> boolean
Is mouse button held? Accepts the 0-based index or a name —
0/"left", 1/"right", 2/"middle". The scene's buttons: a
press a widget holds reads up here (the device's own hold is
get().mouse_buttons_held), and a finger's press reaches here on the
frame the UI leaves it to the scene.
Parameters
button(number | string)(optional) — Button index or name (default 0 = left).
Returns boolean — true when that button is currently held.
if Zin.state.mouseButtonDown(0) then ... end
if Zin.state.mouseButtonDown("left") then ... end
typed/builtin//modules/zinput/state/M/mouseButtonHeldTime
M.mouseButtonHeldTime(button: (number | string)?) -> number?
Seconds the given mouse button has been held, or nil. Accepts the
0-based index or a name — 0/"left", 1/"right", 2/"middle".
Parameters
button(number | string)(optional) — Button index or name (default 0 = left).
Returns number? — Held duration in seconds, or nil.
local t = Zin.state.mouseButtonHeldTime("left")
typed/builtin//modules/zinput/state/M/mouseButtonPressed
M.mouseButtonPressed(button: (number | string)?) -> boolean
Was mouse button just pressed this frame? Accepts the 0-based index
or a name — 0/"left", 1/"right", 2/"middle".
Parameters
button(number | string)(optional) — Button index or name (default 0 = left).
Returns boolean — true on the press frame only.
if Zin.state.mouseButtonPressed("left") then ... end
typed/builtin//modules/zinput/state/M/mouseButtonReleased
M.mouseButtonReleased(button: (number | string)?) -> boolean
Was mouse button just released this frame? Accepts the 0-based index
or a name — 0/"left", 1/"right", 2/"middle".
Parameters
button(number | string)(optional) — Button index or name (default 0 = left).
Returns boolean — true on the release frame only.
if Zin.state.mouseButtonReleased("right") then ... end
typed/builtin//modules/zinput/state/M/mouseDelta
M.mouseDelta() -> (number, number)
Mouse delta since last frame. Returns (dx, dy) as two numbers.
It is the scene's motion: while the UI is using a person's pointer (a
widget that answers for it stands under it or holds the press, a screen
holds it, or a finger's press waits for the UI to decide it) it carries
only what a script drove the game with, and once the UI lets go it reads
the motion from that frame on. get().pointer_owner names whose the
pointer is.
Returns (number, number) — Two numbers — dx, dy. Both default to 0.0 when unavailable.
local dx, dy = Zin.state.mouseDelta()
typed/builtin//modules/zinput/state/M/mouseInViewport
M.mouseInViewport() -> boolean
True while the mouse sits inside the active scene viewport's rect
(always true when no viewport widget is on screen). Reads beside
mousePosition(), which is viewport-local when a viewport is active.
Returns boolean — Whether the pointer is inside the scene viewport.
if Zin.state.mouseInViewport() and Zin.state.mouseButtonPressed(0) then ... end
typed/builtin//modules/zinput/state/M/mousePosition
M.mousePosition() -> (number, number)
Current mouse position. Returns (x, y) as two numbers, in the
scene viewport's physical pixels measured from the top-left of the rect
the scene is drawn into: the space worldToScreen answers in and
screenToRay / Physics.raycastScreen take. ui.fromViewport(x, y)
carries the position into the logical points the UI lays out in.
Returns (number, number) — Two numbers — x, y. Both default to 0.0 when unavailable.
local x, y = Zin.state.mousePosition()
local x, y = Zin.state.mousePosition(); local p = ui.fromViewport(x, y, "window"); local over = ui.hitTest(p.x, p.y)
typed/builtin//modules/zinput/state/M/padAxis
M.padAxis(axis: string | number, slot: (number | string)?) -> number
A pad axis's value. A canonical name reads the canonical axis:
stick axes run -1..1 with y screen-down positive (matching the touch
stick), trigger axes 0..1, and with no slot the reading furthest
from rest across every pad wins, so a second pad resting at zero never
cancels the one being used. A number reads the device's own axis by
its 0-based index (a wheel, a pedal, a throttle, a rudder:
Zin.gamepad.device lists them), -1..1 across the device's native
range, from the first pad the selector names that reports it. A pedal
rests at one end of that range; Zin.bindings.padAxis calibrates it.
Parameters
axisstring | number— Canonical name: left_stick_x, left_stick_y, right_stick_x, right_stick_y, left_trigger, right_trigger; or a 0-based device axis index.slot(number | string)(optional) — Pad slot, a device name to match, or nil for any pad.
Returns number — The axis value, 0 when no pad reports it.
local x = Zin.state.padAxis("left_stick_x")
local brake = Zin.state.padAxis(2, "pedals")
typed/builtin//modules/zinput/state/M/padButtonValue
M.padButtonValue(button: string | number, slot: (number | string)?) -> number
How far a pad button is pushed, 0..1: a device button index reads
the travel the device reports for it (an analog button, a pedal a
device reports as a button), a canonical trigger its analog travel,
and any other canonical button 1 while held. Same slot rules as
padDown; the most-pushed matching pad wins.
Parameters
buttonstring | number— Canonical button name, or a 0-based device button index.slot(number | string)(optional) — Pad slot, a device name to match, or nil for any pad.
Returns number — The travel 0..1.
local squeeze = Zin.state.padButtonValue("right_trigger")
typed/builtin//modules/zinput/state/M/padDown
M.padDown(button: string | number, slot: (number | string)?) -> boolean
Is a pad button held this frame? button is a canonical name, or
a number for the device's own button by its 0-based index, every
button a wheel, a flight stick or a button board reports, past the
seventeen the canonical layout names (Zin.gamepad.device lists them).
With no slot, ANY connected pad holding it counts, which is what a
single-player scheme wants, since whichever controller the person
picked up drives the action with no pairing step. Name a slot for local
multiplayer, or a string to name a device by its name or id.
Parameters
buttonstring | number— Canonical name: south, east, west, north, left_shoulder, right_shoulder, left_trigger, right_trigger, left_stick, right_stick, select, start, guide, dpad_up, dpad_down, dpad_left, dpad_right; or a 0-based device button index.slot(number | string)(optional) — Pad slot, a device name to match, or nil for any pad.
Returns boolean — True when held.
if Zin.state.padDown("south") then ... end
if Zin.state.padDown(19, "wheel") then shiftUp() end
typed/builtin//modules/zinput/state/M/padPressed
M.padPressed(button: string | number, slot: (number | string)?) -> boolean
Did a pad button go down this frame? Same button and slot rules
as padDown.
Parameters
buttonstring | number— Canonical button name, or a 0-based device button index.slot(number | string)(optional) — Pad slot, a device name to match, or nil for any pad.
Returns boolean — True on the press frame.
if Zin.state.padPressed("start") then ... end
typed/builtin//modules/zinput/state/M/padReleased
M.padReleased(button: string | number, slot: (number | string)?) -> boolean
Did a pad button come up this frame? Same button and slot rules
as padDown.
Parameters
buttonstring | number— Canonical button name, or a 0-based device button index.slot(number | string)(optional) — Pad slot, a device name to match, or nil for any pad.
Returns boolean — True on the release frame.
if Zin.state.padReleased("south") then ... end
typed/builtin//modules/zinput/state/M/pointerLockRequested
M.pointerLockRequested() -> boolean
Does a pointer-lock request stand? The intent Zin.pointer.lock
writes and the platform layer reads, which the surface grants on a click
(pointerLocked() is the grant). Reads the snapshot, so a request made
this frame reads here from the next one; Zin.pointer.holders() names
who is asking.
Returns boolean — true while the request stands.
if Zin.state.pointerLockRequested() then ... end
typed/builtin//modules/zinput/state/M/pointerLocked
M.pointerLocked() -> boolean
Is the pointer currently locked?
Returns boolean — true when the pointer is locked.
if Zin.state.pointerLocked() then ... end
typed/builtin//modules/zinput/state/M/sceneContextActive
M.sceneContextActive() -> boolean
True while the SCENE is the active input context: the last pointer
gesture began in a scene viewport's picture (or pointer lock holds), so
continuous scene input (camera fly, buttons, pointer motion) and the keys
belong to the scene. The wheel follows the pointer instead
(scrollDelta). The game's own UI is drawn in that picture, so a press on
one of its buttons is a gesture in the scene, and a text field of its
own takes every key while it holds the caret. A gesture that begins on
an editor widget, or a text field of the editor's taking the caret,
hands the context to the UI until a press lands in the picture again.
With no viewport widget on screen the scene is the whole surface and
this is always true.
Returns boolean — Whether the scene holds the active input context this frame.
if Zin.state.sceneContextActive() then cam:fly(dt) end
typed/builtin//modules/zinput/state/M/scrollDelta
M.scrollDelta() -> number
Mouse wheel delta this frame, turned over the scene. The wheel
belongs to the surface under the pointer: turned over the scene's
picture (or with the pointer locked to it) it reads here, and turned over
an editor panel beside the Scene it scrolls that panel and reads 0,
whichever surface was last pressed. A wheel a script turned for the game
reads here wherever the pointer is.
Returns number — The signed scroll delta, or 0.0 when unavailable.
local dy = Zin.state.scrollDelta()
typed/builtin//modules/zinput/state/M/setRepeatDefaults
M.setRepeatDefaults(opts: RepeatOpts?)
Set the global default delay / period for synthetic key repeat. Either field is optional; omitted fields keep their current value. Default: delay = 0.4 s, period = 0.1 s.
Parameters
optsRepeatOpts(optional) — Partial overrides fordelay/period(seconds).
Zin.state.setRepeatDefaults({ delay = 0.5, period = 0.05 })
typed/builtin//modules/zinput/state/M/uiHoldsPointer
M.uiHoldsPointer() -> { string }
The shown screens holding the pointer this frame, by layer: a
screen with an open modal, or with a shown widget stating
holdsPointer = true. While any does, the cursor is the person's: a
pointer lock the game asks for stands down until none is left, and then
comes back as the game asked. Reads the snapshot, so a screen shown this
frame reads here from the next one.
Returns { string } — An array of screen names; empty while no screen holds the pointer.
if #Zin.state.uiHoldsPointer() > 0 then return end
typed/builtin//modules/zinput/state/M/uiTookPress
M.uiTookPress() -> boolean?
Whether a UI widget holds the pointer press in progress: true
when the press landed on a widget that answers for the pointer (a
button, a slider, anything sensing a click or a drag). false with no
press held, and for a press on empty space, which a HUD's own boxes do
not take, so it tells a press the game should see from one a widget is
handling. nil from the moment a press arrives until a UI pass has run
to decide it. A tap that lifts before that pass reads the pass's answer
on the frame after it, so a tap a button took reads true there.
Returns boolean? — true while a widget holds the press, nil while undecided.
if Zin.state.uiTookPress() == true then return end
typed/builtin//modules/zinput/state/M/uiWantsKeyboard
M.uiWantsKeyboard(space: string?) -> boolean
True while the UI layer holds keyboard focus with a widget that takes
every key — a text field has the caret, a terminal or a widget with its
own onKey is focused — so keys reaching the window belong to it. A
focused button or slider takes only the keys that press or step it and
leaves this false: get().keyboard_owner reads "shared" then, and
get().ui_keys names the keys it takes. Travels separately
from pointer focus: a caret in a field takes keys while the cursor sits
over the viewport, and a hovered panel takes clicks while no field has
the caret. Two UIs can hold it: the game's own, drawn in the game view
("camera" space — a chat box, a name entry), and the editor's, drawn in
the window around it ("window" space — a panel's field, an agent's
terminal). Name a space to ask about one of them; a game asking whether
its own UI is taking the keys passes "camera".
Parameters
spacestring(optional) —"camera"for the game's UI,"window"for the editor's; nil for either.
Returns boolean — Whether that UI holds keyboard focus.
if Zin.state.uiWantsKeyboard("camera") then return end -- the chat box has the keys
typed/builtin//modules/zinput/state/M/uiWantsPointer
M.uiWantsPointer() -> boolean
True while the UI layer holds pointer focus — a widget that answers for the pointer (a button, a slider, a field, anything sensing a click or a drag) is under the cursor, so what the pointer produces belongs to it. A HUD's panels, labels and the space between its widgets answer for nothing, so the pointer over them stays the game's. While a button is held it answers for the press: true for every frame of a press a widget took, false for every frame of one that landed on no widget. Travels separately from keyboard focus: a hovered button takes clicks while no field has the caret, and a caret in a field takes keys while the cursor sits over the viewport. Useful for gating game-side input while a UI is using the pointer.
Returns boolean — true when the UI has pointer focus this frame.
if not Zin.state.uiWantsPointer() then ... end
typed/builtin//modules/zinput/surface/M/_beginFrame
M._beginFrame()
Internal: clear this frame's per-class flags. On the first tick of the session, also captures the capability default as the reported class the change signal compares against. Called by the Zin.tick coordinator on the first tick of each engine frame.
Zin.surface._beginFrame()
typed/builtin//modules/zinput/surface/M/_observeEvent
M._observeEvent(ev: any?)
Internal: per-event observer called by the Zin.tick coordinator. Collects which device classes produced events this frame, telling a simulated input's events from a device's, which of keyboard and mouse or pad came last, and which simulated keys and mouse buttons are held.
Parameters
evany(optional) — The raw input event record.
Zin.surface._observeEvent(ev)
typed/builtin//modules/zinput/surface/M/_reset
M._reset()
Test-only: clear resolution state and subscriptions. Suite isolation; not part of the public contract.
Zin.surface._reset()
typed/builtin//modules/zinput/surface/M/_resolveFrame
M._resolveFrame()
Internal: resolve this frame's class and fire onChange on a flip. Touch wins a frame containing any touch event (the primary contact's projected mouse events never mask their own touch); else the frame's last keyboard, mouse or pad event decides. A device's event resolves the class and ends any simulation; a simulated one presents its class for as long as the input lasts (a contact on the glass, a key or mouse button held, a pad connected), and once it ends the class is the one device input left.
Zin.surface._resolveFrame()
typed/builtin//modules/zinput/surface/M/_settled
M._settled() -> boolean
Internal: whether this frame carried no class-bearing event and no simulated contact, key or mouse button presents the class. The tick's quiescence gate reads it, so the frame after the last simulated contact lifts, or the last simulated key or mouse button is released, is resolved; a simulated pad ends with its disconnection, an event that wakes the tick.
Returns boolean — true when nothing arrived to resolve a surface class from.
if Zin.surface._settled() then ... end
typed/builtin//modules/zinput/surface/M/current
M.current() -> string
The active input-surface class: "touch", "kbm" or
"gamepad". A forced class wins; then "gamepad" while a headset
session holds input focus, since the person then holds its hand
controllers, which present as the pad; then a simulated input that
still lasts (a contact on the glass, a key or mouse button held, a
pad connected) presents its class; then device input history; before
any input it defaults by capability (touch sessions start as
"touch").
Returns string — The surface class string.
if Zin.surface.current() == "touch" then ... end
typed/builtin//modules/zinput/surface/M/force
M.force(class: string?) -> string
Pin the surface class, or hand control back to real input.
This is how a desktop session is checked as a phone: forcing
"touch" mounts the on-screen controls exactly as a device would, so
the layout can be read and its buttons tapped. Nothing else about the
session changes — the pin decides which class is reported, and every
consumer that branches on it follows.
Parameters
classstring(optional) —"kbm"|"touch"|"gamepad", or"auto"/ nil to release the pin.
Returns string — The class in effect after the call.
Zin.surface.force("touch")
Zin.surface.force("auto")
typed/builtin//modules/zinput/surface/M/forced
M.forced() -> string?
Whether the class is currently pinned by force rather than
resolved from real input.
Returns string? — The pinned class, or nil.
if Zin.surface.forced() ~= nil then ... end
typed/builtin//modules/zinput/surface/M/off
M.off(handle: number) -> boolean
Unsubscribe an onChange handle. Returns true when removed.
Parameters
handlenumber— The handle from onChange.
Returns boolean — Whether a subscription was removed.
Zin.surface.off(h)
typed/builtin//modules/zinput/surface/M/onChange
M.onChange(fn: (string, string?) -> ()) -> number
Subscribe to surface-class changes. fn(now, prev) fires from
the tick pipeline on the frame the class flips; prev is the
previously reported class (the first-tick capability default when
no event had resolved yet).
Parameters
fn(string, string?) -> ()— The callback.
Returns number — A numeric handle for Zin.surface.off.
local h = Zin.surface.onChange(function(now) print(now) end)
typed/builtin//modules/zinput/test/M/action
M.action(name: string, value: any?, duration: number?)
Perform a gameplay action through the control the game reads it
from: drive the control named name with value, hold it for
duration seconds, and let it go. A button with no value is tapped —
held until an evaluation of the input maps has read it, then released.
Returns once the game has read the release. The control must be live
(Zin.scheme.bindings() lists them); the value is true for a button,
a number for a 1-D axis, { x, y } for a 2-D axis. No device is
touched, so a person's focus neither takes the action nor receives it.
Parameters
namestring— The control's name ("jump","move","sprint").valueany(optional) — What the control reads while held;truewhen omitted.durationnumber(optional) — Seconds to hold it; one evaluation when omitted.
Zin.test.action("jump")
Zin.test.action("move", { 0, 1 }, 2) -- walk forward for 2 s
typed/builtin//modules/zinput/test/M/clickMouse
M.clickMouse(button: (number | string)?, x: number?, y: number?, duration: number?, target: string?)
Press + release a mouse button, in the order every mouse call here
takes its arguments: which button, where, how long. x and y move
the cursor before pressing; duration holds the button for that many
seconds before releasing. Does NOT tick — call Zin.tick(dt) between
clickMouse and your assertion if you need binding-action handlers
to fire.
Parameters
button(number | string)(optional) — Button index or name, the same pairpressMousetakes (default 0 = left).xnumber(optional) — Window x to move the cursor to first, in physical pixels.ynumber(optional) — Window y to move the cursor to first, in physical pixels.durationnumber(optional) — Hold seconds between press and release.targetstring(optional) —"game"(the default) drives the game's input alone — the scene reads it whatever a person at the window has focused, and no UI widget receives it."ui"reaches the UI the way a person's device does.
Zin.test.clickMouse()
Zin.test.clickMouse(nil, 100, 200)
Zin.test.clickMouse("right", 100, 200, 0.2)
Zin.test.clickMouse(nil, 100, 200, nil, "ui") -- a click on whatever widget is there
typed/builtin//modules/zinput/test/M/connectPad
M.connectPad(name: string?, device: { [string]: any }?) -> number
Connect a simulated pad and return the slot it took. name is the
device name the pad reports, which decides the button legends a
prompt draws; pass a real product name to check a scheme's prompts
on that family. With no device the pad presents the W3C standard
gamepad with rumble motors; device presents another: { axes = 6, buttons = 25 } for a wheel, pedals or a flight stick (elements laid
out by no mapping, read and bound by index), rumble = false for one
with no motors, triggerRumble = true for one with trigger motors,
force = true for a wheel or stick that plays force-feedback effects,
id / vendor / product for its identity, and rest for where its
own axes rest when it connects (a reading -1..1 for every axis, or a
list of one per axis; rest = -1 is a pedal box with every pedal
released). Axes with no rest start at 0.
Parameters
namestring(optional) — Device name; "Simulated Gamepad" when omitted.device{ [string]: any }(optional) —{ axes?, buttons?, rumble?, triggerRumble?, force?, id?, vendor?, product?, rest? }.
Returns number — The slot the pad occupies.
Zin.test.connectPad("Xbox Wireless Controller")
Zin.test.connectPad("Racing Wheel", { axes = 6, buttons = 25 })
Zin.test.connectPad("Pedals", { axes = 3, rest = -1 })
typed/builtin//modules/zinput/test/M/disconnectPad
M.disconnectPad(slot: number?)
Disconnect the pad in slot. Anything it still held is released
first, so a held control ends rather than sticking.
Parameters
slotnumber(optional) — The pad slot; 0 when omitted.
Zin.test.disconnectPad(0)
typed/builtin//modules/zinput/test/M/dragFiles
M.dragFiles(x: number, y: number, count: number)
Stand a drag of count files from outside the engine at a point of
the window, in physical pixels, the way a person holding files over it
does: the widget there reports it through onFileHover. End it with
endFileDrag or dropFiles.
Parameters
xnumber— Window x coordinate, in physical pixels.ynumber— Window y coordinate, in physical pixels.countnumber— How many files the drag carries.
Zin.test.dragFiles(100, 200, 2)
typed/builtin//modules/zinput/test/M/dragLook
M.dragLook(dx: number, dy: number, steps: number?)
Drag across the on-screen look zone by (dx, dy) pixels, spread
over steps frames so the per-frame deltas a look binding reads are
real rather than one impossible jump.
Parameters
dxnumber— Total horizontal travel in pixels.dynumber— Total vertical travel in pixels.stepsnumber(optional) — Frames to spread it over; 8 when omitted.
Zin.test.dragLook(200, 0)
typed/builtin//modules/zinput/test/M/dropFiles
M.dropFiles(x: number, y: number, files: { any })
Drop files on a point of the window, in physical pixels, through the
path a drop from the desktop takes: the widget there receives them through
onFileDrop.
Parameters
xnumber— Window x coordinate, in physical pixels.ynumber— Window y coordinate, in physical pixels.files{ any }— The files, each{ name, bytes, type? }(typeis read off the name when omitted) or{ name, error }for a file that arrives refused.
Zin.test.dropFiles(100, 200, { { name = "note.txt", bytes = "hello" } })
typed/builtin//modules/zinput/test/M/endFileDrag
M.endFileDrag()
End a drag dragFiles stood over the window, the way a person
carrying it off does.
Zin.test.endFileDrag()
typed/builtin//modules/zinput/test/M/engage
M.engage()
Explicit opt-out for suites/harnesses that own their own tick
cadence but haven't injected synthetic input yet — call before the
first Zin.state / Zin.actions / Zin.axes read so the liveness
auto-arm doesn't start Zin.autoTick underneath the harness.
Zin.test.engage()
typed/builtin//modules/zinput/test/M/engaged
M.engaged() -> boolean
True once any synthetic test-input helper (pressKey,
touchStart, etc.) or engage() has run this VM. Read by the
liveness auto-arm so a test/harness VM keeps explicit control of
Zin.tick cadence instead of the first real input read starting
Zin.autoTick.
Returns boolean — Whether this VM has engaged synthetic test input.
if Zin.test.engaged() then ... end
typed/builtin//modules/zinput/test/M/focusScene
M.focusScene()
Hand continuous pointer input to the scene: the pointer the UI reads
and the one the scene reads are both placed at the middle of the
scene's viewport, a placement that reports no pointer motion (a mouse
look reads nothing from it), and the scene becomes the active input
context, which is where a fresh VM's first simulated input already
finds it and where releaseAll puts it back. While a viewport widget
shares the screen with editor panels, the scene reads buttons and motion
only as the active context, and a gesture decides the context by where
it begins, and it reads the wheel only while the pointer is over its
picture — so a test that has been clicking widgets calls this before
driving the scene again. Yields one frame.
Zin.test.focusScene()
typed/builtin//modules/zinput/test/M/held
M.held() -> Held
Everything the session is holding down right now, across every
device class: keys, mouse buttons, touch contacts, the on-screen
stick, and connected pads with the buttons they hold. atRest is
true when it holds nothing. keysEmulated is the subset of keys
the input-emulation floor holds, the same split
Zin.state.keyDownReal reads.
Read from the engine's live input state, so a hold whose caller is
gone — a driver task cancelled mid-press, a macro that errored — is
still reported and can still be let go. releaseAll lets go of what
this reports that the surface itself put down.
Returns Held — { atRest, keys, keysEmulated, mouse, contacts, stick, pads }.
local h = Zin.test.held(); if not h.atRest then Zin.test.releaseAll() end
typed/builtin//modules/zinput/test/M/holdAction
M.holdAction(name: string, value: any?)
Drive a control and leave it driven until releaseAction (or
releaseAll) lets it go. Returns once an evaluation has read it.
Parameters
namestring— The control's name.valueany(optional) — What it reads;truewhen omitted.
Zin.test.holdAction("sprint")
Zin.test.holdAction("move", { 1, 0 })
typed/builtin//modules/zinput/test/M/moveMouse
M.moveMouse(x: number, y: number, target: string?)
Move the cursor to a position on the window, in physical pixels —
the space a layout coordinate reaches through ui.pixelRatio(), and
the space camera.viewData().viewport states the scene's rect in.
Sets the absolute position; the engine computes mouse_delta as
new - old, so successive calls produce meaningful deltas for orbit /
look bindings.
Parameters
xnumber— Absolute window x coordinate, in physical pixels.ynumber— Absolute window y coordinate, in physical pixels.targetstring(optional) —"game"(the default) drives the game's input alone — the scene reads it whatever a person at the window has focused, and no UI widget receives it."ui"reaches the UI the way a person's device does.
Zin.test.moveMouse(100, 200)
typed/builtin//modules/zinput/test/M/moveMouseBy
M.moveMouseBy(dx: number, dy: number, steps: number?, target: string?)
Move the cursor by a relative motion, the way a mouse device
reports one: the motion lands in this frame's mouse_delta and the
position advances by the same amount. The same (dx, dy) repeated
keeps producing look movement, so an axis can be held or steered by
a controller issuing a correction each tick.
steps spreads the motion over that many frames, each carrying its
share of it, for a look sweep whose per-frame deltas are the ones a
binding would really read.
Parameters
dxnumber— Horizontal motion in screen pixels.dynumber— Vertical motion in screen pixels.stepsnumber(optional) — Frames to spread it over; 1 when omitted, which reports the whole motion in a single frame.targetstring(optional) —"game"(the default) drives the game's input alone — the scene reads it whatever a person at the window has focused, and no UI widget receives it."ui"reaches the UI the way a person's device does.
Zin.test.moveMouseBy(0, 140)
Zin.test.moveMouseBy(0, 140, 8)
typed/builtin//modules/zinput/test/M/padDeviceAxis
M.padDeviceAxis(index: number, value: number, duration: number?, slot: number?, rest: number?)
Move a simulated pad's own axis index (0-based, in the device's
order) to value, -1..1 across its range, a wheel turned, a pedal
pressed (a pedal reads -1 released and 1 floored). Holds until moved
again, or for duration seconds before going back to rest (-1 when
omitted, the released pedal; pass 0 for a centred axis).
Parameters
indexnumber— 0-based device axis index.valuenumber— Reading -1..1.durationnumber(optional) — Hold seconds; left there when omitted.slotnumber(optional) — The pad slot; 0 when omitted.restnumber(optional) — The reading it returns to afterduration.
Zin.test.padDeviceAxis(1, 1)
typed/builtin//modules/zinput/test/M/padDeviceButton
M.padDeviceButton(index: number, held: boolean, slot: number?, value: number?)
Push or release a simulated pad's own button index (0-based, in
the device's order), with its travel value (1 held, 0 released when
omitted).
Parameters
indexnumber— 0-based device button index.heldboolean— Whether it is down.slotnumber(optional) — The pad slot; 0 when omitted.valuenumber(optional) — Travel 0..1.
Zin.test.padDeviceButton(24, true)
typed/builtin//modules/zinput/test/M/padDown
M.padDown(button: string, slot: number?)
Push a canonical pad button down and leave it held.
Parameters
buttonstring— Canonical button name.slotnumber(optional) — The pad slot; 0 when omitted.
Zin.test.padDown("south")
typed/builtin//modules/zinput/test/M/padPress
M.padPress(button: string, duration: number?, slot: number?)
Press a canonical pad button — down, optionally held, then up.
Parameters
buttonstring— Canonical button name.durationnumber(optional) — Hold seconds; an instant press when omitted.slotnumber(optional) — The pad slot; 0 when omitted.
Zin.test.padPress("south")
typed/builtin//modules/zinput/test/M/padStick
M.padStick(stick: string, x: number, y: number, duration: number?, slot: number?)
Push a thumbstick to (x, y), each -1..1 with y screen-down
positive. Holds until pushed back to zero, or for duration seconds.
Parameters
stickstring— "left" or "right".xnumber— Deflection -1..1.ynumber— Deflection -1..1, screen-down positive.durationnumber(optional) — Hold seconds; left deflected when omitted.slotnumber(optional) — The pad slot; 0 when omitted.
Zin.test.padStick("left", 0, -1, 2)
typed/builtin//modules/zinput/test/M/padTrigger
M.padTrigger(trigger: string, value: number, duration: number?, slot: number?)
Squeeze a trigger to value, 0..1. Past half throw the trigger's
digital button latches too, so a scheme binding either the analog
travel or the button sees this.
Parameters
triggerstring— "left" or "right".valuenumber— Travel 0..1.durationnumber(optional) — Hold seconds; left squeezed when omitted.slotnumber(optional) — The pad slot; 0 when omitted.
Zin.test.padTrigger("right", 1)
typed/builtin//modules/zinput/test/M/padUp
M.padUp(button: string, slot: number?)
Release a canonical pad button.
Parameters
buttonstring— Canonical button name.slotnumber(optional) — The pad slot; 0 when omitted.
Zin.test.padUp("south")
typed/builtin//modules/zinput/test/M/pasteFiles
M.pasteFiles(files: { any })
Paste files through the path a clipboard image takes: the widget
holding the keyboard focus receives them through onFilePaste.
Parameters
files{ any }— The files, asdropFilestakes them.
Zin.test.pasteFiles({ { name = "shot.png", bytes = png } })
typed/builtin//modules/zinput/test/M/pinch
M.pinch(amount: number, steps: number?)
Pinch two fingers together (negative amount) or spread them
apart (positive) by that many pixels, over steps frames.
Parameters
amountnumber— Pixels; negative pinches, positive spreads.stepsnumber(optional) — Frames to spread it over; 8 when omitted.
Zin.test.pinch(150)
typed/builtin//modules/zinput/test/M/pressKey
M.pressKey(code: string, target: string?)
Hold a key DOWN and leave it held until releaseKey. Returns
inside the frame where keys_pressed contains code, so
Zin.actions.pressed polls and onPressed handlers both fire as
the call returns. A second pressKey on a key that is still held
produces no new press edge — release first, or use tapKey for a
full press+release.
Parameters
codestring— Web-style key code (e.g."KeyM","Space").targetstring(optional) —"game"(the default) drives the game's input alone — the scene reads it whatever a person at the window has focused, and no UI widget receives it."ui"reaches the UI the way a person's device does.
Zin.test.pressKey("KeyM"); Zin.test.releaseKey("KeyM")
Zin.test.pressKey("KeyA", "ui") -- typed into the focused field
typed/builtin//modules/zinput/test/M/pressMouse
M.pressMouse(button: (number | string)?, target: string?)
Simulate a mouse button press. Accepts a 0-based index OR a
case-insensitive name ("left"/"right"/"middle", matching
Zin.bindings.mouse). Default: left.
Parameters
button(number | string)(optional) — Optional button index or name (default 0 = left).targetstring(optional) —"game"(the default) drives the game's input alone — the scene reads it whatever a person at the window has focused, and no UI widget receives it."ui"reaches the UI the way a person's device does.
Zin.test.pressMouse() -- left
Zin.test.pressMouse(1) -- right
Zin.test.pressMouse("right") -- right
typed/builtin//modules/zinput/test/M/pushStick
M.pushStick(x: number, y: number, duration: number?) -> number?
Push the on-screen movement stick to (x, y), each -1..1 with y
screen-down positive. Lands a contact in the stick's zone and lets
the overlay route it, so the deflection is one a player could
actually produce.
Parameters
xnumber— Deflection -1..1.ynumber— Deflection -1..1, screen-down positive. One finger drives the stick for the whole session: a second call moves the finger already down rather than adding another.durationnumber(optional) — Hold seconds, then release. Omitted, the stick STAYS deflected — release it withpushStick(0, 0)orreleaseStick().
Returns number? — The contact id while held, or nil once released.
Zin.test.pushStick(0, -1, 2)
Zin.test.pushStick(0, -1) ; ... ; Zin.test.releaseStick()
typed/builtin//modules/zinput/test/M/releaseAction
M.releaseAction(name: string?)
Let go of a control holdAction drove — or of every driven control
when no name is given. Returns once an evaluation has read the release.
Parameters
namestring(optional) — The control; nil for all of them.
Zin.test.releaseAction("sprint")
typed/builtin//modules/zinput/test/M/releaseAll
M.releaseAll() -> Released
Put the whole session down: drop the on-screen stick, lift every
touch contact, release every held key and mouse button, and
disconnect every pad connectPad connected — a controller plugged
into the machine stays connected, and held() goes on reporting it.
After it, nothing this surface put down is held, the pointer sits
over the middle of the scene's viewport and the scene holds the
input context (see focusScene).
Returns Released — { actions, keys, mouse, contacts, pads, stick } — how many of each was let go, and whether the on-screen stick was one of them.
Zin.test.releaseAll()
typed/builtin//modules/zinput/test/M/releaseKey
M.releaseKey(code: string, target: string?)
Simulate a key release. Returns inside the frame where
keys_released contains code.
Parameters
codestring— Web-style key code.targetstring(optional) —"game"(the default) drives the game's input alone — the scene reads it whatever a person at the window has focused, and no UI widget receives it."ui"reaches the UI the way a person's device does.
Zin.test.releaseKey("KeyM")
typed/builtin//modules/zinput/test/M/releaseMouse
M.releaseMouse(button: (number | string)?, target: string?)
Simulate a mouse button release. Accepts a 0-based index OR a
case-insensitive name ("left"/"right"/"middle"). Default: left.
Parameters
button(number | string)(optional) — Optional button index or name (default 0 = left).targetstring(optional) —"game"(the default) drives the game's input alone — the scene reads it whatever a person at the window has focused, and no UI widget receives it."ui"reaches the UI the way a person's device does.
Zin.test.releaseMouse()
Zin.test.releaseMouse("middle")
typed/builtin//modules/zinput/test/M/releaseStick
M.releaseStick() -> boolean
Lift the finger driving the on-screen stick, if one is down.
pushStick(0, 0) does this too; this is the explicit form, and what
a test calls to be sure it starts from rest.
Returns boolean — True when a contact was lifted.
Zin.test.releaseStick()
typed/builtin//modules/zinput/test/M/releaseUiFocus
M.releaseUiFocus()
Give the UI's focus pair back to the UI pass, which writes its own opinion on its next run.
Zin.test.releaseUiFocus()
typed/builtin//modules/zinput/test/M/runFrame
M.runFrame()
Advance one engine frame: yield until the engine has published a
later frame's snapshot, so simulated events queued before the call have
drained into the state a read after it sees. Use between manual
__zero_input.simulate* calls when you need to checkpoint state
without queueing a new event. Does NOT call Zin.tick() — run it
yourself if you want action / event handlers to dispatch.
Zin.test.runFrame()
typed/builtin//modules/zinput/test/M/scroll
M.scroll(dy: number, target: string?)
Simulate a mouse wheel scroll. Positive dy = up.
Parameters
dynumber— Signed scroll delta.targetstring(optional) —"game"(the default) drives the game's input alone;"ui"reaches the UI the way a person's device does.
Zin.test.scroll(1)
typed/builtin//modules/zinput/test/M/setClipboard
M.setClipboard(content: { text: string?, image: string? }?)
State what the clipboard holds, in place of the host clipboard, until
it is stated again or nil hands it back. Ctrl+V reads it the way it
reads the host's, so pressKey("ControlLeft", "ui") and
tapKey("KeyV", nil, "ui") then run the path a person's paste takes: text
goes into the focused field, and a picture with no text to the widget
taking pasted files (onFilePaste). A copy writes the stated text. A
browser engine hands its clipboard over through the page's paste event,
so it raises there; pasteFiles drives the path that event posts to.
Parameters
content{ text: string?, image: string? }(optional) —{ text?, image? },imagethe bytes of a PNG, or nil for the host clipboard.
Zin.test.setClipboard({ image = png })
typed/builtin//modules/zinput/test/M/tapKey
M.tapKey(code: string, duration: number?, target: string?)
Press + release in one call. If duration is set, waits that
many seconds (held over multiple frames) between press and release.
Does NOT tick — call Zin.tick(dt) between tapKey and your
assertion if you need binding-action handlers to fire.
Parameters
codestring— Web-style key code.durationnumber(optional) — Optional held duration in seconds.targetstring(optional) —"game"(the default) drives the game's input alone — the scene reads it whatever a person at the window has focused, and no UI widget receives it."ui"reaches the UI the way a person's device does.
Zin.test.tapKey("Space", 0.1)
typed/builtin//modules/zinput/test/M/tapTouchButton
M.tapTouchButton(name: string, duration: number?)
Tap the on-screen button name names, at its real centre. name
is any of the three names Zin.touchControls.layout() (and
inputSim layout) lists per button: its id, the actionName of the
control it works, or its label as it reads now. The id and the
control's name read the same in every language. Raises when no live
button answers to name, listing the ones that do: a tap that
silently lands on nothing is worse than one that stops and says so.
A button giving way to a game screen's widget over it (layout().yielded,
a sheet entry's yieldedTo) takes no tap, a press there reaching the
widget, so naming one raises with the widget and screen it gives way to.
A "corner" button giving way takes the tap where its centre is out of
a press's reach of every widget (freeAtCentre), and otherwise is
pressed by its holdFingers contacts held on it for its holdSeconds:
naming one with a duration that long holds them.
Parameters
namestring— The button's id, its control's name, or its label.durationnumber(optional) — Hold seconds; an instant tap when omitted.
Zin.test.tapTouchButton("jump")
Zin.test.tapTouchButton("Jump")
typed/builtin//modules/zinput/test/M/touchCancel
M.touchCancel(id: number, target: string?)
Simulate the platform cancelling a touch contact.
Parameters
idnumber— Stable finger id.targetstring(optional) —"game"(the default) drives the game's input alone;"ui"reaches the UI the way a person's device does.
Zin.test.touchCancel(1)
typed/builtin//modules/zinput/test/M/touchDown
M.touchDown(x: number, y: number, pressure: number?, target: string?) -> number
Put a finger down at (x, y) and return its contact id — the id
touchMove and touchUp take. Ids are handed out for you, so a
two-finger gesture is two of these rather than a bookkeeping problem.
The point is on the window, in physical pixels (see touchStart).
Parameters
xnumber— Window x, in physical pixels.ynumber— Window y, in physical pixels.pressurenumber(optional) — Contact pressure 0..1; 1 when omitted.targetstring(optional) —"game"(the default) drives the game's input alone;"ui"reaches the UI the way a person's device does.
Returns number — The contact id.
local id = Zin.test.touchDown(200, 600)
typed/builtin//modules/zinput/test/M/touchEnd
M.touchEnd(id: number, target: string?)
Simulate a touch contact lifting.
Parameters
idnumber— Stable finger id.targetstring(optional) —"game"(the default) drives the game's input alone;"ui"reaches the UI the way a person's device does.
Zin.test.touchEnd(1)
typed/builtin//modules/zinput/test/M/touchMove
M.touchMove(id: number, x: number, y: number, pressure: number?, target: string?)
Simulate a touch contact moving, to a point on the window in
physical pixels (see touchStart).
Parameters
idnumber— Stable finger id.xnumber— Window x, in physical pixels.ynumber— Window y, in physical pixels.pressurenumber(optional) — Contact pressure 0..1 (defaults to 1).targetstring(optional) —"game"(the default) drives the game's input alone;"ui"reaches the UI the way a person's device does.
Zin.test.touchMove(1, 440, 300)
typed/builtin//modules/zinput/test/M/touchStart
M.touchStart(id: number, x: number, y: number, pressure: number?, target: string?)
Simulate a touch contact beginning, on the window in physical
pixels: the space a finger on the glass arrives in and moveMouse
takes, where a UI widget sits at its ui.getLayoutInfo rect times
ui.pixelRatio(). Zin.touch.slots() reads the contact back in the
scene viewport's space, this point less the origin
camera.viewData().viewport carries, times its scaleX / scaleY. id is any stable number
identifying the finger until its matching touchEnd/touchCancel.
The contact driving the pointer (Zin.touch pointer) also drives
the mouse path.
Parameters
idnumber— Stable finger id.xnumber— Window x, in physical pixels.ynumber— Window y, in physical pixels.pressurenumber(optional) — Contact pressure 0..1 (defaults to 1).targetstring(optional) —"game"(the default) drives the game's input alone;"ui"reaches the UI the way a person's device does.
Zin.test.touchStart(1, 400, 300)
typed/builtin//modules/zinput/test/M/touchUp
M.touchUp(id: number, target: string?)
Lift a contact opened by touchDown.
Parameters
idnumber— The contact id.targetstring(optional) —"game"(the default) drives the game's input alone;"ui"reaches the UI the way a person's device does.
Zin.test.touchUp(id)
typed/builtin//modules/zinput/test/M/uiFocus
M.uiFocus(pointer: boolean, keyboard: boolean)
Hold the UI layer's two focus opinions, so a run with no UI on
screen can put an event on either side of consumed_by_ui. A pointer
event is judged on pointer and a key on keyboard, and both hold
until Zin.test.releaseUiFocus(). Inputs simulated after this call
are routed against the pair.
Parameters
pointerboolean— Whether the UI holds pointer focus.keyboardboolean— Whether the UI holds keyboard focus.
Zin.test.uiFocus(true, false)
typed/builtin//modules/zinput/test/M/xrController
M.xrController(hand: string, control: string, value: (number | { number })?)
Inject a control of an XR hand controller where the runtime's action
set enters the engine. The pad, the turning, the pointer ray and
xr.controller follow it exactly as they follow a held controller, for
as long as the XR session holds input focus. value is a number for a
single control, { x, y } for the thumbstick, and
{ px, py, pz, qx, qy, qz, qw } (tracking space) for grip and aim;
nil returns the control to the runtime. hand poses a modelled hand in
place of hand tracking (the palm's seven numbers, then the curl of the
thumb, index, middle, ring and little finger from 0 open to 1 closed) and
joints states all 26 joints as eight numbers each (pose, radius): a hand
with joints and no controller is driven by hand tracking.
Parameters
handstring— "left_hand" or "right_hand".controlstring— "active", "thumbstick", "thumbstick_click", "trigger", "squeeze", "primary", "secondary", "menu", "grip", "aim", "hand" or "joints".value(number | { number })(optional) — The control's value; nil releases it.
Zin.test.xrController("left_hand", "thumbstick", { 0, 1 })
Zin.test.xrController("right_hand", "thumbstick", { 1, 0 })
Zin.test.xrController("right_hand", "hand", { 0.2, 1.2, -0.4, 0, 0, 0, 1, 0, 0, 0, 0, 0 })
typed/builtin//modules/zinput/test/M/xrHead
M.xrHead(pose: { number }?)
Inject the headset's head pose where the runtime's located head enters
the engine, in the tracking space. Both eyes move rigidly with it, so the
picture, xr.pose("head"), the facing camera.facing reports and the look
ray follow it as they follow a head that moved. It takes effect while the
XR session draws frames.
Parameters
pose{ number }(optional) —{ px, py, pz, qx, qy, qz, qw }; nil returns the head to the runtime.
Zin.test.xrHead({ 0, 1.7, 0, 0, 0.7071, 0, 0.7071 }) -- the head turned a quarter turn left
typed/builtin//modules/zinput/test/M/xrRelease
M.xrRelease()
Return every injected XR controller control and the injected head to the runtime.
Zin.test.xrRelease()
typed/builtin//modules/zinput/test/M/xrSession
M.xrSession(on: boolean)
Start (true) or stop (false) a simulated XR session: the engine
runs its XR frame loop over a session that needs no headset, which holds
input focus, locates a head standing at the tracking space's origin 1.6 m
up and facing -Z, and reports the controllers Zin.test.xrController and
the head Zin.test.xrHead state. The session starts and stops on an
engine frame, so wait for xr.focused() after starting it. Native
engines only.
Parameters
onboolean— true starts the session, false stops it.
Zin.test.xrSession(true)
typed/builtin//modules/zinput/test/M/xrUnfocused
M.xrUnfocused(waitMs: number)
Make the simulated XR session a headset that does not show its frames: it
loses input focus and each wait of its frame loop for the next frame takes
waitMs milliseconds, the pace a runtime throttles such a session to. The
engine's frames do not wait for those waits and no eyes are drawn. 0 gives the
session focus back. Takes effect on the session's next poll. Native
engines only.
Parameters
waitMsnumber— milliseconds each wait for a frame takes while unfocused; 0 restores focus.
Zin.test.xrUnfocused(90)
typed/builtin//modules/zinput/test/M/xrWorn
M.xrWorn(worn: boolean)
Take the simulated XR session's headset off (false) or put it on again
(true). Taken off, the session reports the headset not worn and stands in the
synchronized state, and the engine begins no frame of it: its own frames run at
their pace and no eyes are drawn. Worn again, the frame loop runs and the
session takes focus once a frame has ended. Takes effect on the session's next
poll. Native engines only.
Parameters
wornboolean— false takes the headset off, true puts it on again.
Zin.test.xrWorn(false)
typed/builtin//modules/zinput/touch/M/byId
M.byId(id: number) -> TouchPoint?
Look up an active contact by its finger id.
Parameters
idnumber— The platform finger id.
Returns TouchPoint? — The contact record, or nil.
local t = Zin.touch.byId(3)
typed/builtin//modules/zinput/touch/M/capable
M.capable() -> boolean
Whether the session has (or has declared) a touch input source.
Latched by a device's first contact, set at boot by platforms that
know up front, or declared by a script (input.simulateTouchCapable);
a contact a script simulates reads as one only while it is on the
glass.
Returns boolean — True when a touch source exists.
if Zin.touch.capable() then ... end
typed/builtin//modules/zinput/touch/M/count
M.count() -> number
Number of active touch contacts this frame.
Returns number — The contact count.
if Zin.touch.count() >= 2 then ... end
typed/builtin//modules/zinput/touch/M/off
M.off(handle: any?)
Unsubscribe a handle returned by any Zin.touch.on* function.
Parameters
handleany(optional) — The subscription handle.
Zin.touch.off(h)
typed/builtin//modules/zinput/touch/M/onBegan
M.onBegan(fn: (any, boolean) -> any, opts: any?)
Subscribe to touch-contact-begin events. fn(ev, gpe) where ev =
{ kind = "touch.down", id, x, y, pressure } and gpe is the UI-focus
flag at fire time. Return "sink" to consume. Returns an
Zin.events handle for off.
Parameters
fn(any, boolean) -> any— The callback.optsany(optional) — Optional { priority, context, once } (Zin.events.on opts).
Returns The subscription handle.
local h = Zin.touch.onBegan(function(ev) print(ev.id) end)
typed/builtin//modules/zinput/touch/M/onCancelled
M.onCancelled(fn: (any, boolean) -> any, opts: any?)
Subscribe to platform touch-cancel events ({ kind = "touch.cancel", id }).
Parameters
fn(any, boolean) -> any— The callback.optsany(optional) — Optional Zin.events.on opts.
Returns The subscription handle.
local h = Zin.touch.onCancelled(function(ev) ... end)
typed/builtin//modules/zinput/touch/M/onEnded
M.onEnded(fn: (any, boolean) -> any, opts: any?)
Subscribe to touch-lift events ({ kind = "touch.up", id, x, y }).
Parameters
fn(any, boolean) -> any— The callback.optsany(optional) — Optional Zin.events.on opts.
Returns The subscription handle.
local h = Zin.touch.onEnded(function(ev) ... end)
typed/builtin//modules/zinput/touch/M/onMoved
M.onMoved(fn: (any, boolean) -> any, opts: any?)
Subscribe to touch-move events ({ kind = "touch.move", id, x, y, dx, dy, pressure }).
Parameters
fn(any, boolean) -> any— The callback.optsany(optional) — Optional Zin.events.on opts.
Returns The subscription handle.
local h = Zin.touch.onMoved(function(ev) ... end)
typed/builtin//modules/zinput/touch/M/primary
M.primary() -> TouchPoint?
The primary contact (slot 0), if a finger is down.
Returns TouchPoint? — The primary contact record, or nil.
local p = Zin.touch.primary()
typed/builtin//modules/zinput/touch/M/slots
M.slots() -> { TouchPoint }
All active touch contacts this frame, in begin order. A contact's
x, y are in the scene viewport's physical pixels, measured from the
top-left of the rect the scene is drawn into: the space
Zin.state.get().mouse_position reads the pointer in, capture and
worldToScreen answer in and screenToRay takes.
Returns { TouchPoint } — Array of contact records (may be empty).
for _, t in ipairs(Zin.touch.slots()) do print(t.slot, t.x, t.y) end
typed/builtin//modules/zinput/touchControls/M/_advance
M._advance()
Internal: advance the touch-controls overlay one tick — route
this tick's raw touches into Zin.virtual and recompute layout
first, then auto-mount by Zin.surface.current() and repaint the
overlay if its draw state changed. Wired into Zin.tick, before
Zin.emulation._advance() (the floor consumes the Zin.virtual
state this routing produces).
Zin.touchControls._advance()
typed/builtin//modules/zinput/touchControls/M/_forceMount
M._forceMount(on: boolean)
Test-only: force the overlay to mount regardless of
Zin.surface.current() — for headless tests that want to exercise
rendering without a real touch surface. Touch routing itself is
always active regardless of this flag.
Parameters
onboolean— Whether to force-mount.
Zin.touchControls._forceMount(true)
typed/builtin//modules/zinput/touchControls/M/_onScreen
M._onScreen() -> boolean
Internal: whether the overlay is on screen. An overlay on screen is laid out and drawn from state no device event moves (the canvases, the language shown, the controls code subscribes to); each change of it while the overlay is on screen marks the input layer, so the overlay is drawn again on the tick that mark brings.
Returns boolean — true while the overlay is mounted.
if Zin.touchControls._onScreen() then ... end
typed/builtin//modules/zinput/touchControls/M/_reset
M._reset()
Test-only: unmount (withdrawing the rects the controls covered
from ui.safeArea().controls), clear all routing/layout state, drop
bespoke buttons, release every runtime control, close the fan, clear
the viewport override, and reset the force-mount flag. Registration
(ui.registerScreen) itself is not undone.
Zin.touchControls._reset()
typed/builtin//modules/zinput/touchControls/M/_setViewportOverride
M._setViewportOverride(w: number?, h: number?)
Test-only: override the logical screen size (ui.screenSize()
space) the layout budget/fan math uses, without resizing the real
window — for headless tests that need to prove budget math at a
phone-sized viewport. Pass nil for both to clear the override and
fall back to the real ui.screenSize().
Parameters
wnumber(optional) — Override width, or nil to clear.hnumber(optional) — Override height, or nil to clear.
Zin.touchControls._setViewportOverride(400, 800)
typed/builtin//modules/zinput/touchControls/M/_settled
M._settled() -> boolean
Internal: whether the overlay could change nothing on its next advance -- no live touch assignment, no open fan, mount state matching the surface, and (while mounted) no pending redraw, the layout's inputs unchanged, the faces read in the language now shown and the claimed regions stated where the controls are drawn. The tick's quiescence gate reads it. A redraw pending on an unmounted overlay is paid when it mounts, so it holds nothing awake until then.
Returns boolean — true when the overlay is at rest.
if Zin.touchControls._settled() then ... end
typed/builtin//modules/zinput/touchControls/M/_windowPoint
M._windowPoint(x: number, y: number) -> (number, number)
Internal: the window pixel a point of the layout is drawn at, in
the space a finger on the glass, input.simulateTouchDown and
Zin.test.touchStart take. Read from where the UI drew the overlay's
canvas, so it holds whether the scene fills the window or an editor's
Scene panel shows it, at any display density and render scale.
Parameters
xnumber— Layout x, in the pointslayout()reports.ynumber— Layout y, in the pointslayout()reports.
Returns (number, number) — The window pixel, as x, y.
local wx, wy = Zin.touchControls._windowPoint(entry.cx, entry.cy)
typed/builtin//modules/zinput/touchControls/M/addControl
M.addControl(opts: ControlOpts) -> number
Add a control while the world is running, and put its button on screen.
The control becomes an asset — a one-control .inputMap under
/source/runtimeControls/ — which is then activated and subscribed
to, which is what makes the overlay draw for it. It carries all three
device classes like any other control: give each of kbm / gamepad
a binding, or false plus reasons.<class> saying why it refuses
that device. touch defaults to an on-screen button for a button
control.
At least one handler is required. A control nothing listens to draws
no button, so an addControl with no handler would put nothing on
screen at all.
The control follows the context that added it: one a component adds is removed when that component instance goes (removed, hot-reloaded, or its entity despawned), one a module body adds at the module's next run.
Parameters
optsControlOpts—{ name, label?, kind?, kbm, gamepad, touch?, reasons?, button?, onInput?, onPressed?, onReleased?, onChanged? }.
Returns number — A handle for M.removeControl.
local h = Zin.touchControls.addControl({ name = "cast", label = "Cast", kbm = Zin.bindings.key("KeyF"), gamepad = Zin.bindings.padButton("north"), onPressed = function() print("cast") end })
typed/builtin//modules/zinput/touchControls/M/appearance
M.appearance() -> { [string]: any }
How the overlay is currently drawn - every appearance key with
the value in force, as a copy safe to hold and mutate. The keys are
the ones M.setAppearance accepts, and each button's own resolved
appearance is reported beside it on M.layout().
Returns { [string]: any } — { inset, gap, fill, stroke, strokeWidth, textColor, fontFamily, fontScale, iconFont, iconScale, sheetFill, sheetRounding, fanFill, fanStroke, stickStroke, stickFill, stickWidth }.
local inset = Zin.touchControls.appearance().inset
typed/builtin//modules/zinput/touchControls/M/button
M.button(opts: ButtonOpts) -> number
Add an overlay button. Two flavors:
{ action = "jump" }attaches an extra touchButton binding to an existing action on the active map — a second on-screen instance of a control the map already defines.{ emit = "KeyF", label = "Cast" }registers an overlay-only button: a syntheticemit:KeyFaction carrying both the kbm key binding and the touchButton, so the emulation floor drivesKeyFstraight from this button through the same binding/emulation path every other control uses.label/zone/iconset the button's presentation,placewhere it sits ("column", the default, or"corner"; seeZin.bindings.touchButton), and the appearance keysZin.bindings.touchButtontakes (fill,stroke,strokeWidth,textColor,fontFamily,fontScale,iconFont,iconScale) state this one button's look over the overlay's own; when neither label nor zone is given the button falls back to the action name (or the emit key).labeltakes text or ani18n.textvalue;idnames the button inZin.virtual, and a button whose label is read from a catalog and that states no id takes the action name (or the emit key) as its id.
Parameters
optsButtonOpts—{ action?, emit?, id?, label?, icon?, zone?, place?, fill?, stroke?, strokeWidth?, textColor?, fontFamily?, fontScale?, iconFont?, iconScale? }- exactly one ofaction/emitis required.
Returns number — A handle for M.removeButton.
local h = Zin.touchControls.button({ action = "jump" })
local h = Zin.touchControls.button({ emit = "KeyF", label = "Cast" })
typed/builtin//modules/zinput/touchControls/M/claimed
M.claimed() -> { number }
The contact ids currently claimed by the stick, a button, or the drag zone.
Returns { number } — A sorted array of claimed touch contact ids.
local ids = Zin.touchControls.claimed()
typed/builtin//modules/zinput/touchControls/M/controls
M.controls() -> { any }
Every control M.addControl currently holds, as
{ handle, name, path } in the order they were added.
Returns { any } — Array of runtime-control records.
for _, c in ipairs(Zin.touchControls.controls()) do print(c.name) end
typed/builtin//modules/zinput/touchControls/M/layout
M.layout() -> any
The overlay's current control layout — a copy, safe to hold and
mutate. buttons is the budgeted, VISIBLE stack in draw order, the
corner row after the column
(each entry { id, label, icon, actionName, priority, size, appliedSize, group, place, style, cx, cy, radius } in ui.screenSize()
space - id is the button's identity in Zin.virtual and the name
Zin.test.tapTouchButton takes, actionName the control it works,
label the words on it in the player's language, size is the step the binding declared and appliedSize
the one radius came from, which differ only where a rich scheme's
step-down moved a button one size down; place is "column" for the
action column at the bottom-right or "corner" for the row in the
top-right corner, the place a world's own drawn controls keep clear
of; icon is the glyph the
circle draws in place of its label, and style the appearance it
resolved to out of its own keys and M.appearance()); fan is nil unless the
button set exceeded the two-column budget, in which case it's
{ open, cx, cy, radius, buttons, yieldedTo } — open is whether the
overflow sheet is currently expanded, buttons the overflowed
entries at their sheet positions (tappable only while open).
yielded lists the laid-out buttons a game screen's widget
answering a press lies over, in the same shape plus yieldedTo = { widget, screen }
naming that widget: a press on their circle reaches the widget, until
it goes. A column button is drawn nowhere meanwhile; a "corner" button
is drawn dimmed and carries holdSeconds, the time a contact held still
on the widget takes to press it, holdFingers, how many contacts held
still together at its centre press it (2 where the widget there takes a
held or dragged press, as ui.hitTestRegions states it, and 1 elsewhere),
and freeAtCentre, true while no widget answering a press is in a press's
reach of its centre, so a tap there presses it. The fan and a sheet entry
carry yieldedTo the same way while one lies over them.
stick / drag name the axis + virtual zone each region feeds,
and pinch the axis the two-finger recognizer feeds, each nil when
the active map defines none in the current context. safe is the
rect every control keeps inside: the part of the overlay no system
bar, display cutout or on-screen keyboard covers (ui.safeArea()),
in the same space.
The reading answers for the same instant Zin.scheme.bindings()
does: activating or standing down a map, subscribing a control,
changing context or resizing the screen is reflected by the next
read, in the call that made the change. Empty until a screen size
has resolved. Backs custom control-placement UI and headless tests
that need a button's (or the fan's) center to aim a simulated
touch at.
Returns any — { buttons, yielded, fan?, stick?, drag?, pinch?, width, height, safe = { x, y, width, height } }.
local jumpBtn = Zin.touchControls.layout().buttons[1]
typed/builtin//modules/zinput/touchControls/M/primaryClaimed
M.primaryClaimed() -> boolean
Whether the touch contact driving the pointer (the one
Zin.state.get().pointer_contact names, a contact simulated for the
game alone included) is currently claimed by an on-screen control.
The engine projects the contact driving the pointer onto the mouse so pointer UI works from a finger. A contact that begins on a drawn button, the fan or an open sheet entry is that control's alone and is not projected; one that begins on the movement stick or the look area is, until the UI has decided its press, and so for those frames it also reads as a held left mouse button, which fires every control bound to one. Once the UI leaves its press the contact lets the pointer go, and a finger landing on bare scene meanwhile drives it as a press of the player's own.
A mouse binding means the player pressed a mouse button, and a finger
an on-screen control has claimed is not that. Zin.bindings consults
this so a thumb on the stick does not fire an unrelated control.
Returns boolean — True while an on-screen control owns the contact driving the pointer.
if not Zin.touchControls.primaryClaimed() then ... end
typed/builtin//modules/zinput/touchControls/M/removeButton
M.removeButton(handle: number) -> boolean
Remove a button previously added via M.button.
Parameters
handlenumber— The handle returned byM.button.
Returns boolean — Whether a button was actually removed.
Zin.touchControls.removeButton(h)
typed/builtin//modules/zinput/touchControls/M/removeControl
M.removeControl(handle: number) -> boolean
Release a control added by M.addControl — drop its
subscriptions and release its map, which takes it off the screen and
out of the live set. The asset it was written to stays, so the same
name can be added again and comes back with the same guid.
Parameters
handlenumber— The handle returned byM.addControl.
Returns boolean — Whether a control was actually released.
Zin.touchControls.removeControl(h)
typed/builtin//modules/zinput/touchControls/M/setAppearance
M.setAppearance(opts: { [string]: any }?)
State how the overlay is drawn. Every value a world passes replaces the engine's for as long as the world runs, so a game that typesets its own interface puts the controls the engine draws in the same faces, colours and margins as the rest of it.
The keys, and what each decides:
inset/gap- the margin the button column keeps from the right and bottom edges of the safe area (ui.safeArea(): the screen less its system bars and display cutouts), and the space between two buttons. A game laying its interface out inside a margin of its own states that margin here and the controls keep it too.fill/stroke/strokeWidth- every button's circle.textColor/fontFamily/fontScale- the label on it.fontFamilytakes the liststyle.fontFamilytakes andui.listFonts()names;fontScaleis the share of the button's radius the label is set at.iconFont/iconScale- the same two for a button that declared aniconglyph.sheetFill/sheetRounding- the overflow sheet behind the fan.fanFill/fanStroke- the fan's own circle.stickStroke/stickFill/stickWidth- the movement stick's ring and thumb.
A call states only the keys it carries and leaves the rest as they stand, so appearance composes across several calls. Passing nothing puts every value back to the engine's own.
A single button states any of the button keys for itself through
Zin.bindings.touchButton, which wins over what is set here.
Parameters
opts{ [string]: any }(optional) — A table of appearance keys, or nil to restore the defaults.
Zin.touchControls.setAppearance({ fill = "#10243a", stroke = "#c9a227", textColor = "#f2e6c8", fontFamily = "Inter", inset = 38 })
Zin.touchControls.setAppearance()
typed/builtin//modules/zinput/utils/M/applyCurve
M.applyCurve(curve: (string | (number) -> number)?, x: number) -> number
Apply a response curve to a reading. "linear" (and no curve at
all) is the identity, "quadratic" squares while keeping the sign,
"cubic" cubes, and a function is called with the reading. A function
that raises, or answers with anything other than a number, leaves the
reading as it was.
Parameters
curve(string | (number) -> number)(optional) —"linear"|"quadratic"|"cubic"| a function of the reading.xnumber— The reading to shape.
Returns number — The shaped reading.
Utils.applyCurve("quadratic", -0.5) -- → -0.25
typed/builtin//modules/zinput/utils/M/applyDeadzoneScalar
M.applyDeadzoneScalar(x: number, deadzone: number?) -> number
Apply a scalar deadzone: a magnitude below the threshold reads 0, anything at or above it passes through untouched.
Parameters
xnumber— The reading.deadzonenumber(optional) — The threshold;nilapplies none.
Returns number — The reading, or 0 inside the deadzone.
Utils.applyDeadzoneScalar(0.04, 0.1) -- → 0
typed/builtin//modules/zinput/utils/M/applyDeadzoneVector
M.applyDeadzoneVector(v: Vector2, deadzone: number?) -> Vector2
Apply a radial deadzone to a pair: the MAGNITUDE of the pair is
what the threshold is measured against, so a diagonal held past it
keeps both components and a stick resting inside it reads {0, 0}.
Parameters
vVector2— The reading, as{ x, y }.deadzonenumber(optional) — The threshold;nilapplies none.
Returns Vector2 — A fresh pair — the reading, or {0, 0} inside the deadzone.
Utils.applyDeadzoneVector({ x = 0.05, y = 0.05 }, 0.2) -- → { x = 0, y = 0 }
typed/builtin//modules/zinput/utils/M/buttonIndex
M.buttonIndex(name: string) -> number?
Convert a mouse button name to its 0-based index.
Parameters
namestring— Mouse button name ("left"/"right"/"middle").
Returns number? — The button index, or nil for unknown names.
Utils.buttonIndex("right") -- → 1
typed/builtin//modules/zinput/utils/M/buttonName
M.buttonName(idx: number) -> string?
Convert a 0-based mouse button index to its name.
Parameters
idxnumber— Mouse button index (0=left, 1=right, 2=middle).
Returns string? — The button name ("left"/"right"/"middle") or nil for out-of-range indices.
Utils.buttonName(0) -- → "left"
typed/builtin//modules/zinput/utils/M/keyFields
M.keyFields(surface: string?) -> KeyFields
The snapshot fields that carry a surface's keys: held, pressed
and released. surface is "scene" (the default), the keys pressed
while the scene was the active input context, or "editor", every key
no focused widget took.
Parameters
surfacestring(optional) —"scene"or"editor"; nil reads as"scene".
Returns KeyFields — { held, pressed, released } field names.
local f = Utils.keyFields("editor"); local held = snap[f.held]
typed/builtin//modules/zinput/utils/M/matchModifiers
M.matchModifiers(snapshot: any?, mods: Modifiers, surface: string?) -> boolean
Check whether the current frame's snapshot has the given modifiers
held. Pass any subset of { ctrl, shift, alt }; unspecified keys are
not checked. Returns false if snapshot is not a table — callers
can forward Zin.state.get() directly without nil-checking first.
Parameters
snapshotany(optional) — The frame snapshot table (fromZin.state.get()), or any non-table value (treated as "no modifiers held").modsModifiers— Subset of{ ctrl, shift, alt }booleans to require.surfacestring(optional) — Whose keys to read:"scene"(the default) or"editor".
Returns boolean — true when every specified modifier matches the held state.
Utils.matchModifiers(snap, { ctrl = true })
typed/builtin//modules/zinput/utils/M/normalizeKey
M.normalizeKey(code: string) -> string
Normalize a key code to the engine's canonical web-style form — the
KeyboardEvent.code vocabulary the input map and Zin.state.get().keys
use ("KeyW", "Space", "ArrowUp", "ShiftLeft", …). A single ASCII
letter is promoted to its Key<L> code and a single digit to its
Digit<N> code, so the common shorthand "W" resolves to the "KeyW"
the default map binds instead of a phantom key nothing consumes. Any
other single character is rejected — no bound key code is one character
long. Multi-character codes pass through unchanged.
Parameters
codestring— The raw key code ("KeyW") or a single-letter/digit shorthand ("w").
Returns string — The canonical key code.
Utils.normalizeKey("w") -- → "KeyW"
Utils.normalizeKey("KeyW") -- → "KeyW"
typed/builtin//modules/zinput/utils/M/resolveButtonIndex
M.resolveButtonIndex(button: (number | string)?) -> number
Resolve a mouse button given as a 0-based index OR a
case-insensitive name ("left"/"right"/"middle", the same names
Zin.bindings.mouse takes) to its 0-based index. nil resolves to
left (0). Raises on an unknown name so a typo is loud, not a silent
left-click — the single coercion every input surface that accepts a
button uses so index and name mean the same thing everywhere.
Parameters
button(number | string)(optional) — Button index, name, or nil.
Returns number — The 0-based button index.
Utils.resolveButtonIndex("Right") -- → 1
Utils.resolveButtonIndex(2) -- → 2
typed/builtin//modules/zinput/utils/M/shapeScalar
M.shapeScalar(x: number, deadzone: number?, curve: (string | (number) -> number)?, invert: boolean?) -> number
The whole shaping of a scalar reading: deadzone, then curve, then inversion.
Parameters
xnumber— The reading.deadzonenumber(optional) — Magnitude below which the reading is 0;nilapplies none.curve(string | (number) -> number)(optional) —"linear"|"quadratic"|"cubic"| a function;nilis linear.invertboolean(optional) — Negate the shaped reading.
Returns number — The shaped reading.
Utils.shapeScalar(0.5, 0.1, "quadratic", true) -- → -0.25
typed/builtin//modules/zinput/utils/M/shapeStick
M.shapeStick(v: Vector2, deadzone: number?, curve: (string | (number) -> number)?) -> Vector2
The pair a stick reports, shaped on its magnitude: a magnitude at
or under deadzone reads {0, 0}, the travel past it is stretched
over 0..1 and bent by curve, and the direction the stick points in
is kept. The magnitude is held to 1.
Parameters
vVector2— The deflection, as{ x, y }.deadzonenumber(optional) — The magnitude a stick at rest may report, 0..1;nilor 0 applies none.curve(string | (number) -> number)(optional) —"linear"|"quadratic"|"cubic"| a function of the 0..1 travel;nilis linear.
Returns Vector2 — A fresh, shaped pair.
Utils.shapeStick({ x = 0.03, y = 0.02 }, 0.15) -- → { x = 0, y = 0 }
Utils.shapeStick({ x = 1, y = 0 }, 0.15, "quadratic") -- → { x = 1, y = 0 }
typed/builtin//modules/zinput/utils/M/shapeStickScalar
M.shapeStickScalar(x: number, deadzone: number?, curve: (string | (number) -> number)?) -> number
The deflection a stick reports, past a scaled dead zone and through
a response curve: a magnitude at or under deadzone reads 0, the
travel from deadzone to full deflection is stretched over 0..1, and
curve bends it. The sign is kept and the magnitude is held to 1.
Parameters
xnumber— The deflection, -1..1.deadzonenumber(optional) — The magnitude a stick at rest may report, 0..1;nilor 0 applies none.curve(string | (number) -> number)(optional) —"linear"|"quadratic"|"cubic"| a function of the 0..1 travel;nilis linear.
Returns number — The shaped deflection, -1..1.
Utils.shapeStickScalar(0.04, 0.15) -- → 0
Utils.shapeStickScalar(-0.575, 0.15, "quadratic") -- → -0.25
typed/builtin//modules/zinput/utils/M/shapeVector
M.shapeVector(v: Vector2, deadzone: number?, curve: (string | (number) -> number)?, invert: boolean?) -> Vector2
The whole shaping of a pair: radial deadzone, then the curve on each component, then inversion of both.
Parameters
vVector2— The reading, as{ x, y }.deadzonenumber(optional) — Magnitude of the pair below which it reads{0, 0};nilapplies none.curve(string | (number) -> number)(optional) —"linear"|"quadratic"|"cubic"| a function;nilis linear.invertboolean(optional) — Negate both components.
Returns Vector2 — A fresh, shaped pair.
Utils.shapeVector({ x = 1, y = 0 }, 0.2, "linear", true) -- → { x = -1, y = 0 }
typed/builtin//modules/zinput/utils/M/smoothToward
M.smoothToward(current: number, target: number, dt: number, tau: number) -> number
One step of an exponential approach toward a target: tau is the
time constant in seconds, and the step covers dt of it. A tau of 0
or less arrives immediately; a dt of 0 or less stays put.
Parameters
currentnumber— Where the value is now.targetnumber— Where it is heading.dtnumber— Seconds this step covers.taunumber— The time constant, in seconds.
Returns number — The value after the step.
Utils.smoothToward(0, 1, 0.05, 0.2) -- → ~0.221
typed/builtin//modules/zinput/virtual/M/_beginFrame
M._beginFrame()
Internal: frame boundary — shift button edges, clear drag deltas. Called by the Zin.tick coordinator on the first tick of each engine frame.
Zin.virtual._beginFrame()
typed/builtin//modules/zinput/virtual/M/_reset
M._reset()
Test-only: clear all virtual state.
Zin.virtual._reset()
typed/builtin//modules/zinput/virtual/M/_settled
M._settled() -> boolean
Internal: whether every virtual control sits at rest -- sticks centred, buttons up (this frame and last), drag deltas empty. The tick's quiescence gate reads it.
Returns boolean — true when the virtual layer is producing nothing.
if Zin.virtual._settled() then ... end
typed/builtin//modules/zinput/virtual/M/addDrag
M.addDrag(zone: string, dx: number, dy: number)
Accumulate a drag delta for a zone this tick (cleared at the next frame boundary, like the mouse delta).
Parameters
zonestring— The drag zone id.dxnumber— Delta X in px.dynumber— Delta Y in px.
Zin.virtual.addDrag("right", 4, -2)
typed/builtin//modules/zinput/virtual/M/button
M.button(id: string) -> boolean
A virtual button's held state.
Parameters
idstring— The button id.
Returns boolean — True while held.
if Zin.virtual.button("Jump") then ... end
typed/builtin//modules/zinput/virtual/M/buttonPressed
M.buttonPressed(id: string) -> boolean
Whether a virtual button was pressed this frame (held now, not held at the previous frame boundary).
Parameters
idstring— The button id.
Returns boolean — True on the press frame.
if Zin.virtual.buttonPressed("Jump") then ... end
typed/builtin//modules/zinput/virtual/M/buttonReleased
M.buttonReleased(id: string) -> boolean
Whether a virtual button was released this frame.
Parameters
idstring— The button id.
Returns boolean — True on the release frame.
if Zin.virtual.buttonReleased("Jump") then ... end
typed/builtin//modules/zinput/virtual/M/drag
M.drag(zone: string) -> (number, number)
A zone's accumulated drag delta this frame.
Parameters
zonestring— The drag zone id.
Returns (number, number) — dx, dy.
local dx, dy = Zin.virtual.drag("right")
typed/builtin//modules/zinput/virtual/M/setButton
M.setButton(id: string, held: boolean)
Set a virtual button's held state. Edges (pressed/released) are derived at the frame boundary.
Parameters
idstring— The button id (a touchButton'sid, else its label, else its zone).heldboolean— Whether the button is down.
Zin.virtual.setButton("Jump", true)
typed/builtin//modules/zinput/virtual/M/setStick
M.setStick(zone: string, x: number, y: number)
Set a virtual stick's normalized vector (each component -1..1; values are clamped). Persists until set again or reset.
Parameters
zonestring— The stick's zone id.xnumber— Stick X (right positive).ynumber— Stick Y (down positive, matching screen deltas).
Zin.virtual.setStick("left", 0.4, -0.9)
typed/builtin//modules/zinput/virtual/M/stick
M.stick(zone: string) -> (number, number)
A virtual stick's current vector ({x=0,y=0} when unset).
Parameters
zonestring— The stick's zone id.
Returns (number, number) — x, y components.
local x, y = Zin.virtual.stick("left")
typed/builtin//systems/anim/AnimGraph/AnimGraph/bindSink
AnimGraph.bindSink(body: EntityRef)
Bind a pose sink targeting body's armature, stored on the graph so
:tick(dt) applies the evaluated pose to it. The bone order is the graph's
layout. Re-binding replaces any prior sink. A layout of blend shapes alone
binds no armature: :tick writes its shapes to the meshes the layout names.
Raises when the sink cannot be bound (the body has no Skeleton + Model when
the sink is created).
Parameters
bodyEntityRef— The EntityRef whose bones the graph drives (carries the Skeleton).
graph:bindSink(skinnedBody)
typed/builtin//systems/anim/AnimGraph/AnimGraph/crossfadeTo
AnimGraph.crossfadeTo(toNode: any?, duration: number, removeFromOnDone: boolean?)
Crossfade from the current output to toNode over duration seconds.
Inserts a 2-input Mixer over the previous output and the new node and ramps
weights from (1, 0) to (0, 1); on completion the output collapses to
toNode. Falls back to an instant swap when there is no active output or
duration <= 0 (the old output is freed unless removeFromOnDone is false).
Parameters
toNodeany(optional) — Target node (already constructed).durationnumber— Fade time in seconds (≥ 0).removeFromOnDoneboolean(optional) — When true (default), free the old output when the fade completes.
graph:crossfadeTo(runClip, 0.25)
typed/builtin//systems/anim/AnimGraph/AnimGraph/destroy
AnimGraph.destroy()
Free the whole graph: cascade-destroy() the output subtree, unbind the
pose sink, return every blend shape the graph was covering to its rest
weight, and clear any active crossfade.
graph:destroy()
typed/builtin//systems/anim/AnimGraph/AnimGraph/evaluate
AnimGraph.evaluate() -> any?
Evaluate the output subtree and return its pose buffer. Returns nil when there is no output.
Returns any? — Pose buffer handle (caller MUST NOT destroy), or nil.
local pose = graph:evaluate()
typed/builtin//systems/anim/AnimGraph/AnimGraph/layoutForEntity
AnimGraph.layoutForEntity(body: EntityRef, opts: { [string]: any }?) -> Layout
Build the layout for a graph that drives a body. Resolves the body's rig
from its ecs.Skeleton and packs everything Clip nodes need to retarget
clips onto it and apply poses relative to its rest: boneOrder, the parsed
targetRig, its stride-10 restPose, and the bake-cache key. It adds the
blend shapes of the meshes around the body (shapesUnder from the body's
parent, or from opts.shapeRoot), so a clip's weight tracks reach the face.
A body with blend shapes and no rigged Skeleton (a morph mesh with no skin)
gets a layout of its shapes alone. Raises when body has neither; call it
on a body you intend to animate, after its skeleton and mesh are hydrated.
Parameters
bodyEntityRef— The EntityRef of the body to drive (carries a Skeleton with a rig, or a mesh with blend shapes).opts{ [string]: any }(optional) — Optional{ shapeRoot: string?, shapeAliases: { [string]: { string } }? }.
Returns Layout — A Layout for AnimGraph.new + Clip.new.
local layout = AnimGraph.layoutForEntity(skinnedBody)
typed/builtin//systems/anim/AnimGraph/AnimGraph/new
AnimGraph.new(layout: Layout, driver: string?) -> AnimGraph
Construct an empty AnimGraph with no output. :setOutput names the root
node the graph drives; :bindSink binds the body the pose is applied to.
Parameters
layoutLayout—{ boneOrder, stride?, slotLayout? }— the skeleton layout shared by every node in the graph.driverstring(optional) — A name for whatever owns this graph — the component, tool or system an author would recognise.:tickpublishes it, so it is whatanimation.body(...).drivernames for the body this graph poses.
Returns AnimGraph — The new AnimGraph instance.
local g = AnimGraph.new(AnimGraph.layoutForEntity(body), "Locomotion")
typed/builtin//systems/anim/AnimGraph/AnimGraph/play
AnimGraph.play()
Start the graph's per-frame update loop. Equivalent to :setPlaying(true).
graph:play()
typed/builtin//systems/anim/AnimGraph/AnimGraph/publish
AnimGraph.publish(driver: string?)
Publish what this graph is running on the body it drives, so the
engine's animation observation names the clips, their playheads and their
retarget coverage beside the pose it measures. :tick calls this every
frame; call it directly when advancing a graph by hand. It declares only
what changed since the graph last declared: each clip's playhead reaches
the observation through the sampler that samples it, and every sample
keeps the declaration current, so a graph playing steadily declares
nothing. A graph with no clip, or with a clip that has no sampler yet (a
retarget still baking), declares on every publish, and a graph declares
again once another graph declared over it or forgot the body.
Parameters
driverstring(optional) — A name for whatever owns this graph, shown as the body's driver.
graph:publish("Locomotion")
typed/builtin//systems/anim/AnimGraph/AnimGraph/runNatively
AnimGraph.runNatively(opts: NativeOptions?) -> (number?, string?)
Hand the graph to the engine, which then advances and evaluates it every
frame and applies its pose in place of :tick, with no script running for
it. The engine runs the graph's Clip, Mixer and BlendSpace2D nodes, from the
playheads and parameters they hold now, to the pose the script nodes give
for the same inputs. A stopped graph stays stopped: the engine applies the
pose its playheads stand at once, and while they stand still it writes no
new pose, keeps that pose on the bones (putting back any bone another writer
moved off it) and keeps declaring the graph. opts.locomotion sets a blend space's
parameters each frame from the movement of a root, as the Locomotion
component does:
{ blendSpace, root, anchor, forward, turnRate, moveDeadzone, smoothTime, teleportSpeed, dampedSpeed, dampedAngle, sampleFrame, samplePosition, recentVelocities, velocityX, velocityZ, velocityUp?, recentUp?, air? }.
air blends the body's air states through a Mixer of the graph:
{ mixer, ground, jump?, fall?, land?, footprint, groundGap, fallSpeed, riseSpeed, blendTime, landTime, state?, stateTime?, weights? },
each node one of the graph's (the ground, take-off, fall and landing poses,
inputs of mixer); the engine sweeps the root's footprint for the ground
under it every frame.
opts.holds names the component instance whose update the engine runs in
place of: it is held while the engine runs the graph and runs again from the
frame the engine stops. Any change to the graph through its methods
(:setOutput, :crossfadeTo, :bindSink, :play or :stop when they
change whether it plays, :tick, :destroy) takes it back first, its
playheads where the engine left them.
Parameters
optsNativeOptions(optional) —{ locomotion?, holds? }.
Returns (number?, string?) — The program handle, or nil and why the graph runs in script (a node of another kind, a clip still binding or driving blend shapes, a crossfade under way, no pose sink).
local h, why = graph:runNatively({ holds = public.instanceId })
typed/builtin//systems/anim/AnimGraph/AnimGraph/setOutput
AnimGraph.setOutput(node: any?)
Name the node the graph drives. The node and the subtree it owns become
the graph's output; :update / :evaluate / :destroy cascade from here.
Replacing the output does NOT free the old one — detach or destroy it first
if it is no longer used.
Parameters
nodeany(optional) — The root node (any Clip / Mixer / BlendSpace2D).
graph:setOutput(blendSpace)
typed/builtin//systems/anim/AnimGraph/AnimGraph/setPlaying
AnimGraph.setPlaying(p: boolean)
Set the playing flag explicitly. true resumes per-frame updates;
false freezes them.
Parameters
pboolean— Whether the graph should run per-frame updates.
graph:setPlaying(false)
typed/builtin//systems/anim/AnimGraph/AnimGraph/state
AnimGraph.state() -> { [string]: any }
Snapshot of graph state — handy for tools and debugging. Walks the
output subtree; no internal references are leaked. While the engine runs the
graph (:runNatively) the playheads are the engine's, and native names its
program and the frames it has run.
Returns { [string]: any } — { playing, crossfade?, native?, output = { kind, time, duration, playing, finished, children? } }.
local snap = graph:state()
typed/builtin//systems/anim/AnimGraph/AnimGraph/stop
AnimGraph.stop()
Stop the graph's per-frame update loop. Equivalent to :setPlaying(false).
graph:stop()
typed/builtin//systems/anim/AnimGraph/AnimGraph/stopNatively
AnimGraph.stopNatively() -> { [string]: any }?
Take the graph back from the engine: its playheads and its mixers'
weights move to where the engine left them and :tick drives it again. The engine's last state, or nil
when the engine was not running it (or had stopped it: a body, root or
anchor that left the world). The state is also kept as nativeLast, for the
component the engine ran it for when another caller took the graph back.
Returns { [string]: any }? — { frames, clips, mixers, dampedSpeed?, dampedAngle?, velocityX?, velocityZ?, recentVelocities?, velocityUp?, recentUp?, sampleFrame?, samplePosition?, air? }, or nil; air is { state, stateTime, weights }.
local last = graph:stopNatively()
typed/builtin//systems/anim/AnimGraph/AnimGraph/tick
AnimGraph.tick(dt: number, sink: any?) -> any?
One-call per-frame driver. Advances the graph + crossfade by dt,
evaluates the output, and (when a sink is bound or passed) hands the pose
buffer to skeleton.applyPose, then writes the blend shapes the pose covers
into the body's meshes (:applyShapes). Returns the pose buffer so callers can read
it directly (e.g. screenshot tests). While the output is pending (a clip's
retarget is baking) nothing is applied, so the body holds the pose it has,
and nil is returned.
The engine decides how often each body is evaluated from what the views
see of it (animation.poseDue, animation.poseRate). On a frame the bound
body is not due, a tick through the bound sink evaluates nothing, applies
nothing and returns nil: the body holds its pose, and the frame's dt is
carried into the next tick that evaluates, so the pose it then shows is
the one it would have had.
Parameters
dtnumber— Seconds to advance.sinkany(optional) — A SinkHandle fromskeleton.bindPose. Omitted, the sink bound via:bindSinkis used; passfalseto advance without applying.
Returns any? — The pose buffer handle, or nil when there is no output.
graph:bindSink(skinnedId); graph:tick(dt)
typed/builtin//systems/anim/AnimGraph/AnimGraph/update
AnimGraph.update(dt: number)
Advance the output subtree and the active crossfade by dt. No-op when
the graph is not playing. When a crossfade reaches the end the output
collapses to the target node and the crossfade mixer (plus, by default, the
faded-out source) is freed.
Parameters
dtnumber— Seconds to advance.
graph:update(1 / 60)
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/clear
Additive.clear()
Drop every offset and every held shape: the base passes through.
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/destroy
Additive.destroy()
Cascade-destroy() the base, then free this node's output buffer. A base
detached (set to nil) is skipped.
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/evaluate
Additive.evaluate() -> any
Evaluate the base (or take the rest pose) and add the offsets into the output buffer. With no offsets the base buffer is returned as it is.
Returns any — Owned pose buffer handle. Caller must NOT destroy.
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/has
Additive.has(bone: string) -> boolean
Whether the layout drives a bone of this name.
Parameters
bonestring— The bone's name.
Returns boolean — True when the bone is in the layout's bone order.
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/new
Additive.new(layout: Layout, base: any?) -> any
Construct an Additive Node over base (or over the layout's rest pose when
base is nil). Allocates an output pose buffer.
Parameters
layoutLayout— Layout descriptor:boneOrderrequired,stridedefaults to 10.baseany(optional) — The base Node, or nil to add to the layout'srestPose.
Returns any — The constructed Additive node.
local add = Additive.new(graph.layout, graph.output)
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/pending
Additive.pending() -> boolean
Whether the base is still waiting on work it needs to produce a pose.
Returns boolean — Whether the node is pending.
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/setPosition
Additive.setPosition(bone: string, p: { number }?) -> boolean
Move bone by p (metres, its parent's frame) on top of the base, or stop
moving it with nil.
Parameters
bonestring— The bone's name.p{ number }(optional) — The offset{ x, y, z }, or nil.
Returns boolean — False for a bone the layout does not drive.
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/setRotation
Additive.setRotation(bone: string, q: { number }?) -> boolean
Turn bone by q in its own frame on top of the base, or stop turning it
with nil.
Parameters
bonestring— The bone's name.q{ number }(optional) — The rotation{ x, y, z, w }, or nil.
Returns boolean — False for a bone the layout does not drive.
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/setShape
Additive.setShape(name: string, weight: number?) -> boolean
Hold the blend shape name at weight over whatever the base gives it, or
hand it back to the base with nil.
Parameters
namestring— The shape's name, or an alias the layout carries for it.weightnumber(optional) — The weight, or nil.
Returns boolean — False for a shape the layout does not carry.
add:setShape("eyeBlink", 1)
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/shapeIndex
Additive.shapeIndex(name: string) -> number?
The layout's index of the blend shape name addresses: by the shape's own
name, then by an alias, then ignoring case, spaces and separators.
Parameters
namestring— A shape name or alias.
Returns number? — The 1-based shape index, or nil.
typed/builtin//systems/anim/AnimGraph/Node/Additive/Additive/update
Additive.update(dt: number)
Advance the base.
Parameters
dtnumber— Frame delta time in seconds.
typed/builtin//systems/anim/AnimGraph/Node/BlendSpace2D/BlendSpace2D/destroy
BlendSpace2D.destroy()
Destroy the internal Mixer — which cascade-destroy()s the sample
sources it holds — then clear sample/triangle state. Destroying a
BlendSpace2D frees the subtree below it, same as any composite node.
bs:destroy()
typed/builtin//systems/anim/AnimGraph/Node/BlendSpace2D/BlendSpace2D/evaluate
BlendSpace2D.evaluate() -> any
Weight the samples at the current parameter (see weightsAt), push
the weights into the internal Mixer and evaluate it.
Returns any — Owned pose buffer handle (provided by the internal Mixer). Caller must NOT destroy.
local pose = bs:evaluate()
typed/builtin//systems/anim/AnimGraph/Node/BlendSpace2D/BlendSpace2D/new
BlendSpace2D.new(layout: Layout, samples: { Sample }) -> any
Construct a BlendSpace2D Node. Triangulates the sample anchors once at construction time and reuses an internal Mixer to do the per-frame barycentric weighted blend.
Parameters
layoutLayout— Layout descriptor —boneOrderis required,stridedefaults to 10,slotLayoutis passed through to the internal Mixer.samples{ Sample }— Array of{ x, y, source }entries —sourceis any Node.
Returns any — The constructed BlendSpace2D node.
local bs = BlendSpace2D.new(layout, { { x=0, y=0, source=idle }, { x=1, y=0, source=walk } })
typed/builtin//systems/anim/AnimGraph/Node/BlendSpace2D/BlendSpace2D/pending
BlendSpace2D.pending() -> boolean
Whether any sample is still waiting on work it needs to produce a pose. The parameters pick the weights each evaluation, so every sample counts.
Returns boolean — Whether the blend space is pending.
if bs:pending() then return end
typed/builtin//systems/anim/AnimGraph/Node/BlendSpace2D/BlendSpace2D/place
BlendSpace2D.place(i: number, x: number, y: number)
Move sample i to (x, y) and triangulate the samples again, as when the
speed a clip carries its body at is known only once its retarget bake lands.
Parameters
inumber— The sample's index, in the ordernewwas given them.xnumber— The sample's new X.ynumber— The sample's new Y.
bs:place(2, 0, walk:travelSpeed() * bodyScale)
typed/builtin//systems/anim/AnimGraph/Node/BlendSpace2D/BlendSpace2D/setParams
BlendSpace2D.setParams(x: number, y: number)
Set the (x, y) parameter that drives the blend.
Parameters
xnumber— Parameter X.ynumber— Parameter Y.
bs:setParams(0.5, 0.3)
typed/builtin//systems/anim/AnimGraph/Node/BlendSpace2D/BlendSpace2D/update
BlendSpace2D.update(dt: number)
Cascade update(dt) to every sample source that defines it.
Parameters
dtnumber— Frame delta time in seconds.
bs:update(dt)
typed/builtin//systems/anim/AnimGraph/Node/BlendSpace2D/BlendSpace2D/weightsAt
BlendSpace2D.weightsAt(x: number, y: number) -> { number }
The weight each sample takes at (x, y): the barycentric weights of
the triangle holding it, the two samples of the nearest edge of the
triangulation outside the hull, or the nearest sample alone when the
samples form no triangle. The weights sum to 1.
Parameters
xnumber— Parameter X.ynumber— Parameter Y.
Returns { number } — One weight per sample, in the order new was given them.
local w = bs:weightsAt(45, 2)
typed/builtin//systems/anim/AnimGraph/Node/Clip/Clip/destroy
Clip.destroy()
Free the bound clip sampler and the owned pose buffer.
clip:destroy()
typed/builtin//systems/anim/AnimGraph/Node/Clip/Clip/evaluate
Clip.evaluate() -> any
Sample the clip at the current playhead. With a body layout, returns a COMPLETE local pose: the body's bind, with every driven bone's rotation and translation overlaid — translation applied relative to the bind (rest plus the clip's displacement from its own start). Without a body layout, returns the raw sample. A layout with blend shapes gets each shape's weight and coverage after the bones. The sampler writes the pose straight into the node's buffer.
Returns any — Owned pose buffer handle. Caller must NOT destroy — the Clip owns it.
local pose = clip:evaluate()
typed/builtin//systems/anim/AnimGraph/Node/Clip/Clip/new
Clip.new(clipRef: any?, layout: Layout, looping: boolean, speed: number?, sourceRig: any?) -> (any, string?)
Construct a Clip Node from a .animation asset reference. Reads the
clip bytes and, when the layout carries a body, starts retargeting them onto
the layout's target rig (or takes the bake an earlier node on the same rig
landed). Until the bake lands the node is pending: it holds its playhead
and evaluates to nothing, so the graph leaves the body's pose where it is.
Once bound, it records which bones the clip drives so evaluate overlays
only those on the rest pose; matched == 0 (the clip drives none of these
bones) is logged so a silent rest pose never goes unexplained.
Parameters
clipRefany(optional) — Asset identity string or AssetRef for the.animation.layoutLayout— Layout descriptor —boneOrderis required;stridedefaults to 10.loopingboolean— When true the playhead wraps atduration; otherwise it clamps and marks the clipfinished.speednumber(optional) — Playback rate multiplier (defaults to 1).sourceRigany(optional) — Optional explicit.rigref overriding the clip's recorded source rig.
Returns (any, string?) — The constructed Clip node, or nil + error message when the clip cannot be read.
local clip = Clip.new(clipRef, layout, true, 1.0)
typed/builtin//systems/anim/AnimGraph/Node/Clip/Clip/pending
Clip.pending() -> boolean
Whether the clip is still waiting on its retarget bake. Advances the bake,
and binds the retargeted clip the frame it lands. A bake that fails leaves the
node failed with the reason in failure, which the graph reports.
Returns boolean — True while the bake is running.
if clip:pending() then return end
typed/builtin//systems/anim/AnimGraph/Node/Clip/Clip/rewind
Clip.rewind()
Rewind the playhead to 0, clear finished, and resume playback.
clip:rewind()
typed/builtin//systems/anim/AnimGraph/Node/Clip/Clip/setPlaying
Clip.setPlaying(p: boolean)
Pause or resume the playhead. Any value that is not the boolean true
becomes playing = false.
Parameters
pboolean— New playing state.
clip:setPlaying(false)
typed/builtin//systems/anim/AnimGraph/Node/Clip/Clip/travelSpeed
Clip.travelSpeed() -> number?
How fast the clip carries its body over the ground, in the body rig's units per second: the travel speed its retarget bake measured over the frames the source has a foot down. Nil until the bake lands, and for a clip that plays without a retarget.
Returns number? — The travel speed, or nil.
local v = clip:travelSpeed()
typed/builtin//systems/anim/AnimGraph/Node/Clip/Clip/update
Clip.update(dt: number)
Advance the playhead by dt * speed. Wraps at duration when
looping is true; otherwise clamps and marks the clip finished /
playing = false. No-op when not playing or already finished.
Parameters
dtnumber— Frame delta time in seconds.
clip:update(dt)
typed/builtin//systems/anim/AnimGraph/Node/Layer/Layer/destroy
Layer.destroy()
Cascade-destroy() base + overlay, then free this Layer's output buffer.
A Layer owns both inputs (the graph is a tree), so destroying it frees the
subtree. An input detached (set to nil) is skipped.
layer:destroy()
typed/builtin//systems/anim/AnimGraph/Node/Layer/Layer/evaluate
Layer.evaluate() -> any
Evaluate base + overlay, then per-bone blend overlay onto base by
mask[bone] * weight (translation lerp, rotation nlerp, scale lerp), and per
shape the overlay covers by shapeMask[shape] * weight scaled by that
coverage (weight and coverage lerp), into the
output buffer. With weight 0 (or all-zero masks) the base passes through.
Returns any — Owned pose buffer handle. Caller must NOT destroy.
local pose = layer:evaluate()
typed/builtin//systems/anim/AnimGraph/Node/Layer/Layer/new
Layer.new(layout: Layout, base: any?, overlay: any?, mask: { number }, shapeMask: { number }?) -> any
Construct a Layer Node that blends overlay over base per the per-bone
mask scaled by the layer weight. Allocates an output pose buffer.
Parameters
layoutLayout— Layout descriptor —boneOrderrequired,stridedefaults to 10.baseany(optional) — The base Node (e.g. the locomotion output) — passes through where mask*weight is 0.overlayany(optional) — The overlay Node (e.g. an attack clip) — taken where mask*weight is 1.mask{ number }— Per-bone weight array (one entry per bone, inboneOrder); seeAnimGraph.mask. Missing entries are 0.shapeMask{ number }(optional) — Per-shape weight array (one entry per shape, inshapeOrder); seeAnimGraph.shapeMask. Missing entries, or no array, are 0.
Returns any — The constructed Layer node.
local l = Layer.new(layout, loco, attack, AnimGraph.mask(layout, "upperBody", rig))
local face = Layer.new(layout, loco, smile, AnimGraph.mask(layout, "head", rig), AnimGraph.shapeMask(layout, "face"))
typed/builtin//systems/anim/AnimGraph/Node/Layer/Layer/pending
Layer.pending() -> boolean
Cascade update(dt) to the base and overlay sources. The Layer is the
graph output, so it owns advancing both subtrees.
Whether the base, or an overlay that carries weight, is still waiting on
work it needs to produce a pose.
Returns boolean — Whether the layer is pending.
layer:update(dt)
if layer:pending() then return end
typed/builtin//systems/anim/AnimGraph/Node/Layer/Layer/setWeight
Layer.setWeight(w: number)
Set the layer's global weight (0 = base only, 1 = full overlay where the mask is 1). The owner ramps this to fade the action in and out.
Parameters
wnumber— New weight, typically in[0, 1].
layer:setWeight(0.5)
typed/builtin//systems/anim/AnimGraph/Node/Layer/Layer/update
Layer.update(dt: number)
Parameters
dtnumber
typed/builtin//systems/anim/AnimGraph/Node/Mixer/Mixer/destroy
Mixer.destroy()
Cascade-destroy() every input source, then free this Mixer's own
blend layout and output buffer. A Mixer owns its inputs (the graph is a
tree), so destroying it frees the subtree below it. An input whose source
was detached (set to nil — e.g. a crossfade survivor handed back to the
graph) is skipped.
mix:destroy()
typed/builtin//systems/anim/AnimGraph/Node/Mixer/Mixer/evaluate
Mixer.evaluate() -> any
Evaluate inputs in turn, then weighted-blend their pose buffers
into the output buffer. Inputs with weight <= 0 are skipped.
Returns any — Owned pose buffer handle. Caller must NOT destroy.
local pose = mix:evaluate()
typed/builtin//systems/anim/AnimGraph/Node/Mixer/Mixer/new
Mixer.new(layout: Layout, inputs: { MixerInput }) -> any
Construct a Mixer Node. Allocates an output pose buffer sized for the layout and the engine-side blend layout.
Parameters
layoutLayout— Layout descriptor —boneOrderis required,stridedefaults to 10,slotLayoutdefaults to translation lerp + rotation slerp + scale lerp.inputs{ MixerInput }— Array of{ source = Node, weight = number }entries.
Returns any — The constructed Mixer node.
local mix = Mixer.new(layout, { { source = clipA, weight = 1 }, { source = clipB, weight = 0 } })
typed/builtin//systems/anim/AnimGraph/Node/Mixer/Mixer/pending
Mixer.pending() -> boolean
Whether any input that carries weight is still waiting on work it needs to produce a pose; the blend waits with it rather than leaning on the others.
Returns boolean — Whether the mixer is pending.
if mix:pending() then return end
typed/builtin//systems/anim/AnimGraph/Node/Mixer/Mixer/setWeight
Mixer.setWeight(i: number, w: number)
Set or update an input's weight at index i. Out-of-range index is a no-op.
Parameters
inumber— 1-based input index.wnumber— New weight (typically in[0, 1]).
mix:setWeight(1, 0.5)
typed/builtin//systems/anim/AnimGraph/Node/Mixer/Mixer/update
Mixer.update(dt: number)
Cascade update(dt) to every input source that defines it.
Parameters
dtnumber— Frame delta time in seconds.
mix:update(dt)
typed/builtin//systems/anim/AnimGraph/Node/Node/destroy
Node.destroy()
Default :destroy — no resources to free. Subclasses override
to release owned Channel/Buffer/Layout handles.
node:destroy()
typed/builtin//systems/anim/AnimGraph/Node/Node/evaluate
Node.evaluate() -> any?
Default :evaluate — returns nil. Subclasses override and
return a Buffer handle (caller MUST NOT destroy).
Returns any? — Pose Buffer handle, or nil from the default implementation.
local pose = node:evaluate()
typed/builtin//systems/anim/AnimGraph/Node/Node/new
Node.new() -> Node
Allocate a bare Node table (no Channels, no Buffer). Subclasses
typically wrap setmetatable(Node.new(), <Subclass>) and then set
the subclass-specific fields.
Returns Node — The new Node instance.
local n = Node.new()
typed/builtin//systems/anim/AnimGraph/Node/Node/pending
Node.pending() -> boolean
Default :pending — a node that needs nothing to produce its pose is
never pending. A node that waits on work (a clip whose retarget is baking)
answers true until that work lands, and a node over other nodes answers
true while any node it draws a pose from does.
Returns boolean — Whether the node is still waiting.
if node:pending() then return end
typed/builtin//systems/anim/AnimGraph/Node/Node/update
Node.update(dt: number)
Default :update — no internal state to advance. Subclasses
override to step playhead, ramp weights, etc.
Parameters
dtnumber— Seconds elapsed since the last update.
node:update(1 / 60)
typed/builtin//systems/anim/AnimGraph/rigResolve/R/parseBodyRig
R.parseBodyRig(body: EntityRef) -> any?
The parsed rig of a skinned body, read straight from the ECS — its
ecs.Skeleton bones (rest pose, inverse binds, hierarchy) plus its ecs.RetargetProfile
roles when present. Everything the graph needs is already in the ECS by this
point; no asset is resolved and no document is parsed. A body whose Skeleton
carries no bones returns nil. A body with no RetargetProfile is a
non-humanoid rig — the returned rig simply has an empty role map, so the
graph binds its own clips directly instead of retargeting.
Parameters
bodyEntityRef— The EntityRef of the body to drive.
Returns any?
typed/builtin//systems/anim/AnimGraph/rigResolve/R/parseFromClip
R.parseFromClip(ref: any?, rigOverride: any?) -> any?
The parsed source rig a clip was authored on. ref is a .animation
ref; pass rigOverride (a .rig ref) to force a specific source rig.
Parameters
refany(optional)rigOverrideany(optional)
Returns any?
typed/builtin//systems/anim/AnimGraph/rigResolve/R/refId
R.refId(v: any?) -> string?
The asset identity / guid behind a ref value (an AssetRef or a string).
Parameters
vany(optional)
Returns string?
typed/builtin//systems/anim/AnimGraph/rigResolve/R/restPose
R.restPose(parsedRig: any?) -> { number }
The stride-10 bind pose (translation.xyz + rotation.xyzw + scale.xyz per bone, in rig order) the graph poses relative to. Undriven channels hold this; a clip overlays only the channels it drives.
Parameters
parsedRigany(optional) — A parsed rig (fromretarget.parseRig).
Returns { number }
typed/builtin//systems/anim/AnimGraph/rigResolve/R/rigKey
R.rigKey(parsedRig: any?) -> string
The identity of a rig as a bake reads it — equal for two rigs a clip bakes onto
identically, different whenever the bake would differ. This is the key half
retarget.bakeBytes caches under: key a bake on the rig it targets and every body
built from that rig shares one bake, instead of each re-baking all of its clips.
A body's rig is built from its live Skeleton and RetargetProfile, so the key is
taken over the content the bake reads: the skeleton's structure hash (names, parents,
rest transforms and inverse binds), where its bind pose comes from, and its role map.
Parameters
parsedRigany(optional) — A parsed rig (fromretarget.parseRig).
Returns string — A short stable string, usable directly as a cache key.
local key = rigResolve.rigKey(rig)
typed/builtin//systems/characterController/CharacterController/public/stats
public.stats() -> any
How this character's frames went: how many it took its movement step on, how many it rested on, and whether it rests now. A character standing on the ground with nothing asking it to move rests, and takes its step again the frame something reaches it: a write to its input bus or any field, its feet moved by something else, the ground or the body it rides moving or changing, a collider coming to overlap it, another character moving within reach, the gravity at its feet changing, or its being bound as the local player's body.
Returns any — { resting, stepFrames, restFrames }.
local s = entity(id).component.get("CharacterController"):stats()
typed/builtin//systems/characterController/Locomotion/public/bodyChanged
public.bodyChanged()
State that a body was composed under this entity in place of the one
it carried (an avatar swapped to another body, even one that took the old
body's id): the next update drops the graph built for the body it drove and
builds one for the body the entity carries then. A body that leaves the
world is dropped the same way without a call. An avatar's setCharacter
calls this when it seats a body under a root that carries a Locomotion.
entity(id).component.get("Locomotion"):bodyChanged()
typed/builtin//systems/characterController/Locomotion/public/footingChanged
public.footingChanged()
Read the body's footing again: the footprint and ground gap the air
states sweep with come from its CharacterController's radius and
skinWidth, and the engine runs the graph with them as they were when it
took it, so this takes the graph back and the next frame hands it over
with them as they stand now. The CharacterController calls it when either
field changes.
entity(id).component.get("Locomotion"):footingChanged()
typed/builtin//systems/characterController/Locomotion/public/moversChanged
public.moversChanged()
Read the body's movers again: whether its entity carries a MovementState or a CharacterController decides what its velocity is measured from (against its parent, or in the world when it carries neither) and whether the engine runs its graph, and the engine runs the graph with the movers as they were when it took it, so this takes the graph back and the next frame reads them as they stand now. A MovementState and a CharacterController call it as they are added to the entity and removed from it.
entity(id).component.get("Locomotion"):moversChanged()
typed/builtin//systems/characterController/Locomotion/public/stats
public.stats() -> any
Where the component's graph runs and what its velocity is read from:
native true while the engine runs it in place of update, with its
program handle and frames; otherwise refusal names why it runs in
script (nil while it is still building). motion is "stated" while the
velocity is the walk the character's mover states, "measured" while it is
measured from the body's motion; space is "local" while a measured
velocity is the body's motion against its parent (it carries a
MovementState or a CharacterController), "world" while it is its motion in
the world (it carries neither, and its ancestors move it).
Returns any — { native, handle?, frames?, refusal?, motion, space }.
local where = entity(id).component.get("Locomotion"):stats()
typed/builtin//systems/characterController/characterController/movement/bodyFacing/M/anchor
M.anchor(entityId: string) -> string?
The rotation anchor of the character entityId: the topmost direct
child whose subtree holds its rigged body, so turning it turns the whole
imported character, else the entity itself when it carries a Skeleton.
Parameters
entityIdstring— The entity the facing component sits on.
Returns string? — The anchor's entity id, or nil while no body stands under it.
local anchorId = BodyFacing.anchor(public.entityId)
typed/builtin//systems/characterController/characterController/movement/bodyFacing/M/anchorDirection
M.anchorDirection(anchorId: string, lx: number, ly: number, lz: number) -> (number, number, number)
A direction given in an anchor's local frame, in world space: carried
through the anchor's live world basis, lx along its right, ly along
its up and lz along its local +Z (the opposite of the forward it
faces), the basis entity(id).transform reads. Read as numbers, so a
component turning a body every frame allocates nothing to read it.
Parameters
anchorIdstring— The anchor's entity id.lxnumber— Along the anchor's right.lynumber— Along its up.lznumber— Along its local +Z.
Returns (number, number, number) — wx, wy, wz, of the length the given direction has.
local wx, wy, wz = BodyFacing.anchorDirection(anchorId, 0, 0, -1)
typed/builtin//systems/characterController/characterController/movement/bodyFacing/M/body
M.body(entityId: string) -> string?
The skinned body under entityId: the entity itself when it is
rigged, else the first rigged descendant, depth first.
Parameters
entityIdstring— The character to search.
Returns string? — The body's entity id, or nil while no rigged skeleton stands under it.
local bodyId = BodyFacing.body(public.entityId)
typed/builtin//systems/characterController/characterController/movement/bodyFacing/M/declared
M.declared(componentName: string, component: any?) -> (number, number, number)
The direction a facing component declares the body faces along, in
its anchor's local frame: Locomotion.forward as it stands, and
LocomotionFull.faceSign as (0, 0, -faceSign).
Parameters
componentNamestring—"Locomotion"or"LocomotionFull".componentany(optional) — The component's public fields.
Returns (number, number, number) — The anchor-local direction as three numbers.
local fx, fy, fz = BodyFacing.declared("Locomotion", entity(id).component.get("Locomotion"))
typed/builtin//systems/characterController/characterController/movement/bodyFacing/M/declaring
M.declaring(targetId: string) -> (string?, string?, any)
The entity carrying the component that turns targetId's body: the
subject itself or the nearest ancestor carrying one of COMPONENTS, so a
subject named by its body or its root alike finds the character.
Parameters
targetIdstring— The subject.
Returns (string?, string?, any) — The declaring entity's id, the component's name and its public fields; nil when nothing up the chain turns it.
local id, name, comp = BodyFacing.declaring(bodyId)
typed/builtin//systems/characterController/characterController/movement/bodyFacing/M/forward
M.forward(targetId: string) -> (number?, number?, number?)
The direction targetId's body visibly faces, in world space: the
direction its facing component declares, carried through the live basis
of the anchor that component turns (anchor), so it follows the body as
it turns (heldAnchor). A character whose body has not stood up yet
carries the declaration through the entity the component sits on.
Parameters
targetIdstring— The subject: a character, or any entity under one.
Returns (number?, number?, number?) — Unit world-space direction as three numbers; nil when nothing up the chain turns the subject.
local fx, fy, fz = BodyFacing.forward(characterId)
typed/builtin//systems/characterController/characterController/movement/bodyFacing/M/heldAnchor
M.heldAnchor(entityId: string) -> string?
The rotation anchor of the character entityId, as anchor resolves
it, kept from one read to the next while it stands: an anchor that still
exists as the entity itself or one of its direct children is answered as
it is, and one that has gone (a body setCharacter swapped out) is
resolved again, the way Locomotion and LocomotionFull keep theirs. A
reader that asks every frame walks the body's subtree once.
Parameters
entityIdstring— The entity the facing component sits on.
Returns string? — The anchor's entity id, or nil while no body stands under it.
local anchorId = BodyFacing.heldAnchor(characterId)
typed/builtin//systems/characterController/characterController/movement/bodyFacing/M/isRigged
M.isRigged(entityId: string) -> boolean
Whether entityId carries a Skeleton whose rig has hydrated (bones
present). A rig lands a beat after its Skeleton row while the mesh and
rig content load, so a Skeleton counts as a body once its bones are
present.
Parameters
entityIdstring— The entity to read.
Returns boolean — True when the entity's Skeleton holds at least one bone.
if BodyFacing.isRigged(id) then initGraph(id) end
typed/builtin//systems/characterController/characterController/movement/bodyFacing/M/source
M.source(targetId: string) -> string?
What forward reads targetId's facing from: the entity carrying
the facing component, the component's name, the anchor the declaration
is carried through and the anchor-local direction it declares
(declared), joined as one key. The key changes when a facing component
arrives or goes, when what it declares changes (Locomotion.forward,
LocomotionFull.faceSign) and when the anchor changes (a body standing
up under the character), and holds while the body turns, so a reader
comparing it from one frame to the next sees the facing become known or
be declared anew without following the direction.
Parameters
targetIdstring— The subject: a character, or any entity under one.
Returns string? — The key, or nil when nothing up the chain turns the subject.
local key = BodyFacing.source(characterId)
typed/builtin//systems/characterController/characterController/movement/bodyFacing/M/turnAnchor
M.turnAnchor(anchorId: string, yaw: number)
Turn an anchor about its parent's up (its parent's +Y) by yaw
radians, positive counter-clockwise seen from above: the turn applied to
the anchor's local rotation, which is read and written as numbers, so a
component turning a body every frame allocates nothing to turn it.
Parameters
anchorIdstring— The anchor's entity id.yawnumber— The turn, in radians.
BodyFacing.turnAnchor(anchorId, math.rad(15))
typed/builtin//systems/characterController/characterController/movement/feel/M/jumpsAfter
M.jumpsAfter(jumpCount: number, maxJumps: number, footing: boolean) -> number?
The jump count a granted jump request leaves, or nil when the request
is refused. A character on its feet, or off them for no longer than
coyoteTime, takes its first jump. Off its feet past that, the jump it
could have taken from the ground counts as spent, and a request takes the
next jump while maxJumps has one left: a character with two jumps that
walks off a ledge jumps once in the air, as one that jumped from the
ground does.
Parameters
jumpCountnumber— The jumps spent since the character last stood.maxJumpsnumber— The jumps it may spend before it stands again.footingboolean— Whether it stands, or left its feet withincoyoteTime.
Returns number? — The jump count after the jump, or nil when no jump is taken.
local count = Feel.jumpsAfter(cc.jumpCount, cc.maxJumps, grounded or sinceGround <= coyote)
typed/builtin//systems/characterController/characterController/movement/feel/M/launch
M.launch(settings: Settings, pull: number, held: boolean) -> (number, Rise)
The speed a jump takes off at along up, and how it rises, for a
character whose gravity pulls pull m/s² down along up. jumpHeight
(m) and jumpApexTime (s) above 0 state the jump directly: with both, it
rises exactly jumpHeight and reaches the top jumpApexTime after
take-off; with the height alone it rises that high against pull; with
the time alone it takes off at jumpForce and tops out that long after.
With neither it takes off at jumpForce against pull. minJumpHeight
above 0 makes a release of the jump control during the rise cut it short:
released at take-off it rises minJumpHeight, held to the top the full
height, and anything between in between.
Parameters
settingsSettings— The feel settings (jumpForce,jumpHeight,jumpApexTime,minJumpHeight).pullnumber— The gravity along up, in m/s², positive pulling down.heldboolean— Whether the jump was asked for with the jump control held: a jump asked for so is cut by a release, even one made before it took off (a tap just before landing risesminJumpHeight).
Returns (number, Rise) — speed, rise: the take-off speed in m/s and the Rise to pass Feel.vertical and Feel.release.
local speed, rise = Feel.launch({ jumpHeight = 1.2, jumpApexTime = 0.4 }, 9.81, true)
typed/builtin//systems/characterController/characterController/movement/feel/M/release
M.release(vy: number, rise: Rise?, held: boolean) -> (number, Rise?)
Apply a release of the jump control to a rising jump: a jump asked
for with the control held and still rising faster than its cutTo is
slowed to it on the first step the control reads let go, which tops it
out minJumpHeight above where it was (on the step it takes off, for a
request let go before then). A jump asked for without the control held,
or one rising slower than that already, rises on as it is.
Parameters
vynumber— The velocity along up now, in m/s.riseRise(optional) — The jump'sRise(fromFeel.launch), or nil when no jump is rising.heldboolean— Whether the jump control is held this step.
Returns (number, Rise?) — vy, rise: the velocity along up and the rise, which no longer cuts once released.
vy, rise = Feel.release(vy, rise, cc.inputJumpHeld)
typed/builtin//systems/characterController/characterController/movement/feel/M/vertical
M.vertical(vy: number, dt: number, rise: Rise?, pull: number, settings: Settings) -> (number, number, Rise?)
One step of dt seconds along up for a character off the ground,
integrated exactly for the gravity of each part of the step: a jump
rises against its rise.gravity, anything else rises against pull, and
everything falls at pull times fallGravityMultiplier, no faster than
maxFallSpeed (m/s) when that is above 0. A step that crosses the top
switches gravity there, so a jump tops out exactly where its gravity
says at any frame rate.
Parameters
vynumber— The velocity along up at the start of the step, in m/s.dtnumber— Seconds the step covers.riseRise(optional) — The rising jump'sRise, or nil.pullnumber— The gravity along up, in m/s², positive pulling down.settingsSettings— The feel settings (fallGravityMultiplier,maxFallSpeed).
Returns (number, number, Rise?) — dy, vy, rise: the distance moved along up, the velocity at the end of the step, and the rise, nil once the jump has stopped rising.
local dy, vy, rise = Feel.vertical(vy, dt, rise, 9.81, cfg)
typed/builtin//systems/characterController/characterController/movement/feel/M/walk
M.walk(vx: number, vz: number, wantX: number, wantZ: number, acceleration: number, braking: number, dt: number) -> (number, number, number, number)
The ground velocity (vx, vz) becomes over dt seconds when the
character asks for (wantX, wantZ), both in m/s across the ground, and
the distance it covers over those seconds. Speeding up along the request
takes acceleration m/s²; slowing down takes braking m/s², which is
also the rate the velocity loses the part that points across the
request. So a start ramps up, a stop brakes, a turn sheds its old heading
while it builds the new one, and a reversal brakes to a stop before it
speeds up the other way. An acceleration or braking of 0 reaches the
request at once, the frame it is asked. The distance is exact for that
motion, so a ramp covers the same ground at any frame rate.
Parameters
vxnumber— The ground velocity's X now, in m/s.vznumber— The ground velocity's Z now, in m/s.wantXnumber— The X of the velocity asked for, in m/s.wantZnumber— The Z of the velocity asked for, in m/s.accelerationnumber— How fast the velocity speeds up along the request, in m/s²; 0 at once.brakingnumber— How fast it slows down and sheds a heading the request turned away from, in m/s²; 0 at once.dtnumber— Seconds the step covers.
Returns (number, number, number, number) — vx, vz, dx, dz: the ground velocity at the end of the step and the distance covered across the ground over it.
local vx, vz, dx, dz = Feel.walk(vx, vz, 0, 2.5, 20, 30, dt)
typed/builtin//systems/characterController/characterController/movement/statedWalk/M/facing
M.facing(vx: number, vz: number, askedX: number?, askedZ: number?, moveDeadzone: number) -> (number?, number?)
The direction a body turns toward, across the frame it stands in: the
walk asked for, at whatever speed it is asked; with none asked, the
velocity once it is faster than moveDeadzone. Nil when neither holds,
and the body keeps its facing.
Parameters
vxnumber— The body's velocity across the ground, along the standing frame's X.vznumber— The body's velocity across the ground, along the standing frame's Z.askedXnumber(optional) — The walk asked for along X, or nil when nothing stated one.askedZnumber(optional) — The walk asked for along Z, or nil when nothing stated one.moveDeadzonenumber— The speed, in m/s, a velocity turns the body above.
Returns (number?, number?) — (dirX, dirZ), a unit direction, or nil.
local tx, tz = StatedWalk.facing(vx, vz, ax, az, public.moveDeadzone)
typed/builtin//systems/characterController/characterController/movement/statedWalk/M/isPlacement
M.isPlacement(dx: number, dy: number, dz: number, dt: number) -> boolean
Whether a step of (dx, dy, dz) over dt seconds is a placement (a
teleport, a respawn, a scripted move to somewhere else) rather than
motion: a step faster than TELEPORT_SPEED. A step over no time that
goes anywhere is a placement.
Parameters
dxnumber— Step along world X.dynumber— Step along world Y.dznumber— Step along world Z.dtnumber— The seconds the step spans.
Returns boolean — True when the step is a placement.
if StatedWalk.isPlacement(dx, dy, dz, dt) then vel.y = 0 end
typed/builtin//systems/characterController/characterController/movement/statedWalk/M/measure
M.measure(body: any?, held: Measured, dt: number) -> (number, number, number)
The velocity of body measured in the world: its world position's
step since the frame before over the frame's gameplay seconds, across the
frame it stands in (Frame.standing). A step faster than
TELEPORT_SPEED is a placement and leaves the velocity as it was; a
body not sampled on the frame before measures none.
Parameters
bodyany(optional) — The entity whose motion is measured.heldMeasured— The recordmeasuredmade for the body, updated in place.dtnumber— The frame's gameplay seconds.
Returns (number, number, number) — (vx, vy, vz) in m/s across the standing frame, vy along up.
local vx, vy, vz = StatedWalk.measure(public.entity, measured, dt)
typed/builtin//systems/characterController/characterController/movement/statedWalk/M/measured
M.measured() -> Measured
A fresh record of a body's measured motion, for measure and
motion to keep: nothing sampled yet, and no velocity measured.
Returns Measured — The record, owned by the component that animates the body.
local measured = StatedWalk.measured()
typed/builtin//systems/characterController/characterController/movement/statedWalk/M/motion
M.motion(body: any?, ms: any?, cc: any?, held: Measured, dt: number) -> (number, number, number, number?, number?)
This frame's motion of body across the frame it stands in: its
walk across the ground and its velocity along up, and the walk it was
asked for. The walk is the one read answers whenever a mover states one;
on a frame none does it is the velocity of the body's MovementState, else
of its CharacterController, else (a body with neither) its motion measured
in the world (measure). The velocity along up is always the mover's, or
the measured one for a body with neither.
Parameters
bodyany(optional) — The entity whose motion is read.msany(optional) — The MovementState onbody's entity, or nil.ccany(optional) — The CharacterController onbody's entity, or nil.heldMeasured— The recordmeasuredmade for the body, kept for a body with neither mover.dtnumber— The frame's gameplay seconds.
Returns (number, number, number, number?, number?) — (vx, vy, vz, askedX, askedZ) in m/s across the standing frame; the asked walk is nil when nothing stated one.
local vx, vy, vz, ax, az = StatedWalk.motion(public.entity, MS, CC, measured, dt)
typed/builtin//systems/characterController/characterController/movement/statedWalk/M/moversChanged
M.moversChanged(body: any?)
Tell the components that animate body from its walk (Locomotion,
LocomotionFull) that its movers changed: a MovementState or a
CharacterController came to its entity or went from it. Each reads its
movers again on its next frame.
Parameters
bodyany(optional) — The entity whose movers changed.
StatedWalk.moversChanged(public.entity)
typed/builtin//systems/characterController/characterController/movement/statedWalk/M/read
M.read(body: any?, hasOwnMover: boolean) -> (number?, number?, number?, number?)
The walk the mover of body's character stated this frame, across
the frame body stands in (Frame.standing): the walk it took across what
it stands on and the walk it was asked for. A body with a mover of its own
(a MovementState or a CharacterController on its entity) reads its own
entity's statement; a body with none reads the statement of the nearest
of its ancestors that has one (a body parented under the root a
CharacterController walks). Nil on a frame nothing states a walk for it (a
replica the multiplayer sync moves, a body a script or a path moves), and
the body measures its motion then.
Parameters
bodyany(optional) — The entity the walk is read for.hasOwnMoverboolean— Whetherbody's entity carries a MovementState or a CharacterController.
Returns (number?, number?, number?, number?) — (walkX, walkZ, askedX, askedZ) in m/s across the standing frame, or nil.
local wx, wz, ax, az = StatedWalk.read(public.entity, MS ~= nil or CC ~= nil)
typed/builtin//systems/characterController/characterController/movement/stepSmoothing/M/active
M.active(state: Smoothing) -> boolean
Whether the character's body is drawn off its capsule's height now.
Parameters
stateSmoothing— The character's smoothing, fromnew.
Returns boolean — True while the offset is not zero, still moving, or a child stands shifted.
if StepSmoothing.active(smoothing) then return nil end
typed/builtin//systems/characterController/characterController/movement/stepSmoothing/M/clear
M.clear(state: Smoothing, entityId: string)
Draw the character's children where its capsule stands at once: the offset goes to zero and every shifted child goes back to its own position. A controller calls it when the character is placed by something else, stops being moved by it, or goes away.
Parameters
stateSmoothing— The character's smoothing, fromnew.entityIdstring— The character's entity.
StepSmoothing.clear(smoothing, public.entityId)
typed/builtin//systems/characterController/characterController/movement/stepSmoothing/M/climbed
M.climbed(state: Smoothing, rise: number, travel: number, slopeAngle: number, stepHeight: number) -> number
Take in one grounded step's rise along up. The part of rise past
what the ground's slope gives the step's travel is a step the capsule
took at once, and the drawn body is put back by it, to close over the
following frames. The offset is held within stepHeight either way.
Parameters
stateSmoothing— The character's smoothing, fromnew.risenumber— How far the step moved the feet along up, in metres.travelnumber— How far the step moved the feet across the ground, in metres.slopeAnglenumber— The slope of the ground the step ended on, in degrees.stepHeightnumber— The character's step height, in metres.
Returns number — The offset after the step, in metres.
StepSmoothing.climbed(smoothing, dy, travel, slopeAngle, 0.3)
typed/builtin//systems/characterController/characterController/movement/stepSmoothing/M/new
M.new() -> Smoothing
A fresh step smoothing for one character: no offset, no child shifted.
Returns Smoothing — The smoothing record, owned by the controller that moves the character.
local smoothing = StepSmoothing.new()
typed/builtin//systems/characterController/characterController/movement/stepSmoothing/M/offset
M.offset(state: Smoothing) -> number
The offset the character's drawn children stand at along its up.
Parameters
stateSmoothing— The character's smoothing, fromnew.
Returns number — The offset in metres: negative while the body is drawn below the capsule's height (after a step up), positive above it (after a step down).
local off = StepSmoothing.offset(smoothing)
typed/builtin//systems/characterController/characterController/movement/stepSmoothing/M/settle
M.settle(state: Smoothing, entityId: string, smoothTime: number, dt: number) -> number
Close the offset by dt seconds of a critically damped spring of
smoothTime and draw the character's children at it. A smoothTime of
0 closes it at once. Costs nothing on a frame the offset is zero and no
child is shifted.
Parameters
stateSmoothing— The character's smoothing, fromnew.entityIdstring— The character's entity, whose direct children are drawn shifted.smoothTimenumber— Seconds the spring takes to close most of a step: about three fifths of it in this time, and nine tenths in twice it.dtnumber— Frame delta in seconds.
Returns number — The offset now, in metres.
StepSmoothing.settle(smoothing, public.entityId, public.stepSmoothing, dt)
typed/builtin//systems/characterController/characterController/physics/carry/M/aim
M.aim(c: Cast, origin: any?, direction: any?, maxDistance: number, selfId: string, radius: number?, halfHeight: number?, axis: any?) -> Cast
Point a kept cast (newCast) for the body selfId: from origin
along direction, as far as maxDistance, passing over the collider on
selfId alone until pass adds more, and cast for selfId as its mover
(castOptions). A sphere or capsule cast takes its shape here too.
Parameters
cCast— The cast.originany(optional) — Where the cast starts, in world space: avectoror{ x, y, z }.directionany(optional) — The way it runs: avectoror{ x, y, z }.maxDistancenumber— How far it reaches.selfIdstring— The body's entity ID. An empty string names no mover.radiusnumber(optional) — The sphere's or capsule's radius.halfHeightnumber(optional) — The capsule's half-height between its cap centres.axisany(optional) — The capsule's axis: avectoror{ x, y, z }.
Returns Cast — The cast.
Carry.aim(probe, vector.create(x, y + 0.3, z), vector.create(0, -1, 0), 0.5, selfId)
typed/builtin//systems/characterController/characterController/physics/carry/M/carriedBy
M.carriedBy(entityId: string, selfId: string) -> boolean
Whether the collider on entityId is one the body selfId
carries: the body itself, or an entity parented under it at any depth.
Parameters
entityIdstring— The entity a query hit.selfIdstring— The body's entity ID. An empty string carries nothing.
Returns boolean — true when entityId is selfId or one of its descendants.
if Carry.carriedBy(hit.entityId, selfId) then return nil end
typed/builtin//systems/characterController/characterController/physics/carry/M/castNext
M.castNext(c: Cast) -> any
Cast a kept cast as aim and pass left it: the first surface it
meets, as the result Physics.castMany writes (entityId, point,
normal, distance, startedInside, surfaceVelocity, the vectors as
vector values), or nil when it meets nothing. The result is the cast's
own and the next cast of it rewrites it.
Parameters
cCast— The cast.
Returns any — The result, or nil.
local r = Carry.castNext(probe)
typed/builtin//systems/characterController/characterController/physics/carry/M/castOptions
M.castOptions(selfId: string) -> { mover: string }?
The options a cast made for the body selfId passes to
Physics.raycast and the shape casts: { mover = selfId }, so the cast
meets colliders as the body does (one-way colliders, the contact filter,
Physics.passThrough). An empty selfId names no mover.
Parameters
selfIdstring— The body's entity ID.
Returns { mover: string }? — The options table, or nil for an empty selfId.
local hit = Physics.capsuleCast(origin, 0.3, 0.6, dir, 1, { selfId }, nil, Carry.castOptions(selfId))
typed/builtin//systems/characterController/characterController/physics/carry/M/hit
M.hit(r: any?, into: { [string]: any }?) -> any
A cast result (castNext) as a hit of the caller's own: written into
into when it is given, the vectors as vector values, so a caller
answering every frame into one table allocates nothing; otherwise a new
table in the shape Physics.raycast answers, each vector a { x, y, z }
table. Either way the fields the character passes add to a hit (edge,
character, _sliding) start cleared.
Parameters
rany(optional) — The result.into{ [string]: any }(optional) — The table to write the hit into, or nil for a new one.
Returns any — The hit.
return Carry.hit(Carry.castNext(probe), into)
typed/builtin//systems/characterController/characterController/physics/carry/M/newCast
M.newCast(kind: string) -> Cast
A cast for a caller to keep and ask again frame after frame: one
Physics.castMany query of kind ("ray", "sphere" or "capsule", as
castMany names them), the results it writes its answers into and the
list of colliders it passes over. aim points it and castNext casts it,
and neither allocates.
Parameters
kindstring— The query's kind: "ray", "sphere" or "capsule".
Returns Cast — The Cast, owned by the caller.
local probe = Carry.newCast("sphere")
typed/builtin//systems/characterController/characterController/physics/carry/M/pass
M.pass(c: Cast, entityId: string)
Pass the collider on entityId on the kept cast's next castNext.
Parameters
cCast— The cast.entityIdstring— The entity whose collider the cast passes.
Carry.pass(probe, hit.entityId)
typed/builtin//systems/characterController/characterController/physics/carry/M/rayNext
M.rayNext(origin: any?, dir: any?, maxDist: number, selfId: string) -> any
raycast's answer as the cast result itself (castNext): the
module's own, rewritten by the next rayNext or raycast. A caller that
reads it before casting again allocates nothing.
Parameters
originany(optional) — Ray start in world space: avectoror{ x, y, z }.dirany(optional) — Ray direction (normalized): avectoror{ x, y, z }.maxDistnumber— How far the ray reaches.selfIdstring— The body's entity ID.
Returns any — The result, or nil.
local r = Carry.rayNext(vector.create(px, py + 0.3, pz), vector.create(0, -1, 0), 0.5, selfId)
typed/builtin//systems/characterController/characterController/physics/carry/M/raycast
M.raycast(origin: any?, dir: any?, maxDist: number, selfId: string, into: { [string]: any }?) -> any
Cast a ray for the body selfId and return the first surface it
meets that the body does not carry. The ray passes through the
collider on selfId and through every collider on an entity parented
under it, so a prop the character holds at its feet, overhead or in
front of it never answers for the ground, the ceiling or a wall. The ray
is cast for selfId as its mover (M.castOptions), so it meets the
colliders by the body's contact rules: a one-way platform only from the
side it holds, never a collider the contact filter lets the body pass,
and never a platform the body is dropping through.
Parameters
originany(optional) — Ray start in world space.dirany(optional) — Ray direction (normalized).maxDistnumber— How far the ray reaches.selfIdstring— The body's entity ID.into{ [string]: any }(optional) — A table to write the hit into (Carry.hit), so a caller casting every frame allocates nothing; a new table when left out.
Returns any — Raycast hit table { entityId, point, normal, distance, startedInside } of the first surface the body does not carry (into when given), or nil when there is none within maxDist.
local hit = Carry.raycast({ x = px, y = py + 0.3, z = pz }, { x = 0, y = -1, z = 0 }, 0.5, selfId)
typed/builtin//systems/characterController/characterController/physics/ceiling/M/cast
M.cast(x: number, y: number, z: number, height: number, skinWidth: number, selfId: string, frame: Frame.Frame?, into: { [string]: any }?) -> any
Cast a short ceiling-detection ray upward from the character's
head, up the frame's up (frame, the world's when left out). The ray
starts height - skinWidth above the feet and travels up for
skinWidth * 2.
Parameters
xnumber— Character feet position X.ynumber— Character feet position Y.znumber— Character feet position Z.heightnumber— Character capsule height.skinWidthnumber— Collision skin margin.selfIdstring— The body's entity ID; the ray passes through the colliders on it and on every entity parented under it.frameFrame.Frame(optional) — The frame the character stands in (Frame.at); defaults to the world's, up +Y.into{ [string]: any }(optional) — Optional hit table of the caller's own to write the answer into (Carry.hit): a caller casting every frame allocates nothing.
Returns any — Raycast hit table (into when given), or nil when nothing overhead.
local hit = Ceiling.cast(px, py, pz, 1.8, 0.01, selfId)
typed/builtin//systems/characterController/characterController/physics/characters/M/apart
M.apart(x: number, y: number, z: number, height: number, radius: number, selfId: string, maxStep: number, frame: Frame.Frame?, near: Bodies?) -> (number, number)
The step across the frame that takes the character, feet at
(x, y, z), apart from the characters it overlaps: half of each
overlap, away from the other character, at most maxStep in all. A
character it overlaps that moved towards it since the frame before is
given no way: that one is the one to stop. Each
of the two moves itself by half, so between them they close the overlap;
a pair at the very same point comes apart along the frame's X, the one
whose entity id sorts first towards +X.
Parameters
xnumber— Character feet X.ynumber— Character feet Y.znumber— Character feet Z.heightnumber— Character capsule height.radiusnumber— Character capsule radius.selfIdstring— The character's entity ID.maxStepnumber— The longest the step may be: the separation speed times the step's time.frameFrame.Frame(optional) — The frame the character stands in; defaults to the world's.nearBodies(optional) — The characters to come apart from (near); read here when left out.
Returns (number, number) — stepX, stepZ across the frame, 0, 0 when the character overlaps no other.
local ax, az = Characters.apart(px, py, pz, 1.8, 0.3, selfId, 2 * dt)
typed/builtin//systems/characterController/characterController/physics/characters/M/disturbed
M.disturbed(x: number, y: number, z: number, height: number, radius: number, selfId: string) -> boolean
Whether another character moved, came to stand or was switched on
this frame or the frame before within reach of the character selfId
with feet at (x, y, z): close enough that its capsule can touch this
one's. A character resting where it stands moves only once something
reaches it, and another character reaches it only by moving.
Parameters
xnumber— Character feet X.ynumber— Character feet Y.znumber— Character feet Z.heightnumber— Character capsule height.radiusnumber— Character capsule radius.selfIdstring— The character's entity ID.
Returns boolean — True when such a character moved within reach.
if Characters.disturbed(px, py, pz, 1.8, 0.3, selfId) then rest = nil end
typed/builtin//systems/characterController/characterController/physics/characters/M/near
M.near(x: number, y: number, z: number, reach: number, radius: number, selfId: string, frame: Frame.Frame?, into: Bodies?) -> Bodies
The other characters the character selfId, with feet at
(x, y, z) and radius round, can meet within reach of where it
stands: every entity carrying a CharacterController whose capsule
comes within reach of the character's own across the frame, other
than the character itself, the ones it carries, the ones carrying it and
the ones the contact filter lets it pass. Read once per step and handed
to sweep and apart, so a step's casts read the world once.
Parameters
xnumber— Character feet X.ynumber— Character feet Y.znumber— Character feet Z.reachnumber— How far beyond touching another character counts as near.radiusnumber— The character's capsule radius.selfIdstring— The character's entity ID.frameFrame.Frame(optional) — The frame the character stands in; defaults to the world's.intoBodies(optional) — Optional list of the caller's own to write the bodies into, emptied first: a caller asking every frame into one list allocates nothing. The bodies are the module's own, read again on a later frame.
Returns Bodies — { Body }: each near character's feet, capsule and tag (into when given).
local near = Characters.near(px, py, pz, 0.5, 0.3, selfId)
typed/builtin//systems/characterController/characterController/physics/characters/M/passes
M.passes(tagA: string, tagB: string) -> boolean
Whether two characters with contact tags tagA and tagB pass
through each other: the world's contact filter answers the pair
"ignore" or "sensor" (Physics.setContactFilter).
Parameters
tagAstring— One character'scontactTag.tagBstring— The other's.
Returns boolean — True when the two pass through each other.
if Characters.passes("ghost", "character") then print("ghosts walk through people") end
typed/builtin//systems/characterController/characterController/physics/characters/M/placed
M.placed(selfId: string, x: number, y: number, z: number)
State where the character selfId put its feet, once it has moved
itself: the characters that move after it in the same frame meet it
there.
Parameters
selfIdstring— The character's entity ID.xnumber— Feet X, in world space.ynumber— Feet Y.znumber— Feet Z.
Characters.placed(selfId, px, py, pz)
typed/builtin//systems/characterController/characterController/physics/characters/M/sweep
M.sweep(near: Bodies, x: number, y: number, z: number, dirX: number, dirZ: number, distance: number, height: number, radius: number, frame: Frame.Frame?, bottom: number?, into: { [string]: any }?) -> any
Sweep the character's capsule from feet at (x, y, z) along
(dirX, 0, dirZ) across the frame against the characters near holds,
and report the first it runs into within distance. A character it
already overlaps stands in its way only while the walk goes further into
it: walking away from it, or along it, is free, which is how two
overlapping characters come apart.
Parameters
nearBodies— The characters to sweep against (near).xnumber— Character feet X.ynumber— Character feet Y.znumber— Character feet Z.dirXnumber— Movement direction X across the frame (normalized).dirZnumber— Movement direction Z across the frame (normalized).distancenumber— How far the sweep reaches.heightnumber— Character capsule height.radiusnumber— Character capsule radius.frameFrame.Frame(optional) — The frame the character stands in; defaults to the world's.bottomnumber(optional) — How far above the feet the swept body starts (a body lifted for a step); 0 when left out.into{ [string]: any }(optional) — Optional hit table of the caller's own to write the answer into,pointandnormalwritten into the{ x, y, z }tables it holds: a caller sweeping every frame into one table allocates nothing.
Returns any — Hit table { entityId, point, normal, distance, startedInside, character } (into when given), or nil when no character stands in the way. distance is how far the body travels before it touches the other; normal is in world space, pointing from the other character towards this one; character is true.
local hit = Characters.sweep(near, px, py, pz, 1, 0, 0.05, 1.8, 0.3)
typed/builtin//systems/characterController/characterController/physics/ground/M/cast
M.cast(x: number, y: number, z: number, skinWidth: number, maxDist: number, selfId: string, riseDist: number?, frame: Frame.Frame?, into: { [string]: any }?) -> any
Cast a ground-detection ray downward from a position: down the
frame's up (frame, the world's when left out), so a character on the
side of a planet looks for the ground under its own feet. Origin is
raised by skinWidth plus riseDist so the ray starts above the
feet, and the returned hit.distance is adjusted back to be
relative to the feet (not the ray origin) — negative for ground
that stands above them — and measured to the ground where the frame
draws it (Physics.drawnPose), so a character seated on a body the
simulation blends between ticks stays on it on screen. hit.normal is
in world space.
Parameters
xnumber— Character feet position X.ynumber— Character feet position Y.znumber— Character feet position Z.skinWidthnumber— Small offset above the feet to start the ray from.maxDistnumber— How far below the feet to check.selfIdstring— The body's entity ID; the ray passes through the colliders on it and on every entity parented under it.riseDistnumber(optional) — How far above the feet to check as well. Ground found up there comes back with a negativedistance, which is how much the character has to rise to stand on it. Defaults to 0.frameFrame.Frame(optional) — The frame the character stands in (Frame.at); defaults to the world's, up +Y.into{ [string]: any }(optional) — Optional hit table of the caller's own to write the answer into (Carry.hit, the vectors asvectorvalues): a caller casting every frame into one table allocates nothing.
Returns any — Raycast hit table with distance adjusted to be feet-relative (into when given), or nil.
local hit = Ground.cast(px, py, pz, 0.01, 0.2, selfId, 0.3)
local hit = Ground.cast(px, py, pz, 0.01, 0.2, selfId, 0.3, Frame.at(px, py, pz))
typed/builtin//systems/characterController/characterController/physics/ground/M/projectOnSlope
M.projectOnSlope(moveX: number, moveY: number, moveZ: number, normalX: number, normalY: number, normalZ: number) -> (number, number, number)
Project a movement vector onto the slope plane defined by a
surface normal. Computes v - (v . n) * n — the component of v
that lies in the plane orthogonal to n.
Parameters
moveXnumber— Movement X.moveYnumber— Movement Y.moveZnumber— Movement Z.normalXnumber— Surface normal X.normalYnumber— Surface normal Y.normalZnumber— Surface normal Z.
Returns (number, number, number) — projX, projY, projZ — the projected movement vector.
local px, py, pz = Ground.projectOnSlope(dx, 0, dz, nx, ny, nz)
typed/builtin//systems/characterController/characterController/physics/ground/M/slopeAngle
M.slopeAngle(nx: number, ny: number, nz: number) -> number
Compute the slope angle (degrees) between a ground normal and
up: give the normal along a frame's axes (Frame.toLocal) for the angle
against that frame's up. Returns 0 when the input is the zero vector.
Parameters
nxnumber— Ground normal X.nynumber— Ground normal Y (along up).nznumber— Ground normal Z.
Returns number — Slope angle in degrees, in [0, 180].
local angle = Ground.slopeAngle(hit.normal.x, hit.normal.y, hit.normal.z)
typed/builtin//systems/characterController/characterController/physics/ground/M/support
M.support(x: number, y: number, z: number, radius: number, skinWidth: number, maxDist: number, selfId: string, riseDist: number?, maxSlopeAngle: number?, frame: Frame.Frame?, into: { [string]: any }?) -> any
The ground a body stands on: the surface under its centre
(Ground.cast), or a walkable surface under the rest of its
footprint, the disc of radius around the centre, where that stands
higher. A body whose front has stepped over the edge of a stair stands
on that stair, and one walking off a ledge stands on the ledge until the
last of its footprint leaves it, the way feet do. Ground under the
footprint that only continues the surface under the centre (a ramp seen
a little uphill) leaves the body on the surface under its centre.
Parameters
xnumber— Character feet position X.ynumber— Character feet position Y.znumber— Character feet position Z.radiusnumber— The body's radius: how far from the centre its footprint reaches.skinWidthnumber— Small offset above the feet the casts start from; the footprint reachesradius - skinWidth.maxDistnumber— How far below the feet to check.selfIdstring— The body's entity ID; the casts pass through the colliders on it and on every entity parented under it.riseDistnumber(optional) — How far above the feet to check as well. Ground found up there comes back with a negativedistance. Defaults to 0.maxSlopeAnglenumber(optional) — Steepest surface, in degrees, the footprint stands on.frameFrame.Frame(optional) — The frame the character stands in (Frame.at); defaults to the world's, up +Y.into{ [string]: any }(optional) — Optional hit table of the caller's own to write the answer into (Carry.hit, the vectors asvectorvalues): a caller asking every frame into one table allocates nothing.
Returns any — Hit table as Ground.cast returns it, distance feet-relative and normal the surface's own in world space, with edge = true when it is the surface under the footprint rather than under the centre (into when given); or nil.
local hit = Ground.support(px, py, pz, 0.3, 0.01, 0.3, selfId, 0.3, 45)
typed/builtin//systems/characterController/characterController/physics/platform/M/carry
M.carry(ride: Ride?, x: number, y: number, z: number, up: any?, dt: number?, into: Carry?) -> Carry?
How the body of ride moved the point (x, y, z) since the ride was
held: the point rides the body rigidly, so it is carried by the body's
translation and swung round by its rotation, and the body's turn about
up is the turn a character standing there takes with it. It also
answers how fast the body moves the point this frame (vx, vy, vz):
the velocity the simulation holds for the body (Physics.getVelocity)
plus its spin about where it stands (Physics.getAngularVelocity), or,
for an entity under no body, the displacement over dt. A body that has
gone away carries nothing.
Parameters
rideRide(optional) — The ridePlatform.holdreturned, or nil.xnumber— Point X in world space (a character's feet).ynumber— Point Y.znumber— Point Z.upany(optional) — The up the character stands along, a unit vector{ x, y, z }.dtnumber(optional) — The seconds this frame spans, or nil (the velocity of an entity under no body then reads zero).intoCarry(optional) — A carry the caller keeps (Platform.newCarry) to write the answer into: held so frame after frame, riding a body allocates nothing. A new carry when left out.
Returns Carry? — A Carry { entityId, dx, dy, dz, turn, moved, vx, vy, vz } (into when given), or nil when there is no ride or its body is gone.
local c = Platform.carry(ride, px, py, pz, { x = 0, y = 1, z = 0 }, dt)
typed/builtin//systems/characterController/characterController/physics/platform/M/drawnRise
M.drawnRise(hit: any?, up: any?) -> number
How far along up the surface a cast met stands drawn above the
point the cast met it at. A query meets a body where the last physics
tick left it, while the frame draws a dynamic body blended between its
last two ticks; a character seated on the drawn surface stays on it on
screen. 0 for anything drawn where the simulation holds it.
Parameters
hitany(optional) — A cast hit carryingentityIdandpoint.upany(optional) — The up the character stands along, a unit vector{ x, y, z }.
Returns number — The rise along up, in metres (negative when the drawn surface is lower).
hit.distance -= Platform.drawnRise(hit, frame.up)
typed/builtin//systems/characterController/characterController/physics/platform/M/frameOf
M.frameOf(entityId: string?) -> string?
The entity a character standing on entityId states its pose
relative to for the other peers of a multiplayer session: the entity
carrying the body entityId belongs to when that body moves (a
kinematic or a dynamic body). nil for a static body, for an entity
under no body, and for nil.
Parameters
entityIdstring(optional) — The entity the character stands on (ride.entityId), or nil.
Returns string? — The moving body's entity, or nil.
local frame = Platform.frameOf(ride and ride.entityId)
typed/builtin//systems/characterController/characterController/physics/platform/M/hold
M.hold(entityId: string?, from: Ride?, carry: Carry?, dt: number?, into: Ride?) -> Ride?
Hold the body a character stands on: the entity and the pose it is
drawn at now. The character's next carry measures how far the body
moved it since. Held again on the body the character already rode
(from, with the carry that ride gave this frame over its dt
seconds), the ride's trail goes on; a ride on another body starts its
trail afresh.
Parameters
entityIdstring(optional) — The entity the ground cast hit (hit.entityId).fromRide(optional) — The ride the character stood on as this frame began, or nil.carryCarry(optional) — This frame'scarryfromfrom, or nil.dtnumber(optional) — The seconds this frame spans: the timecarrycovers.intoRide(optional) — A ride the caller keeps (Platform.newRide) to write the ride into, which may befromitself: held so frame after frame, riding a body allocates nothing. A new ride when left out.
Returns Ride? — The ride (into when given), or nil when no entity answers to the id.
local ride = Platform.hold(groundHit.entityId)
ride = Platform.hold(groundHit.entityId, ride, carry, dt)
ride = Platform.hold(groundHit.entityId, ride, carry, dt, heldRide)
typed/builtin//systems/characterController/characterController/physics/platform/M/keptPast
M.keptPast(keptX: number, keptZ: number, vx: number, vz: number) -> (number, number)
The part of a kept motion (steer) that a wall leaves the
character with once the wall pass cut its step to the velocity
(vx, vz): the kept motion along that velocity, and no more of it than
the velocity holds. A wall met head on leaves nothing of it, and one
slid along leaves the part along the wall.
Parameters
keptXnumber— The kept motion across the frame, X.keptZnumber— The kept motion, Z.vxnumber— The velocity the wall pass left, across the frame, X.vznumber— The velocity the wall pass left, Z.
Returns (number, number) — keptX, keptZ after the wall.
keptX, keptZ = Platform.keptPast(keptX, keptZ, vx, vz)
typed/builtin//systems/characterController/characterController/physics/platform/M/newCarry
M.newCarry() -> Carry
A carry for a caller to keep and hand to carry as the carry it
writes into, so a character riding a body frame after frame allocates
nothing.
Returns Carry — The Carry, owned by the caller.
local heldCarry = Platform.newCarry()
typed/builtin//systems/characterController/characterController/physics/platform/M/newRide
M.newRide() -> Ride
A ride for a caller to keep and hand to hold as the ride it
writes into, so a character riding a body frame after frame allocates
nothing. It holds no body until hold writes one.
Returns Ride — The Ride, owned by the caller.
local heldRide = Platform.newRide()
typed/builtin//systems/characterController/characterController/physics/platform/M/placement
M.placement(ride: Ride) -> (number?, number?, number?, number?, number?, number?, number?)
Where the body of ride stands and how it is turned, as seven
numbers (x, y, z, qx, qy, qz, qw, world space), read the cheapest way
that changes whenever the pose the frame draws it at changes: its drawn
pose (Physics.drawnPose) for a body drawn blended between ticks when the
ride was held, its transform otherwise. Two readings are the same exactly
when the body has not moved between them; a reading is compared with
another reading of this function, never with pose.
Parameters
rideRide— The ridePlatform.holdreturned.
Returns (number?, number?, number?, number?, number?, number?, number?) — x, y, z, qx, qy, qz, qw, or nil when no entity answers to the id.
local x, y, z, qx, qy, qz, qw = Platform.placement(ride)
typed/builtin//systems/characterController/characterController/physics/platform/M/pose
M.pose(entityId: string) -> (number?, number?, number?, Quat?)
Where an entity is drawn this frame and how it is turned there, in
world space: its Physics.drawnPose, which is the pose the simulation
blends a dynamic body to between its last two ticks, and the entity's
own transform for anything the simulation does not blend.
Parameters
entityIdstring— The entity to read.
Returns (number?, number?, number?, Quat?) — x, y, z, rotation, or nil when no entity answers to the id.
local x, y, z, q = Platform.pose(liftId)
typed/builtin//systems/characterController/characterController/physics/platform/M/stateFrame
M.stateFrame(entityId: string, frame: string?, stated: string?) -> string?
State the pose of the character entityId relative to frame for
the other peers of a multiplayer session (multiplayer.setPoseFrame),
or in the world with nil, when it differs from stated, the frame
stated last: every other peer then draws the character where it draws
the body it rides.
Parameters
entityIdstring— The character's entity.framestring(optional) — The entity it rides (Platform.frameOf), or nil.statedstring(optional) — The frame this returned last time, or nil.
Returns string? — The frame stated now.
statedFrame = Platform.stateFrame(self.entityId, Platform.frameOf(ride and ride.entityId), statedFrame)
typed/builtin//systems/characterController/characterController/physics/platform/M/steer
M.steer(vx: number, vz: number, walkX: number, walkZ: number, lerp: number, keptX: number, keptZ: number) -> (number, number)
Air control for a character carrying the motion it kept from a body
it left (keptX, keptZ, the across-the-frame part of velocityAt): the
character's velocity steers toward that motion plus the walk it asks
for, so with no walk asked it goes on moving with the body it left, the
way a crate thrown off a moving deck does, and the walk it asks for
moves it relative to that.
Parameters
vxnumber— The character's velocity across the frame, X.vznumber— The character's velocity across the frame, Z.walkXnumber— The walk it asks for across the frame, X (air control's target).walkZnumber— The walk it asks for, Z.lerpnumber— How far toward the target this step steers, from 0 (not at all) to 1.keptXnumber— The kept motion across the frame, X.keptZnumber— The kept motion, Z.
Returns (number, number) — vx, vz steered.
vx, vz = Platform.steer(vx, vz, moveX, moveZ, airLerp, keptX, keptZ)
typed/builtin//systems/characterController/characterController/physics/platform/M/turned
M.turned(turn: Quat, r: Quat) -> Quat
Turn the rotation r by turn in world space (turn * r): a
character's entity rotation turned by the turn its ride carried it.
Parameters
turnQuat— The turn, a unit quaternion.rQuat— The rotation it turns.
Returns Quat — The turned rotation.
local q = Platform.turned(carry.turn, entity.localRotation)
typed/builtin//systems/characterController/characterController/physics/platform/M/turnedParts
M.turnedParts(turn: Quat, rx: number, ry: number, rz: number, rw: number) -> (number, number, number, number)
turned with the rotation it turns given as four numbers, and the
turned rotation answered as four numbers: a turn made every frame
allocates nothing.
Parameters
turnQuat— The turn, a unit quaternion.rxnumber— The rotation it turns, X.rynumber— Y.rznumber— Z.rwnumber— W.
Returns (number, number, number, number) — qx, qy, qz, qw, the turned rotation.
local qx, qy, qz, qw = Platform.turnedParts(carry.turn, rx, ry, rz, rw)
typed/builtin//systems/characterController/characterController/physics/platform/M/velocityAt
M.velocityAt(ride: Ride?, carry: Carry?, dt: number) -> (number, number, number)
How fast the body of ride moves the feet, in world space: the
motion a character standing there keeps as momentum when it leaves the
body. A dynamic body answers with this frame's carry velocity, the
velocity the simulation integrates for it. Anything else (a kinematic
body a script moves by localPosition writes or Physics.setVelocity,
a transform something animates) answers with its velocity averaged over
the ride's last tenth of a second (and at least its last six frames),
this frame's carry included: a kinematic body's velocity is worked out
from how far it moved on each physics tick, so a single frame's reading
depends on how the frames fell against the ticks. A body that has gone
away answers with the ride's trail as it stood.
Parameters
rideRide(optional) — The ride the character stood on, or nil.carryCarry(optional) — This frame'scarryfrom that ride, or nil.dtnumber— The seconds this frame spans: the timecarrycovers.
Returns (number, number, number) — vx, vy, vz in m/s; all zero with no ride.
local vx, vy, vz = Platform.velocityAt(ride, carry, dt)
typed/builtin//systems/characterController/characterController/physics/push/M/into
M.into(hit: any?, walkX: number, walkZ: number, pushForce: number, dt: number, frame: Frame.Frame?) -> number
Push the dynamic body a character's walk met. hit is the wall
the walk ran into (Walls.move's hit, a cast hit naming the collider's
entity); the body it rides is pushed when it is dynamic. The push runs
across the frame the character stands in, along the way into the surface
it met (the hit's normal, turned in and laid flat), through the body's
centre of mass: the impulse is the one that brings the body's speed that
way up to the part of the walk going into it, bounded by
pushForce * dt. A body already moving away at that speed or faster
takes no push.
Parameters
hitany(optional) — The cast hit the walk met:{ entityId, normal }.walkXnumber— The walk the character asks for along the frame's X, in m/s.walkZnumber— The walk the character asks for along the frame's Z, in m/s.pushForcenumber— The most force the character pushes with, in newtons; 0 or below pushes nothing.dtnumber— The time the push acts over, in seconds: the frame's.frameFrame.Frame(optional) — The frame the character stands in; defaults to the world's.
Returns number — The impulse given, in newton-seconds: 0 for a hit on no dynamic body, a walk that does not go into it, or a body already moving away.
local impulse = Push.into(step.hit, vx, vz, 400, dt, frame)
typed/builtin//systems/characterController/characterController/physics/walls/M/castBody
M.castBody(x: number, y: number, z: number, dirX: number, dirZ: number, height: number, radius: number, skinWidth: number, maxSlopeAngle: number, selfId: string, distance: number?, frame: Frame.Frame?) -> any
Sweep the character's capsule from (x, y, z) (its feet) in
direction (dirX, 0, dirZ) and report the wall it runs into within
distance + skinWidth of its own surface. Because the whole body is
swept, a passage narrower than 2 * radius blocks the character even
when nothing stands on its centre line.
The sweep starts above the ground band — the depth a cap of radius
reaches below ground of maxSlopeAngle, which is how far into the
slope the body's own lower cap sits while it stands there. Below that
line the surface belongs to the ground and step passes; above it the
sweep runs clear of the ground and reports the outward normal of the
surface standing across the path.
A contact whose surface faces up or down — ramps the character walks
up, to maxSlopeAngle, and anything directly overhead — belongs to
the ground and ceiling passes. A contact on the rim of a surface, the
edge of a stair or a curb, stands across the path like a wall, and the
step pass of move decides whether the body climbs it. The sweep runs
on up along walkable ground it meets, the way the body climbs it, so a
wall standing at the
top of a ramp stops the walk whether it is part of the ramp's collider
or another; it carries on past a surface overhead to the surface that
stands across the path, and past the colliders the body
carries: selfId and every entity parented under it. The sweep is cast
for selfId as its mover (Carry.castOptions), so a one-way platform it
passes, a collider the contact filter lets it pass and a platform it is
dropping through stand in nobody's way. Another character stands in the
way as its capsule (physics.characters), unless the contact filter
lets the two pass; a hit on one carries character = true.
Parameters
xnumber— Character feet X.ynumber— Character feet Y.znumber— Character feet Z.dirXnumber— Horizontal movement direction X (normalized).dirZnumber— Horizontal movement direction Z (normalized).heightnumber— Character capsule height.radiusnumber— Character capsule radius.skinWidthnumber— How far past the body's own surface the sweep reaches.maxSlopeAnglenumber— Steepest surface, in degrees, the character walks on.selfIdstring— The body's entity ID; the sweep passes through the colliders on it and on the entities parented under it.distancenumber(optional) — How far the body travels this step; the sweep covers it plusskinWidth. Omitted, the sweep reachesskinWidthalone.frameFrame.Frame(optional) — The frame the character stands in: the capsule stands along its up and sweeps across it. Defaults to the world's.
Returns any — Hit table { entityId, point, normal, distance, startedInside, character? }, or nil when the body's path is clear. distance is how far the body travels before its surface touches the wall; normal is in world space.
local hit = Walls.castBody(px, py, pz, dx, dz, 1.8, 0.3, 0.01, 45, selfId)
local hit = Walls.castBody(px, py, pz, dx, dz, 1.8, 0.3, 0.01, 45, selfId, stepLength)
typed/builtin//systems/characterController/characterController/physics/walls/M/castDirection
M.castDirection(x: number, y: number, z: number, dirX: number, dirZ: number, radius: number, skinWidth: number, selfId: string, frame: Frame.Frame?) -> any
Cast a horizontal wall-detection ray from (x, y, z) in
direction (dirX, 0, dirZ) across the frame. Ray length is
radius + skinWidth.
Parameters
xnumber— Character centre X.ynumber— Character centre Y (sample height).znumber— Character centre Z.dirXnumber— Horizontal direction X (normalized).dirZnumber— Horizontal direction Z (normalized).radiusnumber— Character capsule radius (ray starts at the centre).skinWidthnumber— Extra margin for depenetration.selfIdstring— The body's entity ID; the ray passes through the colliders on it and on every entity parented under it.frameFrame.Frame(optional) — The frame the character stands in; defaults to the world's.
Returns any — Raycast hit table, or nil when nothing in front.
local hit = Walls.castDirection(px, py, pz, dx, dz, 0.3, 0.01, selfId)
typed/builtin//systems/characterController/characterController/physics/walls/M/headroom
M.headroom(x: number, y: number, z: number, sx: number, sz: number, maxRise: number, height: number, radius: number, skinWidth: number, maxSlopeAngle: number, selfId: string, frame: Frame.Frame?) -> number
How far the body can rise along up from its feet before its head
meets something overhead: the room a step up has. The body is swept up
from (x, y, z) moved (sx, sz) across the frame, over at most maxRise.
Parameters
xnumber— Character feet X.ynumber— Character feet Y.znumber— Character feet Z.sxnumber— Offset of the feet across the frame along X.sznumber— Offset of the feet across the frame along Z.maxRisenumber— The furthest the body rises.heightnumber— Character capsule height.radiusnumber— Character capsule radius.skinWidthnumber— The clearance the body keeps from what is overhead.maxSlopeAnglenumber— Steepest surface, in degrees, the character walks on.selfIdstring— The body's entity ID; the colliders it carries are nothing overhead.frameFrame.Frame(optional) — The frame the character stands in; defaults to the world's.
Returns number — The rise, from 0 (no room) to maxRise.
local lift = Walls.headroom(px, py, pz, 0, 0, 0.3, 1.8, 0.3, 0.01, 45, selfId)
typed/builtin//systems/characterController/characterController/physics/walls/M/move
M.move(x: number, y: number, z: number, dx: number, dz: number, height: number, radius: number, skinWidth: number, maxSlopeAngle: number, selfId: string, frame: Frame.Frame?, cameFrom: Point?, stepHeight: number?, into: Step?) -> Step
The horizontal pass of a character's step. Puts a body that
overlaps a wall back outside it (pushOut), then carries it along the
step (dx, dz) it asked for: the body stops skinWidth short of the
first wall the step runs into, and what remains of the step slides
along that wall, and along the next one the slide meets. However long
the step, the body ends outside every wall, so the walk it asks for on
the next frame starts clear of them, away from a wall it rests against
as much as along it. Another character is a wall to the step
(physics.characters): the body stops short of it and slides around it.
Parameters
xnumber— Character feet X.ynumber— Character feet Y.znumber— Character feet Z.dxnumber— The step asked for along X, in world units.dznumber— The step asked for along Z, in world units.heightnumber— Character capsule height.radiusnumber— Character capsule radius.skinWidthnumber— The clearance the body keeps from a wall.maxSlopeAnglenumber— Steepest surface, in degrees, the character walks on.selfIdstring— The body's entity ID; the colliders on it and on the entities parented under it are no walls to the step.frameFrame.Frame(optional) — The frame the character stands in:dx, dzand every answer run across it. Defaults to the world's.cameFromPoint(optional) — Where the body's feet last stood clear of every wall, in world space: the push out of a wall the body's centre has crossed since takes it back to that side (pushOut). A mover keeps it as the feet position of its last step that began withoverlappedfalse, or, after a step whose push left itcleared, as where that push put the feet: a wall that moved into the body (a body sliding into it) moves the side it came from along with the push.stepHeightnumber(optional) — The tallest step the body climbs. A wall that cuts the step short is walked again with the body lifted by up to this much, as far as the room over its head allows, and that walk is taken when it carries the body further and comes down on walkable ground: the riser of a stair or a curb is climbed, and a face taller than a step stays a wall. Left out or 0, the body climbs nothing.intoStep(optional) — Optional step of the caller's own (Walls.newStep) to write the answer into: a mover stepping every frame into one step allocates nothing. Itshitis then the module's own, rewritten by the nextmove. A new step, with a hit of its own, when left out.
Returns Step — { dx, dz, pushX, pushZ, overlapped, cleared, blocked, hit, stepUp } (into when given). dx, dz is where the body goes, push included; pushX, pushZ is the part of it that put the body back outside a wall; overlapped is true when the body overlapped a wall where the step began; cleared is true when the push leaves it outside every wall, where a mover takes its next cameFrom from; blocked is true when the step met a wall and carried the body no further towards where it asked to go (pressed into a wall head on, wedged where two meet, or walking into ground too steep to climb); hit is the first wall the step ran into, or nil; stepUp is how far above the feet the ground the step climbed onto stands, 0 for a step that climbed nothing.
local step = Walls.move(px, py, pz, vx * dt, vz * dt, 1.8, 0.3, 0.01, 45, selfId)
local step = Walls.move(px, py, pz, vx * dt, vz * dt, 1.8, 0.3, 0.01, 45, selfId, frame, clearAt, 0.3)
typed/builtin//systems/characterController/characterController/physics/walls/M/newStep
M.newStep() -> Step
A step for a mover to keep and hand to move as the step it
writes into, so a character stepping frame after frame allocates nothing.
Returns Step — The Step, owned by the caller.
local heldStep = Walls.newStep()
typed/builtin//systems/characterController/characterController/physics/walls/M/pushOut
M.pushOut(x: number, y: number, z: number, height: number, radius: number, skinWidth: number, maxSlopeAngle: number, selfId: string, frame: Frame.Frame?, cameFrom: Point?) -> (number, number, boolean, boolean)
Find the push that puts a body overlapping a wall back outside it. A body comes to overlap a wall when something other than its own walk carries it there: it was placed there, a moving body shoved it in, the wall appeared around it, or a long frame's step reached into it. Every sweep begun inside that wall answers about the overlap rather than the path, so this is what lets the body move again.
A wall has two ways out across the frame: the overlap's shortest way
out, the normal a sweep begun inside reports, and the way straight
back through the surface. The push takes the shortest way out, unless
cameFrom, where the body last stood clear of every wall, stands more
than a body radius behind that way out: then the body's centre has
crossed the surface since, and the push takes it back to the side it
came from. A body crossing a mesh collider's surface, a closed but
hollow shell among them, so stays on the side it walked up from.
The push's length is measured by sweeping the same body back in from
one body width out along that way: it ends skinWidth clear of the
surface. Each push reaches at most that body width, which is as deep as
a body reaches into a surface, so a push never carries the body across
a collider to a surface on its far side. A start that lands inside the
same collider, on another of its surfaces (the far wall of a passage
one mesh bounds on both sides), comes in by half until it stands clear
of it, so a body in a passage narrower than two body widths is put back
into the passage. A body inside that collider from every start is
deeper inside a solid than its own width, and is pushed a body width at
a time, along the same way. A body in a corner is pushed out of each
wall in turn. Ground and ceilings, contacts facing up or down, belong to
the ground and ceiling passes and push nothing here, and neither does a
collider the body carries, on selfId or on an entity parented under
it.
Parameters
xnumber— Character feet X.ynumber— Character feet Y.znumber— Character feet Z.heightnumber— Character capsule height.radiusnumber— Character capsule radius.skinWidthnumber— The clearance the body is left with.maxSlopeAnglenumber— Steepest surface, in degrees, the character walks on.selfIdstring— The body's entity ID; the colliders on it and on the entities parented under it push nothing.frameFrame.Frame(optional) — The frame the character stands in; defaults to the world's.cameFromPoint(optional) — Where the body's feet last stood clear of every wall, in world space. Left out, every push takes the overlap's shortest way out.
Returns (number, number, boolean, boolean) — pushX, pushZ, overlapped, clear: the push across the frame (0, 0 for a body that overlaps no wall), whether the body overlapped a wall where it stands, and whether the push leaves it outside every wall.
local px, pz = Walls.pushOut(x, y, z, 1.8, 0.3, 0.01, 45, selfId)
local px, pz, overlapped = Walls.pushOut(x, y, z, 1.8, 0.3, 0.01, 45, selfId, nil, lastClear)
typed/builtin//systems/characterController/characterController/physics/walls/M/sameSeat
M.sameSeat(a: any?, b: any?) -> boolean
Whether two seat answers are the same: both nil, or the same
collider met at the same distance, from the same side, with the same
normal and the same surface motion. Two answers seat wrote into the
same table (its into) are one answer, so a rest kept to compare with
holds its seat in a table of its own.
Parameters
aany(optional) — Oneseatanswer.bany(optional) — The other.
Returns boolean — True when they are the same.
if not Walls.sameSeat(heldSeat, Walls.seat(px, py, pz, 1.8, 0.3, 0.01, 45, selfId)) then rest = nil end
typed/builtin//systems/characterController/characterController/physics/walls/M/seat
M.seat(x: number, y: number, z: number, height: number, radius: number, skinWidth: number, maxSlopeAngle: number, selfId: string, frame: Frame.Frame?, into: { [string]: any }?) -> any
The first surface the body meets swept down onto the ground under
its feet: the capsule castBody sweeps (the body above the ground band)
cast down along up from where it stands, as far as a few skins below the
feet. A body resting on ground meets that ground at the same distance
every frame, with the same normal and surface motion, for as long as
nothing around it changes; a collider that comes to overlap the body
answers first, at no distance, and ground that goes away, starts
moving, stops answering the body (the contact filter, a one-way
collider, Physics.passThrough) or rises into it answers differently or
not at all. The cast passes the colliders the body carries, on selfId
and on every entity parented under it, and meets the rest as the body
does (Carry.castOptions).
Parameters
xnumber— Character feet X.ynumber— Character feet Y.znumber— Character feet Z.heightnumber— Character capsule height.radiusnumber— Character capsule radius.skinWidthnumber— The clearance the body keeps above the ground.maxSlopeAnglenumber— Steepest surface, in degrees, the character walks on.selfIdstring— The body's entity ID.frameFrame.Frame(optional) — The frame the character stands in; defaults to the world's.into{ [string]: any }(optional) — Optional hit table of the caller's own to write the answer into (Carry.hit, the vectors asvectorvalues): a caller asking every frame into one table allocates nothing.
Returns any — Hit table { entityId, point, normal, distance, startedInside, surfaceVelocity? } (into when given), or nil when the sweep meets nothing.
local seat = Walls.seat(px, py, pz, 1.8, 0.3, 0.01, 45, selfId)
typed/builtin//systems/characterController/characterController/physics/walls/M/slideAlongWall
M.slideAlongWall(moveX: number, moveZ: number, normalX: number, normalZ: number) -> (number, number)
Compute a wall-slide direction given the desired horizontal
movement and a wall normal. Strips the component of move that
goes into the wall; returns the input unchanged when the movement
isn't pressing into the wall (dot >= 0) or the normal is
effectively zero in the XZ plane.
Parameters
moveXnumber— Desired horizontal movement X.moveZnumber— Desired horizontal movement Z.normalXnumber— Wall surface normal X.normalZnumber— Wall surface normal Z.
Returns (number, number) — Adjusted moveX, moveZ that slides along the wall.
local mx, mz = Walls.slideAlongWall(dx, dz, nx, nz)
typed/builtin//systems/characterController/characterController/physics/walls/M/standsAt
M.standsAt(placed: Point?, x: number, y: number, z: number) -> boolean
Whether feet standing at (x, y, z) stand at placed, the point a
mover last put them at, to the precision a position is stored at. A
mover keeps the cameFrom it hands move only while this holds: a
body standing anywhere else was moved by something other than the
mover (a teleport, a respawn, a script), and has no side it came from.
Parameters
placedPoint(optional) — Where the mover last put the feet, in world space, or nil before it has put them anywhere.xnumber— Feet X now.ynumber— Feet Y now.znumber— Feet Z now.
Returns boolean — True when the feet stand at placed.
if not Walls.standsAt(placedAt, px, py, pz) then clearAt = nil end
typed/builtin//systems/ik/ik/chain/M/bindSlots
M.bindSlots(c: any?, boneOrder: { string }) -> boolean
Point the chain at a different bone order than the rig's own, mapping
each chain bone to its slot in boneOrder. A pose buffer whose layout is
not the rig's index order needs this before readPose or writePose.
Parameters
cany(optional) — The chain.boneOrder{ string }— The pose layout's bone-name order.
Returns boolean — True when every chain bone was found in boneOrder.
chain.bindSlots(c, layout.boneOrder)
typed/builtin//systems/ik/ik/chain/M/blendToward
M.blendToward(c: any?, snap: { { number } }, weight: number)
Blend the chain's local rotations from snap toward their solved values
by weight. Weight 0 restores the snapshot exactly; weight 1 keeps the
solve. Callers run forward kinematics afterwards.
Parameters
cany(optional) — The chain.snap{ { number } }— A snapshot fromchain.snapshot.weightnumber— Blend factor in[0, 1].
chain.blendToward(c, before, 0.35)
typed/builtin//systems/ik/ik/chain/M/forward
M.forward(c: any?, fromIndex: number?)
Run forward kinematics from fromIndex to the tip, filling model-space
positions and rotations from the chain's locals and its base transform.
Solvers call this after every rotation they apply so later bones see the
updated frame. Each bone's model-space position and rotation are written
into the tables the chain already holds for them, so a pass allocates
nothing.
Parameters
cany(optional) — The chain.fromIndexnumber(optional) — First chain index to recompute; defaults to 1.
chain.forward(c)
typed/builtin//systems/ik/ik/chain/M/forwardBase
M.forwardBase(c: any?, pose: { number }, stride: number)
Compute the chain's base frame by running forward kinematics down the bones above its root, reading them from a pose array. An arm hangs off a shoulder and a leg off a hip, so a chain solved against an identity base would be positioned at the character's origin instead of at its limb. Only the ancestor path is walked, not the whole skeleton, and the frame is written into the chain's own base tables.
Parameters
cany(optional) — The chain.pose{ number }— Flat pose array ofstride * boneCountnumbers.stridenumber— Numbers per bone; the pose buffer default is 10.
chain.forwardBase(c, poseArray, 10)
typed/builtin//systems/ik/ik/chain/M/fromBones
M.fromBones(bones: { any }, rootName: string, tipName: string) -> any?
Build a chain by walking parents from tipName up to rootName. The
walk fails when the tip is not a descendant of the root, or when either
bone is absent from the rig.
Parameters
bones{ any }— Rig bones as{ name, parent, rest = { t, r, s } };parentis 0-based with -1 for a root.rootNamestring— Name of the bone the chain starts at.tipNamestring— Name of the bone the chain ends at.
Returns any? — The chain, or nil when the run cannot be resolved.
local c = chain.fromBones(rig.bones, "leftupperleg", "leftfoot")
typed/builtin//systems/ik/ik/chain/M/fromLeanRoles
M.fromLeanRoles(bones: { any }, roles: { [string]: string }) -> any?
Build the run from the lowest spine bone to the head that a lean bends: a head target that stands off the body is reached by bending the whole run. Falls back through shorter runs so a rig without a lower spine still resolves.
Parameters
bones{ any }— Rig bones as{ name, parent, rest }.roles{ [string]: string }— Canonical role -> bone name map.
Returns any? — The chain, or nil when the rig has no neck-and-head run.
local c = chain.fromLeanRoles(rig.bones, rig.roles)
typed/builtin//systems/ik/ik/chain/M/fromLookRoles
M.fromLookRoles(bones: { any }, roles: { [string]: string }) -> any?
Build the spine-to-head chain a look-at solve turns. Falls back through progressively shorter runs so a rig without an upper chest still resolves.
Parameters
bones{ any }— Rig bones as{ name, parent, rest }.roles{ [string]: string }— Canonical role -> bone name map.
Returns any? — The chain, or nil when the rig has no neck-and-head run.
local c = chain.fromLookRoles(rig.bones, rig.roles)
typed/builtin//systems/ik/ik/chain/M/fromRole
M.fromRole(bones: { any }, roles: { [string]: string }, role: string) -> any?
Build a chain for a canonical limb role, resolved through a rig's role
map so the same spec works on any humanoid mesh. Recognised roles are
leftarm, rightarm, leftleg, and rightleg.
Parameters
bones{ any }— Rig bones as{ name, parent, rest }.roles{ [string]: string }— Canonical role -> bone name map, as carried byecs.RetargetProfile.rolestring— The limb role to resolve.
Returns any? — The chain, or nil when the role is unknown or the rig lacks its bones.
local c = chain.fromRole(rig.bones, rig.roles, "leftleg")
typed/builtin//systems/ik/ik/chain/M/limbRoles
M.limbRoles() -> { string }
The limb roles fromRole accepts, for error messages and tooling.
Returns { string } — The limb role names.
log.info(table.concat(chain.limbRoles(), ", "))
typed/builtin//systems/ik/ik/chain/M/orientTip
M.orientTip(c: any?, rotation: { number }, weight: number?)
Turn the chain's tip bone until its model-space rotation is rotation,
rewriting only the tip's local rotation. A limb solver places the tip where
the target is; this gives the tip, a hand or a foot, the orientation the
target states.
Parameters
cany(optional) — The chain, with forward kinematics current.rotation{ number }— The model-space rotation the tip should have.weightnumber(optional) — Blend from the tip's incoming local rotation (0) to the wanted one (1); defaults to 1.
chain.orientTip(c, handRotation, 1)
typed/builtin//systems/ik/ik/chain/M/parentRotation
M.parentRotation(c: any?, i: number) -> { number }
The model-space rotation of chain bone i's parent — the frame its
local rotation is expressed in.
Parameters
cany(optional) — The chain.inumber— Chain index.
Returns { number } — The parent's model-space rotation.
local frame = chain.parentRotation(c, 2)
typed/builtin//systems/ik/ik/chain/M/readPose
M.readPose(c: any?, pose: { number }, stride: number)
Seed the chain's local transforms from a flat pose array, reading each bone from its slot in the pose's bone order into the tables the chain already holds for it.
Parameters
cany(optional) — The chain.pose{ number }— Flat pose array ofstride * boneCountnumbers.stridenumber— Numbers per bone; the pose buffer default is 10.
chain.readPose(c, poseArray, 10)
typed/builtin//systems/ik/ik/chain/M/rotateGlobal
M.rotateGlobal(c: any?, i: number, q: { number })
Apply a model-space rotation to chain bone i, rewriting its local
rotation so the change survives the next forward-kinematics pass. This is
how every solver moves a bone. The local rotation is written into the table
the chain holds for it.
Parameters
cany(optional) — The chain.inumber— Chain index to rotate.q{ number }— The model-space rotation to pre-multiply onto the bone.
chain.rotateGlobal(c, 1, rigmath.shortestArc(current, wanted))
typed/builtin//systems/ik/ik/chain/M/setBase
M.setBase(c: any?, pos: { number }, rot: { number })
Set the model-space transform the chain's root hangs from — the pose of the root bone's parent. Defaults to the identity frame.
Parameters
cany(optional) — The chain.pos{ number }— Model-space position of the root's parent.rot{ number }— Model-space rotation of the root's parent.
chain.setBase(c, parentPos, parentRot)
typed/builtin//systems/ik/ik/chain/M/snapshot
M.snapshot(c: any?) -> { { number } }
Copy the chain's current local rotations so a solve can be blended back toward the incoming pose by weight.
Parameters
cany(optional) — The chain.
Returns { { number } } — An array of local rotations, parallel to the chain's bones.
local before = chain.snapshot(c)
typed/builtin//systems/ik/ik/chain/M/spreadTwist
M.spreadTwist(c: any?, share: number)
Share a tip's twist with the bone before it: the tip's turn about the bone before it (a hand's about the forearm) is taken partly by that bone, so the skin twists along the forearm rather than wringing at the wrist. The tip keeps its model-space rotation.
Parameters
cany(optional) — The chain, with forward kinematics current.sharenumber— The share of the twist the bone before the tip takes, 0 to 1.
chain.spreadTwist(c, 0.5)
typed/builtin//systems/ik/ik/chain/M/tipDistance
M.tipDistance(c: any?, point: { number }) -> number
Distance from the chain's tip to a model-space point, the convergence measure every iterative solver reports against.
Parameters
cany(optional) — The chain.point{ number }— The point to measure to.
Returns number — The distance.
local err = chain.tipDistance(c, target)
typed/builtin//systems/ik/ik/chain/M/tipPosition
M.tipPosition(c: any?) -> { number }
The model-space position of the chain's tip after the last forward kinematics pass.
Parameters
cany(optional) — The chain.
Returns { number } — The tip position.
local tip = chain.tipPosition(c)
typed/builtin//systems/ik/ik/chain/M/writePose
M.writePose(c: any?, pose: { number }, stride: number)
Write the chain's solved local rotations back into a flat pose array. Translations and scales are left as the incoming pose set them, because a chain solve changes orientation only.
Parameters
cany(optional) — The chain.pose{ number }— Flat pose array to write into, modified in place.stridenumber— Numbers per bone; the pose buffer default is 10.
chain.writePose(c, poseArray, 10)
typed/builtin//systems/ik/ik/spine/M/frame
M.frame(bones: { any }, roles: { [string]: string }) -> (Frame?, string?)
What the body rules read from a humanoid rig's rest pose: which way it is up, forward and to its right in model space, the head bone's rest rotation, the torso's and the leg's lengths and the rest heights.
Parameters
bones{ any }— The rig's bones,{ name, parent, rest = { t, r } }.roles{ [string]: string }— The rig's canonical role -> bone name map.
Returns (Frame?, string?) — The frame, or nil and the reason when the rig lacks the hips, the head or the legs.
local frame, why = spine.frame(rig.bones, rig.roles)
typed/builtin//systems/ik/ik/spine/M/headRotation
M.headRotation(frame: Frame, look: V) -> V
The head bone's model-space rotation for a head looking as look does.
Parameters
frameFrame— The body's frame.lookV— The head's model-space rotation as a camera frame.
Returns V — The head bone's rotation.
typed/builtin//systems/ik/ik/spine/M/headTurn
M.headTurn(frame: Frame, look: V) -> V
The turn from a head looking along the body's forward, upright, to a head
at look: the rotation the head bone takes on top of its rest rotation.
Parameters
frameFrame— The body's frame.lookV— The head's model-space rotation as a camera frame (-Z where it looks, +Y up).
Returns V — The model-space rotation.
typed/builtin//systems/ik/ik/spine/M/pelvisTilt
M.pelvisTilt(frame: Frame, posture: Posture) -> V
The pelvis's share of the torso's tilt, as a model-space rotation to put on the hips' animated rotation.
Parameters
frameFrame— The body's frame.posturePosture— The posture.
Returns V — The rotation.
typed/builtin//systems/ik/ik/spine/M/posture
M.posture(frame: Frame, head: V, look: V, ankleHeight: number, unitsPerMetre: number, proportions: { torso: number?, leg: number? }?, support: V?) -> Posture
Where the hips stand for a head at head looking as look does: over the
feet at support, a little behind them against the way the head faces and
further back in a squat, at the height a torso's length from the head
leaves them, between a full squat and straight legs over the feet at
ankleHeight. A head too far or too high for that draws the hips off the
feet toward it; one too low sits them lower behind the feet.
Parameters
frameFrame— The body's frame.headV— The head bone's model-space position.lookV— The head's model-space rotation as a camera frame.ankleHeightnumber— The height of the ankles the feet stand on, model space, along up.unitsPerMetrenumber— The rig's units in a metre.proportions{ torso: number?, leg: number? }(optional) — The torso's and the leg's lengths in the pose being solved as shares of the rest pose's, for an animation whose bone translations differ from it; one each when nil.supportV(optional) — The point between the feet, model space; the model's origin when nil.
Returns Posture — The posture.
typed/builtin//systems/ik/ik/spine/M/solve
M.solve(c: any?, opts: any?) -> boolean
Bend the run from the lowest spine bone to the head so the head bone
stands at opts.target, then turn the head bone to opts.rotation. The
chest first turns a share of the way the head has; the bend is spread over
every bone below the head in passes, each pass turning each bone a share of
the way toward the target, and no bone bends past its limit from where the
animation put it.
Parameters
cany(optional) — The chain, the head its last bone; the caller runs forward kinematics on it first.optsany(optional) —{ target, rotation?, chestTurn?, up?, weight? }, model space.
Returns boolean — True when the chain was solved, false when it is too short or has no target.
typed/builtin//systems/procgen/Generator/public/apply
public.apply()
Swap the generator for the asset it makes, in place: the frame being
presented is written as a durable bundle, and the Generator component is
replaced by an Asset component standing that bundle on the same entity.
The result renders with no graph, no evaluation and no Generator — like
applying a modifier — and nothing about it depends on the graph any more.
The bundle is named by what it holds: the graph as it stands, the params,
the outputs, the live state it read and the frame. Every copy applying the
same cook references ONE bundle, so six generators on one prop become six
references to one asset. One frame is what a flatten takes, so a graph that
moves collapses to wherever its playhead stands. An asset-reference output
(a graph ending in a write sink) is already durable and is carried in the
bundle as a reference to it. A graph of the call form flattens what it
shows: the value each io.output stands, under the name it was shown under.
Returns The bundle the entity now stands.
local bundle = generator:apply()
typed/builtin//systems/procgen/Generator/public/cancelCook
public.cancelCook()
Cancel the in-flight cook, if any — a queued request that hasn't started yet, or a cook already running (it stops at its next checkpoint). The previous output stays realized either way. A graph in the call form then asks no cook until the graph or its inputs change.
Returns true when a cook was cancelled; false when the generator was idle.
generator:cancelCook()
typed/builtin//systems/procgen/Generator/public/cookError
public.cookError() -> string?
Why the latest cook of the graph, or the realizing of what it cooked, failed, while it does; nil otherwise. The
same text as playback().cookError, read without building the rest of that report, so a caller waiting a frame at a
time for the generator to stand ready can watch for a failure every frame.
Returns string? — The failure, or nil.
if generator:cookError() ~= nil then print(generator:cookError()) end
typed/builtin//systems/procgen/Generator/public/describeGraph
public.describeGraph()
What the bound graph declares, from the graph the generator already
holds: { id, description, inputs, outputs }. inputs is
{ [name] = { type, default, min, max, options, description, value, animated } },
options being the values a choice input may hold,
description being what the graph says the input does, value being
the generator's override where it has one and the declared default
otherwise, and animated whether that value changes over the graph's time;
outputs is the declared output names, sorted. Nil while no graph is bound.
Returns The description, or nil.
for name, input in pairs(generator:describeGraph().inputs) do print(name, input.type) end
typed/builtin//systems/procgen/Generator/public/getFrame
public.getFrame()
The graph frame being presented.
Returns The frame; on a timeline with no end, the frame the running time falls in at the timeline's rate.
local f = generator:getFrame()
typed/builtin//systems/procgen/Generator/public/getTime
public.getTime()
The graph time being presented, in seconds.
Returns Seconds along the graph's timeline.
local t = generator:getTime()
typed/builtin//systems/procgen/Generator/public/heldBreakdown
public.heldBreakdown()
The Luau bytes the generator holds: each field of its state, and of its play when it stands one, largest first;
cacheBytes, what its node caches hold; and heaviestEntries, the largest entries of its play's node cache. Walks
everything the state holds, so it costs as much as the state is large.
Returns { generator = { { field, bytes } }, play = { { field, bytes } }?, cacheBytes, heaviestEntries = { { id, policy, bytes, trimmed } }? }.
for _, row in generator:heldBreakdown().generator do print(row.field, row.bytes) end
print(generator:heldBreakdown().cacheBytes)
typed/builtin//systems/procgen/Generator/public/hold
public.hold()
Play the range once and stay on its last frame, whatever the graph
declares: sets ending to "hold".
generator:hold()
typed/builtin//systems/procgen/Generator/public/isReady
public.isReady() -> boolean
Whether playing on from the playhead asks no cook: a graph of the call
form has presented the frame the playhead stands on with the inputs it
holds now, one of the node form on a timeline with an end has every frame
of its range cooked and kept, and one with no end stands on the device.
False while a present or a cook runs, and while the latest one failed
(playback().cookError says why).
Returns boolean
if generator:isReady() then generator:play() end
typed/builtin//systems/procgen/Generator/public/loop
public.loop()
Play the range round and round, whatever the graph declares: sets
ending to "loop".
generator:loop()
typed/builtin//systems/procgen/Generator/public/pause
public.pause()
Stop the graph's clock where it is, on every peer. What is in the scene stays, and nothing cooks or is touched until the clock moves again.
generator:pause()
typed/builtin//systems/procgen/Generator/public/play
public.play()
Run the graph's clock. A generator plays from the moment it binds a
graph; this resumes one that was paused, and plays again one that reached
the end of its range and held — from its first frame, or from its last
when speed runs it backwards. It reaches every peer: each runs its own
clock from where this one stood. A play asked for by gameplay code (a
component's awake, start, update or a gameplay task: task.class()
answers "gameplay") runs on the gameplay clock, so in edit mode, where
engine.paused holds that clock, it stands on its frame until the clock
runs; one asked for anywhere else (the editor, execute, a module) plays
in edit mode too. playback().heldByPause says when a play stands so.
generator:play()
typed/builtin//systems/procgen/Generator/public/playback
public.playback() -> PlaybackState
Where the graph's clock stands and what running it has cost: { playing, heldByPause, held, realTime, wallTime, frame, time, first, last, frames, fps, loop, ends, cookedThrough, cooked, hits, nodes, ms, cost, steps, restarts, replacing, placement, placementByGraph }. heldByPause is true while a play gameplay
code asked for stands because engine.paused holds the gameplay clock (see
play). cookedThrough
is the last frame of the range cooked ahead so far; cooked counts node
cooks and hits cache hits since the generator bound its graph,
nodes is cooks per node id and ms the CPU milliseconds each node's
cooks have taken. cost is { frames, frameMs, cooks, cookMs }: the
frames the generator ticked and the milliseconds that took apart from its
cooks, and the cooks it presented and the milliseconds its cook worker ran
— cooking, realizing and cooking ahead, apart from the frames it waited
out. frameMs + cookMs over frames is what running the graph costs a
frame in script; drainMs is what the render side spent recording the
device work the generator queued, the rest of a frame's cost. Of the
frames' milliseconds, deviceMs went on the
devicePresents presents made by rewriting the output on the device and
realizeMs on realizing outputs read back from it; rewriteMs is those
presents' milliseconds by the node or kernel each rewrite brought on.
memoPresents counts the presents served from frames already cooked, and
framePresents the ones shown from the frames the engine holds once a
timeline with an end is cooked through (heldFrames; notHeldFrames says
why a play does not stand on them).
onDevice is whether a new time is presented by rewriting the
standing output on the device rather than by a cook, and offDevice,
while it is not, why: the node or value that holds the graph to cooking.
drawn is per point-domain output how its elements reach the screen:
{ as, count, because?, pieces? }, as being "instances" (one
instanced draw) or "entities" (an entity per element), because what a
domain of one mesh and one material carries that made it entities, and
pieces one such record per piece of a population of several. count is
the elements the draw holds a slot for: for a population whose live count
is held on the device it is the capacity those slots were made at, and the
particles alive at a moment are the slots the solver has filled. A graph
of the call form reports it per output by the name the output was shown
under.
owner is the name the device runs of this generator's play are held
under (proc.substrate.owner), which the GPU profiler's
compute.list:<owner> rows carry for the lists it runs.
steps counts the fixed steps its solvers
took and restarts the times one went back to its start. diskCache is
per output its graph caches: { key, frames, static, complete, hits }
where this generator uses the cache — frames the frames its index holds
and hits the presents it answered — or { reason } where it cannot.
replacing counts the outputs built again whose earlier state still
stands in the scene until the new one can draw.
placement is per node where its cooks ran, as the engine saw them rather
than as the op says: { runs, output, declared, cooks, uploads, uploadBytes, readbacks, readbackBytes } — declared where the op says
it runs ("device" for one declaring deviceColumns, which fails a cook
that reads a column back, "cpu" otherwise) — and
runs "device" for a node that moved nothing
between the CPU and the device and left its output on the device, "cpu"
for one whose output is on the CPU, "mixed" for one that moved data across
or left some of each, "values" for one that made no columns. A graph used
as a node is written out, so its nodes are here under <node>/<inner>, and
placementByGraph sums them per such node: { nodes, device, cpu, mixed, uploadBytes, readbackBytes, onCpu }, onCpu naming the inner nodes
that are not on the device.
error is why the bound graph's source does not load, while it does
not: the output standing is then the last one that loaded, and the cook
history holds a failed cook targeting "source" with the same text.
cookError is why the latest cook of the graph, or the realizing of what
it cooked, failed, while it does: the output standing is then the last
one that cooked and was realized.
stored is the generator's stored result (StoredState): the key it is
filed under, whether it stands now in place of a cook (standing, with
standMs, the entities, meshes and instance sets it stood; rewrites, the
recorded rewrites that move it on the device each frame, the dispatches a
frame of them queues, fused when they run as one kernel or
fusedBecause naming why they replay as recorded, with ticks, the
mean tickMs a frame's run of them took and the result's time; or
moving with cookedBecause when only its cook moves it, which takes
over once it stands), and what the last write of a cook's
result did (written: { written, blobs, kept, bytes }, writing while
one runs, writeError, or skipped naming why a cook was not stored).
A generator standing its stored result with nothing cooked answers no
cook and no node, at the time its stored rewrites stand at.
call is, for a graph built in the call form, the report of its play: the
nodes it cooks from, what its plan waited on, the assets its calls reach
and the cook counts.
lane is the lane of the frame's budget its cooperative work runs on (FrameBudget.lane): ahead while a
play a caller started waits on the work for the frame it shows next, background while its entity stands out of
the scene, normal otherwise.
Returns PlaybackState — The playback state (PlaybackState): tables keyed by name (drawn, nodes, ms, placement, diskCache, placementByGraph) are maps read with pairs.
print(generator:playback().cooked)
for output, d in pairs(generator:playback().drawn) do print(output, d.as, d.count) end
typed/builtin//systems/procgen/Generator/public/prepare
public.prepare()
Make the first frame stand ready to be shown, without playing: the graph
is bound and planned, its outputs are cooked and the frame at the start of
its timeline is presented, on an entity that is not running yet as on one
that is. The clock stays where play finds it, on its first frame; the
work runs over the frames after the call, and isReady says when it is
done. An entity kept out of the scene, waiting to be played, is prepared
this way so its first play shows what stands.
generator:prepare()
typed/builtin//systems/procgen/Generator/public/presenting
public.presenting() -> boolean
Whether a present of the generator's graph is running now: a cook, a play moving on to a later time on the device, or a build of a graph whose source was written and which the generator has not taken up yet. A present that records its device work for the first time spans frames, and what the generator draws is the previous present's until it ends.
Returns boolean — true while a present runs.
if generator:presenting() then task.wait() end
typed/builtin//systems/procgen/Generator/public/seek
public.seek(seconds: number)
Move the playhead to seconds from the start of the range and present
that frame, on every peer. A frame already cooked is served from the cache. To take
pictures of a generator, procgen.frames pictures it at the graph times you
name and puts its clock back after, and procgen.onPresent fires on a
moment while it plays — neither needs the clock held by hand.
Parameters
secondsnumber— Time from the start of the range.
generator:seek(2.5)
typed/builtin//systems/procgen/Generator/public/seekFrame
public.seekFrame(frame: number)
Move the playhead to frame frame of the timeline and present it.
Parameters
framenumber— The frame, counted from the timeline's first.
generator:seekFrame(90)
typed/builtin//systems/procgen/Generator/public/setFps
public.setFps(fps: number)
Play at fps frames per second instead of the rate the graph declares.
Parameters
fpsnumber— Frames per second.
generator:setFps(12)
typed/builtin//systems/procgen/Generator/public/setRange
public.setRange(first: number, last: number)
Hold playback to frames first to last of the timeline: playing,
looping and holding all happen inside them, and cooking ahead covers them
alone. On a real-time timeline the range gives it an end: it finishes on
frame last.
Parameters
firstnumber— The first frame of the range.lastnumber— The last frame of the range.
generator:setRange(30, 89)
typed/builtin//systems/procgen/Generator/public/setWallTime
public.setWallTime(on: boolean)
Let the playhead follow the clock on the wall. Off, the default, every frame is presented in order and a slow device plays slower and shows exactly what a fast one does. On, the playhead keeps wall time and the frames it passes while one is being presented are not shown.
Parameters
onboolean— Whether the playhead follows wall time.
generator:setWallTime(true)
typed/builtin//tools/guides/shared/M/catalog
M.catalog() -> { Guide }
Every guide this engine can reach, listed once each, in identity
order. The .guide assets — built-in, package-shipped and world-authored
alike — and the asset types, whose READMEs document them under
types/<name>.
Returns { Guide } — Array of { identity, body, kind, guid?, aliases }, where kind is "guide" or "assettype".
for _, g in shared.catalog() do print(g.identity) end
typed/builtin//tools/guides/shared/M/normalize
M.normalize(input: string) -> string
The spelling a caller typed, reduced to the form the catalogue lists:
surrounding slashes, a guide's own guide.md file name, a .md suffix
and a .guide suffix all come off, so a path copied from anywhere
resolves.
Parameters
inputstring— What the caller typed.
Returns string — The normalised identity.
shared.normalize("/topics/physics.guide") -- "topics/physics"
shared.normalize("/zero/source/kit.package/my-guide.guide/guide.md") -- "zero/source/kit.package/my-guide"
typed/builtin//tools/guides/shared/M/pathOf
M.pathOf(rawIdentity: string, folder: string) -> string
The path a guide is listed under, from the identity the asset index
holds and the folder it sits in. guides.list lists it, guides.read
opens it, and the documentation search hands it back as a hit's path.
A built-in arrives in dot form (@builtin::docs.topics.physics); stripping
the library and the docs. shell leaves topics/physics. Anything else is
named by its location, with the source prefix and the .guide suffix
removed (controlsKit.package/my-guide), so a content guide's path says
where it sits.
Parameters
rawIdentitystring— The identity the asset index holds for the guide.folderstring— The guide's folder, or the path of any file inside it.
Returns string — The guide path.
shared.pathOf("@builtin::docs.topics.physics", "/zero/source/libs/@builtin/docs/topics/physics.guide") -- "topics/physics"
typed/builtin//tools/guides/shared/M/resolve
M.resolve(assets: { Guide }, wanted: string) -> Resolution
Resolve a path against the catalogue, widening only while the answer
stays unique: an exact spelling (the listed path, an asset identity the
guide answers to, its guid, or the VFS path of its folder or its
guide.md), then one ignoring case, then anything
ending in /<wanted>, then a bare stem, then a run of name segments
(controlsKit/my-guide reaches controlsKit.package/my-guide). A
widening that matches several guides is reported as those spellings
rather than picking one, because which one the caller meant is not
knowable from what they typed.
Parameters
assets{ Guide }— The catalogue to resolve against.wantedstring— A normalised identity.
Returns Resolution — { found } when one guide answers, { ambiguous } when several do, and neither when none does.
local r = shared.resolve(shared.catalog(), "physics")
typed/builtin//tools/guides/shared/M/segments
M.segments(spelling: string) -> { string }
The name segments a spelling is made of, lowercased: the parts
between /, . and :, with a library namespace (@builtin::) and a
package marker (~) dropped. controlsKit.my-guide,
controlsKit/my-guide and ~controlsKit.my-guide are the same two
segments; controlsKit.package/my-guide is three.
Parameters
spellingstring— A guide path, an asset identity, or what a caller typed.
Returns { string } — The segments, in order.
shared.segments("@builtin::docs.topics.physics") -- { "docs", "topics", "physics" }
typed/builtin//tools/guides/shared/M/suggest
M.suggest(query: string, candidates: { string }, limit: number) -> { string }
The identities closest to a path that resolved to nothing, best first.
A candidate containing the whole spelling outranks one that only shares a
segment, so a typo is answered by the guide it was reaching for. The
segments are those segments reads, so a dotted asset identity is
matched part by part the way a slashed path is.
Parameters
querystring— The spelling that found nothing.candidates{ string }— The identities to suggest from.limitnumber— How many to return.
Returns { string } — The suggestions, best first, possibly none.
shared.suggest("physic", { "topics/physics" }, 5)