pub fn repl() {
    let lua = get_lua_state(None).unwrap();
    lua.context(|ctx| {
        let mut editor = Editor::<()>::new();
        loop {
            let mut prompt = "> ";
            let mut line = String::new();
        
            loop {
                match editor.readline(prompt) {
                    Ok(input) => line.push_str(&input),
                    Err(_) => return,
                }

                // did the user input a repl command?
                if let Some(':') = line.chars().next() {
                    match run_command(&line) {
                        0 => return,
                        _ => break,
                    };
                }

                let code = transpile(&line);

                match ctx.load(&code).eval::<MultiValue>() {
                    Ok(values) => {
                        editor.add_history_entry(line);
                        let output = values
                                    .iter()
                                    .map(|value| show_swedish_values(&value))
                                    .collect::<Vec<_>>()
                                    .join("\t");
                        if cfg!(windows) {
                            println!("{}", output);
                        } else {
                            println!("{}", output.green());
                        }
                        break;
                    }
                    Err(Error::SyntaxError {
                        incomplete_input: true,
                        ..
                    }) => {
                        line.push_str("\n");
                        prompt = ">> ";
                    }
                    Err(e) => {
                        if cfg!(windows) {
                            eprintln!("{}", error_repr(e));
                        } else {
                            eprintln!("{}", error_repr(e).red());
                        }
                        break; 
                    }
                }
            }
        }
    });
}
// REPL based on rlua example code 
REPL based on rlua example code
REPL based on rlua example code
pub fn repl() {
    let lua = get_lua_state(None).unwrap();
    lua.context(|ctx| {
        let mut editor = Editor::<()>::new();
        loop {
            let mut prompt = "> ";
            let mut line = String::new();
            loop {
                match editor.readline(prompt) {
                    Ok(input) => line.push_str(&input),
                    Err(_) => return,
                }
                // did the user input a repl command?
                if let Some(':') = line.chars().next() {
                    match run_command(&line) {
                        0 => return,
                        _ => break,
                    };
                }
                let code = transpile(&line);
                match ctx.load(&code).eval::<MultiValue>() {
                    Ok(values) => {
                        editor.add_history_entry(line);
                        let output = values
                                    .iter()
                                    .map(|value| show_swedish_values(&value))
                                    .collect::<Vec<_>>()
                                    .join("\t");
                        if cfg!(windows) {
                            println!("{}", output);
                        } else {
                            println!("{}", output.green());
                        }
                        break;
                    }
                    Err(Error::SyntaxError {
                        incomplete_input: true,
                        ..
                    }) => {
                        line.push_str("\n");
                        prompt = ">> ";
                    }
                    Err(e) => {
                        if cfg!(windows) {
                            eprintln!("{}", error_repr(e));
                        } else {
                            eprintln!("{}", error_repr(e).red());
                        }
                        break; 
                    }
                }
            }
        }
    });
}
pub fn repl ( ) { let lua = get_lua_state ( None ) . unwrap ( ) ; lua . context ( | ctx | { let mut editor = Editor :: < ( ) > :: new ( ) ; loop { let mut prompt = " " ; let mut line = String :: new ( ) ; loop { match editor . readline ( prompt ) { Ok ( input ) => line . push_str ( & input ) , Err ( _ ) => return , } // did the user input a repl command? if let Some ( ':' ) = line . chars ( ) . next ( ) { match run_command ( & line ) { 0 => return , _ => break , } ; } let code = transpile ( & line ) ; match ctx . load ( & code ) . eval :: < MultiValue > ( ) { Ok ( values ) => { editor . add_history_entry ( line ) ; let output = values . iter ( ) . map ( | value | show_swedish_values ( & value ) ) . collect :: < Vec < _ > > ( ) . join ( " \t " ) ; if cfg ! ( windows ) { println ! ( " " output ) ; } else { println ! ( " " output green ( ) ) ; } break ; } Err ( Error :: SyntaxError { incomplete_input : true , .. } ) => { line . push_str ( " \n " ) ; prompt = " " ; } Err ( e ) => { if cfg ! ( windows ) { eprintln ! ( " " error_repr ( e ) ) ; } else { eprintln ! ( " " error_repr ( e ) red ( ) ) ; } break ; } } } } } ) ; }
REPL based on rlua example code
REPL based on rlua example code