summaryrefslogtreecommitdiffstats
path: root/options/m_config.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-24 20:39:51 +0100
committerwm4 <wm4@nowhere>2014-02-24 22:50:23 +0100
commit942fb43d0cdc58b0b2fad15bab564fd5105698ff (patch)
tree797aa3db62fb264869123e335f35266539335e52 /options/m_config.c
parenta6ebfbea6922632efb2cab020303397a418959f1 (diff)
downloadmpv-942fb43d0cdc58b0b2fad15bab564fd5105698ff.tar.bz2
mpv-942fb43d0cdc58b0b2fad15bab564fd5105698ff.tar.xz
client API: implement setting options using their native type too
This is only half-implemented: actually the option will first be converted from mpv_node to its native type, then it's converted to a string, and then back to its native type. This is because the option API was made for strings and not anything else. Other than being grossly inelegant, the only downside is probably with string lists and key/value lists, which don't escape strings containing syntax elements correctly.
Diffstat (limited to 'options/m_config.c')
-rw-r--r--options/m_config.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/options/m_config.c b/options/m_config.c
index 4b520c758a..d2b75389fe 100644
--- a/options/m_config.c
+++ b/options/m_config.c
@@ -28,6 +28,8 @@
#include <assert.h>
#include <stdbool.h>
+#include "libmpv/client.h"
+
#include "talloc.h"
#include "m_config.h"
@@ -606,6 +608,35 @@ int m_config_set_option(struct m_config *config, struct bstr name,
return m_config_set_option_ext(config, name, param, 0);
}
+int m_config_set_option_node(struct m_config *config, bstr name,
+ struct mpv_node *data, int flags)
+{
+ char *value = NULL;
+ if (data->format == MPV_FORMAT_STRING) {
+ value = *(char **)data;
+ } else {
+ // This is pretty lame, but the simplest for now. It will fail very
+ // hard for string lists with items that contain ',' characters.
+ union m_option_value val = {0};
+ const struct m_option *opt = m_config_get_option(config, name);
+ if (!opt)
+ return M_OPT_UNKNOWN;
+ if (m_option_set_node(opt, &val, data) < 0)
+ return M_OPT_INVALID;
+ value = m_option_print(opt, &val);
+ m_option_free(opt, &val);
+ }
+ int r;
+ if (value) {
+ r = m_config_set_option_ext(config, name, bstr0(value), flags);
+ } else {
+ r = M_OPT_OUT_OF_RANGE;
+ }
+ if (data->format != MPV_FORMAT_STRING)
+ talloc_free(value);
+ return r;
+}
+
const struct m_option *m_config_get_option(const struct m_config *config,
struct bstr name)
{