editor + debug love2d

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
borr
Prole
Posts: 42
Joined: Wed Oct 16, 2019 7:39 pm

editor + debug love2d

Post by borr »

I want to share my experience of setting up an vscode editor for debugging code (OS Windows 10)

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
                }
            }
        }
    ]
}
2. create separate lua file in project with function

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
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
Attachments
logutility.lua
color code thanx to pgimeno
(2.41 KiB) Downloaded 73 times
dezoitodemaio
Prole
Posts: 15
Joined: Mon Oct 26, 2020 2:02 pm

Re: editor + debug love2d

Post by dezoitodemaio »

Nice tip.

Why use that instead of the love console?
borr
Prole
Posts: 42
Joined: Wed Oct 16, 2019 7:39 pm

Re: editor + debug love2d

Post by borr »

see the fourth point
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
plus you get search functionality by CTRL+F
Post Reply

Who is online

Users browsing this forum: No registered users and 99 guests