mirror of
https://github.com/mpv-player/mpv
synced 2024-12-23 23:32:26 +00:00
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.
This commit is contained in:
parent
82067e6ac3
commit
d3b5643589
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
16
player/lua.c
16
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
|
||||
|
Loading…
Reference in New Issue
Block a user