lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Feb 16, 2011 at 11:23 AM, Mike Pall <mikelu-1102@mike.de> wrote:
>> for foop, cbak in pairs (callbacks) do
>>     cback (foop)        -- ??
>> end
>
> 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
end

-- somewhere else

foop = ffi.C.find_some_foo()
callbacks[foop](...)

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
function.

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?

-- 
Javier