diff options
author | wm4 <wm4@nowhere> | 2014-10-21 00:15:30 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-10-21 00:38:56 +0200 |
commit | 40d6b5ca85e61252871158097e099916376a5dd4 (patch) | |
tree | c254727a54dcd2175d7c8412dd692f1ec1250b34 /player/lua/defaults.lua | |
parent | 131633b4e5a378ce67ad7e04ca713097f0c01c71 (diff) | |
download | mpv-40d6b5ca85e61252871158097e099916376a5dd4.tar.bz2 mpv-40d6b5ca85e61252871158097e099916376a5dd4.tar.xz |
lua: add convenience function for hooks
So the user doesn't have to care about the awkward low-level details.
Diffstat (limited to 'player/lua/defaults.lua')
-rw-r--r-- | player/lua/defaults.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 1ae8dd965d..6708f06470 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -399,6 +399,27 @@ function mp.osd_message(text, duration) mp.commandv("show_text", text, duration) end +local hook_table = {} +local hook_registered = false + +local function hook_run(id, cont) + local fn = hook_table[tonumber(id)] + if fn then + fn() + end + mp.commandv("hook_ack", cont) +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) +end + function mp.format_table(t, set) if not set then set = { [t] = true } |