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