-
Notifications
You must be signed in to change notification settings - Fork 0
Language Guide
Language Guide
适用版本:4.0.0。
Applies to 4.0.0.
AuroraScript 的写法接近 JavaScript,但语义和运行时 API 以 AuroraScript 为准。不要把浏览器、Node.js 或 ECMAScript 的 API 假定为可用。
AuroraScript resembles JavaScript in syntax, but its semantics and runtime APIs are defined by AuroraScript. Do not assume browser, Node.js, or ECMAScript APIs are available.
Modules and Dependencies
每个可执行模块以 @module(NAME); 开始。import 导入模块导出,include 合并源码;路径由宿主的 Source Resolver 解析,而不是由脚本直接读取文件系统。
Every executable module begins with
@module(NAME);.importconsumes module exports andincludecombines 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
使用 var 声明可变局部变量,const 声明不可重新赋值的绑定。函数可以作为值传递并捕获外层局部变量;热点循环中应把反复读取的属性缓存到 local。
Use
varfor mutable locals andconstfor 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); // 42Objects, Arrays, and Built-in Values
普通对象适合灵活属性,Array 适合异构集合;已知长度且只做数值循环时,优先使用 Int32Array、Float64Array、Int8Array 或 BooleanArray。详细成员请在脚本 API 参考中按对象查找。
Ordinary objects suit flexible properties and
Arraysuits heterogeneous collections. For known-length numeric loops, preferInt32Array,Float64Array,Int8Array, orBooleanArray. 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
用 throw new Error(message) 表示无法继续的错误;正常的“未找到”结果通常应返回 null 或约定值。使用 console.log 和 console.error 输出由宿主收集的日志。
Use
throw new Error(message)for failures from which execution cannot continue; an expected “not found” result should usually returnnullor an agreed value. Useconsole.logandconsole.errorfor 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
宿主通过 ScriptGlobal 注入的名称可以直接在脚本中使用。若需要编辑器诊断和补全,在 Resolver 可见目录添加独立的 @global(); 声明文件;使用 declare const、declare var 或 declare func,不要使用 export declare。
Names injected by the host through
ScriptGlobalcan be used directly in scripts. For editor diagnostics and completion, add a standalone@global();declaration file visible to the Resolver; usedeclare const,declare var, ordeclare func, notexport declare.
@global();
declare const APP_NAME;
declare func HOST_ADD(left, right);Continue Reading
-
宿主集成:配置 Resolver、Domain、状态和 CLR 互操作。
Host Integration: configure resolvers, domains, state, and CLR interop.
-
示例手册:面向常见任务的完整小样例。
Cookbook: complete small examples for common tasks.
-
性能与基准:热点写法与可复现测量方法。
Performance and Benchmarks: hot-path patterns and reproducible measurement.
AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License