Until I can spec this out fully, I’m just going to quote my original blurb:
Even though Lua was intended as an embedded language, its standalone interpreter makes testing modules much easier. However, testing against multiple versions of Lua isn’t exactly straightforward. luarocks, a module manager similar to Ruby Gems, hard-codes the path to Lua not only in config files but the
luarocksscript itself. Worse, Lua’s module loader assumes Lua is installed in/usr/localon Unix systems. Users can override the search path in the standlone interpreter by setting an environment variable, and within the interpreter one can changepackage.pathandpackage.cpath. It might be simpler, though, to change those defaults to the directory in which Lua is installed – found once in luaconfig.h – and then compile the interpreter.Following in the footsteps of rvm and especially rbenv, this Lua Environment Version Manager thing would let developers install multiple versions of Lua in their home directories, set a default, type
luaat the command line, and it would Just Work. Likewise installed Lua Rocks would Just Work.
…
A fully functional version would download Lua versions, tweak the default load path, compile Lua, and install it in a version-specific directory. Subcommands would set the default version, list all installed versions, uninstall a version, and so on.
luaenvneed not support every facility ofrbenvthough. A user default version overriden by an environment variable would suffice. (Directory-specific configuration would be nice to have, though.)luaenvwould also need only a few “shims”, mainly forlua,luac,luarocks, andluarocks-admin, although conceivably a Lua Rock could include an executable script.
Update 2024-11-08
There are at least three projects that maintain multiple Lua versions:
-
https://github.com/cehoffman/luaenv
A clone of
rbenvbut altered for Lua. -
https://github.com/spacekookie/luaenv
Creates virtual environments similar to
rvmorvert, but, and I quote,luaenv doesn’t clutter your home directory with more
.folders. It uses unix standards where things should be stored -
https://github.com/DhavalKapil/luaver
Installs, uninstalls, and switches between versions of Lua, Lua Rocks, and LuaJIT.
Comparing the features of these three:
| luaenv #1 | luaenv #2 | luaver | Feature |
|---|---|---|---|
| X | Uses rbenv/pyenv commands |
||
| X | X | Can specify global default version | |
| X | Can specify version local to a directory. | ||
| X | Can specify version local to a shell environment. | ||
| X | Creates virtual environments | ||
| X | X | Supports the sh/bash/dash shell |
|
| X | X | Supports the fish shell |
|
| X | Modified in the last year. | ||
| X | Available through Homebrew |
From this superficial comparison, it looks like luaenv #1 is closest to what I envisioned … but it lacks versions, so it’s not available through Homebrew, my package manager of choice.
So I’m installing luaver through Homebrew and luaenv #1 through git.
I’ll tinker with each one and see which I like better.
As for luaenv #2 … I don’t use the fish shell, and I can’t get it to
work even if I start a fish shell. So that one’s clearly out.
If I get bored maybe I’ll port it to sh/bash/dash. I like that it
uses either $HOME/.local/** or an “env” directory to create virtual
environments, which may be more appropriate for lightweight Lua than, say,
Python.
Update 2024-11-09
I found a fourth one:
-
https://github.com/aconbere/vert
Creates virtual environments just like Python.
It’s a Lua program installed through LuaRocks. That’s exactly what I was
talking about above, although due to a quirk in LuaRocks I can’t get it
to not import the LuaRocks I’ve installed in my home directory.
So either I stick with luaver and vert exclusively,
or I live with possible contamination of virtual environments.
Speaking of, luaenv #1’s support for LuaRocks is old and buggy, so I’m
less enamored of it. luaver seems to install multiple copies of the same
luarocks distribution, but at least it works. Not that luaver doesn’t
have its quirks: you have to specify version numbers exactly, and its technique
of rewriting the PATH variable seems a little fragile, but it works. Mostly.