summaryrefslogtreecommitdiffstats
path: root/player/lua.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-16 23:06:06 +0100
committerwm4 <wm4@nowhere>2014-01-16 23:06:41 +0100
commitd3b56435896d5fde202f56214e3ea3c2e153465d (patch)
tree7cbf71ce4a5f6a043bebeb875a420ac1eaa9e489 /player/lua.c
parent82067e6ac37f73099923c86cf38fc44100a8d3c2 (diff)
downloadmpv-d3b56435896d5fde202f56214e3ea3c2e153465d.tar.bz2
mpv-d3b56435896d5fde202f56214e3ea3c2e153465d.tar.xz
lua: add a --lua-opts option, which can be queried by scripts
The values set by this new option can be queried by Lua scripts using the mp.getopt() function. The function takes a string parameter, and returns the value of the first key that matches. If no key matches, nil is returned.
Diffstat (limited to 'player/lua.c')
-rw-r--r--player/lua.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/player/lua.c b/player/lua.c
index a9aebf90ca..f77f9d1a7e 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -676,6 +676,21 @@ static int script_format_time(lua_State *L)
return 1;
}
+static int script_getopt(lua_State *L)
+{
+ struct MPContext *mpctx = get_mpctx(L);
+ char **opts = mpctx->opts->lua_opts;
+ const char *name = luaL_checkstring(L, 1);
+
+ for (int n = 0; opts && opts[n] && opts[n + 1]; n++) {
+ if (strcmp(opts[n], name) == 0) {
+ lua_pushstring(L, opts[n + 1]);
+ return 1;
+ }
+ }
+ return 0;
+}
+
struct fn_entry {
const char *name;
int (*fn)(lua_State *L);
@@ -702,6 +717,7 @@ static struct fn_entry fn_list[] = {
FN_ENTRY(input_set_section_mouse_area),
FN_ENTRY(format_time),
FN_ENTRY(enable_messages),
+ FN_ENTRY(getopt),
};
// On stack: mp table