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.
Showing the changes to player/javascript (1 of 2 files). Show all
Unified · Split
| @@ -670,25 +670,10 @@ function register_event_handler(t) { · 669 unmodified lines | |||
| 670 | mp.input = { | 670 | mp.input = { |
| 671 | get: function(t) { | 671 | get: function(t) { |
| 672 | mp.commandv("script-message-to", "console", "get-input", mp.script_name, | 672 | mp.commandv("script-message-to", "console", "get-input", mp.script_name, |
| 673 | JSON.stringify({ | 673 | JSON.stringify(t)); |
| 674 | prompt: t.prompt, | ||
| 675 | default_text: t.default_text, | ||
| 676 | cursor_position: t.cursor_position, | ||
| 677 | id: t.id, | ||
| 678 | })); | ||
| 679 | 674 | ||
| 680 | register_event_handler(t) | 675 | register_event_handler(t) |
| 681 | }, | 676 | }, |
| 682 | select: function (t) { | ||
| 683 | mp.commandv("script-message-to", "console", "get-input", mp.script_name, | ||
| 684 | JSON.stringify({ | ||
| 685 | prompt: t.prompt, | ||
| 686 | items: t.items, | ||
| 687 | default_item: t.default_item, | ||
| 688 | })); | ||
| 689 | |||
| 690 | register_event_handler(t); | ||
| 691 | }, | ||
| 692 | terminate: function () { | 677 | terminate: function () { |
| 693 | mp.commandv("script-message-to", "console", "disable"); | 678 | mp.commandv("script-message-to", "console", "disable"); |
| 694 | }, | 679 | }, |
| @@ -708,6 +693,7 @@ mp.input = { · 13 unmodified lines | |||
| 708 | JSON.stringify(log)); | 693 | JSON.stringify(log)); |
| 709 | } | 694 | } |
| 710 | } | 695 | } |
| 696 | mp.input.select = mp.input.get | ||
| 711 | 697 | ||
| 712 | /********************************************************************** | 698 | /********************************************************************** |
| 713 | * various | 699 | * various |