From 348c610b68edb578b98d08b27760f09cb7063fe2 Mon Sep 17 00:00:00 2001 From: Olivier Perret Date: Sun, 15 Jan 2017 16:22:19 +0100 Subject: lua: allow unregistration of idle handlers --- DOCS/man/lua.rst | 5 +++++ player/lua/defaults.lua | 10 ++++++++++ 2 files changed, 15 insertions(+) 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) -- cgit v1.2.3