summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-11 00:25:07 +0200
committerwm4 <wm4@nowhere>2014-10-11 00:33:09 +0200
commitc5c21abf78811d1458dc4ade95e5f04cb4b14733 (patch)
treee1ad8e18ee2cf41e23f1742cfd3aaed628e72ee0
parent63e2b6c4aef2afd5879b3cfb2b172ee05f17f765 (diff)
downloadmpv-c5c21abf78811d1458dc4ade95e5f04cb4b14733.tar.bz2
mpv-c5c21abf78811d1458dc4ade95e5f04cb4b14733.tar.xz
lua: add command_native() function
This is the Lua equivalent of mpv_command_node().
-rw-r--r--DOCS/man/lua.rst9
-rw-r--r--player/lua.c23
2 files changed, 32 insertions, 0 deletions
diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst
index 1c4605eacd..a01e429034 100644
--- a/DOCS/man/lua.rst
+++ b/DOCS/man/lua.rst
@@ -94,6 +94,15 @@ The ``mp`` module is preloaded, although it can be loaded manually with
the ``expand-properties`` prefix, or the ``mp.get_property`` family of
functions.
+``mp.command_native(table [,def])``
+ Similar to ``mp.commandv``, but pass the argument list as table. This has
+ the advantage that in at least some cases, arguments can be passed as
+ native types.
+
+ Returns a result table on success (usually empty), or ``def, error`` on
+ error. ``def`` is the second parameter provided to the function, and is
+ nil if it's missing.
+
``mp.get_property(name [,def])``
Return the value of the given property as string. These are the same
properties as used in input.conf. See `Properties`_ for a list of
diff --git a/player/lua.c b/player/lua.c
index 8aa6b594fb..ef8dc1ca7d 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -891,6 +891,28 @@ static int script_raw_unobserve_property(lua_State *L)
return 1;
}
+static int script_command_native(lua_State *L)
+{
+ struct script_ctx *ctx = get_ctx(L);
+ struct mpv_node node;
+ struct mpv_node result;
+ void *tmp = talloc_new(NULL);
+ makenode(tmp, &node, L, 1);
+ int err = mpv_command_node(ctx->client, &node, &result);
+ talloc_free(tmp);
+ const char *errstr = mpv_error_string(err);
+ if (err >= 0) {
+ bool ok = pushnode(L, &result, 50);
+ mpv_free_node_contents(&result);
+ if (ok)
+ return 1;
+ errstr = "command result too large";
+ }
+ lua_pushvalue(L, 2);
+ lua_pushstring(L, errstr);
+ return 2;
+}
+
static int script_set_osd_ass(lua_State *L)
{
struct MPContext *mpctx = get_mpctx(L);
@@ -1117,6 +1139,7 @@ static const struct fn_entry main_fns[] = {
FN_ENTRY(find_config_file),
FN_ENTRY(command),
FN_ENTRY(commandv),
+ FN_ENTRY(command_native),
FN_ENTRY(get_property_bool),
FN_ENTRY(get_property_number),
FN_ENTRY(get_property_native),