Home

Awesome

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:

Motivation

See:

Requirements

Installation

This package is available on luarocks.

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