From 6e72b85232a5801dc8f700fcaebf8495a92df7ed Mon Sep 17 00:00:00 2001 From: kikito Date: Sat, 27 Oct 2012 18:31:21 +0200 Subject: [PATCH] Rollback loop change (references #2) Tests didn't pass. Further examination revealed that, even if the Lua standard seems to allow for eliminating table keys while parsing it in a loop, in reality those values remained in the table. --- cron.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cron.lua b/cron.lua index 3e2708b..1ededbe 100644 --- a/cron.lua +++ b/cron.lua @@ -79,8 +79,12 @@ end function cron.update(dt) assert(type(dt) == "number" and dt >= 0, "dt must be a non-negative number") + local expired = {} for id, entry in pairs(entries) do - if entry:update(dt) then entry[id] = nil end + if entry:update(dt) then expired[id] = true end + end + for id,_ in pairs(expired) do + entries[id] = nil end end