-
Notifications
You must be signed in to change notification settings - Fork 0
API Host ClosureFunction
Compiled script function object returned by GetMethod and function-valued properties.
Namespace: AuroraScript.Runtime.Types. Kind: class.
Back to .NET Host API Reference
ClosureFunction is a handle to a compiled script function together with its captured environment. Hosts obtain one from ScriptDomain.GetMethod or by reading a function-valued property, then invoke it directly.
Tip
Prefer ScriptDomain.Execute for ordinary calls. Use ClosureFunction when the host needs to control the ScriptContext or invoke the same closure repeatedly, for example from a callback stored by the host.
A minimal use of ClosureFunction.
var run = domain.GetMethod("MAIN", "run");
if (run is not null)
{
var result = run.InvokeClrDetached(ScriptDatum.FromNumber(20));
Console.WriteLine(result);
}string FuncNameScript function name.
Parameters
None.
Returns
Returns string.
Console.WriteLine(run.FuncName);ScriptModule ModuleModule the function was compiled in.
Parameters
None.
Returns
Returns ScriptModule.
var module = run.Module;ScriptDatum InvokeClr(ScriptContext ctx, params ScriptDatum[] args)Invokes the closure using an active script context.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
ctx |
ScriptContext |
Yes | Active script execution context. |
args |
ScriptDatum[] |
No | Positional arguments passed to the function. |
Returns
Returns ScriptDatum.
Behavior
Use this overload while already inside script execution, such as from a host callback that received a ScriptContext.
ClrDatumDelegate invoke = (
ScriptContext ctx,
ScriptObject module,
Span<ScriptDatum> args,
ref ScriptDatum result) =>
{
result = run.InvokeClr(ctx, ScriptDatum.FromNumber(20));
};ScriptDatum InvokeClrDetached(params ScriptDatum[] args)
ScriptDatum InvokeClrDetached(ScriptObject userState, params ScriptDatum[] args)Invokes the closure from a new root context; use for deferred or asynchronous host calls.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
userState |
ScriptObject |
Yes | Host state attached to the new root context. Used by the second overload. |
args |
ScriptDatum[] |
No | Positional arguments passed to the function. |
Returns
Returns ScriptDatum.
Behavior
The call creates its own root context, so it is safe after the originating Execute call has returned.
var result = run.InvokeClrDetached(ScriptDatum.FromNumber(20));AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License