From 6d880a607d59f4370c50226fc384ed145ca7ecc1 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:37:08 -0500 Subject: [PATCH] defaults.lua: support custom arg in mp.add_key_binding() The information is available in the table. --- DOCS/man/lua.rst | 9 +++++++-- player/lua/defaults.lua | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst index d4a4a25027bb9..9513b5ff9388b 100644 --- a/DOCS/man/lua.rst +++ b/DOCS/man/lua.rst @@ -316,8 +316,8 @@ The ``mp`` module is preloaded, although it can be loaded manually with 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: + The ``flags`` argument is used for optional parameters. This is a table, + which can have the following entries: ``repeatable`` If set to ``true``, enables key repeat for this specific binding. @@ -361,6 +361,11 @@ The ``mp`` module is preloaded, although it can be loaded manually with The scale of the key, such as the ones produced by ``WHEEL_*`` keys. The scale is 1 if the key is nonscalable. + ``arg`` + User-provided string in the ``arg`` argument in the + ``script-binding`` command if the key binding is invoked + by that command. + Internally, key bindings are dispatched via the ``script-message-to`` or ``script-binding`` input commands and ``mp.register_script_message``. diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 6a353d5a878b8..111e21e324000 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -60,10 +60,10 @@ local function reserve_binding() return "__keybinding" .. tostring(message_id) end -local function dispatch_key_binding(name, state, key_name, key_text, scale) +local function dispatch_key_binding(name, state, key_name, key_text, scale, arg) local fn = dispatch_key_bindings[name] if fn then - fn(name, state, key_name, key_text, scale) + fn(name, state, key_name, key_text, scale, arg) end end @@ -201,7 +201,7 @@ local function add_binding(attrs, key, name, fn, rp) ["r"] = "repeat", ["p"] = "press", } - key_cb = function(_, state, key_name, key_text, scale) + key_cb = function(_, state, key_name, key_text, scale, arg) if key_text == "" then key_text = nil end @@ -212,6 +212,7 @@ local function add_binding(attrs, key, name, fn, rp) key_name = key_name, key_text = key_text, scale = tonumber(scale), + arg = arg, }) end msg_cb = function()