FFI Basics: ffi.cdef and ffi.load
Declare C types and load shared libraries with LuaJIT's ffi module.
What Is the FFI?
LuaJIT's FFI (Foreign Function Interface) lets you call C library functions and use C data structures directly from Lua, with no C wrapper code needed.
Requiring the FFI
Load the FFI library with require("ffi"). It is built into LuaJIT and not available in standard PUC Lua.
local ffi = require("ffi")All lessons in this course
- FFI Basics: ffi.cdef and ffi.load
- Calling C Functions via FFI
- Pointers, Structs, and Arrays in FFI
- Callbacks: Passing Lua Functions to C