Skip to content

LuaRocks Support

Cody Tilkins edited this page Feb 25, 2021 · 2 revisions

Table of Contents

Windows

LuaRocks presents this problem: it lacks the ability to use arg AND tuple for arguments (`arg or {...}`). LuaConsole gives you the option to use arg and tuple for arguments using the -T switch as a compatibility layer to existing Lua code and to avoid conforming to a standard if you don't want to. By default you do not need this -T switch, just beware if you use it.

LuaRocks requires an initial installation of Lua. The version doesn't matter, as they are all interchangeable. Acquire Lua from https://www.lua.org/ftp/(lua.org). This version of Lua will be replaced by LuaConsole and your wanted build of lua will still be used. You should use the generated .dll from LuaConsole bin folder from doing `build.bat driver lua-x.x.x` as that lua dll is then used to link with other dlls such as the common `core.dll`.

Replace the x's below name with your version.

  1. Download the latest LuaRocks `git clone https://github.com/luarocks/luarocks`
  2. `cd` into the git root directory
  3. Run `install /F /MW`, installs to `C:\Program Files (x86)\LuaRocks` for the pre-packaged version, add `/L`
    1. If `/L`, 'Delete all installed lua51 executables, MSVCRT stuff, manifest, and lua51.dll, and `\include\*`'
  4. Add in your own version of lua5x.dll liblua5x.dll.a to the root, add all needed lua headers into `\include\`
  5. Rename `config-5.x.lua` to match your version (config-5.1 (5.1 for jit), config-5.2, etc)
  6. Edit `config-5.x.lua`
  7. Edit `lua\luarocks\site_config.lua`
  8. Edit `luarocks.bat` to point to your `luaw.exe` executable, and pass the arguments correctly
  9. Ensure LuaRocks is in your %PATH%. Check out using.bat so you can use `using %luarocks%` to keep environment variables clean.
  10. Ensure LuaRocks packages are in %LUA_PATH% and %LUA_CPATH% or you won't be able to use downloaded rocks packages without setting `package.cpath` or `package.path` in-lua. Try the command `luarocks.bat path --bin` if you are wondering how I made the batch script below. This doesn't work with self-contained installations, edit it as necessary. This will have to be run every time you use LuaRocks unless you make it final by setting it in your environment variables. (Which is why I recommend `using.bat` above). Keeps everything clean and organized.

config-5.x.lua

variables = {
	CC = "gcc"; -- your gcc name, mingw32 uses mingw32-gcc and the like
	LD = "gcc"; -- your gcc name
	LUALIB = 'lua-x.x.x.dll'; -- name of added library
	-- if a MSVCRT-like variable exists here, delete it
}

site_config.lua

site_config.LUA_INTERPRETER=[[luaw]] -- name of lua interpreter exe
site_config.LUAROCKS_UNAME_S=[[MINGW]]

luarocks.bat

REM I keep my `luaw.exe` in my `%path%`, this should be on line 12 or something
"luaw" "C:\Program Files (x86)\LuaRocks\luarocks.lua" "-n" %*

luarocks_patch.bat

@echo off

set lua_ver_str=5.3
set userdir=%HOMEDRIVE%%HOMEPATH%
set luarocksdir=C:\Program Files (x86)\LuaRocks


set LUA_PATH=%userdir%\AppData\Roaming/luarocks/share/lua/%lua_ver_str%/?.lua;%userdir%\AppData\Roaming/luarocks/share/lua/%lua_ver_str%/?/init.lua;%luarocksdir%\systree/share/lua/%lua_ver_str%/?.lua;%luarocksdir%\systree/share/lua/%lua_ver_str%/?/init.lua;%luarocksdir%/lua/?.lua;%luarocksdir%\lua\?.lua;%luarocksdir%\lua\?\init.lua;

SET LUA_CPATH=%userdir%\AppData\Roaming/luarocks/lib/lua/%lua_ver_str%/?.dll;%luarocksdir%\systree/lib/lua/%lua_ver_str%/?.dll;%windir%\system32\?.dll;%windir%\system32\..\lib\lua\%lua_ver_str%\?.dll;%windir%\system32\loadall.dll;.\?.dll

set PATH=%userdir%\AppData\Roaming/luarocks/bin;%luarocksdir%\systree/bin;%luarocksdir%;%path%

Linux

    • Not tested yet, feel free - its just the new shebang**
  1. Download lua version of choice or collect the .so you used to build LuaConsole
  2. Download luarocks latest
  3. cd, in terminal, to luarocks
  4. Run `./configure`, installs to `/usr/local/bin` and `/usr/local/etc/luarocks` and `/usr/local/share/lua/5.x`
  5. Edit `/usr/local/share/lua/5.x/luarocks/core/site_config_5_x.lua`
  6. Edit `/usr/local/bin/luarocks` change shebang

site_config_5_x.lua

local site_config = {}
site_config.LUA_INTERPRETER=[[luaw]] -- name of lua interpreter
...etc...
return site_config

luarocks

#!/bin/sh
":" //# comment; exec /usr/bin/env "luaw" "-n" '$*'