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:
wm4
2013-12-20 18:01:04 +01:00
parent 833eba5304
commit 18930ba7dd
3 changed files with 185 additions and 70 deletions

View File

@@ -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),