Simplified function registration to not require explicit coercion step. Simplified eval to take &str instead of String
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user