Browse Source

update protected/safe api calls to omit errhandler_index

pull/2/head
Sami Vaarala 11 years ago
parent
commit
f2ca1e8450
  1. 13
      website/api/duk_pcall.txt
  2. 4
      website/api/duk_pcall_method.txt
  3. 4
      website/api/duk_pcall_prop.txt
  4. 12
      website/api/duk_safe_call.txt

13
website/api/duk_pcall.txt

@ -1,5 +1,5 @@
=proto =proto
int duk_pcall(duk_context *ctx, int nargs, int errhandler_index); int duk_pcall(duk_context *ctx, int nargs);
=stack =stack
[ ... func! arg1! ...! argN! ] -> [ ... retval! ] (if success, return value == 0) [ ... func! arg1! ...! argN! ] -> [ ... retval! ] (if success, return value == 0)
@ -9,11 +9,7 @@ int duk_pcall(duk_context *ctx, int nargs, int errhandler_index);
<p>Call target function <code>func</code> with <code>nargs</code> arguments <p>Call target function <code>func</code> with <code>nargs</code> arguments
(not counting the function itself). The function and its arguments (not counting the function itself). The function and its arguments
are replaced by a single return value or a single error value. are replaced by a single return value or a single error value.
An error thrown during the function call is caught. <code>errhandler_index</code> points An error thrown during the function call is caught.</p>
to an error handler function in the current stack frame (below call arguments) which
can modify an error value before it is thrown; to use the default error handler,
set <code>errhandler_index</code> to <code>DUK_INVALID_INDEX</code>.</p>
</p>
<p>The return value is:</p> <p>The return value is:</p>
<ul> <ul>
@ -50,7 +46,7 @@ int rc;
duk_dup(ctx, func_idx); duk_dup(ctx, func_idx);
duk_push_int(ctx, 2); duk_push_int(ctx, 2);
duk_push_int(ctx, 3); duk_push_int(ctx, 3);
rc = duk_pcall(ctx, 2, DUK_INVALID_INDEX); /* [ ... func 2 3 ] -> [ 5 ] */ rc = duk_pcall(ctx, 2); /* [ ... func 2 3 ] -> [ 5 ] */
if (rc == DUK_EXEC_SUCCESS) { if (rc == DUK_EXEC_SUCCESS) {
printf("2+3=%d\n", duk_get_int(ctx, -1)); printf("2+3=%d\n", duk_get_int(ctx, -1));
} else { } else {
@ -64,6 +60,3 @@ call
=seealso =seealso
duk_pcall_method duk_pcall_method
duk_pcall_prop duk_pcall_prop
=fixme
Error handler model to be cleaned up.

4
website/api/duk_pcall_method.txt

@ -1,5 +1,5 @@
=proto =proto
int duk_pcall_method(duk_context *ctx, int nargs, int errhandler_index); int duk_pcall_method(duk_context *ctx, int nargs);
=stack =stack
[ ... func! this! arg! ...! argN! ] -> [ ... retval! ] (if success, return value == 0) [ ... func! this! arg! ...! argN! ] -> [ ... retval! ] (if success, return value == 0)
@ -27,7 +27,7 @@ duk_eval(ctx); /* -> [ ... func ] */
duk_push_int(ctx, 123); duk_push_int(ctx, 123);
duk_push_int(ctx, 2); duk_push_int(ctx, 2);
duk_push_int(ctx, 3); duk_push_int(ctx, 3);
rc = duk_pcall_method(ctx, 2, DUK_INVALID_INDEX); /* [ ... func 123 2 3 ] -> [ 5 ] */ rc = duk_pcall_method(ctx, 2); /* [ ... func 123 2 3 ] -> [ 5 ] */
if (rc == DUK_EXEC_SUCCESS) { if (rc == DUK_EXEC_SUCCESS) {
printf("2+3=%d\n", duk_get_int(ctx, -1)); /* prints 5 */ printf("2+3=%d\n", duk_get_int(ctx, -1)); /* prints 5 */
} else { } else {

4
website/api/duk_pcall_prop.txt

@ -1,5 +1,5 @@
=proto =proto
int duk_pcall_prop(duk_context *ctx, int obj_index, int nargs, int errhandler_index); int duk_pcall_prop(duk_context *ctx, int obj_index, int nargs);
=stack =stack
[ ... obj! ... key! arg1! ...! argN! ] -> [ ... obj! ... retval! ] (if success, return value == 0) [ ... obj! ... key! arg1! ...! argN! ] -> [ ... obj! ... retval! ] (if success, return value == 0)
@ -18,7 +18,7 @@ int rc;
duk_push_string(ctx, "myAdderMethod"); duk_push_string(ctx, "myAdderMethod");
duk_push_int(ctx, 2); duk_push_int(ctx, 2);
duk_push_int(ctx, 3); duk_push_int(ctx, 3);
rc = duk_pcall_prop(ctx, obj_idx, 2, DUK_INVALID_INDEX); /* [ ... "myAdderMethod" 2 3 ] -> [ ... 5 ] */ rc = duk_pcall_prop(ctx, obj_idx, 2); /* [ ... "myAdderMethod" 2 3 ] -> [ ... 5 ] */
if (rc == DUK_EXEC_SUCCESS) { if (rc == DUK_EXEC_SUCCESS) {
printf("2+3=%d\n", duk_get_int(ctx, -1)); printf("2+3=%d\n", duk_get_int(ctx, -1));
} else { } else {

12
website/api/duk_safe_call.txt

@ -1,5 +1,5 @@
=proto =proto
int duk_safe_call(duk_context *ctx, duk_safe_call_function func, int nargs, int nrets, int errhandler_index); int duk_safe_call(duk_context *ctx, duk_safe_call_function func, int nargs, int nrets);
=stack =stack
[ ... arg1! ...! argN! ] -> [ ... ret1! ...! retN! ] [ ... arg1! ...! argN! ] -> [ ... ret1! ...! retN! ]
@ -8,10 +8,7 @@ int duk_safe_call(duk_context *ctx, duk_safe_call_function func, int nargs, int
<p>Perform a protected pure C function call inside the current value stack frame <p>Perform a protected pure C function call inside the current value stack frame
(the call is not visible on the call stack). <code>nargs</code> topmost values in the (the call is not visible on the call stack). <code>nargs</code> topmost values in the
current value stack frame are identified as call arguments, and <code>nrets</code> current value stack frame are identified as call arguments, and <code>nrets</code>
return values are provided after the call returns. <code>errhandler_index</code> points return values are provided after the call returns.</p>
to an error handler function in the current stack frame (below call arguments) which
can modify an error value before it is thrown; to use the default error handler,
set <code>errhandler_index</code> to <code>DUK_INVALID_INDEX</code>.</p>
<p>The return value is:</p> <p>The return value is:</p>
<ul> <ul>
@ -98,7 +95,7 @@ int my_func(duk_context *ctx) {
duk_push_int(ctx, 10); duk_push_int(ctx, 10);
duk_push_int(ctx, 11); duk_push_int(ctx, 11);
duk_push_int(ctx, 12); duk_push_int(ctx, 12);
rc = duk_safe_call(ctx, my_func, 3 /*nargs*/, 2 /*nrets*/, DUK_INVALID_INDEX); rc = duk_safe_call(ctx, my_func, 3 /*nargs*/, 2 /*nrets*/);
if (rc == DUK_EXEC_SUCCESS) { if (rc == DUK_EXEC_SUCCESS) {
printf("1st return value: %s\n", duk_to_string(ctx, -2)); /* 21 */ printf("1st return value: %s\n", duk_to_string(ctx, -2)); /* 21 */
printf("2nd return value: %s\n", duk_to_string(ctx, -1)); /* undefined */ printf("2nd return value: %s\n", duk_to_string(ctx, -1)); /* undefined */
@ -109,6 +106,3 @@ duk_pop_2(ctx);
=tags =tags
call call
=fixme
Error handler model to be cleaned up.

Loading…
Cancel
Save