如何调试lua脚本

首先感谢下ZeroBrane Studio

这里拿cocos2dx/samples/Lua/HelloLua做例子来说明,其他的都是同样道理。

1、下载调试Lua所需的IDE,地址在这。有经济实力的请支持这个他们这款牛逼的开源软件。然后解压(我的目录是C:UsersailuDesktoperoBraneStudioEduPack-0.39-win32)。

2、开启调试服务器:运行zbstudio.exe->Project->Start Debug Server。如果你这是灰的说明已经开启了

3、选择项目目录:Project->Project Directory->Choose->选择samplesLuaHelloLuaResources

4、编辑hello.lua,如下

local function main()
    -- avoid memory leak
    collectgarbage("setpause", 100)
    collectgarbage("setstepmul", 5000)
     
    require('mobdebug').start()--插入这句话

    ……
    ……

5、把编译好的HelloLua.exe和一大堆的dll拷贝到samplesLuaHelloLuaResources

6、创建一个文本命名为debug.bat,并粘贴一下这段(ZBS请根据自己的解压目录重新设置),保存文件。

set ZBS=C:UsersailuDesktoperoBraneStudioEduPack-0.39-win32
set LUA_PATH=./?.lua;%ZBS%/lualibs/?/?.lua;%ZBS%/lualibs/?.lua
set LUA_CPATH=%ZBS%/bin/?.dll;%ZBS%/bin/clibs/?.dll
HelloLua.exe

7、双击debug.bat,然后自动会启动C:UsersailuDesktoperoBraneStudioEduPack-0.39-win32zbstudio.exe。如下图

8、插入断点然后喝啤酒去吧。

原文地址:https://www.cnblogs.com/mrblue/p/3431968.html