Reference · reference

wscript prelude

4 min read · 2026-09-02 · config-weave 0.1.0

The prelude is the set of functions every script can call without a use line. The built-in types Option[T], Result[T, E], List[T], Map[K, V] and weak[T] are also always in scope, as is every host-registered type such as Value, CheckResult and ApplyResult. The prelude's role in a script is explained in wscript: values, types and functions.

rust
fn print(value: any)
fn println(value: any)
fn println()

Render a value with its Display implementation and emit it. println appends a newline and, with no argument, emits a bare newline. In config-weave neither writes to standard output: every line is routed to the log module at the info level, so println("done") and log::info("done") produce the same log record. See log module.

str

rust
fn str(value: any) -> string

Convert any value to a string. A struct or enum with a Display implementation, derived or hand-written, renders through it. str is also the rendering used for a {expr} hole inside a string literal.

fmt

rust
fn fmt(template: string, args: any...) -> string

Substitute the arguments into the {} placeholders of the template, in order. Write {{ and }} for a literal brace. When the template is a literal, the compiler checks the placeholder count against the argument count and checks each format spec. A placeholder may carry a spec after a colon.

Spec partFormMeaning
fill and align[fill]<, [fill]^, [fill]>left, centre or right in the width, padded with the fill character
zero0zero-pad a number, sign-aware
widthan integerminimum width in characters
precision.Ndigits after the point for a float; truncation length for a string
typex, X, b, ohex, upper hex, binary or octal; integers only

For example {:>8} right-aligns in eight characters, {:.2} gives two decimals, {:04} zero-pads to four, and {:x} renders hex. A spec is rejected inside an interpolation hole; only fmt formats.

same

rust
fn same(a: T, b: T) -> bool

Return whether two references point at the same object. This is reference identity, not value equality. == compares values and needs an Eq implementation on a struct or enum.

weak

rust
fn weak(value: T) -> weak[T]

Make a weak reference from a reference-typed value. The argument must be a reference type. Call .upgrade() on the result to get an Option[T], which is None once every strong reference is gone. Use it to break reference cycles, which otherwise leak; see memory.

int

rust
fn int(value: int) -> int
fn int(value: float) -> int
fn int(value: char) -> int

Convert to a 64-bit integer. A float truncates toward zero. A char gives its Unicode code point. There is no implicit numeric conversion in wscript, so this is the only way to add a float to an int.

float

rust
fn float(value: int) -> float
fn float(value: float) -> float

Convert an integer to a 64-bit float. A float passes through unchanged.