From 12f588a6368ed26f8f274f4950a1c586f469e812 Mon Sep 17 00:00:00 2001 From: "Robert G. Jakabosky" Date: Sun, 27 Feb 2011 18:58:02 -0800 Subject: [PATCH] Fixed context initialization from FFI cdata value. --- zmq.nobj.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/zmq.nobj.lua b/zmq.nobj.lua index c5923ae..a55f990 100644 --- a/zmq.nobj.lua +++ b/zmq.nobj.lua @@ -149,15 +149,18 @@ c_function "init_ctx" { if(lua_isuserdata(L, ${ptr::idx})) { ${ctx} = lua_touserdata(L, ${ptr::idx}); } else { - /* check if value is a LuaJIT 'cdata' */ - int type = lua_type(L, ${ptr::idx}); - const char *typename = lua_typename(L, type); - if(strncmp(typename, "cdata", sizeof("cdata")) == 0) { - ${ctx} = (void *)lua_topointer(L, ${ptr::idx}); - } else { - return luaL_argerror(L, ${ptr::idx}, "(expected userdata)"); - } + return luaL_argerror(L, ${ptr::idx}, "expected lightuserdata"); } +]], + ffi_source[[ + local p_type = type(${ptr}) + if p_type == 'userdata' then + ${ctx} = ffi.cast('void *', ${ptr}); + elseif p_type == 'cdata' then + ${ctx} = ${ptr}; + else + return error("expected lightuserdata/cdata"); + end ]], }, c_function "device" {