name: duk_pcall_method proto: | duk_int_t duk_pcall_method(duk_context *ctx, duk_idx_t nargs); stack: | [ ... func! this! arg! ...! argN! ] -> [ ... retval! ] (if success, return value == 0) [ ... func! this! arg! ...! argN! ] -> [ ... err! ] (if failure, return value != 0) summary: |

Like duk_pcall(), but the target function func is called with an explicit this binding given on the value stack.

example: | /* The target function here prints: * * this: 123 * 2 3 * * and returns 5. */ duk_int_t rc; duk_push_string(ctx, "(function(x,y) { print('this:', this); " "print(x,y); return x+y; })"); duk_eval(ctx); /* -> [ ... func ] */ duk_push_int(ctx, 123); duk_push_int(ctx, 2); duk_push_int(ctx, 3); rc = duk_pcall_method(ctx, 2); /* [ ... func 123 2 3 ] -> [ 5 ] */ if (rc == DUK_EXEC_SUCCESS) { printf("2+3=%ld\n", (long) duk_get_int(ctx, -1)); /* prints 5 */ } else { printf("error: %s\n", duk_to_string(ctx, -1)); } duk_pop(ctx); tags: - call - protected introduced: 1.0.0