From 780f172a8a09bbd4a1ce5a582ba26b5737788d3b Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 17 Mar 2014 18:27:25 +0100 Subject: [PATCH] lua: rename mp.register_script_command() to mp.register_script_message() More consistent naming. --- DOCS/man/en/lua.rst | 10 +++++----- player/lua/defaults.lua | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/DOCS/man/en/lua.rst b/DOCS/man/en/lua.rst index fc7606a5fc..2cf485ba35 100644 --- a/DOCS/man/en/lua.rst +++ b/DOCS/man/en/lua.rst @@ -169,7 +169,7 @@ The ``mp`` module is preloaded, although it can be loaded manually with internally. Internally, key bindings are dispatched via the ``script_message_to`` input - command and ``mp.register_script_command``. + command and ``mp.register_script_message``. Trying to map multiple commands to a key will essentially prefer a random binding, while the other bindings are not called. It is guaranteed that @@ -298,17 +298,17 @@ The ``mp`` module is preloaded, although it can be loaded manually with the ``log-message`` event. See the description of this event for details. The level is a string, see ``msg.log`` for allowed log levels. -``mp.register_script_command(name, fn)`` +``mp.register_script_message(name, fn)`` This is a helper to dispatch ``script_message`` or ``script_message_to`` invocations to Lua functions. ``fn`` is called if ``script_message`` or ``script_message_to`` (with this script as destination) is run with ``name`` as first parameter. The other parameters are passed to ``fn``. - If a command with the given name is already registered, it's overwritten. + If a message with the given name is already registered, it's overwritten. Used by ``mp.add_key_binding``, so be careful about name collisions. -``mp.unregister_script_command(name)`` - Undo a previous registration with ``mp.register_script_command``. Does +``mp.unregister_script_message(name)`` + Undo a previous registration with ``mp.register_script_message``. Does nothing if the ``name`` wasn't registered. mp.msg functions diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index fbc09d48a3..557a0ff4a7 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -87,7 +87,7 @@ end -- "Newer" and more convenient API local key_bindings = {} -local command_id = 1 +local message_id = 1 local function update_key_bindings() for i = 1, 2 do @@ -116,15 +116,15 @@ end local function add_binding(attrs, key, name, fn) if (type(name) ~= "string") and (not fn) then fn = name - name = "command" .. tostring(command_id) - command_id = command_id + 1 + name = "message" .. tostring(message_id) + message_id = message_id + 1 end attrs.key = key attrs.name = name key_bindings[name] = attrs update_key_bindings() if fn then - mp.register_script_command(name, fn) + mp.register_script_message(name, fn) end end @@ -139,7 +139,7 @@ end function mp.remove_key_binding(name) key_bindings[name] = nil update_key_bindings() - mp.unregister_script_command(name) + mp.unregister_script_message(name) end local timers = {} @@ -201,19 +201,19 @@ local function process_timers() end end -local commands = {} +local messages = {} -function mp.register_script_command(name, fn) - commands[name] = fn +function mp.register_script_message(name, fn) + messages[name] = fn end -function mp.unregister_script_command(name) - commands[name] = nil +function mp.unregister_script_message(name) + messages[name] = nil end -local function command_dispatch(ev) +local function message_dispatch(ev) if #ev.args > 0 then - local handler = commands[ev.args[1]] + local handler = messages[ev.args[1]] if handler then handler(unpack(ev.args, 2)) end @@ -238,7 +238,7 @@ end -- default handlers mp.register_event("shutdown", function() mp.keep_running = false end) mp.register_event("script-input-dispatch", script_dispatch) -mp.register_event("client-message", command_dispatch) +mp.register_event("client-message", message_dispatch) mp.msg = { log = mp.log,