lua: rename mp.register_script_command() to mp.register_script_message()

More consistent naming.
This commit is contained in:
wm4 2014-03-17 18:27:25 +01:00
parent 637664d95a
commit 780f172a8a
2 changed files with 18 additions and 18 deletions

View File

@ -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

View File

@ -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,