Reference · reference
wscript prelude
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.
print and 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
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
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 part | Form | Meaning |
|---|---|---|
| fill and align | [fill]<, [fill]^, [fill]> | left, centre or right in the width, padded with the fill character |
| zero | 0 | zero-pad a number, sign-aware |
| width | an integer | minimum width in characters |
| precision | .N | digits after the point for a float; truncation length for a string |
| type | x, X, b, o | hex, 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
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
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
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
Convert an integer to a 64-bit float. A float passes through unchanged.