feat: upgrade to zig v0.15.1
note: emu crashes for unknown reason
This commit is contained in:
28
src/lib.zig
Normal file
28
src/lib.zig
Normal file
@@ -0,0 +1,28 @@
|
||||
pub const c = @cImport({
|
||||
@cDefine("SDL_DISABLE_OLD_NAMES", {});
|
||||
@cDefine("SDL_MAIN_HANDLED", {});
|
||||
|
||||
@cInclude("SDL3/SDL.h");
|
||||
@cInclude("SDL3/SDL_main.h");
|
||||
});
|
||||
|
||||
// https://github.com/castholm/zig-examples/blob/77a829c85b5ddbad673026d504626015db4093ac/opengl-sdl/main.zig#L200-L219
|
||||
pub inline fn errify(value: anytype) error{sdl_error}!switch (@typeInfo(@TypeOf(value))) {
|
||||
.bool => void,
|
||||
.pointer, .optional => @TypeOf(value.?),
|
||||
.int => |info| switch (info.signedness) {
|
||||
.signed => @TypeOf(@max(0, value)),
|
||||
.unsigned => @TypeOf(value),
|
||||
},
|
||||
else => @compileError("unerrifiable type: " ++ @typeName(@TypeOf(value))),
|
||||
} {
|
||||
return switch (@typeInfo(@TypeOf(value))) {
|
||||
.bool => if (!value) error.sdl_error,
|
||||
.pointer, .optional => value orelse error.sdl_error,
|
||||
.int => |info| switch (info.signedness) {
|
||||
.signed => if (value >= 0) @max(0, value) else error.sdl_error,
|
||||
.unsigned => if (value != 0) value else error.sdl_error,
|
||||
},
|
||||
else => comptime unreachable,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user