Use run and i64 instead of eval and INT for examples.

This commit is contained in:
Stephen Chung
2022-01-11 22:12:46 +08:00
parent 6048c5804b
commit f0e9d4a557
7 changed files with 25 additions and 25 deletions

View File

@@ -1,20 +1,20 @@
use rhai::{Engine, EvalAltResult, Scope, INT};
use rhai::{Engine, EvalAltResult, Scope};
fn main() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
let mut scope = Scope::new();
engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5")?;
engine.run_with_scope(&mut scope, "let x = 4 + 5")?;
println!("x = {}", scope.get_value::<INT>("x").unwrap());
println!("x = {}", scope.get_value::<i64>("x").unwrap());
for _ in 0..10 {
let result = engine.eval_with_scope::<INT>(&mut scope, "x += 1; x")?;
let result = engine.eval_with_scope::<i64>(&mut scope, "x += 1; x")?;
println!("result: {}", result);
}
println!("x = {}", scope.get_value::<INT>("x").unwrap());
println!("x = {}", scope.get_value::<i64>("x").unwrap());
Ok(())
}