pub fn eval_repl_entry(source: &str) -> EmbeddedResult<RunOutcome>Examples found in repository?
examples/repl.rs (line 33)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 println!("RustScript embedded REPL (JIT off)");
7 println!("commands: .help, .quit");
8
9 let stdin = io::stdin();
10 let mut input = stdin.lock();
11 let mut line = String::new();
12
13 loop {
14 print!("rs-emb> ");
15 io::stdout().flush()?;
16 line.clear();
17 if input.read_line(&mut line)? == 0 {
18 println!();
19 break;
20 }
21
22 let source = line.trim();
23 match source {
24 "" => continue,
25 ".quit" | ".exit" => break,
26 ".help" => {
27 println!("enter RustScript statements, for example: print(1 + 2);");
28 continue;
29 }
30 _ => {}
31 }
32
33 match eval_repl_entry(source)? {
34 RunOutcome::Halted { stack } => {
35 if let Some(value) = stack.last() {
36 println!("=> {}", render_value(value));
37 } else {
38 println!("=> <empty>");
39 }
40 }
41 }
42 }
43
44 Ok(())
45}