Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn build(b: *Build) void {
c_headers.step.dependOn(&install_lib.step);

const ziglua_c = c_headers.createModule();
b.modules.put("ziglua-c", ziglua_c) catch @panic("OOM");
b.modules.put(b.graph.arena, "ziglua-c", ziglua_c) catch @panic("OOM");

zlua.addImport("c", ziglua_c);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/interpreter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn flushedStdoutPrint(io: std.Io, comptime fmt: []const u8, args: anytype) !void
}

pub fn main() anyerror!void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
var gpa = std.heap.DebugAllocator(.{}){};
const allocator = gpa.allocator();
defer _ = gpa.deinit();

Expand Down
12 changes: 5 additions & 7 deletions examples/luau-bytecode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ const std = @import("std");
// The zlua module is made available in build.zig
const zlua = @import("zlua");

pub fn main() anyerror!void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer _ = gpa.deinit();
pub fn main(init: std.process.Init) anyerror!void {
const gpa = init.gpa;

// Initialize The Lua vm and get a reference to the main thread
//
// Passing a Zig allocator to the Lua state requires a stable pointer
var lua = try zlua.Lua.init(allocator);
var lua = try zlua.Lua.init(gpa);
defer lua.deinit();

// Open all Lua standard libraries
lua.openLibs();

// Load bytecode
const src = @embedFile("./test.luau");
const bc = try zlua.compile(allocator, src, zlua.CompileOptions{});
defer allocator.free(bc);
const bc = try zlua.compile(gpa, src, zlua.CompileOptions{});
defer gpa.free(bc);

try lua.loadBytecode("...", bc);
try lua.protectedCall(.{});
Expand Down
10 changes: 4 additions & 6 deletions examples/multithreaded.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ fn add_to_x(lua: *zlua.Lua, num: usize) void {
lua.protectedCall(.{}) catch return;
}

pub fn main() anyerror!void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer _ = gpa.deinit();
pub fn main(init: std.process.Init) anyerror!void {
const gpa = init.gpa;

// Initialize The Lua vm and get a reference to the main thread
var lua = try zlua.Lua.init(allocator);
var lua = try zlua.Lua.init(gpa);
defer lua.deinit();

lua.openLibs();
Expand All @@ -56,7 +54,7 @@ pub fn main() anyerror!void {

// create a thread pool to run all the functions
var pool: std.Thread.Pool = undefined;
try pool.init(.{ .allocator = allocator, .n_jobs = n_jobs });
try pool.init(.{ .allocator = gpa, .n_jobs = n_jobs });
defer pool.deinit();

var wg: std.Thread.WaitGroup = .{};
Expand Down
8 changes: 3 additions & 5 deletions examples/zig-fn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ fn adder(lua: *Lua) i32 {
return 1;
}

pub fn main() anyerror!void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer _ = gpa.deinit();
pub fn main(init: std.process.Init) anyerror!void {
const gpa = init.gpa;

// Initialize The Lua vm and get a reference to the main thread
var lua = try Lua.init(allocator);
var lua = try Lua.init(gpa);
defer lua.deinit();

// Push the adder function to the Lua stack.
Expand Down
10 changes: 4 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ const zlua = @import("zlua");

const Lua = zlua.Lua;

pub fn main() anyerror!void {
// Create an allocator
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer _ = gpa.deinit();
pub fn main(init: std.process.Init) anyerror!void {
// Get an allocator from juicy main
const gpa = init.gpa;

// Initialize the Lua vm
var lua = try Lua.init(allocator);
var lua = try Lua.init(gpa);
defer lua.deinit();

// Add an integer to the Lua stack and retrieve it
Expand Down
Loading