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.
 
 
 
 
 
 

38 lines
1.1 KiB

=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
<p>Like <code><a href="#duk_compile">duk_compile()</a></code> 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.</p>
=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