rhai/examples/reuse_scope.rs

15 lines
337 B
Rust
Raw Normal View History

2020-03-09 09:54:43 +01:00
use rhai::{Engine, EvalAltResult, Scope};
2016-03-04 14:45:43 +01:00
2020-03-09 09:54:43 +01:00
fn main() -> Result<(), EvalAltResult> {
2016-03-04 14:45:43 +01:00
let mut engine = Engine::new();
2019-09-18 12:21:07 +02:00
let mut scope = Scope::new();
2016-03-04 14:45:43 +01:00
2020-03-09 09:54:43 +01:00
engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5")?;
2016-03-04 14:45:43 +01:00
2020-03-09 09:54:43 +01:00
let result = engine.eval_with_scope::<i64>(&mut scope, "x")?;
println!("result: {}", result);
Ok(())
2016-03-04 14:45:43 +01:00
}