1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
const std = @import("std");
const wayland = @import("root.zig");
const Self = @This();
const VTable = struct {
on_event: *const fn (ptr: *anyopaque, ctx: *wayland.Context, opcode: u16, args: []const u8) void,
};
id: ?u32 = null,
ptr: ?*anyopaque,
vtable: VTable,
pub inline fn on_event(self: *Self, ctx: *wayland.Context, opcode: u16, args: []const u8) !void {
if (self.ptr) |ptr| {
self.vtable.on_event(ptr, ctx, opcode, args);
} else {
return error.UseAfterRelease;
}
}
pub inline fn from_self(ptr: anytype) Self {
return .{
.ptr = ptr,
.vtable = VTable{
.on_event = @TypeOf(ptr.*).Events.on_event,
},
};
}
pub fn format(
self: *const Self,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
_ = fmt;
_ = options;
try writer.print("Object {{ {?} }}", .{self.id});
}
|