glfw: force init error type work around

This commit is contained in:
InKryption 2021-11-21 20:42:32 +01:00 committed by Stephen Gutekanst
parent 9f241b5109
commit 44fee8f1f1
10 changed files with 67 additions and 69 deletions

View file

@ -65,7 +65,7 @@ pub inline fn create(image: Image, xhot: isize, yhot: isize) error{ PlatformErro
const img = image.toC(); const img = image.toC();
const cursor = c.glfwCreateCursor(&img, @intCast(c_int, xhot), @intCast(c_int, yhot)); const cursor = c.glfwCreateCursor(&img, @intCast(c_int, xhot), @intCast(c_int, yhot));
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return Cursor{ .ptr = cursor.? }; return Cursor{ .ptr = cursor.? };
@ -86,7 +86,7 @@ pub inline fn createStandard(shape: Shape) error{ InvalidEnum, PlatformError }!C
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
// TODO: should be impossible given that only the values in 'Shape' are available, unless the user explicitly gives us a bad value via casting // TODO: should be impossible given that only the values in 'Shape' are available, unless the user explicitly gives us a bad value via casting
Error.InvalidEnum => unreachable, Error.InvalidEnum => unreachable,
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return Cursor{ .ptr = cursor.? }; return Cursor{ .ptr = cursor.? };

View file

@ -92,7 +92,7 @@ pub inline fn present(self: Joystick) error{ InvalidEnum, PlatformError }!bool {
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum, Error.InvalidEnum,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidEnum, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return is_present == c.GLFW_TRUE; return is_present == c.GLFW_TRUE;
@ -125,7 +125,7 @@ pub inline fn getAxes(self: Joystick) error{ InvalidEnum, PlatformError }!?[]con
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum, Error.InvalidEnum,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidEnum, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
if (axes == null) return null; if (axes == null) return null;
@ -163,7 +163,7 @@ pub inline fn getButtons(self: Joystick) error{ InvalidEnum, PlatformError }!?[]
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum, Error.InvalidEnum,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidEnum, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
if (buttons == null) return null; if (buttons == null) return null;
@ -217,7 +217,7 @@ pub inline fn getHats(self: Joystick) error{ InvalidEnum, PlatformError }!?[]con
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum, Error.InvalidEnum,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidEnum, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
if (hats == null) return null; if (hats == null) return null;
@ -250,7 +250,7 @@ pub inline fn getName(self: Joystick) error{ InvalidEnum, PlatformError }!?[:0]c
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum, Error.InvalidEnum,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidEnum, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return if (name_opt) |name| return if (name_opt) |name|
@ -292,7 +292,7 @@ pub inline fn getGUID(self: Joystick) error{ InvalidEnum, PlatformError }!?[:0]c
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum, Error.InvalidEnum,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidEnum, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return if (guid_opt) |guid| return if (guid_opt) |guid|
@ -408,7 +408,7 @@ pub inline fn updateGamepadMappings(gamepad_mappings: [*:0]const u8) error{ Inva
internal_debug.assertInitialized(); internal_debug.assertInitialized();
_ = c.glfwUpdateGamepadMappings(gamepad_mappings); _ = c.glfwUpdateGamepadMappings(gamepad_mappings);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidValue => err, Error.InvalidValue => @errSetCast(error{ InvalidValue }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -466,7 +466,7 @@ pub inline fn getGamepadName(self: Joystick) error{ InvalidEnum }!?[:0]const u8
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const name_opt = c.glfwGetGamepadName(self.jid); const name_opt = c.glfwGetGamepadName(self.jid);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum => err, Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err),
else => unreachable, else => unreachable,
}; };
return if (name_opt) |name| return if (name_opt) |name|
@ -504,7 +504,7 @@ pub inline fn getGamepadState(self: Joystick) error{ InvalidEnum }!?GamepadState
var state: GamepadState = undefined; var state: GamepadState = undefined;
const success = c.glfwGetGamepadState(self.jid, @ptrCast(*c.GLFWgamepadstate, &state)); const success = c.glfwGetGamepadState(self.jid, @ptrCast(*c.GLFWgamepadstate, &state));
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum => err, Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err),
else => unreachable, else => unreachable,
}; };
return if (success == c.GLFW_TRUE) state else null; return if (success == c.GLFW_TRUE) state else null;

View file

@ -38,7 +38,7 @@ pub inline fn getPos(self: Monitor) error{ PlatformError }!Pos {
var ypos: c_int = 0; var ypos: c_int = 0;
c.glfwGetMonitorPos(self.handle, &xpos, &ypos); c.glfwGetMonitorPos(self.handle, &xpos, &ypos);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return Pos{ .x = @intCast(usize, xpos), .y = @intCast(usize, ypos) }; return Pos{ .x = @intCast(usize, xpos), .y = @intCast(usize, ypos) };
@ -72,7 +72,7 @@ pub inline fn getWorkarea(self: Monitor) error{ PlatformError }!Workarea {
var height: c_int = 0; var height: c_int = 0;
c.glfwGetMonitorWorkarea(self.handle, &xpos, &ypos, &width, &height); c.glfwGetMonitorWorkarea(self.handle, &xpos, &ypos, &width, &height);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return Workarea{ .x = @intCast(usize, xpos), .y = @intCast(usize, ypos), .width = @intCast(usize, width), .height = @intCast(usize, height) }; return Workarea{ .x = @intCast(usize, xpos), .y = @intCast(usize, ypos), .width = @intCast(usize, width), .height = @intCast(usize, height) };
@ -137,7 +137,7 @@ pub inline fn getContentScale(self: Monitor) error{ PlatformError }!ContentScale
var y_scale: f32 = 0; var y_scale: f32 = 0;
c.glfwGetMonitorContentScale(self.handle, &x_scale, &y_scale); c.glfwGetMonitorContentScale(self.handle, &x_scale, &y_scale);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return ContentScale{ .x_scale = @floatCast(f32, x_scale), .y_scale = @floatCast(f32, y_scale) }; return ContentScale{ .x_scale = @floatCast(f32, x_scale), .y_scale = @floatCast(f32, y_scale) };
@ -224,7 +224,7 @@ pub inline fn getVideoModes(self: Monitor, allocator: *mem.Allocator) (mem.Alloc
var count: c_int = 0; var count: c_int = 0;
const modes = c.glfwGetVideoModes(self.handle, &count); const modes = c.glfwGetVideoModes(self.handle, &count);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
@ -251,7 +251,7 @@ pub inline fn getVideoMode(self: Monitor) error{ PlatformError }!VideoMode {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const mode = c.glfwGetVideoMode(self.handle); const mode = c.glfwGetVideoMode(self.handle);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return VideoMode{ .handle = mode.?.* }; return VideoMode{ .handle = mode.?.* };
@ -283,7 +283,7 @@ pub inline fn setGamma(self: Monitor, gamma: f32) error{ InvalidValue, PlatformE
// TODO: Consider whether to assert that 'gamma' is a valid value instead of leaving it to GLFW's error handling. // TODO: Consider whether to assert that 'gamma' is a valid value instead of leaving it to GLFW's error handling.
Error.InvalidValue, Error.InvalidValue,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidValue, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -307,7 +307,7 @@ pub inline fn getGammaRamp(self: Monitor) error{ PlatformError }!GammaRamp {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const ramp = c.glfwGetGammaRamp(self.handle); const ramp = c.glfwGetGammaRamp(self.handle);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return GammaRamp.fromC(ramp.*); return GammaRamp.fromC(ramp.*);
@ -342,7 +342,7 @@ pub inline fn setGammaRamp(self: Monitor, ramp: GammaRamp) error{ PlatformError
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetGammaRamp(self.handle, &ramp.toC()); c.glfwSetGammaRamp(self.handle, &ramp.toC());
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }

View file

@ -505,7 +505,7 @@ pub inline fn setTitle(self: Window, title: [*:0]const u8) error{ PlatformError
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetWindowTitle(self.handle, title); c.glfwSetWindowTitle(self.handle, title);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -547,7 +547,7 @@ pub inline fn setIcon(self: Window, allocator: *mem.Allocator, images: ?[]Image)
c.glfwSetWindowIcon(self.handle, @intCast(c_int, im.len), &tmp[0]); c.glfwSetWindowIcon(self.handle, @intCast(c_int, im.len), &tmp[0]);
} else c.glfwSetWindowIcon(self.handle, 0, null); } else c.glfwSetWindowIcon(self.handle, 0, null);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -576,7 +576,7 @@ pub inline fn getPos(self: Window) error{ PlatformError }!Pos {
var y: c_int = 0; var y: c_int = 0;
c.glfwGetWindowPos(self.handle, &x, &y); c.glfwGetWindowPos(self.handle, &x, &y);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return Pos{ .x = @intCast(usize, x), .y = @intCast(usize, y) }; return Pos{ .x = @intCast(usize, x), .y = @intCast(usize, y) };
@ -606,7 +606,7 @@ pub inline fn setPos(self: Window, pos: Pos) error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetWindowPos(self.handle, @intCast(c_int, pos.x), @intCast(c_int, pos.y)); c.glfwSetWindowPos(self.handle, @intCast(c_int, pos.x), @intCast(c_int, pos.y));
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -633,7 +633,7 @@ pub inline fn getSize(self: Window) error{ PlatformError }!Size {
var height: c_int = 0; var height: c_int = 0;
c.glfwGetWindowSize(self.handle, &width, &height); c.glfwGetWindowSize(self.handle, &width, &height);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return Size{ .width = @intCast(usize, width), .height = @intCast(usize, height) }; return Size{ .width = @intCast(usize, width), .height = @intCast(usize, height) };
@ -665,7 +665,7 @@ pub inline fn setSize(self: Window, size: Size) error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetWindowSize(self.handle, @intCast(c_int, size.width), @intCast(c_int, size.height)); c.glfwSetWindowSize(self.handle, @intCast(c_int, size.width), @intCast(c_int, size.height));
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -703,7 +703,7 @@ pub inline fn setSizeLimits(self: Window, min: Size, max: Size) error{ InvalidVa
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidValue, Error.InvalidValue,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidValue, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -740,7 +740,7 @@ pub inline fn setAspectRatio(self: Window, numerator: usize, denominator: usize)
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidValue, Error.InvalidValue,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidValue, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -761,7 +761,7 @@ pub inline fn getFramebufferSize(self: Window) error{ PlatformError }!Size {
var height: c_int = 0; var height: c_int = 0;
c.glfwGetFramebufferSize(self.handle, &width, &height); c.glfwGetFramebufferSize(self.handle, &width, &height);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return Size{ .width = @intCast(usize, width), .height = @intCast(usize, height) }; return Size{ .width = @intCast(usize, width), .height = @intCast(usize, height) };
@ -796,7 +796,7 @@ pub inline fn getFrameSize(self: Window) error{ PlatformError }!FrameSize {
var bottom: c_int = 0; var bottom: c_int = 0;
c.glfwGetWindowFrameSize(self.handle, &left, &top, &right, &bottom); c.glfwGetWindowFrameSize(self.handle, &left, &top, &right, &bottom);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return FrameSize{ return FrameSize{
@ -835,7 +835,7 @@ pub inline fn getContentScale(self: Window) error{ PlatformError }!ContentScale
var y_scale: f32 = 0; var y_scale: f32 = 0;
c.glfwGetWindowContentScale(self.handle, &x_scale, &y_scale); c.glfwGetWindowContentScale(self.handle, &x_scale, &y_scale);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return ContentScale{ .x_scale = x_scale, .y_scale = y_scale }; return ContentScale{ .x_scale = x_scale, .y_scale = y_scale };
@ -860,7 +860,7 @@ pub inline fn getOpacity(self: Window) error{ PlatformError }!f32 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const opacity = c.glfwGetWindowOpacity(self.handle); const opacity = c.glfwGetWindowOpacity(self.handle);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return opacity; return opacity;
@ -887,7 +887,7 @@ pub inline fn setOpacity(self: Window, opacity: f32) error{ PlatformError }!void
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetWindowOpacity(self.handle, opacity); c.glfwSetWindowOpacity(self.handle, opacity);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -912,7 +912,7 @@ pub inline fn iconify(self: Window) error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwIconifyWindow(self.handle); c.glfwIconifyWindow(self.handle);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -934,7 +934,7 @@ pub inline fn restore(self: Window) error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwRestoreWindow(self.handle); c.glfwRestoreWindow(self.handle);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -955,7 +955,7 @@ pub inline fn maximize(self: Window) error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwMaximizeWindow(self.handle); c.glfwMaximizeWindow(self.handle);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -978,7 +978,7 @@ pub inline fn show(self: Window) error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwShowWindow(self.handle); c.glfwShowWindow(self.handle);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -997,7 +997,7 @@ pub inline fn hide(self: Window) error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwHideWindow(self.handle); c.glfwHideWindow(self.handle);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -1030,7 +1030,7 @@ pub inline fn focus(self: Window) error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwFocusWindow(self.handle); c.glfwFocusWindow(self.handle);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -1054,7 +1054,7 @@ pub inline fn requestAttention(self: Window) error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwRequestWindowAttention(self.handle); c.glfwRequestWindowAttention(self.handle);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -1086,7 +1086,7 @@ pub inline fn swapBuffers(self: Window) error{ NoWindowContext, PlatformError }!
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.NoWindowContext, Error.NoWindowContext,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ NoWindowContext, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -1165,7 +1165,7 @@ pub inline fn setMonitor(self: Window, monitor: ?Monitor, xpos: isize, ypos: isi
@intCast(c_int, refresh_rate), @intCast(c_int, refresh_rate),
); );
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -1224,7 +1224,7 @@ pub inline fn getAttrib(self: Window, attrib: Attrib) error{ InvalidEnum, Platfo
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum, Error.InvalidEnum,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidEnum, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return v; return v;
@ -1262,7 +1262,7 @@ pub inline fn setAttrib(self: Window, attrib: Attrib, value: bool) error{ Invali
Error.InvalidEnum, Error.InvalidEnum,
Error.InvalidValue, Error.InvalidValue,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidEnum, InvalidValue, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -1748,7 +1748,7 @@ pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) error{
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum, Error.InvalidEnum,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidEnum, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -1783,7 +1783,7 @@ pub inline fn getKey(self: Window, key: Key) error{ InvalidEnum }!Action {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const state = c.glfwGetKey(self.handle, @enumToInt(key)); const state = c.glfwGetKey(self.handle, @enumToInt(key));
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum => err, Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err),
else => unreachable, else => unreachable,
}; };
return @intToEnum(Action, state); return @intToEnum(Action, state);
@ -1809,7 +1809,7 @@ pub inline fn getMouseButton(self: Window, button: MouseButton) error{ InvalidEn
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const state = c.glfwGetMouseButton(self.handle, @enumToInt(button)); const state = c.glfwGetMouseButton(self.handle, @enumToInt(button));
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum => err, Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err),
else => unreachable, else => unreachable,
}; };
return @intToEnum(Action, state); return @intToEnum(Action, state);
@ -1850,7 +1850,7 @@ pub inline fn getCursorPos(self: Window) error{ PlatformError }!CursorPos {
var pos: CursorPos = undefined; var pos: CursorPos = undefined;
c.glfwGetCursorPos(self.handle, &pos.xpos, &pos.ypos); c.glfwGetCursorPos(self.handle, &pos.xpos, &pos.ypos);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return pos; return pos;
@ -1885,7 +1885,7 @@ pub inline fn setCursorPos(self: Window, xpos: f64, ypos: f64) error{ PlatformEr
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetCursorPos(self.handle, xpos, ypos); c.glfwSetCursorPos(self.handle, xpos, ypos);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -1909,7 +1909,7 @@ pub inline fn setCursor(self: Window, cursor: Cursor) error{ PlatformError }!voi
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetCursor(self.handle, cursor.ptr); c.glfwSetCursor(self.handle, cursor.ptr);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }

View file

@ -23,7 +23,7 @@ pub inline fn setClipboardString(value: [*:0]const u8) error{ PlatformError }!vo
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetClipboardString(null, value); c.glfwSetClipboardString(null, value);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -49,7 +49,7 @@ pub inline fn getClipboardString() error{ PlatformError }![:0]const u8 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const value = c.glfwGetClipboardString(null); const value = c.glfwGetClipboardString(null);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return std.mem.span(value); return std.mem.span(value);

View file

@ -218,7 +218,7 @@ pub const Key = enum(c_int) {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const name_opt = cc.glfwGetKeyName(@enumToInt(self), @intCast(c_int, scancode)); const name_opt = cc.glfwGetKeyName(@enumToInt(self), @intCast(c_int, scancode));
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return if (name_opt) |name| return if (name_opt) |name|
@ -244,7 +244,7 @@ pub const Key = enum(c_int) {
const scancode = cc.glfwGetKeyScancode(@enumToInt(self)); const scancode = cc.glfwGetKeyScancode(@enumToInt(self));
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum => unreachable, // Should be unreachable for any valid 'Key' value. Error.InvalidEnum => unreachable, // Should be unreachable for any valid 'Key' value.
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return scancode; return scancode;

View file

@ -68,8 +68,7 @@ pub inline fn init(hints: InitHints) error{ PlatformError }!void {
initHint(init_hint, init_value) catch |err| switch (err) { initHint(init_hint, init_value) catch |err| switch (err) {
// TODO: Consider this; should not be reachable, given that all of the hint tags and hint values // TODO: Consider this; should not be reachable, given that all of the hint tags and hint values
// are coming in from a strict set of predefined values in 'InitHints' and 'InitHint' // are coming in from a strict set of predefined values in 'InitHints' and 'InitHint'
Error.InvalidValue, error.InvalidValue,
Error.InvalidEnum,
=> unreachable, => unreachable,
else => unreachable, else => unreachable,
}; };
@ -77,7 +76,7 @@ pub inline fn init(hints: InitHints) error{ PlatformError }!void {
_ = c.glfwInit(); _ = c.glfwInit();
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -182,7 +181,7 @@ fn initHint(hint: InitHint, value: anytype) error{ InvalidValue }!void {
} }
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.InvalidEnum => unreachable, // impossible for any valid 'InitHint' value Error.InvalidEnum => unreachable, // impossible for any valid 'InitHint' value
Error.InvalidValue => err, Error.InvalidValue => @errSetCast(error{ InvalidValue }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -238,7 +237,7 @@ pub inline fn pollEvents() error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwPollEvents(); c.glfwPollEvents();
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -277,7 +276,7 @@ pub inline fn waitEvents() error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwWaitEvents(); c.glfwWaitEvents();
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -324,7 +323,7 @@ pub inline fn waitEventsTimeout(timeout: f64) error{ InvalidValue, PlatformError
// and make its branch unreachable. // and make its branch unreachable.
Error.InvalidValue, Error.InvalidValue,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ InvalidValue, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -343,7 +342,7 @@ pub inline fn postEmptyEvent() error{ PlatformError }!void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwPostEmptyEvent(); c.glfwPostEmptyEvent();
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.PlatformError => err, Error.PlatformError => @errSetCast(error{ PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }

View file

@ -37,7 +37,7 @@ pub inline fn makeContextCurrent(window: ?Window) error{ NoWindowContext, Platfo
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.NoWindowContext, Error.NoWindowContext,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ NoWindowContext, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -54,8 +54,7 @@ pub inline fn makeContextCurrent(window: ?Window) error{ NoWindowContext, Platfo
/// @thread_safety This function may be called from any thread. /// @thread_safety This function may be called from any thread.
/// ///
/// see also: context_current, glfwMakeContextCurrent /// see also: context_current, glfwMakeContextCurrent
// TODO: Remove error stub pub inline fn getCurrentContext() std.mem.Allocator.Error!?Window {
pub inline fn getCurrentContext() error{}!?Window {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const handle = c.glfwGetCurrentContext(); const handle = c.glfwGetCurrentContext();
getError() catch unreachable; // Only error 'GLFW_NOT_INITIALIZED' is impossible getError() catch unreachable; // Only error 'GLFW_NOT_INITIALIZED' is impossible
@ -102,7 +101,7 @@ pub inline fn swapInterval(interval: isize) error{ NoCurrentContext, PlatformErr
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.NoCurrentContext, Error.NoCurrentContext,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ NoCurrentContext, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
} }
@ -138,7 +137,7 @@ pub inline fn extensionSupported(extension: [*:0]const u8) error{ NoCurrentConte
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.NoCurrentContext, Error.NoCurrentContext,
Error.InvalidValue, Error.InvalidValue,
=> err, => @errSetCast(error{ NoCurrentContext, InvalidValue }, err),
else => unreachable, else => unreachable,
}; };
return supported == c.GLFW_TRUE; return supported == c.GLFW_TRUE;

View file

@ -58,7 +58,7 @@ pub inline fn setTime(time: f64) error{ InvalidValue }!void {
c.glfwSetTime(time); c.glfwSetTime(time);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
// TODO: Consider whether to use GLFW error handling, or assert that 'time' is a valid value // TODO: Consider whether to use GLFW error handling, or assert that 'time' is a valid value
Error.InvalidValue => err, Error.InvalidValue => @errSetCast(error{ InvalidValue }, err),
else => unreachable, else => unreachable,
}; };
} }

View file

@ -66,7 +66,7 @@ pub inline fn getRequiredInstanceExtensions() error{ APIUnavailable }![][*:0]con
var count: u32 = 0; var count: u32 = 0;
const extensions = c.glfwGetRequiredInstanceExtensions(&count); const extensions = c.glfwGetRequiredInstanceExtensions(&count);
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.APIUnavailable => err, Error.APIUnavailable => @errSetCast(error{ APIUnavailable }, err),
else => unreachable, else => unreachable,
}; };
return @ptrCast([*][*:0]const u8, extensions)[0..count]; return @ptrCast([*][*:0]const u8, extensions)[0..count];
@ -153,7 +153,7 @@ pub inline fn getPhysicalDevicePresentationSupport(vk_instance: *opaque {}, vk_p
getError() catch |err| return switch (err) { getError() catch |err| return switch (err) {
Error.APIUnavailable, Error.APIUnavailable,
Error.PlatformError, Error.PlatformError,
=> err, => @errSetCast(error{ APIUnavailable, PlatformError }, err),
else => unreachable, else => unreachable,
}; };
return v == c.GLFW_TRUE; return v == c.GLFW_TRUE;