-
Notifications
You must be signed in to change notification settings - Fork 0
API Host ScriptGlobal
一个 Domain 的全局对象
Global object for one domain
ScriptGlobal 是宿主向脚本暴露值、委托和对象的主要入口。Define 可以设置可写性和可枚举性;SetPropertyValue 用于更新已有或动态全局成员。
ScriptGlobalis the main entry point for exposing values, delegates, and objects to scripts.Definesets writability and enumerability;SetPropertyValueupdates existing or dynamic global members.
Returns
所属 AuroraEngine。
Owning
AuroraEngine.
var global = engine.NewEnvironment();
Console.WriteLine(ReferenceEquals(global.Engine, engine));Parameters:
-
key
脚本名称。Script name.
-
value
CLR 对象、ScriptObject或ScriptDatum。CLR object,
ScriptObject, orScriptDatum. -
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);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.
AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License