name: duk_call proto: | void duk_call(duk_context *ctx, duk_idx_t nargs); stack: | [ ... func! arg1! ...! argN! ] -> [ ... retval! ] 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. An error thrown during the function call is not automatically caught.

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_call_method() or duk_call_prop() instead.

This API call is equivalent to:

  var retval = func(arg1, ..., argN);
  

or:

  var retval = func.call(undefined, arg1, ..., argN);
  
example: | /* Assume target function is already on stack at func_idx; the target * function adds arguments and returns the result. */ duk_idx_t func_idx = /* ... */; duk_dup(ctx, func_idx); duk_push_int(ctx, 2); duk_push_int(ctx, 3); duk_call(ctx, 2); /* [ ... func 2 3 ] -> [ 5 ] */ printf("2+3=%ld\n", (long) duk_get_int(ctx, -1)); duk_pop(ctx); tags: - call seealso: - duk_call_method - duk_call_prop introduced: 1.0.0