diff options
author | rr- <rr-@sakuya.pl> | 2016-09-20 20:32:16 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-09-21 12:43:21 +0200 |
commit | f66f0b34c8aabe8883a85b46d42e5893d633c81c (patch) | |
tree | 1108c5a53568db934fe01887f5d3e67f6acabcee /player/lua.c | |
parent | af6126adbe61fb2b6cc780025246d33df93072e6 (diff) | |
download | mpv-f66f0b34c8aabe8883a85b46d42e5893d633c81c.tar.bz2 mpv-f66f0b34c8aabe8883a85b46d42e5893d633c81c.tar.xz |
lua: expose subprocess_detached
Diffstat (limited to 'player/lua.c')
-rw-r--r-- | player/lua.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/player/lua.c b/player/lua.c index 1c3d526349..8bf8f2b590 100644 --- a/player/lua.c +++ b/player/lua.c @@ -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} |