Mpv: v0.32.0 fails to locate required lua scripts

Created on 27 Jan 2020  ·  7Comments  ·  Source: mpv-player/mpv

Important Information

Provide following Information:

  • mpv version:
    mpv 0.32.0
  • Linux Distribution and Version
    arch Linux, kernel version 4.19.98-1-lts

  • Source of the mpv binary
    arch distro standard package.

  • If known which version of mpv introduced the problem
    latest on this distro, 0.32.0

  • Window Manager and version
    i3 version 4.17.1 (2019-08-30)

  • GPU driver and version
    VGA compatible controller: Intel Corporation HD Graphics 620 (rev 02)

  • Possible screenshot or video of visual glitches
    N/A

Reproduction steps

Upon loading any video file with the newest version 0.32.0 a number of scripts in ${HOME}/.config/mpv/scripts/ fail to load because they require another utils.lua package in the same directory.

The sorts of errors I am receiving (red in a console when starting from the command line):

[eof_del] Lua error: ${HOME}/.config/mpv/scripts/eof-del.lua:1: module 'utils' not found:
[eof_del]       no field package.preload['utils']
[eof_del]       no file '/usr/share/lua/5.2/utils.lua'
[eof_del]       no file '/usr/share/lua/5.2/utils/init.lua'
[eof_del]       no file '/usr/lib/lua/5.2/utils.lua'
[eof_del]       no file '/usr/lib/lua/5.2/utils/init.lua'
[eof_del]       no file './utils.lua'
[eof_del]       no file '/usr/lib/lua/5.2/utils.so'
[eof_del]       no file '/usr/lib/lua/5.2/loadall.so'
[eof_del]       no file './utils.so'

Explanation
I have a script ${HOME}/.config/mpv/scripts/eof-del.lua that in turns calls ${HOME}/.config/mpv/scripts/utils.lua with a require directive:

${HOME}/.config/mpv/scripts/eof-del.lua:
---
local utils = require 'utils'
...

Both files exist and are readable. Furthermore, downgrading back to the previous version 0.31.0 restores functionality with no errors. I have the exact same Lua script setup on a number of other machines, ranging in mpv version from 0.27.2 to 0.31.0, and I have never seen this issue before.

Expected behavior

No errors as indicated above.

Actual behavior

Lua-script loading reported and described above.

Log file

https://0x0.st/irDl.txt

Sample files

Place the script

toy.lua
---
local tb = require 'toy-utils'

in ${HOME}/.config/mpv/scripts/ along with the package it requires:

toy-utils.lua
---
tb={}
return tb
linux

All 7 comments

As far as I understand it, this was intentionally changed in commit bc1c024ae032e5b5c2d8beb06cf310636e402de4.

This will, I bet, be massively stupid of me, but how does one use functions across different Lua scripts then? Surely it's useful to define a function in one file and use it elsewhere, perhaps in multiple other scripts..

Right now I have symlinked the utils.lua package into /usr/share/lua/5.2/, where the error messages report it is being looked for, but surely there should be ways to do this locally, without having to pollute /usr/ with stray links..


Edit:

Never mind, the solution I'll settle for is to simply add the following line in all of those scripts that need to import my mpv package(s) from ${HOME}/.config/mpv/scripts:

package.path = package.path .. ';${HOME}/.config/mpv/scripts/?.lua'

where ${HOME} is my actual fully-expanded home directory.


2nd Edit:

Or more robustly, so as to have it work across multiple systems with different main usernames, etc.:

local home = os.getenv("HOME")
package.path = package.path .. ';' .. home .. '/.config/mpv/scripts/?.lua'

Install them into the official package paths.

Personally I'd do a preface to the tune of:

local lua_modules = mp.find_config_file('scripts/lua-modules')
if lua_modules then
    -- lua_modules can be nil if the folder does not exist or we're in --no-config mode
    package.path = package.path .. ';' .. lua_modules .. '/?.lua;' .. lua_modules .. '/?/init.lua'
end

-- scripts/
-- require_test.lua
--  lua-modules/
--    my_module.lua
local my_module = require('my_module')
my_module.woot()

This enables requiring modules in scripts/lua-modules (as module.lua or module/init.lua) and works on Linux and Windows.
(Well, at least until mp.find_config_file is removed, as it's undocumented and therefore technically unsupported.)
(Also there might be multiple scripts directories in the many places mpv looks for config files, but mp.find_config_file will only give you the first one found.)

@wm4, actually the "portable_config" functionality is broken though. Package.pack cannot see portable_config any longer and scripts in /portable_config/scripts/*.lua are not loaded correctly, using version mpv 0.32.0-258-g281f5c63c1

BEFORE

package.path = ".\?.lua;c:\somedir\MPlayer\lua\?.lua;c:\somedir\MPlayer\lua\?\init.lua;;c:/somedir/MPlayer/portable_config/scripts/?.lua"

AFTER

package.path = "c:\somedir\MPlayer\lua\?.lua;c:\somedir\MPlayer\lua\?\init.lua" <--here the /portable_config/ subdir is missing

That is not supposed to work.

Before upgrading to new mpv git version, it was working correctly. I have module.lua and script.lua in the same /portable_config/scripts directory. Right now I'm getting this message:

[testscript]
[testscript] stack traceback:
[testscript] ...somedir/MPlayer/portable_config/scripts/testscript.lua:1: in main chunk
[testscript] [C]: at 0x010acb40
[testscript] [C]: at 0x010ac180
[testscript] Lua error: ...somedir/MPlayer/portable_config/scripts/testscript.lua:1: module 'lib_myass' not found:
[testscript] no field package.preload['lib_myass']
[testscript] no file 'c:\somedir\MPlayer\lua\lib_myass.lua'
[testscript] no file 'c:\somedir\MPlayer\lua\lib_myass\init.lua'
[testscript] no file 'c:\somedir\MPlayer\lib_myass.dll'
[testscript] no file 'c:\somedir\MPlayer\loadall.dll'

It's missing c:\somedir\MPlayer\portable_config\lua\ path so it cannot load the lib_myass.lua module...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thebunnyrules picture thebunnyrules  ·  3Comments

422658476 picture 422658476  ·  3Comments

beew picture beew  ·  3Comments

ww7 picture ww7  ·  3Comments

SPDurkee picture SPDurkee  ·  3Comments