Support Dynamic return values.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use rhai::{Engine, EvalAltResult, Position, Scope, AST};
|
||||
use rhai::{Dynamic, Engine, EvalAltResult, Position, Scope, AST};
|
||||
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
use rhai::OptimizationLevel;
|
||||
@@ -137,7 +137,7 @@ fn main() {
|
||||
_ => (),
|
||||
}
|
||||
|
||||
if let Err(err) = engine
|
||||
match engine
|
||||
.compile_with_scope(&scope, &script)
|
||||
.map_err(EvalAltResult::ErrorParsing)
|
||||
.and_then(|r| {
|
||||
@@ -157,22 +157,20 @@ fn main() {
|
||||
main_ast = main_ast.merge(&ast);
|
||||
|
||||
// Evaluate
|
||||
let result = engine
|
||||
.consume_ast_with_scope(&mut scope, &main_ast)
|
||||
.or_else(|err| match err {
|
||||
EvalAltResult::Return(_, _) => Ok(()),
|
||||
err => Err(err),
|
||||
});
|
||||
|
||||
// Throw away all the statements, leaving only the functions
|
||||
main_ast.retain_functions();
|
||||
|
||||
result
|
||||
})
|
||||
{
|
||||
println!();
|
||||
print_error(&input, err);
|
||||
println!();
|
||||
engine.eval_ast_with_scope::<Dynamic>(&mut scope, &main_ast)
|
||||
}) {
|
||||
Ok(result) => {
|
||||
println!("=> {:?}", result);
|
||||
println!();
|
||||
}
|
||||
Err(err) => {
|
||||
println!();
|
||||
print_error(&input, err);
|
||||
println!();
|
||||
}
|
||||
}
|
||||
|
||||
// Throw away all the statements, leaving only the functions
|
||||
main_ast.retain_functions();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user