2019-09-18 12:21:07 +02:00
|
|
|
use rhai::{Engine, RegisterFn, Scope};
|
2017-10-15 17:50:39 +02:00
|
|
|
use std::io::{stdin, stdout, Write};
|
2019-09-18 12:21:07 +02:00
|
|
|
use std::process::exit;
|
2017-10-15 17:50:39 +02:00
|
|
|
|
|
|
|
pub fn main() {
|
2017-12-20 12:16:14 +01:00
|
|
|
let mut engine = Engine::new();
|
|
|
|
let mut scope = Scope::new();
|
2017-10-15 17:50:39 +02:00
|
|
|
|
2020-03-02 08:19:59 +01:00
|
|
|
engine.register_fn("exit", || exit(0));
|
2017-10-15 17:50:39 +02:00
|
|
|
|
2017-12-20 12:16:14 +01:00
|
|
|
loop {
|
|
|
|
print!("> ");
|
2020-03-02 08:19:59 +01:00
|
|
|
|
2017-12-20 12:16:14 +01:00
|
|
|
let mut input = String::new();
|
|
|
|
stdout().flush().expect("couldn't flush stdout");
|
2020-03-02 08:19:59 +01:00
|
|
|
|
2017-12-20 12:16:14 +01:00
|
|
|
if let Err(e) = stdin().read_line(&mut input) {
|
|
|
|
println!("input error: {}", e);
|
|
|
|
}
|
2017-10-15 17:50:39 +02:00
|
|
|
|
2017-12-20 12:16:14 +01:00
|
|
|
if let Err(e) = engine.consume_with_scope(&mut scope, &input) {
|
|
|
|
println!("error: {}", e);
|
|
|
|
}
|
|
|
|
}
|
2017-10-15 17:50:39 +02:00
|
|
|
}
|