Skip to content

API Host BondingFunction

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

BondingFunction

Script callable wrapper for a ClrDatumDelegate.

Namespace: AuroraScript.Runtime.Types. Kind: class.

Back to .NET Host API Reference

Overview

BondingFunction turns a raw ClrDatumDelegate into a value that scripts can call like any other function. It is the advanced path: the delegate receives the script context, the owning module, the argument span, and a ref result slot.

Tip

For simple host functions, passing a normal CLR delegate to ScriptGlobal.Define is usually easier.

Quick Reference

A minimal use of BondingFunction.

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

var function = new BondingFunction(answer);

Constructors

BondingFunction

BondingFunction(ClrDatumDelegate callback)

Wraps a host delegate as a script-callable function.

Parameters

Name Type Required Description
callback ClrDatumDelegate Yes Callback invoked by the runtime.

Returns

A new BondingFunction instance.

var function = new BondingFunction(answer);

Properties

Name

string Name

Function name reported to scripts.

Parameters

None.

Returns

Returns string.

Console.WriteLine(function.Name);

Fields

Target

ScriptObject Target

Object the function is bound to, or null when unbound.

Parameters

None.

Returns

Returns ScriptObject.

var target = function.Target;

DatumMethod

ClrDatumDelegate DatumMethod

Underlying host delegate the function invokes.

Parameters

None.

Returns

Returns ClrDatumDelegate.

var callback = function.DatumMethod;

Methods

Bind

BondingFunction Bind(ScriptObject target)

Returns a function bound to the supplied target object.

Parameters

Name Type Required Description
target ScriptObject Yes Object to bind as the call target.

Returns

Returns BondingFunction.

var bound = function.Bind(hostService);

Clone this wiki locally