use imgui::*; use rlua::{Lua, MultiValue}; mod support; mod testbench; #[derive(Default)] struct State { lua: Lua, console: Vec, repl_input: ImString, } impl State { fn new() -> State { State { lua: Lua::new(), console: Vec::new(), repl_input: ImString::with_capacity(256), } } } fn draw_console(_run: &mut bool, ui: &mut Ui, state: &mut State) { let win = Window::new(im_str!("Lua Console")) .size([400., 500.], Condition::Appearing) .position([440., 20.], Condition::Appearing); win.build(&ui, || { ChildWindow::new("console") .size([0., 400.]) .scrollable(true) .build(&ui, || { for line in &state.console { ui.text(line); } }); ui.separator(); ui.input_text(im_str!("Lua"), &mut state.repl_input).build(); ui.same_line(0.); if ui.button(im_str!("Eval"), [0., 0.]) { let input = state.repl_input.to_str().clone(); let mut new_text = String::new(); state.lua.context(|ctx| { match ctx.load(input).eval::() { Ok(values) => { new_text.push_str( &values .iter() .map(|value| format!("{:?}", value)) .collect::>() .join("\t"), ); } Err(e) => { new_text.push_str(&e.to_string()); } }; }); state.console.push(ImString::new(format!("> {}", input))); state.console.push(ImString::new(new_text)); state.repl_input.clear(); } }); } fn main() { let system = support::init(file!()); let mut state = State::new(); let mut bench = testbench::Bench::new(); system.main_loop(move |run, ui| { // ui.show_demo_window(run); bench.draw(run, ui); draw_console(run, ui, &mut state); }); }