Lua package managers and integration with ZeroBrane Studio

Lua ecosystem has two package managers: LuaDist and LuaRocks. Both managers allow users to install Lua and C modules and work on Windows, Mac OS X and Linux, but have some important differences in how they operate, which I'll briefly go over.

LuaDist:

  • Unified build system for all modules based on CMake.
  • Mixed binary/source distribution that allows to use whatever dependency is available in the repository.
  • Everything is stored in git (using github as host) including the repository manifest. Tags are used for versions and branches for binary distributions.
  • Provides "batteries included" binary distributions (as a successor to Lua for Windows).
  • Relies on few Lua modules (luasocket, lfs, lua-git) for its implementation.
  • Allows for building the modules manually without using LuaDist.
  • Can be used from a command line or as a library (local ld = require "dist"; ld.install("luaexpat"))
  • Uses dist.info files for package specification information (mostly for dependency tracking, no build information).
  • Provides support for packaging modules for distribution.
  • Includes about 260 projects (as of November 2013; based on the number of sub-modules in the repository).
  • Includes a good number of pre-compiled binaries for Windows, but many for outdated module versions.

LuaRocks:

  • Supports local and remote repositories.
  • Distributed as a Lua scripts without dependencies, but relies on Unix tools for module deployment and installation.
  • Uses .rockspec files as a package specification file.
  • Uses "native" build instructions for each rock.
  • Includes rocks for 330 projects (as of November 2013).
  • Have several repositories: main one with manual curation and rocks.moonscript repository that supports (non-curated) rock submission and download statistics.

As we are talking about Lua module distribution, I'll also mention a nice project of Pierre Chapuis: lua toolbox. It provides a list of modules with short descriptions and their endorsement by various users (along with a simple tagging mechanism).

Both systems are easy to use as command-line tools. When you have one of the package managers installed, it's a matter of running luarocks install module or luadist install module commands to get the modules you need (assuming you have the tools available and don't run into compilation issues). It is certainly possible to setup LuaDist and LuaRocks to deploy modules to the directories you need and make those directories available to your project (see for example this nice write up by Thijs Schreijer on Setting up Lua installation on Windows using Lua Rocks and ZeroBrane Studio), but I'd prefer to have something simpler for users who may be new to programming and Lua.

I teach a semester long computer science class at a local high school during summer (using Lua and ZeroBrane Studio) and sometimes want to install Lua modules like penlight to my students' computers and use them from ZeroBrane Studio. I have 18 students using their own laptops running different systems and want to be able to say "install penlight" and then make "require 'pl.strict'" to work in their Lua scripts. The coming version (v0.40) of ZeroBrane Studio (and the current master branch) integrates with LuaDist and allows you to do just that.

ZeroBrane Studio now includes LuaDist module dependencies and if you install luadist plugin, you will be able to run LuaDist commands in the Local console of ZeroBrane Studio:

> luadist.install('penlight')
Running 'install' for Lua 5.1 in '...\luadist\5.1'.
Downloading repository information...
Finding out available versions of penlight...
 - trying another candidate due to: Error when resolving dependencies: Error when retrieving the info about 'penlight': Error fetching package 'penlight-1.2.1' from 'git://github.com/LuaDist/penlight.git' to '...\luadist\5.1\tmp': Binary version of module not available and using source modules disabled.
Getting penlight-1.1 (binary)...
Finding out available versions of luafilesystem...
Getting luafilesystem-1.6.2 (binary)...
Finding out available versions of alien...
Getting alien-0.7.0 (binary)...
Finding out available versions of libffi...
Getting libffi-3.0.9 (binary)...
Installation successful.
Completed in 25 second(s).

> require 'pl.strict'
{closed_module = function() --[[..skipped..]] end, make_all_strict = function() --[[..skipped..]] end, module = function() --[[..skipped..]] end} --[[table: 0x03e4b790]]

You can then use penlight modules from the console or from your Lua scripts. Some of the other commands you may use:

  • luadist.install('lpeg') -- install lpeg binary version for Lua 5.1 on Windows/OSX (if available) and source version on Linux.
  • luadist.remove('lpeg') -- remove lpeg module (for Lua 5.1)
  • luadist.install('lpeg', {source = true}) -- install lpeg source version (will likely get Lua as well)
  • luadist.install('lpeg', {source = true, debug = true}) -- include all cmake commands and verbose output
  • luadist.install('lpeg', {source = true, verbose = true}) -- include verbose output, but not cmake commands
  • luadist.install(5.2, 'lpeg', {source = true}) -- install lpeg source version for Lua 5.2 (will likely get Lua as well)
  • luadist.install('lua-5.1.3') -- install specific Lua version; you may need to remove the current one first using luadist.remove('lua-5.1.5') command.

You can also try other LuaDist commands show, info, search, tree, and so on. All commands that don't include Lua version will work with default Lua 5.1 interpreter and if you include 5.2, the commands will use 5.2 interpreter. Modules for Lua 5.1 and Lua 5.2 are installed into different folders, so you can use both interpreters without conflicts.

If you get an error during installation, try running the same command with debug=true option to see what the actual cmake error is.

What works:

  • Windows binary installs (where available) and source installations using Lua 5.1 and Lua 5.2. Tested with cmake 2.8.10+ and mingw-tdm.
  • OSX source installs using Lua 5.1 and Lua 5.2 (configured to build universal binaries); you'll need CMake 2.8.10+.
  • Linux source installs using Lua 5.1 and Lua 5.2 (both 32bit and 64bit)

What doesn't work:

  • Windows binary install using Lua 5.2 (this retrieves the same module as for Lua 5.1, which doesn't load)
You should get a copy of my slick ZeroBrane Studio IDE.

2 Comments

Hello,

I installed the luadist package but when I try to run luadist.install('penlight') at the ZeroBrane console, I get an error that says, among other things, "module 'dist' not found" and it shows that it's looking for lib\lua\lua/dist.lua

Any idea what might be going on here?

Thanks,

Steve

Hi Steve, thank you for reporting. There was indeed an issue and it's been fixed in luadist and in ZBS. If you are using the latest version of ZBS (0.90 or the master branch), you'll need to download the updated version of luadist and refresh the ZBS code from the master branch. My apologies for the inconvenience. Paul.

Leave a comment

what will you say?
(required)
(required)
Close