summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-12 18:48:35 +0200
committerwm4 <wm4@nowhere>2018-05-24 19:56:34 +0200
commitdbe831bd025d34930b97c493d9ef61278408cf46 (patch)
tree3430a50e39d1785b5ba919bd5180bdc67dfcf6e0 /player
parent9c530c7ee9ac0641e58ac1203bd46675e8700cc5 (diff)
downloadmpv-dbe831bd025d34930b97c493d9ef61278408cf46.tar.bz2
mpv-dbe831bd025d34930b97c493d9ef61278408cf46.tar.xz
lua: expose mpv_abort_async_command()
Also somewhat cleans up mp.command_native_async() error handling.
Diffstat (limited to 'player')
-rw-r--r--player/lua.c9
-rw-r--r--player/lua/defaults.lua20
2 files changed, 26 insertions, 3 deletions
diff --git a/player/lua.c b/player/lua.c
index d08aaa3b45..757f449f7b 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -985,6 +985,14 @@ static int script_raw_command_native_async(lua_State *L)
return check_error(L, res);
}
+static int script_raw_abort_async_command(lua_State *L)
+{
+ struct script_ctx *ctx = get_ctx(L);
+ uint64_t id = luaL_checknumber(L, 1);
+ mpv_abort_async_command(ctx->client, id);
+ return 0;
+}
+
static int script_set_osd_ass(lua_State *L)
{
struct script_ctx *ctx = get_ctx(L);
@@ -1252,6 +1260,7 @@ static const struct fn_entry main_fns[] = {
FN_ENTRY(commandv),
FN_ENTRY(command_native),
FN_ENTRY(raw_command_native_async),
+ FN_ENTRY(raw_abort_async_command),
FN_ENTRY(get_property_bool),
FN_ENTRY(get_property_number),
FN_ENTRY(get_property_native),
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index a00a563478..1da6420182 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -534,13 +534,21 @@ local async_next_id = 1
function mp.command_native_async(node, cb)
local id = async_next_id
async_next_id = async_next_id + 1
- async_call_table[id] = cb
- mp.raw_command_native_async(id, node)
+ local res, err = mp.raw_command_native_async(id, node)
+ if not res then
+ cb(false, nil, err)
+ return res, err
+ end
+ local t = {cb = cb, id = id}
+ async_call_table[id] = t
+ return t
end
mp.register_event("command-reply", function(ev)
local id = tonumber(ev.id)
- cb = async_call_table[id]
+ local t = async_call_table[id]
+ local cb = t.cb
+ t.id = nil
async_call_table[id] = nil
if ev.error then
cb(false, nil, ev.error)
@@ -549,6 +557,12 @@ mp.register_event("command-reply", function(ev)
end
end)
+function mp.abort_async_command(t)
+ if t.id ~= nil then
+ mp.raw_abort_async_command(t.id)
+ end
+end
+
local mp_utils = package.loaded["mp.utils"]
function mp_utils.format_table(t, set)