summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-20 18:01:04 +0100
committerwm4 <wm4@nowhere>2013-12-20 18:01:04 +0100
commit18930ba7ddf1af59b20bfafd4f9a87f140e16832 (patch)
treea7dd527aadc379f8486dce36ff11133f78c40f87 /player
parent833eba5304474392153189f3cc6b7baa8eb914cc (diff)
downloadmpv-18930ba7ddf1af59b20bfafd4f9a87f140e16832.tar.bz2
mpv-18930ba7ddf1af59b20bfafd4f9a87f140e16832.tar.xz
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.
Diffstat (limited to 'player')
-rw-r--r--player/lua.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/player/lua.c b/player/lua.c
index 3687f75b87..5a3ec1db82 100644
--- a/player/lua.c
+++ b/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),