From 42c3b9b47ecd760af3a3a3d6ff5698b9378544a8 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sat, 31 Mar 2012 15:05:07 +0200 Subject: [PATCH] Make Timer.add[Periodic]() return timer handle. Export Timer.handle --- timer.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/timer.lua b/timer.lua index d3fbb46..d8fd2d8 100644 --- a/timer.lua +++ b/timer.lua @@ -41,18 +41,15 @@ local function update(dt) end local function add(delay, func) - assert(not functions[func], ("Function already scheduled to run in %.2fs"):format(functions[func])) + assert(not functions[func], "Function already scheduled to run.") functions[func] = delay -end - -local function cancel(func) - functions[func] = nil + return func end local function addPeriodic(delay, func, count) local count = count or math.huge -- exploit below: math.huge - 1 = math.huge - add(delay, function(f) + return add(delay, function(f) if func(func) == false then return end count = count - 1 if count > 0 then @@ -61,6 +58,10 @@ local function addPeriodic(delay, func, count) end) end +local function cancel(func) + functions[func] = nil +end + local function clear() functions = {} end @@ -86,6 +87,7 @@ return { update = update, add = add, addPeriodic = addPeriodic, + cancel = cancel, clear = clear, Interpolator = Interpolator, Oscillator = Oscillator