diff options
author | wm4 <wm4@nowhere> | 2018-03-23 16:24:49 +0100 |
---|---|---|
committer | Kevin Mitchell <kevmitch@gmail.com> | 2018-03-26 23:02:23 -0700 |
commit | f60826c3a14ba3b49077f17e5364b7347f9b468a (patch) | |
tree | 285f39963a9f978939743b12527539e1ec8a3f54 /player/lua/defaults.lua | |
parent | 6d7cfdfae582353e1f10797bb2c587e6ada0aed7 (diff) | |
download | mpv-f60826c3a14ba3b49077f17e5364b7347f9b468a.tar.bz2 mpv-f60826c3a14ba3b49077f17e5364b7347f9b468a.tar.xz |
client API: add a first class hook API, and deprecate old API
As it turns out, there are multiple libmpv users who saw a need to
use the hook API. The API is kind of shitty and was never meant to be
actually public (it was mostly a hack for the ytdl script).
Introduce a proper API and deprecate the old one. The old one will
probably continue to work for a few releases, but will be removed
eventually.
There are some slight changes to the old API, but if a user followed
the manual properly, it won't break.
Mostly untested. Appears to work with ytdl_hook.
Diffstat (limited to 'player/lua/defaults.lua')
-rw-r--r-- | player/lua/defaults.lua | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 32dfed9948..d5bb194c50 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -511,24 +511,21 @@ function mp.osd_message(text, duration) end local hook_table = {} -local hook_registered = false -local function hook_run(id, cont) - local fn = hook_table[tonumber(id)] +mp.register_event("hook", function(ev) + local fn = hook_table[tonumber(ev.id)] if fn then fn() end - mp.commandv("hook-ack", cont) -end + mp.raw_hook_continue(ev.hook_id) +end) function mp.add_hook(name, pri, cb) - if not hook_registered then - mp.register_script_message("hook_run", hook_run) - hook_registered = true - end local id = #hook_table + 1 hook_table[id] = cb - mp.commandv("hook-add", name, id, pri) + -- The C API suggests using 0 for a neutral priority, but lua.rst suggests + -- 50 (?), so whatever. + mp.raw_hook_add(id, name, pri - 50) end local mp_utils = package.loaded["mp.utils"] |