Skip to content

Commit 046bc13

Browse files
committed
Upgrade to Zig 0.15.1 and track Zig latest stable on main instead of nightly
1 parent 5950508 commit 046bc13

11 files changed

Lines changed: 89 additions & 45 deletions

File tree

.github/workflows/tests-ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: (Z) Install Zig
2121
uses: mlugg/setup-zig@v2
2222
with:
23-
version: 0.15.0-dev.565+8e72a2528
23+
version: 0.15.1
2424

2525
- name: Run tests
2626
shell: bash

.github/workflows/tests-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: (Z) Install Zig
2121
uses: mlugg/setup-zig@v2
2222
with:
23-
version: 0.15.0-dev.565+8e72a2528
23+
version: 0.15.1
2424

2525
- name: ▶️ Run tests
2626
shell: pwsh

LICENSE

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
Copyright (c) 2025 Theodore Sackos
22

3-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
4-
files (the " Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
5-
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
6-
is furnished to do so, subject to the following conditions:
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
software and associated documentation files (the " Software"), to deal in the Software
5+
without restriction, including without limitation the rights to use, copy, modify,
6+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
permit persons to whom the Software is furnished to do so, subject to the following
8+
conditions:
79

8-
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial
9-
portions of the Software.
10+
The above copyright notice and this permission notice (including the next
11+
paragraph) shall be included in all copies or substantial portions of the Software.
1012

11-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
12-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13-
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
14-
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
17+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18+
USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ checks in `Debug` and `ReleaseSafe` builds and provides full test coverage of th
2323

2424
## Zig Version
2525

26-
The `main` branch targets recent builds of Zig's `master` branch (last tested with Zig `0.15.0-dev.565+8e72a2528`).
26+
The `main` branch targets the latest stable Zig version. Currently `0.15.1`.
27+
28+
For other Zig versions look for branches with the named version.
2729

2830
## Installation & Usage
2931

build.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ pub fn build(b: *std.Build) void {
1818
.optimize = optimize,
1919
});
2020

21-
const lib = b.addStaticLibrary(.{
21+
const lib = b.addLibrary(.{
2222
.name = "luajit",
23+
.linkage = .static,
2324
.root_module = lib_mod,
2425
});
2526
lib.root_module.addImport("c", luajit_build);

build.zig.zon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.{
22
.name = .luajit,
33
.fingerprint = 0xda4bba66d285c19c,
4-
.version = "2.0.0",
4+
.version = "2.1.0",
55
.dependencies = .{
66
.luajit_build = .{
7-
.url = "git+https://github.com/sackosoft/zig-luajit-build#d75c20acaa4df39f51187926fa9d98e4e5231064",
8-
.hash = "luajit_build-1.1.4-HFjoU14-AACEEcPwP8nRnDSLS3EByuR8u5ZWAXBq08PH",
7+
.url = "git+https://github.com/sackosoft/zig-luajit-build#1664f2be707feccf4191fb8c6c6dff9ac2bd6edb",
8+
.hash = "luajit_build-1.1.6-HFjoU9xAAAANlxEGfin2P8D_sVc-AHtqKC6Fg8WWztZN",
99
},
1010
},
1111
.paths = .{

examples/simple-repl/LAST_TESTED_WITH_ZIG_VERSION.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/simple-repl/README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
1+
# simple-repl
2+
3+
This sample application is provided to demonstrate the functionality of the the `zig-luajit` bindings.
4+
It creates a Read-Evaluate-Print Loop (REPL) which reads a line of Lua code as input from the user,
5+
evaluates the expression and prints the result to the output.
6+
7+
## Version
8+
9+
Last tested with Zig version `0.15.1`.
10+
11+
## Usage
12+
113
Usage instructions:
214

3-
* Build the repl with `zig build` -- ensure your current working directory is within `zig-luajit/examples/simple-repl`.
4-
* Run the executable with `zig-luajit/examples/simple-repl/zig-out/bin/simple-repl`.
5-
* Use `print()` to make Lua print the value to standard output.
6-
- The `simple-repl` does not do any output itself.
15+
* Ensure your current working directory is `zig-luajit/examples/simple-repl`.
16+
* Use `zig build run` to run the application.
17+
* Use `print()` to write Lua values to standard output. The REPL does not do any output itself.
18+
* Use `exit` or `quit` or `Ctrl+C` to stop.
19+
20+
## Example Output
21+
22+
Here's a sample of running the interpreter:
23+
24+
```
25+
~/repos/zig-luajit/examples/simple-repl > zig build run
26+
> print('Hello, world!')
27+
Hello, world!
28+
> print(1 + 1)
29+
2
30+
> f = function() print("Yes, even functions work too") end
31+
> f()
32+
Yes, even functions work too
33+
> exit
34+
~/repos/zig-luajit/examples/simple-repl >
35+
```

examples/simple-repl/main.zig

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,35 @@ pub fn main() !void {
1414

1515
lua.openBaseLib();
1616

17-
const stdin = std.io.getStdIn();
18-
const stdout = std.io.getStdOut();
17+
var stdin_buffer: [1024]u8 = undefined;
18+
var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer);
19+
const stdin = &stdin_reader.interface;
1920

20-
var buf: [1025]u8 = undefined;
21-
const read_slice = buf[0..1024];
21+
var stdout_buffer: [1024]u8 = undefined;
22+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
23+
const stdout = &stdout_writer.interface;
24+
25+
var line_buffer: [1025]u8 = undefined;
2226

2327
while (true) {
2428
try stdout.writeAll("> ");
29+
try stdout.flush();
30+
31+
var line_writer = std.Io.Writer.fixed(&line_buffer);
32+
const input_len = try stdin.streamDelimiterLimit(&line_writer, '\n', std.Io.Limit.limited(1024));
33+
if (input_len == 0) continue;
2534

26-
const input = try stdin.reader().readUntilDelimiter(read_slice, '\n');
27-
if (input.len == 0) continue;
35+
// Throw away the `\n` on the input.
36+
stdin.toss(1);
2837

29-
if (std.mem.eql(u8, input, "exit")) break;
38+
// Replace the `\n` terminated string with a null terminated (`\0`) string.
39+
line_buffer[input_len] = '\u{0}';
40+
const input = line_buffer[0..input_len :0];
3041

31-
buf[input.len] = 0;
32-
const actual = buf[0..input.len :0];
42+
if (std.mem.eql(u8, input[0..4], "exit")) break;
43+
if (std.mem.eql(u8, input[0..4], "quit")) break;
3344

34-
lua.doString(actual) catch |err| {
45+
lua.doString(input) catch |err| {
3546
std.debug.print("Error: {}\n", .{err});
3647
continue;
3748
};

src/allocator_adapter.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub const AllocFn = fn (
1515
ptr: ?*anyopaque,
1616
osize: usize,
1717
nsize: usize,
18-
) callconv(.C) ?*align(max_alignment_bytes) anyopaque;
18+
) callconv(.c) ?*align(max_alignment_bytes) anyopaque;
1919

2020
/// Memory allocation function used by Lua instances. This functino acts as an adaptor from the C API to the
2121
/// idiomatic Zig `std.mem.Allocator` type. The implementation provides functionality similar to realloc.
@@ -37,7 +37,7 @@ pub const AllocFn = fn (
3737
///
3838
/// From: `void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);`
3939
/// Refer to: https://www.lua.org/manual/5.1/manual.html#lua_Alloc
40-
pub fn alloc(ud: ?*anyopaque, ptr: ?*anyopaque, osize: usize, nsize: usize) callconv(.C) ?*align(max_alignment_bytes) anyopaque {
40+
pub fn alloc(ud: ?*anyopaque, ptr: ?*anyopaque, osize: usize, nsize: usize) callconv(.c) ?*align(max_alignment_bytes) anyopaque {
4141
std.debug.assert(ud != null);
4242

4343
const user_data: *AllocationUserdata = @ptrCast(@alignCast(ud.?));

0 commit comments

Comments
 (0)