diff options
author | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:11:21 +0200 |
---|---|---|
committer | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:51:35 +0200 |
commit | ae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch) | |
tree | 5f462459ae4b47d22114eed717d1382d08cf4dfe /sdl2/errors.ha |
Diffstat (limited to 'sdl2/errors.ha')
-rw-r--r-- | sdl2/errors.ha | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/sdl2/errors.ha b/sdl2/errors.ha new file mode 100644 index 0000000..a848667 --- /dev/null +++ b/sdl2/errors.ha @@ -0,0 +1,31 @@ +use types::c; + +// Returned when an error occurs in an SDL function. +export type error = !str; + +// Converts an SDL error into a human-friendly string. +export fn strerror(err: error) str = { + return err: str; +}; + +@symbol("SDL_GetError") fn SDL_GetError() const *c::char; + +export fn wrapvoid(ret: int) (void | error) = { + wrapint(ret)?; +}; + +export fn wrapint(ret: int) (int | error) = { + if (ret < 0) { + return c::tostr(SDL_GetError()): error; + }; + return ret; +}; + +export fn wrapptr(ret: nullable *opaque) (*opaque | error) = { + match (ret) { + case let v: *opaque => + return v; + case null => + return c::tostr(SDL_GetError()): error; + }; +}; |