From d3b56435896d5fde202f56214e3ea3c2e153465d Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 16 Jan 2014 23:06:06 +0100 Subject: 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. --- player/lua.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'player/lua.c') 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 -- cgit v1.2.3