1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 15:22:09 +00:00

lua: expose subprocess_detached

This commit is contained in:
rr- 2016-09-20 20:32:16 +02:00 committed by wm4
parent af6126adbe
commit f66f0b34c8
2 changed files with 45 additions and 0 deletions

View File

@ -635,6 +635,19 @@ strictly part of the guaranteed API.
In all cases, ``mp.resume_all()`` is implicitly called.
``utils.subprocess_detached(t)``
Runs an external process and detaches it from mpv's control.
The parameter ``t`` is a table. The function reads the following entries:
``args``
Array of strings of the same semantics as the ``args`` used in the
``subprocess`` function.
The function returns ``nil``.
In all cases, ``mp.resume_all()`` is implicitly called.
``utils.parse_json(str [, trail])``
Parses the given string argument as JSON, and returns it as a Lua table. On
error, returns ``nil, error``. (Currently, ``error`` is just a string

View File

@ -1185,6 +1185,37 @@ static int script_subprocess(lua_State *L)
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);
mp_resume_all(ctx->client);
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_parse_json(lua_State *L)
{
mp_lua_optarg(L, 2);
@ -1269,6 +1300,7 @@ static const struct fn_entry utils_fns[] = {
FN_ENTRY(split_path),
FN_ENTRY(join_path),
FN_ENTRY(subprocess),
FN_ENTRY(subprocess_detached),
FN_ENTRY(parse_json),
FN_ENTRY(format_json),
{0}