Skip to content

API Host ClrDatumDelegate

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

ClrDatumDelegate

Advanced delegate shape for native host functions that operate directly on ScriptDatum values.

Namespace: AuroraScript.Runtime.Types. Kind: delegate.

Back to .NET Host API Reference

Overview

ClrDatumDelegate is the lowest-level host function shape. The runtime hands over the active context, the owning module, the argument span, and a ref result slot, so the callback reads and writes runtime values without boxing or intermediate conversion.

Wrap a delegate in BondingFunction to expose it as a script-callable value, and use the Extended span readers to pull typed arguments out of args.

Tip

For simple host functions, passing a normal CLR delegate to ScriptGlobal.Define is usually easier; use this shape only when the host needs raw ScriptDatum access.

Quick Reference

A minimal use of ClrDatumDelegate.

ClrDatumDelegate answer = (
    ScriptContext ctx,
    ScriptObject module,
    Span<ScriptDatum> args,
    ref ScriptDatum result) =>
{
    result = ScriptDatum.FromNumber(42);
};

Methods

Invoke

void Invoke(ScriptContext ctx, ScriptObject module, Span<ScriptDatum> args, ref ScriptDatum result)

Delegate signature invoked by the runtime.

Parameters

Name Type Required Description
ctx ScriptContext Yes Active script execution context.
module ScriptObject Yes Module or object owning the call.
args Span<ScriptDatum> Yes Positional arguments supplied by the script.
result ref ScriptDatum Yes Slot receiving the return value.

Returns

None. The return value is written to result.

Behavior

args is a stack-based span that is only valid for the duration of the call; copy any value the host needs to keep.

ClrDatumDelegate add = (
    ScriptContext ctx,
    ScriptObject module,
    Span<ScriptDatum> args,
    ref ScriptDatum result) =>
{
    if (args.TryGetNumber(0, out var left) && args.TryGetNumber(1, out var right))
        result = ScriptDatum.FromNumber(left + right);
};

Clone this wiki locally