diff options
author | Sam Gross <colesbury@gmail.com> | 2015-08-17 23:03:23 +0300 |
---|---|---|
committer | Sam Gross <colesbury@gmail.com> | 2015-08-17 23:03:23 +0300 |
commit | dbbe3a6f29cb0153d5ae902237c6906f4ddf3f18 (patch) | |
tree | ed39a5f5c8834ebe95225dfc2e5af41efba5cdd0 | |
parent | edfa6df42677ef7e864d4e085badb057114d77e3 (diff) |
Update README.md
-rw-r--r-- | README.md | 33 |
1 files changed, 22 insertions, 11 deletions
@@ -1,7 +1,7 @@ About ----- This is a library for calling C function and manipulating C types from lua. It -is designed to be interface compatible with the FFI library in luajit (see +is designed to be interface compatible with the FFI library in LuaJIT (see http://luajit.org/ext_ffi.html). It can parse C function declarations and struct definitions that have been directly copied out of C header files and into lua source as a string. @@ -16,7 +16,7 @@ Platforms --------- Currently supported: - Linux x86/x64 -- OSX x86/x64 +- OS X x86/x64 Runs with both Lua 5.1 and Lua 5.2. @@ -24,13 +24,24 @@ Build ----- - Run `luarocks make` +Documentation +------------- +This library is designed to be source compatible with LuaJIT's FFI extension. The documentation at http://luajit.org/ext_ffi.html describes the API and semantics. + +Pointer Comparison +------------ +Use `ffi.NULL` instead of `nil` when checking for `NULL` pointers. +```lua + ffi.new('void *', 0) == ffi.NULL -- true +``` + Known Issues ------------ -- Comparing a ctype pointer to nil doesn't work the same as luajit. This is - unfixable with the current metamethod semantics. Instead use ffi.NULL +- Comparing a ctype pointer to `nil` doesn't work the same as in LuaJIT (see above). + This is unfixable with the current metamethod semantics. - Constant expressions can't handle non integer intermediate values (eg offsetof won't work because it manipulates pointers) -- Not all metamethods work with lua 5.1 (eg char* + number). This is due to +- Not all metamethods work with Lua 5.1 (eg char* + number). This is due to the way metamethods are looked up with mixed types in Lua 5.1. If you need this upgrade to Lua 5.2 or use boxed numbers (uint64_t and uintptr_t). - All bitfields are treated as unsigned (does anyone even use signed @@ -53,15 +64,15 @@ Boxed cdata types are pushed into lua as a userdata containing the struct cdata structure (which contains the struct ctype of the data as its header) followed by the boxed data. -The functions in ffi.c provide the cdata and ctype metatables and ffi.* +The functions in `ffi.C` provide the `cdata` and `ctype` metatables and ffi.* functions which manipulate these two types. C functions (and function pointers) are pushed into lua as a lua c function with the function pointer cdata as the first upvalue. The actual code is JITed using dynasm (see call_x86.dasc). The JITed code does the following in order: -1. Calls the needed unpack functions in ffi.c placing each argument on the HW stack -2. Updates errno -3. Performs the c call -4. Retrieves errno -5. Pushes the result back into lua from the HW register or stack +1. Calls the needed unpack functions in `ffi.C` placing each argument on the HW stack +2. Updates `errno` +3. Performs the C call +4. Retrieves `errno` +5. Pushes the result back into lua from the HW register or stack |