Quirrel4.41.0

types.Function.acall

Method on every function
function.acall(args: array): any

Calls the closure with the arguments taken from an array: args[0] becomes this, and the rest of args becomes the closure's own parameters.

The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing ... from the prose below, not from the signature.

Parameters

argsarrayan array; its first element is this, the rest are the arguments

Return value

Whatever the call returns.

Errors

Throws parameter 1 of 'acall' has an invalid type when args is not an array. Whatever the call itself throws is otherwise propagated unchanged.

Notes

Unlike call, acall takes exactly one explicit argument - the array - so f.acall(a, b) fails with a parameter-count error. Use it when the argument list is already an array, for example one built in a loop.

Example

examples/types/function/acall.nut
function greet(prefix) { return $"{prefix} {this.name}" }
println("greet.acall([{name = \"Bob\"}, \"Hi\"]) =", greet.acall([{name = "Bob"}, "Hi"]))

// acall takes exactly one array argument - it is not itself variadic
try { greet.acall([{name = "Bob"}, "Hi"], "extra") } catch(e) { println("greet.acall(..., \"extra\") throws:", e) }
try { greet.acall(1) } catch(e) { println("greet.acall(1) throws:", e) }
Output:
greet.acall([{name = "Bob"}, "Hi"]) = Hi Bob
greet.acall(..., "extra") throws: wrong number of parameters passed to native closure 'acall' (3 passed, 2 required)
greet.acall(1) throws: parameter 1 of 'acall' has an invalid type 'integer' ; expected: 'array'

See also

callCalls the closure, using env as its this and forwarding the rest of the arguments as its own parameters.
pacallCalls the closure like acall does, taking this and the arguments from an array: args[0] becomes this, and the rest of args becomes the closure's own parameters.
functionclass index