- Lua 96%
- Batchfile 4%
| .github/workflows | ||
| spec | ||
| .busted | ||
| .gitignore | ||
| .luacheckrc | ||
| LICENSE | ||
| nlua | ||
| nlua-scm-1.rockspec | ||
| nlua.bat | ||
| README.md | ||
| rockspec.template | ||
nlua
Lua script that lets you use Neovim as a Lua interpreter.
Neovim embeds a Lua interpreter, but it doesn't expose the same command line interface as plain lua.
The plain interface looks like this:
usage: lua [options] [script [args]]
Available options are:
-e stat execute string 'stat'
-i enter interactive mode after executing 'script'
-l mod require library 'mod' into global 'mod'
-l g=mod require library 'mod' into global 'g'
-v show version information
-E ignore environment variables
-W turn warnings on
-- stop handling options
- stop handling options and execute stdin
nlua is a script which emulates that interface, Using Neovim's -l option under the hood.
Currently supported:
-e-v--[script [args]]- stdin handling
Motivation
-
It lets you use Neovim as Lua interpreter for luarocks. This in turn allows you to run tools like busted to test Neovim plugins.
-
It allows tools like local-lua-debugger-vscode to use the Neovim Lua. Enabling debugging of busted test cases for Neovim plugins.
See:
Requirements
envexecutable supporting the-Soption. Runenv --helpin a shell to verify.- Neovim 0.9+ with LuaJIT
Installation
This package is available on luarocks.
-
Install luarocks using a package manager. For example
pacman -S luarocks -
Install
nluavialuarocks:luarocks --local install nlua -
Add
~/.luarocks/bin/nluato your$PATH:export PATH=$PATH:$HOME/.luarocks/bin: -
Confirm it's working:
echo "print(1 + 2)" | nlua
Note
On Windows, luarocks will install a
nlua.batwrapper script.
Usage
Busted
luarocks --local install busted
busted --lua nlua spec/mytest_spec.lua
If you see a module 'busted.runner' not found error you need to update your LUA_PATH:
eval $(luarocks path --no-bin)
busted --lua nlua spec/mytest_spec.lua
CI for Neovim Plugins
You can use the plugin template to create a new repository that contains nlua/busted based test setup.
As Lua interpreter for luarocks
This allows package installation directly via nlua instead of a system lua
Create a ~/.luarocks/config-nlua.lua with the following contents.
For luarocks 3.10.0 and above:
lua_version = "5.1"
variables = {
LUA = "$HOME/.luarocks/bin/nlua", -- path to where nlua is installed
LUA_INCDIR = "/usr/include/luajit-2.1",
}
For luarocks 3.9.2 and below:
lua_version = "5.1"
variables = {
lua_interpreter = "nlua"
LUA_INCDIR = "/usr/include/luajit-2.1",
LUA_BINDIR = "$HOME/.luarocks/bin", -- path to where nlua is installed
}
To make using this custom configuration a bit easier, you can create a small wrapper.
Create a file called nluarocks somewhere in $PATH - e.g. in
~/.local/bin/nluarocks - with the following content:
#!/usr/bin/env bash
LUAROCKS_CONFIG=$HOME/.luarocks/config-nlua.lua luarocks --local "$@"
Now you should be able to install packages from luarocks using the nvim
Lua-interpreter. For example:
nluarocks install busted