From 13ea2be1c13a3d8f5a0c5fbe16ca3cc1f5afab5e Mon Sep 17 00:00:00 2001 From: Aron Gabriel Date: Sat, 24 Jun 2023 14:07:03 +0800 Subject: [PATCH] Fix `@call` usage errors and duplicate test names --- zig-ecs/src/resources/cache.zig | 4 ++-- zig-ecs/src/signals/delegate.zig | 3 ++- zig-ecs/tests/registry_test.zig | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/zig-ecs/src/resources/cache.zig b/zig-ecs/src/resources/cache.zig index e4d9a3f..9ada0ad 100644 --- a/zig-ecs/src/resources/cache.zig +++ b/zig-ecs/src/resources/cache.zig @@ -59,7 +59,7 @@ pub fn Cache(comptime T: type) type { pub fn remove(self: *@This(), id: u32) void { if (self.resources.fetchRemove(id)) |kv| { if (@hasDecl(T, "deinit")) { - @call(.always_inline, @field(kv.value, "deinit"), .{}); + @call(.always_inline, T.deinit, .{kv.value}); } } } @@ -69,7 +69,7 @@ pub fn Cache(comptime T: type) type { if (@hasDecl(T, "deinit")) { var iter = self.resources.iterator(); while (iter.next()) |kv| { - @call(.always_inline, @field(kv.value_ptr.*, "deinit"), .{}); + @call(.always_inline, T.deinit, .{kv.value_ptr.*}); } } self.resources.clearAndFree(); diff --git a/zig-ecs/src/signals/delegate.zig b/zig-ecs/src/signals/delegate.zig index 05549be..f69d879 100644 --- a/zig-ecs/src/signals/delegate.zig +++ b/zig-ecs/src/signals/delegate.zig @@ -17,12 +17,13 @@ pub fn Delegate(comptime Event: type) type { std.debug.assert(@intFromPtr(ctx) != 0); const T = @TypeOf(ctx); + const BaseT = @typeInfo(T).Pointer.child; return Self{ .ctx_ptr_address = @intFromPtr(ctx), .callback = .{ .bound = struct { fn cb(self: usize, param: Event) void { - @call(.always_inline, @field(@ptrFromInt(T, self), fn_name), .{param}); + @call(.always_inline, @field(BaseT, fn_name), .{ @ptrFromInt(T, self), param }); } }.cb, }, diff --git a/zig-ecs/tests/registry_test.zig b/zig-ecs/tests/registry_test.zig index 3d443f0..8f1553b 100644 --- a/zig-ecs/tests/registry_test.zig +++ b/zig-ecs/tests/registry_test.zig @@ -58,7 +58,7 @@ test "context not pointer" { // reg.setContext(pos); } -test "context get/set/unset" { +test "context get/set/unset typed" { const SomeType = struct { dummy: u1 }; var reg = Registry.init(std.testing.allocator);