Forbid shadowing of state variable.

This commit is contained in:
Stephen Chung 2022-02-27 22:47:13 +08:00
parent b17e891b63
commit 15448bf660
3 changed files with 7 additions and 1 deletions

View File

@ -26,6 +26,7 @@ Enhancements
* Variable definitions are optimized so that shadowed variables are reused as much as possible to reduce memory consumption.
* `FnAccess` and `FnNamespace` now implement `Ord` and `PartialOrd`.
* The `event_handler_map` example is enhanced to prevent shadowing of the state object map.
Version 1.5.0

View File

@ -56,7 +56,11 @@ pub fn main() {
};
// Create Engine
let engine = Engine::new();
let mut engine = Engine::new();
// Prevent shadowing of `state`
#[allow(deprecated)]
engine.on_def_var(|_, info, _| Ok(info.name != "state"));
// Create a custom 'Scope' to hold state
let mut scope = Scope::new();

View File

@ -47,6 +47,7 @@ fn main() {
},
};
// Initialize scripting engine
let mut engine = Engine::new();
#[cfg(not(feature = "no_optimize"))]