js: support shared script properties (match 7e4819e7)

This commit is contained in:
Avi Halachmi (:avih) 2019-12-19 15:35:20 +02:00
parent 4fc5cd32d0
commit 3460a7b696
1 changed files with 22 additions and 0 deletions

View File

@ -170,6 +170,28 @@ mp.abort_async_command = function abort_async_command(id) {
mp._abort_async_command(id);
}
// shared-script-properties - always an object, even if without properties
function shared_script_property_set(name, val) {
if (arguments.length > 1)
return mp.commandv("change-list", "shared-script-properties", "append", "" + name + "=" + val);
else
return mp.commandv("change-list", "shared-script-properties", "remove", name);
}
function shared_script_property_get(name) {
return mp.get_property_native("shared-script-properties")[name];
}
function shared_script_property_observe(name, cb) {
return mp.observe_property("shared-script-properties", "native",
function shared_props_cb(_name, val) { cb(name, val[name]) }
);
}
mp.utils.shared_script_property_set = shared_script_property_set;
mp.utils.shared_script_property_get = shared_script_property_get;
mp.utils.shared_script_property_observe = shared_script_property_observe;
/**********************************************************************
* key bindings
*********************************************************************/