diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/lua.txt | 4 | ||||
-rw-r--r-- | runtime/lua/vim/shared.lua | 8 |
2 files changed, 7 insertions, 5 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 14f2ba2b04..ebbf8bb463 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -1635,8 +1635,8 @@ defaulttable({create}) *vim.defaulttable()* < Parameters: ~ - • {create} (function|nil) The function called to create a missing - value. + • {create} function?(key:any):any The function called to create a + missing value. Return: ~ (table) Empty table with metamethod 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, }) |