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.
 
 
 
 
 
 

39 lines
1010 B

=proto
int duk_pcall_method(duk_context *ctx, int 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.
*/
int 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=%d\n", duk_get_int(ctx, -1)); /* prints 5 */
} else {
printf("error: %s\n", duk_to_string(ctx, -1));
}
duk_pop(ctx);
=tags
call