summaryrefslogtreecommitdiffstats
path: root/player/lua.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-03-23 16:24:49 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-03-26 23:02:23 -0700
commitf60826c3a14ba3b49077f17e5364b7347f9b468a (patch)
tree285f39963a9f978939743b12527539e1ec8a3f54 /player/lua.c
parent6d7cfdfae582353e1f10797bb2c587e6ada0aed7 (diff)
downloadmpv-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.c')
-rw-r--r--player/lua.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/player/lua.c b/player/lua.c
index 778830976c..98dcfee5b2 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -556,6 +556,12 @@ static int script_wait_event(lua_State *L)
lua_setfield(L, -2, "data");
break;
}
+ case MPV_EVENT_HOOK: {
+ mpv_event_hook *hook = event->data;
+ lua_pushinteger(L, hook->id);
+ lua_setfield(L, -2, "hook_id");
+ break;
+ }
default: ;
}
@@ -1046,6 +1052,22 @@ static int script_get_wakeup_pipe(lua_State *L)
return 1;
}
+static int script_raw_hook_add(lua_State *L)
+{
+ struct script_ctx *ctx = get_ctx(L);
+ uint64_t ud = luaL_checkinteger(L, 1);
+ const char *name = luaL_checkstring(L, 2);
+ int pri = luaL_checkinteger(L, 3);
+ return check_error(L, mpv_hook_add(ctx->client, ud, name, pri));
+}
+
+static int script_raw_hook_continue(lua_State *L)
+{
+ struct script_ctx *ctx = get_ctx(L);
+ lua_Integer id = luaL_checkinteger(L, 1);
+ return check_error(L, mpv_hook_continue(ctx->client, id));
+}
+
static int script_readdir(lua_State *L)
{
// 0 1 2 3
@@ -1335,6 +1357,8 @@ static const struct fn_entry main_fns[] = {
FN_ENTRY(format_time),
FN_ENTRY(enable_messages),
FN_ENTRY(get_wakeup_pipe),
+ FN_ENTRY(raw_hook_add),
+ FN_ENTRY(raw_hook_continue),
{0}
};