Setup#
Lua’s entire reference implementation fits in a few hundred KB. The operator’s setup problem is usually picking which Lua and where to put it, the system interpreter, LuaJIT, or the Lua that ships inside another tool (Neovim, Nmap, Wireshark, Redis, OpenResty).
Install#
1. Pick the implementation.
PUC-Rio Lua (the reference): plain, slow, the default.
LuaJIT: JIT-compiled, ABI-compatible with Lua 5.1, much faster. The default for performance work.
Embedded Lua: the version shipped inside the host tool (Neovim ships LuaJIT, Nmap ships PUC 5.3, Wireshark embeds PUC 5.x). The operator targets the host’s version.
2. Install via the system package manager.
$ sudo apt install lua5.4 luarocks # Debian / Ubuntu
$ sudo dnf install lua luarocks # Fedora / RHEL
$ brew install lua luarocks # macOS
For multiple versions side-by-side, hererocks lets the
operator install isolated Lua + LuaRocks trees.
$ pipx install hererocks
$ hererocks .luaenv -l5.4 -rlatest
$ source .luaenv/bin/activate
3. Verify.
$ lua -v
$ luajit -v
$ luarocks --version
Setup project#
1. Bootstrap.
$ mkdir my-lua && cd my-lua
$ luarocks init # creates rockspec, ./lua_modules
2. Add dependencies.
$ luarocks install --tree=lua_modules luasocket
$ luarocks install --tree=lua_modules dkjson
3. Lay out the source.
my-lua/
├── my-lua-dev-1.rockspec
├── lua_modules/ # local rocks tree
├── src/
│ └── my_lua/
│ └── init.lua
└── spec/
└── my_lua_spec.lua # busted tests
4. Run.
$ eval $(luarocks path --tree=lua_modules)
$ lua src/my_lua/init.lua
Common Tasks#
Run a one-liner.
$ lua -e 'print("hello")'
Install a rock locally to a project tree.
$ luarocks install --tree=lua_modules <name>
Use LuaJIT instead of PUC Lua.
$ luajit script.lua
Test which Lua the operator is on.
$ lua -e 'print(_VERSION, jit and jit.version)'
References#
Tooling for the build / package / test toolchain.