Skip to main content

function.acall(arguments)

Calls the target function and passes array values into its parameters

Availability

Device + Agent

Parameters

Name Type Description
arguments Array The function’s parameters in array form

Returns

Nothing

Description

This method provides a way of passing an array of values to a function in place of separate parameters.

Where a function might, for instance, take three parameters:

doSomething(value1, value2, value3);

and be called with appropriate values:

doSomething(42, "fish", "biro");

the acall() method passes these parameters as a single array:

local array = [this, 42, "fish", "biro"];
doSomething.acall(array);

The array passed to acall() must include sufficient elements to cover all of the function’s mandatory parameters, ie. those without default values.

In agent code, you can pass no more than ten array elements or an error will be thrown. This limit will be added to device code in impOS™ 40.

Like call(), acall() can also pass an alternative context object to the function, effectively exposing the usually hidden first parameter, this. In this instance, the new context object must be placed at the head of the array’s elements, ie. at index zero. Most of the time, the caller’s own context object should be passed, in which case the array should start with this, as seen in the example above.

For a version of this call which sidesteps Squirrel’s error callback, see pacall.

Further Information

For more detailed guidance on the role of context objects in Squirrel, please see Squirrel Closures And Context Objects.