diff options
Diffstat (limited to 'src/object.zig')
| -rw-r--r-- | src/object.zig | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/object.zig b/src/object.zig index 14089c1..5502d3d 100644 --- a/src/object.zig +++ b/src/object.zig @@ -6,13 +6,24 @@ 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, + on_event: *const fn ( + ptr: *anyopaque, + ctx: *const wayland.Context, + opcode: u16, + args: []const u8, + ) void, }; ptr: ?*anyopaque, vtable: VTable, +name: []const u8, -pub inline fn on_event(self: *Self, ctx: *wayland.Context, opcode: u16, args: []const u8) !void { +pub inline fn on_event( + self: *Self, + ctx: *const wayland.Context, + opcode: u16, + args: []const u8, +) !void { if (self.ptr) |ptr| { self.vtable.on_event(ptr, ctx, opcode, args); } else { @@ -21,11 +32,14 @@ pub inline fn on_event(self: *Self, ctx: *wayland.Context, opcode: u16, args: [] } pub inline fn from_self(ptr: anytype) Self { + const T = @TypeOf(ptr.*); + return .{ .ptr = ptr, .vtable = VTable{ - .on_event = @TypeOf(ptr.*).Events.on_event, + .on_event = T.Events.on_event, }, + .name = @typeName(T), }; } @@ -42,5 +56,5 @@ pub fn format( _ = fmt; _ = options; - try writer.print("Object {{ {?} }}", .{self.ptr}); + try writer.print("Object<{s}> {{ {?} }}", .{self.name, self.ptr}); } |