mirror of https://github.com/mpv-player/mpv
input.lua,defaults.js: don't hardcode mp.input arguments
Pass everything in the tables passed by mp.input callers to console.lua so new flags can be added without modifying these clients. In Lua, callbacks have to be excluded from the argument tables to not make utils.format_json() error, while with JSON.stringify they are automatically omitted.
This commit is contained in:
parent
dcd681ecdd
commit
b3f8464fa9
|
@ -670,25 +670,10 @@ function register_event_handler(t) {
|
|||
mp.input = {
|
||||
get: function(t) {
|
||||
mp.commandv("script-message-to", "console", "get-input", mp.script_name,
|
||||
JSON.stringify({
|
||||
prompt: t.prompt,
|
||||
default_text: t.default_text,
|
||||
cursor_position: t.cursor_position,
|
||||
id: t.id,
|
||||
}));
|
||||
JSON.stringify(t));
|
||||
|
||||
register_event_handler(t)
|
||||
},
|
||||
select: function (t) {
|
||||
mp.commandv("script-message-to", "console", "get-input", mp.script_name,
|
||||
JSON.stringify({
|
||||
prompt: t.prompt,
|
||||
items: t.items,
|
||||
default_item: t.default_item,
|
||||
}));
|
||||
|
||||
register_event_handler(t);
|
||||
},
|
||||
terminate: function () {
|
||||
mp.commandv("script-message-to", "console", "disable");
|
||||
},
|
||||
|
@ -708,6 +693,7 @@ mp.input = {
|
|||
JSON.stringify(log));
|
||||
}
|
||||
}
|
||||
mp.input.select = mp.input.get
|
||||
|
||||
/**********************************************************************
|
||||
* various
|
||||
|
|
|
@ -18,6 +18,18 @@ License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|||
local utils = require "mp.utils"
|
||||
local input = {}
|
||||
|
||||
local function get_non_callbacks(t)
|
||||
local non_callbacks = {}
|
||||
|
||||
for key, value in pairs(t) do
|
||||
if type(value) ~= "function" then
|
||||
non_callbacks[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
return non_callbacks
|
||||
end
|
||||
|
||||
local function register_event_handler(t)
|
||||
mp.register_script_message("input-event", function (type, args)
|
||||
if t[type] then
|
||||
|
@ -38,26 +50,12 @@ end
|
|||
|
||||
function input.get(t)
|
||||
mp.commandv("script-message-to", "console", "get-input",
|
||||
mp.get_script_name(), utils.format_json({
|
||||
prompt = t.prompt,
|
||||
default_text = t.default_text,
|
||||
cursor_position = t.cursor_position,
|
||||
id = t.id,
|
||||
}))
|
||||
mp.get_script_name(), utils.format_json(get_non_callbacks(t)))
|
||||
|
||||
register_event_handler(t)
|
||||
end
|
||||
|
||||
function input.select(t)
|
||||
mp.commandv("script-message-to", "console", "get-input",
|
||||
mp.get_script_name(), utils.format_json({
|
||||
prompt = t.prompt,
|
||||
items = t.items,
|
||||
default_item = t.default_item,
|
||||
}))
|
||||
|
||||
register_event_handler(t)
|
||||
end
|
||||
input.select = input.get
|
||||
|
||||
function input.terminate()
|
||||
mp.commandv("script-message-to", "console", "disable")
|
||||
|
|
Loading…
Reference in New Issue