rhai/examples/repl.rs
2020-03-02 15:19:59 +08:00

26 lines
604 B
Rust

use rhai::{Engine, RegisterFn, Scope};
use std::io::{stdin, stdout, Write};
use std::process::exit;
pub fn main() {
let mut engine = Engine::new();
let mut scope = Scope::new();
engine.register_fn("exit", || exit(0));
loop {
print!("> ");
let mut input = String::new();
stdout().flush().expect("couldn't flush stdout");
if let Err(e) = stdin().read_line(&mut input) {
println!("input error: {}", e);
}
if let Err(e) = engine.consume_with_scope(&mut scope, &input) {
println!("error: {}", e);
}
}
}