From c5ce02c084ac55d18b973c677440fa9cc497c58e Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Mon, 17 Jun 2024 21:00:42 +0200 Subject: [PATCH] Warn users when calling textFormat with a non-tuple type --- .gitignore | 1 + lib/preludes/raylib-prelude.zig | 13 +++++++++++++ lib/raylib.zig | 13 +++++++++++++ 3 files changed, 27 insertions(+) diff --git a/.gitignore b/.gitignore index 45055c0..3c99eaa 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ zig-cache/ +.zig-cache/ zig-out/ .idea/ Project/* diff --git a/lib/preludes/raylib-prelude.zig b/lib/preludes/raylib-prelude.zig index 8abb929..85f2d7a 100755 --- a/lib/preludes/raylib-prelude.zig +++ b/lib/preludes/raylib-prelude.zig @@ -1852,6 +1852,19 @@ pub fn loadCodepoints(text: [:0]const u8) RaylibError![]i32 { } pub fn textFormat(text: [:0]const u8, args: anytype) [:0]const u8 { + comptime { + const info = @typeInfo(@TypeOf(args)); + switch (info) { + .Struct => { + if (!info.Struct.is_tuple) + @compileError("Args should be in a tuple (call this function like textFormat(.{arg1, arg2, ...});)!"); + }, + else => { + @compileError("Args should be in a tuple (call this function like textFormat(.{arg1, arg2, ...});)!"); + } + } + } + return std.mem.span(@call(.auto, cdef.TextFormat, .{@as([*c]const u8, @ptrCast(text))} ++ args)); } diff --git a/lib/raylib.zig b/lib/raylib.zig index 8f1279d..ce9ac17 100644 --- a/lib/raylib.zig +++ b/lib/raylib.zig @@ -1852,6 +1852,19 @@ pub fn loadCodepoints(text: [:0]const u8) RaylibError![]i32 { } pub fn textFormat(text: [:0]const u8, args: anytype) [:0]const u8 { + comptime { + const info = @typeInfo(@TypeOf(args)); + switch (info) { + .Struct => { + if (!info.Struct.is_tuple) + @compileError("Args should be in a tuple (call this function like textFormat(.{arg1, arg2, ...});)!"); + }, + else => { + @compileError("Args should be in a tuple (call this function like textFormat(.{arg1, arg2, ...});)!"); + } + } + } + return std.mem.span(@call(.auto, cdef.TextFormat, .{@as([*c]const u8, @ptrCast(text))} ++ args)); }