summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-11-23 14:40:00 +0100
committerwm4 <wm4@nowhere>2019-11-23 14:40:00 +0100
commit311cc5b611ae9baed47549ee3ad2cef04f4892e0 (patch)
treec4d00cbbc860270d179e03f2e8d1071ac4703149
parent66a46cba89e386de08634d53549e26aa0b558199 (diff)
downloadmpv-311cc5b611ae9baed47549ee3ad2cef04f4892e0.tar.bz2
mpv-311cc5b611ae9baed47549ee3ad2cef04f4892e0.tar.xz
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.
-rw-r--r--DOCS/man/lua.rst4
-rw-r--r--player/lua/defaults.lua6
2 files changed, 8 insertions, 2 deletions
diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst
index 2900a5393c..5da358a12c 100644
--- a/DOCS/man/lua.rst
+++ b/DOCS/man/lua.rst
@@ -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
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
- 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
have the following entries:
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index 38b6a9d04b..72b73b566b 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -157,8 +157,12 @@ end
local function add_binding(attrs, key, name, fn, rp)
rp = rp or ""
- if (type(name) ~= "string") and (not fn) then
+ if (type(name) ~= "string") and (name ~= nil) then
+ rp = fn
fn = name
+ name = nil
+ end
+ if name == nil then
name = reserve_binding()
end
local repeatable = rp == "repeatable" or rp["repeatable"]