aboutsummaryrefslogtreecommitdiff
path: root/sdl2/image/image.ha
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2021-12-10 09:42:10 +0100
committerDrew DeVault <sir@cmpwn.com>2021-12-10 09:44:50 +0100
commit9607eb0de784fab1a99833f567c0eaca72b67e4a (patch)
tree7f79a0914a6db1d963d877bed051f6856c54cfa8 /sdl2/image/image.ha
parentMakefile: drop -T+libc (diff)
downloadhare-chip8-9607eb0de784fab1a99833f567c0eaca72b67e4a.tar.gz
all: rig up Hare-native error handling
Diffstat (limited to 'sdl2/image/image.ha')
-rw-r--r--sdl2/image/image.ha22
1 files changed, 19 insertions, 3 deletions
diff --git a/sdl2/image/image.ha b/sdl2/image/image.ha
index 03301e9..6cabee2 100644
--- a/sdl2/image/image.ha
+++ b/sdl2/image/image.ha
@@ -1,6 +1,7 @@
// TODO: Flesh me out
// TODO: SDL_RWops
use sdl2;
+use strings;
// Flags for [[init]].
export type init_flags = enum int {
@@ -20,9 +21,24 @@ export @symbol("IMG_Init") fn init(flags: init_flags) int;
// Unloads libraries loaded with [[init]]
export @symbol("IMG_Quit") fn quit() void;
+@symbol("IMG_Load") fn _load(file: const *char) nullable *sdl2::surface;
+
// Load an image from a file path.
-export @symbol("IMG_Load") fn load(file: const *char) nullable *sdl2::surface;
+export fn load(file: str) (*sdl2::surface | sdl2::error) = {
+ const file = strings::to_c(file);
+ defer free(file);
+ return sdl2::wrapptr(_load(file))?: *sdl2::surface;
+};
-// Load an image directly into a render texture.
-export @symbol("IMG_LoadTexture") fn load_texture(renderer: *sdl2::renderer,
+@symbol("IMG_LoadTexture") fn _load_texture(renderer: *sdl2::renderer,
file: const *char) nullable *sdl2::texture;
+
+// Load an image directly into a render texture.
+export fn load_texture(
+ renderer: *sdl2::renderer,
+ file: str,
+) (*sdl2::texture | sdl2::error) = {
+ const file = strings::to_c(file);
+ defer free(file);
+ return sdl2::wrapptr(_load_texture(renderer, file))?: *sdl2::texture;
+};