Skip to content

API Special Values

Liu.Yandong.Hanks edited this page Aug 21, 2026 · 3 revisions

$state and $args

Compiler-provided context values available inside script code.

Script API Reference

Overview

$state and $args are not constructors or global objects. They are context values the compiler supplies, so they are read directly rather than constructed or called.

Important

Neither name can be used as a CompileBlock parameter name.

Values

$state

Returns

The ScriptObject user state the host supplied when it created the ScriptDomain, or null when no state exists.

Behavior

Read-only from the script side. Treat the shape of the state object as a contract with the host.

Example

@module(MAIN);

export func userName() {
    return $state.Name;
}

$args

Returns

The collection of every argument the current function call received, readable through length and numeric indexes.

Tip

Prefer explicit function parameters. Use $args only when variable arity is genuinely part of the function's contract.

Example

@module(MAIN);

export func last() {
    return $args[$args.length - 1];
}

Clone this wiki locally