Showing the changes to player/javascript/defaults.js (1 of 2 files). Show all
Unified · Split
| @@ -123,22 +123,19 @@ function dispatch_message(ev) { · 122 unmodified lines | ||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // ----- hooks ----- |
| 126 | −var next_hid = 1, | |
| 127 | − hooks = new_cache(); // items of id: fn | |
| 126 | +var hooks = []; // array of callbacks, id is index+1 | |
| 128 | 127 | |
| 129 | −function hook_run(id, cont) { | |
| 130 | − var cb = hooks[id]; | |
| 128 | +function run_hook(ev) { | |
| 129 | + var cb = ev.id > 0 && hooks[ev.id - 1]; | |
| 131 | 130 | if (cb) |
| 132 | 131 | cb(); |
| 133 | − mp.commandv("hook-ack", cont); | |
| 132 | + mp._hook_continue(ev.hook_id); | |
| 134 | 133 | } |
| 135 | 134 | |
| 136 | 135 | mp.add_hook = function add_hook(name, pri, fn) { |
| 137 | − if (next_hid == 1) // doesn't really matter if we do it once or always | |
| 138 | − mp.register_script_message("hook_run", hook_run); | |
| 139 | − var id = next_hid++; | |
| 140 | − hooks[id] = fn; | |
| 141 | − return mp.commandv("hook-add", name, id, pri); | |
| 136 | + hooks.push(fn); | |
| 137 | + // 50 (scripting docs default priority) maps to 0 (default in C API docs) | |
| 138 | + return mp._hook_add(name, pri - 50, hooks.length); | |
| 142 | 139 | } |
| 143 | 140 | |
| 144 | 141 | /********************************************************************** |
| @@ -559,6 +556,7 @@ mp.keep_running = true; · 414 unmodified lines | ||
| 559 | 556 | g.exit = function() { mp.keep_running = false }; // user-facing too |
| 560 | 557 | mp.register_event("shutdown", g.exit); |
| 561 | 558 | mp.register_event("property-change", notify_observer); |
| 559 | +mp.register_event("hook", run_hook); | |
| 562 | 560 | mp.register_event("client-message", dispatch_message); |
| 563 | 561 | mp.register_script_message("key-binding", dispatch_key_binding); |
| 564 | 562 | |