Skip to content
Konjure / spatial intelligence

builtin

← Builtin reference

The standard module automatically available to every supplied source module.

Signature

builtin

Use builtin. to qualify prelude types, traits and interpreter functions explicitly, or refer to those names without an import. Primitive types, pi and callback-only entity/time/tick bindings do not use this qualifier.

builtin is reserved. Its definitions ship inside Rust; it does not fetch code, resolve package versions, or grant device permissions.

Examples

Qualify builtin names

Both qualified operations use the same prelude and interpreter as unqualified names.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
2

Rust definition

The compiler loads catalog::PRELUDE as a reserved module and resolves native registrations in Rust.

Values

print

Appends a bounded textual rendering of a value to the machine log without external I/O.

func print(value: T) -> Unit

Rendering must fit the machine string bound. Logs are a bounded ring buffer: when full, the oldest retained line is discarded, and no external I/O occurs.

value: T
Any checked value whose rendered log text fits the machine string limit.
Unit

Unit after the bounded log update.

print writes the interpreter log.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
hello

Rust interpreter builtin dispatch; polymorphic calls and function values are checked from their concrete context.

noop

Does nothing and returns a successful Unit result; useful as a default zero-argument callback.

Signature

func noop() -> Res[Unit, DataError]

It is a concrete function value, so it can be stored in Button.action without a string callback name or a host effect.

Returns

Res[Unit, DataError]

Ok(Unit) without a state change.

Examples

Default action

noop is assignable to a zero-argument recoverable callback.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
(no log output)

Rust definition

Rust interpreter builtin dispatch; Type is func() -> Res[Unit, DataError].

ignore_number

Accepts and ignores one Number; useful as a default slider callback.

Signature

func ignore_number(value: Number) -> Res[Unit, DataError]

It is a concrete function value for Slider.action. The Number is checked then discarded, with no scene or host state update.

Parameters

value: f64
A Number accepted without a state change.

Returns

Res[Unit, DataError]

Ok(Unit).

Examples

Default slider action

ignore_number has the Slider callback type.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
(no log output)

Rust definition

Rust interpreter builtin dispatch; Type is func(Number) -> Res[Unit, DataError].

bytes

Builds immutable bytes from checked unsigned 8-bit values.

Signature

func bytes(values: List[u8]) -> Bin

Each element is a u8, so out-of-range literal bytes are compile errors. The Bin owns shared immutable storage and has no text encoding until decoded explicitly.

Parameters

values: List[u8]
Unsigned 8-bit values; list literals inherit u8.

Returns

Bin

Immutable packed bytes.

Examples

Builds immutable bytes from checked unsigned 8-bit values

Run the example, then change the data and inspect the result.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
AB

Rust definition

Rust SDK data primitives; the language checker specializes the same runtime operation.

Number

A finite IEEE 754 binary64 scalar with canonical language type f64.

Signature

Number remains a source alias for f64 and this host representation remains compatible with native spatial interfaces. Literals without numeric context default to f64. Exact integer widths and f16/f32/f128 use Scalar instead. Numeric variables never implicitly change dtype; use .convert[T]() for an explicit conversion, which rejects overflow and loss of information.

Methods

sin
sin() -> Res[f64, DataError]

Returns the numeric result or DataError when the operation cannot be represented.

cos
cos() -> Res[f64, DataError]

Returns the numeric result or DataError when the operation cannot be represented.

sqrt
sqrt() -> Res[f64, DataError]

Returns the numeric result or DataError when the operation cannot be represented.

abs
abs() -> Res[f64, DataError]

Returns the numeric result or DataError when the operation cannot be represented.

floor
floor() -> Res[f64, DataError]

Returns the numeric result or DataError when the operation cannot be represented.

ceil
ceil() -> Res[f64, DataError]

Returns the numeric result or DataError when the operation cannot be represented.

min
min(f64) -> Res[f64, DataError]

Returns the numeric result or DataError when the operation cannot be represented.

max
max(f64) -> Res[f64, DataError]

Returns the numeric result or DataError when the operation cannot be represented.

clamp
clamp(f64, f64) -> Res[f64, DataError]

Returns the numeric result or DataError when the operation cannot be represented.

pow
pow(f64) -> Res[f64, DataError]

Returns the numeric result or DataError when the operation cannot be represented.

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate a distance

Change either side length and inspect the hypotenuse.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
5

Rust definition

Value::Number(f64); one finite Rust f64 per language value.

See Numeric types for exact integer widths and floating-point formats.

Bool

A Boolean value used by conditions and short-circuit expressions.

Signature

Bool stores a Rust bool and has exactly two values: true and false. if and while require Bool; numeric zero and empty collections do not act as false. and and or evaluate their right side only when needed.

Examples

Combine conditions

The right side of and is skipped when ready is false.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
false
true

Rust definition

Value::Bool(bool); conditions never coerce numbers or strings.

Str

Immutable UTF-8 text with canonical language type Str (String is an alias).

Signature

Clones share an Arc allocation. Concatenation creates a new value without implicit conversion. len, indexing, and slices count Unicode scalar values, while allocation limits count UTF-8 bytes. utf8 encodes to Bin and decode validates Bin as UTF-8. Text is the separate visible scene component.

Methods

len
len() -> f64

Returns the receiver's element, byte, or Unicode scalar count.

utf8
utf8() -> Bin

Encodes text as immutable UTF-8 bytes.

get
get(f64) -> Opt[Str]

Returns Some(value) for a valid index and None otherwise.

Examples

Join and measure text

The accented character counts as one scalar value even though it uses two UTF-8 bytes.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
hello café
4

Rust definition

Value::Text(konjure_sdk::data::Str); shared immutable UTF-8 text.

String

Immutable UTF-8 text with canonical language type Str (String is an alias).

Signature

Clones share an Arc allocation. Concatenation creates a new value without implicit conversion. len, indexing, and slices count Unicode scalar values, while allocation limits count UTF-8 bytes. utf8 encodes to Bin and decode validates Bin as UTF-8. Text is the separate visible scene component.

Methods

len
len() -> f64

Returns the receiver's element, byte, or Unicode scalar count.

utf8
utf8() -> Bin

Encodes text as immutable UTF-8 bytes.

get
get(f64) -> Opt[Str]

Returns Some(value) for a valid index and None otherwise.

Examples

Read existing source

The compatibility spelling resolves to the same immutable text type.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
text

Rust definition

Compatibility spelling of Str; new source uses Str.

Bin

Immutable bytes without an implied text encoding.

Signature

Cloning shares a packed Arc allocation. bytes constructs Bin from List[u8], Str.utf8 encodes text, and Bin.decode validates UTF-8 with a Res result. Indexing returns Res[u8, DataError]; slicing produces Res[Bin, DataError]. Concatenation creates independent data and respects byte limits.

Methods

len
len() -> f64

Returns the receiver's element, byte, or Unicode scalar count.

decode
decode() -> Res[Str, DataError]

Decodes UTF-8 bytes or returns DataError for malformed input.

get
get(f64) -> Opt[u8]

Returns Some(value) for a valid index and None otherwise.

Examples

Keep bytes distinct from text

Encoding is explicit; byte length and Unicode scalar count differ.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
4
5
café

Rust definition

Value::Bin(konjure_sdk::data::Bin); shared immutable byte storage.

Unit

The single empty value returned by procedures.

Signature

Unit is represented by the payload-free Rust Value::Unit variant and spelled () in the language. A function returning Unit may end without a value or use ret;. Unit is not null, an absent field, or an optional value.

Examples

Return from a procedure

The procedure logs its work; its result is the empty value ().

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
ready
()

Rust definition

Value::Unit; a Rust enum variant with no payload.

time

Accepted simulation time in seconds inside a system lifecycle callback.

Signature

time: Number

time advances with accepted simulation ticks, not wall-clock time or browser rendering. The embedding host chooses the fixed cadence. Failed ticks do not publish new time; this immutable binding is unavailable at module scope.

Examples

Read simulation time

Step once: time is positive after the first accepted tick.

Press Step once to reach the checked result.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading the language runtime…
Output 0
No output.
Expected output
true

Rust definition

Machine supplies accepted simulation seconds as Value::Number.

tick

The accepted simulation tick number inside a system lifecycle callback.

Signature

tick: Number

tick is an immutable Number supplied by the runtime. It counts accepted simulation updates; browser animation frames and rejected updates do not increment it. It is available only inside init, frame and done callbacks.

Examples

Count accepted updates

Step twice to log 1 and 2. Reset starts a fresh run.

Press Step 2 times to reach the checked result.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading the language runtime…
Output 0
No output.
Expected output
1
2

Rust definition

Machine exposes its accepted tick counter as Value::Number.

i8

Signed 8-bit integer, from -128 through 127; checked arithmetic.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

i16

Signed 16-bit integer, from -32768 through 32767; checked arithmetic.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

i32

Signed 32-bit integer, from -2147483648 through 2147483647; checked arithmetic.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

i64

Signed 64-bit integer, from -9223372036854775808 through 9223372036854775807; checked arithmetic.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

i128

Signed 128-bit integer, from -170141183460469231731687303715884105728 through 170141183460469231731687303715884105727; checked arithmetic.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

u8

Unsigned 8-bit integer, from 0 through 255; checked arithmetic.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

u16

Unsigned 16-bit integer, from 0 through 65535; checked arithmetic.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

u32

Unsigned 32-bit integer, from 0 through 4294967295; checked arithmetic.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

u64

Unsigned 64-bit integer, from 0 through 18446744073709551615; checked arithmetic.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

u128

Unsigned 128-bit integer, from 0 through 340282366920938463463374607431768211455; checked arithmetic.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

f16

IEEE binary16: 11 significand bits, normal exponents -14 through 15, subnormals through 2^-24. Finite values only; ties-to-even rounding.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

f32

IEEE binary32: 24 significand bits, normal exponents -126 through 127, subnormals through 2^-149. Finite values only; ties-to-even rounding.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

f64

IEEE binary64: 53 significand bits, normal exponents -1022 through 1023, subnormals through 2^-1074. Finite values only; ties-to-even rounding.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

f128

IEEE binary128: 113 significand bits, normal exponents -16382 through 16383, subnormals through 2^-16494. Portable software arithmetic retains all 128 bits. Finite values only; ties-to-even rounding.

Signature

Integer arithmetic checks overflow; floating-point arithmetic rounds each operation at its declared precision and rejects nonfinite results. Mixed representations require explicit conversion, which rejects loss of range or precision. Values serialize as decimal strings so JSON hosts retain the exact value.

Methods

convert
convert[U]() -> Res[U, DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Calculate at a declared precision

Both operands have this dtype; changing the annotation changes its range and precision.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
42

Rust definition

Rust SDK Scalar with an explicit dtype and validated bits; exact scalar JSON uses strings.

Opt

An optional value that records presence explicitly.

Signature

enum Opt[T] { Some(T), None }

Match both Some and None before using an optional result.

Cases

Some(T)
Contains a present value of T.
None
Records that no value is present.

Examples

Match an optional value

Both cases make absence explicit.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
4

Rust definition

Value::Enum with the concrete Opt[T] type and checked case payload.

Res

A recoverable success or error result.

Signature

enum Res[T, E] { Ok(T), Err(E) }

Use ? to propagate Err to a compatible Res-returning boundary, or match both cases locally.

Cases

Ok(T)
Contains a successful value of T.
Err(E)
Contains a recoverable error of E.

Examples

Match a result

A result carries either its value or its error payload.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
4

Rust definition

Value::Enum with the concrete Res[T, E] type and checked case payload.

DataError

A stable recoverable error emitted by checked numeric, byte, and tensor operations.

Signature

enum DataError { ... }

Each case name and description comes from the Rust SDK data-error registry.

Cases

TypeMismatch
An operation requires operands with the same declared element type.
InvalidLiteral
Text is not a valid literal of the requested type.
InvalidUtf8
Bytes are not valid UTF-8 where a text value is required.
Overflow
A value or checked integer operation exceeds the destination range.
NonFinite
Infinity and NaN cannot enter a portable data value.
InexactConversion
A conversion would round, truncate, or discard a signed zero.
DivisionByZero
Division or remainder has a zero divisor.
InvalidShape
Shape, rank, or buffer length is not a valid tensor layout.
ShapeMismatch
Shapes cannot participate in the requested operation.
Bounds
An index is outside the requested value.
InvalidSlice
Slice selectors are malformed, including a zero step.
InvalidMetadata
Decoded media metadata disagrees with its payload.
AllocationLimit
A checked allocation exceeds the portable data limit.

Examples

Handle invalid UTF-8

Decoding reports InvalidUtf8 instead of replacing malformed bytes.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
InvalidUtf8

Rust definition

konjure_sdk::data::DataError, carried in Res error payloads.

Collections

range

Creates a bounded sequence of exactly representable integer Numbers from start inclusive to end exclusive.

Signature

func range(end: Number) -> Res[List[Number], DataError]
func range(start: Number, end: Number) -> Res[List[Number], DataError]

Each bound must be finite, integral, and exactly representable from -9007199254740991 through 9007199254740991. End is exclusive; descending bounds produce an empty list. Invalid endpoints return DataError; a host resource limit remains a Diagnostic.

Parameters

end: f64
Exactly representable finite integer from -9007199254740991 through 9007199254740991; it is exclusive.
start: f64
Exactly representable finite integer from -9007199254740991 through 9007199254740991; omitted start is zero.

Returns

Res[List[f64], DataError]

Ok(List[Number]) for valid endpoints, Err(DataError) for invalid numeric endpoints. A host resource limit rejects execution diagnostically.

Examples

Range from zero

One bound starts at zero.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
3
Range with bounds

The start is inclusive and end is exclusive.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
3

Rust definition

Rust interpreter builtin dispatch; one- and two-argument Number overloads return Res[List[Number], DataError] for invalid numeric endpoints.

tensor

Constructs packed numeric data with explicit dimensions.

Signature

func tensor[T](values: List[T], dimensions: List[Number]) -> Res[Tensor[T], DataError]

T is a numeric dtype. Values are row-major and their count must equal the checked product of the dimensions. Invalid shapes return Err(DataError). Host byte and execution limits reject execution before allocation.

Parameters

values: List[T]
Flat elements of the selected dtype; literals inherit T.
dimensions: List[f64]
Nonnegative integer dimensions in row-major axis order; [] constructs a rank-zero scalar from one value.

Returns

Res[Tensor[T], DataError]

Ok(Tensor[T]) with packed storage, or Err(DataError) for invalid dimensions or an element-count mismatch.

Examples

Constructs packed numeric data with explicit dimensions

Run the example, then change the data and inspect the result.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
3

Rust definition

Rust SDK data primitives; the language checker specializes the same runtime operation.

Tensor

An immutable packed Tensor[T] with shared storage and checked shape/stride views.

Signature

A tensor stores one numeric dtype and a runtime shape. Comma-separated indices select scalar elements; slices preserve tensors and share their allocation. Arithmetic broadcasts trailing dimensions; @ multiplies matrices and batches. Arithmetic and indexing return Res; get returns Opt for a scalar lookup. Dtypes must match, with contextual typing reserved for literal operands.

Methods

len
len() -> f64

Returns the receiver's element, byte, or Unicode scalar count.

get
get(List[f64]) -> Opt[T]

Returns Some(value) for a valid index and None otherwise.

shape
shape() -> List[f64]

Returns one nonnegative extent for each tensor axis.

reshape
reshape(List[f64]) -> Res[Tensor[T], DataError]

Returns a reshaped tensor or DataError when dimensions do not fit.

transpose
transpose() -> Res[Tensor[T], DataError]
transpose(List[f64]) -> Res[Tensor[T], DataError]

Returns a reordered tensor or DataError for an invalid axis permutation.

sum
sum() -> Res[T, DataError]

Returns the tensor sum or DataError when the operation cannot be represented.

matmul
matmul(Tensor[T]) -> Res[Tensor[T], DataError]

Returns a matrix product or DataError when tensor shapes are incompatible.

convert
convert[U]() -> Res[Tensor[U], DataError]

Converts to explicit numeric dtype U or returns DataError when exact conversion fails.

Examples

Slice a matrix

A slice is an immutable view; indexing with one integer per axis returns a typed scalar.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
[2, 2]
Some(5)

Rust definition

Value::Tensor(konjure_sdk::data::Tensor); a numeric dtype, shape, strides and shared packed storage.

List

An ordered owned collection whose elements share one language type.

Signature

List[T]

List[T] stores Rust Vec<Value> data. The compiler retains T and the runtime checks elements at typed boundaries. An empty literal needs a contextual element type, such as let values: List[f64] = [];.

Indexing starts at zero and rejects out-of-range indices. Assignment copies a list value; .append(value) returns a new list. .get(index) returns Opt[T], while indexing returns Res[T, DataError]. Collection length and nested values remain subject to the embedding host's Limits.

Methods

len
len() -> f64

Returns the receiver's element, byte, or Unicode scalar count.

append
append(T) -> List[T]

Returns a new list with one value appended.

get
get(f64) -> Opt[T]

Returns Some(value) for a valid index and None otherwise.

Examples

Append without changing the original

append returns a new list. Change the appended value and compare both lists.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
2
2
4
6

Rust definition

Value::List(Vec<Value>); static T and runtime validation enforce homogeneous elements.

Math

Vec3

A three-component numeric vector with zero defaults.

Signature

type Vec3 {
  x: Number = 0;
  y: Number = 0;
  z: Number = 0;
}

Spatial consumers interpret components as meters, directions, or radians based on their containing field; Vec3 itself carries no unit.

Fields

x: f64
X component; defaults to 0.
Default0
y: f64
Y component; defaults to 0.
Default0
z: f64
Z component; defaults to 0.
Default0

Examples

Construct a vector

Unset components retain their zero default.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
2

Rust definition

Interpreter RecordValue schema, copied by value at language boundaries.

Transform

Local pose and scale for an entity.

Signature

type Transform {
  position: Vec3 = Vec3 {};
  rotation: Vec3 = Vec3 {};
  scale: Vec3 = Vec3 { x: 1, y: 1, z: 1 };
}

Position is meters, rotation is XYZ Euler radians, and scale defaults to one on every axis. Physics owns the position and rotation of dynamic bodies.

Fields

position: Vec3
Translation in meters; defaults to the local origin.
DefaultVec3 {}
rotation: Vec3
XYZ Euler rotation in radians; defaults to zero rotation.
DefaultVec3 {}
scale: Vec3
Per-axis multiplier; defaults to (1, 1, 1). Physical spheres require uniform positive scale.
DefaultVec3 { x: 1, y: 1, z: 1 }

Examples

Set a pose

Create a transform value in meters.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
2
Attach a renderable pose

A scene adapter reads Transform from an entity with geometry.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
1

Rust definition

Interpreter RecordValue schema consumed by spatial adapters.

pi

The mathematical constant pi, available as a Number.

Signature

pi: Number

pi is a finite binary64 approximation. Angles passed to sin and cos are radians; one full turn is 2 * pi. The name is available in ordinary expressions.

Examples

Measure a circle

The circumference scales linearly with the radius.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
12.566370614359172

Rust definition

The Rust interpreter installs std::f64::consts::PI as a Number binding.

Entities

spawn

Creates an entity with one record component and returns its opaque identity.

Signature

func spawn(component: C) -> Entity

The C placeholder means one concrete type value, never a trait or primitive. Entity creation is bounded and rejected when the machine has no remaining entity capacity.

Parameters

component: C
A constructed type value; traits and primitive values are rejected.

Returns

Entity

The new Entity identity.

Examples

Create an entity

A spawned component receives the first entity identity.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
entity(1)

Rust definition

Rust interpreter builtin dispatch; Type is specialized from a concrete type argument.

add

Adds a record component to an existing entity.

Signature

func add(entity: Entity, component: C) -> Unit

C means a concrete type value. Adding a component that the entity already owns, or addressing a missing entity, rejects the current transaction.

Parameters

entity: Entity
An existing entity identity.
component: C
A type value whose type is not already attached.

Returns

Unit

Unit after the component update is accepted.

Examples

Add a component

A new Sphere component becomes queryable on the entity.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
true

Rust definition

Rust interpreter builtin dispatch; Type is specialized from the concrete component type.

get

Reads a typed component copy from an entity; the entity must have that component.

Signature

func get[C](entity: Entity) -> C

C means a concrete type selector. The result is a component copy; update the live entity with set, or use a system binding or bind[C](entity) method callback for persistent mutation.

Parameters

entity: Entity
An entity that has the selected concrete type component.

Returns

C

A copy of component C.

Examples

Select a component

The explicit selector fixes the component type for a function value.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
2

Rust definition

Rust interpreter builtin dispatch; C must name a concrete type and is checked during specialization.

set

Replaces an existing record component on an entity.

Signature

func set(entity: Entity, component: C) -> Unit

C means a concrete type value. set requires that component to exist already and replaces it atomically; use add for a new component.

Parameters

entity: Entity
An entity that already has the component type.
component: C
The replacement type value.

Returns

Unit

Unit after the replacement is accepted.

Examples

Replace a component

set updates an already attached component.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
2

Rust definition

Rust interpreter builtin dispatch; Type is specialized from the concrete component type.

has

Tests whether an entity has the selected concrete component type.

Signature

func has[C](entity: Entity) -> Bool

C means a concrete type selector. The result observes the entity's current component set and rejects an unknown entity rather than inventing absence.

Parameters

entity: Entity
An existing entity identity.

Returns

Bool

True when the entity has component C.

Examples

Test component presence

The selector is required when the function value would otherwise not identify C.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
true

Rust definition

Rust interpreter builtin dispatch; C must name a concrete type and is checked during specialization.

query

Returns entity identities that have the selected type or implement the selected trait.

Signature

func query[C]() -> List[Entity]

C means a concrete type or trait selector. The returned entity handles are ordered by creation and are a snapshot value; later lifecycle changes do not mutate the returned list.

Returns

List[Entity]

Matching entities in stable creation order.

Examples

Query matching entities

The selector makes the query function value concrete.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
1

Rust definition

Rust interpreter builtin dispatch; C is a checked concrete type or trait selector.

despawn

Schedules an entity for removal when the current initializer, callback, or action completes.

Signature

func despawn(entity: Entity) -> Unit

The entity must exist. Removal is deferred until the enclosing initializer, callback, or action completes so checked work sees a consistent world.

Parameters

entity: Entity
An existing entity identity.

Returns

Unit

Unit; removal is deferred to preserve transactional execution.

Examples

Schedule removal

The current value remains printable while removal is pending.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
entity(1)

Rust definition

Rust interpreter builtin dispatch; Type is func(Entity) -> Unit.

bind

Binds a concrete entity component so extracted methods can update that live component transactionally.

Signature

func bind[C](entity: Entity) -> ComponentReference[C]

C means a concrete type selector, never a trait. The reference owns an entity and component identity; extracted mutating methods commit back transactionally and fail if the component is unavailable.

Parameters

entity: Entity
An entity with the selected concrete type component.

Returns

ComponentReference[C]

A ComponentReference[C] whose mutating extracted methods write back to that entity.

Examples

Bind a live component

A bound mutating method commits its component update.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
1

Rust definition

Rust interpreter builtin dispatch; C must name a concrete type and produces ComponentReference[C] for typed function values.

Entity

An opaque ECS identity created by spawn.

Signature

Entity stores a Rust u64 handle. IDs are allocated in creation order and cannot be constructed from a Number in the language. Copying a handle keeps the same identity; it does not duplicate the entity or its components.

Use get, set, has and bind with a concrete component type. A handle can outlive its entity, but subsequent access to a removed entity is rejected.

Examples

Share an entity identity

Both handles address the same entity, so the update through alias is visible through item.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
4

Rust definition

Value::Entity(u64); stable interpreter identity, not a pointer or a Rust SDK Entity struct.

ComponentReference

A typed entity/component identity used to capture live component methods.

Signature

ComponentReference[T] pairs a Rust entity ID with a canonical concrete type name. bind[T](entity) validates that the component exists; method calls resolve it again and commit accepted receiver changes transactionally.

This is an interpreter handle, not a Rust borrow or raw memory reference. Access component data with get and set; invoke methods through the reference. Invoking a reference after its entity disappears is an error.

Examples

Capture a live component method

Calling advance updates the stored component, rather than a copied receiver.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
1

Rust definition

Value::ComponentReference(ComponentReference); an entity ID and canonical component type resolved at invocation.

entity

The current entity handle inside a system lifecycle callback.

Signature

entity: Entity

entity identifies the entity whose component join is being processed. It is immutable and available in init, frame and done, not at module scope. Use it to access other components or schedule removal at the callback boundary.

Examples

Inspect the current entity

Step once to see the two entities in creation order.

Press Step once to reach the checked result.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading the language runtime…
Output 0
No output.
Expected output
entity(1)
entity(2)

Rust definition

Machine supplies a Value::Entity for the currently executing system join.

Geometry

Render

A typed presentation contract with one render operation.

Signature

trait Render { func render() -> Unit; }

Querying Render implementers is language behavior. Rendering remains an adapter responsibility; declaring this trait never schedules an automatic render call.

Methods

render
func render() -> Unit

Required presentation operation. A host or system chooses when to invoke it.

Examples

Implement a render operation

The trait only checks the method contract.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
rendered

Rust definition

Trait declaration checked by the interpreter; graphics handles remain host-owned.

Sphere

A sphere centered at its entity origin.

Signature

type Sphere { radius: Number = 0.2; }

The spatial adapter requires a positive radius before tessellation. A Sphere is also one of the two collision shapes accepted by RigidBody.

Fields

radius: f64
Radius in meters; defaults to 0.2 and must be positive for physics.
Default0.2

Examples

Create a sphere

Geometry becomes renderable when attached to an entity.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
0.5

Rust definition

Interpreter RecordValue geometry schema consumed by spatial adapters.

Box

An axis-aligned local box with full dimensions.

Signature

type Box { size: Vec3 = Vec3 { x: 1, y: 1, z: 1 }; }

The spatial adapter validates positive dimensions before rendering. Box is one of the two collision shapes accepted by RigidBody; size uses full extents.

Fields

size: Vec3
Full width, height, and depth in meters; each physical dimension must be positive.
DefaultVec3 { x: 1, y: 1, z: 1 }

Examples

Create a box

Size records full extents, not half extents.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
2

Rust definition

Interpreter RecordValue geometry schema consumed by spatial adapters.

Cylinder

A cylinder aligned with local Y.

Signature

type Cylinder { radius: Number = 0.2; height: Number = 1; }

Radius and height must be positive when a spatial adapter tessellates this geometry. Cylinders currently render but are not RigidBody collision shapes.

Fields

radius: f64
Radius in meters; defaults to 0.2.
Default0.2
height: f64
Full height in meters along local Y; defaults to 1.
Default1

Examples

Create a cylinder

The current spatial adapter renders it along local Y.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
2

Rust definition

Interpreter RecordValue geometry schema consumed by spatial adapters.

Quad

A rectangular local XY surface facing local +Z.

Signature

type Quad { width: Number = 1; height: Number = 1; }

Width and height must be positive when rendered. The adapter expands Quad into two triangles with +Z normals; it is not a RigidBody collision shape.

Fields

width: f64
Width in meters along local X; defaults to 1.
Default1
height: f64
Height in meters along local Y; defaults to 1.
Default1

Examples

Create a quad

The adapter places the surface in local XY.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
3

Rust definition

Interpreter RecordValue geometry schema consumed by spatial adapters.

Line

A line segment between two local positions.

Signature

type Line { from: Vec3 = Vec3 {}; to: Vec3 = Vec3 { x: 1 }; }

Endpoints are passed through as meters. The adapter tessellates the segment for rendering; no positive length or physics collision contract is declared here.

Fields

from: Vec3
Start point in local meters; defaults to the origin.
DefaultVec3 {}
to: Vec3
End point in local meters; defaults to (1, 0, 0).
DefaultVec3 { x: 1 }

Examples

Create a segment

Line endpoints are expressed in the entity's local coordinates.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
2

Rust definition

Interpreter RecordValue geometry schema consumed by spatial adapters.

Ray

A visual ray with an explicit finite length.

Signature

type Ray {
  origin: Vec3 = Vec3 {};
  direction: Vec3 = Vec3 { z: -1 };
  length: Number = 1;
}

The adapter requires direction magnitude greater than 1e-12 and positive length. It normalizes an accepted direction before building the rendered line.

Fields

origin: Vec3
Local origin in meters; defaults to zero.
DefaultVec3 {}
direction: Vec3
Local direction; spatial conversion requires magnitude greater than 1e-12 and normalizes the vector.
DefaultVec3 { z: -1 }
length: f64
Visible distance in meters; defaults to 1.
Default1

Examples

Create a ray

The default direction is local negative Z.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
-1

Rust definition

Interpreter RecordValue geometry schema consumed by spatial adapters.

Mesh

Indexed triangle geometry.

Signature

type Mesh { positions: Tensor[f32] = tensor[f32]([], [0, 3])?; indices: Tensor[u32] = tensor[u32]([], [0, 3])?; }

The spatial adapter requires 3..=16384 positions and 1..=32768 triangles, validates indices, and computes normals when it builds a render mesh.

Fields

positions: Tensor[f32]
An N by 3 Tensor[f32] of local XYZ coordinates in meters. The empty default is not renderable.
Defaulttensor[f32]([], [0, 3])?
indices: Tensor[u32]
An M by 3 Tensor[u32]; each row is a triangle and every index must address a position.
Defaulttensor[u32]([], [0, 3])?

Examples

Define one triangle

Indices address positions in triples.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
3
Inspect an unfilled schema

Construction itself does not invoke the mesh adapter.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
0

Rust definition

Interpreter RecordValue geometry schema; adapter validation produces the render mesh.

PointCloud

A bounded set of points rendered with a shared radius.

Signature

type PointCloud { points: Tensor[f32] = tensor[f32]([], [0, 3])?; radius: Number = 0.02; }

Rendering requires 1 through 16384 points and a positive radius. The adapter expands each point into tessellated sphere geometry, so this is not a point GPU primitive contract.

Fields

points: Tensor[f32]
An N by 3 Tensor[f32] of local XYZ positions in meters; the adapter requires 1..=16384 points.
Defaulttensor[f32]([], [0, 3])?
radius: f64
Point radius in meters; defaults to 0.02.
Default0.02

Examples

Create points

A spatial adapter consumes the points when the value is attached to an entity.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
2

Rust definition

Interpreter RecordValue geometry schema; the adapter expands points into render geometry.

Material

Surface appearance for geometry rendered by the spatial adapter.

Signature

type Material {
  color: Str = "#6fe3ff";
  roughness: Number = 0.6;
  emissive: Number = 0;
}

The adapter validates color as #RRGGBB or #RRGGBBAA. Roughness must be in 0..=1 and emissive intensity in 0..=100. Renderable geometry receives default Transform and Material values when omitted.

Fields

color: Str
Color in #RRGGBB or #RRGGBBAA form; defaults to #6fe3ff.
Default"#6fe3ff"
roughness: f64
Surface roughness from 0 through 1; defaults to 0.6.
Default0.6
emissive: f64
Emissive intensity from 0 through 100; defaults to 0.
Default0

Examples

Attach material

Geometry receives a default material if none is attached by the spatial adapter.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
#ff0000

Rust definition

Interpreter RecordValue appearance schema consumed by spatial adapters.

Physics

RigidBody

Physical-body configuration for a Sphere or Box entity.

Signature

type RigidBody {
  kind: Str = "dynamic";
  mass: Number = 1;
  velocity: Vec3 = Vec3 {};
  angular_velocity: Vec3 = Vec3 {};
  restitution: Number = 0.3;
  friction: Number = 0.5;
}

kind must be dynamic, fixed, or kinematic. Only dynamic bodies accept Force or Impulse; fixed bodies must have zero velocities.

Fields

kind: Str
dynamic, fixed, or kinematic; defaults to dynamic.
Default"dynamic"
mass: f64
Positive mass used by the collider; defaults to 1.
Default1
velocity: Vec3
Linear velocity in meters per second; defaults to zero.
DefaultVec3 {}
angular_velocity: Vec3
Angular velocity in radians per second; defaults to zero.
DefaultVec3 {}
restitution: f64
Bounciness in 0..=1; defaults to 0.3.
Default0.3
friction: f64
Contact friction in 0..=1; defaults to 0.5.
Default0.5

Examples

Advance a dynamic sphere

Systems run before physics in each fixed tick, so the second callback observes the position advanced by the first integration step.

Press Step 2 times to reach the checked result.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
true
Choose a fixed body

Fixed bodies keep zero velocity.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
fixed

Rust definition

Interpreter RecordValue physics schema consumed by the Rapier-backed spatial adapter.

Force

A world-space force applied every fixed physics tick.

Signature

type Force { value: Vec3 = Vec3 {}; }

The physics adapter applies it only to a dynamic RigidBody and reapplies the current value on each fixed step. Attaching Force without such a body is rejected.

Fields

value: Vec3
Force vector in newtons; defaults to zero and requires a dynamic RigidBody.
DefaultVec3 {}

Examples

Apply force on fixed ticks

The second callback observes movement produced by the first fixed integration step; the force remains attached for later steps.

Press Step 2 times to reach the checked result.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
true

Rust definition

Interpreter RecordValue force schema consumed by the physics adapter.

Impulse

A world-space impulse consumed once by physics reconciliation.

Signature

type Impulse { value: Vec3 = Vec3 {}; }

The physics adapter accepts it only with a dynamic RigidBody, applies it once, then resets value to zero. Attaching Impulse without such a body is rejected.

Fields

value: Vec3
Impulse vector in newton-seconds; defaults to zero and requires a dynamic RigidBody.
DefaultVec3 {}

Examples

Apply one impulse

The second callback observes movement from the first integration step, after which the adapter has consumed the impulse.

Press Step 2 times to reach the checked result.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading…Drag to orbit · select to inspect
0 entities
Loading the language runtime…
Output 0
No output.
Expected output
true

Rust definition

Interpreter RecordValue impulse schema consumed by the physics adapter.

Interface

Click

A typed interaction contract with one click operation.

Signature

trait Click { func click() -> Unit; }

Implement Click when a type should satisfy a nominal interaction contract or appear in query[Click](). Hosts may also invoke an ordinary checked click method without this trait; the host owns event dispatch.

Methods

click
func click() -> Unit

Required action with no arguments. A direct record method may mutate its receiver; a bound component callback is required when that mutation must persist to an entity.

Examples

Implement a click action

A type satisfies the contract with a matching typed method.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
clicked

Rust definition

Trait declaration checked by the interpreter; it is not a Rust SDK trait.

Text

Visible text content represented as a host UI schema.

Signature

type Text { value: Str = ""; size: Number = 0.2; }

Text is a declarative value only: layout, fonts, glyph shaping, and drawing remain host responsibilities. Constructing it never performs text rendering by itself.

Fields

value: Str
UTF-8 text content; defaults to empty.
Default""
size: f64
Requested text size in host scene units; defaults to 0.2.
Default0.2

Examples

Create text

Construction records content but does not itself draw it.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
hello

Rust definition

Interpreter RecordValue schema; text layout and drawing are host responsibilities.

Button

A host-rendered control with a typed no-argument action.

Signature

type Button { label: Str = "Button"; action: func() -> Res[Unit, DataError] = noop; }

The host invokes action through Machine::invoke_component. The default noop is intentional; a Button schema never dispatches an action by itself.

Fields

label: Str
Visible label; defaults to Button.
Default"Button"
action: func() -> Res[Unit, DataError]
Typed zero-argument callback; defaults to noop. Bind a live component method to persist mutations.
Defaultnoop

Examples

Use the default action

The default callback is callable and produces no log output.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
Button
Expose a clickable control

The spawned control retains a typed callback for host click dispatch; initialization makes the example's ready state observable.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading the language runtime…
Output 0
No output.
Expected output
button ready

Rust definition

Interpreter RecordValue UI schema; host input dispatch owns actual clicks.

Slider

A host-rendered numeric control with a typed value action.

Signature

type Slider {
  label: Str = "Slider";
  action: func(Number) -> Res[Unit, DataError] = ignore_number;
  min: Number = 0;
  max: Number = 1;
  value: Number = 0;
}

The host supplies a Number to action. A callback accepting input owns any update to Slider.value; schema construction and host input do not mutate it automatically.

Fields

label: Str
Visible label; defaults to Slider.
Default"Slider"
action: func(f64) -> Res[Unit, DataError]
Typed callback accepting the requested numeric value; defaults to ignore_number.
Defaultignore_number
min: f64
Lower requested bound; defaults to 0. Hosts should present min no greater than max.
Default0
max: f64
Upper requested bound; defaults to 1. Hosts should present max no less than min.
Default1
value: f64
Current requested numeric value; defaults to 0 and changes only through explicit checked state updates.
Default0

Examples

Inspect defaults

The default range is 0 through 1.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
1
Expose a changeable control

Change Gain: set_gain clamps the input, updates the stored Slider value, and logs the accepted value.

Tick 0 · 0.00 sThis device
main.kj⌘ / Ctrl + Enter
Loading the language runtime…
Output 0
No output.
Expected output
slider ready

Rust definition

Interpreter RecordValue UI schema; host input dispatch owns actual slider interaction.

Media

Image

An image resource request with display dimensions.

Signature

type Image {
  source: Str = "";
  width: Number = 1;
  height: Number = 1;
}

This schema declares desired resource data only. A host resolves source, owns I/O and permissions, and reports any loading failure; construction performs no I/O.

Fields

source: Str
Host-defined image locator; defaults to empty.
Default""
width: f64
Requested display width in scene units; defaults to 1.
Default1
height: f64
Requested display height in scene units; defaults to 1.
Default1

Examples

Describe an image

No file is read until a host chooses to resolve the source.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
poster.png

Rust definition

Interpreter RecordValue resource schema, not an image decoder or Rust SDK image handle.

Video

A video resource request with display dimensions.

Signature

type Video {
  source: Str = "";
  width: Number = 1;
  height: Number = 1;
}

This is a schema, not playback: the host owns decoding, timing, I/O, and any playback controls. Constructing it never starts a video.

Fields

source: Str
Host-defined video locator; defaults to empty.
Default""
width: f64
Requested display width in scene units; defaults to 1.
Default1
height: f64
Requested display height in scene units; defaults to 1.
Default1

Examples

Describe a video

The host decides whether and how the named resource plays.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
clip.mp4

Rust definition

Interpreter RecordValue resource schema, not a video decoder or playback handle.

VideoStream

A live video input request with display dimensions.

Signature

type VideoStream {
  source: Str = "camera";
  width: Number = 1;
  height: Number = 1;
}

The host owns permission, capture lifecycle, frame orientation, and resource contention. The default camera string is only a requested source selector.

Fields

source: Str
Host-defined live-video selector; defaults to camera.
Default"camera"
width: f64
Requested display width in scene units; defaults to 1.
Default1
height: f64
Requested display height in scene units; defaults to 1.
Default1

Examples

Request a stream

A host must grant permission and create the actual capture session.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
camera

Rust definition

Interpreter RecordValue stream schema, not a camera session or frame source.

Audio

An audio resource request with a gain value.

Signature

type Audio { source: Str = ""; volume: Number = 1; }

This schema does not decode or play audio. The host resolves source, owns I/O and playback lifecycle, and interprets the requested linear gain.

Fields

source: Str
Host-defined audio locator; defaults to empty.
Default""
volume: f64
Requested linear gain; defaults to 1 and is interpreted by the host.
Default1

Examples

Describe audio

Construction does not resolve or play the source.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
0.5

Rust definition

Interpreter RecordValue resource schema, not an audio decoder or playback handle.

AudioStream

A live audio input request with a gain value.

Signature

type AudioStream { source: Str = "microphone"; volume: Number = 1; }

The host owns microphone permission, capture lifecycle, and stream routing; this declaration does not open a microphone.

Fields

source: Str
Host-defined live-audio selector; defaults to microphone.
Default"microphone"
volume: f64
Requested linear gain; defaults to 1 and is interpreted by the host.
Default1

Examples

Request audio input

A host must grant permission and create any actual stream.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
microphone

Rust definition

Interpreter RecordValue stream schema, not a microphone session or audio buffer.

ImageFrame

Decoded byte pixels with an explicit channel axis.

Signature

type ImageFrame { pixels: Tensor[u8]; }

Pixels have shape [height, width, channels], with 1, 3 or 4 channels for Gray, RGB or RGBA. Construction uses the SDK Image validator. Channel order follows the last axis; this value contains no encoded file or device handle.

Fields

pixels: Tensor[u8]
Packed u8 pixels; height and width are positive and channels is 1, 3 or 4.

Examples

Construct ImageFrame

Inspect the typed payload and metadata.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
[1, 1, 4]

Rust definition

A checked language record delegating decoded media validation to konjure_sdk::data.

AudioBlock

Decoded audio samples with a checked sample rate.

Signature

type AudioBlock { samples: Tensor[f32]; sample_rate: u32; }

Samples have shape [sample_frames, channels] and finite f32 values. The SDK validates channel count and sample rate. This is a decoded block; playback, capture and scheduling belong to the host.

Fields

samples: Tensor[f32]
Sample-major f32 data with channels on the trailing axis.
sample_rate: u32
Samples per second, from 1 through 384000.

Examples

Construct AudioBlock

Inspect the typed payload and metadata.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
[4, 1]
48000

Rust definition

A checked language record delegating decoded media validation to konjure_sdk::data.

VideoFrame

A decoded image associated with a presentation timestamp.

Signature

type VideoFrame { image: ImageFrame; timestamp_ns: u64; }

Nanoseconds are exact u64 values, independent of wall-clock time. Place frames in a VideoClip to validate timestamp order and consistent image layout. A frame can be exchanged without starting a player or camera.

Fields

image: ImageFrame
A validated decoded image.
timestamp_ns: u64
Presentation timestamp in nanoseconds; no wall-clock origin is implied.

Examples

Construct VideoFrame

Inspect the typed payload and metadata.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
16666667

Rust definition

A checked language record delegating decoded media validation to konjure_sdk::data.

VideoClip

An immutable-value sequence of validated decoded video frames.

Signature

type VideoClip { frames: List[VideoFrame]; }

The SDK requires a nonempty sequence, strictly increasing timestamps and consistent image dimensions, dtype and channel format. Tensor buffers retain shared ownership. A live stream additionally needs host backpressure and lifetime handling.

Fields

frames: List[VideoFrame]
A nonempty ordered list of decoded frames with matching layouts.

Examples

Construct VideoClip

Inspect the typed payload and metadata.

Tick 0 · 0.00 s⌘ / Ctrl + EnterThis device
main.kj
Loading the language runtime…
Output 0
No output.
Expected output
2

Rust definition

A checked language record delegating decoded media validation to konjure_sdk::data.