Simplified function registration to not require explicit coercion step. Simplified eval to take &str instead of String

This commit is contained in:
jonathandturner
2016-03-16 18:07:08 -04:00
parent 6950219251
commit 254f4b081c
9 changed files with 143 additions and 116 deletions

View File

@@ -8,9 +8,9 @@ fn add(x: i32, y: i32) -> i32 {
fn main() {
let mut engine = Engine::new();
&(add as fn(x: i32, y: i32)->i32).register(&mut engine, "add");
engine.register_fn("add", add);
if let Ok(result) = engine.eval("add(40, 2)".to_string()).unwrap().downcast::<i32>() {
if let Ok(result) = engine.eval("add(40, 2)").unwrap().downcast::<i32>() {
println!("Answer: {}", *result); // prints 42
}
}