I misunderstood CogentRedTester's review in https://github.com/mpv-player/mpv/pull/10282#discussion_r1428972352 as referring to the cursor_position in mp.input's arguments instead of the one received by the closed callback. The cursor_position passed to input.get doesn't need to be converted to a number because it was already JSON, while the cursor_position received by the closed callback is currently a string, and we need to pass JSON in input-event script messages to keep it as an integer to work around mpv converting integer script message arguments to string. This is more noticeable after implementing mp.input.select(): its submit argument currently receives the selected index as a string, and this makes Lua error if you use it as an index of a numerical table, e.g.: submit = function (id) mp.set_property(property, tracks[tonumber(id)].selected and "no" or tracks[tonumber(id)].id) ... end, This commit avoids having to call tonumber(id).
Showing the changes to player/lua/input.lua (1 of 4 files). Show all
Unified · Split
| @@ -19,9 +19,10 @@ local utils = require "mp.utils" · 18 unmodified lines | |||
| 19 | local input = {} | 19 | local input = {} |
| 20 | 20 | ||
| 21 | local function register_event_handler(t) | 21 | local function register_event_handler(t) |
| 22 | mp.register_script_message("input-event", function (type, text, cursor_position) | 22 | mp.register_script_message("input-event", function (type, args) |
| 23 | if t[type] then | 23 | if t[type] then |
| 24 | local suggestions, completion_start_position = t[type](text, cursor_position) | 24 | local suggestions, completion_start_position = |
| 25 | t[type](unpack(utils.parse_json(args or "") or {})) | ||
| 25 | 26 | ||
| 26 | if type == "complete" and suggestions then | 27 | if type == "complete" and suggestions then |
| 27 | mp.commandv("script-message-to", "console", "complete", | 28 | mp.commandv("script-message-to", "console", "complete", |