[Love] VSCODE 调试 LOVE 引擎游戏
VSCODE调试LOVE引擎游戏
安装插件


配置插件
按 CTRL + SHIFT + P
,打开Preferences: Open User Settings (JSON)
,为settings.json添加如下代码
"Lua.runtime.version": "LuaJIT",
"Lua.diagnostics.globals": [
"love",
],
"Lua.workspace.library": [
"${3rd}/love2d/library"
],
"Lua.workspace.checkThirdParty": false,
添加系统环境变量

配置启动文件
到Run and Debug
配置launch.json
,该文件将出现在你工作目录下的 .vscode 文件夹
{
"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": [
".",
],
},
]
}
添加至 main.lua最顶部
if arg[2] == "debug" then
require("lldebugger").start()
end
添加至main.lua最底部(可选)
出错信息不会显示在游戏窗口画面上,而是直接定位到当前错误的行

local love_errorhandler = love.errhand
function love.errorhandler(msg)
if lldebugger then
error(msg, 2)
else
return love_errorhandler(msg)
end
end
关闭外部控制台
修改conf.lua
,关闭t.console
,否则调试器会无法获取到信息而卡住
-- conf.lua
love.conf = function(t)
-- t.console = true
end
启动调试
按F5启动游戏,你现在可以选择两种方式来启动
- Debug 可以调试游戏(需要设置断点)
- Release 直接运行游戏

如果出现提示 '"love"' �����ڲ����ⲿ���Ҳ���ǿ����еij��� ���������ļ���
只需要重启VSCODE
关于调试器
tomblind/local-lua-debugger-vscode: Local Lua Debugger for VSCode (github.com)
⭐ 快速模板
if arg[2] == "debug" then
require("lldebugger").start()
end
-- your code
local love_errorhandler = love.errhand
function love.errorhandler(msg)
if lldebugger then
error(msg, 2)
else
return love_errorhandler(msg)
end
end
{
"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": [
".",
],
},
]
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为DeepSeek添加本地知识库
· 精选4款基于.NET开源、功能强大的通讯调试工具
· DeepSeek智能编程
· 大模型工具KTransformer的安装
· [计算机/硬件/GPU] 显卡