summaryrefslogtreecommitdiffstats
path: root/player/lua.c
diff options
context:
space:
mode:
Diffstat (limited to 'player/lua.c')
-rw-r--r--player/lua.c136
1 files changed, 28 insertions, 108 deletions
diff --git a/player/lua.c b/player/lua.c
index 98dcfee5b2..757f449f7b 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -562,6 +562,12 @@ static int script_wait_event(lua_State *L)
lua_setfield(L, -2, "hook_id");
break;
}
+ case MPV_EVENT_COMMAND_REPLY: {
+ mpv_event_command *cmd = event->data;
+ pushnode(L, &cmd->result);
+ lua_setfield(L, -2, "result");
+ break;
+ }
default: ;
}
@@ -967,6 +973,26 @@ static int script_command_native(lua_State *L)
return 2;
}
+static int script_raw_command_native_async(lua_State *L)
+{
+ struct script_ctx *ctx = get_ctx(L);
+ uint64_t id = luaL_checknumber(L, 1);
+ struct mpv_node node;
+ void *tmp = mp_lua_PITA(L);
+ makenode(tmp, &node, L, 2);
+ int res = mpv_command_node_async(ctx->client, id, &node);
+ talloc_free_children(tmp);
+ 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);
@@ -1169,112 +1195,6 @@ static int script_join_path(lua_State *L)
return 1;
}
-struct subprocess_cb_ctx {
- struct mp_log *log;
- void* talloc_ctx;
- int64_t max_size;
- bstr output;
-};
-
-static void subprocess_stdout(void *p, char *data, size_t size)
-{
- struct subprocess_cb_ctx *ctx = p;
- if (ctx->output.len < ctx->max_size)
- bstr_xappend(ctx->talloc_ctx, &ctx->output, (bstr){data, size});
-}
-
-static void subprocess_stderr(void *p, char *data, size_t size)
-{
- struct subprocess_cb_ctx *ctx = p;
- MP_INFO(ctx, "%.*s", (int)size, data);
-}
-
-static int script_subprocess(lua_State *L)
-{
- struct script_ctx *ctx = get_ctx(L);
- luaL_checktype(L, 1, LUA_TTABLE);
- void *tmp = mp_lua_PITA(L);
-
- lua_getfield(L, 1, "args"); // args
- int num_args = mp_lua_len(L, -1);
- char *args[256];
- if (num_args > MP_ARRAY_SIZE(args) - 1) // last needs to be NULL
- luaL_error(L, "too many arguments");
- if (num_args < 1)
- luaL_error(L, "program name missing");
- for (int n = 0; n < num_args; n++) {
- lua_pushinteger(L, n + 1); // args n
- lua_gettable(L, -2); // args arg
- args[n] = talloc_strdup(tmp, lua_tostring(L, -1));
- if (!args[n])
- luaL_error(L, "program arguments must be strings");
- lua_pop(L, 1); // args
- }
- args[num_args] = NULL;
- lua_pop(L, 1); // -
-
- lua_getfield(L, 1, "cancellable"); // c
- struct mp_cancel *cancel = NULL;
- if (lua_isnil(L, -1) ? true : lua_toboolean(L, -1))
- cancel = ctx->mpctx->playback_abort;
- lua_pop(L, 1); // -
-
- lua_getfield(L, 1, "max_size"); // m
- int64_t max_size = lua_isnil(L, -1) ? 64 * 1024 * 1024 : lua_tointeger(L, -1);
-
- struct subprocess_cb_ctx cb_ctx = {
- .log = ctx->log,
- .talloc_ctx = tmp,
- .max_size = max_size,
- };
-
- char *error = NULL;
- int status = mp_subprocess(args, cancel, &cb_ctx, subprocess_stdout,
- subprocess_stderr, &error);
-
- lua_newtable(L); // res
- if (error) {
- lua_pushstring(L, error); // res e
- lua_setfield(L, -2, "error"); // res
- }
- lua_pushinteger(L, status); // res s
- lua_setfield(L, -2, "status"); // res
- lua_pushlstring(L, cb_ctx.output.start, cb_ctx.output.len); // res d
- lua_setfield(L, -2, "stdout"); // res
- lua_pushboolean(L, status == MP_SUBPROCESS_EKILLED_BY_US); // res b
- lua_setfield(L, -2, "killed_by_us"); // res
- return 1;
-}
-
-static int script_subprocess_detached(lua_State *L)
-{
- struct script_ctx *ctx = get_ctx(L);
- luaL_checktype(L, 1, LUA_TTABLE);
- void *tmp = mp_lua_PITA(L);
-
- lua_getfield(L, 1, "args"); // args
- int num_args = mp_lua_len(L, -1);
- char *args[256];
- if (num_args > MP_ARRAY_SIZE(args) - 1) // last needs to be NULL
- luaL_error(L, "too many arguments");
- if (num_args < 1)
- luaL_error(L, "program name missing");
- for (int n = 0; n < num_args; n++) {
- lua_pushinteger(L, n + 1); // args n
- lua_gettable(L, -2); // args arg
- args[n] = talloc_strdup(tmp, lua_tostring(L, -1));
- if (!args[n])
- luaL_error(L, "program arguments must be strings");
- lua_pop(L, 1); // args
- }
- args[num_args] = NULL;
- lua_pop(L, 1); // -
-
- mp_subprocess_detached(ctx->log, args);
- lua_pushnil(L);
- return 1;
-}
-
static int script_getpid(lua_State *L)
{
lua_pushnumber(L, mp_getpid());
@@ -1339,6 +1259,8 @@ static const struct fn_entry main_fns[] = {
FN_ENTRY(command),
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),
@@ -1367,8 +1289,6 @@ static const struct fn_entry utils_fns[] = {
FN_ENTRY(file_info),
FN_ENTRY(split_path),
FN_ENTRY(join_path),
- FN_ENTRY(subprocess),
- FN_ENTRY(subprocess_detached),
FN_ENTRY(getpid),
FN_ENTRY(parse_json),
FN_ENTRY(format_json),