From f60826c3a14ba3b49077f17e5364b7347f9b468a Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 23 Mar 2018 16:24:49 +0100 Subject: 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. --- player/lua.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'player/lua.c') 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} }; -- cgit v1.2.3