mirror of https://github.com/svaarala/duktape.git
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.
42 lines
1.1 KiB
42 lines
1.1 KiB
name: duk_pnew
|
|
|
|
proto: |
|
|
duk_ret_t duk_pnew(duk_context *ctx, duk_idx_t nargs);
|
|
|
|
stack: |
|
|
[ ... constructor! arg1! ...! argN! ] -> [ ... retval! ] (if success, return value == 0)
|
|
[ ... constructor! arg1! ...! argN! ] -> [ ... err! ] (if failure, return value != 0)
|
|
|
|
summary: |
|
|
<p>Like <code><a href="#duk_new">duk_new()</a></code> but catches errors.
|
|
A zero return value indicates success and the constructor result is left on
|
|
the stack top. A non-zero return value indicates an error, and the error
|
|
is left on the stack top.</p>
|
|
|
|
<p>If value stack top is too low (smaller than nargs + 1), or <code>nargs</code>
|
|
is negative, an error is thrown.</p>
|
|
|
|
example: |
|
|
duk_ret_t rc;
|
|
|
|
/* Protected call to: new MyConstructor("foo", 123) */
|
|
duk_eval_string(ctx, "MyConstructor");
|
|
duk_push_string(ctx, "foo");
|
|
duk_push_int(ctx, 123);
|
|
rc = duk_pnew(ctx, 2); /* [ ... func "foo" 123 ] -> [ ... res ] */
|
|
if (rc != 0) {
|
|
printf("failed: %s\n", duk_safe_to_string(ctx, -1));
|
|
} else {
|
|
printf("success\n");
|
|
}
|
|
duk_pop(ctx);
|
|
|
|
tags:
|
|
- object
|
|
- call
|
|
- protected
|
|
|
|
seealso:
|
|
- duk_new
|
|
|
|
introduced: 1.3.0
|
|
|