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);