1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-29 18:42:09 +00:00

lua: reimplement mp.subprocess_detached() by invoking the "run" command

The "run" command is old. I'm not sure why the separate Lua
implementation was added. But maybe it as because the "run" command used
to be limited to a small number of arguments. This limit has been
removed a while ago. In any case, the old implementation is not needed
anymore.
This commit is contained in:
wm4 2018-05-12 16:03:04 +02:00
parent 548ef07864
commit 7f91e2684e
3 changed files with 7 additions and 30 deletions

View File

@ -682,6 +682,9 @@ strictly part of the guaranteed API.
The function returns ``nil``. The function returns ``nil``.
This is a legacy wrapper around calling the ``run`` command with
``mp.commandv`` and other functions.
``utils.getpid()`` ``utils.getpid()``
Returns the process ID of the running mpv process. This can be used to identify Returns the process ID of the running mpv process. This can be used to identify
the calling mpv when launching (detached) subprocesses. the calling mpv when launching (detached) subprocesses.

View File

@ -1187,35 +1187,6 @@ static int script_join_path(lua_State *L)
return 1; 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) static int script_getpid(lua_State *L)
{ {
lua_pushnumber(L, mp_getpid()); lua_pushnumber(L, mp_getpid());
@ -1309,7 +1280,6 @@ static const struct fn_entry utils_fns[] = {
FN_ENTRY(file_info), FN_ENTRY(file_info),
FN_ENTRY(split_path), FN_ENTRY(split_path),
FN_ENTRY(join_path), FN_ENTRY(join_path),
FN_ENTRY(subprocess_detached),
FN_ENTRY(getpid), FN_ENTRY(getpid),
FN_ENTRY(parse_json), FN_ENTRY(parse_json),
FN_ENTRY(format_json), FN_ENTRY(format_json),

View File

@ -640,4 +640,8 @@ function mp_utils.subprocess(t)
return res return res
end end
function mp_utils.subprocess_detached(t)
mp.commandv("run", unpack(t.args))
end
return {} return {}