timer: Add a callback constructor property

Avoids having to keep a local variable just to be able to
register the callback.
This commit is contained in:
Emmanuel Lepage Vallee 2016-12-28 23:56:03 -05:00
parent bd96eacbe2
commit d8f51a4039
1 changed files with 6 additions and 0 deletions

View File

@ -105,6 +105,8 @@ local timer_instance_mt = {
-- @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. -- @tparam[opt=false] boolean args.autostart Automatically start the timer.
-- @tparam[opt=nil] function args.callback Callback function to connect to the
-- "timeout" signal.
-- @treturn timer -- @treturn timer
-- @function gears.timer -- @function gears.timer
function timer.new(args) function timer.new(args)
@ -122,6 +124,10 @@ function timer.new(args)
ret:start() ret:start()
end end
if args.callback then
ret:connect_signal("timeout", args.callback)
end
return ret return ret
end end