Quirrel4.41.0

types.Class.acall

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

Creates a new instance of the class, passing it the constructor arguments packed into an array. Equivalent to call, only with the arguments collected into one array instead of listed one by one.

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

argsarrayarray of constructor arguments; args[0] must be present but its value is ignored

Return value

The new instance.

Errors

Throws a parameter type error if args is not an array. Takes exactly one argument beyond the receiver, so calling it with zero or two throws wrong number of parameters passed to native closure 'acall' (N passed, 2 required). Whatever the constructor itself throws propagates uncaught, same as calling ClassName(...) directly.

Notes

function.acall(array_args) documents array_args[0] as the required this object. Class.acall shares that array shape for consistency with Function.acall, but a class ignores whatever sits at args[0]: constructing an instance always supplies the new instance itself as this, so args[0] is only a placeholder and args[1] is the constructor's first real argument. Use null there for clarity. call has the same leading placeholder argument; see its Notes for the non-array form.

Example

examples/types/class/acall.nut
class Rect {
  w = 0
  h = 0
  constructor(w, h) { this.w = w; this.h = h }
}
// args[0] is a required placeholder; the class supplies its own instance as "this"
let r = Rect.acall([null, 3, 4])
println("r.w =", r.w, "r.h =", r.h)
Output:
r.w = 3 r.h = 4

See also

callCreates a new instance of the class and runs its constructor, the same as writing ClassName(...). Exists so a class value obtained indirectly (through a variable, a table slot, or getclass()) can still be instantiated through a uniform .call(...) spelling shared with functions.
pacallSame as acall, except a failure does not invoke the VM's registered error callback.
instanceCreates a new instance of the class without running its constructor.
acallCalls the closure with the arguments taken from an array: args[0] becomes this, and the rest of args becomes the closure's own parameters.
classclass index