summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Perret <vaeljin@gmail.com>2017-01-15 16:22:19 +0100
committerwm4 <wm4@nowhere>2017-01-15 17:02:21 +0100
commit348c610b68edb578b98d08b27760f09cb7063fe2 (patch)
tree098246b56b9ca989754ba10f02c510cd580b0cb7
parent397705b12ca07984090a5bfc189b5dba8e5c6f39 (diff)
downloadmpv-348c610b68edb578b98d08b27760f09cb7063fe2.tar.bz2
mpv-348c610b68edb578b98d08b27760f09cb7063fe2.tar.xz
lua: allow unregistration of idle handlers
-rw-r--r--DOCS/man/lua.rst5
-rw-r--r--player/lua/defaults.lua10
2 files changed, 15 insertions, 0 deletions
diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst
index 7d91090ca8..e2f47a862a 100644
--- a/DOCS/man/lua.rst
+++ b/DOCS/man/lua.rst
@@ -451,6 +451,11 @@ are useful only in special situations.
multiple properties at once, you might not want to act on each property
change, but only when all change notifications have been received.
+``mp.unregister_idle(fn)``
+ Undo ``mp.register_idle(fn)``. This removes all idle handlers that
+ are equal to the ``fn`` parameter. This uses normal Lua ``==`` comparison,
+ so be careful when dealing with closures.
+
``mp.enable_messages(level)``
Set the minimum log level of which mpv message output to receive. These
messages are normally printed to the terminal. By calling this function,
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index 08616c5638..6669cf38a4 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -419,6 +419,16 @@ function mp.register_idle(cb)
idle_handlers[#idle_handlers + 1] = cb
end
+function mp.unregister_idle(cb)
+ local new = {}
+ for _, handler in ipairs(idle_handlers) do
+ if handler ~= cb then
+ new[#new + 1] = handler
+ end
+ end
+ idle_handlers = new
+end
+
-- sent by "script-binding"
mp.register_script_message("key-binding", dispatch_key_binding)