NAME
std/eval - Evaluate Zuzu code in a nested caller scope.
SYNOPSIS
from std/eval import eval;
let x := 2;
let y := eval("x + 40;");
IMPLEMENTATION SUPPORT
This module is supported by all implementations of ZuzuScript.
DESCRIPTION
This module exports eval(str), which parses and runs str as Zuzu code using the current runtime configuration. The evaluated code runs in a fresh nested scope whose parent is the caller's scope. It can read and update mutable symbols that already exist in the caller, but new declarations, functions, classes, and imports created by eval are local to the eval call and are not automatically visible to the caller.
Optional named arguments can further reduce capabilities for the evaluated code:
eval("from std/io import Path;", deny_fs: true);
Supported denials are deny_fs, deny_net, deny_perl, deny_js, deny_proc, deny_db, deny_clib, deny_gui, and deny_worker. Existing runtime denials are always inherited; named denials only add to them. Passing a false denial value does not relax a denial from the runtime or an outer eval call.
Syntax and runtime errors thrown while evaluating code are catchable as normal Zuzu exceptions. Compile exceptions expose eval source metadata, including message, file, line, and code.
EXPORTS
Functions
eval(String source, ... PairList denials)Parameters:
sourceis ZuzuScript source text anddenialsare optional named capability-denial flags. Returns: value. Parses and evaluatessourcein a nested caller scope.
COPYRIGHT AND LICENCE
std/eval is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.