lua-users home
lua-l archive

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


Hi,

I'm thinking about using LuaJIT's FFI in the next lupa release to provide access to CPython's buffer interface. This would allow direct low-level access to NumPy matrices and the like, thus providing an efficient Lua companion for the huge set of scientific computation libraries in SciPy, Sage and the like.

Now, these buffers are basically represented as a struct containing a void* together with layout meta data, and it's up to the code that uses them to cast the pointer to the appropriate item type. This cannot be handled transparently inside of lupa, as only the user code will know the correct type to use. So I'm wondering how to best design the interface here. 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.

Is there a way to cast a void pointer in LuaJIT-FFI code?

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?

I'm also missing an example of how to actually inject C pointers into the FFI using code. Does the FFI automatically dereference (light)userdata objects, for example?

Stefan