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:
parent
397705b12c
commit
348c610b68
@ -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,
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user