mirror of https://github.com/mpv-player/mpv
options: deprecate 'lua' based options/dirs for 'script'
- --lua and --lua-opts change to --script and --script-opts - 'lua' default script dirs change to 'scripts' - DOCS updated - 'lua-settings' dir was _not_ modified The old lua-based names/dirs still work, but display a warning. Signed-off-by: wm4 <wm4@nowhere>
This commit is contained in:
parent
06828f71a1
commit
39e04e9294
|
@ -1,10 +1,10 @@
|
|||
LUA SCRIPTING
|
||||
=============
|
||||
|
||||
mpv can load Lua scripts. Scripts passed to the ``--lua`` option, or found in
|
||||
the ``lua`` subdirectory of the mpv configuration directory (usually
|
||||
``~/.config/mpv/lua/``) will be loaded on program start. mpv also appends the
|
||||
``lua`` subdirectory to the end of Lua's path so you can import scripts from
|
||||
mpv can load Lua scripts. Scripts passed to the ``--script`` option, or found in
|
||||
the ``scripts`` subdirectory of the mpv configuration directory (usually
|
||||
``~/.config/mpv/scripts/``) will be loaded on program start. mpv also appends the
|
||||
``scripts`` subdirectory to the end of Lua's path so you can import scripts from
|
||||
there too. Since it's added to the end, don't name scripts you want to import
|
||||
the same as Lua libraries because they will be overshadowed by them.
|
||||
|
||||
|
@ -35,9 +35,9 @@ allow users implement features which are not going to be added to the mpv core.
|
|||
Mode of operation
|
||||
-----------------
|
||||
|
||||
Your script will be loaded by the player at program start from the ``lua``
|
||||
configuration subdirectory, from a path specified with the ``--lua`` option, or
|
||||
in some cases, internally (like ``--osc``). Each script runs in its own
|
||||
Your script will be loaded by the player at program start from the ``scripts``
|
||||
configuration subdirectory, from a path specified with the ``--script`` option,
|
||||
or in some cases, internally (like ``--osc``). Each script runs in its own
|
||||
thread. Your script is first run "as is", and once that is done, the event loop
|
||||
is entered. This event loop will dispatch events received by mpv and call your
|
||||
own event handlers which you have registered with ``mp.register_event``, or
|
||||
|
@ -361,7 +361,7 @@ The ``mp`` module is preloaded, although it can be loaded manually with
|
|||
|
||||
|
||||
``mp.get_opt(key)``
|
||||
Return a setting from the ``--lua-opts`` option. It's up to the user and
|
||||
Return a setting from the ``--script-opts`` option. It's up to the user and
|
||||
the script how this mechanism is used. Currently, all scripts can access
|
||||
this equally, so you should be careful about collisions.
|
||||
|
||||
|
@ -513,12 +513,12 @@ Example config::
|
|||
optionC=no
|
||||
|
||||
|
||||
Command-line options are read from the ``--lua-opts`` parameter. To avoid
|
||||
Command-line options are read from the ``--script-opts`` parameter. To avoid
|
||||
collisions, all keys have to be prefixed with ``identifier-``.
|
||||
|
||||
Example command-line::
|
||||
|
||||
--lua-opts=myscript-optionA=TEST:myscript-optionB=0:myscript-optionC=yes
|
||||
--script-opts=myscript-optionA=TEST:myscript-optionB=0:myscript-optionC=yes
|
||||
|
||||
|
||||
mp.utils options
|
||||
|
|
|
@ -712,9 +712,9 @@ FILES
|
|||
``~/.config/mpv/input.conf``
|
||||
key bindings (see `INPUT.CONF`_ section)
|
||||
|
||||
``~/.config/mpv/lua/``
|
||||
All files in this directly are loaded as if they were passed to the
|
||||
``--lua`` option. They are loaded in alphabetical order, and sub-directories
|
||||
``~/.config/mpv/scripts/``
|
||||
All files in this directory are loaded as if they were passed to the
|
||||
``--script`` option. They are loaded in alphabetical order, and sub-directories
|
||||
and files with no ``.lua`` extension are ignored. The ``--load-scripts=no``
|
||||
option disables loading these files.
|
||||
|
||||
|
@ -738,8 +738,8 @@ locations are different:
|
|||
``%APPDATA%/mpv/input.conf``
|
||||
key bindings (see `INPUT.CONF`_ section)
|
||||
|
||||
``%APPDATA%/mpv/lua/``
|
||||
equivalent of ``~/.config/mpv/lua/`` on Unix.
|
||||
``%APPDATA%/mpv/scripts/``
|
||||
equivalent of ``~/.config/mpv/scripts/`` on Unix.
|
||||
|
||||
The environment variable ``$MPV_HOME`` completely overrides these, like on
|
||||
UNIX.
|
||||
|
|
|
@ -345,18 +345,18 @@ Program Behavior
|
|||
Specify configuration file to be parsed after the default ones.
|
||||
|
||||
``--load-scripts=<yes|no>``
|
||||
If set to ``no``, don't auto-load scripts from the ``lua`` configuration
|
||||
subdirectory (usually ``~/.config/mpv/lua/``).
|
||||
If set to ``no``, don't auto-load scripts from the ``scripts``
|
||||
configuration subdirectory (usually ``~/.config/mpv/scripts/``).
|
||||
(Default: ``yes``)
|
||||
|
||||
``--lua=<filename>``
|
||||
``--script=<filename>``
|
||||
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
|
||||
``--script-opts=key1=value1,key2=value2,...``
|
||||
Set options for scripts. A 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.
|
||||
the loaded scripts. Values not claimed by any scripts are ignored.
|
||||
|
||||
``--merge-files``
|
||||
Pretend that all files passed to mpv are concatenated into a single, big
|
||||
|
|
|
@ -138,7 +138,7 @@ Configuration
|
|||
|
||||
The OSC offers limited configuration through a config file
|
||||
``lua-settings/osc.conf`` placed in mpv's user dir and through the
|
||||
``--lua-opts`` command-line option. Options provided through the command-line
|
||||
``--script-opts`` command-line option. Options provided through the command-line
|
||||
will override those from the config file.
|
||||
|
||||
Config Syntax
|
||||
|
@ -161,7 +161,7 @@ To avoid collisions with other scripts, all options need to be prefixed with
|
|||
|
||||
Example::
|
||||
|
||||
--lua-opts=osc-optionA=value1,osc-optionB=value2
|
||||
--script-opts=osc-optionA=value1,osc-optionB=value2
|
||||
|
||||
|
||||
Configurable Options
|
||||
|
|
|
@ -4,9 +4,9 @@ mpv lua scripts
|
|||
The lua scripts in this folder can be loaded on a one-time basis by
|
||||
adding the option
|
||||
|
||||
--lua=/path/to/script.lua
|
||||
--script=/path/to/script.lua
|
||||
|
||||
to mpv's command line.
|
||||
|
||||
Where appropriate, they may also be placed in ~/.config/mpv/lua from where
|
||||
they will be automatically loaded when mpv starts.
|
||||
Where appropriate, they may also be placed in ~/.config/mpv/scripts/ from
|
||||
where they will be automatically loaded when mpv starts.
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
-- The default delay between insertion of the cropdetect and
|
||||
-- crop filters may be overridden by adding
|
||||
--
|
||||
-- --lua-opts=autocrop.detect_seconds=<number of seconds>
|
||||
-- --script-opts=autocrop.detect_seconds=<number of seconds>
|
||||
--
|
||||
-- to mpv's arguments. This may be desirable to allow cropdetect more
|
||||
-- time to collect data.
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
--
|
||||
-- The default detection time may be overridden by adding
|
||||
--
|
||||
-- --lua-opts=autodeint.detect_seconds=<number of seconds>
|
||||
-- --script-opts=autodeint.detect_seconds=<number of seconds>
|
||||
--
|
||||
-- to mpv's arguments. This may be desirable to allow idet more
|
||||
-- time to collect data.
|
||||
|
|
|
@ -127,8 +127,8 @@ const m_option_t mp_opts[] = {
|
|||
OPT_STRINGLIST("reset-on-next-file", reset_options, M_OPT_GLOBAL),
|
||||
|
||||
#if HAVE_LUA
|
||||
OPT_STRINGLIST("lua", lua_files, CONF_GLOBAL | M_OPT_FILE),
|
||||
OPT_KEYVALUELIST("lua-opts", lua_opts, M_OPT_GLOBAL),
|
||||
OPT_STRINGLIST("script", script_files, CONF_GLOBAL | M_OPT_FILE),
|
||||
OPT_KEYVALUELIST("script-opts", script_opts, M_OPT_GLOBAL),
|
||||
OPT_FLAG("osc", lua_load_osc, CONF_GLOBAL),
|
||||
OPT_FLAG("ytdl", lua_load_ytdl, CONF_GLOBAL),
|
||||
OPT_STRING("ytdl-format", lua_ytdl_format, CONF_GLOBAL),
|
||||
|
@ -594,6 +594,8 @@ const m_option_t mp_opts[] = {
|
|||
OPT_REMOVED("lavdopts", "use --vd-lavc-..."),
|
||||
OPT_REMOVED("lavfdopts", "use --demuxer-lavf-..."),
|
||||
OPT_REPLACED("lircconf", "input-lirc-conf"),
|
||||
OPT_REPLACED("lua", "script"),
|
||||
OPT_REPLACED("lua-opts", "script-opts"),
|
||||
OPT_REMOVED("mixer-channel", "use AO suboptions (alsa, oss)"),
|
||||
OPT_REMOVED("mixer", "use AO suboptions (alsa, oss)"),
|
||||
OPT_REPLACED("mouse-movements", "input-cursor"),
|
||||
|
|
|
@ -59,8 +59,8 @@ typedef struct MPOpts {
|
|||
int msg_time;
|
||||
|
||||
char **reset_options;
|
||||
char **lua_files;
|
||||
char **lua_opts;
|
||||
char **script_files;
|
||||
char **script_opts;
|
||||
int lua_load_osc;
|
||||
int lua_load_ytdl;
|
||||
char *lua_ytdl_format;
|
||||
|
|
14
player/lua.c
14
player/lua.c
|
@ -279,10 +279,16 @@ static void set_path(lua_State *L)
|
|||
const char *path = lua_tostring(L, -1);
|
||||
|
||||
char *newpath = talloc_strdup(tmp, path ? path : "");
|
||||
char **luadir = mp_find_all_config_files(tmp, get_mpctx(L)->global, "lua");
|
||||
for (int i = 0; luadir && luadir[i]; i++) {
|
||||
newpath = talloc_asprintf_append(newpath, ";%s",
|
||||
mp_path_join(tmp, bstr0(luadir[i]), bstr0("?.lua")));
|
||||
char *dirs[] = {"scripts", "lua", NULL};
|
||||
for (int s = 0; dirs[s]; s++) {
|
||||
char **luadir = mp_find_all_config_files(tmp, get_mpctx(L)->global,
|
||||
dirs[s]);
|
||||
for (int i = 0; luadir && luadir[i]; i++) {
|
||||
// No need to display a warning for lua files in the deprecated
|
||||
// 'lua' dirs since scripting.c already warned on them
|
||||
newpath = talloc_asprintf_append(newpath, ";%s",
|
||||
mp_path_join(tmp, bstr0(luadir[i]), bstr0("?.lua")));
|
||||
}
|
||||
}
|
||||
|
||||
lua_pushstring(L, newpath); // package path newpath
|
||||
|
|
|
@ -14,7 +14,7 @@ function mp.get_script_name()
|
|||
end
|
||||
|
||||
function mp.get_opt(key, def)
|
||||
local opts = mp.get_property_native("options/lua-opts")
|
||||
local opts = mp.get_property_native("options/script-opts")
|
||||
local val = opts[key]
|
||||
if val == nil then
|
||||
val = def
|
||||
|
|
|
@ -79,18 +79,18 @@ function read_options(options, identifier)
|
|||
end
|
||||
|
||||
--parse command-line options
|
||||
for key, val in pairs(mp.get_property_native("options/lua-opts")) do
|
||||
for key, val in pairs(mp.get_property_native("options/script-opts")) do
|
||||
local prefix = identifier.."-"
|
||||
if not (string.find(key, prefix, 1, true) == nil) then
|
||||
key = string.sub(key, string.len(prefix)+1)
|
||||
|
||||
-- match found values with defaults
|
||||
if options[key] == nil then
|
||||
msg.warn("lua-opts: unknown key " .. key .. ", ignoring")
|
||||
msg.warn("script-opts: unknown key " .. key .. ", ignoring")
|
||||
else
|
||||
local convval = typeconv(options[key], val)
|
||||
if convval == nil then
|
||||
msg.error("lua-opts: error converting value '" .. val ..
|
||||
msg.error("script-opts: error converting value '" .. val ..
|
||||
"' for key '" .. key .. "'")
|
||||
else
|
||||
options[key] = convval
|
||||
|
|
|
@ -179,7 +179,7 @@ void mp_load_scripts(struct MPContext *mpctx)
|
|||
mp_load_script(mpctx, "@osc.lua");
|
||||
if (mpctx->opts->lua_load_ytdl)
|
||||
mp_load_script(mpctx, "@ytdl_hook.lua");
|
||||
char **files = mpctx->opts->lua_files;
|
||||
char **files = mpctx->opts->script_files;
|
||||
for (int n = 0; files && files[n]; n++) {
|
||||
if (files[n][0])
|
||||
mp_load_script(mpctx, files[n]);
|
||||
|
@ -187,13 +187,24 @@ void mp_load_scripts(struct MPContext *mpctx)
|
|||
if (!mpctx->opts->auto_load_scripts)
|
||||
return;
|
||||
|
||||
// Load all lua scripts
|
||||
// Load all scripts
|
||||
void *tmp = talloc_new(NULL);
|
||||
char **luadir = mp_find_all_config_files(tmp, mpctx->global, "lua");
|
||||
for (int i = 0; luadir && luadir[i]; i++) {
|
||||
files = list_script_files(tmp, luadir[i]);
|
||||
for (int n = 0; files && files[n]; n++)
|
||||
mp_load_script(mpctx, files[n]);
|
||||
const char *dirs[] = {"scripts", "lua", NULL}; // 'lua' is deprecated
|
||||
int warning_displayed = 0;
|
||||
for (int s = 0; dirs[s]; s++) {
|
||||
char **scriptsdir = mp_find_all_config_files(tmp, mpctx->global, dirs[s]);
|
||||
for (int i = 0; scriptsdir && scriptsdir[i]; i++) {
|
||||
files = list_script_files(tmp, scriptsdir[i]);
|
||||
for (int n = 0; files && files[n]; n++) {
|
||||
if (s && !warning_displayed) {
|
||||
warning_displayed = 1;
|
||||
MP_WARN(mpctx,
|
||||
"warning: '%s' - '%s' dirs are deprecated. Please move scripts to '%s'.",
|
||||
files[n], dirs[s], dirs[0]);
|
||||
}
|
||||
mp_load_script(mpctx, files[n]);
|
||||
}
|
||||
}
|
||||
}
|
||||
talloc_free(tmp);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue