diff --git a/luahelper/src/lib.rs b/luahelper/src/lib.rs index a77425c4d..ade2c6bf3 100644 --- a/luahelper/src/lib.rs +++ b/luahelper/src/lib.rs @@ -307,14 +307,6 @@ impl<'lua> ValuePrinterHelper<'lua> { impl<'lua> std::fmt::Debug for ValuePrinterHelper<'lua> { fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> { match &self.value { - LuaValue::Nil => fmt.write_str("nil"), - LuaValue::Boolean(b) => fmt.write_str(if *b { "true" } else { "false" }), - LuaValue::Integer(i) => fmt.write_fmt(format_args!("{}", i)), - LuaValue::Number(i) => fmt.write_fmt(format_args!("{}", i)), - LuaValue::String(s) => match s.to_str() { - Ok(s) => fmt.write_fmt(format_args!("{:?}", s)), - Err(_) => fmt.write_fmt(format_args!("{:?}", s.as_bytes())), - }, LuaValue::Table(t) => { self.visited .borrow_mut() @@ -379,8 +371,8 @@ impl<'lua> std::fmt::Debug for ValuePrinterHelper<'lua> { fmt.debug_map().entries(&map).finish() } } - LuaValue::UserData(ud) => match ud.get_metatable() { - Ok(mt) => { + LuaValue::UserData(ud) => { + if let Ok(mt) = ud.get_metatable() { if let Ok(to_dynamic) = mt.get::("__wezterm_to_dynamic") { return match to_dynamic.call(LuaValue::UserData(ud.clone())) { Ok(value) => Self { @@ -391,28 +383,17 @@ impl<'lua> std::fmt::Debug for ValuePrinterHelper<'lua> { Err(err) => write!(fmt, "Error calling __wezterm_to_dynamic: {err}"), }; } - match mt.get::(mlua::MetaMethod::ToString) { - Ok(to_string) => match to_string.call(LuaValue::UserData(ud.clone())) { - Ok(value) => Self { - visited: Rc::clone(&self.visited), - value, - } - .fmt(fmt), - Err(err) => { - write!(fmt, "Error calling tostring: {err:#}") - } - }, - Err(err) => { - write!(fmt, "Error getting tostring: {err:#}") - } - } } - Err(_) => fmt.write_str("userdata"), - }, - LuaValue::LightUserData(_) => fmt.write_str("userdata"), - LuaValue::Thread(_) => fmt.write_str("thread"), - LuaValue::Function(_) => fmt.write_str("function"), + match self.value.to_string() { + Ok(s) => fmt.write_str(&s), + Err(err) => write!(fmt, "userdata ({err:#})"), + } + } LuaValue::Error(e) => fmt.write_fmt(format_args!("error {}", e)), + _ => match self.value.to_string() { + Ok(s) => fmt.write_str(&s), + Err(err) => write!(fmt, "({err:#})"), + }, } } }