Merge pull request #15767 from lewis6991/lua_var_index

feat(lua): allow passing handles to `vim.b/w/t`
This commit is contained in:
Björn Linse
2021-10-19 22:21:31 +02:00
committed by GitHub
3 changed files with 44 additions and 8 deletions

View File

@@ -323,22 +323,25 @@ end
do
local validate = vim.validate
local function make_dict_accessor(scope)
local function make_dict_accessor(scope, handle)
validate {
scope = {scope, 's'};
}
local mt = {}
function mt:__newindex(k, v)
return vim._setvar(scope, 0, k, v)
return vim._setvar(scope, handle or 0, k, v)
end
function mt:__index(k)
return vim._getvar(scope, 0, k)
if handle == nil and type(k) == 'number' then
return make_dict_accessor(scope, k)
end
return vim._getvar(scope, handle or 0, k)
end
return setmetatable({}, mt)
end
vim.g = make_dict_accessor('g')
vim.v = make_dict_accessor('v')
vim.g = make_dict_accessor('g', false)
vim.v = make_dict_accessor('v', false)
vim.b = make_dict_accessor('b')
vim.w = make_dict_accessor('w')
vim.t = make_dict_accessor('t')