1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-27 02:40:53 +00:00

lua: make add_key_binding() rotate optional arguments correctly

add_key_binding() makes the name argument optional (in weird Lua
fashion), which did not work if there were additional arguments. So
there is no way to avoid specifying a name while passing a rp argument.
Fix this, declare this way of skipping the argument as deprecated, and
allow passing name=nil as the preferred way to skip the name argument.
This commit is contained in:
wm4 2019-11-23 14:40:00 +01:00
parent 66a46cba89
commit 311cc5b611
2 changed files with 8 additions and 2 deletions

View File

@ -240,7 +240,9 @@ The ``mp`` module is preloaded, although it can be loaded manually with
an example). The name should be unique across other bindings in the same an example). The name should be unique across other bindings in the same
script - if not, the previous binding with the same name will be script - if not, the previous binding with the same name will be
overwritten. You can omit the name, in which case a random name is generated overwritten. You can omit the name, in which case a random name is generated
internally. internally. (Omitting works as follows: either pass ``nil`` for ``name``,
or pass the ``fn`` argument in place of the name. The latter is not
recommended and is handled for compatibility only.)
The last argument is used for optional flags. This is a table, which can The last argument is used for optional flags. This is a table, which can
have the following entries: have the following entries:

View File

@ -157,8 +157,12 @@ end
local function add_binding(attrs, key, name, fn, rp) local function add_binding(attrs, key, name, fn, rp)
rp = rp or "" rp = rp or ""
if (type(name) ~= "string") and (not fn) then if (type(name) ~= "string") and (name ~= nil) then
rp = fn
fn = name fn = name
name = nil
end
if name == nil then
name = reserve_binding() name = reserve_binding()
end end
local repeatable = rp == "repeatable" or rp["repeatable"] local repeatable = rp == "repeatable" or rp["repeatable"]