Closed Straskal closed 4 years ago
I have the same problem on macOS, can't require local lua modules.
I'm looking forward to the solution, because this is the only debugger that really works 🥳. Nothing else works on my mac 😟.
Found a dirty and hacky solution. I created the separated debug.lua file that I run with debugger:
debug.vscode = os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1"
if debug.vscode then
local separator = string.sub(package.config, 1, 1)
local filePath = debug.getinfo(1).short_src
local rootFolder = string.gsub(filePath, "^(.+"..separator..")[^"..separator.."]+$", "%1");
package.path = rootFolder .. [[?.lua]]
end
dofile("main.lua")
That work around works perfectly for now. @astrochili Thanks!
Have you tried setting cwd
in your launch.json?
"configurations": [
{
"name": "Debug",
"type": "lua-local",
"request": "launch",
"program": {
"lua": "lua53.exe",
"file": "main.lua"
},
"cwd": "${workspaceFolder}"
}
]
Have you tried setting
cwd
in your launch.json?
It doesn't help me, a similar error.
Another problem is the luarocks libraries finding.
For example, luarocks installed the lume module to /usr/local/var/homebrew/linked/luarocks/share/lua/5.3/lume.lua
. And the code require("lume")
works perfectly with Lua in the terminal.
But the debugger tries to find modules in this short list of paths:
no field package.preload['lume']
no file '/Users/.../.vscode/extensions/tomblind.local-lua-debugger-vscode-0.1.3/debugger/lume.lua'
no file '/usr/local/lib/lua/5.3/lume.so'
no file '/usr/local/lib/lua/5.3/loadall.so'
no file './lume.so'
It looks like the debugger doesn't check the paths list that defined in the system for succesful modules finding.
You're on OSX, right? It seems environment variables like LUA_PATH
aren't passed to the child process in OSX (see # 5 #7). I don't have a Mac right now so I'll need to find one to debug this issue.
Thinking about it, this issue must be different since the debugger script itself is being found.
You're on OSX, right?
Yes. Feel free to ask any questions or test tasks, maybe I can help you.
Wow. Found a more clean solution in #10 that solves all my path finding problems. Just add this to debug configutation:
"env": {
"LUA_PATH": "./?.lua;[ADDITIONAL_PATHS]"
}
where [ADDITIONAL_PATHS]
in my case is all that luarocks path
terminal command returns. The final configuration looks like this:
{
"configurations": [
{
"name": "Debug",
"type": "lua-local",
"request": "launch",
"program": {
"lua": "lua5.3",
"file": "${workspaceFolder}/main.lua"
},
"env": {
"LUA_PATH": "./?.lua;/usr/local/Cellar/luarocks/3.2.1/share/lua/5.3/?.lua;/usr/local/share/lua/5.3/?.lua;/usr/local/share/lua/5.3/?/init.lua;/usr/local/lib/lua/5.3/?.lua;/usr/local/lib/lua/5.3/?/init.lua;./?.lua;./?/init.lua;/Users/username/.luarocks/share/lua/5.3/?.lua;/Users/username/.luarocks/share/lua/5.3/?/init.lua"
}
}
]
}
Now I don't have any problems with local and external lua modules requiring and I don't need to create a separated module for debugger running.
It looks like LUA_PATH
is not being passed to the debug adapter from vscode. Will you try this in your launch.json and see if it works?
"env": {
"LUA_PATH": "${env:LUA_PATH}"
}
"LUA_PATH": "a${env:LUA_PATH}b"
in the configuration and It returned no file 'ab'
.echo $LUA_PATH
in the terminal and it returned nothing. Should there be anything?print(package.path)
in pure Lua in the terminal and it returned /usr/local/share/lua/5.3/?.lua;/usr/local/share/lua/5.3/?/init.lua;/usr/local/lib/lua/5.3/?.lua;/usr/local/lib/lua/5.3/?/init.lua;./?.lua;./?/init.lua
. That's a correct path of course, so I placed it to "env": { "LUA_PATH": ... }
and it works perfectly for local and luarocks modules.print(package.path)
in the debugger without any workarounds and it returned only /Users/.../.vscode/extensions/tomblind.local-lua-debugger-vscode-0.1.3/debugger/?.lua
.Thanks for the exhaustive testing! 😄
It looks like LUA_PATH
isn't being used to set package.path
. If you don't mind, will you try testing with LUA_PATH_5_3
? It's possible that's what your setup is using instead of LUA_PATH
.
Nope, the same situation:
In the terminal of vscode or an external one? There should be something in one of those two env variables, because that's where package.path
is set from.
I mean the external system terminal app, not VSCode.
With Lua in the terminal:
os.getenv("LUA_PATH")
-> nilos.getenv("LUA_PATH_5_3")
-> nilLUA_PATH
-> nilLUA_PATH_5_3
-> nilWith debugger in VSCode:
os.getenv("LUA_PATH")
-> /Users/.../.vscode/extensions/tomblind.local-lua-debugger-vscode-0.1.3/debugger/?.lua
os.getenv("LUA_PATH_5_3")
-> nilLUA_PATH
-> nilLUA_PATH_5_3
-> nilVery strange, Lua must be getting its path from somewhere other than the standard env vars.
On the terminal, can you type declare
and see if any env vars reference those paths?
I typed declare
and there are no matches for those paths and nothing with word lua
🤔.
Well now I'm very confused 😆 It's got to be getting those paths from somewhere.
Look at this, sounds like Lua get default paths from luaconf.h
. And that seems real because it has LUA_PATH_DEFAULT variable with my paths.
Ah yeah, that's where it's getting the defaults. But how does it find the luarocks modules? You said before those work when running from terminal, right?
Yeah, it's simple because luarocks installs modules in these paths. For example luarocks module lume
has a path /usr/local/share/lua/5.3/lume.lua
. I don't know why luarocks path
returns such long list of paths but I don't need them, as we see. The default list of paths from luaconf.h
is enough.
Ahhh. Ok. Now it all makes sense 😄
Yes, in short, the problem is that the debugger doesn't read the standard lua paths from luaconf.h
. I don’t know what about LUA_PATH
, because I don’t have it, maybe it doesn’t work too.
"cwd": "${workspaceFolder}" definitely helped with loading assets. Thanks!
And it looks like everything's working! Awesome.
Hi there!
I'm having issues regarding relative file paths for assets (images) and require paths (other lua files).
lldebugger.lua
instead of thelua53.exe
.I have my
launch.json
configured to use thelua53.exe
interpreter andmain.lua
as my entry file.Folder structure:
main.lua is not able to find imageLoader.lua via
require()
I bundled the two files together to avoid
require()
, but then my program is unable to find the image.Any help or work arounds would be greatly appreciated!
Thank you.