From fe34354be03c296dfb8c7c11657126052c1a15aa Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Sat, 6 Jul 2024 22:36:29 +0200 Subject: [PATCH] Seperate error union --- lib/preludes/raygui-prelude.zig | 8 ++++++-- lib/preludes/raylib-prelude.zig | 24 ++++++++++++++++-------- lib/raygui.zig | 8 ++++++-- lib/raylib.zig | 24 ++++++++++++++++-------- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/lib/preludes/raygui-prelude.zig b/lib/preludes/raygui-prelude.zig index db10234..2ebf837 100644 --- a/lib/preludes/raygui-prelude.zig +++ b/lib/preludes/raygui-prelude.zig @@ -6,6 +6,10 @@ test { std.testing.refAllDeclsRecursive(@This()); } +pub const RayguiError = error{ + GetIcons +}; + const Vector2 = rl.Vector2; const Vector3 = rl.Vector3; const Color = rl.Color; @@ -413,11 +417,11 @@ pub const GuiIconName = enum(c_int) { }; /// Get raygui icons data pointer -pub fn guiGetIcons() rl.RaylibError![]u32 { +pub fn guiGetIcons() RayguiError![]u32 { var res: []u32 = undefined; const ptr = cdef.GuiGetIcons(); - if (ptr == 0) return rl.RaylibError.GenericError; + if (ptr == 0) return RayguiError.GetIcons; res.ptr = @as([*]u32, @ptrCast(ptr)); res.len = @as(usize, @intCast(256 * 256)); // RAYGUI_ICON_MAX_ICONS * RAYGUI_ICON_MAX_ICONS diff --git a/lib/preludes/raylib-prelude.zig b/lib/preludes/raylib-prelude.zig index 07ebaf8..62aa95f 100755 --- a/lib/preludes/raylib-prelude.zig +++ b/lib/preludes/raylib-prelude.zig @@ -10,7 +10,15 @@ test { std.testing.refAllDeclsRecursive(@This()); } -pub const RaylibError = error{GenericError}; +pub const RaylibError = error{ + LoadFileData, + LoadImageColors, + LoadImagePalette, + LoadFontData, + LoadCodepoints, + LoadMaterials, + LoadModelAnimations +}; pub const Vector2 = extern struct { x: f32, @@ -2000,7 +2008,7 @@ pub fn loadFileData(fileName: [:0]const u8) RaylibError![]u8 { var res: []u8 = undefined; const ptr = cdef.LoadFileData(@as([*c]const u8, @ptrCast(fileName)), @as([*c]c_int, @ptrCast(&bytesRead))); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadFileData; res.ptr = @as([*]u8, @ptrCast(ptr)); res.len = @as(usize, @intCast(bytesRead)); @@ -2067,7 +2075,7 @@ pub fn loadImageColors(image: Image) RaylibError![]Color { var res: []Color = undefined; const ptr = cdef.LoadImageColors(image); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadImageColors; res.ptr = @as([*]Color, @ptrCast(ptr)); res.len = @as(usize, @intCast(image.width * image.height)); @@ -2080,7 +2088,7 @@ pub fn loadImagePalette(image: Image, maxPaletteSize: i32) RaylibError![]Color { var res: []Color = undefined; const ptr = cdef.LoadImagePalette(image, @as(c_int, maxPaletteSize), @as([*c]c_int, @ptrCast(&colorCount))); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadImagePalette; res.ptr = @as([*]Color, @ptrCast(ptr)); res.len = @as(usize, @intCast(colorCount)); @@ -2115,7 +2123,7 @@ pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: F var res: []GlyphInfo = undefined; const ptr = cdef.LoadFontData(@as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len)), ty); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadFontData; res.ptr = @as([*]GlyphInfo, @ptrCast(ptr)); res.len = @as(usize, @intCast(fontChars.len)); @@ -2131,7 +2139,7 @@ pub fn loadCodepoints(text: [:0]const u8) RaylibError![]i32 { var res: []i32 = undefined; const ptr = cdef.LoadCodepoints(@as([*c]const u8, @ptrCast(text)), @as([*c]c_int, @ptrCast(&count))); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadCodepoints; res.ptr = @as([*]i32, @ptrCast(ptr)); res.len = @as(usize, @intCast(count)); @@ -2176,7 +2184,7 @@ pub fn loadMaterials(fileName: [:0]const u8) RaylibError![]Material { var res: []Material = undefined; const ptr = cdef.LoadMaterials(@as([*c]const u8, @ptrCast(fileName)), @as([*c]c_int, @ptrCast(&materialCount))); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadMaterials; res.ptr = @as([*]Material, @ptrCast(ptr)); res.len = @as(usize, @intCast(materialCount)); @@ -2189,7 +2197,7 @@ pub fn loadModelAnimations(fileName: [:0]const u8) RaylibError![]ModelAnimation var res: []ModelAnimation = undefined; const ptr = cdef.LoadModelAnimations(@as([*c]const u8, @ptrCast(fileName)), @as([*c]c_int, @ptrCast(&animCount))); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadModelAnimations; res.ptr = @as([*]ModelAnimation, @ptrCast(ptr)); res.len = @as(usize, @intCast(animCount)); diff --git a/lib/raygui.zig b/lib/raygui.zig index a610380..ecca576 100644 --- a/lib/raygui.zig +++ b/lib/raygui.zig @@ -6,6 +6,10 @@ test { std.testing.refAllDeclsRecursive(@This()); } +pub const RayguiError = error{ + GetIcons +}; + const Vector2 = rl.Vector2; const Vector3 = rl.Vector3; const Color = rl.Color; @@ -413,11 +417,11 @@ pub const GuiIconName = enum(c_int) { }; /// Get raygui icons data pointer -pub fn guiGetIcons() rl.RaylibError![]u32 { +pub fn guiGetIcons() RayguiError![]u32 { var res: []u32 = undefined; const ptr = cdef.GuiGetIcons(); - if (ptr == 0) return rl.RaylibError.GenericError; + if (ptr == 0) return RayguiError.GetIcons; res.ptr = @as([*]u32, @ptrCast(ptr)); res.len = @as(usize, @intCast(256 * 256)); // RAYGUI_ICON_MAX_ICONS * RAYGUI_ICON_MAX_ICONS diff --git a/lib/raylib.zig b/lib/raylib.zig index 196b557..98808b2 100644 --- a/lib/raylib.zig +++ b/lib/raylib.zig @@ -10,7 +10,15 @@ test { std.testing.refAllDeclsRecursive(@This()); } -pub const RaylibError = error{GenericError}; +pub const RaylibError = error{ + LoadFileData, + LoadImageColors, + LoadImagePalette, + LoadFontData, + LoadCodepoints, + LoadMaterials, + LoadModelAnimations +}; pub const Vector2 = extern struct { x: f32, @@ -2000,7 +2008,7 @@ pub fn loadFileData(fileName: [:0]const u8) RaylibError![]u8 { var res: []u8 = undefined; const ptr = cdef.LoadFileData(@as([*c]const u8, @ptrCast(fileName)), @as([*c]c_int, @ptrCast(&bytesRead))); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadFileData; res.ptr = @as([*]u8, @ptrCast(ptr)); res.len = @as(usize, @intCast(bytesRead)); @@ -2067,7 +2075,7 @@ pub fn loadImageColors(image: Image) RaylibError![]Color { var res: []Color = undefined; const ptr = cdef.LoadImageColors(image); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadImageColors; res.ptr = @as([*]Color, @ptrCast(ptr)); res.len = @as(usize, @intCast(image.width * image.height)); @@ -2080,7 +2088,7 @@ pub fn loadImagePalette(image: Image, maxPaletteSize: i32) RaylibError![]Color { var res: []Color = undefined; const ptr = cdef.LoadImagePalette(image, @as(c_int, maxPaletteSize), @as([*c]c_int, @ptrCast(&colorCount))); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadImagePalette; res.ptr = @as([*]Color, @ptrCast(ptr)); res.len = @as(usize, @intCast(colorCount)); @@ -2115,7 +2123,7 @@ pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: F var res: []GlyphInfo = undefined; const ptr = cdef.LoadFontData(@as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len)), ty); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadFontData; res.ptr = @as([*]GlyphInfo, @ptrCast(ptr)); res.len = @as(usize, @intCast(fontChars.len)); @@ -2131,7 +2139,7 @@ pub fn loadCodepoints(text: [:0]const u8) RaylibError![]i32 { var res: []i32 = undefined; const ptr = cdef.LoadCodepoints(@as([*c]const u8, @ptrCast(text)), @as([*c]c_int, @ptrCast(&count))); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadCodepoints; res.ptr = @as([*]i32, @ptrCast(ptr)); res.len = @as(usize, @intCast(count)); @@ -2176,7 +2184,7 @@ pub fn loadMaterials(fileName: [:0]const u8) RaylibError![]Material { var res: []Material = undefined; const ptr = cdef.LoadMaterials(@as([*c]const u8, @ptrCast(fileName)), @as([*c]c_int, @ptrCast(&materialCount))); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadMaterials; res.ptr = @as([*]Material, @ptrCast(ptr)); res.len = @as(usize, @intCast(materialCount)); @@ -2189,7 +2197,7 @@ pub fn loadModelAnimations(fileName: [:0]const u8) RaylibError![]ModelAnimation var res: []ModelAnimation = undefined; const ptr = cdef.LoadModelAnimations(@as([*c]const u8, @ptrCast(fileName)), @as([*c]c_int, @ptrCast(&animCount))); - if (ptr == 0) return RaylibError.GenericError; + if (ptr == 0) return RaylibError.LoadModelAnimations; res.ptr = @as([*]ModelAnimation, @ptrCast(ptr)); res.len = @as(usize, @intCast(animCount));