You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
1.1 KiB

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: |
<p>Like <code><a href="#duk_pcall">duk_pcall()</a></code>, but the target function
<code>func</code> is called with an explicit <code>this</code> binding given on the value
stack.</p>
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