Func Object

class Func extends Object

Represents a user-defined or built-in function.

For information about other objects which can be called like functions, see Function Objects.

The Closure class extends Func but does not define any new properties.

For each built-in function or function definition within the script, there is a corresponding read-only variable containing a Func object. This variable is directly used to call the function, but its value can also be read to retrieve the function itself, as a value. For example:

InspectFn StrLen
InspectFn InspectFn

InspectFn(fn)
{
    ; Display information about the passed function.
    MsgBox fn.Name "() is " (fn.IsBuiltIn ? "built-in." : "user-defined.")
}

"FuncObj" is used below as a placeholder for any Func object, as "Func" is the class itself.

In addition to the methods and property inherited from Object, Func objects have the following predefined methods and properties.

Table of Contents

Methods

Call

Calls the function.

FuncObj(Param1, Param2, ...)
FuncObj.Call(Param1, Param2, ...)
Param1, Param2, ...
Parameters and return value are defined by the function.

The "Call" method is implied when calling a value, so need not be explicitly specified.

Bind

Binds parameters to the function and returns a BoundFunc object.

BoundFunc := FuncObj.Bind(Param1, Param2, ...)
Param1, Param2, ...
Any number of parameters.

For details and examples, see BoundFunc object.

IsByRef

Determines whether a parameter is ByRef.

Boolean := FuncObj.IsByRef(ParamIndex)
ParamIndex

Type: Integer

Optional: the one-based index of a parameter. If omitted, Boolean indicates whether the function has any ByRef parameters.

Returns a boolean value indicating whether the parameter is ByRef. If ParamIndex is invalid, an exception is thrown.

IsOptional

Determines whether a parameter is optional.

Boolean := FuncObj.IsOptional(ParamIndex)
ParamIndex

Type: Integer

Optional: the one-based index of a parameter. If omitted, Boolean indicates whether the function has any optional parameters.

Returns a boolean value indicating whether the parameter is optional. If ParamIndex is invalid, an exception is thrown.

Parameters do not need to be formally declared if the function is variadic. Built-in functions are supported.

Properties

Name

Returns the function's name.

FunctionName := FuncObj.Name

IsBuiltIn

Returns true if the function is built-in and false otherwise.

Boolean := FuncObj.IsBuiltIn

IsVariadic

Returns true if the function is variadic and false otherwise.

Boolean := FuncObj.IsVariadic

MinParams

Returns the number of required parameters.

ParamCount := FuncObj.MinParams

MaxParams

Returns the number of formally-declared parameters for a user-defined function or maximum parameters for a built-in function.

ParamCount := FuncObj.MaxParams

If the function is variadic, ParamCount indicates the maximum number of parameters which can be accepted by the function without overflowing into the "variadic*" parameter.