The project is a ffi library for calling c functions, using c data structures, in pure lua environment. It also supports calling lua function from c functions. It's ported from luajit-ffi and is originally from https://github.com/facebookarchive/luaffifb . I copy it from https://github.com/dibyendumajumdar/ravi-ffi. You can get some tutorials from the luajit ffi page.
Comparing with standard lua c call, it can make up up to 75% in performance. Slower than luajit-ffi though,
this is a lot better than libffi.
But there's still some change from the original lua ffi library:
- from lua 5.3, int64 result is passed as an integer from c call except for intptr_t type.
- ffi.i64 and ffi.u64 are no longer available since lua 5.3 .
- libgcc is not available on Android.
- cdata array can be iterated by ipairs or pairs and its length can be retrieved by # operator now.
- ffi.metatype should be called once you change any metafield of the metatable for the ctype.Note that the metatable won't be kept by the type.I use another table to store metafields.
- more detailed error message.
- several bugs are fixed.
Some known issues:
- cdata doesn't equal to any lua value by operator '==' .
- complex number must be declared by ffi.new or ffi.cast.
- unsupported bit operation.
- struct/union/complex values passed by value in variadic procedure is unsupported.
- gcc extension vector type is unsupported.
__atrribte__((aligned))
use gcc definition rather than the clang one.- for msvc, the c runtime for the project and the lua.dll must be the same, or else cast for lua FILE object to c FILE object won't work because msvcrt.dll doesn't compat with ucrtbase.dll
To build it for systems other than Android, cd src/main/cpp
and run cmake ./ && make
.