diff options
Diffstat (limited to 'player/lua/defaults.lua')
-rw-r--r-- | player/lua/defaults.lua | 20 |
1 files changed, 17 insertions, 3 deletions
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) |