Maximum Number of Variables
Rhai by default does not limit how many variables/constants can be defined within a single Scope
.
This can be changed via the Engine::set_max_variables
method. Notice that setting the
maximum number of variables to zero does not indicate unlimited variables, but disallows
defining any variable altogether.
A script attempting to define more than the maximum number of variables/constants will terminate with an error result.
This check can be disabled via the unchecked
feature for higher performance (but higher risks as well).
let mut engine = Engine::new();
engine.set_max_variables(5); // allow defining only up to 5 variables
engine.set_max_variables(0); // disallow defining any variable (maximum = zero)
engine.set_max_variables(1000); // set to a large number for effectively unlimited variables
It is possible to reuse a variable such that it is counted only once.
let x = 42; // counted as 1 variable
let y = 123;
let x = 0; // previous 'x' reused: not counted as new variable