闽公网安备 35020302035485号
配置插件
按 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
love.conf = function(t)
-- t.console = true
end
启动调试
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": [
".",
],
},
]
}