Closed snowman closed 3 years ago
Edited:
require(modname)
funciton.When the script seek-to.lua
is loaded with loader.lua
, seek-to.lua
does NOT respond to the input.conf
key bindings.
-- FILE: MPV_CONFIG_DIR/scripts/loader.lua
require "occivink/mpv-scripts/scripts/seek-to"
-- FILE: MPV_CONFIG_DIR/scripts/occivink/mpv-scripts/scripts/seek-to.lua
mp.add_key_binding(nil, "toggle-seeker", toggle-seeker)
## FILE: input.conf
## This does not work, because "seek-to.lua" is required by "loader.lua"
##
## So the target name is "loader" instead of "seek_to", you can check
## script name by put "mp.msg.error(mp.get_script_name())" at the top of
## "seek_to.lua"
t script-message-to seek_to toggle-seeker
Edited: https://mpv.io/manual/master/#command-interface-script-message-to
Same as script-message, but send it only to the client named
. Each client (scripts etc.) has a unique name.
For example, Lua scripts can get their name via "mp.get_script_name()".
This command has a variable number of arguments, and cannot be used with named arguments.
## FILE: input.conf
## Either work
t script-message toggle-seeker
t script-message-to loader toggle-seeker
emmm, anyway, using require(modname)
is not the best practice.
What if the script has options script-opts/SCRIPT_NAME.conf
file?
so use this instead:
function load_script(script)
mp.command("load-script " .. "~~/scripts/" .. script)
end
-- mpv-scripts
load_script("vendor/occivink/mpv-scripts/scripts/seek-to.lua")
So the best practice to load a script is to use mp.command("load-script " .. path_to_script)
instead of require(modname)
which has the limitation not allowing VERSION number like 3.1
to appear in the modename.
I have no clue what you are trying to achieve and what you are doing
Use version number with dot(.) like 3.1
in SimpleUndo-3.1.lua is not best practice, how about strip the version number -3.1
off into SimpleUndo.lua
But now i am using mp.command("load-script " .. "SimpleUndo-3.1.lua")
, the problem never bother me, so help yourself :D
You can load the scripts, simply by placing them in the scripts directory. It will automatically use the script. But I believe removing the version number is a better approach, I will be removing it in the future. Feel free to remove it, it won't break anything.
If oneself wants to remap the keybinding,
## FILE: input.conf
## use "SmartHistory_1_7_1/resume" instead of "resume" to avoid conflict
x script-binding resume
x script-binding SmartHistory_1_7_1/resume
## same as above
x script-message resume
x script-message-to SmartHistory_1_7_1 resume
After upgrade SmartHistory
from 1.7.1
into 1.7.2
, you have to change those input.conf
accordingly.
Thanks :heart:
Renamed version number from scripts
description
When using
require("SCRIPT_NAME-VERSION")
to load Lua script, it'll first replace version number with "directory separator" in the modname, for example:require (modname)
document: https://www.lua.org/manual/5.1/manual.html#5.3What's expected?
Strip version number from the script file name, for example,
SmartHistory-1.7.1.lua
should be renamed intoSmartHistory.lua