diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2023-04-01 08:02:58 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-01 08:02:58 -0600 |
commit | 643c0ed571f1ac6e83f73ab2593132901278b4da (patch) | |
tree | aa37b3c75806a016f2d0b76b4691a9024bbc253c /runtime/lua/vim/shared.lua | |
parent | 6a4ebf894fa39bfb09695a129a3300cb99408542 (diff) | |
download | rneovim-643c0ed571f1ac6e83f73ab2593132901278b4da.tar.gz rneovim-643c0ed571f1ac6e83f73ab2593132901278b4da.tar.bz2 rneovim-643c0ed571f1ac6e83f73ab2593132901278b4da.zip |
feat: allow function passed to defaulttable to take an argument (#22839)
Pass the value of the key being accessed to the create function, to
allow users to dynamically generate default values.
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r-- | runtime/lua/vim/shared.lua | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index 884929e33a..9e337e93e8 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -796,13 +796,15 @@ end --- a.b.c = 1 --- </pre> --- ----@param create function|nil The function called to create a missing value. +---@param create function?(key:any):any The function called to create a missing value. ---@return table Empty table with metamethod function vim.defaulttable(create) - create = create or vim.defaulttable + create = create or function(_) + return vim.defaulttable() + end return setmetatable({}, { __index = function(tbl, key) - rawset(tbl, key, create()) + rawset(tbl, key, create(key)) return rawget(tbl, key) end, }) |