-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Bruno Silvestre edited this page Aug 27, 2014
·
3 revisions
- Move almost all implementation from C to Lua. The C library only retrieves the time in microseconds;
- Add Windows platform;
- Use poll of timers.
luatimer.createpoll()
Create a new poll of timers.
poll:create(freq)
Create a new timer with frequence freq (in seconds). Use decimal numbers to precision in milli or microseconds.
poll:cancel(t)
Cancel the timer t, removing it from the poll. However, passing the string "all" to this function, all the timers in the poll are cancelled.
poll:size()
Return the number of timers in the poll.
poll:nextshot()
Return the remain among of time to the next timer expires. If some timer is already expired, the function returns 0 (zero).
poll:fired(t)
Return the timers that were expired. If t is the string "all", the function returns a table with all the expired timers. If t is a string "one", the function returns one of the expired timers. In the case that there is no expired times, fired() returns nil.
require("luatimer")
timers = luatimer.createpoll()
t3 = timers:create(3)
t5 = timers:create(5)
t6 = timers:create(6)
print("poll size", timers:size())
print("Next shot: ", timers:nextshot())
-- sleep(4 segundos)
t = timers:fired("one")
print(t)
print(t == t3)
timers:cancel(t3)
print(timers:nextshot())
-- sleep(3 segundos)
tb = timers:fired("all")
for k, t in ipairs(tb) do
print(t)
end
timers:cancel("all")