From 26909c1113ab86801ca3e1f8097f7ed0e06d35d4 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 8 Apr 2015 21:21:44 +0200 Subject: manpage: lua: clarify timer usage This seems to come up often. I guess '.' vs. ':' for Lua calls is confusing, and this part of the scripting API is the only one which requires using it. --- DOCS/man/lua.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst index d8912dac2b..4700b90cb2 100644 --- a/DOCS/man/lua.rst +++ b/DOCS/man/lua.rst @@ -356,6 +356,23 @@ The ``mp`` module is preloaded, although it can be loaded manually with (``true``). This value is used when the timer expires (but before the timer callback function fn is run). + Note that these are method, and you have to call them using ``:`` instead + of ``.`` (Refer to http://www.lua.org/manual/5.2/manual.html#3.4.9 .) + + Example: + + :: + + seconds = 0 + timer = mp.add_periodic_timer(1, function() + print("called every second") + # stop it after 10 seconds + seconds = seconds + 1 + if seconds >= 10 then + timer:kill() + end + end) + ``mp.get_opt(key)`` Return a setting from the ``--script-opts`` option. It's up to the user and -- cgit v1.2.3