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");
|
||||
|
||||
|
|
@ -12,7 +10,7 @@ const internal_debug = @import("internal_debug.zig");
|
|||
///
|
||||
/// @param[in] string A UTF-8 encoded string.
|
||||
///
|
||||
/// Possible errors include glfw.Error.PlatformError.
|
||||
/// Possible errors include glfw.ErrorCode.PlatformError.
|
||||
///
|
||||
/// @pointer_lifetime The specified string is copied before this function returns.
|
||||
///
|
||||
|
|
@ -28,11 +26,11 @@ pub inline fn setClipboardString(value: [*:0]const u8) void {
|
|||
///
|
||||
/// This function returns the contents of the system clipboard, if it contains or is convertible to
|
||||
/// a UTF-8 encoded string. If the clipboard is empty or if its contents cannot be converted,
|
||||
/// glfw.Error.FormatUnavailable is returned.
|
||||
/// glfw.ErrorCode.FormatUnavailable is returned.
|
||||
///
|
||||
/// @return The contents of the clipboard as a UTF-8 encoded string.
|
||||
///
|
||||
/// Possible errors include glfw.Error.FormatUnavailable and glfw.Error.PlatformError.
|
||||
/// Possible errors include glfw.ErrorCode.FormatUnavailable and glfw.ErrorCode.PlatformError.
|
||||
/// null is returned in the event of an error.
|
||||
///
|
||||
/// @pointer_lifetime The returned string is allocated and freed by GLFW. You should not free it
|
||||
|
|
@ -50,7 +48,7 @@ pub inline fn getClipboardString() ?[:0]const u8 {
|
|||
|
||||
test "setClipboardString" {
|
||||
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);
|
||||
|
|
@ -62,7 +60,7 @@ test "setClipboardString" {
|
|||
|
||||
test "getClipboardString" {
|
||||
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