feat: add vim.tbl_get (#17831)

vim.tbl_get takes a table with subsequent string arguments (variadic) that
index into the table. If the value pointed to by the set of keys exists,
the function returns the value. If the set of keys does not exist, the
function returns nil.
This commit is contained in:
Michael Lingelbach
2022-03-24 12:01:04 -07:00
committed by GitHub
parent 39af40580a
commit 69f1de86dc
3 changed files with 49 additions and 0 deletions

View File

@@ -490,6 +490,12 @@ describe('lua stdlib', function()
eq(false, exec_lua("return vim.tbl_isempty({a=1, b=2, c=3})"))
end)
it('vim.tbl_get', function()
eq(true, exec_lua("return vim.tbl_get({ test = { nested_test = true }}, 'test', 'nested_test')"))
eq(NIL, exec_lua("return vim.tbl_get({}, 'missing_key')"))
eq(NIL, exec_lua("return vim.tbl_get({})"))
end)
it('vim.tbl_extend', function()
ok(exec_lua([[
local a = {x = 1}