Fix ActiveFunc calling convention
This commit is contained in:
parent
293b8729c0
commit
452be0a0b8
@ -1,4 +1,5 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const c = @cImport({
|
||||
@cInclude("MiniFB.h");
|
||||
@cInclude("MiniFB_enums.h");
|
||||
@ -48,7 +49,9 @@ pub fn Window(comptime TUserData: type) type {
|
||||
const cTitle = @as([*c]const u8, title);
|
||||
const cwin: ?*c.mfb_window = c.mfb_open_ex(cTitle, width, height, intFlags);
|
||||
if (cwin) |value| {
|
||||
return Window(TUserData){ .cwin = value };
|
||||
const win = Window(TUserData){ .cwin = value };
|
||||
assert(@bitCast(usize, win) == @ptrToInt(win.cwin));
|
||||
return win;
|
||||
} else {
|
||||
return error.ItBroke;
|
||||
}
|
||||
@ -75,12 +78,10 @@ pub fn Window(comptime TUserData: type) type {
|
||||
|
||||
pub fn getUserData(self: Window(TUserData)) ?*TUserData {
|
||||
var cData = c.mfb_get_user_data(self.cwin);
|
||||
std.log.info("@alignOf cwin={d}, addr={x}", .{ @alignOf(@TypeOf(self.cwin)), @ptrToInt(self.cwin) });
|
||||
std.log.info("@alignOf cdata={d}, addr={x}", .{ @alignOf(@TypeOf(cData)), @ptrToInt(cData) });
|
||||
return @ptrCast(?*TUserData, @alignCast(@alignOf(?*TUserData), cData));
|
||||
}
|
||||
|
||||
pub const ActiveFunc = fn (win: Window(TUserData), isActive: bool) void;
|
||||
pub const ActiveFunc = fn (win: Window(TUserData), isActive: bool) callconv(.C) void;
|
||||
pub fn setActiveCallback(self: Window(TUserData), callback: ActiveFunc) void {
|
||||
c.mfb_set_active_callback(self.cwin, @ptrCast(c.mfb_active_func, callback));
|
||||
}
|
||||
@ -93,13 +94,13 @@ test "user data is null if never set" {
|
||||
try testing.expectEqual(@as(?*u64, null), data);
|
||||
}
|
||||
|
||||
// test "user data is not null if previously set" {
|
||||
// const win = try Window(u64).open("abc", 100, 100, .{});
|
||||
// var data: u64 = 42;
|
||||
// win.setUserData(&data);
|
||||
// const expected: u64 = 42;
|
||||
// try testing.expectEqual(expected, win.getUserData().?.*);
|
||||
// }
|
||||
test "user data is not null if previously set" {
|
||||
const win = try Window(u64).open("abc", 100, 100, .{});
|
||||
var data: u64 = 42;
|
||||
win.setUserData(&data);
|
||||
const expected: u64 = 42;
|
||||
try testing.expectEqual(expected, win.getUserData().?.*);
|
||||
}
|
||||
|
||||
pub fn getTargetFPS() u32 {
|
||||
return c.mfb_get_target_fps();
|
||||
|
@ -98,7 +98,7 @@ const Buffer = struct {
|
||||
}
|
||||
};
|
||||
|
||||
fn handleActive(win: mfb.Window(State), isActive: bool) void {
|
||||
fn handleActive(win: mfb.Window(State), isActive: bool) callconv(.C) void {
|
||||
// win.getUserData().?.*.active = isActive;
|
||||
var data = win.getUserData();
|
||||
std.log.info("got data", .{});
|
||||
|
Loading…
Reference in New Issue
Block a user