types.Function.pacall
Calls 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.
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
args | array | an array; its first element is this, the rest are the arguments |
Return value
Whatever the call returns.
Errors
Throws parameter 1 of 'pacall' has an invalid type when args is not an array. Whatever the call itself throws is otherwise propagated unchanged.
Notes
pacall is to acall what pcall is to call: the calling convention is identical, but an unhandled error raised inside the call does not show this frame to a host-installed runtime error reporter (see the Notes on pcall for what that does and does not change).
Example
function greet(prefix) { return $"{prefix} {this.name}" }
println("greet.pacall([{name = \"Bob\"}, \"Hi\"]) =", greet.pacall([{name = "Bob"}, "Hi"]))
function thrower() { throw "boom" }
try { thrower.pacall([{}]) } catch(e) { println("caught:", e) }Output:
greet.pacall([{name = "Bob"}, "Hi"]) = Hi Bob
caught: boomSee also
acall | 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. |
pcall | Calls the closure like call does, using env as its this and forwarding the rest of the arguments as its own parameters. |
| function | class index |