Where are the modules installed using luarocks - lua

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"

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.

Missing core.lua installing redis-lua for lua5.1

I'm trying to install a redis client for Lua5.1, any client will do.
I installed redis-lua(https://github.com/nrk/redis-lua)
and
LuaSocket(http://w3.impa.br/~diego/software/luasocket/),
But when I try to get a "redis.connect" in my lua script, it says "could not find module "socket.core" .
And I find that there is no core.lua under /usr/local/share/lua/5.1/socket directory, how should I solve this?
p.s. I'v tried many redis clients for lua, and because I'm not familia with lua and luarocks, non of them works, always missing some dependencies that I cannot find, or got error when compiling with gcc.

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

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

Installing ejabberd-websockets module in Mac OSX

I have downloaded ejabberd and even done a :
sudo port install ejabberd
After this, I am trying to install the ejabberd-websocket module from here : https://github.com/superfeedr/ejabberd-websockets
However, try as I might I am not able to install it by issuing :
./build.sh
This is the error that I am getting :
Recompile: src/mod_websocket
src/mod_websocket.erl:22: can't find include file "ejabberd.hrl"
src/mod_websocket.erl:23: can't find include file "jlib.hrl"
src/mod_websocket.erl:36: undefined macro 'DEBUG/2'
src/mod_websocket.erl:16: function process/2 undefined
src/mod_websocket.erl:14: Warning: behaviour gen_mod undefined
src/mod_websocket.erl:95: Warning: function validate_origin/1 is unused
src/mod_websocket.erl:171: Warning: function build_stream_end/0 is unused
I even have erlang as I installed it via macports. However, I am not able to install the module.
I am using Mac OSX Mountain Lion.
Any help would be great.
I can help you get around some of your issues. At least in my case, ejabber installed into a different location than this project expects. If you open Emakefile you will see it tries to include /usr/lib/ejabber/include, but in my case I had to remove the /usr part so it is just /lib/ejabberd/include. It may not be exactly the same in your case, but you just need to find your ejabber installation and make sure those directory paths match.
My Emakefile for reference
{'src/mod_websocket', [{outdir, "ebin"},{i,"/lib/ejabberd/include"},{i,"/lib/ejabberd/include/web","src"}]}.
{'src/ejabberd_xmpp_websocket', [{outdir, "ebin"},{i,"/lib/ejabberd/include"},{i,"/lib/ejabberd/include/web","src"}]}.
{'src/ejabberd_websocket', [{outdir, "ebin"},{i,"/lib/ejabberd/include"},{i,"/lib/ejabberd/include/web","src"}]}.
I also had to modify the build.sh script, but I don't think it solved any of my problems
#!/bin/sh
erl -pa /lib/ejabberd /lib/ejabberd/include /lib/ejabberd/ebin -pz ebin -make

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