Using LuaRocks with PolypopLive
LuaRocks is a package manager for Lua. It works by downloading, compiling and deploying
Lua modules for use in a Lua environment. By downloading packages and adding them to Lua, you can add a multitude of functions and features to the language to help you build interesting things.
To work with PolypopLive, LuaRocks needs to use the same version of Lua that PolypopLive uses to
ensure compiled modules link to the same Lua library. Let’s see how to set things up.
Setting Up the Environment
To set things up on Windows, let's create a folder where the PolypopLive lua distribution will live.
Download PolypopLive’s Lua distribution zip here
Create the following folder on your C drive:
C:\Users\YOUR_USER_NAME\PolyPop\Dev\luaNext, extract the two folders from the zip into the folder. You should have the following structure:
C:\Users\..\PolyPop\Dev\lua
\bin
\include
Next off, if you haven’t already done so, install Visual Studio Community edition so you'll have access to a C compiler that will be used by LuaRocks to compile Lua modules that use native code.
Next, follow the guide here (https://github.com/luarocks/luarocks/wiki/Installation-instructions-for-Windows) to download and extract LuaRocks. You'll need to download the latest all-in-one package
(legacy Windows package) the article mentions (e.g. luarocks-3.9.0-win32.zip)Once downloaded, extract the zip to a temp folder.
Now open a command prompt into the folder and write the following:
install /lua "C:\Users\YOUR_USER_NAME\PolyPop\Dev\lua"
This will install LuaRocks to "C:\Program Files (x86)\LuaRocks" and configure it to point to the lua distribution
we setup earlier.
You can now delete the temp folder you extracted the LuaRocks package to.
Due to a bug in LuaRocks (encountered with luarocks-3.9.0-win32.zip) you'll need to modify the default
config file so it points to the MD5 checksum tool correctly.
Open "C:\Program Files (x86)\LuaRocks\config-5.4.lua" in a text editor and add the following item within
the variables table:
variables {
...
MD5SUM = [[tools\md5sum]],
}
Finally, open a command prompt to "C:\Program Files (x86)\LuaRocks". You should now be able to install
LuaRocks that are compatible with PolypopLive. For instance, type:
luarocks install luafilesystem
This will download and compile the luafilesystem
module and place its compiled module into “C:\Users\YOUR_USER_NMAE\PolyPop\Dev\lua\lib\lua...”
If using Visual Studio Community edition, LuaRocks should configure the terminal environment it runs in to be able to access the compiler tools. If for some reason it doesn’t, or you are using a different compiler tool, be sure to configure things for a x64 architecture compiling environment. PolypopLive and its Lua distribution is 64-bit so any module compiled for it must be 64-bit as well.
Using LuaRocks Modules With Polypop UIXs
One the LuaRocks module is fully built, you can bundle the module alongside your PolyPop UIX and lua files and load it in the code at the top of your lua file using:
lib = require("lib")
Note that you should omit the file extension for the "require" argument.