Very primitive and dumb, but fulfils its purpose for the next commits. I chose this specific implementation because it has the lowest footprint in command.c, without resorting to crazy hacks such as sending messages between scripts (which would be hard to coordinate especially on startup).
Showing the changes to player/lua/defaults.lua (1 of 3 files). Show all
Unified · Split
| @@ -676,4 +676,28 @@ function mp_utils.subprocess_detached(t) · 675 unmodified lines | ||
| 676 | 676 | mp.commandv("run", unpack(t.args)) |
| 677 | 677 | end |
| 678 | 678 | |
| 679 | +function mp_utils.shared_script_property_set(name, value) | |
| 680 | + if value ~= nil then | |
| 681 | + -- no such thing as change-list with mpv_node, so build a string value | |
| 682 | + mp.commandv("change-list", "shared-script-properties", "append", | |
| 683 | + name .. "=" .. value) | |
| 684 | + else | |
| 685 | + mp.commandv("change-list", "shared-script-properties", "remove", name) | |
| 686 | + end | |
| 687 | +end | |
| 688 | + | |
| 689 | +function mp_utils.shared_script_property_get(name) | |
| 690 | + local map = mp.get_property_native("shared-script-properties") | |
| 691 | + return map and map[name] | |
| 692 | +end | |
| 693 | + | |
| 694 | +-- cb(name, value) on change and on init | |
| 695 | +function mp_utils.shared_script_property_observe(name, cb) | |
| 696 | + -- it's _very_ wasteful to observe the mpv core "super" property for every | |
| 697 | + -- shared sub-property, but then again you shouldn't use this | |
| 698 | + mp.observe_property("shared-script-properties", "native", function(_, val) | |
| 699 | + cb(name, val and val[name]) | |
| 700 | + end) | |
| 701 | +end | |
| 702 | + | |
| 679 | 703 | return {} |