Skip to content

Language Guide

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

Language Guide

Learn the core AuroraScript syntax, module model, runtime values, and host-global declarations.

Applies to 4.0.0.

Home · Script API Reference

On this page

Modules and Dependencies

Every executable module begins with @module(NAME);. import consumes module exports and include combines source; paths are resolved by the host's Source Resolver rather than by scripts reading the file system directly.

// math.as
@module(MATH);

export func add(left, right) {
    return left + right;
}
// main.as
@module(MAIN);
import math from "./math";

export func run() {
    return math.add(20, 22);
}

Variables, Functions, and Closures

Use var for mutable locals and const for bindings that are not reassigned. Functions can be passed as values and capture outer locals; cache repeatedly read properties in a local inside hot loops.

func makeAdder(base) {
    return value => base + value;
}

var addTwenty = makeAdder(20);
return addTwenty(22); // 42

Objects, Arrays, and Built-in Values

Ordinary objects suit flexible properties and Array suits heterogeneous collections. For known-length numeric loops, prefer Int32Array, Float64Array, Int8Array, or BooleanArray. Look up detailed members by object in the Script API Reference.

var profile = { name: "Aurora", enabled: true };
var scores = [20, 22];
scores.push(42);
return profile.name + ":" + scores.join(",");

Errors, Diagnostics, and Output

Use throw new Error(message) for failures from which execution cannot continue; an expected “not found” result should usually return null or an agreed value. Use console.log and console.error for host-collected output.

func findPositive(values) {
    var item = values.find(value => value > 0);
    if (item == null) throw new Error("positive value is required");
    console.log("found", item);
    return item;
}

Host Globals and Declaration Files

Names injected by the host through ScriptGlobal can be used directly in scripts. For editor diagnostics and completion, add a standalone @global(); declaration file visible to the Resolver; use declare const, declare var, or declare func, not export declare.

@global();

declare const APP_NAME;
declare func HOST_ADD(left, right);

Next steps

Clone this wiki locally