Skip to content

qtiuto/luaffi

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

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:

  1. from lua 5.3, int64 result is passed as an integer from c call except for intptr_t type.
  2. ffi.i64 and ffi.u64 are no longer available since lua 5.3 .
  3. libgcc is not available on Android.
  4. cdata array can be iterated by ipairs or pairs and its length can be retrieved by # operator now.
  5. 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.
  6. more detailed error message.
  7. several bugs are fixed.

Some known issues:

  1. cdata doesn't equal to any lua value by operator '==' .
  2. complex number must be declared by ffi.new or ffi.cast.
  3. unsupported bit operation.
  4. struct/union/complex values passed by value in variadic procedure is unsupported.
  5. gcc extension vector type is unsupported.
  6. __atrribte__((aligned)) use gcc definition rather than the clang one.
  7. 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.

About

luaffi library for standard lua

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages