Quirrel4.41.0

types.Class.pacall

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

Same as acall, except a failure does not invoke the VM's registered error callback.

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.
examples/types/class/pacall-basic.nut
class Rect { w = 0 constructor(w) { this.w = w } }
let r = Rect.pacall([null, 9])
println("r.w =", r.w)
Output:
r.w = 9

Parameters

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

Return value

The new instance.

Errors

Throws a parameter type error if args is not an array. Takes exactly one argument beyond the receiver. A constructor failure still raises a normal, catchable script error - "protected" here only means the host's error hook is skipped, not that the error is swallowed; see Notes.

Notes

The p in pcall/pacall stands for "protected call", but in Quirrel that protection is aimed at the host embedding the VM, not at the calling script: a failed pacall still throws, and an uncaught throw still stops the script. Wrap the call in try/catch if the script itself needs to recover.

Example

examples/types/class/pacall.nut
class Bad {
  constructor() { throw "boom" }
}
try {
  Bad.pacall([null])
} catch (e) {
  println("Bad.pacall([null]) throws:", e)
}
Output:
Bad.pacall([null]) throws: boom

See also

acallCreates 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.
pcallSame as call, except a failure does not invoke the VM's registered error callback.
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.
classclass index