Function helpers - Manhunter07/MFL GitHub Wiki
Function helpers are special pre-defined objects that are only available when declaring a function, including special function types like constructors and destructors.
function Self: function = \built-in\
If the function is a constructor or a converter, Self
returns a reference to the type. Otherwise, it returns a reference to the function.
const VarArg = \built-in\
Equals True
if the current function is variadic, otherwise False
.
const IsConstructor = \built-in\
Equals True
if the current function is a constructor for a type, otherwise False
.
const IsConverter = \built-in\
Equals True
if the current function is a converter for a type, otherwise False
.
const Params: array = \built-in\
Equals an array value of records consisting of the following fields:
-
Name
: Parameter identifier -
VarArg
: Vararg flag -
T
: Parameter type -
Default
: Fallback value
function Args: record = \built-in\
Returns a record with a field for each call argument. The field identifiers are the parameter name whereas the field values are their values. Any defined or fallback argument are listed, including all vararg parameters.
function Caller: function = \built-in\
Returns a reference to the function that called this function, if available. If the function would be called from the bare program or package, Caller
returns Nil
.
This way we can return the name of a function without explicitely mentioning it in the code (using System.NameOf
):
function MyName = NameOf(Self) \returns "MyName"\
For var-arg functions we can determine the amount of arguments passed (using System.Length
):
function GetCount(Arg &&) = Length(Args)