From 3c89931a8ca5dea29a14e916ddc6b244b6de3f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20N=C3=A9meth?= Date: Thu, 28 Dec 2023 02:20:14 +0100 Subject: [PATCH 1/2] Change never mutated vars to consts Both are fine on 0.11.0 but 0.12.0-dev raises an error on build. --- build.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.zig b/build.zig index 7329786..c68032a 100755 --- a/build.zig +++ b/build.zig @@ -20,7 +20,7 @@ pub fn link( .target = target, .optimize = optimize, }); - var art = raylib.artifact("raylib"); + const art = raylib.artifact("raylib"); const target_os = exe.target.toTarget().os.tag; switch (target_os) { @@ -94,7 +94,7 @@ fn getModuleInternal(b: *std.Build) *std.Build.Module { pub const math = struct { pub fn getModule(b: *std.Build, comptime rl_path: []const u8) *std.Build.Module { - var raylib = rl.getModule(b, rl_path); + const raylib = rl.getModule(b, rl_path); return b.addModule("raylib-math", .{ .source_file = .{ .path = rl_path ++ "/lib/raylib-zig-math.zig" }, .dependencies = &.{.{ .name = "raylib-zig", .module = raylib }}, @@ -102,7 +102,7 @@ pub const math = struct { } fn getModuleInternal(b: *std.Build) *std.Build.Module { - var raylib = rl.getModuleInternal(b); + const raylib = rl.getModuleInternal(b); return b.addModule("raylib-math", .{ .source_file = .{ .path = "lib/raylib-zig-math.zig" }, .dependencies = &.{.{ .name = "raylib-zig", .module = raylib }}, @@ -179,8 +179,8 @@ pub fn build(b: *std.Build) !void { const examples_step = b.step("examples", "Builds all the examples"); - var raylib = rl.getModuleInternal(b); - var raylib_math = rl.math.getModuleInternal(b); + const raylib = rl.getModuleInternal(b); + const raylib_math = rl.math.getModuleInternal(b); for (examples) |ex| { if (target.getOsTag() == .emscripten) { From 5eeb74c9082168952a2de43baafc4815a07a31b6 Mon Sep 17 00:00:00 2001 From: seppelin Date: Sat, 6 Jan 2024 21:30:14 +0100 Subject: [PATCH 2/2] add default fontChars support --- lib/raylib-zig.zig | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/raylib-zig.zig b/lib/raylib-zig.zig index 491956a..3307661 100644 --- a/lib/raylib-zig.zig +++ b/lib/raylib-zig.zig @@ -542,7 +542,7 @@ pub const Font = extern struct { return rl.loadFontFromImage(image, key, firstChar); } - pub fn fromMemory(fileType: [:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { + pub fn fromMemory(fileType: [:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: ?[]i32) Font { return rl.loadFontFromMemory(fileType, fileData, fontSize, fontChars); } @@ -1281,14 +1281,20 @@ pub fn loadImagePalette(image: Image, maxPaletteSize: i32) []Color { return res; } -pub fn loadFontFromMemory(fileType: [:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { - var fileDataFinal = @as([*c]const u8, 0); - var fileDataLen: i32 = 0; +pub fn loadFontFromMemory(fileType: [:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: ?[]i32) Font { + var fileDataFinal: [*c]const u8 = 0; + var fileDataLen: c_int = undefined; if (fileData) |fileDataSure| { - fileDataFinal = @as([*c]const u8, @ptrCast(fileDataSure)); - fileDataLen = @as(i32, @intCast(fileDataSure.len)); + fileDataFinal = @ptrCast(fileDataSure); + fileDataLen = @intCast(fileDataSure.len); } - return cdef.LoadFontFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileDataFinal)), @as(c_int, @intCast(fileDataLen)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len))); + var fontCharsFinal: [*c]c_int = 0; + var fontCharsLen: c_int = undefined; + if (fontChars) |fontCharsSure| { + fontCharsFinal = @ptrCast(fontCharsSure); + fontCharsLen = @intCast(fontCharsSure.len); + } + return cdef.LoadFontFromMemory(@ptrCast(fileType), fileDataFinal, fileDataLen, fontSize, fontCharsFinal, fontCharsLen); } pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: i32) []GlyphInfo {