Fix issue #24: cancel not removing periodic timers.

This commit is contained in:
Matthias Richter 2013-08-22 11:10:56 +02:00
parent 87b82750ff
commit ff60ae5372
2 changed files with 5 additions and 4 deletions

View File

@ -7,7 +7,7 @@ Contents:
------------
* *gamestate.lua*: Easy gamestate management.
* *timer.lua*: Delayed and time-limited function calls.
* *timer.lua*: Delayed and time-limited function calls and tweening functionality.
* *vector.lua*: 2D vector math.
* *vector-light.lua*: Lightweight 2D vector math (for optimisation purposes - leads to potentially ugly code).
* *class.lua*: Lightweight object orientation (class or prototype based).

View File

@ -60,15 +60,16 @@ function Timer:add(delay, func)
end
function Timer:addPeriodic(delay, func, count)
local count = count or math.huge -- exploit below: math.huge - 1 = math.huge
local count, handle = count or math.huge -- exploit below: math.huge - 1 = math.huge
return self:add(delay, function(f)
handle = self:add(delay, function(f)
if func(func) == false then return end
count = count - 1
if count > 0 then
self:add(delay, f)
self.functions[handle] = delay
end
end)
return handle
end
function Timer:cancel(handle)