当前位置:网站首页>lua-调试技巧
lua-调试技巧
2022-07-29 17:14:00 【蝶泳奈何桥.】
title: lua-调试技巧
categories: Lua
tags: [lua, 调试, 技巧]
date: 2022-07-14 16:31:27
comments: false
mathjax: true
toc: true
lua-调试技巧
前篇
游戏 lua 脚本调试技巧, 达到修改逻辑脚本后能实时生效执行, 提高开发效率
pc 端 editor 模式
新建一个测试代码脚本
gDebugCustom = gDebugCustom or { } function gDebugCustom.Test01() gLog("--- Test01") endeditor 增加解析这个脚本, 显示出 按钮

点击按钮去执行对应的方法
csharp
GameMgr.CallLuaFunction("Debug_ExecCustomLua", luaFile, funcName);lua
-- 动态执行 自定义 lua 文件调试 function Debug_ExecCustomLua(luaFile, funcName) local ok = xpcall(function() gAssert(Utils.IsFileExist(luaFile), "--- 找不到lua 文件, path: {0}", luaFile) dofile(luaFile) gAssert(gDebugCustom, "--- 找不到全局 table: gDebugCustom") gAssert(type(gDebugCustom[funcName]) == "function", "--- 找不到 gDebugCustom.{0} 方法", funcName) gDebugCustom[funcName]() end, __G__TRACKBACK__) if ok then gLog("<color=#00ff00ff>--- gDebugCustom.{0} success!</color>", funcName) else gLog("<color=yellow>--- gDebugCustom.{0} execute fail!</color>", funcName) end end
移动端
下载 lua
在 [pc 端 editor 模式](#pc 端 editor 模式) 测试脚本上增加一个全局方法
gDebugWebFn, 用来 web 执行gDebugCustom = gDebugCustom or { } function gDebugCustom.Test01() gLog("--- Test01") end -- 增加的全局方法 gDebugWebFn = function() gDebugCustom.Test01() end游戏调试 ui 按钮上去执行一个下载测试脚本, 并执行
gDebugWebFnlocal function testDynamicLua() local url = "http://192.168.1.200:59090/lua/custom_unittest.lua" gTool.SafeDoString(url, function(isStop, msg) gLog("<color=#ffff00>--- gTool.SafeDoString, isStop: {0}</color>, msg: {1}", isStop, msg) gAssert(type(gDebugWebFn) == "function", "--- 找不到全局调试方法 gDebugWebFn") gDebugWebFn() end) end
进阶
动态执行的脚本, 再次动态下载其他逻辑脚本, 这样会重写 lua 方法, 达到实时刷新脚本逻辑
-- 避免出现在 unity editor中 gDebugCustom.requireExt = function(luaPath, callback) local luaDirUrl = "http://192.168.1.200:59090/require" local newPath = string.gsub(luaPath, "%.", "/") local relaPath = string.formatExt("{0}.lua", newPath) local fullUrl = string.formatExt("{0}/{1}", luaDirUrl, relaPath) -- gLog("--- fullUrl: {0}", fullUrl) local cbWrap = function(isOk, res) gAssert(isOk, "--- url require fail, luaPath: {0}, fullUrl: {1}", luaPath, fullUrl) gLog("<color=#00ff00>--- url require success</color>, luaPath: {0}, fullUrl: {1}", luaPath, fullUrl) if callback then callback(res) end end gBestHttpMgr:GetData(fullUrl, function(isSucc, data) if isSucc and not IsNull(data) then local text = Utils.BytesToUTF8(data) local ok, res = xpcall(loadstring(text), __G__TRACKBACK__) if not ok then cbWrap(false, "do remote string error") else -- 移动端非 ab 模式, 写入本地 if gLogicTool.IsMobile() and not Const.LuaBundleMode then local fullPath = gTool.PathJoin(Application.persistentDataPath, Const.kResluaDir, relaPath) Utils.WriteFileUTF8(fullPath, text) end cbWrap(true, res) end else cbWrap(false, "Network error") end end) end function gDebugCustom.Dynamic() local function testGm() gDebugCustom.requireExt("logic.common.gm", function() local input = "show me the log" local isOk = gGmMgr:Do(input) gLog("--- gm ok: {0}", isOk) end) end -- 测试 testGm() end
Android 端拷贝 lua
明文 lua 的方式, 可以直接将项目内的 lua 脚本用 adb 命令拷到包体目录下, 然后重启游戏 or 重启 lua 虚拟机
adb 命令
$ adb push E:/its/rummy_itc-v4/z_tempSave/lua /sdcard/Android/data/com.aaa.bbb/files
边栏推荐
猜你喜欢

阶乘因式分解

Groeb - "gramm, explicit and complete n -" gramm mask language model, implements the explicit n - "gramm semantic unit modeling knowledge.

【Translation】Device Manager—Intel NIC Properties Setting Advanced Options Function
![[PCL study notes] Commonly used libraries and APIs for point cloud processing (PCL library Eigen)](/img/b6/0f6113109aef776c777cb25a0ffb95.png)
[PCL study notes] Commonly used libraries and APIs for point cloud processing (PCL library Eigen)

js图片等分对比插件

HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界

Texture 】 【 terrain 】 【 virtual virtual terrain texture technology is introduced

(notes) Build the was configured to -- Settings repositories over project repositories but solutions

生物JC TRIM37防止凝集物组织的异位纺锤体极点的形成,以确保有丝分裂的保真度

js选择多张图片对比功能插件
随机推荐
Lanzhou Mencius Lightweight Pre-training Model Technical Practice
SSM整合案例分析(详解)
城堡跑酷js小游戏源码
LinkedList 5-141. The circular linked list
新建和编辑共用一个表单,编辑之后新建,form表单resetFields失效
Chicken and rabbit in the same cage
Review | Tech Talk activities based on Amazon KVS create intelligent visual products
[Network] Routing Routing Policy
一键搭建博客:如何使用WordPress插件搭建专属博客
什么时候使用UserCF,什么时候使用ItemCF?
自动化win训练脚本+日志
Swagger
tutorial/detailed_workflow.ipynb 量化金融Qlib库
可行性研究报告模板
Domino服务器SSL证书安装指南
蓝思科技发力整机组装业务,子公司拟30亿建智能终端设备智造项目
Interviewer: How does MySQL tune SQL statements based on execution plans?
如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然
Loadrunner与Jmeter区别与相同
TensorFlow Serving 高性能的机器学习模型服务系统