diff options
Diffstat (limited to 'player/lua.c')
-rw-r--r-- | player/lua.c | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/player/lua.c b/player/lua.c index 84d7295640..442a2ba073 100644 --- a/player/lua.c +++ b/player/lua.c @@ -377,8 +377,10 @@ static int load_lua(struct mpv_handle *client, const char *fname) } lua_State *L = ctx->state = luaL_newstate(); - if (!L) + if (!L) { + MP_FATAL(ctx, "Could not initialize Lua.\n"); goto error_out; + } if (mp_cpcall(L, run_lua, ctx)) { const char *err = "unknown error"; @@ -391,7 +393,6 @@ static int load_lua(struct mpv_handle *client, const char *fname) r = 0; error_out: - osd_set_external(ctx->mpctx->osd, client, 0, 0, NULL); // remove overlay mp_resume_all(client); if (ctx->state) lua_close(ctx->state); @@ -450,6 +451,8 @@ static int script_find_config_file(lua_State *L) static int script_suspend(lua_State *L) { struct script_ctx *ctx = get_ctx(L); + MP_WARN(ctx, "mp.suspend() (possibly triggered by mp.use_suspend) is " + "deprecated.\n"); mpv_suspend(ctx->client); return 0; } @@ -708,7 +711,7 @@ static void makenode(void *tmp, mpv_node *dst, lua_State *L, int t) bool empty = lua_isnil(L, -1); // t[n] lua_pop(L, 1); // - if (empty) { - count = n; + count = n - 1; break; } } @@ -750,7 +753,7 @@ static void makenode(void *tmp, mpv_node *dst, lua_State *L, int t) makenode(tmp, &list->values[list->num], L, -1); if (lua_type(L, -2) != LUA_TSTRING) { luaL_error(L, "key must be a string, but got %s", - lua_typename(L, -2)); + lua_typename(L, lua_type(L, -2))); } list->keys[list->num] = talloc_strdup(tmp, lua_tostring(L, -2)); list->num++; @@ -971,7 +974,7 @@ static int script_set_osd_ass(lua_State *L) if (!text[0]) text = " "; // force external OSD initialization osd_set_external(ctx->mpctx->osd, ctx->client, res_x, res_y, (char *)text); - mp_input_wakeup(ctx->mpctx->input); + mp_wakeup_core(ctx->mpctx); return 0; } @@ -1184,6 +1187,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); @@ -1268,6 +1302,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} |