2022-02-12 12:41:04 +08:00
|
|
|
//! A simple example that evaluates an expression and prints the result.
|
|
|
|
|
2022-01-11 22:12:46 +08:00
|
|
|
use rhai::{Engine, EvalAltResult};
|
2016-03-03 11:08:34 -05:00
|
|
|
|
2020-04-21 23:25:12 +08:00
|
|
|
fn main() -> Result<(), Box<EvalAltResult>> {
|
2020-10-07 15:52:24 +08:00
|
|
|
let engine = Engine::new();
|
2016-03-03 11:08:34 -05:00
|
|
|
|
2021-08-06 14:46:27 +08:00
|
|
|
engine.run(r#"print("hello, world!")"#)?;
|
2021-02-20 23:46:25 +08:00
|
|
|
|
2022-01-11 22:12:46 +08:00
|
|
|
let result = engine.eval::<i64>("40 + 2")?;
|
2020-03-09 16:54:43 +08:00
|
|
|
|
2022-02-10 12:54:30 +08:00
|
|
|
println!("The Answer: {}", result); // prints 42
|
2020-03-09 16:54:43 +08:00
|
|
|
|
|
|
|
Ok(())
|
2017-12-20 12:16:14 +01:00
|
|
|
}
|