mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
input, lua: add functions to take pre-split input commands
So you can pass a command as list of strings (each item is an argument), instead of having to worry about escaping and such. These functions also take an argument for the default command flags. In particular, this allows setting saner defaults for commands sent by program code. Expose this to Lua as mp.send_commandv command (suggestions for a better name welcome). The Lua version doesn't allow setting the default command flags, but it can still use command prefixes. The default flags are different from input.conf, and disable OSD and property expansion.
This commit is contained in:
23
player/lua.c
23
player/lua.c
@@ -378,6 +378,28 @@ static int script_send_command(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int script_send_commandv(lua_State *L)
|
||||
{
|
||||
struct script_ctx *ctx = get_ctx(L);
|
||||
int num = lua_gettop(L);
|
||||
bstr args[50];
|
||||
if (num > MP_ARRAY_SIZE(args))
|
||||
luaL_error(L, "too many arguments");
|
||||
for (int n = 1; n <= num; n++) {
|
||||
size_t len;
|
||||
const char *s = lua_tolstring(L, n, &len);
|
||||
if (!s)
|
||||
luaL_error(L, "argument %d is not a string", n);
|
||||
args[n - 1] = (bstr){(char *)s, len};
|
||||
}
|
||||
mp_cmd_t *cmd = mp_input_parse_cmd_bstrv(ctx->log, 0, num, args, "<lua>");
|
||||
if (!cmd)
|
||||
luaL_error(L, "error parsing command");
|
||||
mp_input_queue_cmd(ctx->mpctx->input, cmd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int script_property_list(lua_State *L)
|
||||
{
|
||||
const struct m_option *props = mp_get_property_list();
|
||||
@@ -625,6 +647,7 @@ static struct fn_entry fn_list[] = {
|
||||
FN_ENTRY(log),
|
||||
FN_ENTRY(find_config_file),
|
||||
FN_ENTRY(send_command),
|
||||
FN_ENTRY(send_commandv),
|
||||
FN_ENTRY(property_list),
|
||||
FN_ENTRY(set_osd_ass),
|
||||
FN_ENTRY(get_osd_resolution),
|
||||
|
||||
Reference in New Issue
Block a user