diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2019-11-27 20:45:41 +0100 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2020-01-01 19:26:29 +0100 |
commit | ea4127e9a7a624484f51c21e17f37c766da15da0 (patch) | |
tree | bcac8ad881805acd86a1d62d87741c5007f31d91 /runtime/lua/vim/shared.lua | |
parent | a251b588acb3a561e5da695280774b9b6fbcd0ea (diff) | |
download | rneovim-ea4127e9a7a624484f51c21e17f37c766da15da0.tar.gz rneovim-ea4127e9a7a624484f51c21e17f37c766da15da0.tar.bz2 rneovim-ea4127e9a7a624484f51c21e17f37c766da15da0.zip |
lua: metatable for empty dict value
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r-- | runtime/lua/vim/shared.lua | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index b5b04d7757..6df9bf1c2f 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -275,9 +275,15 @@ function vim.tbl_flatten(t) end -- Determine whether a Lua table can be treated as an array. +-- +-- An empty table `{}` will default to being treated as an array. +-- Use `vim.emtpy_dict()` to create a table treated as an +-- empty dict. Empty tables returned by `rpcrequest()` and +-- `vim.fn` functions can be checked using this function +-- whether they represent empty API arrays and vimL lists. --- --@params Table ---@returns true: A non-empty array, false: A non-empty table, nil: An empty table +--@returns true: An array-like table, false: A dict-like or mixed table function vim.tbl_islist(t) if type(t) ~= 'table' then return false @@ -296,7 +302,12 @@ function vim.tbl_islist(t) if count > 0 then return true else - return nil + -- TODO(bfredl): in the future, we will always be inside nvim + -- then this check can be deleted. + if vim._empty_dict_mt == nil then + return nil + end + return getmetatable(t) ~= vim._empty_dict_mt end end |