Home

Awesome

MoonTimers: Concurrent timers for Lua

MoonTimers is a Lua module that provides concurrent timers.

It runs on GNU/Linux and on Windows (MSYS2/MinGW) and requires Lua (>=5.3).

Author: Stefano Trettel

Lua logo

License

MIT/X11 license (same as Lua). See LICENSE.

Documentation

See the Reference Manual.

Getting and installing

Setup the build environment as described here, then:

$ git clone https://github.com/stetre/moontimers
$ cd moontimers
moontimers$ make
moontimers$ sudo make install

Examples

The example below creates a timer, starts it so to expire after 2 seconds, and restarts it each time it expires.

Other examples can be found in the examples/ directory of this repo.

-- MoonTimers example: hello.lua
local timers = require("moontimers")

local duration = 2 -- seconds
local function callback(timer, exptime)
   print(string.format("timer expired, system time = %f", timers.now()))
   timer:start(exptime+duration)
end

-- Create a timer:
local t1 = timers.new(duration, callback)

-- Start it:
t1:start()

-- Event loop:
while true do
   timers.trigger()
end

The script can be executed at the shell prompt with the standard Lua interpreter:

$ lua hello.lua

See the examples/ directory.

See also