[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: LuaJIT FFI: pointer<->lightuserdata ?
- From: Javier Guerra Giraldez <javier@...>
- Date: Wed, 16 Feb 2011 12:06:41 -0500
On Wed, Feb 16, 2011 at 11:23 AM, Mike Pall <email@example.com> wrote:
>> for foop, cbak in pairs (callbacks) do
>> cback (foop) -- ??
> That doesn't look right. And I'm wondering what you really want to
> achieve ... do you need the pointers to be unique? Otherwise you
> could just place the pointers into an array, and later traverse it
> and call ffi.C.use_foo(array_of_ptrs[i]).
well, the loop wasn't the most representative part, and the stored
closure would do more than just call ffi.C.use_foo()
maybe something like: (pseudo-Lua-code, without needed FFI casts)
for i=1:n do
foop = ffi.C.create_foo()
callbacks[foop] = function () .... end
-- somewhere else
foop = ffi.C.find_some_foo()
the point is that i have a set of C objects, and a C function that
returns a pointer to one of these. I want to associate a Lua function
for each of these, so under 'normal' Lua/C API (not using FFI) i would
cast the returned pointer to a userdata and use it to fetch the
under FFI, casting to a number solves the keyability part, but then
the point is: can it be cast back to the same pointer? or should i
keep the boxed pointer?