$ show natecraddock/ziglua
Ziglua is a Zig library providing idiomatic bindings to the Lua C API, supporting Lua versions 5.1 through 5.5, LuaJIT, and Luau. It compiles the chosen Lua runtime from source at build time and exposes nearly the entire C API through a safe, Zig-native interface. The library leverages Zig's features such as slices, enums, optionals, and error unions to reduce memory unsafety and improve ergonomics compared to raw C bindings. It also includes a set of higher-level utilities like `wrap` for converting Zig functions into Lua-callable closures, `Buffer` for efficient string construction, and `toAny`/`pushAny` for automatic Lua–Zig serialization of common types. Architecturally, Ziglua is a single Zig module (`zlua`) that can be imported by any Zig project. The build system (`build.zig`) handles fetching the Lua source code, applying necessary patches, and compiling it as a static or shared library. Bindings are generated via Zig's `translate-c` tool from the Lua C headers, with additional manual Zig wrappers in `src/lib.zig`. The project is well-tested across multiple platforms (Linux, macOS, Windows) and supports Lua version selection, allocator integration, and both embedded and shared-library usage. Ziglua is actively maintained against Zig's master branch, with documented API and a clear changelog.
The LLM identified 1 files worth highlighting for reuse:
Provides a `define()` function and `DefineState` that, given a list of Zig struct types, generates Lua type definition annotations (EmmyLua-style `---@class` and `---@field`). It uses comptime reflection to traverse struct fields, enums, nested types, and pointers, mapping them to Lua type names (e.g., `integer`, `string`, `boolean`, userdata). This module is self-contained (imports only `std`), demonstrates non-obvious Zig comptime metaprogramming, and can be easily extracted and reused in other projects that need to emit Lua type definitions from Zig schemas.