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
6 changes: 3 additions & 3 deletions examples/define-exe.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Bippity = struct { A: ?i32, B: *bool, C: []const u8, D: ?*SubType };
const TestType = struct { a: i32, b: f32, c: bool, d: SubType, e: [10]Bippity };
const Foo = struct { far: MyEnum, near: SubType };

pub fn main() !void {
const output_file_path = std.mem.sliceTo(std.os.argv[1], 0);
try zlua.define(std.heap.c_allocator, output_file_path, &.{ T, TestType, Foo });
pub fn main(init: std.process.Init) !void {
const output_file_path = std.mem.sliceTo(init.minimal.args.vector[1], 0);
try zlua.define(init.io, std.heap.c_allocator, output_file_path, &.{ T, TestType, Foo });
}
16 changes: 7 additions & 9 deletions src/define.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub const DefineState = struct {
};

pub fn define(
io: std.Io,
gpa: std.mem.Allocator,
absolute_output_path: []const u8,
comptime to_define: []const type,
Expand All @@ -33,21 +34,18 @@ pub fn define(
defer state.deinit(gpa);

inline for (to_define) |T| {
_ = try addClass(&state, T);
_ = try addClass(&state, gpa, T);
}

var file = try std.fs.createFileAbsolute(absolute_output_path, .{});
defer file.close();
var file = try std.Io.Dir.createFileAbsolute(io, absolute_output_path, .{});
defer file.close(io);

try file.seekTo(0);
try file.writeAll(file_header);
try file.writeStreamingAll(io, file_header);

for (state.definitions.items) |def| {
try file.writeAll(def.items);
try file.writeAll("\n");
try file.writeStreamingAll(io, def.items);
try file.writeStreamingAll(io, "\n");
}

try file.setEndPos(try file.getPos());
}

const file_header: []const u8 =
Expand Down