From 2fc72cf66d660322ee190cd3ee67fbd08ddb42ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20Garc=C3=ADa=20Cota?= Date: Sun, 24 Apr 2011 17:15:54 +0200 Subject: [PATCH] small update refactoring --- cron.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cron.lua b/cron.lua index 354a60f..67ad1f1 100644 --- a/cron.lua +++ b/cron.lua @@ -25,11 +25,11 @@ local function newEntry(time, callback, update, ...) return entry end -local function updateTimedEntry(self, dt) +local function updateTimedEntry(self, dt) -- returns true if expired self.running = self.running + dt if self.running >= self.time then self.callback(unpack(self.args)) - self.expired = true + return true end end @@ -68,11 +68,10 @@ function cron.update(dt) local expired = {} for _, entry in pairs(entries) do - entry:update(dt, runningTime) - if entry.expired then expired[entry] = entry end + if entry:update(dt, runningTime) then table.insert(expired,entry) end end - for _, entry in pairs(expired) do entries[entry] = nil end + for i=1, #expired do entries[expired[i]] = nil end end return cron