iamaleksey / lua-zmq Goto Github PK
View Code? Open in Web Editor NEWLua zeromq2 binding
Home Page: http://github.com/iamaleksey/lua-zmq
Lua zeromq2 binding
Home Page: http://github.com/iamaleksey/lua-zmq
Please provide a tag or an archive for lua-zmq repository, possibly one with the version as numeric value in it.
assert() isn't a function call, it's a macro, and calling it with side-effects is an error. See the first Warning here:
http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_28.html
All the calls like this are bugs:
assert(zmq_term(ctx->ptr) == 0);
After running publisher.lua and subscriber.lua for a while I see that the lua running subscriber.lua is using more and more memory. Is there something that needs to be freed somewhere or is this a genuine leak?
Thanks
I've downloaded and installed zeromq 2.0.10 and the lua binding on both win32 and linux and on both I have the same reult:
client.lua and server.lua start and sit there waiting forever without any sign of life and I use ctrl-c to finish then.
Is this an issue someone else is experimenting ?
I can't get the bindings to work with luajit. Tried to:
gcc -I/usr/local/include/luajit-2.0/ -o zmq.lo -c -pthread -fPIC -Wall -O2 zmq.c
gcc -shared -lzmq -lluajit-51 zmq.lo -o zmq.so
requiring zmq gives the following error:
dlopen(/usr/local/lib/lua/5.1/zmq.so, 2): Library not loaded: libluajit.so
EDIT: Additional compilation flags and prober libluajit renaming are need for Mac OS
ZMQ_PULL/ZMQ_PUSH are not defined in earlier zmq headers (2.0.7)
Hi!
Wonder if you could provide an example similar to https://github.com/Neopallium/lua-zmq/blob/master/examples/ev_subscriber.lua for joyent/libuv?
TIA,
--Vladimir
diff --git a/zmq.c b/zmq.c
index 70ce0d2..1343feb 100644
--- a/zmq.c
+++ b/zmq.c
@@ -119,10 +119,10 @@ static int Lzmq_setsockopt(lua_State *L)
int rc = 0;
switch (option) {
- case ZMQ_HWM:
- case ZMQ_LWM:
case ZMQ_SWAP:
- case ZMQ_AFFINITY:
+ case ZMQ_RATE:
+ case ZMQ_RECOVERY_IVL:
+ case ZMQ_MCAST_LOOP:
{
int64_t optval = (int64_t) luaL_checklong(L, 3);
rc = zmq_setsockopt(s->ptr, option, (void *) &optval, sizeof(int64_t));
@@ -137,9 +137,8 @@ static int Lzmq_setsockopt(lua_State *L)
rc = zmq_setsockopt(s->ptr, option, (void *) optval, optvallen);
}
break;
- case ZMQ_RATE:
- case ZMQ_RECOVERY_IVL:
- case ZMQ_MCAST_LOOP:
+ case ZMQ_HWM:
+ case ZMQ_AFFINITY:
case ZMQ_SNDBUF:
case ZMQ_RCVBUF:
{
@@ -168,12 +167,14 @@ static int Lzmq_getsockopt(lua_State *L)
int rc = 0;
switch (option) {
- case ZMQ_HWM:
- case ZMQ_LWM:
case ZMQ_SWAP:
- case ZMQ_AFFINITY:
+ case ZMQ_RATE:
+ case ZMQ_RECOVERY_IVL:
+ case ZMQ_MCAST_LOOP:
+ case ZMQ_RCVMORE:
{
int64_t optval;
+ optvallen = sizeof(int64_t);
rc = zmq_getsockopt(s->ptr, option, (void *) &optval, &optvallen);
if (rc == 0) {
lua_pushinteger(L, (lua_Integer) optval);
@@ -181,18 +182,26 @@ static int Lzmq_getsockopt(lua_State *L)
}
}
break;
- /* case ZMQ_IDENTITY:
- * case ZMQ_SUBSCRIBE:
- * case ZMQ_UNSUBSCRIBE:
- */
- case ZMQ_RATE:
- case ZMQ_RECOVERY_IVL:
- case ZMQ_MCAST_LOOP:
+ case ZMQ_IDENTITY:
+ {
+ char id[256];
+ memset((void *)id, '\0', 256);
+ optvallen = 256;
+ rc = zmq_getsockopt(s->ptr, option, (void *)id, &optvallen);
+ id[255] = '\0';
+ if (rc == 0) {
+ lua_pushstring(L, id);
+ return 1;
+ }
+ }
+ break;
+ case ZMQ_HWM:
+ case ZMQ_AFFINITY:
case ZMQ_SNDBUF:
case ZMQ_RCVBUF:
- case ZMQ_RCVMORE:
{
uint64_t optval;
+ optvallen = sizeof(uint64_t);
rc = zmq_getsockopt(s->ptr, option, (void *) &optval, &optvallen);
if (rc == 0) {
lua_pushinteger(L, (lua_Integer) optval);
@@ -344,7 +353,6 @@ LUALIB_API int luaopen_zmq(lua_State *L)
set_zmq_const(DOWNSTREAM);
set_zmq_const(HWM);
- set_zmq_const(LWM);
set_zmq_const(SWAP);
set_zmq_const(AFFINITY);
set_zmq_const(IDENTITY);
Hopefully someone will find this gist useful:
diff --git a/Makefile b/Makefile
index 5f89db2..41465f0 100644
--- a/Makefile
+++ b/Makefile
@@ -18,9 +18,9 @@
-CFLAGS = pkg-config lua5.1 --cflags
-fPIC -O3 -Wall
-LFLAGS = -shared pkg-config --libs --cflags libzmq
-INSTALL_PATH = pkg-config lua5.1 --variable=INSTALL_CMOD
+CFLAGS = -fPIC -O3 -Wall -I/opt/local/include
+LFLAGS = -shared -L/opt/local/lib -llua -lzmq
+INSTALL_PATH = /opt/local/lib
all: zmq.so
@@ -35,7 +35,7 @@ zmq.so: zmq.lo
install: zmq.so
install -D -s zmq.so $(INSTALL_PATH)/zmq.so
install zmq.so $(INSTALL_PATH)
clean:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.