mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-09 12:07:27 +00:00
Warn users when calling textFormat with a non-tuple type
This commit is contained in:
parent
43d15b05c2
commit
c5ce02c084
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
zig-cache/
|
zig-cache/
|
||||||
|
.zig-cache/
|
||||||
zig-out/
|
zig-out/
|
||||||
.idea/
|
.idea/
|
||||||
Project/*
|
Project/*
|
||||||
|
@ -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 {
|
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));
|
return std.mem.span(@call(.auto, cdef.TextFormat, .{@as([*c]const u8, @ptrCast(text))} ++ args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
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));
|
return std.mem.span(@call(.auto, cdef.TextFormat, .{@as([*c]const u8, @ptrCast(text))} ++ args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user