关键词:
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") end
-
editor 增加解析这个脚本, 显示出 按钮
-
点击按钮去执行对应的方法
-
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 按钮上去执行一个下载测试脚本, 并执行
gDebugWebFn
local 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
lua-调试技巧(代码片段)
title:lua-调试技巧categories:Luatags:[lua,调试,技巧]date:2022-07-1416:31:27comments:falsemathjax:truetoc:truelua-调试技巧前篇游戏lua脚本调试技巧,达到修改逻辑脚本后能实时生效执行,提高开发效率pc端editor模式新建一个测试代码脚本gDebugCustom=gD... 查看详情
lua-调试技巧(代码片段)
title:lua-调试技巧categories:Luatags:[lua,调试,技巧]date:2022-07-1416:31:27comments:falsemathjax:truetoc:truelua-调试技巧前篇游戏lua脚本调试技巧,达到修改逻辑脚本后能实时生效执行,提高开发效率pc端editor模式新建一个测试代码脚本gDebugCustom=gD... 查看详情
textchrome控制台调试技巧(代码片段)
textjavascript和jquery调试技巧(代码片段)
撰写c函数的技巧(代码片段)
第26章撰写C函数的技巧官方的API和辅助函数库都提供了一些帮助程序员如何写好C函数的机制。在这一章我们将讨论数组操纵、string处理、在C中存储Lua值等一些特殊的机制。26.1数组操作 Lua中数组实际上就是以特殊方式使用... 查看详情
javascript调试技巧(代码片段)
...ole.timeEnd()测试循环console.log()和console.dir()的区别阐述我们调试Javascript一般会用到Chrome和Firefox的控制台作为调试工具,本文列出了几条用于调试Javascript的技巧,掌握它们 查看详情
javascript调试技巧(代码片段)
...ole.timeEnd()测试循环console.log()和console.dir()的区别阐述我们调试Javascript一般会用到Chrome和Firefox的控制台作为调试工具,本文列出了几条用于调试Javascript的技巧,掌握它们 查看详情
实用调试技巧(代码片段)
调试技巧调试是什么?有多重要?一、调试的基本步骤二、Debug和Release的介绍。三、学会快捷键四、调试的时候查看程序当前信息五.实例实例一实例二六.如何写出好(易于调试)的代码示范注意七.编程常见错误... 查看详情
gdb调试基本技巧(代码片段)
1 说明本文主要介绍一些简单的、常用的gdb调试技巧。环境:GNUgdb(GDB)RedHatEnterpriseLinux(7.2-60.el6_4.1)参考文档:《gdb调试技巧》 作者不详2 测试代码1#include<stdio.h>23inttest_func2(void)45inta=1;6intb=2;78returna+b;91011v 查看详情
dockerdebug调试技巧(代码片段)
『重用』容器名但我们在编写/调试Dockerfile的时候我们经常会重复之前的command,比如这种dockerrun--namejstorm-zookeeperzookeeper:3.4,然后就容器名就冲突了。$dockerrun--namejstorm-zookeeperzookeeper:3.4...$dockerrun--namejstorm-zookeeperzookeep 查看详情
markdown调试扫描仪的一些技巧(代码片段)
继续分享5个实用的vs调试技巧(代码片段)
继续分享5个实用的vs调试技巧原总结调试vs2019vs前言我在上一篇文章《5个非常实用的vs调试技巧》中分享了5个我认为非常值得了解的vs调试技巧,本周继续分享5个很基础但同样实用的调试技巧。1.条件断点作用简介:顾名思义,... 查看详情
lua从青铜到王者基础篇第十三篇:lua调试(debug)(代码片段)
系列文章目录文章目录系列文章目录前言🌲一、Lua调试(Debug)🌳二、另一个实例🌴三、调试类型💬🌲🌳🌴🌵总结前言🌲一、Lua调试(Debug)Lua提供了debug库用于提供创建我们自定义调试器的功... 查看详情
快速掌握lua5.3——编写提供给lua使用的c库函数的技巧(代码片段)
Q:如何在C库函数中灵活的操作Lua的”table”?A:--[[voidlua_settable(lua_State*L,intindex);从虚拟栈中"index"处获得"table",栈顶获得"value",栈顶下面一个元素获得"key"。相当于在Lua环境中 查看详情
#前端浏览器调试工具使用技巧(代码片段)
前端浏览器调试工具使用技巧文章目录前端浏览器调试工具使用技巧调试hover后出现的元素方法一方法二JS断点调试debugger方式直接在调试窗口打断点浏览器快捷键Console使用Overrids使用本地Js替换服务上的JsF12ctrl+shift+p调出命... 查看详情
chrome调试技巧(代码片段)
写在前面本文包括浏览器调试,不包括web移动端调试。本文调试均在chrome浏览器进行alert这个不用多说了,不言自明console基本输出想必大家都在用console.log在控制台输出点东西,其实console还有其它的方法:console.log("打印字符串")... 查看详情
你可能不知道的14个javascript调试技巧(代码片段)
以更快的速度和更高的效率调试你的JavaScript了解你的工具可以在完成任务的过程中发挥重大作用。尽管传言JavaScript难以调试,但是如果你掌握了一些调试技巧,那么你将会花费更少的时间来解决这些错误。我们已经列出了14个... 查看详情
c语言调试小技巧(代码片段)
经常看到有人介绍一些IDE或者像gdb这样的调试器的很高级的调试功能,也听人说过有些牛人做工程的时候就用printf来调试,不用特殊的调试器。特别是在代码经过编译器一些比较复杂的优化后,会变得“难以辨认”,使用调试器... 查看详情