sackosoft/zig-luajit-build
A package to compile LuaJIT using the Zig toolchain. Install to access the LuaJIT C API. For Zig API see https://github.com/sackosoft/zig-luajit
538a82133ad6fddfd0ca64de167c4aca3bc1a2da
LuaJIT is a fork from the Lua project -- "Lua is a powerful, efficient, lightweight, embeddable scripting language."
This package does not contain Zig language bindings to the C API. This package only handles building and linking the LuaJIT library into a Zig application.
If you're looking to run Lua on LuaJIT in your Zig application, you're probably looking for one of these projects:
zig-luajit-build
.The main
branch targets Zig's master
(nightly) deployment (last tested with 0.15.0-dev.565+8e72a2528
).
Install using zig fetch
. This will add a luajit_build
dependency to your build.zig.zon
file.
zig fetch --save=luajit_build git+https://github.com/sackosoft/zig-luajit-build
Next, in order for your code to import the LuaJIT C API, you'll need to update your build.zig
to:
luajit-build
dependency which was added by zig fetch.luajit-build
module, containing the native LuaJIT C API.// (1) Reference the dependency
const luajit_build_dep = b.dependency("luajit_build", .{
.target = target,
.optimize = optimize,
.link_as = .static // Or .dynamic to link as a shared library
});
// (2) Reference the module containing the LuaJIT C API.
const luajit_build = luajit_build_dep.module("luajit-build");
// Set up your library or executable
const lib = // ...
const exe = // ...
// (3) Add the module as an import, available via `@import("c")`, or any other name you choose here.
lib.root_module.addImport("c", luajit_build);
// Or
exe.root_module.addImport("c", luajit_build);
Now the code in your library or executable can import and access the LuaJIT C API!
const c = @import("c"); // Access LuaJIT functions via 'c'
pub fn main() !void {
const state: ?*c.lua_State = c.luaL_newstate();
if (state) |L| {
c.luaL_openlibs(L);
c.luaL_dostring(
L,
\\ print("Hello, world!")
);
}
}
This package supports one configuration option, shown in the example above.
link_as
: Controls how LuaJIT is linked.static
: Build and link LuaJIT as a static library (default)..dynamic
: Build and link LuaJIT as a shared library.Some files in this repository were copied or adapted from the natecraddock/ziglua project. Any files copied or adapted from that project have a comment describing the attribution at the top. Such files are shared by Nathan Craddock under the MIT License in ziglua/license.
All other files are released under the MIT License in zig-luajit-build/LICENSE.