diff options
-rw-r--r-- | DOCS/man/en/options.rst | 5 | ||||
-rw-r--r-- | options/options.c | 1 | ||||
-rw-r--r-- | options/options.h | 1 | ||||
-rw-r--r-- | player/lua.c | 16 |
4 files changed, 23 insertions, 0 deletions
diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index f1ee540793..20e8ea4a9d 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -1296,6 +1296,11 @@ OPTIONS Load a Lua script. You can load multiple scripts by separating them with commas (``,``). +``--lua-opts=key1=value1,key2=value2,...`` + Set options for scripts. A Lua script can query an option by key. If an + option is used and what semantics the option value has depends entirely on + the loaded Lua scripts. Values not claimed by any scripts are ignored. + ``--mc=<seconds/frame>`` Maximum A-V sync correction per frame (in seconds) diff --git a/options/options.c b/options/options.c index cff2eff810..b1131f0938 100644 --- a/options/options.c +++ b/options/options.c @@ -239,6 +239,7 @@ const m_option_t mp_opts[] = { #if HAVE_LUA OPT_STRINGLIST("lua", lua_files, CONF_GLOBAL), + OPT_KEYVALUELIST("lua-opts", lua_opts, CONF_GLOBAL), OPT_FLAG("osc", lua_load_osc, CONF_GLOBAL), #endif diff --git a/options/options.h b/options/options.h index 0a50352d0d..e328ccd25c 100644 --- a/options/options.h +++ b/options/options.h @@ -52,6 +52,7 @@ typedef struct MPOpts { char **reset_options; char **lua_files; + char **lua_opts; int lua_load_osc; struct m_obj_settings *audio_driver_list, *ao_defs; 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 |