diff --git a/docs/config/lua/wezterm.table/count.md b/docs/config/lua/wezterm.table/count.md index 6efa831a02e..36de9e30bba 100644 --- a/docs/config/lua/wezterm.table/count.md +++ b/docs/config/lua/wezterm.table/count.md @@ -2,11 +2,12 @@ {{since('nightly')}} -This function returns the number of non-nil elements of a Lua table (or array) passed to it. +This function returns the number of non-nil elements of any Lua table passed to it. Note: The Lua function `#` also returns the length of an array, but `#` only works for array-style tables with contiguous integer keys starting with index `1`, and not sparse arrays (with gaps in -their integer keys), or object or other style of tables with non-integer keys. +their integer keys), or object or other style of tables with non-integer keys. `wezterm.table.count` +can instead be used for such tables. ```lua local wezterm = require 'wezterm' diff --git a/lua-api-crates/table-funcs/src/lib.rs b/lua-api-crates/table-funcs/src/lib.rs index 230439f4fdb..449e201cef3 100644 --- a/lua-api-crates/table-funcs/src/lib.rs +++ b/lua-api-crates/table-funcs/src/lib.rs @@ -1,5 +1,5 @@ use config::lua::get_or_create_sub_module; -use config::lua::mlua::{self, Lua, Table, Value as LuaValue}; +use config::lua::mlua::{self, Lua, Table, Value as LuaValue, MultiValue as LuaMultiValue}; use luahelper::impl_lua_conversion_dynamic; use wezterm_dynamic::{FromDynamic, ToDynamic}; @@ -29,6 +29,16 @@ enum ConflictMode { } impl_lua_conversion_dynamic!(ConflictMode); +#[derive(Default, Debug, FromDynamic, ToDynamic, Clone, PartialEq, Eq, Copy)] +enum DepthMode { + /// Take the latest value + #[default] + Top, + /// Raise an error + Deep, +} +impl_lua_conversion_dynamic!(DepthMode); + // merge tables // (in case of overlap of the tables, we default to taking the key-value pair from the last table) // Note that we don't use a HashMap since we want to keep the order of the tables, which @@ -104,28 +114,41 @@ fn deep_extend<'lua>( Ok(tbl) } -fn clone<'lua>(lua: &'lua Lua, table: Table<'lua>) -> mlua::Result