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

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Mantismal
Prole
Posts: 1
Joined: Sun Jun 02, 2024 10:53 pm

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

Post 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.
Trystan
Prole
Posts: 15
Joined: Fri Nov 24, 2023 9:30 am

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

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests