Page 1 of 1

Is there any way to use the vscode terminal for debugging with love2d?

Posted: Sun Jun 02, 2024 11:01 pm
by Mantismal
Im just wondering if there is any way to use the vscode terminal for debugging?is there like an extension or something or some other way to do it.

Re: Is there any way to use the vscode terminal for debugging with love2d?

Posted: Sun Jun 09, 2024 1:02 pm
by Trystan
To make it so you can output message to the terminal with print commands you just need the following line at the start of your main.lua file:

Code: Select all

io.stdout:setvbuf("no")
For full debugging (breakpoints and stepping through functions etc.) I use https://marketplace.visualstudio.com/it ... ger-vscode

That takes a bit more setting up and my setup may not be the best, I got it going a while ago have been copying a bese template project ever since so can't quite remember which bits I did anything to and which bits I haven't.

My launch.json I use (this file should be in the .vscode subfolder of your love projects) is:

Code: Select all

{
    "version": "0.2.0",
    "configurations": [
      {
        "type": "lua-local",
        "request": "launch",
        "name": "Debug",
        "program": {
          "command": "love"
        },
        "args": [
          ".",
          "debug"
        ],
      },
      {
        "type": "lua-local",
        "request": "launch",
        "name": "Release",
        "program": {
          "command": "love"
        },
        "args": [
          ".",
        ],
      },
    ]
  }
Then in love.load() I enable the debugger like this:

Code: Select all

    -- Enable debugger
    debugMode = false
    if arg[2] == "debug" then
        require("lldebugger").start()
        debugMode = true
    end
Finally, for the debugger to catch errors you need to override the love error handler:

Code: Select all

local loveErrorhandler = love.errorhandler or love.errhand
function love.errorhandler(msg)
    if debugMode then
        error(msg, 2)
    else
        return loveErrorhandler(msg)
    end
end