mirror of https://github.com/mpv-player/mpv
lua: rename mp.register_script_command() to mp.register_script_message()
More consistent naming.
This commit is contained in:
parent
637664d95a
commit
780f172a8a
|
@ -169,7 +169,7 @@ The ``mp`` module is preloaded, although it can be loaded manually with
|
||||||
internally.
|
internally.
|
||||||
|
|
||||||
Internally, key bindings are dispatched via the ``script_message_to`` input
|
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
|
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
|
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 ``log-message`` event. See the description of this event for details.
|
||||||
The level is a string, see ``msg.log`` for allowed log levels.
|
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``
|
This is a helper to dispatch ``script_message`` or ``script_message_to``
|
||||||
invocations to Lua functions. ``fn`` is called if ``script_message`` or
|
invocations to Lua functions. ``fn`` is called if ``script_message`` or
|
||||||
``script_message_to`` (with this script as destination) is run
|
``script_message_to`` (with this script as destination) is run
|
||||||
with ``name`` as first parameter. The other parameters are passed to ``fn``.
|
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.
|
Used by ``mp.add_key_binding``, so be careful about name collisions.
|
||||||
|
|
||||||
``mp.unregister_script_command(name)``
|
``mp.unregister_script_message(name)``
|
||||||
Undo a previous registration with ``mp.register_script_command``. Does
|
Undo a previous registration with ``mp.register_script_message``. Does
|
||||||
nothing if the ``name`` wasn't registered.
|
nothing if the ``name`` wasn't registered.
|
||||||
|
|
||||||
mp.msg functions
|
mp.msg functions
|
||||||
|
|
|
@ -87,7 +87,7 @@ end
|
||||||
-- "Newer" and more convenient API
|
-- "Newer" and more convenient API
|
||||||
|
|
||||||
local key_bindings = {}
|
local key_bindings = {}
|
||||||
local command_id = 1
|
local message_id = 1
|
||||||
|
|
||||||
local function update_key_bindings()
|
local function update_key_bindings()
|
||||||
for i = 1, 2 do
|
for i = 1, 2 do
|
||||||
|
@ -116,15 +116,15 @@ end
|
||||||
local function add_binding(attrs, key, name, fn)
|
local function add_binding(attrs, key, name, fn)
|
||||||
if (type(name) ~= "string") and (not fn) then
|
if (type(name) ~= "string") and (not fn) then
|
||||||
fn = name
|
fn = name
|
||||||
name = "command" .. tostring(command_id)
|
name = "message" .. tostring(message_id)
|
||||||
command_id = command_id + 1
|
message_id = message_id + 1
|
||||||
end
|
end
|
||||||
attrs.key = key
|
attrs.key = key
|
||||||
attrs.name = name
|
attrs.name = name
|
||||||
key_bindings[name] = attrs
|
key_bindings[name] = attrs
|
||||||
update_key_bindings()
|
update_key_bindings()
|
||||||
if fn then
|
if fn then
|
||||||
mp.register_script_command(name, fn)
|
mp.register_script_message(name, fn)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ end
|
||||||
function mp.remove_key_binding(name)
|
function mp.remove_key_binding(name)
|
||||||
key_bindings[name] = nil
|
key_bindings[name] = nil
|
||||||
update_key_bindings()
|
update_key_bindings()
|
||||||
mp.unregister_script_command(name)
|
mp.unregister_script_message(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
local timers = {}
|
local timers = {}
|
||||||
|
@ -201,19 +201,19 @@ local function process_timers()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local commands = {}
|
local messages = {}
|
||||||
|
|
||||||
function mp.register_script_command(name, fn)
|
function mp.register_script_message(name, fn)
|
||||||
commands[name] = fn
|
messages[name] = fn
|
||||||
end
|
end
|
||||||
|
|
||||||
function mp.unregister_script_command(name)
|
function mp.unregister_script_message(name)
|
||||||
commands[name] = nil
|
messages[name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function command_dispatch(ev)
|
local function message_dispatch(ev)
|
||||||
if #ev.args > 0 then
|
if #ev.args > 0 then
|
||||||
local handler = commands[ev.args[1]]
|
local handler = messages[ev.args[1]]
|
||||||
if handler then
|
if handler then
|
||||||
handler(unpack(ev.args, 2))
|
handler(unpack(ev.args, 2))
|
||||||
end
|
end
|
||||||
|
@ -238,7 +238,7 @@ end
|
||||||
-- default handlers
|
-- default handlers
|
||||||
mp.register_event("shutdown", function() mp.keep_running = false end)
|
mp.register_event("shutdown", function() mp.keep_running = false end)
|
||||||
mp.register_event("script-input-dispatch", script_dispatch)
|
mp.register_event("script-input-dispatch", script_dispatch)
|
||||||
mp.register_event("client-message", command_dispatch)
|
mp.register_event("client-message", message_dispatch)
|
||||||
|
|
||||||
mp.msg = {
|
mp.msg = {
|
||||||
log = mp.log,
|
log = mp.log,
|
||||||
|
|
Loading…
Reference in New Issue