RE: Making FFI callbacks call free() automatically when it's collected

  • From: William Adams <william_a_adams@xxxxxxx>
  • To: <luajit@xxxxxxxxxxxxx>
  • Date: Fri, 20 Jul 2012 04:50:13 +0000

I did the pointer thing like the following, to try and be somewhat size 


function PointerToString(instance)
 if ffi.abi("64bit") then
  return string.format("0x%016x", tonumber(ffi.cast("int64_t", ffi.cast("void 
*", instance))))
 elseif ffi.abi("32bit") then
  return string.format("0x%08x", tonumber(ffi.cast("int32_t", ffi.cast("void 
*", instance))))

 return nil


- Shaping clay is easier than digging it out of the ground.

> Yes, thanks for the suggestion. I now just use:
> local function cdata_addr(cd) return tonumber(ffi.cast("int", cd)) end
> to produce the address' value, and use that as the key internally, to
> avoid the problem of cdata objects not suitable as the key directly.
> best,
> Johnson

Other related posts: