How to install modules?
I need modules like luafilesystem
This is not a package manager.
This is not a package manager.
Is it possible to use my own Lua installation instead of the one that comes with the extension?
I don't understand what you mean.
tl;dr: to debug scripts that need modules (that you installed witgh luarocks), make sure that your script works when you launch it with the installed lua interpreter, then modify the launch.json file in your workspace to add the paths to luarocks to PATH, LUA_PATH and LUA_CPATH
Sorry to dig a 1 year old message, but that might help someone... I was in the same situation than you, I needed to debug in VS Code a lua script that used some modules like luafilesystem, socket etc. ...
I was initially able to use my own lua interpreter by setting the luaexe tag in the launch.json: "luaexe": "<...whatever path is your lua installed...>/bin/lua54.exe",
All worked, but strangely, in the debugger, the breakpoints were working, but not the "step over" ! Trying to do so was just silently terminating my script.
I fould a better way, and here is my setup now:
- I don't use an external lua interpreter, I stick with the one provided in the extension -> I don't have the "luaexe" tag defined anymore in the launch.json
- I added this in the launch.json: "env": { "DEBUGGER": "True", "PATH": "${env:PATH};<...path to luarocks...>\lib\lua\5.4", "LUA_CPATH": "<...path to luarocks...>/lib/lua/5.4/?54.dll;<...path to luarocks...>/lib/lua/5.4/?.dll;", "LUA_PATH": "<...path to luarocks...>/share/lua/5.4/?.lua;<...path to luarocks...>/share/lua/5.4/?/init.lua;./?.lua", }, Some of the plugins require that the .dll are in the PATH environment variable. I don't know if that's expected, but it doesn't work for some modules if I don't do that.
@flioscordel Thanks very much. That is very helpful.
Correction, sorry. It's not in the "ENV" block that you need to specify the path and cpath. They have their own section in the launch.json: I give you my own launch.json, that works. Please note that "${workspaceFolder}/../lua/rocks" is a folder where I replicate my lua rocks files, to make sure the repository is autonomous.
"version": "0.2.0",
"configurations": [
{
"name": "Debug Current File",
"type": "lua",
"request": "launch",
"program": "${file}", // Launches the current file
"cwd": "${workspaceFolder}", // Sets the working directory to the workspace folder
// Uncomment if you want to use your specific Lua interpreter
// "luaexe": "${workspaceFolder}/../lua/bin/lua54.exe",
"luaVersion": "lua54", // Change to your Lua version
"env": {
"DEBUGGER": "True",
"PATH": "${env:PATH};${workspaceFolder}/../lua/rocks/lib/lua/5.4",
},
"cpath": "${workspaceFolder}/../lua/rocks/lib/lua/5.4/?54.dll;${workspaceFolder}/../lua/rocks/lib/lua/5.4/?.dll;",
"path": "${workspaceFolder}/../lua/rocks/share/lua/5.4/?.lua;${workspaceFolder}/../lua/rocks/share/lua/5.4/?/init.lua;./?.lua",
"arg": [], // Additional arguments if needed
"stopOnEntry": false // Whether to stop at the first line
}
]