Move to lib style, move scripts into their own directory, start source examples
This commit is contained in:
38
examples/rhai_runner.rs
Normal file
38
examples/rhai_runner.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::fmt::Display;
|
||||
|
||||
extern crate rhai;
|
||||
use rhai::{Engine, FnRegister};
|
||||
|
||||
fn showit<T: Display>(x: &mut T) -> () {
|
||||
println!("{}", x)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for fname in env::args().skip(1) {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
&(showit as fn(x: &mut i32)->()).register(&mut engine, "print");
|
||||
&(showit as fn(x: &mut i64)->()).register(&mut engine, "print");
|
||||
&(showit as fn(x: &mut u32)->()).register(&mut engine, "print");
|
||||
&(showit as fn(x: &mut u64)->()).register(&mut engine, "print");
|
||||
&(showit as fn(x: &mut f32)->()).register(&mut engine, "print");
|
||||
&(showit as fn(x: &mut f64)->()).register(&mut engine, "print");
|
||||
&(showit as fn(x: &mut bool)->()).register(&mut engine, "print");
|
||||
&(showit as fn(x: &mut String)->()).register(&mut engine, "print");
|
||||
|
||||
if let Ok(mut f) = File::open(fname.clone()) {
|
||||
let mut contents = String::new();
|
||||
if let Ok(_) = f.read_to_string(&mut contents) {
|
||||
|
||||
match engine.eval(contents) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {println!("Error: {:?}", e)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user