-
Notifications
You must be signed in to change notification settings - Fork 0
API Host ClrMarshaller
Value conversion helper between CLR values and AuroraScript runtime values.
Namespace: AuroraScript.Runtime.Interop. Kind: class.
Back to .NET Host API Reference
ClrMarshaller provides explicit boundary conversion. When an API already accepts ScriptDatum, pass the datum directly to avoid unnecessary object wrapping and conversion back.
Tip
Use ToDatum and ToScript for ordinary host values; use ScriptDatum factories when exact runtime kinds are required.
A minimal use of ClrMarshaller.
var arguments = ClrMarshaller.ToDatums(new object[] { 20, 22 });
var result = domain.Execute("MAIN", "add", arguments);static ScriptDatum ToDatum(object value)Converts a CLR value to a runtime value.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
object |
Yes | CLR value to convert. |
Returns
Returns ScriptDatum.
var datum = ClrMarshaller.ToDatum(new[] { 1, 2, 3 });static void WriteToDatum(ref ScriptDatum datum, object value)Writes a converted CLR value into an existing datum slot.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
datum |
ref ScriptDatum |
Yes | Slot receiving the converted value. |
value |
object |
Yes | CLR value to convert. |
Returns
None.
Behavior
Prefer this overload inside raw ClrDatumDelegate callbacks, where the result slot is already available by reference.
var datum = ClrMarshaller.ToDatum(new[] { 1, 2, 3 });
ClrMarshaller.WriteToDatum(ref datum, "Aurora");static ScriptDatum[] ToDatums(object[] values)
static ScriptDatum[] ToDatums(ScriptObject[] arguments)Converts an argument array to runtime values.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
values |
object[] |
Yes | CLR values to convert. Used by the first overload. |
arguments |
ScriptObject[] |
Yes | Script objects to convert. Used by the second overload. |
Returns
Returns ScriptDatum[].
var arguments = ClrMarshaller.ToDatums(new object[] { 20, 22 });
var result = domain.Execute("MAIN", "add", arguments);static ScriptObject ToScript(object value)Converts a CLR value to a script object.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value |
object |
Yes | CLR value to convert. |
Returns
Returns ScriptObject usable by scripts.
var scriptValue = ClrMarshaller.ToScript(new { Name = "Aurora" });static bool TryConvertArgument(ScriptObject scriptValue, Type targetType, out object result)
static bool TryConvertArgument(in ScriptDatum datum, Type targetType, out object result)Attempts to convert a script value to a requested CLR type.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
scriptValue |
ScriptObject |
Yes | Script object to convert. Used by the first overload. |
datum |
in ScriptDatum |
Yes | Runtime value to convert. Used by the second overload. |
targetType |
Type |
Yes | Requested CLR type. |
result |
out object |
Yes | Receives the conversion result. |
Returns
true when conversion succeeded; otherwise false.
Behavior
The method reports failure through its return value instead of throwing, so the host decides how to handle an incompatible script value.
var value = ScriptDatum.FromNumber(42);
if (ClrMarshaller.TryConvertArgument(value, typeof(int), out var result))
{
Console.WriteLine((int)result);
}AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License