diff --git a/src/iter.zig b/src/iter.zig index d7edcd0..3cf7f3a 100644 --- a/src/iter.zig +++ b/src/iter.zig @@ -1,5 +1,7 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; + const c = @import("./c.zig"); -const flecszigble = @import("./main.zig"); pub fn Iter(comptime ctx: anytype) type { return struct { @@ -12,21 +14,21 @@ pub fn Iter(comptime ctx: anytype) type { world: *World, raw: *c.ecs_iter_t, - owned: bool, + allocator: ?Allocator, pub fn fromRawPtr(world: *World, ptr: *c.ecs_iter_t) Self { - return .{ .world = world, .raw = ptr, .owned = false }; + return .{ .world = world, .raw = ptr, .allocator = null }; } - pub fn fromRawValue(world: *World, value: c.ecs_iter_t) !Self { - const raw = try flecszigble.allocator.create(c.ecs_iter_t); + pub fn fromRawValue(world: *World, value: c.ecs_iter_t, allocator: Allocator) !Self { + const raw = try allocator.create(c.ecs_iter_t); raw.* = value; - return .{ .world = world, .raw = raw, .owned = true }; + return .{ .world = world, .raw = raw, .allocator = allocator }; } pub fn deinit(self: Self) void { if (self.isValid()) c.ecs_iter_fini(self.raw); - if (self.owned) flecszigble.allocator.destroy(self.raw); + if (self.allocator) |alloc| alloc.destroy(self.raw); } pub fn isValid(self: Self) bool {