Skip to content
Browse files

Fix convertion of Ctx from cdata to lightuserdata for passing to sub-…

…threads.
  • Loading branch information...
1 parent 5423280 commit 052d18ffb2c07b56da33bee30b51132fb1eeb182 @Neopallium Neopallium committed Nov 30, 2011
Showing with 15 additions and 5 deletions.
  1. +12 −2 src/ctx.nobj.lua
  2. +3 −3 zmq.nobj.lua
View
14 src/ctx.nobj.lua
@@ -19,17 +19,27 @@
-- THE SOFTWARE.
object "ZMQ_Ctx" {
+ sys_include"string.h",
error_on_null = "get_zmq_strerror()",
c_source [[
typedef struct ZMQ_Ctx ZMQ_Ctx;
]],
destructor "term" {
c_method_call "ZMQ_Error" "zmq_term" {}
},
- method "lightuserdata" {
+ method "lightuserdata" { override_this = true,
+ var_in{ "<any>", "this" },
var_out{ "void *", "ptr" },
c_source[[
- ${ptr} = ${this};
+ if(lua_isuserdata(L, ${this::idx})) {
+ ${ptr} = lua_touserdata(L, ${this::idx});
+ } else {
+ /* check for LuaJIT's cdata. */
+ int tp = lua_type(L, ${this::idx});
+ if(strncmp("cdata", lua_typename(L, tp), 5) == 0) {
+ ${ptr} = *((void **)lua_topointer(L, ${this::idx}));
+ }
+ }
]]
},
method "socket" {
View
6 zmq.nobj.lua
@@ -145,9 +145,9 @@ c_function "init_ctx" {
ffi_source[[
local p_type = type(${ptr})
if p_type == 'userdata' then
- ${ctx} = ffi.cast('void *', ${ptr});
- elseif p_type == 'cdata' then
- ${ctx} = ${ptr};
+ ${ctx} = ffi.cast('ZMQ_Ctx *', ${ptr});
+ elseif p_type == 'cdata' and ffi.istype('void *', ${ptr}) then
+ ${ctx} = ffi.cast('ZMQ_Ctx *', ${ptr});
else
return error("expected lightuserdata/cdata<void *>");
end

0 comments on commit 052d18f

Please sign in to comment.
Something went wrong with that request. Please try again.