const std = @import("std"); const wayland = @import("root.zig"); const Self = @This(); pub const Ref = usize; const VTable = struct { on_event: *const fn (ptr: *anyopaque, ctx: *wayland.Context, opcode: u16, args: []const u8) void, }; 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 disable(self: *Self) void { self.ptr = null; } pub fn format( self: *const Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype, ) !void { _ = fmt; _ = options; try writer.print("Object {{ {?} }}", .{self.ptr}); }