0Pricing
Lua Academy · Lesson

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

  1. FFI Basics: ffi.cdef and ffi.load
  2. Calling C Functions via FFI
  3. Pointers, Structs, and Arrays in FFI
  4. Callbacks: Passing Lua Functions to C
← Back to Lua Academy