timer: Add an autostart constructor property
This commit is contained in:
parent
2c3aebc19e
commit
bd96eacbe2
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue