rhai/examples/hello.rs

16 lines
352 B
Rust
Raw Normal View History

2022-02-12 12:41:04 +08:00
//! A simple example that evaluates an expression and prints the result.
use rhai::{Engine, EvalAltResult};
fn main() -> Result<(), Box<EvalAltResult>> {
2020-10-07 15:52:24 +08:00
let engine = Engine::new();
engine.run(r#"print("hello, world!")"#)?;
2021-02-20 23:46:25 +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
}