You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
}
]
@flioscordel That was super helpful, thanks a ton!
Here's my config for a self-hosted remote development environment (uses code-server in Docker), just in case someone comes across this and has a setup similar to mine:
{
"type": "lua",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/main.lua",
"cwd": "${workspaceFolder}", // Sets the working directory to the workspace folder"luaexe": "/usr/bin/lua",
"luaVersion": "lua51",
"env": {
"DEBUGGER": "True",
"PATH": "${env:PATH};/config/.luarocks/lib/luarocks/rocks5.1"
},
"cpath": "/config/.luarocks/lib/luarocks/rocks5.1/?51.dll;/config/.luarocks/lib/luarocks/rocks5.1/?.dll;",
"path": "/config/.luarocks/share/lua/5.1/?.lua;/config/.luarocks/share/lua/5.1/?/init.lua;./?.lua",
"arg": [], // Additional arguments if needed"stopOnEntry": false// Whether to stop at the first line
}
Activity
actboy168 commentedon Feb 26, 2024
This is not a package manager.
a7k4xz commentedon Feb 26, 2024
Is it possible to use my own Lua installation instead of the one that comes with the extension?
actboy168 commentedon Feb 26, 2024
I don't understand what you mean.
flioscordel commentedon Feb 1, 2025
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:
"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.
a7k4xz commentedon Feb 1, 2025
@flioscordel Thanks very much. That is very helpful.
flioscordel commentedon Feb 3, 2025
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.
FunctionDJ commentedon Nov 18, 2025
@flioscordel That was super helpful, thanks a ton!
Here's my config for a self-hosted remote development environment (uses code-server in Docker), just in case someone comes across this and has a setup similar to mine:
{ "type": "lua", "request": "launch", "name": "Debug", "program": "${workspaceFolder}/main.lua", "cwd": "${workspaceFolder}", // Sets the working directory to the workspace folder "luaexe": "/usr/bin/lua", "luaVersion": "lua51", "env": { "DEBUGGER": "True", "PATH": "${env:PATH};/config/.luarocks/lib/luarocks/rocks5.1" }, "cpath": "/config/.luarocks/lib/luarocks/rocks5.1/?51.dll;/config/.luarocks/lib/luarocks/rocks5.1/?.dll;", "path": "/config/.luarocks/share/lua/5.1/?.lua;/config/.luarocks/share/lua/5.1/?/init.lua;./?.lua", "arg": [], // Additional arguments if needed "stopOnEntry": false // Whether to stop at the first line }