This commit is contained in:
2026-04-02 23:53:31 +08:00
parent e5135515c7
commit 949b99c356
3 changed files with 507 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
use mlua::{Error, Lua, MultiValue};
use rustyline::DefaultEditor;
fn main() {
let lua = Lua::new();
let mut editor = DefaultEditor::new().expect("Failed to create editor");
loop {
let mut prompt = "> ";
let mut line = String::new();
loop {
match editor.readline(prompt) {
Ok(input) => line.push_str(&input),
Err(_) => return,
}
match lua.load(&line).eval::<MultiValue>() {
Ok(values) => {
editor.add_history_entry(line).unwrap();
if values.len() > 0 {
println!(
"{}",
values
.iter()
.map(|value| format!("{:#?}", value))
.collect::<Vec<_>>()
.join("\t")
);
}
break;
}
Err(Error::SyntaxError {
incomplete_input: true,
..
}) => {
// continue reading input and append it to `line`
line.push_str("\n"); // separate input lines
prompt = ">> ";
}
Err(e) => {
eprintln!("error: {}", e);
break;
}
}
}
}
}