From 23540e591959ae76921481451a20f8cc7c6483a4 Mon Sep 17 00:00:00 2001 From: Ukendio Date: Sun, 6 Jul 2025 09:52:06 +0200 Subject: [PATCH] Make iterators simple functions --- addons/observers.luau | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/addons/observers.luau b/addons/observers.luau index 1f11e27..9656781 100755 --- a/addons/observers.luau +++ b/addons/observers.luau @@ -51,20 +51,18 @@ local function observers_new(world, query, callback) world:changed(term, emplaced) end - return setmetatable({}, { - __iter = function() - local row = i - return function() - if row == 0 then - i = 0 - table.clear(entities) - end - local entity = entities[row] - row -= 1 - return entity - end - end - }) + return function() + local row = i + return function() + if row == 0 then + i = 0 + table.clear(entities) + end + local entity = entities[row] + row -= 1 + return entity + end + end end local function join(world, component) @@ -152,6 +150,19 @@ local function monitors_new(world, query, callback) world:added(term, emplaced) world:removed(term, removed) end + + return function() + local row = i + return function() + if row == 0 then + i = 0 + table.clear(entities) + end + local entity = entities[row] + row -= 1 + return entity + end + end end local function observers_add(world: jecs.World): PatchedWorld