From a264b26c487402fcd3ff738d50f2fc15871ca33a Mon Sep 17 00:00:00 2001 From: "Robert G. Jakabosky" Date: Fri, 23 Dec 2011 17:54:36 -0800 Subject: [PATCH] Fix recv() method when used with ZeroMQ 3.1.x --- src/pre_generated-zmq.nobj.c | 537 +++++++++++++++++++++++++++-------- src/socket.nobj.lua | 4 +- 2 files changed, 419 insertions(+), 122 deletions(-) diff --git a/src/pre_generated-zmq.nobj.c b/src/pre_generated-zmq.nobj.c index 0afec85..b762661 100644 --- a/src/pre_generated-zmq.nobj.c +++ b/src/pre_generated-zmq.nobj.c @@ -98,19 +98,26 @@ typedef int bool; #define assert_obj_type(type, obj) #endif -#ifndef obj_type_free +void *nobj_realloc(void *ptr, size_t osize, size_t nsize); + +void *nobj_realloc(void *ptr, size_t osize, size_t nsize) { + (void)osize; + if(0 == nsize) { + free(ptr); + return NULL; + } + return realloc(ptr, nsize); +} + #define obj_type_free(type, obj) do { \ assert_obj_type(type, obj); \ - free((obj)); \ + nobj_realloc((obj), sizeof(type), 0); \ } while(0) -#endif -#ifndef obj_type_new #define obj_type_new(type, obj) do { \ assert_obj_type(type, obj); \ - (obj) = malloc(sizeof(type)); \ + (obj) = nobj_realloc(NULL, 0, sizeof(type)); \ } while(0) -#endif typedef struct obj_type obj_type; @@ -201,9 +208,13 @@ static char obj_udata_weak_ref_key[] = "obj_udata_weak_ref_key"; static char obj_udata_private_key[] = "obj_udata_private_key"; #if LUAJIT_FFI +typedef int (*ffi_export_func_t)(void); typedef struct ffi_export_symbol { const char *name; - void *sym; + union { + void *data; + ffi_export_func_t func; + } sym; } ffi_export_symbol; #endif @@ -273,18 +284,10 @@ static obj_type obj_types[] = { #if LUAJIT_FFI -static int nobj_udata_new_ffi(lua_State *L) { - size_t size = luaL_checkinteger(L, 1); - luaL_checktype(L, 2, LUA_TTABLE); - lua_settop(L, 2); - /* create userdata. */ - lua_newuserdata(L, size); - lua_replace(L, 1); - /* set userdata's metatable. */ - lua_setmetatable(L, 1); - return 1; -} +/* nobj_ffi_support_enabled_hint should be set to 1 when FFI support is enabled in at-least one + * instance of a LuaJIT state. It should never be set back to 0. */ +static int nobj_ffi_support_enabled_hint = 0; static const char nobj_ffi_support_key[] = "LuaNativeObject_FFI_SUPPORT"; static const char nobj_check_ffi_support_code[] = "local stat, ffi=pcall(require,\"ffi\")\n" /* try loading LuaJIT`s FFI module. */ @@ -326,6 +329,12 @@ static int nobj_check_ffi_support(lua_State *L) { lua_pushstring(L, nobj_ffi_support_key); lua_pushboolean(L, rc); lua_rawset(L, LUA_REGISTRYINDEX); + + /* turn-on hint that there is FFI code enabled. */ + if(rc) { + nobj_ffi_support_enabled_hint = 1; + } + return rc; } @@ -337,7 +346,7 @@ static int nobj_try_loading_ffi(lua_State *L, const char *ffi_mod_name, /* export symbols to priv_table. */ while(ffi_exports->name != NULL) { lua_pushstring(L, ffi_exports->name); - lua_pushlightuserdata(L, ffi_exports->sym); + lua_pushlightuserdata(L, ffi_exports->sym.data); lua_settable(L, priv_table); ffi_exports++; } @@ -346,7 +355,7 @@ static int nobj_try_loading_ffi(lua_State *L, const char *ffi_mod_name, lua_pushvalue(L, -2); /* dup C module's table. */ lua_pushvalue(L, priv_table); /* move priv_table to top of stack. */ lua_remove(L, priv_table); - lua_pushcfunction(L, nobj_udata_new_ffi); + lua_pushvalue(L, LUA_REGISTRYINDEX); err = lua_pcall(L, 3, 0, 0); } if(err) { @@ -355,6 +364,7 @@ static int nobj_try_loading_ffi(lua_State *L, const char *ffi_mod_name, msg = lua_tostring(L, -1); } printf("Failed to install FFI-based bindings: %s\n", msg); +lua_error(L); lua_pop(L, 1); /* pop error message. */ } return err; @@ -511,6 +521,17 @@ static FUNC_UNUSED void obj_udata_luapush(lua_State *L, void *obj, obj_type *typ lua_pushnil(L); return; } +#if LUAJIT_FFI + lua_pushlightuserdata(L, type); + lua_rawget(L, LUA_REGISTRYINDEX); /* type's metatable. */ + if(nobj_ffi_support_enabled_hint && lua_isfunction(L, -1)) { + /* call special FFI "void *" to FFI object convertion function. */ + lua_pushlightuserdata(L, obj); + lua_pushinteger(L, flags); + lua_call(L, 2, 1); + return; + } +#endif /* check for type caster. */ if(type->dcaster) { (type->dcaster)(&obj, &type); @@ -520,8 +541,12 @@ static FUNC_UNUSED void obj_udata_luapush(lua_State *L, void *obj, obj_type *typ ud->obj = obj; ud->flags = flags; /* get obj_type metatable. */ +#if LUAJIT_FFI + lua_insert(L, -2); /* move userdata below metatable. */ +#else lua_pushlightuserdata(L, type); lua_rawget(L, LUA_REGISTRYINDEX); /* type's metatable. */ +#endif lua_setmetatable(L, -2); } @@ -567,6 +592,18 @@ static FUNC_UNUSED void obj_udata_luapush_weak(lua_State *L, void *obj, obj_type } lua_pop(L, 1); /* pop nil. */ +#if LUAJIT_FFI + lua_pushlightuserdata(L, type); + lua_rawget(L, LUA_REGISTRYINDEX); /* type's metatable. */ + if(nobj_ffi_support_enabled_hint && lua_isfunction(L, -1)) { + lua_remove(L, -2); + /* call special FFI "void *" to FFI object convertion function. */ + lua_pushlightuserdata(L, obj); + lua_pushinteger(L, flags); + lua_call(L, 2, 1); + return; + } +#endif /* create new userdata. */ ud = (obj_udata *)lua_newuserdata(L, sizeof(obj_udata)); @@ -574,8 +611,12 @@ static FUNC_UNUSED void obj_udata_luapush_weak(lua_State *L, void *obj, obj_type ud->obj = obj; ud->flags = flags; /* get obj_type metatable. */ +#if LUAJIT_FFI + lua_insert(L, -2); /* move userdata below metatable. */ +#else lua_pushlightuserdata(L, type); lua_rawget(L, LUA_REGISTRYINDEX); /* type's metatable. */ +#endif lua_setmetatable(L, -2); /* add weak reference to object. */ @@ -680,12 +721,26 @@ static FUNC_UNUSED void * obj_simple_udata_luadelete(lua_State *L, int _index, o static FUNC_UNUSED void *obj_simple_udata_luapush(lua_State *L, void *obj, int size, obj_type *type) { +#if LUAJIT_FFI + lua_pushlightuserdata(L, type); + lua_rawget(L, LUA_REGISTRYINDEX); /* type's metatable. */ + if(nobj_ffi_support_enabled_hint && lua_isfunction(L, -1)) { + /* call special FFI "void *" to FFI object convertion function. */ + lua_pushlightuserdata(L, obj); + lua_call(L, 1, 1); + return obj; + } +#endif /* create new userdata. */ void *ud = lua_newuserdata(L, size); memcpy(ud, obj, size); /* get obj_type metatable. */ +#if LUAJIT_FFI + lua_insert(L, -2); /* move userdata below metatable. */ +#else lua_pushlightuserdata(L, type); lua_rawget(L, LUA_REGISTRYINDEX); /* type's metatable. */ +#endif lua_setmetatable(L, -2); return ud; @@ -901,6 +956,12 @@ static void obj_type_register(lua_State *L, const reg_sub_module *type_reg, int lua_pop(L, 2); /* drop metatable & methods */ } +static FUNC_UNUSED int lua_checktype_ref(lua_State *L, int _index, int _type) { + luaL_checktype(L,_index,_type); + lua_pushvalue(L,_index); + return luaL_ref(L, LUA_REGISTRYINDEX); +} + #define obj_type_zmq_msg_t_check(L, _index) \ @@ -962,10 +1023,25 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return assert(ffi_safe_load(name, global))\n" "end\n" "\n" +"local function ffi_string(ptr)\n" +" if ptr ~= nil then\n" +" return ffi.string(ptr)\n" +" end\n" +" return nil\n" +"end\n" +"\n" +"local function ffi_string_len(ptr, len)\n" +" if ptr ~= nil then\n" +" return ffi.string(ptr, len)\n" +" end\n" +" return nil\n" +"end\n" +"\n" "local error = error\n" "local type = type\n" "local tonumber = tonumber\n" "local tostring = tostring\n" +"local sformat = string.format\n" "local rawset = rawset\n" "local setmetatable = setmetatable\n" "local p_config = package.config\n" @@ -1004,7 +1080,9 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" "end\n" "\n" -"local _M, _priv, udata_new = ...\n" +"local _M, _priv, reg_table = ...\n" +"local REG_OBJECTS_AS_GLOBALS = false\n" +"local C = ffi.C\n" "\n" "local OBJ_UDATA_FLAG_OWN = 1\n" "\n" @@ -1048,6 +1126,10 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" "]])\n" "\n" +"local nobj_callback_states = {}\n" +"local nobj_weak_objects = setmetatable({}, {__mode = \"v\"})\n" +"local nobj_obj_flags = {}\n" +"\n" "local function obj_ptr_to_id(ptr)\n" " return tonumber(ffi.cast('uintptr_t', ptr))\n" "end\n" @@ -1057,18 +1139,29 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "end\n" "\n" "local function register_default_constructor(_pub, obj_name, constructor)\n" -" local pub_constructor = _pub[obj_name]\n" -" if type(pub_constructor) == 'table' then\n" -" setmetatable(pub_constructor, { __call = function(t,...)\n" +" local obj_pub = _pub[obj_name]\n" +" if type(obj_pub) == 'table' then\n" +" -- copy table since it might have a locked metatable\n" +" local new_pub = {}\n" +" for k,v in pairs(obj_pub) do\n" +" new_pub[k] = v\n" +" end\n" +" setmetatable(new_pub, { __call = function(t,...)\n" " return constructor(...)\n" " end,\n" " __metatable = false,\n" " })\n" +" obj_pub = new_pub\n" " else\n" -" _pub[obj_name] = constructor\n" +" obj_pub = constructor\n" +" end\n" +" _pub[obj_name] = obj_pub\n" +" _M[obj_name] = obj_pub\n" +" if REG_OBJECTS_AS_GLOBALS then\n" +" _G[obj_name] = obj_pub\n" " end\n" "end\n" -"local C = ffi_load_cmodule(\"zmq\", false)\n" +"C = ffi_load_cmodule(\"zmq\", false)\n" "\n" "ffi.cdef[[\n" "typedef int ZMQ_Error;\n" @@ -1272,23 +1365,22 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" "]]\n" "\n" +"REG_OBJECTS_AS_GLOBALS = false\n" "local _pub = {}\n" "local _meth = {}\n" +"local _push = {}\n" +"local _obj_subs = {}\n" +"local _type_names = {}\n" +"local _ctypes = {}\n" "for obj_name,mt in pairs(_priv) do\n" -" if type(mt) == 'table' and mt.__index then\n" -" _meth[obj_name] = mt.__index\n" +" if type(mt) == 'table' then\n" +" _obj_subs[obj_name] = {}\n" +" if mt.__index then\n" +" _meth[obj_name] = mt.__index\n" +" end\n" " end\n" "end\n" -"_pub.zmq = _M\n" "for obj_name,pub in pairs(_M) do\n" -" if type(pub) == 'table' then\n" -" local new_pub = {}\n" -" for k,v in pairs(pub) do\n" -" new_pub[k] = v\n" -" end\n" -" pub = new_pub\n" -" _M[obj_name] = pub\n" -" end\n" " _pub[obj_name] = pub\n" "end\n" "\n" @@ -1299,13 +1391,11 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" "do\n" " local obj_mt = _priv.zmq_msg_t\n" -" local zmq_msg_t_sizeof = ffi.sizeof\"zmq_msg_t\"\n" -"\n" " local obj_type = obj_mt['.type']\n" -" _priv[obj_type] = function(obj)\n" -" if ffi.istype(\"zmq_msg_t\", obj) then return obj end\n" -" return nil\n" -" end\n" +" local obj_ctype = ffi.typeof(\"zmq_msg_t\")\n" +" _ctypes.zmq_msg_t = obj_ctype\n" +" _type_names.zmq_msg_t = tostring(obj_ctype)\n" +" local zmq_msg_t_sizeof = ffi.sizeof\"zmq_msg_t\"\n" "\n" " function obj_type_zmq_msg_t_check(obj)\n" " return obj\n" @@ -1320,14 +1410,27 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" "\n" " function obj_mt:__tostring()\n" -" return \"zmq_msg_t: \" .. tostring(ffi.cast('void *', self))\n" +" return sformat(\"zmq_msg_t: %p\", self)\n" " end\n" "\n" " function obj_mt.__eq(val1, val2)\n" -" if not ffi.istype(\"zmq_msg_t\", val2) then return false end\n" -" assert(ffi.istype(\"zmq_msg_t\", val1), \"expected zmq_msg_t\")\n" +" if not ffi.istype(obj_type, val2) then return false end\n" +" assert(ffi.istype(obj_type, val1), \"expected zmq_msg_t\")\n" " return (C.memcmp(val1, val2, zmq_msg_t_sizeof) == 0)\n" " end\n" +"\n" +" -- type checking function for C API.\n" +" _priv[obj_type] = function(obj)\n" +" if ffi.istype(obj_type, obj) then return obj end\n" +" return nil\n" +" end\n" +" -- push function for C API.\n" +" reg_table[obj_type] = function(ptr)\n" +" local obj = obj_ctype()\n" +" ffi.copy(obj, ptr, zmq_msg_t_sizeof);\n" +" return obj\n" +" end\n" +"\n" "end\n" "\n" "\n" @@ -1337,44 +1440,58 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" "do\n" " local obj_mt = _priv.ZMQ_Socket\n" -" local objects = setmetatable({}, {__mode = \"v\"})\n" -" local obj_flags = {}\n" -"\n" " local obj_type = obj_mt['.type']\n" -" _priv[obj_type] = function(ptr)\n" -" if ffi.istype(\"ZMQ_Socket *\", ptr) then return ptr end\n" -" return nil\n" -" end\n" +" local obj_ctype = ffi.typeof(\"ZMQ_Socket *\")\n" +" _ctypes.ZMQ_Socket = obj_ctype\n" +" _type_names.ZMQ_Socket = tostring(obj_ctype)\n" "\n" " function obj_type_ZMQ_Socket_check(ptr)\n" -" return ptr\n" +" -- if ptr is nil or is the correct type, then just return it.\n" +" if not ptr or ffi.istype(obj_ctype, ptr) then return ptr end\n" +" -- check if it is a compatible type.\n" +" local ctype = tostring(ffi.typeof(ptr))\n" +" local bcaster = _obj_subs.ZMQ_Socket[ctype]\n" +" if bcaster then\n" +" return bcaster(ptr)\n" +" end\n" +" return error(\"Expected 'ZMQ_Socket *'\", 2)\n" " end\n" "\n" " function obj_type_ZMQ_Socket_delete(ptr)\n" " local id = obj_ptr_to_id(ptr)\n" -" local flags = obj_flags[id]\n" +" local flags = nobj_obj_flags[id]\n" " if not flags then return nil, 0 end\n" " ffi.gc(ptr, nil)\n" -" obj_flags[id] = nil\n" +" nobj_obj_flags[id] = nil\n" " return ptr, flags\n" " end\n" "\n" " function obj_type_ZMQ_Socket_push(ptr, flags)\n" " local id = obj_ptr_to_id(ptr)\n" " -- check weak refs\n" -" local old_ptr = objects[id]\n" +" local old_ptr = nobj_weak_objects[id]\n" " if old_ptr then return old_ptr end\n" -" if flags then\n" -" obj_flags[id] = flags\n" +"\n" +" if flags ~= 0 then\n" +" nobj_obj_flags[id] = flags\n" " ffi.gc(ptr, obj_mt.__gc)\n" " end\n" -" objects[id] = ptr\n" +" nobj_weak_objects[id] = ptr\n" " return ptr\n" " end\n" "\n" " function obj_mt:__tostring()\n" -" local id = obj_ptr_to_id(self)\n" -" return \"ZMQ_Socket: \" .. tostring(id)\n" +" return sformat(\"ZMQ_Socket: %p, flags=%d\", self, nobj_obj_flags[obj_ptr_to_id(self)] or 0)\n" +" end\n" +"\n" +" -- type checking function for C API.\n" +" _priv[obj_type] = function(ptr)\n" +" if ffi.istype(obj_ctype, ptr) then return ptr end\n" +" return nil\n" +" end\n" +" -- push function for C API.\n" +" reg_table[obj_type] = function(ptr, flags)\n" +" return obj_type_ZMQ_Socket_push(ffi.cast(obj_ctype,ptr), flags)\n" " end\n" "\n" "end\n" @@ -1386,13 +1503,11 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" "do\n" " local obj_mt = _priv.ZMQ_Poller\n" -" local ZMQ_Poller_sizeof = ffi.sizeof\"ZMQ_Poller\"\n" -"\n" " local obj_type = obj_mt['.type']\n" -" _priv[obj_type] = function(obj)\n" -" if ffi.istype(\"ZMQ_Poller\", obj) then return obj end\n" -" return nil\n" -" end\n" +" local obj_ctype = ffi.typeof(\"ZMQ_Poller\")\n" +" _ctypes.ZMQ_Poller = obj_ctype\n" +" _type_names.ZMQ_Poller = tostring(obj_ctype)\n" +" local ZMQ_Poller_sizeof = ffi.sizeof\"ZMQ_Poller\"\n" "\n" " function obj_type_ZMQ_Poller_check(obj)\n" " return obj\n" @@ -1407,14 +1522,27 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" "\n" " function obj_mt:__tostring()\n" -" return \"ZMQ_Poller: \" .. tostring(ffi.cast('void *', self))\n" +" return sformat(\"ZMQ_Poller: %p\", self)\n" " end\n" "\n" " function obj_mt.__eq(val1, val2)\n" -" if not ffi.istype(\"ZMQ_Poller\", val2) then return false end\n" -" assert(ffi.istype(\"ZMQ_Poller\", val1), \"expected ZMQ_Poller\")\n" +" if not ffi.istype(obj_type, val2) then return false end\n" +" assert(ffi.istype(obj_type, val1), \"expected ZMQ_Poller\")\n" " return (C.memcmp(val1, val2, ZMQ_Poller_sizeof) == 0)\n" " end\n" +"\n" +" -- type checking function for C API.\n" +" _priv[obj_type] = function(obj)\n" +" if ffi.istype(obj_type, obj) then return obj end\n" +" return nil\n" +" end\n" +" -- push function for C API.\n" +" reg_table[obj_type] = function(ptr)\n" +" local obj = obj_ctype()\n" +" ffi.copy(obj, ptr, ZMQ_Poller_sizeof);\n" +" return obj\n" +" end\n" +"\n" "end\n" "\n" "\n" @@ -1424,44 +1552,58 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" "do\n" " local obj_mt = _priv.ZMQ_Ctx\n" -" local objects = setmetatable({}, {__mode = \"v\"})\n" -" local obj_flags = {}\n" -"\n" " local obj_type = obj_mt['.type']\n" -" _priv[obj_type] = function(ptr)\n" -" if ffi.istype(\"ZMQ_Ctx *\", ptr) then return ptr end\n" -" return nil\n" -" end\n" +" local obj_ctype = ffi.typeof(\"ZMQ_Ctx *\")\n" +" _ctypes.ZMQ_Ctx = obj_ctype\n" +" _type_names.ZMQ_Ctx = tostring(obj_ctype)\n" "\n" " function obj_type_ZMQ_Ctx_check(ptr)\n" -" return ptr\n" +" -- if ptr is nil or is the correct type, then just return it.\n" +" if not ptr or ffi.istype(obj_ctype, ptr) then return ptr end\n" +" -- check if it is a compatible type.\n" +" local ctype = tostring(ffi.typeof(ptr))\n" +" local bcaster = _obj_subs.ZMQ_Ctx[ctype]\n" +" if bcaster then\n" +" return bcaster(ptr)\n" +" end\n" +" return error(\"Expected 'ZMQ_Ctx *'\", 2)\n" " end\n" "\n" " function obj_type_ZMQ_Ctx_delete(ptr)\n" " local id = obj_ptr_to_id(ptr)\n" -" local flags = obj_flags[id]\n" +" local flags = nobj_obj_flags[id]\n" " if not flags then return nil, 0 end\n" " ffi.gc(ptr, nil)\n" -" obj_flags[id] = nil\n" +" nobj_obj_flags[id] = nil\n" " return ptr, flags\n" " end\n" "\n" " function obj_type_ZMQ_Ctx_push(ptr, flags)\n" " local id = obj_ptr_to_id(ptr)\n" " -- check weak refs\n" -" local old_ptr = objects[id]\n" +" local old_ptr = nobj_weak_objects[id]\n" " if old_ptr then return old_ptr end\n" -" if flags then\n" -" obj_flags[id] = flags\n" +"\n" +" if flags ~= 0 then\n" +" nobj_obj_flags[id] = flags\n" " ffi.gc(ptr, obj_mt.__gc)\n" " end\n" -" objects[id] = ptr\n" +" nobj_weak_objects[id] = ptr\n" " return ptr\n" " end\n" "\n" " function obj_mt:__tostring()\n" -" local id = obj_ptr_to_id(self)\n" -" return \"ZMQ_Ctx: \" .. tostring(id)\n" +" return sformat(\"ZMQ_Ctx: %p, flags=%d\", self, nobj_obj_flags[obj_ptr_to_id(self)] or 0)\n" +" end\n" +"\n" +" -- type checking function for C API.\n" +" _priv[obj_type] = function(ptr)\n" +" if ffi.istype(obj_ctype, ptr) then return ptr end\n" +" return nil\n" +" end\n" +" -- push function for C API.\n" +" reg_table[obj_type] = function(ptr, flags)\n" +" return obj_type_ZMQ_Ctx_push(ffi.cast(obj_ctype,ptr), flags)\n" " end\n" "\n" "end\n" @@ -1473,44 +1615,58 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" "do\n" " local obj_mt = _priv.ZMQ_StopWatch\n" -" local objects = setmetatable({}, {__mode = \"v\"})\n" -" local obj_flags = {}\n" -"\n" " local obj_type = obj_mt['.type']\n" -" _priv[obj_type] = function(ptr)\n" -" if ffi.istype(\"ZMQ_StopWatch *\", ptr) then return ptr end\n" -" return nil\n" -" end\n" +" local obj_ctype = ffi.typeof(\"ZMQ_StopWatch *\")\n" +" _ctypes.ZMQ_StopWatch = obj_ctype\n" +" _type_names.ZMQ_StopWatch = tostring(obj_ctype)\n" "\n" " function obj_type_ZMQ_StopWatch_check(ptr)\n" -" return ptr\n" +" -- if ptr is nil or is the correct type, then just return it.\n" +" if not ptr or ffi.istype(obj_ctype, ptr) then return ptr end\n" +" -- check if it is a compatible type.\n" +" local ctype = tostring(ffi.typeof(ptr))\n" +" local bcaster = _obj_subs.ZMQ_StopWatch[ctype]\n" +" if bcaster then\n" +" return bcaster(ptr)\n" +" end\n" +" return error(\"Expected 'ZMQ_StopWatch *'\", 2)\n" " end\n" "\n" " function obj_type_ZMQ_StopWatch_delete(ptr)\n" " local id = obj_ptr_to_id(ptr)\n" -" local flags = obj_flags[id]\n" +" local flags = nobj_obj_flags[id]\n" " if not flags then return nil, 0 end\n" " ffi.gc(ptr, nil)\n" -" obj_flags[id] = nil\n" +" nobj_obj_flags[id] = nil\n" " return ptr, flags\n" " end\n" "\n" " function obj_type_ZMQ_StopWatch_push(ptr, flags)\n" " local id = obj_ptr_to_id(ptr)\n" " -- check weak refs\n" -" local old_ptr = objects[id]\n" +" local old_ptr = nobj_weak_objects[id]\n" " if old_ptr then return old_ptr end\n" -" if flags then\n" -" obj_flags[id] = flags\n" +"\n" +" if flags ~= 0 then\n" +" nobj_obj_flags[id] = flags\n" " ffi.gc(ptr, obj_mt.__gc)\n" " end\n" -" objects[id] = ptr\n" +" nobj_weak_objects[id] = ptr\n" " return ptr\n" " end\n" "\n" " function obj_mt:__tostring()\n" -" local id = obj_ptr_to_id(self)\n" -" return \"ZMQ_StopWatch: \" .. tostring(id)\n" +" return sformat(\"ZMQ_StopWatch: %p, flags=%d\", self, nobj_obj_flags[obj_ptr_to_id(self)] or 0)\n" +" end\n" +"\n" +" -- type checking function for C API.\n" +" _priv[obj_type] = function(ptr)\n" +" if ffi.istype(obj_ctype, ptr) then return ptr end\n" +" return nil\n" +" end\n" +" -- push function for C API.\n" +" reg_table[obj_type] = function(ptr, flags)\n" +" return obj_type_ZMQ_StopWatch_push(ffi.cast(obj_ctype,ptr), flags)\n" " end\n" "\n" "end\n" @@ -1553,6 +1709,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return obj_type_zmq_msg_t_push(self)\n" "end\n" "register_default_constructor(_pub,\"zmq_msg_t\",_pub.zmq_msg_t.init)\n" +"\n" "-- method: init_size\n" "function _pub.zmq_msg_t.init_size(size1)\n" " \n" @@ -1564,6 +1721,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return obj_type_zmq_msg_t_push(self)\n" "end\n" +"\n" "-- method: init_data\n" "function _pub.zmq_msg_t.init_data(data1)\n" " local data_len1 = #data1\n" @@ -1580,6 +1738,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return obj_type_zmq_msg_t_push(self)\n" "end\n" +"\n" "-- method: __gc\n" "function _priv.zmq_msg_t.__gc(self)\n" " local self = obj_type_zmq_msg_t_delete(self)\n" @@ -1592,6 +1751,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "-- method: close\n" "function _meth.zmq_msg_t.close(self)\n" " \n" @@ -1603,6 +1763,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "-- method: move\n" "function _meth.zmq_msg_t.move(self, src2)\n" " \n" @@ -1615,6 +1776,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "-- method: copy\n" "function _meth.zmq_msg_t.copy(self, src2)\n" " \n" @@ -1627,6 +1789,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "-- method: set_data\n" "function _meth.zmq_msg_t.set_data(self, data2)\n" " \n" @@ -1650,13 +1813,15 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "-- method: data\n" "function _meth.zmq_msg_t.data(self)\n" " \n" -" local rc_zmq_msg_data1 = NULL\n" +" local rc_zmq_msg_data1\n" " rc_zmq_msg_data1 = C.zmq_msg_data(self)\n" " return rc_zmq_msg_data1\n" "end\n" +"\n" "-- method: set_size\n" "function _meth.zmq_msg_t.set_size(self, size2)\n" " \n" @@ -1678,6 +1843,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "-- method: size\n" "function _meth.zmq_msg_t.size(self)\n" " \n" @@ -1685,16 +1851,19 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " rc_zmq_msg_size1 = C.zmq_msg_size(self)\n" " return rc_zmq_msg_size1\n" "end\n" +"\n" "-- method: __tostring\n" "function _priv.zmq_msg_t.__tostring(self)\n" " \n" " local data_len1 = 0\n" -" local data1 = NULL\n" +" local data1\n" " data1 = C.zmq_msg_data(self);\n" " data_len1 = C.zmq_msg_size(self);\n" "\n" -" return ((nil ~= data1) and ffi.string(data1,data_len1))\n" +" return ffi_string_len(data1,data_len1)\n" "end\n" +"\n" +"_push.zmq_msg_t = obj_type_zmq_msg_t_push\n" "ffi.metatype(\"zmq_msg_t\", _priv.zmq_msg_t)\n" "-- End \"zmq_msg_t\" FFI interface\n" "\n" @@ -1725,6 +1894,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "_priv.ZMQ_Socket.__gc = _meth.ZMQ_Socket.close\n" +"\n" "-- method: bind\n" "function _meth.ZMQ_Socket.bind(self, addr2)\n" " \n" @@ -1737,6 +1907,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "-- method: connect\n" "function _meth.ZMQ_Socket.connect(self, addr2)\n" " \n" @@ -1749,6 +1920,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "local option_gets = {}\n" "local option_sets = {}\n" "\n" @@ -1819,6 +1991,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "local tmp_val_len = ffi.new('size_t[1]', 4)\n" "\n" "-- method: getopt\n" @@ -1836,6 +2009,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" " return val1\n" "end\n" +"\n" "-- method: send_msg\n" "function _meth.ZMQ_Socket.send_msg(self, msg2, flags3)\n" " \n" @@ -1849,6 +2023,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "-- method: send\n" "function _meth.ZMQ_Socket.send(self, data2, flags3)\n" " \n" @@ -1862,6 +2037,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "-- method: recv_msg\n" "function _meth.ZMQ_Socket.recv_msg(self, msg2, flags3)\n" " \n" @@ -1875,6 +2051,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return true\n" "end\n" +"\n" "local tmp_msg = ffi.new('zmq_msg_t')\n" "\n" "-- method: recv\n" @@ -1882,7 +2059,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " \n" " flags2 = flags2 or 0\n" " local data_len1 = 0\n" -" local data1 = NULL\n" +" local data1\n" " local err2 = 0\n" " local msg = tmp_msg\n" " -- initialize blank message.\n" @@ -1892,7 +2069,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" " -- receive message\n" " err2 = zmq_recvmsg(self, msg, flags2)\n" -" if 0 == err2 then\n" +" if err2 >= 0 then\n" " local data = ffi.string(C.zmq_msg_data(msg), C.zmq_msg_size(msg))\n" " -- close message\n" " C.zmq_msg_close(msg)\n" @@ -1905,8 +2082,10 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " -- close message\n" " C.zmq_msg_close(msg)\n" "\n" -" return ((nil ~= data1) and ffi.string(data1,data_len1))\n" +" return ffi_string_len(data1,data_len1)\n" "end\n" +"\n" +"do\n" " local hwm_value_tmp = ffi.new(\"int[1]\")\n" "-- method: hwm\n" "if (VERSION_2_0 or VERSION_3_0) then\n" @@ -1921,6 +2100,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_hwm\n" "if (VERSION_2_0 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_hwm(self, value2)\n" @@ -1935,6 +2116,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local swap_value_tmp = ffi.new(\"int[1]\")\n" "-- method: swap\n" "if (VERSION_2_0) then\n" @@ -1949,6 +2132,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_swap\n" "if (VERSION_2_0) then\n" "function _meth.ZMQ_Socket.set_swap(self, value2)\n" @@ -1963,6 +2148,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local affinity_value_tmp = ffi.new(\"uint64_t[1]\")\n" "-- method: affinity\n" "if (VERSION_2_0 or VERSION_3_0) then\n" @@ -1977,6 +2164,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_affinity\n" "if (VERSION_2_0 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_affinity(self, value2)\n" @@ -1991,20 +2180,22 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" "-- method: identity\n" "if (VERSION_2_0 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.identity(self)\n" " \n" " local value_len1 = 0\n" -" local value1 = NULL\n" +" local value1\n" " local rc_lzmq_socket_identity2 = 0\n" " rc_lzmq_socket_identity2 = C.lzmq_socket_identity(self, value1, value_len1)\n" " if (-1 == rc_lzmq_socket_identity2) then\n" " return nil,error_code__ZMQ_Error__push(rc_lzmq_socket_identity2)\n" " end\n" -" return ((nil ~= value1) and ffi.string(value1,value_len1))\n" +" return ffi_string_len(value1,value_len1)\n" "end\n" "end\n" +"\n" "-- method: set_identity\n" "if (VERSION_2_0 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_identity(self, value2)\n" @@ -2019,6 +2210,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" "-- method: subscribe\n" "if (VERSION_2_0 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.subscribe(self, value2)\n" @@ -2033,6 +2225,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" "-- method: unsubscribe\n" "if (VERSION_2_0 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.unsubscribe(self, value2)\n" @@ -2047,6 +2240,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local rate_value_tmp = ffi.new(\"int[1]\")\n" "-- method: rate\n" "if (VERSION_2_0 or VERSION_3_0) then\n" @@ -2061,6 +2256,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_rate\n" "if (VERSION_2_0 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_rate(self, value2)\n" @@ -2075,6 +2272,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local recovery_ivl_value_tmp = ffi.new(\"int[1]\")\n" "-- method: recovery_ivl\n" "if (VERSION_2_0 or VERSION_3_0) then\n" @@ -2089,6 +2288,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_recovery_ivl\n" "if (VERSION_2_0 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_recovery_ivl(self, value2)\n" @@ -2103,6 +2304,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local mcast_loop_value_tmp = ffi.new(\"int[1]\")\n" "-- method: mcast_loop\n" "if (VERSION_2_0) then\n" @@ -2117,6 +2320,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_mcast_loop\n" "if (VERSION_2_0) then\n" "function _meth.ZMQ_Socket.set_mcast_loop(self, value2)\n" @@ -2131,6 +2336,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local sndbuf_value_tmp = ffi.new(\"int[1]\")\n" "-- method: sndbuf\n" "if (VERSION_2_0 or VERSION_3_0) then\n" @@ -2145,6 +2352,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_sndbuf\n" "if (VERSION_2_0 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_sndbuf(self, value2)\n" @@ -2159,6 +2368,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local rcvbuf_value_tmp = ffi.new(\"int[1]\")\n" "-- method: rcvbuf\n" "if (VERSION_2_0 or VERSION_3_0) then\n" @@ -2173,6 +2384,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_rcvbuf\n" "if (VERSION_2_0 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_rcvbuf(self, value2)\n" @@ -2187,6 +2400,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local rcvmore_value_tmp = ffi.new(\"int[1]\")\n" "-- method: rcvmore\n" "if (VERSION_2_0 or VERSION_3_0) then\n" @@ -2201,6 +2416,9 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" +"do\n" " local fd_value_tmp = ffi.new(\"int[1]\")\n" "-- method: fd\n" "if (VERSION_2_1 or VERSION_3_0) then\n" @@ -2215,6 +2433,9 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" +"do\n" " local events_value_tmp = ffi.new(\"int[1]\")\n" "-- method: events\n" "if (VERSION_2_1 or VERSION_3_0) then\n" @@ -2229,6 +2450,9 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" +"do\n" " local type_value_tmp = ffi.new(\"int[1]\")\n" "-- method: type\n" "if (VERSION_2_1 or VERSION_3_0) then\n" @@ -2243,6 +2467,9 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" +"do\n" " local linger_value_tmp = ffi.new(\"int[1]\")\n" "-- method: linger\n" "if (VERSION_2_1 or VERSION_3_0) then\n" @@ -2257,6 +2484,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_linger\n" "if (VERSION_2_1 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_linger(self, value2)\n" @@ -2271,6 +2500,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local reconnect_ivl_value_tmp = ffi.new(\"int[1]\")\n" "-- method: reconnect_ivl\n" "if (VERSION_2_1 or VERSION_3_0) then\n" @@ -2285,6 +2516,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_reconnect_ivl\n" "if (VERSION_2_1 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_reconnect_ivl(self, value2)\n" @@ -2299,6 +2532,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local backlog_value_tmp = ffi.new(\"int[1]\")\n" "-- method: backlog\n" "if (VERSION_2_1 or VERSION_3_0) then\n" @@ -2313,6 +2548,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_backlog\n" "if (VERSION_2_1 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_backlog(self, value2)\n" @@ -2327,6 +2564,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local recovery_ivl_msec_value_tmp = ffi.new(\"int64_t[1]\")\n" "-- method: recovery_ivl_msec\n" "if (VERSION_2_1) then\n" @@ -2341,6 +2580,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_recovery_ivl_msec\n" "if (VERSION_2_1) then\n" "function _meth.ZMQ_Socket.set_recovery_ivl_msec(self, value2)\n" @@ -2355,6 +2596,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local reconnect_ivl_max_value_tmp = ffi.new(\"int[1]\")\n" "-- method: reconnect_ivl_max\n" "if (VERSION_2_1 or VERSION_3_0) then\n" @@ -2369,6 +2612,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_reconnect_ivl_max\n" "if (VERSION_2_1 or VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_reconnect_ivl_max(self, value2)\n" @@ -2383,6 +2628,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local maxmsgsize_value_tmp = ffi.new(\"int64_t[1]\")\n" "-- method: maxmsgsize\n" "if (VERSION_3_0) then\n" @@ -2397,6 +2644,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_maxmsgsize\n" "if (VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_maxmsgsize(self, value2)\n" @@ -2411,6 +2660,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local sndhwm_value_tmp = ffi.new(\"int[1]\")\n" "-- method: sndhwm\n" "if (VERSION_3_0) then\n" @@ -2425,6 +2676,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_sndhwm\n" "if (VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_sndhwm(self, value2)\n" @@ -2439,6 +2692,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local rcvhwm_value_tmp = ffi.new(\"int[1]\")\n" "-- method: rcvhwm\n" "if (VERSION_3_0) then\n" @@ -2453,6 +2708,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_rcvhwm\n" "if (VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_rcvhwm(self, value2)\n" @@ -2467,6 +2724,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local multicast_hops_value_tmp = ffi.new(\"int[1]\")\n" "-- method: multicast_hops\n" "if (VERSION_3_0) then\n" @@ -2481,6 +2740,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_multicast_hops\n" "if (VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_multicast_hops(self, value2)\n" @@ -2495,6 +2756,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local rcvtimeo_value_tmp = ffi.new(\"int[1]\")\n" "-- method: rcvtimeo\n" "if (VERSION_3_0) then\n" @@ -2509,6 +2772,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_rcvtimeo\n" "if (VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_rcvtimeo(self, value2)\n" @@ -2523,6 +2788,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local sndtimeo_value_tmp = ffi.new(\"int[1]\")\n" "-- method: sndtimeo\n" "if (VERSION_3_0) then\n" @@ -2537,6 +2804,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_sndtimeo\n" "if (VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_sndtimeo(self, value2)\n" @@ -2551,6 +2820,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"do\n" " local ipv4only_value_tmp = ffi.new(\"int[1]\")\n" "-- method: ipv4only\n" "if (VERSION_3_0) then\n" @@ -2565,6 +2836,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return value1[0]\n" "end\n" "end\n" +"end\n" +"\n" "-- method: set_ipv4only\n" "if (VERSION_3_0) then\n" "function _meth.ZMQ_Socket.set_ipv4only(self, value2)\n" @@ -2579,6 +2852,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" +"_push.ZMQ_Socket = obj_type_ZMQ_Socket_push\n" "ffi.metatype(\"ZMQ_Socket\", _priv.ZMQ_Socket)\n" "-- End \"ZMQ_Socket\" FFI interface\n" "\n" @@ -2592,6 +2867,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return obj_type_ZMQ_Poller_push(self)\n" "end\n" "register_default_constructor(_pub,\"ZMQ_Poller\",_pub.ZMQ_Poller.new)\n" +"\n" "-- method: close\n" "function _meth.ZMQ_Poller.close(self)\n" " local self = obj_type_ZMQ_Poller_delete(self)\n" @@ -2600,6 +2876,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return \n" "end\n" "_priv.ZMQ_Poller.__gc = _meth.ZMQ_Poller.close\n" +"\n" "-- method: add\n" "function _meth.ZMQ_Poller.add(self, sock2, events3)\n" " \n" @@ -2622,6 +2899,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" " return idx1\n" "end\n" +"\n" "-- method: modify\n" "function _meth.ZMQ_Poller.modify(self, sock2, events3)\n" " \n" @@ -2651,6 +2929,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" " return idx1\n" "end\n" +"\n" "-- method: remove\n" "function _meth.ZMQ_Poller.remove(self, sock2)\n" " \n" @@ -2674,6 +2953,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" " return idx1\n" "end\n" +"\n" "-- method: poll\n" "function _meth.ZMQ_Poller.poll(self, timeout2)\n" " \n" @@ -2695,6 +2975,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return count1\n" "end\n" +"\n" +"do\n" " local next_revents_idx_revents_tmp = ffi.new(\"int[1]\")\n" "-- method: next_revents_idx\n" "function _meth.ZMQ_Poller.next_revents_idx(self)\n" @@ -2704,6 +2986,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " idx1 = C.poller_next_revents(self, revents2)\n" " return idx1, revents2[0]\n" "end\n" +"end\n" +"\n" "-- method: count\n" "function _meth.ZMQ_Poller.count(self)\n" " \n" @@ -2712,6 +2996,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" "\n" " return count1\n" "end\n" +"\n" +"_push.ZMQ_Poller = obj_type_ZMQ_Poller_push\n" "ffi.metatype(\"ZMQ_Poller\", _priv.ZMQ_Poller)\n" "-- End \"ZMQ_Poller\" FFI interface\n" "\n" @@ -2730,6 +3016,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "_priv.ZMQ_Ctx.__gc = _meth.ZMQ_Ctx.term\n" +"\n" "-- method: socket\n" "function _meth.ZMQ_Ctx.socket(self, type2)\n" " \n" @@ -2742,6 +3029,8 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return obj_type_ZMQ_Socket_push(rc_zmq_socket1, rc_zmq_socket_flags1)\n" "end\n" +"\n" +"_push.ZMQ_Ctx = obj_type_ZMQ_Ctx_push\n" "ffi.metatype(\"ZMQ_Ctx\", _priv.ZMQ_Ctx)\n" "-- End \"ZMQ_Ctx\" FFI interface\n" "\n" @@ -2755,6 +3044,7 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return obj_type_ZMQ_StopWatch_push(self, this_flags1)\n" "end\n" "register_default_constructor(_pub,\"ZMQ_StopWatch\",_pub.ZMQ_StopWatch.start)\n" +"\n" "-- method: stop\n" "function _meth.ZMQ_StopWatch.stop(self)\n" " local self,this_flags1 = obj_type_ZMQ_StopWatch_delete(self)\n" @@ -2764,11 +3054,13 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return tonumber(usecs1)\n" "end\n" "_priv.ZMQ_StopWatch.__gc = _meth.ZMQ_StopWatch.stop\n" +"\n" +"_push.ZMQ_StopWatch = obj_type_ZMQ_StopWatch_push\n" "ffi.metatype(\"ZMQ_StopWatch\", _priv.ZMQ_StopWatch)\n" "-- End \"ZMQ_StopWatch\" FFI interface\n" "\n" "-- method: init\n" -"function _pub.zmq.init(io_threads1)\n" +"function _M.init(io_threads1)\n" " \n" " local rc_zmq_init_flags1 = OBJ_UDATA_FLAG_OWN\n" " local rc_zmq_init1\n" @@ -2778,8 +3070,9 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return obj_type_ZMQ_Ctx_push(rc_zmq_init1, rc_zmq_init_flags1)\n" "end\n" +"\n" "-- method: init_ctx\n" -"function _pub.zmq.init_ctx(ptr1)\n" +"function _M.init_ctx(ptr1)\n" " local ctx1\n" " local p_type = type(ptr1)\n" " if p_type == 'userdata' then\n" @@ -2795,9 +3088,10 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " end\n" " return obj_type_ZMQ_Ctx_push(ctx1, 0)\n" "end\n" +"\n" "-- method: device\n" "if (VERSION_2_0) then\n" -"function _pub.zmq.device(device1, insock2, outsock3)\n" +"function _M.device(device1, insock2, outsock3)\n" " \n" " \n" " \n" @@ -2810,19 +3104,22 @@ static const char zmq_ffi_lua_code[] = "local ffi=require\"ffi\"\n" " return true\n" "end\n" "end\n" +"\n" "-- method: stopwatch_start\n" -"function _pub.zmq.stopwatch_start()\n" +"function _M.stopwatch_start()\n" " local rc_zmq_stopwatch_start_flags1 = OBJ_UDATA_FLAG_OWN\n" " local rc_zmq_stopwatch_start1\n" " rc_zmq_stopwatch_start1 = C.zmq_stopwatch_start()\n" " return obj_type_ZMQ_StopWatch_push(rc_zmq_stopwatch_start1, rc_zmq_stopwatch_start_flags1)\n" "end\n" +"\n" "-- method: sleep\n" -"function _pub.zmq.sleep(seconds_1)\n" +"function _M.sleep(seconds_1)\n" " \n" " C.zmq_sleep(seconds_1)\n" " return \n" "end\n" +"\n" ""; static char *zmq_ZErrors_key = "zmq_ZErrors_key"; /* @@ -4172,7 +4469,7 @@ static int ZMQ_Socket__recv__meth(lua_State *L) { if(0 == err2) { /* receive message */ err2 = zmq_recvmsg(this1, &msg, flags2); - if(0 == err2) { + if(err2 >= 0) { data1 = zmq_msg_data(&msg); data_len1 = zmq_msg_size(&msg); } @@ -6305,9 +6602,9 @@ static const reg_sub_module reg_sub_modules[] = { #if LUAJIT_FFI static const ffi_export_symbol zmq_ffi_export[] = { -{ "zmq_sendmsg", zmq_sendmsg }, -{ "zmq_recvmsg", zmq_recvmsg }, - {NULL, NULL} +{ "zmq_sendmsg", { .func = (ffi_export_func_t)zmq_sendmsg } }, +{ "zmq_recvmsg", { .func = (ffi_export_func_t)zmq_recvmsg } }, + {NULL, { .data = NULL } } }; #endif diff --git a/src/socket.nobj.lua b/src/socket.nobj.lua index 6205c8e..0981646 100644 --- a/src/socket.nobj.lua +++ b/src/socket.nobj.lua @@ -693,7 +693,7 @@ local tmp_msg = ffi.new('zmq_msg_t') if(0 == ${err}) { /* receive message */ ${err} = zmq_recvmsg(${this}, &msg, ${flags}); - if(0 == ${err}) { + if(${err} >= 0) { ${data} = zmq_msg_data(&msg); ${data_len} = zmq_msg_size(&msg); } @@ -712,7 +712,7 @@ local tmp_msg = ffi.new('zmq_msg_t') -- receive message ${err} = zmq_recvmsg(${this}, msg, ${flags}) - if 0 == ${err} then + if ${err} >= 0 then local data = ffi.string(C.zmq_msg_data(msg), C.zmq_msg_size(msg)) -- close message C.zmq_msg_close(msg)