Skip to content

API Host CompiledBlock

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

CompiledBlock

Disposable compiled function-body block.

Namespace: AuroraScript.Runtime. Kind: class.

Back to .NET Host API Reference

Overview

CompiledBlock is produced by AuroraEngine.CompileBlock. It does not enter the module system, does not support import or include, and does not participate in hot patching; it suits formulas, filters, and small rules.

The type is disposable because block compilation registers dynamic delegates. Dispose the block when the host stops using it.

Quick Reference

A minimal use of CompiledBlock.

using var block = engine.CompileBlock("return value * 2;", ["value"]);
var result = block.Invoke(ScriptDatum.FromNumber(21));

Methods

Invoke

ScriptDatum Invoke(params ScriptDatum[] arguments)
ScriptDatum Invoke(params ScriptObject[] arguments)
ScriptDatum Invoke(ScriptDomain domain)
ScriptDatum Invoke(ScriptDomain domain, params ScriptDatum[] arguments)
ScriptDatum Invoke(ScriptDomain domain, params ScriptObject[] arguments)
ScriptDatum Invoke(ScriptContext context, ReadOnlySpan<ScriptDatum> arguments)

Invokes the compiled block.

Parameters

Name Type Required Description
arguments ScriptDatum[] or ScriptObject[] No Positional arguments matching the block parameter names.
domain ScriptDomain Yes Domain supplying globals and state for the call. Used by the domain overloads.
context ScriptContext Yes Explicit script context. Used by the context overload.

Returns

Returns ScriptDatum.

Behavior

Pass a domain or context when the block must observe domain globals or an existing execution context; the parameterless-domain overloads run the block on their own.

using var block = engine.CompileBlock("return value * 2;", ["value"]);
var result = block.Invoke(ScriptDatum.FromNumber(21));
using var domain = engine.CreateDomain();
using var block = engine.CompileBlock("return value + 1;", ["value"]);
var result = block.Invoke(domain, ScriptDatum.FromNumber(41));
using var domain = engine.CreateDomain();
using var block = engine.CompileBlock("return value;", ["value"]);
var values = new[] { ScriptDatum.FromNumber(42) };
var result = block.Invoke(new ScriptContext(domain), values);

Dispose

void Dispose()

Releases dynamic delegates registered during block compilation.

Parameters

None.

Returns

None.

Behavior

Disposal is deterministic; do not invoke the block afterward.

using (var block = engine.CompileBlock("return 42;", Array.Empty<string>()))
{
    var result = block.Invoke();
}

Clone this wiki locally