Skip to content

API Host ScriptGlobal

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

ScriptGlobal

一个 Domain 的全局对象

Global object for one domain

.NET Host API 目录

概述

ScriptGlobal 是宿主向脚本暴露值、委托和对象的主要入口。Define 可以设置可写性和可枚举性;SetPropertyValue 用于更新已有或动态全局成员。

ScriptGlobal is the main entry point for exposing values, delegates, and objects to scripts. Define sets writability and enumerability; SetPropertyValue updates existing or dynamic global members.

Engine

Returns

所属 AuroraEngine

Owning AuroraEngine.

var global = engine.NewEnvironment();
Console.WriteLine(ReferenceEquals(global.Engine, engine));

Define(key, value, [writeable], [enumerable])

Parameters:

  • key
    脚本名称。

    Script name.

  • value
    CLR 对象、ScriptObjectScriptDatum

    CLR object, ScriptObject, or ScriptDatum.

  • writeable
    是否允许脚本写入。

    Whether scripts may write it.

  • enumerable
    是否参与枚举。

    Whether it participates in enumeration.

Returns

无。

None.

var global = engine.NewEnvironment();
global.Define("HOST_ADD", (Func<int, int, int>)((left, right) => left + right));
global.Define("BUILD", ScriptDatum.FromNumber(4), writeable: false, enumerable: true);

SetPropertyValue(key, value)

Parameters:

  • key
    要更新的全局名。

    Global name to update.

  • value
    CLR 对象或 ScriptObject

    CLR object or ScriptObject.

Returns

无。

None.

var global = engine.NewEnvironment();
global.SetPropertyValue("REQUEST_ID", "r-42");

若脚本需要静态诊断与补全,另建 @global(); 声明文件,而不是在脚本中重复定义宿主全局。

when scripts need static diagnostics and completion, create a @global(); declaration file rather than redefining host globals in script.

Clone this wiki locally