From f66f0b34c8aabe8883a85b46d42e5893d633c81c Mon Sep 17 00:00:00 2001 From: rr- Date: Tue, 20 Sep 2016 20:32:16 +0200 Subject: lua: expose subprocess_detached --- player/lua.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'player') 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} -- cgit v1.2.3