1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-22 06:42:03 +00:00

lua: allow unregistration of idle handlers

This commit is contained in:
Olivier Perret 2017-01-15 16:22:19 +01:00 committed by wm4
parent 397705b12c
commit 348c610b68
2 changed files with 15 additions and 0 deletions

View File

@ -451,6 +451,11 @@ are useful only in special situations.
multiple properties at once, you might not want to act on each property multiple properties at once, you might not want to act on each property
change, but only when all change notifications have been received. 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)`` ``mp.enable_messages(level)``
Set the minimum log level of which mpv message output to receive. These Set the minimum log level of which mpv message output to receive. These
messages are normally printed to the terminal. By calling this function, messages are normally printed to the terminal. By calling this function,

View File

@ -419,6 +419,16 @@ function mp.register_idle(cb)
idle_handlers[#idle_handlers + 1] = cb idle_handlers[#idle_handlers + 1] = cb
end 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" -- sent by "script-binding"
mp.register_script_message("key-binding", dispatch_key_binding) mp.register_script_message("key-binding", dispatch_key_binding)