VS Code配置Lua调试环境
我这里选用Emmylua进行Lua代码调试,调试环境配置如下:
一、安装Emmylua
在VS Code扩展里搜索emmylua,然后进行安装, 如下
二、配置launch.json
在Run and Debug里生成launch.json文件
点击以上菜单后,生成launch.json文件如下:
三、配置.emmyrc.json
.emmyrc.json文件放在lua工程文件的根目录,注意文件前面有个"."号, 其内容如下:
{
"completion": {
"autoRequire": true,
"autoRequireFunction": "require",
"autoRequireNamingConvention": "camelCase",
"callSnippet": false,
"postfix": "@"
},
"signature": {
"detailSignatureHelper": false
},
"diagnostics": {
"disable": [
],
"globals": [],
"globalsRegex": [],
"severity": {
},
"enables": [
]
},
"hint": {
"paramHint": true,
"indexHint": true,
"localHint": true,
"overrideHint": true
},
"runtime": {
"version": "Lua5.4",
"requireLikeFunction": [],
"frameworkVersions": [],
"extensions": [],
"requirePattern": []
},
"workspace": {
"ignoreDir": [
],
"ignoreGlobs": [
],
"library": [],
"workspaceRoots": [],
"preloadFileSize": 1048576,
"encoding": ""
},
"resource": {
"paths": [
]
},
"codeLens": {
"enable": true
},
"strict": {
"requirePath": false,
"typeCall": true
}
}
了解详情
四、添加调试连接代码
在lua启动的脚步最上方加上如下代码
package.cpath = package.cpath .. ";C:/Users/xxx/.vscode/extensions/tangzx.emmylua-0.8.20-win32-x64/debugger/emmy/windows/x64/?.dll"
local dbg = require("emmy_core")
dbg.tcpConnect("localhost", 9966)
五、调试Lua代码
在VS Code里按下F5,或者点击如下圈起来的按钮
最后启动游戏即可进行Lua代码的断点调试.