2020-03-24 02:49:08 +01:00
|
|
|
use rhai::{Engine, EvalAltResult, Scope, INT};
|
2016-03-04 14:45:43 +01:00
|
|
|
|
2020-04-21 17:25:12 +02:00
|
|
|
fn main() -> Result<(), Box<EvalAltResult>> {
|
2020-04-07 07:23:06 +02:00
|
|
|
let 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-12 07:54:14 +01:00
|
|
|
engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5")?;
|
2016-03-04 14:45:43 +01:00
|
|
|
|
2021-02-20 16:46:25 +01:00
|
|
|
println!("x = {}", scope.get_value::<INT>("x").unwrap());
|
2020-03-09 09:54:43 +01:00
|
|
|
|
2021-02-20 16:46:25 +01:00
|
|
|
for _ in 0..10 {
|
|
|
|
let result = engine.eval_with_scope::<INT>(&mut scope, "x += 1; x")?;
|
|
|
|
|
|
|
|
println!("result: {}", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("x = {}", scope.get_value::<INT>("x").unwrap());
|
2020-03-09 09:54:43 +01:00
|
|
|
|
|
|
|
Ok(())
|
2016-03-04 14:45:43 +01:00
|
|
|
}
|