mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 15:08:35 +00:00
Merge pull request #17375 from shadmansaleh/fix/vim.g/autoload
fix: autoload variables not loaded with vim.g & nvim_get_var
This commit is contained in:
@@ -601,7 +601,19 @@ void nvim_del_current_line(Error *err)
|
||||
Object nvim_get_var(String name, Error *err)
|
||||
FUNC_API_SINCE(1)
|
||||
{
|
||||
return dict_get_value(&globvardict, name, err);
|
||||
dictitem_T *di = tv_dict_find(&globvardict, name.data, (ptrdiff_t)name.size);
|
||||
if (di == NULL) { // try to autoload script
|
||||
if (!script_autoload(name.data, name.size, false) || aborting()) {
|
||||
api_set_error(err, kErrorTypeValidation, "Key not found: %s", name.data);
|
||||
return (Object)OBJECT_INIT;
|
||||
}
|
||||
di = tv_dict_find(&globvardict, name.data, (ptrdiff_t)name.size);
|
||||
}
|
||||
if (di == NULL) {
|
||||
api_set_error(err, kErrorTypeValidation, "Key not found: %s", name.data);
|
||||
return (Object)OBJECT_INIT;
|
||||
}
|
||||
return vim_to_object(&di->di_tv);
|
||||
}
|
||||
|
||||
/// Sets a global (g:) variable.
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include "nvim/func_attr.h"
|
||||
#include "nvim/garray.h"
|
||||
#include "nvim/getchar.h"
|
||||
#include "nvim/globals.h"
|
||||
#include "nvim/lua/converter.h"
|
||||
#include "nvim/lua/executor.h"
|
||||
#include "nvim/lua/stdlib.h"
|
||||
@@ -408,6 +409,12 @@ int nlua_getvar(lua_State *lstate)
|
||||
const char *name = luaL_checklstring(lstate, 3, &len);
|
||||
|
||||
dictitem_T *di = tv_dict_find(dict, name, (ptrdiff_t)len);
|
||||
if (di == NULL && dict == &globvardict) { // try to autoload script
|
||||
if (!script_autoload(name, len, false) || aborting()) {
|
||||
return 0; // nil
|
||||
}
|
||||
di = tv_dict_find(dict, name, (ptrdiff_t)len);
|
||||
}
|
||||
if (di == NULL) {
|
||||
return 0; // nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user