wired:script
Script lifecycle exports and host permission queries.
Interface lifecycle
Lifecycle callbacks exported by every script and invoked by the host.
Calls never overlap. If a callback is still running when its next turn arrives, that turn is skipped rather than queued. Scripts that hang are terminated.
tick
Timing snapshot from the local monotonic clock shared by scripts on this peer (not synchronized across peers).
dt: f32 | Seconds elapsed since the previous call to this export (0 on the first call). |
time: f64 | Elapsed seconds on the host clock. |
index: u64 | Zero-based call count for this export. |
init
init: func() -> result<_, string>Called once before any other export. Returning an error logs the message and stops the script.
update
update: func(tick: tick)Called once per rendered frame. Use for visual interpolation and animation.
fixed-update
fixed-update: func(tick: tick)Called on a fixed timestep (currently 20 Hz), with tick.dt carrying the
step duration. Use for input, messaging, and simulation.
Interface host
Uses permission.
Host queries available to a running script.
granted
granted: func(permission: permission) -> boolReturns whether the script's document currently has permission. Grants
can change at runtime if the user updates trust levels.
Source
/// Script lifecycle exports and host permission queries.
package wired:script;
/// Lifecycle callbacks exported by every script and invoked by the host.
///
/// Calls never overlap. If a callback is still running when its next turn
/// arrives, that turn is skipped rather than queued. Scripts that hang are
/// terminated.
interface lifecycle {
/// Timing snapshot from the local monotonic clock shared by scripts on this
/// peer (not synchronized across peers).
record tick {
/// Seconds elapsed since the previous call to this export (`0` on the
/// first call).
dt: f32,
/// Elapsed seconds on the host clock.
time: f64,
/// Zero-based call count for this export.
index: u64,
}
/// Called once before any other export. Returning an error logs the message
/// and stops the script.
init: func() -> result<_, string>;
/// Called once per rendered frame. Use for visual interpolation and
/// animation.
update: func(tick: tick);
/// Called on a fixed timestep (currently 20 Hz), with `tick.dt` carrying the
/// step duration. Use for input, messaging, and simulation.
fixed-update: func(tick: tick);
}
/// Host queries available to a running script.
interface host {
use wired:core/error.{permission};
/// Returns whether the script's document currently has `permission`. Grants
/// can change at runtime if the user updates trust levels.
granted: func(permission: permission) -> bool;
}