Warn users when calling textFormat with a non-tuple type

This commit is contained in:
Not-Nik 2024-06-17 21:00:42 +02:00
parent 43d15b05c2
commit c5ce02c084
No known key found for this signature in database
GPG Key ID: E95F679E3CDD9784
3 changed files with 27 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
zig-cache/
.zig-cache/
zig-out/
.idea/
Project/*

View File

@ -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));
}

View File

@ -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));
}