lua-users home
lua-l archive

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


On Wed, Feb 16, 2011 at 9:09 AM, Mike Pall <mikelu-1102@mike.de> wrote:
>> i can haz?
>
> Only if I find a good place for it in the API. Maybe a special
> type for ffi.cast.

sounds good, that was the first place i looked for it

> If you're already using the FFI, then a void pointer is exactly
> what you want. You can't dereference a void pointer or do pointer
> arithmetic with it.



>> also, FFI does cast the lightuserdata back to the same pointer.  how
>> could i do it with a number?  i would have to store the boxed pointer
>> somewhere, right?  (update: i see there's a conversion between C
>> number and pointer, i'll play a little with the uintptr_t cast)
>
> See the tutorial. And use intptr_t, the conversion is faster.

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

-----------------------------

i'll have to try that.   thanks!


-- 
Javier