+50
-1
lines changedFilter options
+50
-1
lines changed Original file line number Diff line number Diff line change
@@ -601,7 +601,19 @@ void nvim_del_current_line(Error *err)
601
601
Object nvim_get_var(String name, Error *err)
602
602
FUNC_API_SINCE(1)
603
603
{
604
-
return dict_get_value(&globvardict, name, err);
604
+
dictitem_T *di = tv_dict_find(&globvardict, name.data, (ptrdiff_t)name.size);
605
+
if (di == NULL) { // try to autoload script
606
+
if (!script_autoload(name.data, name.size, false) || aborting()) {
607
+
api_set_error(err, kErrorTypeValidation, "Key not found: %s", name.data);
608
+
return (Object)OBJECT_INIT;
609
+
}
610
+
di = tv_dict_find(&globvardict, name.data, (ptrdiff_t)name.size);
611
+
}
612
+
if (di == NULL) {
613
+
api_set_error(err, kErrorTypeValidation, "Key not found: %s", name.data);
614
+
return (Object)OBJECT_INIT;
615
+
}
616
+
return vim_to_object(&di->di_tv);
605
617
}
606
618
607
619
/// Sets a global (g:) variable.
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
25
25
#include "nvim/func_attr.h"
26
26
#include "nvim/garray.h"
27
27
#include "nvim/getchar.h"
28
+
#include "nvim/globals.h"
28
29
#include "nvim/lua/converter.h"
29
30
#include "nvim/lua/executor.h"
30
31
#include "nvim/lua/stdlib.h"
@@ -408,6 +409,12 @@ int nlua_getvar(lua_State *lstate)
408
409
const char *name = luaL_checklstring(lstate, 3, &len);
409
410
410
411
dictitem_T *di = tv_dict_find(dict, name, (ptrdiff_t)len);
412
+
if (di == NULL && dict == &globvardict) { // try to autoload script
413
+
if (!script_autoload(name, len, false) || aborting()) {
414
+
return 0; // nil
415
+
}
416
+
di = tv_dict_find(dict, name, (ptrdiff_t)len);
417
+
}
411
418
if (di == NULL) {
412
419
return 0; // nil
413
420
}
Original file line number Diff line number Diff line change
@@ -898,6 +898,19 @@ describe('API', function()
898
898
command('lockvar lua')
899
899
eq('Key is locked: lua', pcall_err(meths.del_var, 'lua'))
900
900
eq('Key is locked: lua', pcall_err(meths.set_var, 'lua', 1))
901
+
902
+
-- Check if autoload works properly
903
+
local pathsep = helpers.get_pathsep()
904
+
local xconfig = 'Xhome' .. pathsep .. 'Xconfig'
905
+
local xdata = 'Xhome' .. pathsep .. 'Xdata'
906
+
local autoload_folder = table.concat({xconfig, 'nvim', 'autoload'}, pathsep)
907
+
local autoload_file = table.concat({autoload_folder , 'testload.vim'}, pathsep)
908
+
mkdir_p(autoload_folder)
909
+
write_file(autoload_file , [[let testload#value = 2]])
910
+
911
+
clear{ args_rm={'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_DATA_HOME=xdata } }
912
+
eq(2, meths.get_var('testload#value'))
913
+
rmdir('Xhome')
901
914
end)
902
915
903
916
it('nvim_get_vvar, nvim_set_vvar', function()
Original file line number Diff line number Diff line change
@@ -19,6 +19,9 @@ local NIL = helpers.NIL
19
19
local retry = helpers.retry
20
20
local next_msg = helpers.next_msg
21
21
local remove_trace = helpers.remove_trace
22
+
local mkdir_p = helpers.mkdir_p
23
+
local rmdir = helpers.rmdir
24
+
local write_file = helpers.write_file
22
25
23
26
before_each(clear)
24
27
@@ -1019,6 +1022,20 @@ describe('lua stdlib', function()
1019
1022
eq(3, exec_lua([[return vim.g.GetCounter()]]))
1020
1023
exec_lua([[vim.api.nvim_get_var('AddCounter')()]])
1021
1024
eq(4, exec_lua([[return vim.api.nvim_get_var('GetCounter')()]]))
1025
+
1026
+
-- Check if autoload works properly
1027
+
local pathsep = helpers.get_pathsep()
1028
+
local xconfig = 'Xhome' .. pathsep .. 'Xconfig'
1029
+
local xdata = 'Xhome' .. pathsep .. 'Xdata'
1030
+
local autoload_folder = table.concat({xconfig, 'nvim', 'autoload'}, pathsep)
1031
+
local autoload_file = table.concat({autoload_folder , 'testload.vim'}, pathsep)
1032
+
mkdir_p(autoload_folder)
1033
+
write_file(autoload_file , [[let testload#value = 2]])
1034
+
1035
+
clear{ args_rm={'-u'}, env={ XDG_CONFIG_HOME=xconfig, XDG_DATA_HOME=xdata } }
1036
+
1037
+
eq(2, exec_lua("return vim.g['testload#value']"))
1038
+
rmdir('Xhome')
1022
1039
end)
1023
1040
1024
1041
it('vim.b', function()
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4