diff --git a/DOCS/interface-changes/command-name.txt b/DOCS/interface-changes/command-name.txt new file mode 100644 index 0000000000..33db7ab79d --- /dev/null +++ b/DOCS/interface-changes/command-name.txt @@ -0,0 +1 @@ +make `mpv_command_node` accept `_name` for command name diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 60d9d5059f..8a8b7c11b2 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -271,7 +271,7 @@ This applies to certain APIs, such as ``mp.command_native()`` (with tables that have string keys) in Lua scripting, or ``mpv_command_node()`` (with MPV_FORMAT_NODE_MAP) in the C libmpv client API. -The name of the command is provided with a ``name`` string field. The name of +The name of the command is provided with a ``_name`` string field. The name of each command is defined in each command description in the `List of Input Commands`_. ``--input-cmdlist`` also lists them. See the ``subprocess`` command for an example. diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst index 3b76453ebb..b02ba3c197 100644 --- a/DOCS/man/lua.rst +++ b/DOCS/man/lua.rst @@ -155,11 +155,14 @@ The ``mp`` module is preloaded, although it can be loaded manually with ``mp.commandv()`` (but can be a native type instead of a string). If the table contains string keys, it's interpreted as command with named - arguments. This requires at least an entry with the key ``name`` to be - present, which must be a string, and contains the command name. The special - entry ``_flags`` is optional, and if present, must be an array of - `Input Command Prefixes`_ to apply. All other entries are interpreted as - arguments. + arguments. This requires at least an entry with the key ``_name`` to be + present, which must be a string, and contains the command name. + For compatibility, if the key ``_name`` does not exist, then the entry with + the key ``name`` will be used instead. The special entry ``_flags`` is + optional, and if present, must be an array of `Input Command Prefixes`_ to + apply. All other entries are interpreted as arguments. Note that some + commands have arguments named ``name``, and can only be used if the command + name is specified with key ``_name`` instead of ``name``. Returns a result table on success (usually empty), or ``def, error`` on error. ``def`` is the second parameter provided to the function, and is diff --git a/include/mpv/client.h b/include/mpv/client.h index feb48fda9a..f72a0e0a46 100644 --- a/include/mpv/client.h +++ b/include/mpv/client.h @@ -924,13 +924,17 @@ MPV_EXPORT int mpv_command(mpv_handle *ctx, const char **args); * of arguments is as documented in each command description. * * MPV_FORMAT_NODE_MAP: - * Named arguments. This requires at least an entry with the key "name" - * to be present, which must be a string, and contains the command name. + * Named arguments. This requires at least a special entry with the key + * "_name" to be present, which must be a string, and contains the command + * name. For compatibility, if the key "_name" does not exist, then the + * entry with the key "name" will be used instead. * The special entry "_flags" is optional, and if present, must be an * array of strings, each being a command prefix to apply. All other * entries are interpreted as arguments. They must use the argument names * as documented in each command description. Some commands do not * support named arguments at all, and must use MPV_FORMAT_NODE_ARRAY. + * Some commands have arguments named "name", and can only be used if + * the command name is specified with key "_name" instead of "name". * * @param[in] args mpv_node with format set to one of the values documented * above (see there for details) diff --git a/input/cmd.c b/input/cmd.c index 44e76dadba..a9ca48f1aa 100644 --- a/input/cmd.c +++ b/input/cmd.c @@ -230,7 +230,12 @@ static bool cmd_node_map(struct mp_log *log, struct mp_cmd *cmd, mpv_node *node) mp_assert(node->format == MPV_FORMAT_NODE_MAP); mpv_node_list *args = node->u.list; - mpv_node *name = node_map_get(node, "name"); + bool old_name = false; + mpv_node *name = node_map_get(node, "_name"); + if (!name || name->format != MPV_FORMAT_STRING) { + old_name = true; + name = node_map_get(node, "name"); + } if (!name || name->format != MPV_FORMAT_STRING) return false; @@ -248,7 +253,7 @@ static bool cmd_node_map(struct mp_log *log, struct mp_cmd *cmd, mpv_node *node) const char *key = args->keys[n]; mpv_node *val = &args->values[n]; - if (strcmp(key, "name") == 0) { + if (strcmp(key, "_name") == 0 || (old_name && strcmp(key, "name") == 0)) { // already handled above } else if (strcmp(key, "_flags") == 0) { if (val->format != MPV_FORMAT_NODE_ARRAY)