name: duk_pcall proto: | duk_int_t duk_pcall(duk_context *ctx, duk_idx_t nargs); stack: | [ ... func! arg1! ...! argN! ] -> [ ... retval! ] (if success, return value == 0) [ ... func! arg1! ...! argN! ] -> [ ... err! ] (if failure, return value != 0) summary: |
Call target function func
with nargs
arguments
(not counting the function itself). The function and its arguments
are replaced by a single return value or a single error value.
An error thrown during the function call is caught.
The return value is:
DUK_EXEC_SUCCESS
(0): call succeeded, nargs
arguments are replaced
with a single return value. (This return code constant is guaranteed to be zero, so
that one can check for success with a "zero or non-zero" check.)DUK_EXEC_ERROR
: call failed, nargs
arguments are replaced with a
single error value. (In exceptional cases, e.g. when there are too few
arguments on the value stack, the call returns non-zero but may leave the stack
in an inconsistent state.)Error objects caught are typically instances of Error and have useful
properties like .stack
, .fileName
, and
.lineNumber
. These can be accessed using the normal property
methods. However, arbitrary values can be thrown so you should avoid
assuming that's always the case.
The target function this
binding is initially set to
undefined
. If the target function is not strict, the binding
is replaced by the global object before the function is invoked; see
Entering Function Code.
If you want to control the this
binding, you can use
duk_pcall_method()
or
duk_pcall_prop()
instead.