Skip to content

Built in Functions

Mick edited this page Jul 7, 2026 · 3 revisions

Built-in Function Reference

Function names are case-sensitive. Wrong argument counts, invalid conversions, invalid paths, and out-of-range indexes throw RuntimeException.

Built-ins participate in the same overload resolution model as user and host functions. New integrations should read built-in metadata through RuleScriptAnalysisResult.Functions and RuleScriptFunctionSymbol where Kind == RuleScriptFunctionKind.Builtin.

General and Type Helpers

Function Return Description
Print(value) any Returns value and reports a host-observable Print runtime event.
ToString(value) string Converts a value to invariant text; null becomes an empty string.
TypeOf(value) string Returns null, string, bool, number, array, or object.
IsNull(value) bool Returns whether the value is null.
Coalesce(value, fallback) any Returns value unless it is null; otherwise returns fallback.

Conversion

Function Return Description
ParseInt(value) number Parses a string or whole numeric value as an integer number.
ParseDecimal(value) number Parses a string or numeric value as a decimal number.
ParseBool(value) bool Parses a bool or string value as a boolean.

Strings

Function Return Description
Trim(value) string Converts to text and trims whitespace.
ToUpper(value) string Converts to uppercase invariant text.
ToLower(value) string Converts to lowercase invariant text.
StartsWith(value, prefix) bool Tests with ordinal comparison.
EndsWith(value, suffix) bool Tests with ordinal comparison.
Contains(value, searchValue) bool Tests with ordinal comparison.
Split(value, separator) array Splits text into an array.
Join(separator, values) string Joins array values into text.
Replace(value, oldValue, newValue) string Replaces ordinal text matches.
Substring(value, start, length) string Extracts a zero-based range.
Length(value) number Returns array count or text length.

Arrays

Array helpers mutate the supplied array when applicable.

Function Return Description
ArrayAdd(array, value) array Appends a value and returns the same array.
ArrayInsert(array, index, value) array Inserts a value at a zero-based index.
ArrayRemove(array, value) bool Removes the first matching value and returns whether one was removed.
ArrayRemoveAt(array, index) any Removes and returns the indexed value.
ArraySort(array) array Sorts an all-string or all-number array ascending.
ArrayContains(array, value) bool Tests whether the array contains a matching value.
ArrayClear(array) array Removes all items and returns the same array.
var values = [3, 1, 2];
ArrayAdd(values, 4);
ArraySort(values);
var hasTwo = ArrayContains(values, 2);

Objects

Function Return Description
ObjectKeys(object) array Returns property names in ordinal sort order.
ObjectContainsKey(object, key) bool Tests whether a string key exists.
var robot = { status: "OK", distance: 519 };
var keys = ObjectKeys(robot);
var hasStatus = ObjectContainsKey(robot, "status");

Mathematics

Function Return Description
Abs(value) number Returns the absolute value.
Min(left, right) number Returns the smaller number.
Max(left, right) number Returns the larger number.
Clamp(value, min, max) number Restricts a number to an inclusive range.
Round(value) number Rounds to the nearest whole number.
Floor(value) number Rounds down.
Ceiling(value) number Rounds up.

JSON

Function Return Description
JsonParse(json) object Parses JSON text into RuleScript objects, arrays, and primitive values.
JsonStringify(value) string Serializes a supported value to JSON text.
JsonGet(value, path) any Reads a dot-separated path, including array indexes such as items.0.name.
JsonSet(value, path, newValue) any Sets an existing path and returns the updated root.
JsonExists(value, path) bool Tests whether a path exists.
var payload = JsonParse("{ \"items\": [{ \"name\": \"A\" }] }");
var name = JsonGet(payload, "items.0.name");
JsonSet(payload, "items.0.name", "B");
var json = JsonStringify(payload);

JsonSet mutates dictionaries and lists in place.

Clone this wiki locally