2016-02-29 22:43:45 +01:00
|
|
|
use std::env;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::prelude::*;
|
2016-02-29 22:56:26 +01:00
|
|
|
use std::fmt::Display;
|
2016-02-29 22:43:45 +01:00
|
|
|
|
2016-03-03 16:55:28 +01:00
|
|
|
extern crate rhai;
|
|
|
|
use rhai::{Engine, FnRegister};
|
2016-02-29 22:43:45 +01:00
|
|
|
|
2016-02-29 22:56:26 +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) {
|
2016-03-02 02:45:02 +01:00
|
|
|
let mut engine = Engine::new();
|
2016-03-02 03:36:46 +01:00
|
|
|
|
2016-03-02 02:45:02 +01:00
|
|
|
&(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");
|
|
|
|
|
2016-02-29 22:43:45 +01:00
|
|
|
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)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-03 16:55:28 +01:00
|
|
|
|