Add custom state.
This commit is contained in:
@@ -55,7 +55,7 @@ fn test_debugger_state() -> Result<(), Box<EvalAltResult>> {
|
||||
state.insert("foo".into(), false.into());
|
||||
Dynamic::from_map(state)
|
||||
},
|
||||
|context, _, _, _, _| {
|
||||
|mut context, _, _, _, _| {
|
||||
// Get global runtime state
|
||||
let global = context.global_runtime_state_mut();
|
||||
|
||||
|
@@ -202,9 +202,15 @@ fn test_var_def_filter() -> Result<(), Box<EvalAltResult>> {
|
||||
let ast = engine.compile("let x = 42;")?;
|
||||
engine.run_ast(&ast)?;
|
||||
|
||||
engine.on_def_var(|_, info, _| match (info.name, info.nesting_level) {
|
||||
("x", 0 | 1) => Ok(false),
|
||||
_ => Ok(true),
|
||||
engine.on_def_var(|_, info, mut ctx| {
|
||||
if ctx.tag().is::<()>() {
|
||||
*ctx.tag_mut() = rhai::Dynamic::ONE;
|
||||
}
|
||||
println!("Tag = {}", ctx.tag());
|
||||
match (info.name, info.nesting_level) {
|
||||
("x", 0 | 1) => Ok(false),
|
||||
_ => Ok(true),
|
||||
}
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
|
Reference in New Issue
Block a user