-
Notifications
You must be signed in to change notification settings - Fork 0
Using LuaRocks
So, you followed the installation instructions (either on Unix or Windows) and now you have LuaRocks installed in your machine. Now you probably want to install some rocks (packages containing Lua modules) and use them in your Lua code.
For LuaRocks to function properly, we have a quick checklist to go through first:
LuaRocks installs some command-line tools which are your interface for managing your rocks: luarocks and luarocks-admin. Make sure the directory where they are located is in your PATH -- the exact location depends on the flags you gave when installing LuaRocks.
Run luarocks to see the available commands:
luarocks
You can get help on any command by using the help command:
luarocks help install
Installing packages is done by typing commands such as:
luarocks install luasocket
Most installations will feature two rocks trees:
To use modules installed with LuaRocks, all you need to do is make sure they are found by Lua's module loading mechanism. The exact location depends on your installation flags, and how to set up the Lua modules path depends on your Lua interpreter and your application: you can use the LUA_PATH and LUA_CPATH environment variables, or update the value of thepackage.path and package.cpath variables from Lua code. This can't be any more vague.
If you installed the Lua interpreter bundled with LuaRocks on Windows, or if you built both Lua and LuaRocks on Unix with the default paths, the default library path settings will be already appropriate.
If your Lua paths are not already set correctly, you can use the following command:
luarocks path --bin
It will print commands suitable for your platform for setting up your environment.
If you want to make use of LuaRocks' support for multiple installed versions of modules, you need to load a custom package loader: luarocks.loader.
You should be able to launch the Lua interpreter with the LuaRocks-enabled loader by typing:
lua -lluarocks.loader
Alternatively, you can load the LuaRocks module loader from Lua by issuing this command:
require "luarocks.loader"
If your system is correctly set up so that this command runs with no errors, subsequent calls to require() are LuaRocks-aware and the exact version of each module will be determined based on the dependency tree of previously loaded modules.
Besides modules, rocks can also install command-line scripts. The default location of this directory (unless you configured your local repository differently) is /usr/local/bin for system-wide installs and ~/.luarocks/bin for per-user installs on Unix and %APPDATA%/luarocks/bin on Windows -- make sure it is in your PATH as well.
If you use the --bin argument in luarocks path, it will also print the appropriate PATH configuration:
luarocks path --bin
When you use LuaRocks to install a package while you aren't root, the package will get installed in $HOME/.luarocks/ instead of the system-wide (by default, /usr/local/) and become only available for you. Moreover Lua doesn't know with its default setup that packages can be available in the current user's home. If you want to install a package available for all users, you should run it as superuser, typically using sudo.
For example:
sudo luarocks install stdlib
After that, some files may not have correct permissions. For example, if /usr/local/share/lua/5.1/base.lua is only readable by root user, you should at least set them to readable for all users (chmod a+r or chmod 644). For example:
cd /usr/local/share/lua/5.1 sudo chmod a+r *
Because rocks are generally available in the repository as source rocks rather than binary rocks, it is best to have a C compiler available.
On Windows, MinGW and Microsoft compilers are supported. The compiler should be in the system path, or explicitly configured in the LuaRocks config files. On Windows systems, one way of getting the compiler in the system path is to open the appropriate command prompt as configured by your compiler package (for example, the MSVC Command Prompt for Visual Studio).
Note that for compiling binary rocks that have dependencies on other libraries, LuaRocks needs to be able to find external dependencies.