Lua bindings for ggml built as a Lua C module (ggml.so).
This project now exposes ggml pointers as managed Lua userdata handles by default.
Current caveat:
- Lua callbacks are still intentionally blocked for ggml APIs that may invoke from worker threads (for example logging, abort hooks, scheduler eval callbacks, and custom ops). Calling back into a Lua state from ggml worker threads is not safe without a dedicated callback marshalling design.
- CMake >= 3.14
- C/C++ compiler toolchain
- Lua 5.4 runtime and development headers
- Python 3 (for wrapper generation)
clangCLI (for JSON AST parsing in the binding generator)
git submodule update --init --recursivecmake -S . -B build
cmake --build build -jRun the integration tests:
lua tests/test.lua
lua examples/gpt2.lua --helpOutputs:
build/ggml.so(Lua module)build/ggml/src/libggml.so(ggml shared library)build/generated/lua_ggml_bindings.c(auto-generated wrappers)
package.cpath = "./build/?.so;" .. package.cpath
local ggml = require("ggml")
local ctx = ggml.init(16 * 1024 * 1024)
assert(ctx ~= nil)
assert(ctx:is_owned())
-- Generated wrappers are also registered:
assert(type(ggml.permute) == "function")
local tensor = ggml.new_tensor_1d(ctx, ggml.TYPE_I32, 2)
tensor:set_data(string.pack("<i4i4", 10, 20))
assert(tensor:shape()[1] == 2)
ggml.free(ctx)
assert(ctx:is_null())Auto-generation is enabled by default through CMake option:
-DLUA_GGML_AUTO_BINDINGS=ONGenerator script:
tools/gen_lua_bindings.py
The generator intentionally skips signatures that are unsafe or not yet expressible through the current type mapper, and prints a skip summary during build.
It currently scans these headers:
ggml/include/ggml.hggml/include/ggml-alloc.hggml/include/ggml-backend.hggml/include/ggml-cpu.hggml/include/gguf.h
And conditionally scans additional backend headers when their corresponding ggml backend targets are built, such as CUDA, Metal, Vulkan, OpenCL, SYCL, RPC, BLAS, and other optional backends.
- This project: MIT (
LICENSE) - Vendored dependency: ggml under MIT (
ggml/LICENSE) - See
THIRD_PARTY_NOTICES.mdfor details