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.

Helpers

Self

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.

VarArg

const VarArg = \built-in\

Equals True if the current function is variadic, otherwise False.

IsConstructor

const IsConstructor = \built-in\

Equals True if the current function is a constructor for a type, otherwise False.

IsConverter

const IsConverter = \built-in\

Equals True if the current function is a converter for a type, otherwise False.

Params

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

Args

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.

Caller

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.

Examples

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)