Does luarocks management have "./node_modules" equivalent for projects? - lua

In NodeJS/NPM, you can create a package.json and run npm install to install all your dependencies in a folder within your project: ./node_modules. (A project can be an app or another module/package.)
Ruby also has a "bundler" system (using a .bundle file) that keeps track of gems specific to a dir (ie project).
Does LuaRocks have similar conventions? Or is it recommeneded to install everything to /usr or $HOME?
So far I've been able to get similiar functionality, but I have to create a custom LuaRocks config file and specify --tree=my_local_lua_rocks_dir every time I want to install a rock. Granted, I can always create a bash script. The point is that it seems I'm going against a convention.

It is possible to install rocks into a directory under the current directory, using the --tree flag:
luarocks install --tree ./lua_modules lpeg
And then you have to configure your package.path and package.cpath variables in Lua (settable via LUA_PATH and LUA_CPATH environment variables) so it finds the modules installed inside it. There are several ways to do this conveniently: this tutorial explains how to do it, with more examples.

Instead of using Vert, I've decided to just edit the LuaRocks config file:
In /etc/luarocks/config.lua :
rocks_servers = {
[[http://rocks.moonscript.org/]],
[[http://luarocks.org/repositories/rocks]]
}
rocks_trees = {
[[/usr/local]],
[[./my_dir]]
}
./my_dir is relative to the pwd you're in, not to the location of the config file. Of course, change my_dir to whatever you want.
"The order of the rock_trees matters: When installing rocks, LuaRocks tries to pick a location to store the rock starting from the bottom of the list; when loading rocks in runtime, LuaRocks scans from the top of the list." From: http://luarocks.org/en/Config_file_format
Then in your .bashrc:
eval `luarocks path`
export PATH=$PATH:my_dir/bin
However, for certain commands you now have to specify the tree or it will give you a confusing error:
luarocks make --tree=my_dir

Related

Warning: Could not find Lua 5.3 in PATH - When Trying to Install Gumbo library with Luarocks

When writing luarocks install gumbo
In the location/directory of my luarocks file in cmd, I am getting the following error
Warning: Could not find Lua 5.3 in PATH.
Modules may not install with the correct configurations. You may want to specify the path prefix to your build of Lua 5.3 using --lua-dir
Installing https://luarocks.org/gumbo-0.5-1.src.rock
Error: Failed finding Lua library. You may need to configure LUA_LIBDIR.
I've added lua53.exe to the same directory, and added the file both to my user variables and system variables in control panel.
Not sure if worth mentioning, but when running lua53.exe and trying to use luarocks install gumbo from there,
the lua53 cmd-like window responds with stdin:1: syntax error near 'install'
I was hoping to do some web scraping with lua, and later on building a World of Warcraft addon that utilizes gumbo to show certain helpful information within the WoW client, but I can't seem to even get the most basic stuff to work...
Setting up LuaRocks on Windows is annoying and I'm not familiar with it myself. If you added both the LuaRocks and Lua 5.3 Windows binaries (Executables and Includes) to your Path system variable:
luarocks path prints the commands for setting up the LUA_PATH and LUA_CPATH system variables.
The config.lua file tells you what your variables.LUA_LIBDIR value is. You can check it with luarocks config. For me that file would be in:
C:/Users/Ketho/AppData/Roaming/luarocks/config-5.3.lua
otherwise you can create an empty file there and put in this line to point it to wherever your Lua folder is:
variables.LUA_LIBDIR = "C:/lua-5.3.5_Win32_bin"
variables.LUA_INCDIR = "C:/lua-5.3.5_Win32_bin/include"
As for using gumbo to show information within WoW, the addon environment is sandboxed. Unless you meant you just want to get the data to hardcode into your addon.

Is there a way for a Lua script installed with Luarocks to find its installation prefix at run time?

Suppose that I a have a Luarocks package named foo, which installs an executable called myscript. When myscript runs, is there a way for it to know the path to the Luarocks installation prefix where foo is installed?
In particular, I would like to know if there is a way for myscript to access data files that have been copied to the installation prefix with build.copy_directories.

Where are the modules installed using luarocks

I am trying to require a module I downloaded using luarocks using
require "lualogging"
but lua (and I!) cannot find where this module was downloaded to. Here is what I did
I have used apt-get to install luarocks, and then I ran
sudo luarocks install lualogging
I then ran
luarocks list
and received the following output
Installed rocks:
lualogging
1.3.0-1 (installed) - /usr/local/lib/luarocks/rocks
luasocket
3.0rc1-1 (installed) - /usr/local/lib/luarocks/rocks
Natural this led me to believe that lualogging was located in /usr/local/lib/luarocks/rocks, but running this command
find /usr/local/lib/luarocks/rocks "lualogging.lua"
returned nothing. What am I doing wrong here? This may be related, but I cannot find what my LUA_PATH environment variable is so it may be that it was never set? I'd like to be able to run require "lualogging" from any file regardless of where it is located in the filesystem, and then log to my heart's content. But I can't even find where lualogging.lua exists...
Run luarocks show lualogging. It will list all modules and where they are.
It should be
require "logging"
not
require "lualogging"

Homebrew installed to home directory - how to link to libs in autoconf?

Not sure if this belongs on here or SuperUser, but here goes:
I have Homebrew installed in my $HOME/opt/homebrew dir (I'm pretty religious about isolation for user accounts - yes, I'm one of THOSE people). In any case, Homebrew doesn't install to /usr/local/. It works fine because I added Homebrew to the head of my personal path in .bashrc.
I'm now using autoconf. I'm a C newb. I have a configure.ac that checks for Apache Portable Runtime. It does the --install to generate a ./configure just fine. When I run ./configure, it doesn't find it - probably because it's not looking where Homebrew installed it.
I assume I have to provide arguments to the ./configure script setting the includedir and libdir. But it doesn't work. What is the right way to link to these Homebrew libs?
For posterity:
In configure.ac, I use the PKG_CHECK_MODULES macro. This assumes, of course, that you have pkg-check installed, which I do via Homebrew.
PKG_CHECK_MODULES(GLIB2, glib-2.0, [], [AC_MSG_FAILURE([glib-2.0 is not installed])])
The macro above sets a group of variables for use in the autoconf and automake files prefixed with GLIB2.
I use this in the Makefile.am thus:
bin_PROGRAMS = <myprogram>
<myprogram>_SOURCES = \
main.c
<myprogram>_CFLAGS = ${GLIB2_CFLAGS}
<myprogram>_LDADD = ${LIBS} ${GLIB2_LIBS}
It's really rather straightforward if you use pkg-config. You can even package your own libs and install them for use that way, linking them in place with Homebrew.

Lua: Install a rock using luarocks from a locally installed rock (or from a .zip/.tar.gz)

I hunted around but I couldn't determine if this is possible.
Basically, http://luarocks.org is down, and I already have a copy of luafilesystem installed on another machine locally here. With Ruby, it's possible to cross install ruby gems using the 'gem' command locally. I'm wondering if the same is possible with rocks and luarocks.
Is there any way to 'cross-install' a rock (for instance, luafilesystem), by using another local installation of that rock?
Something like:
luarocks install //10.0.1.123/machine/path/to/luafilesystem/on/other/machine
is what I'd like to be able to do.
UPDATE: I'd even be happy with how to install a rock from the .tar.gz or .zip, for instance, if I downloaded one of the images from this location (in the case of LuaFileSystem).
In which case, the 'source' for the install would / could be local to the machine, rather than remote (and wouldn't necessarily already be installed as a rock).
If you have the source zip, you can unpack it and point luarocks to the the rockspec file. Here is how I installed 'busted' from source.
git clone https://github.com/Olivine-Labs/busted.git
luarocks install busted/busted-1.3-1.rockspec
Or install it directly from source
cd busted
luarocks make
LuaRocks has a pack subcommand that will create a binary rock (a zip file containing all files for an installed module). You can use that binary rock to install the same module on another computer, given that the architecture matches.
E.g.
luarocks pack luafilesystem
produces luafilesystem-1.6.2-2.linux-x86_64.rock on my machine, and
luarocks install luafilesystem-1.6.2-2.linux-x86_64.rock
will reinstall luafilesystem with no internet connection necessary.
If Someone want an installation from the local source rock.
Just do this:
cd /path/to/source-rock
luarocks make source-rock.rockspec
NOTE:
Use make instead of install. The reason is here (quoted below).
LuaRocks offers this:
make Compile package in current directory using a rockspec.
install Install a rock.
However, install does not utilize the present make. It tries
to download and recompile the same package from the server instead
of the one I customized locally.
Any way round this?
The make command will actually build and install your customized
rockspec. The poor naming choice causes confusion every now and then,
I know.

Resources