From 75955bca0b0c625e7c41d6fa052459ebe9e117e1 Mon Sep 17 00:00:00 2001 From: Jacob Simpson Date: Sat, 5 Jan 2019 06:42:39 -0800 Subject: [PATCH 1/2] Reformat and comment VimL. Change the structure of the code in the VimL file in the `plugin` directory so that the different parts are distinct from each other. Also added more comments explaining what each part demonstrates. --- plugin/nvim-example-lua-plugin.vim | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/plugin/nvim-example-lua-plugin.vim b/plugin/nvim-example-lua-plugin.vim index 5fc2c34..1cab460 100644 --- a/plugin/nvim-example-lua-plugin.vim +++ b/plugin/nvim-example-lua-plugin.vim @@ -1,23 +1,28 @@ -" 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 -lua < Date: Sat, 5 Jan 2019 07:15:11 -0800 Subject: [PATCH 2/2] Expand on Lua demonstration code. --- lua/luamodule/definestuff.lua | 7 +++++++ lua/luamodule/init.lua | 8 ++------ plugin/nvim-example-lua-plugin.vim | 20 +++++++++++++++++--- 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 lua/luamodule/definestuff.lua 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 1cab460..b7e34cb 100644 --- a/plugin/nvim-example-lua-plugin.vim +++ b/plugin/nvim-example-lua-plugin.vim @@ -12,7 +12,7 @@ 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 -" Loa code using a VimL file. There are two possibilities: +" 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()