rhai/examples/rhai_runner.rs

28 lines
931 B
Rust
Raw Normal View History

2019-09-18 12:21:07 +02:00
use rhai::{Engine, RegisterFn};
2016-02-29 22:43:45 +01:00
use std::env;
use std::fmt::Display;
2016-02-29 22:43:45 +01:00
fn showit<T: Display>(x: &mut T) -> () {
println!("{}", x)
}
2016-02-29 22:43:45 +01:00
fn main() {
for fname in env::args().skip(1) {
let mut engine = Engine::new();
2016-03-02 03:36:46 +01:00
2017-12-20 12:16:14 +01:00
engine.register_fn("print", showit as fn(x: &mut i32) -> ());
engine.register_fn("print", showit as fn(x: &mut i64) -> ());
engine.register_fn("print", showit as fn(x: &mut u32) -> ());
engine.register_fn("print", showit as fn(x: &mut u64) -> ());
engine.register_fn("print", showit as fn(x: &mut f32) -> ());
engine.register_fn("print", showit as fn(x: &mut f64) -> ());
engine.register_fn("print", showit as fn(x: &mut bool) -> ());
engine.register_fn("print", showit as fn(x: &mut String) -> ());
2016-03-17 13:45:48 +01:00
match engine.eval_file::<()>(&fname) {
Ok(_) => (),
2017-12-20 12:16:14 +01:00
Err(e) => println!("Error: {}", e),
2016-02-29 22:43:45 +01:00
}
}
}