diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a039165..812cb2ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/examples/event_handler_map/main.rs b/examples/event_handler_map/main.rs index 7227fcc7..24f9df2a 100644 --- a/examples/event_handler_map/main.rs +++ b/examples/event_handler_map/main.rs @@ -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(); diff --git a/src/bin/rhai-run.rs b/src/bin/rhai-run.rs index 257a7b08..b6e4e6fa 100644 --- a/src/bin/rhai-run.rs +++ b/src/bin/rhai-run.rs @@ -47,6 +47,7 @@ fn main() { }, }; + // Initialize scripting engine let mut engine = Engine::new(); #[cfg(not(feature = "no_optimize"))]