History

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

wm4 committed 6 years ago

Commit 7e4819e1 parent 6ab013c3 files · +77 −0Browse files

Showing the changes to player/lua/defaults.lua (1 of 3 files). Show all

Unified · Split

player/lua/defaults.lua+24−0
@@ -676,4 +676,28 @@ function mp_utils.subprocess_detached(t) · 675 unmodified lines
676 mp.commandv("run", unpack(t.args))676 mp.commandv("run", unpack(t.args))
677end677end
678 678
679function 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
687end
688
689function mp_utils.shared_script_property_get(name)
690 local map = mp.get_property_native("shared-script-properties")
691 return map and map[name]
692end
693
694-- cb(name, value) on change and on init
695function 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)
701end
702
679return {}703return {}

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