diff options
author | wm4 <wm4@nowhere> | 2019-12-18 08:58:49 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2019-12-18 08:58:49 +0100 |
commit | 7e4819e705d2f046de06fcff53ce151d835bbdad (patch) | |
tree | c775dc2f1517c05bfa2931c10ca8999b5cd7e63a /player/lua/defaults.lua | |
parent | 6ab013cbdd9d627f7cdd5eb1eca8df0da112b929 (diff) | |
download | mpv-7e4819e705d2f046de06fcff53ce151d835bbdad.tar.bz2 mpv-7e4819e705d2f046de06fcff53ce151d835bbdad.tar.xz |
command, lua: add a way to share data between scripts
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).
Diffstat (limited to 'player/lua/defaults.lua')
-rw-r--r-- | player/lua/defaults.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index f2983e8dc3..29e513f4ea 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -676,4 +676,28 @@ function mp_utils.subprocess_detached(t) mp.commandv("run", unpack(t.args)) end +function mp_utils.shared_script_property_set(name, value) + if value ~= nil then + -- no such thing as change-list with mpv_node, so build a string value + mp.commandv("change-list", "shared-script-properties", "append", + name .. "=" .. value) + else + mp.commandv("change-list", "shared-script-properties", "remove", name) + end +end + +function mp_utils.shared_script_property_get(name) + local map = mp.get_property_native("shared-script-properties") + return map and map[name] +end + +-- cb(name, value) on change and on init +function mp_utils.shared_script_property_observe(name, cb) + -- it's _very_ wasteful to observe the mpv core "super" property for every + -- shared sub-property, but then again you shouldn't use this + mp.observe_property("shared-script-properties", "native", function(_, val) + cb(name, val and val[name]) + end) +end + return {} |