diff options
author | Mike Will <myQwil@gmail.com> | 2023-10-06 18:38:46 -0400 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-10-11 21:04:13 +0000 |
commit | 5ac37500c5f069b749ea06489cc45be749f4bc9c (patch) | |
tree | 54f4cb9b2dd909461bf29ce14ab14c7ce10f77da /player/lua/defaults.lua | |
parent | 644cf010678aefe3c8f93d03129f08ebab48bf72 (diff) | |
download | mpv-5ac37500c5f069b749ea06489cc45be749f4bc9c.tar.bz2 mpv-5ac37500c5f069b749ea06489cc45be749f4bc9c.tar.xz |
defaults.lua: add a disabled parameter to timer constructors
Added to the functions `mp.add_timeout` and `mp.add_periodic_timer`.
If the `disabled` argument is set to `true` or a truthy value, the
timer will wait to be manually started with a call to its `resume()`
method.
Diffstat (limited to 'player/lua/defaults.lua')
-rw-r--r-- | player/lua/defaults.lua | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index e0914115f5..2246dccfa4 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -265,20 +265,22 @@ local timers = {} local timer_mt = {} timer_mt.__index = timer_mt -function mp.add_timeout(seconds, cb) - local t = mp.add_periodic_timer(seconds, cb) +function mp.add_timeout(seconds, cb, disabled) + local t = mp.add_periodic_timer(seconds, cb, disabled) t.oneshot = true return t end -function mp.add_periodic_timer(seconds, cb) +function mp.add_periodic_timer(seconds, cb, disabled) local t = { timeout = seconds, cb = cb, oneshot = false, } setmetatable(t, timer_mt) - t:resume() + if not disabled then + t:resume() + end return t end |