glfw: refactor getError and related functions
`getError()` now returns a struct `Error` containing `error_code` and
`description`. Rationale: retrieving the error code with the previous
implementation of `getError()` caused `getErrorString()` to return
null (the reverse is also true). The new implementation allows both
values to be retrieved at once.
The previous `getError()` function has been renamed to
`getErrorCode()` to reflect the fact that it returns a simple Zig
error rather than the `Error` struct. The error set returned by
`getErrorCode()` is now named `ErrorCode` rather than `Error`.
The behavior of the `getError()` family of functions clearing the
stored error is unchanged. However, since all code that used
`defer glfw.getError() catch {}` to explicitly clear errors had to be
refactored, a new `glfw.clearError()` function that returns void is
now available to make this operation more explicit.
Additionally, `mustGetError()` is now `mustGetErrorCode()`, and new
functions `mustGetError()` and `mustGetErrorString()` have been added
which wrap `getError()` and `getErrorString()` but panic if no error
is actually available.
Tests and API documentation had to be refactored across all of
`mach/glfw`. This commit also takes the opportunity to skip tests
involving window creation on CI so that other tests may still execute
normally.
This commit is contained in:
parent
779359a519
commit
eed2be4591
14 changed files with 512 additions and 449 deletions
|
|
@ -1,8 +1,6 @@
|
|||
const std = @import("std");
|
||||
|
||||
const c = @import("c.zig").c;
|
||||
const Error = @import("errors.zig").Error;
|
||||
const getError = @import("errors.zig").getError;
|
||||
|
||||
const internal_debug = @import("internal_debug.zig");
|
||||
|
||||
|
|
@ -46,7 +44,7 @@ pub inline fn getTime() f64 {
|
|||
///
|
||||
/// @param[in] time The new value, in seconds.
|
||||
///
|
||||
/// Possible errors include glfw.Error.InvalidValue.
|
||||
/// Possible errors include glfw.ErrorCode.InvalidValue.
|
||||
///
|
||||
/// The upper limit of GLFW time is calculated as `floor((2^64 - 1) / 10^9)` and is due to
|
||||
/// implementations storing nanoseconds in 64 bits. The limit may be increased in the future.
|
||||
|
|
@ -108,7 +106,7 @@ pub inline fn getTimerFrequency() u64 {
|
|||
|
||||
test "getTime" {
|
||||
const glfw = @import("main.zig");
|
||||
defer glfw.getError() catch {}; // clear any error we generate
|
||||
defer glfw.clearError(); // clear any error we generate
|
||||
if (!glfw.init(.{})) {
|
||||
std.log.err("failed to initialize GLFW: {?s}", .{glfw.getErrorString()});
|
||||
std.process.exit(1);
|
||||
|
|
@ -120,7 +118,7 @@ test "getTime" {
|
|||
|
||||
test "setTime" {
|
||||
const glfw = @import("main.zig");
|
||||
defer glfw.getError() catch {}; // clear any error we generate
|
||||
defer glfw.clearError(); // clear any error we generate
|
||||
if (!glfw.init(.{})) {
|
||||
std.log.err("failed to initialize GLFW: {?s}", .{glfw.getErrorString()});
|
||||
std.process.exit(1);
|
||||
|
|
@ -132,7 +130,7 @@ test "setTime" {
|
|||
|
||||
test "getTimerValue" {
|
||||
const glfw = @import("main.zig");
|
||||
defer glfw.getError() catch {}; // clear any error we generate
|
||||
defer glfw.clearError(); // clear any error we generate
|
||||
if (!glfw.init(.{})) {
|
||||
std.log.err("failed to initialize GLFW: {?s}", .{glfw.getErrorString()});
|
||||
std.process.exit(1);
|
||||
|
|
@ -144,7 +142,7 @@ test "getTimerValue" {
|
|||
|
||||
test "getTimerFrequency" {
|
||||
const glfw = @import("main.zig");
|
||||
defer glfw.getError() catch {}; // clear any error we generate
|
||||
defer glfw.clearError(); // clear any error we generate
|
||||
if (!glfw.init(.{})) {
|
||||
std.log.err("failed to initialize GLFW: {?s}", .{glfw.getErrorString()});
|
||||
std.process.exit(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue