Zero-Cost Handshake Between C and Lua: Anatomy of the FFI Subsystem
LuaJIT lets you call C functions, access C structs, and implement callbacks without writing C glue code. Learn how the FFI subsystem bridges two worlds with near-zero overhead.
7 posts
LuaJIT lets you call C functions, access C structs, and implement callbacks without writing C glue code. Learn how the FFI subsystem bridges two worlds with near-zero overhead.
LuaJIT's garbage collector runs concurrently with your code, never stopping the world for long. Learn how the tri-color invariant and write barriers make incremental GC possible.
LuaJIT's optimizer fits in 2653 lines yet handles constant folding, algebraic simplification, CSE, and more. Learn how the FOLD engine uses a semi-perfect hash table generated at build time.
Every LuaJIT compiler pass speaks the same language — SSA IR. Learn how the IRIns structure, 120 opcodes, and strict SSA form enable LuaJIT's powerful optimizations.
Every Lua value fits in 8 bytes. Learn how NaN-boxing exploits IEEE 754's unused NaN bit patterns to encode an entire type system in a single double.
V8 compiles entire functions; LuaJIT compiles a single path through them. Why tracing JIT's 'precision strike' approach wins for dynamic languages — and how mmap + mprotect makes it real.
LuaJIT runs on 7 CPU architectures with hand-written assembly — written once. Learn how DynASM bridges C and assembly by building a minimal bytecode interpreter from scratch.