aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2019-06-26 14:33:48 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2019-06-30 15:16:32 +0200
commit99f24dfbed84cea24fc1d8bb80ab10a2dd3eca0b (patch)
tree9f379c0e1e929a5ca4821c4db0cb0def18cdfedd
parentd33aaa0f5f96afb1608a4a3eb2057da956a24b2b (diff)
downloadrneovim-99f24dfbed84cea24fc1d8bb80ab10a2dd3eca0b.tar.gz
rneovim-99f24dfbed84cea24fc1d8bb80ab10a2dd3eca0b.tar.bz2
rneovim-99f24dfbed84cea24fc1d8bb80ab10a2dd3eca0b.zip
make vim.loop == require'luv'
This avoids initializing libluv a second time if a plugin invokes require'luv'. It is probably not an issue, but better to be safe.
-rw-r--r--src/nvim/lua/executor.c11
-rw-r--r--test/functional/lua/loop_spec.lua4
2 files changed, 14 insertions, 1 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 0127bfae7c..4fd4e4c4fa 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -228,7 +228,16 @@ static int nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
luv_set_loop(lstate, &main_loop.uv);
luv_set_callback(lstate, nlua_luv_cfpcall);
luaopen_luv(lstate);
- lua_setfield(lstate, -2, "loop");
+ lua_pushvalue(lstate, -1);
+ lua_setfield(lstate, -3, "loop");
+
+ // package.loaded.luv = vim.loop
+ // otherwise luv will be reinitialized when require'luv'
+ lua_getglobal(lstate, "package");
+ lua_getfield(lstate, -1, "loaded");
+ lua_pushvalue(lstate, -3);
+ lua_setfield(lstate, -2, "luv");
+ lua_pop(lstate, 3);
lua_setglobal(lstate, "vim");
return 0;
diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua
index 3b3b81f886..cd3b935e1a 100644
--- a/test/functional/lua/loop_spec.lua
+++ b/test/functional/lua/loop_spec.lua
@@ -142,4 +142,8 @@ describe('vim.loop', function()
]])
eq({blocking=false, mode='n'}, exec_lua("return _G.mode"))
end)
+
+ it("is equal to require('luv')", function()
+ eq(true, exec_lua("return vim.loop == require('luv')"))
+ end)
end)