mirror of
https://github.com/mpv-player/mpv.git
synced 2026-10-16 22:40:53 +08:00
input/cmd: use _name for command name in mpv_command_node
Some commands have named arguments named "name", which conflict with the "name" entry used to specify command name in mpv_command_node, so they cannot be used with mpv_command_node. These commands include: set, del, change-list, add, cycle, multiply, enable-section, disable-section, define-section, script-binding, keybind, keypress, keydown, keyup, apply-profile. This makes mpv_command_node accept command name as key "_name", so "name" can be used to specify command arguments. For compatibility, if "_name" entry does not exist, then "name" is used as fallback.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
make `mpv_command_node` accept `_name` for command name
|
||||
+1
-1
@@ -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.
|
||||
|
||||
+8
-5
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
+7
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user