[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaJIT FFI: pointer<->lightuserdata ?
- From: Mike Pall <mikelu-1102@...>
- Date: Wed, 16 Feb 2011 17:23:53 +0100
Javier Guerra Giraldez wrote:
> so, the whole cycle would be like:
>
> ffi.cdef [[
> struct foo { int a, b; };
>
> struct foo *find_some_foo (...);
> void use_foo(struct foo *p);
> ]]
>
> p = ffi.C.findsome_foo(....) -- p is a boxed pointer
> x = tonumber(ffi.cast("intptr_t", p)) -- get a Lua number..
>
> callbacks[x] = function(p) -- to use as a table index
> ffi.C.use_foo (p)
> end
>
> --- some other part
>
> 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]).
--Mike