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.
 
 
 
 
 
 

45 lines
1.1 KiB

=proto
void duk_eval(duk_context *ctx);
=stack
[ ... source! ] -> [ ... result! ]
=summary
<p>Evaluate the Ecmascript source code at the top of the stack, and leave a single
return value on top of the stack. May throw an error, errors are not caught
automatically. The filename associated with the temporary eval function is
automatically provided from the <code>__FILE__</code> preprocessor define
of the caller.</p>
<p>This is essentially a shortcut for:</p>
<pre class="c-code">
int flags = DUK_COMPILE_EVAL;
if (duk_is_strict_call(ctx)) {
flags |= DUK_COMPILE_STRICT;
}
duk_push_string(ctx, __FILE__);
duk_compile(ctx, flags);
duk_call(ctx, 0);
</pre>
<p>If the eval input is a fixed string, you can also use
<code><a href="#duk_eval_string">duk_eval_string()</a></code>.</p>
=example
/* Eval result in Ecmascript is the last non-empty statement; here, the
* result of the eval is the number 123.
*/
duk_push_string(ctx, "print('Hello world!'); 123;");
duk_eval(ctx);
printf("return value is: %lf\n", duk_get_number(ctx, -1));
duk_pop(ctx);
=tags
compile
=seealso
duk_peval
duk_eval_string
duk_eval_file
duk_eval_noresult