From 9607eb0de784fab1a99833f567c0eaca72b67e4a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 10 Dec 2021 09:42:10 +0100 Subject: all: rig up Hare-native error handling --- sdl2/video.ha | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'sdl2/video.ha') diff --git a/sdl2/video.ha b/sdl2/video.ha index e6dfa58..b1f8b22 100644 --- a/sdl2/video.ha +++ b/sdl2/video.ha @@ -1,4 +1,5 @@ // TODO: Flesh me out +use strings; // The type used to identify a window. (Opaque) export type window = void; @@ -32,6 +33,9 @@ export type window_flags = enum u32 { export def WINDOWPOS_UNDEFINED: int = 0x1FFF0000; export def WINDOWPOS_CENTERED: int = 0x2FFF0000; +@symbol("SDL_CreateWindow") fn _create_window(title: const *char, + x: int, y: int, w: int, h: int, flags: window_flags) nullable *window; + // Create a window with the specified position, dimensions, and flags. // // 'title' is the title of the window, in UTF-8 encoding. See [[strings::to_c]] @@ -66,8 +70,18 @@ export def WINDOWPOS_CENTERED: int = 0x2FFF0000; // removed in a future version of SDL. // // See also: [[destroy_window]] [[gl_loadlibrary]], [[vulkan_loadlibrary]]. -export @symbol("SDL_CreateWindow") fn create_window(title: const *char, - x: int, y: int, w: int, h: int, flags: window_flags) nullable *window; +export fn create_window( + title: str, + x: int, + y: int, + w: int, + h: int, + flags: window_flags, +) (*window | error) = { + let title = strings::to_c(title); + defer free(title); + return wrapptr(_create_window(title, x, y, w, h, flags))?: *window; +}; // Destroy a window. export @symbol("SDL_DestroyWindow") fn destroy_window(window: *window) void; -- cgit v1.2.3