mirror of
https://github.com/vrld/hump.git
synced 2024-11-23 12:24:19 +00:00
Make Timer.add[Periodic]() return timer handle. Export Timer.handle
This commit is contained in:
parent
7c257c891d
commit
42c3b9b47e
14
timer.lua
14
timer.lua
@ -41,18 +41,15 @@ local function update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function add(delay, func)
|
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
|
functions[func] = delay
|
||||||
end
|
return func
|
||||||
|
|
||||||
local function cancel(func)
|
|
||||||
functions[func] = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function addPeriodic(delay, func, count)
|
local function addPeriodic(delay, func, count)
|
||||||
local count = count or math.huge -- exploit below: math.huge - 1 = math.huge
|
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
|
if func(func) == false then return end
|
||||||
count = count - 1
|
count = count - 1
|
||||||
if count > 0 then
|
if count > 0 then
|
||||||
@ -61,6 +58,10 @@ local function addPeriodic(delay, func, count)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function cancel(func)
|
||||||
|
functions[func] = nil
|
||||||
|
end
|
||||||
|
|
||||||
local function clear()
|
local function clear()
|
||||||
functions = {}
|
functions = {}
|
||||||
end
|
end
|
||||||
@ -86,6 +87,7 @@ return {
|
|||||||
update = update,
|
update = update,
|
||||||
add = add,
|
add = add,
|
||||||
addPeriodic = addPeriodic,
|
addPeriodic = addPeriodic,
|
||||||
|
cancel = cancel,
|
||||||
clear = clear,
|
clear = clear,
|
||||||
Interpolator = Interpolator,
|
Interpolator = Interpolator,
|
||||||
Oscillator = Oscillator
|
Oscillator = Oscillator
|
||||||
|
Loading…
Reference in New Issue
Block a user