summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-12-18 08:58:49 +0100
committerwm4 <wm4@nowhere>2019-12-18 08:58:49 +0100
commit7e4819e705d2f046de06fcff53ce151d835bbdad (patch)
treec775dc2f1517c05bfa2931c10ca8999b5cd7e63a /player/command.c
parent6ab013cbdd9d627f7cdd5eb1eca8df0da112b929 (diff)
downloadmpv-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/command.c')
-rw-r--r--player/command.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index 8576e36da7..32e4e3dfea 100644
--- a/player/command.c
+++ b/player/command.c
@@ -102,6 +102,12 @@ struct command_ctx {
struct ao_hotplug *hotplug;
struct mp_cmd_ctx *cache_dump_cmd; // in progress cache dumping
+
+ char **script_props;
+};
+
+static const struct m_option script_props_type = {
+ .type = &m_option_type_keyvalue_list
};
struct overlay {
@@ -3217,6 +3223,27 @@ static int mp_property_bindings(void *ctx, struct m_property *prop,
return M_PROPERTY_NOT_IMPLEMENTED;
}
+
+static int mp_property_script_props(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ MPContext *mpctx = ctx;
+ struct command_ctx *cmd = mpctx->command_ctx;
+ switch (action) {
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = script_props_type;
+ return M_PROPERTY_OK;
+ case M_PROPERTY_GET:
+ m_option_copy(&script_props_type, arg, &cmd->script_props);
+ return M_PROPERTY_OK;
+ case M_PROPERTY_SET:
+ m_option_copy(&script_props_type, &cmd->script_props, arg);
+ mp_notify_property(mpctx, prop->name);
+ return M_PROPERTY_OK;
+ }
+ return M_PROPERTY_NOT_IMPLEMENTED;
+}
+
// Redirect a property name to another
#define M_PROPERTY_ALIAS(name, real_property) \
{(name), mp_property_alias, .priv = (real_property)}
@@ -3391,6 +3418,8 @@ static const struct m_property mp_properties_base[] = {
{"command-list", mp_property_commands},
{"input-bindings", mp_property_bindings},
+ {"shared-script-properties", mp_property_script_props},
+
M_PROPERTY_ALIAS("video", "vid"),
M_PROPERTY_ALIAS("audio", "aid"),
M_PROPERTY_ALIAS("sub", "sid"),
@@ -5856,6 +5885,8 @@ void command_uninit(struct MPContext *mpctx)
overlay_uninit(mpctx);
ao_hotplug_destroy(ctx->hotplug);
+ m_option_free(&script_props_type, &ctx->script_props);
+
talloc_free(mpctx->command_ctx);
mpctx->command_ctx = NULL;
}