[Unity实战]一个好用的lua调试工具vscode-luaide-lite插件 好用到飞起..[Debug][开箱可用][xlua]
- 简介
- 官方例子:xlua/tolua/slua/lua5.1等
- 1.安装
- 2.配置
- 3.使用
- 3.1启动unity
- 3.2vscode-debug:Unity Editor
- 3.3vscode-debug:
- 3.4运行unity进入断点...
- 4.核心代码:
- 5.github地址
简介
luaide-lite官网
luaide-lite
Author: Wells Hsu
Email: wellshsu@outlook.com
Github: https://github.com/wellshsu/luaide-lite
Features | 功能特性
有问题请在github->issue中反馈,不定期查看.
legacy的解析库不再维护(推介使用emmy), debug和format模块会继续维护.
若emmy解析库不生效,请检查java环境是否配置.
【代码编写】
标准格式化: 与 IntelliJ IDEA 平台的 EmmyLua 格式化结果一致, 参考VS的格式化标准, 大文件格式化更快.
批量格式化: 选中文件/文件夹, 点击'Lua/Format File(s)'以格式化这些文件.
代码注解: 引用自 EmmyLua, 使用参考 https://emmylua.github.io/annotation.html
智能提示: 支持查找引用, 重构, 定义跳转, 文件符号, 变量颜色高亮等.
【代码调试】
多平台调试: 支持cocos, lua51, tolua, slua, xlua 等, 调试示例在群文件或Github中下载, 环境配置请参考各示例的README.md文件.
单文件调试: 支持使用Lua51调试demo.
条件断点: 支持设置表达式以及断点次数.
【辅助功能】
解析库切换: 设置 'luaide-lite.core' 以指定代码解析工具, emmy-使用emmylua库解析工程(推介使用), legacy-使用既有版本解析工程(不再维护).
To Typescript: 将Lua代码转换为Typescript.
To CSharp: 将Lua代码转换为CSharp.
模板文件: 在设置中添加 'templateDir' 和 'templateDefine' 以指定模板文件目录以及全局文本替换字段, 在工程结构目录右键选择 'Lua/New Template' 以创建模板文件.
官方例子:xlua/tolua/slua/lua5.1等
1.安装
VSCODE->Extensions->luaide-lite v0.3.1安装
2.配置
.vscode\launch.json
{// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "Unity Editor","type": "unity","path": "${workspaceFolder}/Library/EditorInstance.json","request": "launch"},{"name": "Unity-xlua","type": "lua","request": "attach","runtimeType": "Unity","localRoot": "${workspaceRoot}","fileExtNames": [".lua",".txt",".lua.txt",".bytes"],"port": 7003,"printType": 1},]
}
3.使用
3.1启动unity
3.2vscode-debug:Unity Editor
{string dir = Application.dataPath + "/LuaScripts/";LuaEnv luaenv = new LuaEnv();luaenv.AddLoader(new LuaEnv.CustomLoader((ref string f) =>{f = f.Replace(".", "/");f = dir + f + ".lua";return File.ReadAllBytes(f);}));luaenv.DoString("require 'Main'");Table = luaenv.Global.Get<LuaTable>("Main");AwakeFunction = Table.Get<LuaFunction>("Awake");StartFunction = Table.Get<LuaFunction>("Start");UpdateFunction = Table.Get<LuaFunction>("Update");OnDestroyFunction = Table.Get<LuaFunction>("OnDestroy");if (AwakeFunction != null) { AwakeFunction.Call(gameObject); }}void Start(){if (StartFunction != null) { StartFunction.Call(); }}void Update(){if (UpdateFunction != null) { UpdateFunction.Call(); }}void OnDestroy(){if (OnDestroyFunction != null) { OnDestroyFunction.Call(); }}
}
Main.lua
local BREAKINFOFUNC, XPCALLFUNC = require("LuaDebug")("localhost", 7003)
Main = {}function Main.Awake(gameObject)print("Main.Awake")
endfunction Main.Start()print("Main.Start")
endfunction Main.Update()endfunction Main.OnDestroy()print("Main.OnDestroy")
end
.vs/launch.json
{// 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "Unity Editor","type": "unity","path": "${workspaceFolder}/Library/EditorInstance.json","request": "launch"},{"name": "Unity-xlua","type": "lua","request": "attach","runtimeType": "Unity","localRoot": "${workspaceRoot}","fileExtNames": [".lua",".txt",".lua.txt",".bytes"],"port": 7003,"printType": 1},]
}
5.github地址
MyXlua_Luaide-Lite