=proto void duk_eval(duk_context *ctx); =stack [ ... source! ] -> [ ... result! ] =summary

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 __FILE__ preprocessor define of the caller.

This is essentially a shortcut for:

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);

If the eval input is a fixed string, you can also use duk_eval_string().

=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