diff options
author | wm4 <wm4@nowhere> | 2016-09-21 14:36:10 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-09-21 15:47:52 +0200 |
commit | 47f3cc7e6bf78609551312f84c93cccf194a5930 (patch) | |
tree | 7376da7cbdc383d486c7a446b11837543729ad57 /player | |
parent | b521f15ae9799a08d1cb328e3c1ef294d75f30c2 (diff) | |
download | mpv-47f3cc7e6bf78609551312f84c93cccf194a5930.tar.bz2 mpv-47f3cc7e6bf78609551312f84c93cccf194a5930.tar.xz |
lua: add API for registering idle handlers
This is only a functionality the Lua event dispatcher provides, rather
than the libmpv client API.
Diffstat (limited to 'player')
-rw-r--r-- | player/lua/defaults.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 2c38361994..c65fda7c9b 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -412,6 +412,13 @@ mp.register_event("shutdown", function() mp.keep_running = false end) mp.register_event("client-message", message_dispatch) mp.register_event("property-change", property_change) +-- called before the event loop goes back to sleep +local idle_handlers = {} + +function mp.register_idle(cb) + idle_handlers[#idle_handlers + 1] = cb +end + -- sent by "script-binding" mp.register_script_message("key-binding", dispatch_key_binding) @@ -455,6 +462,9 @@ function mp.dispatch_events(allow_wait) if not more_events then wait = process_timers() if wait == nil then + for _, handler in ipairs(idle_handlers) do + handler() + end wait = 1e20 -- infinity for all practical purposes end -- Resume playloop - important especially if an error happened while |