Skip to content

API Host ScriptContext

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

ScriptContext

传递给高级宿主回调和 CompileBlock 调用的执行上下文。

Execution context passed to advanced host callbacks and compiled block invocations.

命名空间:AuroraScript.Runtime。类型:class。

Namespace: AuroraScript.Runtime. Kind: class.

返回 .NET Host API 参考

Back to .NET Host API Reference

用途

Purpose

ScriptContext 是公开宿主类型。通过下方签名选择调用方式;对运行时对象、生命周期和异常,应由宿主在边界处明确处理。

Execution context passed to advanced host callbacks and compiled block invocations.

注意

此类型主要用于自定义 CLR 回调和高级闭包调用。

Use this type mainly for custom CLR callbacks and advanced closure invocation.

简单示例

Simple Example

下面是 ScriptContext 的最小使用方式。

A minimal use of ScriptContext.

using var domain = engine.CreateDomain();

var context = new ScriptContext(domain);
Console.WriteLine(context.Domain == domain); // True

成员

Members

Constructor

签名

  • ScriptContext(ScriptDomain domain)
  • ScriptContext(ScriptDomain domain, ScriptObject userState)

创建 ScriptContext 实例。

Use the member according to its public signature.

Parameters:

  • domain
    要使用的脚本 Domain。

    Script Domain to use.

  • userState
    与执行上下文关联的用户状态。

    User state associated with the execution context.

Returns

新建的 ScriptContext 实例。

A new ScriptContext instance.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

var value = new ScriptContext(/* 参数 */);

ScriptDomain Domain

读取 Domain 字段。

Use the member according to its public signature.

Parameters:

  • 无。

    None.

Returns

返回 ScriptDomain

Returns ScriptDomain.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

ScriptContext value = /* 从宿主 API 获取实例 */;
var current = value.Domain;

AuroraEngine Engine

读取 Engine 字段。

Use the member according to its public signature.

Parameters:

  • 无。

    None.

Returns

返回 AuroraEngine

Returns AuroraEngine.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

ScriptContext value = /* 从宿主 API 获取实例 */;
var current = value.Engine;

ScriptGlobal Global

读取 Global 字段。

Use the member according to its public signature.

Parameters:

  • 无。

    None.

Returns

返回 ScriptGlobal

Returns ScriptGlobal.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

ScriptContext value = /* 从宿主 API 获取实例 */;
var current = value.Global;

ScriptModule Module

读取 Module 字段。

Use the member according to its public signature.

Parameters:

  • 无。

    None.

Returns

返回 ScriptModule

Returns ScriptModule.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

ScriptContext value = /* 从宿主 API 获取实例 */;
var current = value.Module;

ScriptObject UserState

读取 UserState 字段。

Use the member according to its public signature.

Parameters:

  • 无。

    None.

Returns

返回 ScriptObject

Returns ScriptObject.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

ScriptContext value = /* 从宿主 API 获取实例 */;
var current = value.UserState;

ClosureFunction Target

读取 Target 字段。

Use the member according to its public signature.

Parameters:

  • 无。

    None.

Returns

返回 ClosureFunction

Returns ClosureFunction.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

ScriptContext value = /* 从宿主 API 获取实例 */;
var current = value.Target;

long Location

读取 Location 字段。

Use the member according to its public signature.

Parameters:

  • 无。

    None.

Returns

返回 long

Returns long.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

ScriptContext value = /* 从宿主 API 获取实例 */;
var current = value.Location;

With

签名

  • ScriptContext With(ScriptModule module, ClosureFunction closure = null)
  • ScriptContext With(ClosureFunction closure)
  • ScriptContext With(ScriptModule module, ClosureFunction closure, ScriptObject userState)

调用 With 完成其公开操作。

Use the member according to its public signature.

Parameters:

  • module
    要关联或执行的脚本模块。

    Script module to associate or execute.

  • closure
    要调用的闭包函数。

    Closure function to invoke.

  • userState
    与执行上下文关联的用户状态。

    User state associated with the execution context.

Returns

返回 ScriptContext

Returns ScriptContext.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

ScriptContext value = /* 从宿主 API 获取实例 */;
var result = value.With(/* module */, /* closure */);

AuroraStackTrace[] CallStack()

调用 CallStack 完成其公开操作。

Use the member according to its public signature.

Parameters:

  • 无。

    None.

Returns

返回 AuroraStackTrace[]

Returns AuroraStackTrace[].

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

ScriptContext value = /* 从宿主 API 获取实例 */;
var result = value.CallStack();

List<AuroraStackTrace> StackTrace()

调用 StackTrace 完成其公开操作。

Use the member according to its public signature.

Parameters:

  • 无。

    None.

Returns

返回 List<AuroraStackTrace>

Returns List<AuroraStackTrace>.

调用示意

以下示例展示调用形状;将占位实例和参数替换为宿主中的实际值。

The example shows the call shape; replace placeholder instances and arguments with actual host values.

ScriptContext value = /* 从宿主 API 获取实例 */;
var result = value.StackTrace();

Clone this wiki locally