From a34b3ce7770e7313d4891caf5d4f0958473dc7d2 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 28 Jun 2022 16:59:28 -0700 Subject: [PATCH] properly fix action=wezterm.action.ExtendSelectionToMouseCursor(nil) ee5206db507f257776230fcc3c461734802b3a5a attempted to fix this by replacing all DynValue::Null values with a special null userdata. However, a consequence of that is that it broke: ``` window:get_config_overrides() or {} ``` because a userdata is always true, even if it represents a null value. This commit fixes that case by being selective with the userdata usage: we only use it when converting the value portion of a table key/value pair. refs: #2177 refs: #2200 --- luahelper/src/lib.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/luahelper/src/lib.rs b/luahelper/src/lib.rs index 9c4b383a2..11e036f06 100644 --- a/luahelper/src/lib.rs +++ b/luahelper/src/lib.rs @@ -58,12 +58,30 @@ macro_rules! impl_lua_conversion_dynamic { pub fn dynamic_to_lua_value<'lua>( lua: &'lua mlua::Lua, value: DynValue, +) -> mlua::Result { + dynamic_to_lua_value_impl(lua, value, false) +} + +pub fn dynamic_to_lua_table_value<'lua>( + lua: &'lua mlua::Lua, + value: DynValue, +) -> mlua::Result { + dynamic_to_lua_value_impl(lua, value, true) +} + +fn dynamic_to_lua_value_impl<'lua>( + lua: &'lua mlua::Lua, + value: DynValue, + is_table_value: bool, ) -> mlua::Result { Ok(match value { // Use a special userdata as a proxy for Null, because if we are a value // and we use Nil then the key is implicitly deleted and that changes // the representation of the data in unexpected ways - DynValue::Null => LuaValue::LightUserData(mlua::LightUserData(std::ptr::null_mut())), + DynValue::Null if is_table_value => { + LuaValue::LightUserData(mlua::LightUserData(std::ptr::null_mut())) + } + DynValue::Null => LuaValue::Nil, DynValue::Bool(b) => LuaValue::Boolean(b), DynValue::String(s) => s.to_lua(lua)?, DynValue::U64(u) => u.to_lua(lua)?, @@ -81,7 +99,7 @@ pub fn dynamic_to_lua_value<'lua>( for (key, value) in object.into_iter() { table.set( dynamic_to_lua_value(lua, key)?, - dynamic_to_lua_value(lua, value)?, + dynamic_to_lua_table_value(lua, value)?, )?; } LuaValue::Table(table)