-
Notifications
You must be signed in to change notification settings - Fork 0
Typed Functions and Analysis
RuleScript v1.10.0 includes the v1.9 typed function and overload model. User, host, and built-in functions participate in one signature-based resolution model.
function Format(value: number, prefix: string, enabled: bool) -> string:
if enabled then:
return prefix + ToString(value);
endif
return prefix;
endfunction
Supported type names are:
anynullnumberstring-
bool/boolean arrayobjectvoid
Untyped parameters accept any value. Old-style functions remain valid, but new code should declare return types when the return contract matters.
function Notify(message: string) -> void:
Print(message);
return;
endfunction
void functions must not return a value. return; is valid.
Functions may share a name when their parameter signatures differ:
function Format(value: number) -> string:
return ToString(value);
endfunction
function Format(value: string) -> string:
return value;
endfunction
Duplicate signatures are rejected. Overloads with the same name must use the same declared return type.
Overload resolution uses function name, argument count, argument type compatibility, and exact matches before any. Return type does not participate in overload resolution. Runtime does not perform automatic type conversion for overload selection.
engine.RegisterFunction(
"Add",
parameters:
[
new("left", RuleScriptValueType.Number),
new("right", RuleScriptValueType.Number)
],
returnType: RuleScriptValueType.Number,
function: args => Convert.ToDouble(args[0]) + Convert.ToDouble(args[1]));Typed Host Functions validate argument count and types before invoking the delegate, then validate its return value. Equivalent overloads exist for RegisterFunctionAsync.
Use RuleScriptAnalysisResult.Functions for current editor-facing metadata:
RuleScriptAnalysisResult symbols = engine.Analyze(script);
foreach (var function in symbols.Functions)
{
Console.WriteLine($"{function.Kind}: {function.Signature}");
}RuleScriptFunctionSymbol.Kind identifies:
UserImportedHostBuiltin
RuleScriptFunctionSymbol can expose parameters, return type, declared return type, documentation, source location, import metadata, host metadata, built-in metadata, and Host Trigger metadata.
These APIs remain available for compatibility, but new integrations should prefer Functions and RuleScriptFunctionSymbol:
UserFunctionsHostFunctionsBuiltinFunctionsUserFunctionNamesHostFunctionNamesBuiltinFunctionNamesFunctionNamesRuleScriptHostFunctionSymbolRuleScriptBuiltinFunctionSymbol
RuleScriptHostFunctionSymbol and RuleScriptBuiltinFunctionSymbol are compatibility adapters around the unified symbol model.
var symbols = engine.Analyze(script, line, column);
var suggestions = symbols.VisibleVariables;Inside a function, visible variables include globals, that function's parameters, and its locals without exposing locals from other functions. TryAnalyze(script, line, column) provides best-effort completion for incomplete editor input.
Functions marked with @HostTrigger appear in RuleScriptAnalysisResult.HostTriggers:
foreach (var trigger in symbols.HostTriggers)
{
Console.WriteLine(trigger.HostTriggerMetadata?.Name);
Console.WriteLine(trigger.Signature);
}This lets a host discover trigger names and typed signatures before starting a runtime.