Re: A way to associate a Lua value with a FFI pointer?

  • From: Alex <initrd.gz@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 9 Apr 2014 17:10:17 -0400

A better way of describing it: pointer cdata objects are
pointers-to-pointers.

This is because LuaJIT stores only references to cdata objects, similar to
tables, userdata, functions, etc. A "void*" cdata object is simply a
structure that holds a void* pointer. Thus, you have a reference to a cdata
object that holds a pointer. LuaJIT is free to allocate different cdata
'containers' that point to the same pointer. Printing them prints the
cdata's address, and not the address to which the cdata points.


On Wed, Apr 9, 2014 at 9:23 AM, Javier Guerra Giraldez
<javier@xxxxxxxxxxx>wrote:

> On Wed, Apr 9, 2014 at 4:51 AM, Daniel Kolesa <quaker66@xxxxxxxxx> wrote:
> > Yes, I know this. But that's not relevant in my case and the cases you're
> > showing do not happen in my particular situation :)
>
>
> as soon as you pass one of these pointers through a C function, or via
> some kind of non-Lua-value channel, you'll get a different instance of
> "the same" pointer, with a different cdata address and resolving to a
> different hash slot.
>
> it's safer to cast it to some Lua value.
>
> --
> Javier
>
>


-- 
Sincerely,
Alex Parrill

Other related posts: