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
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
- name: Run tests
run: make test_zig_nightly

#------ zig-0.14 ------
test_zig_014:
#------ zig-0.15 ------
test_zig_015:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm]
Expand All @@ -42,10 +42,10 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: "0.14.1"
version: "0.15.1"

- name: Run tests
run: make test_zig_014
run: make test_zig_stable

#------ cross compilation ------
test_cross:
Expand Down
4 changes: 3 additions & 1 deletion build/patch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub fn main() !void {
const patch_file = patch_file: {
const patch_file = try std.fs.cwd().openFile(patch_file_path, .{ .mode = .read_only });
defer patch_file.close();
break :patch_file try patch_file.readToEndAlloc(allocator, std.math.maxInt(usize));
var buf: [4096]u8 = undefined;
var reader = patch_file.reader(&buf);
break :patch_file try reader.interface.allocRemaining(allocator, .unlimited);
};
const chunk_details = Chunk.init(allocator, patch_file, 0) orelse @panic("No chunk data found");

Expand Down
42 changes: 14 additions & 28 deletions examples/interpreter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,23 @@ const zlua = @import("zlua");
const ReadError = error{BufferTooSmall};

fn readlineStdin(out_buf: []u8) anyerror!usize {
const builtin = @import("builtin");
// Backwards compatibility with zig-0.14
// TODO remove when zig-0.15 is released
if (builtin.zig_version.major == 0 and builtin.zig_version.minor < 15) {
var stdin = std.io.getStdIn().reader();
return try stdin.read(out_buf);
} else {
var in_buf: [4096]u8 = undefined;
var stdin_file = std.fs.File.stdin().reader(&in_buf);
const stdin = &stdin_file.interface;
const s = try stdin.takeDelimiterExclusive('\n');
if (s.len < out_buf.len) {
@memcpy(out_buf[0..s.len], s);
return s.len;
}
return error.BufferTooSmall;
var in_buf: [4096]u8 = undefined;
var stdin_file = std.fs.File.stdin().reader(&in_buf);
const stdin = &stdin_file.interface;
const s = try stdin.takeDelimiterExclusive('\n');
if (s.len < out_buf.len) {
@memcpy(out_buf[0..s.len], s);
return s.len;
}
return error.BufferTooSmall;
}

fn flushedStdoutPrint(comptime fmt: []const u8, args: anytype) !void {
const builtin = @import("builtin");
// Backwards compatibility with zig-0.14
// TODO remove when zig-0.15 is released
if (builtin.zig_version.major == 0 and builtin.zig_version.minor < 15) {
try std.io.getStdOut().writer().print(fmt, args);
} else {
var out_buf: [4096]u8 = undefined;
var w = std.fs.File.stdout().writer(&out_buf);
const stdout = &w.interface;
try stdout.print(fmt, args);
try stdout.flush();
}
var out_buf: [4096]u8 = undefined;
var w = std.fs.File.stdout().writer(&out_buf);
const stdout = &w.interface;
try stdout.print(fmt, args);
try stdout.flush();
}

pub fn main() anyerror!void {
Expand Down Expand Up @@ -68,6 +53,7 @@ pub fn main() anyerror!void {
try flushedStdoutPrint("error: line too long!\n", .{});
continue;
},
error.EndOfStream => break,
else => return err,
}
};
Expand Down
5 changes: 3 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ test_zig_nightly:

zig build -Dlang=luajit

# A subset of tests that are expected to work also on zig-0.14
test_zig_014:
# A subset of tests that are expected to work also on stable builds of zig
test_zig_stable:
zig build test --summary failures -Dlang=lua51
zig build test --summary failures -Dlang=lua52
zig build test --summary failures -Dlang=lua53
zig build test --summary failures -Dlang=lua54
Expand Down
8 changes: 4 additions & 4 deletions src/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2987,16 +2987,16 @@ test "define" {
_ = try zlua.def.addClass(&state, a, my_type);
}

var buffer: [10000]u8 = .{0} ** 10000;
var buffer_stream = std.io.fixedBufferStream(&buffer);
var writer = buffer_stream.writer();
var buffer: [10000]u8 = @splat(0);
var writer: std.Io.Writer = .failing;
writer.buffer = &buffer;

for (state.definitions.items) |def| {
try writer.writeAll(def.items);
try writer.writeAll("\n");
}

try std.testing.expectEqualSlices(u8, expected, buffer_stream.getWritten());
try std.testing.expectEqualSlices(u8, expected, buffer[0..writer.end]);
}

test "interrupt" {
Expand Down
Loading