Finally I got around to trying out LuaRocks by installing it in my system and also creating a rockspec to add my simple Lua module in the LuaRocks collection. Here are some tips I picked up:
Create and upload a rock to Luarocks
The major steps are as follows:- Write the rockspec file as explained here
- Save the file with the name as lowercase package and version example many2one-1.14.11.12-3.rockspec. Here 1.14.11.12 is the version number and -3 is the rockspec number in case I just change something in the rockspec. This should match the version mentioned in the rockspec.
- Create a rock using luarocks and the rockspec described below
- Test the rock as described below
- Upload the rock and rockspec to Luarocks
Creating a rockspec
The instructions are very clear and easy to follow here. I had my script in github. One thing I did wrong was to provide an https url for github and then luarocks gives an error in installation. I had to make the URL start withgit://
that fixed it. Creating a rock
I then ran the command:And it packed the files in a rock file.
NOTE: When I put the rockspec in a subdirectory like I did in tableUtils I had to run the command from the repository root directory like this:
It created a rock in the repository root. Also note in the rockspec the module file path has to be given from the repository root.
Then I simply uploaded the rockspec and rock files on LuaRocks and my 1st Lua script is available through LuaRocks!
Testing a rock
Before you upload to the LuaRocks server it is a good idea to test the rock. This can be done by simply going to the folder having the rock and typing:If that works and installs the rock then you can upload the rockspec and rock file to the LuaRocks server.
Installing LuaRocks
Installing LuaRocks was not as straightforward. Here are some notes to help anyone who needs some extra help:Install Lua
If you want the non default version of Lua (LuaRocks default is 5.1 and I wanted to go with 5.2.3) then you need to have it installed at a path in the following structure:Download LuaRocks
This page gives the download linkInstall LuaRocks
Installation on windows is done by running install.bat batch file in the downloaded archive. Use install /? for all the command line options. Open a command terminal with administrator privileges. The command I used was:Make sure MinGW is installed and is in the path of the shell from which you execute the above command.
/LV specifies my lua version
/LUA specifies my Lua root path which is the root directory path of the hierarchy I described above
/MW specifies I want to use mingw as my build system
/P specifies where I want the LuaRocks to be installed. LuaRocks creates the last directory (in the above case 'luarocks') and installs there.
/NOADMIN The installer requires admin priviledges. If not available it will elevate a new process. Use this switch to prevent elevation, but make sure the destination paths are all accessible for the current user.
Now the problem with this installation is that the rocks installed are not in my Lua Path. So I need to have package.path and package.cpath updated in my Lua executable so it points to the directory where LuaRocks installs its rocks.
At the end of the installation LuaRocks displays a list of paths that must be updated in the Lua executable and the command environment. For guidance on how to update the paths in the Lua executable directly see here. I simply took the text from the LuaRocks output and converted to a batch file which looks like this:
NOTE Here in the 1st Path statement I placed the luarocks bin path in front of all the previously defined paths so that when this batch file is run it places the lua executable in the luarocks installation 1st in line to run when lua is called from the command line.
I simply run this batch file to initialize my LuaRocks environment. I did not add them permanently since I have a separate Lua setup system which I use.
After the install process is done. It is best to run:
This package is needed for uploading rockspecs and may be used by LuaRocks at other times as well.
Installing a complicated rock on your LuaRocks setup
Here I will list out the steps to install LuaSec using LuaRocks. The installation is not straightforward since it depends on openssl and LuaSec rockspec does not compile it and generate its dependencies. So you need to compile openssl separately and then place the dependency files in the LuaRocks tree and then run the LuaSec install. Here are the steps:- Download and compile openssl. If you are not able to do that refer here for instructions and a script on how it can be done on windows
- Copy the include directory (named openssl) containing all the include files of openssl sources into the rootPath\include directory.
- Copy the generated dll files (libeay32 and ssleay32) into the rootPath\bin directory
- Copy the generated dll files (libeay32 and ssleay32) into the path of your compiler libraries. I was using MinGW so I placed them at C:\mingw\lib directory. To see which directories mingw compiler is looking at do:
- Now run:
- It should be able to install the rock now.