lua-users home
lua-l archive

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


Stefan Behnel wrote:
> From the current documentation at
> 
> http://luajit.org/ext_ffi.html
> 
> 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
  LEARN MORE."

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:

  http://luajit.org/ext_ffi_api.html#ffi_cast

> 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
  http://luajit.org/ext_ffi_api.html
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?

http://luajit.org/ext_ffi_semantics.html#convert_fromlua

--Mike