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文章来源:https://www.toymoban.com/news/detail-667245.html
关于调试器
tomblind/local-lua-debugger-vscode: Local Lua Debugger for VSCode (github.com)文章来源地址https://www.toymoban.com/news/detail-667245.html
⭐ 快速模板
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": [
".",
],
},
]
}
到了这里,关于[Love] VSCODE 调试 LOVE 引擎游戏的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!