editor + debug love2d
Posted: Sun Feb 14, 2021 8:55 am
I want to share my experience of setting up an vscode editor for debugging code (OS Windows 10)
1. create task
2. create separate lua file in project with function
3. call in you code logmsg("test", false) or logmsg("test", true)
4. now inside vscode terminal you see something like main.lua:32:[test]
ctrl + click on main.lua:32 then press enter key -> jump to call logmsg in main.lua
color output string get from here https://love2d.org/forums/viewtopic.php?t=85185
1. create task
Code: Select all
{
"version": "2.0.0",
"tasks": [
{
"label": "LOVE",
// The command is the path to your love install exe.
"command": "C:/Program Files/LOVE/lovec.exe", //!!!warning!!!! lovec not love.exe
// args are appended onto the command run, just like a batch file
"args": ["${workspaceRoot}"],
// The command is a shell script, and not just a normal command
"type": "process",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"group": {
"kind": "build",
"isDefault": true
}
,
"problemMatcher": {
"owner": "lua",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
Code: Select all
function logmsg(msg, isfull)
local level = 2 --start from preview func
local isfullstr = "";
if isfull then
isfullstr = "-- ";
end
while true do
local info = debug.getinfo(level, "Sl")
if not info then break end
-- is a C function?
if info.what == "C" then
break --print(level, "C function")
else -- a Lua function
if level == 2 then
print(string.format("%s:%d:[%s]", info.short_src, info.currentline, msg))
if isfull then
print("-------------------begin---------------------")
end
else
print(string.format("%s%s:%d", isfullstr, info.short_src, info.currentline))
end
end
level = level + 1
if not isfull then break end
end
if isfull then print("-------------------end-----------------------") end
end
4. now inside vscode terminal you see something like main.lua:32:[test]
ctrl + click on main.lua:32 then press enter key -> jump to call logmsg in main.lua
color output string get from here https://love2d.org/forums/viewtopic.php?t=85185