Closed stax76 closed 2 years ago
Perhaps @avih, who is a mpv dev that is active with scripting, can help us.
So far I don't understand the issue or its context.
Is the problem about being able to debug lua scripts while running in mpv? I don't have any experience with this, but IIRC some lua debug things depend on luasocket, which is probably unlikely to work with the embedded version of lua at libmpv.
Or is it about a specific issue in some script which you're not sure how to solve? (if yes, where's the script, and what's the issue?)
Or something else?
Is the problem about being able to debug lua scripts while running in mpv?
That's it, yes. Thanks for the input.
This is because the file is loaded does not meet the specification.
see: https://www.lua.org/manual/5.1/manual.html#3.8
source: If the function was defined in a string, then source is that string. If the function was defined in a file, then source starts with a '@' followed by the file name.
You should use load(filecontent, '@' .. filepath)
I will try this, thanks!
This launch.json is enough to load the debugger.
{
"version": "0.2.0",
"configurations": [
{
"type": "lua",
"request": "launch",
"name": "launch",
"runtimeExecutable": "${workspaceFolder}/mpv.exe",
"stopOnEntry": true,
"luaVersion": "5.1",
}
]
}
As @sumneko said, mpv doesn't set the chunkname correctly, so the debugger can't get information about the source file.
For mpv's built-in lua, you can use sourcemaps
to map them to the correct files. But you have to make sure that the mapped file is exactly the same as the file used by mpv. Of course the best solution is to let mpv use the correct chunkname.
"sourceMaps": [
[
"mp.*",
"${workspaceFolder}/mpv/player/lua/*.lua"
],
[
"@*",
"${workspaceFolder}/mpv/player/lua/*"
]
]
For non-built-in lua, mpv does not add @ in chunkname, so sourcemap can't solve it either.
I have it fully working now, wrote about it in the mpv thread, thank you for your great work and support, greatly appreciated.
@actboy168 Change was added to mpv master here:
https://github.com/mpv-player/mpv/commit/84821dbcb6d9e16b8f11da2135208e4f3e66fcd0
In launch.json do I need "request": "attach" or "request": "launch" ? Or might both work?
I tried both methods and had some success with both, but not full success.
In both cases, the breakpoints were not hit in the lua script that was loaded by mpv, but they were hit in another file called with dofile.
Is maybe the way how mpv loads the script the problem? Code is here:
https://github.com/mpv-player/mpv/blob/master/player/lua.c#L247
I've made a mpv debug build with msys2 and this guide:
https://github.com/mpv-player/mpv/blob/master/DOCS/compile-windows.md#native-compilation-with-msys2
The project I work on is a mpv frontend:
https://github.com/stax76/mpv.net
Perhaps @avih, who is a mpv dev that is active with scripting, can help us. He has helped me before with scripting.
My launch.json config: