timer: Add an autostart constructor property

This commit is contained in:
Emmanuel Lepage Vallee 2016-12-28 23:52:36 -05:00
parent 2c3aebc19e
commit bd96eacbe2
1 changed files with 7 additions and 1 deletions

View File

@ -104,9 +104,11 @@ local timer_instance_mt = {
--- Create a new timer object. --- Create a new timer object.
-- @tparam table args Arguments. -- @tparam table args Arguments.
-- @tparam number args.timeout Timeout in seconds (e.g. 1.5). -- @tparam number args.timeout Timeout in seconds (e.g. 1.5).
-- @tparam[opt=false] boolean args.autostart Automatically start the timer.
-- @treturn timer -- @treturn timer
-- @function gears.timer -- @function gears.timer
timer.new = function(args) function timer.new(args)
args = args or {}
local ret = object() local ret = object()
ret.data = { timeout = 0 } ret.data = { timeout = 0 }
@ -116,6 +118,10 @@ timer.new = function(args)
ret[k] = v ret[k] = v
end end
if args.autostart then
ret:start()
end
return ret return ret
end end