zig has extern unions now

This commit is contained in:
Andrew Kelley 2018-03-27 18:03:03 -04:00
parent a2a3fc57d1
commit 2dd7e5b51e

View File

@ -21,19 +21,8 @@ extern fn SDL_PollEvent(event: &c.SDL_Event) c_int;
// and to debuggers. // and to debuggers.
// SDL_rwops.h:#define SDL_RWclose(ctx) (ctx)->close(ctx) // SDL_rwops.h:#define SDL_RWclose(ctx) (ctx)->close(ctx)
inline fn SDL_RWclose(ctx: &c.SDL_RWops) c_int { inline fn SDL_RWclose(ctx: &c.SDL_RWops) c_int {
const aligned_ctx = @alignCast(@alignOf(my_SDL_RWops), ctx); return (??ctx.close)(ctx);
const casted_ctx = @ptrCast(&my_SDL_RWops, aligned_ctx);
return casted_ctx.close(casted_ctx);
} }
// Zig does not support extern unions yet.
// See https://github.com/zig-lang/zig/issues/144
const my_SDL_RWops = extern struct {
size: extern fn()void,
seek: extern fn()void,
read: extern fn()void,
write: extern fn()void,
close: extern fn(context: &my_SDL_RWops)c_int,
};
pub fn main() !void { pub fn main() !void {
if (c.SDL_Init(c.SDL_INIT_VIDEO) != 0) { if (c.SDL_Init(c.SDL_INIT_VIDEO) != 0) {