-
Notifications
You must be signed in to change notification settings - Fork 0
API Host ScriptDomain
隔离的脚本运行环境
Isolated script execution environment
ScriptDomain 绑定一个已编译的 AuroraEngine,但拥有独立的 Global、模块注册表和可选 UserState。它实现 IDisposable;不再使用时必须释放。
ScriptDomainis bound to a compiledAuroraEngine, but owns an independentGlobal, module registry, and optionalUserState. It implementsIDisposableand must be disposed when no longer needed.
Returns
当前 Domain 的全局对象、所属 Engine 和可选状态。
Current domain global, owning engine, and optional state.
using var domain = engine.CreateDomain();
Console.WriteLine(ReferenceEquals(domain.Engine, engine));
domain.Global.Define("REQUEST_ID", "r-42");Parameters:
-
moduleName
@module名。@modulename. -
methodName
导出函数名。Exported function name.
-
arguments
ScriptDatum或ScriptObject实参。ScriptDatumorScriptObjectarguments;部分重载也接受调用时的userState/ some overloads also accept call-timeuserState.
Returns
ScriptDatum 结果。
ScriptDatumresult.
using var domain = engine.CreateDomain();
var result = domain.Execute(
"MAIN",
"main",
ScriptDatum.FromNumber(20));Parameters:
-
moduleName
模块名。Module name.
-
methodName
导出函数名。Exported function name.
Returns
用于高级调用的 ClosureFunction。
ClosureFunctionfor advanced invocation.
var method = domain.GetMethod("MAIN", "main");
var result = method.InvokeClrDetached(ScriptDatum.FromNumber(20));通常优先使用 Execute;只有需要控制 ScriptContext 或重复调用闭包时再使用 GetMethod。
prefer
Executenormally; useGetMethodonly when controllingScriptContextor repeatedly invoking a closure is needed.
Parameters:
-
moduleName
模块名。Module name.
Returns
模块对象。
Module object.
var module = domain.GetModule("MAIN");Parameters:
-
source或modulePath。Patch source or target module path.
-
script
补丁源码。Patch source text.
-
patchType
HotPatchType标志。HotPatchTypeflags.
Returns
无。
None.
domain.DynamicPatch(
"scripts/main.as",
"@module(MAIN); export func run() { return 42; }",
HotPatchType.Replace);Parameters:
- 与同步版本相同,另加可选取消令牌。
Same inputs as synchronous overloads plus optional cancellation token.
Returns
代表补丁完成的 Task。
Taskfor patch completion.
await domain.DynamicPatchAsync(
"scripts/main.as",
"export func added() { return 1; }",
HotPatchType.Incremental);
ReplacePatch(modulePath, script, [ignoreDepends]) / IncrementalPatch(modulePath, script, [ignoreDepends])
Parameters:
-
modulePath
目标路径。Target path.
-
script
替换或增量源码。Replacement or incremental source.
-
ignoreDepends
是否跳过依赖更新。Whether to skip dependency updates.
Returns
无。
None.
domain.ReplacePatch("scripts/main.as", "@module(MAIN); export func run() { return 42; }");
domain.IncrementalPatch("scripts/main.as", "export func added() { return 1; }");Parameters:
- 与同步版本相同,另加可选取消令牌。
Same inputs as synchronous versions plus optional cancellation token.
Returns
Task。
Task.
await domain.ReplacePatchAsync("scripts/main.as", "@module(MAIN); export func run() { return 42; }");
await domain.IncrementalPatchAsync("scripts/main.as", "export func added() { return 1; }");Parameters:
- 无。
None.
Returns
无。
None.
用途
释放 Domain 关联资源,之后不得再调用它。
Releases domain-associated resources; do not use the domain afterward.
using var domain = engine.CreateDomain();
var result = domain.Execute("MAIN", "run");AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License