diff --git a/lua/luamodule/definestuff.lua b/lua/luamodule/definestuff.lua new file mode 100644 index 0000000..6fe7300 --- /dev/null +++ b/lua/luamodule/definestuff.lua @@ -0,0 +1,7 @@ +local o = {} + +o.showstuff = function () + print "nvim-example-lua-plugin.luamodule.definestuff showstuff: hello" +end + +return o diff --git a/lua/luamodule/init.lua b/lua/luamodule/init.lua index 28ccdb0..2537282 100644 --- a/lua/luamodule/init.lua +++ b/lua/luamodule/init.lua @@ -1,7 +1,3 @@ -local luamodule = {} - -luamodule.showstuff = function () - print "nvim-example-lua-plugin.luamodule.showstuff: hello" +function GlobalLuaFunction() + print "nvim-example-lua-plugin.luamodule.init GlobalLuaFunction: hello" end - -return luamodule diff --git a/plugin/nvim-example-lua-plugin.vim b/plugin/nvim-example-lua-plugin.vim index 5fc2c34..b7e34cb 100644 --- a/plugin/nvim-example-lua-plugin.vim +++ b/plugin/nvim-example-lua-plugin.vim @@ -1,23 +1,42 @@ -" The VimL/VimScript code is included in this sample plugin to demonstrate the -" two different approaches but it is not required you use VimL. Feel free to -" delete this code and proceed without it. +" The VimL/VimScript code is included in this file to demonstrate that the +" file is being loaded. It is not required for the Lua code to execute and can +" be deleted. -"echo "nvim-example-lua-plugin.vim: VimL code executing." +echo "nvim-example-lua-plugin.vim: VimL code executing." function LuaDoItVimL() echo "nvim-example-lua-plugin.vim LuaDoItVimL(): hello" endfunction + +" Neovim knows about finding VimL files in the `plugin` directory, but it +" won't find Lua files in the same location. So, you need to bootstrap your +" Lua code using a VimL file. There are two possibilities: + +" 1. Lua code can be embedded in a VimL file by using a lua block. lua < :lua GlobalLuaFunction() + +" Lua code can be defined in other files, rather than just `lua.lua` or +" `init.lua`. Here, Lua code is defined in `lua\luamodule\definestuff.lua`. +lua require("luamodule.definestuff").showstuff()