From 601c886f4b40d6a513563b5a883010633e52bf43 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Tue, 11 Mar 2025 16:30:50 +0900 Subject: Port to Zig 0.14.0 --- src/Window.zig | 9 +++++---- src/input.zig | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/Window.zig b/src/Window.zig index d5bb8e7..6771e21 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -44,13 +44,13 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { c.GLFWcursorposfun => struct { pub fn callback(window: ?*Impl, xpos: f64, ypos: f64) callconv(.C) void { - fun(@fieldParentPtr(Self, "pimpl", &window.?).*, xpos, ypos); + fun(@as(*const Self, @fieldParentPtr("pimpl", &window.?)).*, xpos, ypos); } }, c.GLFWkeyfun => struct { pub fn callback(window: ?*Impl, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void { - fun(@fieldParentPtr(Self, "pimpl", &window.?).*, + fun(@as(*const Self, @fieldParentPtr("pimpl", &window.?)).*, @enumFromInt(key), scancode, @enumFromInt(action), Mods.fromInt(mods)); } @@ -58,7 +58,7 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { c.GLFWmousebuttonfun => struct { pub fn callback(window: ?*Impl, button: c_int, action: c_int, mods: c_int) callconv(.C) void { - fun(@fieldParentPtr(Self, "pimpl", &window.?).*, + fun(@as(*const Self, @fieldParentPtr("pimpl", &window.?)).*, @enumFromInt(button), @enumFromInt(action), Mods.fromInt(mods)); } @@ -66,7 +66,8 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { c.GLFWwindowsizefun => struct { pub fn callback(window: ?*Impl, width: c_int, height: c_int) callconv(.C) void { - fun(@fieldParentPtr(Self, "pimpl", &window.?).*, width, height); + fun(@as(*const Self, @fieldParentPtr("pimpl", &window.?)).*, + width, height); } }, else => unreachable, diff --git a/src/input.zig b/src/input.zig index 31fda2e..2b22c9c 100644 --- a/src/input.zig +++ b/src/input.zig @@ -22,7 +22,7 @@ const endian = @import("builtin").target.cpu.arch.endian(); const c = @import("cimport.zig"); const std = @import("std"); -const keys = [_][]const u8{ +const keys = [_][:0]const u8{ // Printable keys "SPACE", "APOSTROPHE", "COMMA", "MINUS", "PERIOD", "SLASH", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "SEMICOLON", "EQUAL", @@ -45,7 +45,7 @@ const keys = [_][]const u8{ }; /// Keyboard key enumeration: https://www.glfw.org/docs/latest/group__keys.html -pub const Key = @Type(.{ .Enum = .{ +pub const Key = @Type(.{ .@"enum" = .{ .tag_type = c_int, .fields = blk: { var fields: [keys.len]EnumField = undefined; @@ -85,8 +85,8 @@ pub const Mods = packed struct { const integer: MaskInt = @intCast(mask); return @bitCast(Mask{ .integer = switch (endian) { - .Big => @bitReverse(integer), - .Little => integer, + .big => @bitReverse(integer), + .little => integer, }, }); } @@ -95,8 +95,8 @@ pub const Mods = packed struct { pub fn toInt(self: Mods) c_int { const integer = @as(Mask, @bitCast(self)).integer; return @intCast(switch (endian) { - .Big => @bitReverse(integer), - .Little => integer, + .big => @bitReverse(integer), + .little => integer, }); } }; -- cgit 1.4.1