diff --git a/engine/src/core/repl/zlua.rs b/engine/src/core/repl/zlua.rs index c5c483b..90203c5 100644 --- a/engine/src/core/repl/zlua.rs +++ b/engine/src/core/repl/zlua.rs @@ -23,12 +23,12 @@ impl Command for ZLua { globals.set("add", add)?; let is_equal = lua.create_function(|_, (list1, list2): (i32, i32)| { - // This function just checks whether two string lists are equal, and in an inefficient way. - // Lua callbacks return `mlua::Result`, an Ok value is a normal return, and an Err return - // turns into a Lua 'error'. Again, any type that is convertible to Lua may be returned. + if list1 == 0 || list2 == 0 { + return Err(mlua::Error::RuntimeError("Zero values not allowed".to_string())); + } Ok(list1 == list2) })?; - globals.set("is_equal", is_equal)?; + globals.set("isEqual", is_equal)?; let log = lua.create_function(|_, (msg,): (String,)| { println!("{}", msg); @@ -36,7 +36,11 @@ impl Command for ZLua { })?; globals.set("log", log)?; - + let fail_safe = lua.create_function(|_,()|{ + println!("Failed"); + Ok(()) + })?; + globals.set("failSafe",fail_safe)?; let mut editor = DefaultEditor::new().expect("Failed to create editor"); loop { @@ -55,6 +59,15 @@ impl Command for ZLua { match lua.load(&line).eval::() { Ok(values) => { + for value in &values { + match value { + mlua::Value::Nil => println!("Got nil value"), + mlua::Value::Number(n) => println!("Got number: {}", n), + mlua::Value::String(s) => println!("Got string: {}", s.to_str()?), + mlua::Value::Boolean(b) => println!("Got boolean: {}", b), + _ => eprintln!("Got unexpected type: {:#?}", value) + } + } editor.add_history_entry(line).unwrap(); println!( "{}", @@ -76,9 +89,11 @@ impl Command for ZLua { } Err(e) => { - eprintln!("error: {}", e); + eprintln!("Error: {} at line {}", e, line.lines().count()); + eprintln!("Input that caused error: {}", line); break; } + } } }