From e3e9661a33e9c810a6f6be6cd76978d1c2df9ec4 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 2 Apr 2014 17:09:45 +0200 Subject: lua: give more control over timers Now they can be paused and resumed. Since pausing and disabling the timer is essentially the same underlying operation, we also just provide one method for it. mp.cancel_timer probably still works, but I'm considering this deprecated, and it's removed from the manpage. (We didn't have a release with this function yet, so no formal deprecation.) --- DOCS/man/en/lua.rst | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'DOCS/man/en') diff --git a/DOCS/man/en/lua.rst b/DOCS/man/en/lua.rst index 34d1d0e8c3..ac37f1eabb 100644 --- a/DOCS/man/en/lua.rst +++ b/DOCS/man/en/lua.rst @@ -248,17 +248,29 @@ The ``mp`` module is preloaded, although it can be loaded manually with This is a one-shot timer: it will be removed when it's fired. - Returns a timer handle. See ``mp.cancel_timer``. + Returns a timer object. See ``mp.add_periodic_timer`` for details. ``mp.add_periodic_timer(seconds, fn)`` Call the given function periodically. This is like ``mp.add_timeout``, but the timer is re-added after the function fn is run. - Returns a timer handle. See ``mp.cancel_timer``. + Returns a timer object. The timer object provides the following methods: + + ``stop()`` + Disable the timer. Does nothing if the timer is already disabled. + This will remember the current elapsed time when stopping, so that + ``resume()`` essentially unpauses the timer. + + ``kill()`` + Disable the timer. Resets the elapsed time. + + ``resume()`` + Restart the timer. If the timer was disabled with ``stop()``, this + will resume at the time it was stopped. If the timer was disabled + with ``kill()``, or if it's a previously fired one-shot timer (added + with ``add_timeout()``), this starts the timer from the beginning, + using the initially configured timeout. -``mp.cancel_timer(t)`` - Terminate the given timer. t is a timer handle (value returned by - ``mp.add_timeout`` or ``mp.add_periodic_timer``). ``mp.get_opt(key)`` Return a setting from the ``--lua-opts`` option. It's up to the user and -- cgit v1.2.3