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

  • From: "Robert G. Jakabosky" <bobby@xxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 19 Jul 2012 22:30:27 -0700

On Thursday 19, William Adams wrote:
> I did the pointer thing like the following, to try and be somewhat size
> conscious:
> function PointerToString(instance)
>  if ffi.abi("64bit") then
>   return string.format("0x%016x", tonumber(ffi.cast("int64_t", 
ffi.cast("void *", instance))))

I don't think this will guarantee preservation of all 64 bits of a pointer, 
since tonumber() will convert it to a double and only 52 bits of the integer 
will be preserved.

I think in most cases it will be fine, since the lost bits will be zero 

For table lookups I would use numbers instead of strings.

Robert G. Jakabosky

Other related posts: