Lua bindings

Neopallium Bindings (latest)

These new Lua bindings add optional support for LuaJIT2's new FFI extension. The bindings will still work with Lua VMs that don't have the FFI extension by falling back to using the standard Lua C API.

Now you can get throughput very close to that of C++ code when running Lua code running under LuaJIT2.

Additional features:

  • zmq.poller which wraps zmq_poll().
  • zmq.threads which make it easy to create threads from Lua that shared a common 0MQ context.

Source Code

https://github.com/Neopallium/lua-zmq

Download build for Windows

Try the LuaJIT 2.0 + zeromq 2.2.0 on Windows 32bit or 64bit:
https://github.com/downloads/Neopallium/lua-zmq/luajit2_zmq2.2_llthreads.zip

Build and installation

ØMQ iteself has to be installed on the system prior to building the Lua binding:

Using LuaRocks 2.0.4.1:

$ sudo luarocks install https://raw.github.com/Neopallium/lua-zmq/master/rockspecs/lua-zmq-scm-1.rockspec

For threads support:

$ sudo luarocks install https://raw.github.com/Neopallium/lua-llthreads/master/rockspecs/lua-llthreads-scm-0.rockspec
$ sudo luarocks install https://raw.github.com/Neopallium/lua-zmq/master/rockspecs/lua-zmq-threads-scm-0.rockspec

With CMake:

$ git clone git://github.com/Neopallium/lua-zmq.git
$ cd lua-zmq ; mkdir build ; cd build
$ cmake ..
$ make
$ sudo make install

Performance

Throughput benchmark using the tcp transport over localhost:
message size: 30 [B]
message count: 100000000

Using send/recv functions running under Lua 5.1.4:
mean throughput: 1577407 [msg/s]
mean throughput: 378.578 [Mb/s]

Using send/recv functions running under LuaJIT2 (git HEAD):
mean throughput: 5112158 [msg/s]
mean throughput: 1226.918 [Mb/s]

Using send_msg/recv_msg functions running under LuaJIT2 (git HEAD):
mean throughput: 6160911 [msg/s]
mean throughput: 1478.619 [Mb/s]

C++ code:
mean throughput: 6241452 [msg/s]
mean throughput: 1497.948 [Mb/s]

Documentation

https://github.com/Neopallium/lua-zmq/blob/master/API.md

Bug Reporting

If you encounter problems please fill a bug report at:

https://github.com/Neopallium/lua-zmq/issues

or write an e-mail to:

moc.mlaerderahs|ybbob#moc.mlaerderahs|ybbob

Alexey Melnichuk bindings

This binding provide C and FFI (pure lua) binding for ZeroMQ >= 3.2.
This bindig does not support ZeroMQ version 2.x.

Additional functions in comparison with lua-zmq:

  • provides more extensive interface (send/receive multipart messages, parameters in context/socket constructors)
  • simple event loop with time events
  • ffi interface is pure Lua
  • support zmq_socket_monitor and recv_event functions to monitoring sockets activity

Source Code

https://github.com/zeromq/lzmq

Build and installation

LuaRocks

OMQ iteself has to be installed on the system prior to building the Lua binding:

$ sudo luarocks install lzmq

or
$ sudo luarocks install lzmq-ffi

For threads support you also should install lua-llthreads2 or lua-llthreads library (version > 1.2):

$ sudo luarocks install lua-llthreads2-compat

or
$ sudo luarocks install lua-llthreads2

or
$ sudo luarocks install https://raw.github.com/Neopallium/lua-llthreads/master/rockspecs/lua-llthreads-scm-0.rockspec

LuaDist

$ sudo luadist install lzmq

or
$ sudo luadist install lzmq-ffi

Install lua-llthreads2 library

$ sudo luadist install lua-llthreads2-compat

or
$ sudo luadist install lua-llthreads2

Performance

This is average for 10 runs on LuaJIT 2.0.1.
ZeroMQ 4.0.1.
Intel Core2 6300 1.86 GHz, Windows XP SP3.
For all modules I use MSVC Express 2010.

Inproc Throughput test:
message size: 30 [B]
message count: 10000

C++ code:
mean throughput: 389.0245 [Mb/s]

Using send/recv functions
mean throughput: 310,1113 [Mb/s]

Using send/recv functions (ffi)
mean throughput: 406,2838 [Mb/s]

Using send_msg/recv_msg functions:
mean throughput: 179,3944 [Mb/s]

Using send_msg/recv_msg functions (ffi):
mean throughput: 297,6132 [Mb/s]

Documentation

http://moteus.github.io/lzmq/index.html
Also you coulde see exampes form OMQ - The Guide.

Bug Reporting

If you encounter problems please fill a bug report at:

https://github.com/zeromq/lzmq/issues

iamaleksey Bindings (older)

Source Code

http://github.com/iamaleksey/lua-zmq

Build and installation

Following command will build and install the binding into appropriate directory. ØMQ itself has to be installed on the system prior to building the Lua binding:

$ make install

Documentation

http://github.com/iamaleksey/lua-zmq/blob/master/API.md

Bug Reporting

If you encounter problems please fill a bug report at:

http://github.com/iamaleksey/lua-zmq/issues

or write an e-mail to:

moc.oknehcsey|yeskela#moc.oknehcsey|yeskela

FAQ

lua crashes when I use 0MQ?

As lua is designed without multi-thread function, the 'lua' binary is linked without -pthread.
Note this is also needed on Linux (See glibc bug report).

  • Download lua source and rebuild it with -pthread
  • Modify lua-5.1.4/src/Makefile: LIBS= -lm $(MYLIBS) -pthread

More details: http://kasicass.blog.163.com/blog/static/39561920108475639702/

Another option is to preload libpthread.so when running Lua:

  • LD_PRELOAD=/lib/libpthread.so lua

This could be added to a wrapper bash script.

Mailing List

Discussions about the LUA language bindings take place on the general zeromq-dev list.