=proto
duk_int_t duk_pcompile(duk_context *ctx, duk_uint_t flags);
=stack
[ ... source! filename! ] -> [ ... function! ] (if success, return value == 0)
[ ... source! filename! ] -> [ ... err! ] (if failure, return value != 0)
=summary
Like duk_compile()
but catches errors
related to compilation (such as syntax errors in the source). A zero return
value indicates success and the compiled function is left on the stack top.
A non-zero return value indicates an error, and the error is left on the stack top.
=example
duk_push_string(ctx, "print('program'); syntax error here=");
duk_push_string(ctx, "hello-with-syntax-error");
if (duk_pcompile(ctx, 0) != 0) {
printf("compile failed: %s\n", duk_safe_to_string(ctx, -1));
} else {
duk_call(ctx, 0); /* [ func ] -> [ result ] */
printf("program result: %s\n", duk_safe_to_string(ctx, -1));
}
duk_pop(ctx);
=tags
compile
protected
=seealso
duk_compile
duk_pcompile_string
duk_pcompile_string_filename
duk_pcompile_lstring
duk_pcompile_lstring_filename
duk_pcompile_file
=introduced
1.0.0