[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: using void* in LuaJIT2 FFI
- From: Mike Pall <mikelu-1102@...>
- Date: Sat, 12 Feb 2011 17:25:25 +0100
Stefan Behnel wrote:
> From the current documentation at
> which is more tutorial style than a reference, I cannot see how such
> a runtime cast would be supported.
Quoting, emphasis mine:
"This page gives a short introduction to the usage of the FFI
library. PLEASE USE THE FFI SUB-TOPICS IN THE NAVIGATION BAR TO
Please tell me what's unclear about this sentence.
> Is there a way to cast a void pointer in LuaJIT-FFI code?
I was under the impression that ffi.cast might be an intuitive
name for such a function, but you proved me wrong:
> OTOH, I could also imagine letting the user code provide the item
> type as a string so that lupa could generate corresponding FFI
> definition (C) code on the fly that simply defines the returned
> buffer struct with a pointer of the provided type (instead of using
> the original C declaration).
> Any comments here?
The first item in the glossary of
is pretty clear about that:
"... C type declaration (a Lua string)"
The whole point is to construct C types at runtime. In fact,
that's the only way to do it.
> I'm also missing an example of how to actually inject C pointers
> into the FFI using code.
Usually you'd get it as a return value from a C call.
> Does the FFI automatically dereference (light)userdata objects,
> for example?