Skip to content

Getting Started

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

快速开始

Getting Started

适用版本:4.0.0

Applies to 4.0.0.

首页 · 宿主集成 · 语言指南

Home · Host Integration · Language Guide

本页内容 · On This Page

安装

Installation

在 .NET 宿主项目中安装 NuGet 包:

Install the NuGet package in the .NET host project:

dotnet add package AuroraScript.JIT --version 4.0.0

当前包目标框架为 net8.0net9.0net10.0DynamicOnlyRun 可用于这三个目标;Persistence 需要 net9.0 或更高版本。

The package targets net8.0, net9.0, and net10.0. Dynamic and OnlyRun work on all three targets; Persistence requires net9.0 or later.

第一个模块

Your First Module

先创建脚本文件 scripts/main.as@module 必须是第一条有效语句。

First create scripts/main.as. @module must be the first effective statement.

@module(MAIN);

export func main(value) {
    return value + 22;
}

再创建引擎、编译脚本、创建 Domain 并执行导出函数。

Then create the engine, build the script, create a domain, and execute the exported function.

using AuroraScript;
using AuroraScript.Core;
using AuroraScript.Runtime;

var options = EngineOptions.Default
    .WithCompiler(compiler =>
    {
        compiler.SourceResolver = ScriptSources.FileSystem("./scripts");
        compiler.Mode = CompilationMode.Dynamic;
    });

var engine = new AuroraEngine(options);
await engine.BuildAsync("main.as");

using var domain = engine.CreateDomain();
var result = domain.Execute("MAIN", "main", ScriptDatum.FromNumber(20));
Console.WriteLine(result); // 42

AuroraEngine 负责配置和编译;ScriptDomain 是一次独立运行环境,拥有自己的全局对象和模块实例。

AuroraEngine owns configuration and compilation; ScriptDomain is an isolated execution environment with its own global object and module instances.

下一步

Next Steps

Clone this wiki locally