-
Notifications
You must be signed in to change notification settings - Fork 0
API Host Extended
Host callback helpers for reading ScriptDatum spans and checking runtime value flags.
Namespace: AuroraScript. Kind: class.
Back to .NET Host API Reference
Extended is a static class of extension methods. The span readers pull a typed value out of a positional argument span without copying or boxing it, and Include tests a ValueKind flag.
Note
These helpers are mainly useful inside ClrDatumDelegate or other raw ScriptDatum host callbacks.
A minimal use of Extended.
Span<ScriptDatum> args = [ScriptDatum.FromNumber(42)];
if (args.TryGetInt32(0, out var value))
{
Console.WriteLine(value); // 42
}static bool Include(this ValueKind valueKind, ValueKind flag)Tests whether a value kind contains a flag.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
valueKind |
ValueKind |
Yes | Value kind to inspect. |
flag |
ValueKind |
Yes | Flag to test for. |
Returns
true when the flag is set; otherwise false.
if (datum.Kind.Include(ValueKind.String))
{
Console.WriteLine(ScriptDatum.ToString(datum));
}static bool TryGetNumber(this Span<ScriptDatum> source, int index, out double value)
static bool TryGetInteger(this Span<ScriptDatum> source, int index, out long value)
static bool TryGetInt32(this Span<ScriptDatum> source, int index, out int value)
static bool TryGetStrictNumber(this Span<ScriptDatum> source, int index, out double value)
static bool TryGetString(this Span<ScriptDatum> source, int index, out string value)
static bool TryGetObject(this Span<ScriptDatum> source, int index, out ScriptObject value)
static bool TryGetEnumerator(this Span<ScriptDatum> source, int index, out ScriptEnumerator value)
static bool TryGetFunction(this Span<ScriptDatum> source, int index, out ClosureFunction value)
static bool TryGetBoolean(this Span<ScriptDatum> source, int index, out bool value)
static bool TryGetRef(this Span<ScriptDatum> source, int index, ref ScriptDatum value)Reads one positional argument as a specific type.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
source |
Span<ScriptDatum> |
Yes | Argument span supplied to the host callback. |
index |
int |
Yes | Zero-based argument index to read. |
value |
out or ref parameter |
Yes | Receives the read value. Its type depends on the reader. |
Returns
true when the argument exists and matches the requested type; otherwise false.
Behavior
-
TryGetNumberapplies script number coercion;TryGetStrictNumberaccepts number values only. -
TryGetReftakes the target byrefso the callback can read and write the same slot. - Reading past the end of
sourcereturnsfalseinstead of throwing, so a callback can treat missing arguments as optional.
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);
};AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License