Neopallium / lua-zmq

Lua zeromq2 binding
http://github.com/Neopallium/lua-zmq
MIT License
153 stars 36 forks source link

attempt to index global index 'zmq' (a nil value) #22

Closed dustingooding closed 12 years ago

dustingooding commented 12 years ago

I'm trying to use your Lua bindings for ZMQ, but am not having much luck.

I'm running Ubuntu 11.10 (up to date). I installed ZMQ from the Ubuntu package (sudo apt-get install libzmq-dev libzmq1). Then I used the instructions here to install lua-zmq using CMake (as I didn't have luarocks installed, yet). I didn't see any errors during the install.

I copy-pasted an example from zeromq.org (http://zguide.zeromq.org/lua:interrupt) but it fails to execute. The example, as written, gives the following output:

$ lua -i interruptTest.lua 
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
lua: interruptTest.lua:7: module 'zhelpers' not found:
    no field package.preload['zhelpers']
    no file './zhelpers.lua'
    no file '/usr/local/share/lua/5.1/zhelpers.lua'
    no file '/usr/local/share/lua/5.1/zhelpers/init.lua'
    no file '/usr/local/lib/lua/5.1/zhelpers.lua'
    no file '/usr/local/lib/lua/5.1/zhelpers/init.lua'
    no file '/usr/share/lua/5.1/zhelpers.lua'
    no file '/usr/share/lua/5.1/zhelpers/init.lua'
    no file '/opt/ros/electric/stacks/orocos_toolchain/ocl/lua/modules/zhelpers.lua'
    no file './zhelpers.so'
    no file '/usr/local/lib/lua/5.1/zhelpers.so'
    no file '/usr/lib/x86_64-linux-gnu/lua/5.1/zhelpers.so'
    no file '/usr/lib/lua/5.1/zhelpers.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    interruptTest.lua:7: in main chunk
    [C]: ?

Sure enough, "zhelpers.h" is nowhere to be found on my machine. I don't blame lua-zmq for this. So, I comment out the require"zhelpers" line and run again.

$ lua -i interruptTest.lua 
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
lua: interruptTest.lua:9: attempt to index global 'zmq' (a nil value)
stack traceback:
    interruptTest.lua:9: in main chunk
    [C]: ?

This, I believe is a problem. Lua had no problem with require"zmq", but it did when I attempt to use zmq functionality. What am I missing?

For completeness, I installed the Ubuntu package for Lua's Python bindings (sudo apt-get install python-zmq) and attempted running the companion example (http://zguide.zeromq.org/py:interrupt), and I had no trouble. So, this tells me ZMQ is installed correctly and bindings work.

I went to reinstall lua-zmq using Ubuntu's package for luarocks (sudo apt-get install luarocks). I used the first instruction (sudo luarocks install https://github.com/Neopallium/lua-zmq/raw/master/rockspecs/lua-zmq-scm-1.rockspec), but because I'm behind a firewall, I'm unable to use the git:// protocol to access github.com. So, I just downloaded the rockspec, changed the url line:

package = "lua-zmq"
version = "scm-1"
source = {
        url = "https://github.com/Neopallium/lua-zmq.git",
}
...

But, even that fails.

$ sudo luarocks install lua-zmq-scm-1.rockspec 

Error: Error fetching file: Failed downloading https://github.com/Neopallium/lua-zmq.git

I really would like to use your software, but I'm just having the worst luck. Any help?

dustingooding commented 12 years ago

Forgive me. I'm still new to Lua.

Apparently I was supposed to use zmq = require"zmq", not just require"zmq".

And apparently luarocks doesn't support the smart http protocol.

Neopallium commented 12 years ago

the zhelpers.lua file is located at: https://github.com/imatix/zguide/blob/master/examples/Lua/zhelpers.lua

When running the Lua examples from the guide it is best to download all the *.lua files from this folder: https://github.com/imatix/zguide/blob/master/examples/Lua/

Older releases of lua-zmq had registered the module as the global "zmq". But it seems the Lua community is recommending that module don't create globals and just return a value during initialization.

New code should do: local zmq = require"zmq"

For now I have change lua-zmq to still create a global for the module, until I have time to update the examples in the zmq guide.

When using a "https://" url luarocks doesn't know that it is a git repository. Maybe report this issue to the luarocks mailing list: http://luarocks.org/en/Mailing_list since other people behind firewalls may have the same problem.

LuaRocks should add support for using an http proxy for accessing repositories from behind firewalls: http://stackoverflow.com/questions/128035/how-do-i-pull-from-a-git-repository-through-an-http-proxy