Pointers, Structs, and Arrays in FFI
Work with C pointers, struct types, and array allocations in FFI.
C Types in FFI
FFI supports all standard C types: int, float, double, char, pointers, arrays, and structs. Declare them in ffi.cdef.
Creating C Arrays
Allocate a C array with ffi.new("type[N]"). Access elements with 0-based indexing (C convention).
local ffi = require("ffi")
local arr = ffi.new("int[5]", {10, 20, 30, 40, 50})
print(arr[0], arr[1], arr[4]) -- 10 20 50All 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