Ulua&ToLua 调试
2018-03-01 10:43
1191 查看
1.准备工作
注意:LuaIde 调试采用 LuaSocket 进行数据传输,所以需要调试的宿主必须包含LuaSocket 库平台支持:
win
mac
Linux
android
ios
luaIDE免费版本
下载地址:https://www.jianshu.com/p/a2142d4f119c调试代码下载:
下载对应版本的 lua 调试文件下载调试代码后请将对应的调试代码文件放入脚本文件根目录,如果想放入其他目录,那么在require 请填写正确路径
LuaDebug.lua 对应Lua
LuaDebjgjit.lua对应 luajit (cocos3.x 默认为jit 版本,slua 最新版本默认也为jit)
免费版本调试文件LuaDebug.zip
收费版本调试文件 LuaDebug_1.0.4.zip
2.生成调试配置
这里很多同学出现过一个问题,就是同时下载了很多的lua 调试插件,所以这里需要* * 注意 如果使用luaide进行lua调试,需要先禁用或卸载其他的lua调试插件.步骤:
1.如果你没有生成过调试配置 那么先生成
2.如果你已经有调试配置了可修改/删除工作目录下的.vscode/launch.json
3.根据调试需要选择本地或者远程调试即可
#launch.json文件注释 #attach 远程调试 Unity 调试都为远程调试 不分平台请注意 { "name": "Unity-ulua", "type": "lua", "request": "attach", "runtimeType": "Unity", "localRoot": "${workspaceRoot}", "fileExtname": ".lua", "port": 7003, "printType": 1 } name:命名调试器选择项名字 type: 默认配置不需要修改 request:默认配置不需要修改 runtimeType:默认配置不需要修改 localRoot: 与本地调试不同,远程调试 localRoot 当做scriptMap 一般情况下默认为 ${workspaceRoot} 即可,如果你的代码目录是 ${workspaceRoot} 下载的某个路径 也可明确指定 如 ${workspaceRoot}/scripts fileExtname:该选项ulua 用默认值就可,如果项目中lua文件后缀不是.lua可修改为具体的后缀来告诉调试器 例如:"fileExtname": ".txt" port: 调试端口 和 调试代码中的端口统一即可 无特殊需求 printType: print打印方式:控制台和系统输出,控制台输出,系统输出
3.调试代码添加
说明:下载对应的LuaDebug 或 LuaDebugjit 后放入脚本目录中local breakSocketHandle,debugXpCall = require("LuaDebugjit")("192.168.1.102",7003) local breakSocketHandle,debugXpCall = require("LuaDebugjit")("localhost",7003) 1. IP地址当本机调试时可使用localhost远程调试或移动设备端调试是需要输入调试器所在机器具体的ip 2. port 端口 LuaIde 默认配置中端口为7003 如有需要可执行更改确保调试器配置端口和调用 代码的端口统一即可 3. breakSocketHandle luaIde断点及时刷新函数,需要在定时器中调用 该函数确保断点能够及时的 发送到lua 客户端 4. debugXpCall 程序异常监听函数,用于当程序出现异常时调试器定位错误代码 ulua 中为找到合适的位置添加 可忽略该方法
4.开启LuaSocket
ulua 默认关闭了luaSocket 如果项目没有开启请自行开启打开 Assets/Manager/LuaManager.cs 并添加如下代码
#region luaide 调试库添加 //如果项目中没有luasocket 请打开 [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))] static int LuaOpen_Socket_Core(IntPtr L) { return LuaDLL.luaopen_socket_core(L); } protected void OpenLuaSocket() { LuaConst.openLuaSocket = true; lua.BeginPreLoad(); lua.RegFunction("socket.core", LuaOpen_Socket_Core); lua.EndPreLoad(); } #endregion
并在OpenLibs 方法中调用 OpenLuaSocket()
/// <summary> /// 初始化加载第三方库 /// </summary> void OpenLibs() { lua.OpenLibs(LuaDLL.luaopen_pb); lua.OpenLibs(LuaDLL.luaopen_sproto_core); lua.OpenLibs(LuaDLL.luaopen_protobuf_c); lua.OpenLibs(LuaDLL.luaopen_lpeg); lua.OpenLibs(LuaDLL.luaopen_bit); //luaide socket 开启 lua.OpenLibs(LuaDLL.luaopen_socket_core); this.OpenLuaSocket(); //end luaide this.OpenCJson(); }
在Main.lua文件中添加调试代码
local breakSocketHandle,debugXpCall = require("LuaDebugjit")("localhost",7003) local timer = Timer.New(function() breakSocketHandle() end, 1, -1, false) timer:Start();
5.高阶用法(查看userdata 的值)
由于采用的是c#语言所以可以利用到反射机制这样可以通过反射获取一些c#类型的值显示在调试器中1.下载 LuaDebugTool.cs .
2.将LuaDebugTool.txt 重命名为 LuaDebugTool.cs 后加入到 Assets/Scripts/Utility/ 目录下.
3.打开Editor 项目中的CustomSetting.cs.
4.搜索 public static BindType[] customTypeList 所在位置添加如下代码.
_GT(typeof(LuaDebugTool)), _GT(typeof(LuaValueInfo)),
5.重新生成warp 这里我采用的是Clear warp files->Generate AllWrap.
转载:Ulua&ToLua 调试https://www.jianshu.com/p/3768fb6f9ade
相关文章推荐
- Ulua&ToLua 调试
- Unity Lua调试 ulua/tolua slua调试教程
- Lua&tolua++与c++的使用
- 无证书真机调试出现Unable to add App ID because the '10' App ID limit in '7' days has been exceeded.
- c++求教:我在linux下用CodeLite编译调试时出现&"warning: GDB: Failed to set controlling terminal: Operation not permitted/n"
- lua报错,attempt to call global 'setmetatable'(a nil value)或者类似错误
- LUA中遇到这个错误attempt to call a nil value (global 'loadstring')
- 【Android调试】 解决The connection to adb is down, and a severe error has occured. ADB server didn't ACK 问
- 远程调试 ERROR: JDWP unable to get necessary JVMTI capabilities. ["debugInit.c",L279]
- jdk1.6调试异常:JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return c
- 解决borland c++调试中“unable to open include file 'stdio.h'”的问题
- ulua,tolua升级到替换为xlua
- Lua: attempt to call method 'xxxx' (a nil value)
- AndroidStudio-无法用真机调试异常-Instant Run requires 'Tools | Android | Enable ADB integration' to be enable
- [LUA ERROR] [string ".\cocos/cocos2d/Cocos2dConstants.lua"]:620: attempt to index a nil value
- lua loadlib函数 attempt to call global 'loadlib' (a nil value)
- (pbc lua 加入)c++_lua_Python with/without extension性能测试 (10万次SerializeToString & ParseFromString)
- 初识 love2d. Hello World & lua 调试 & iOS 环境运行
- xcode在真机调试的时候出现"The identity used to sign the executable is no longer valid"
- Android NDK调试出错Unknown Application ABI, Unable to detect application ABI's的解决方案