History

console.lua: don't convert integers for mp.input to string

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).

Guido Cella committed 2 years ago

Commit eb4c6be1 parent 994a08f4 files · +13 −10Browse files

Showing the changes to player/javascript/defaults.js (1 of 4 files). Show all

Unified · Split

player/javascript/defaults.js+3−2
@@ -647,9 +647,10 @@ mp.options = { read_options: read_options }; · 646 unmodified lines
647* input647* input
648*********************************************************************/648*********************************************************************/
649function register_event_handler(t) {649function register_event_handler(t) {
650 mp.register_script_message("input-event", function (type, text, cursor_position) {650 mp.register_script_message("input-event", function (type, args) {
651 if (t[type]) {651 if (t[type]) {
652 var result = t[type](text, cursor_position);652 args = JSON.parse(args)
653 var result = t[type](args[0], args[1]);
653 654
654 if (type == "complete" && result) {655 if (type == "complete" && result) {
655 mp.commandv("script-message-to", "console", "complete",656 mp.commandv("script-message-to", "console", "complete",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t