aboutsummaryrefslogtreecommitdiff
path: root/src/object.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/object.zig')
-rw-r--r--src/object.zig41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/object.zig b/src/object.zig
new file mode 100644
index 0000000..0751859
--- /dev/null
+++ b/src/object.zig
@@ -0,0 +1,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});
+}