calog/examples/scripts/libraries/timer.lua

20 lines
521 B
Lua

-- Showcase the calog timer library with Lua callbacks: timerAfter schedules a
-- one-shot, timerEvery fires a repeating tick, and the tick handler cancels its
-- own timer after 3 ticks and then exits.
-- Run: bin/calog examples/scripts/libraries/timer.lua
timerAfter(100, function()
calogPrint("one-shot")
end)
local ticks = 0
local tickId
tickId = timerEvery(60, function()
ticks = ticks + 1
calogPrint("tick", ticks)
if ticks >= 3 then
timerCancel(tickId)
calogExit(0)
end
end)