summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/defaults.lua21
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 }