如何使用ZEROBRANE STUDIO远程调试COCOS2D-X的LUA脚本

http://www.cocos2d-x.org/docs/manual/framework/native/v2/lua/lua-remote-debug-via-zerobrane/zh

ZeroBrane Studio做为一个轻量级的Lua IDE,因为它支持跨平台(支持WindowsMacLinux)和支持真机调试(AndoridIPhoneIPad),所以经常被用来调试Lua。目前,Cocos2d-x通过集成LuaSocket也支持应用ZeroBrane Studio进行测试例的调试(Linux除外)。我们以HelloLua为例,详细描述如何使用ZeroBrane Studio进行iOS模拟器和Android真机的调试。

版本

  • Cocos2d-x Version 3.0 Beta2

iOS模拟器调试

测试环境
  • ZeroBrane Studio (0.39 for mac; MobDebug 0.542)
  • Mac OS X 10.9
  • Xcode 5.01

1.将ZeroBrane Studio.app/Contents/ZeroBraneStudio/lualibs/mobdebug/mobdebug.lua这个文件拷贝到cocos2d-x/samples/Lua/HelloLua/Resources目录下。这步过程在Cocos2d-x v3.0 Beta2及以上版本可以略过,引擎已经集成了这个文件。

2.用Xcode打开cocos2d-x/build/cocos2d_samples.xcodeproj之后,先把mobdebug.lua文件加入HelloLua工程,然后在HelloLua/Resources/hello.lua文件里面添加debugger调用的指令,仅需要插入require('mobdebug').start()一句,插入在require "hello2"行之前,如下:

local function main()
    ...
    require('mobdebug').start() --<-- only insert this line
    require "hello2"
    cclog("result is " .. myadd(1, 1))
    ...
end    

3.运行ZeroBrane Studio,点击界面从左上角的Project下面的...按钮, 然后选中cocos2d-x/samples/Lua/HelloLua/Resources目录,将HelloLua的Resources导入到Project下,如图所示:

importResource.png

4.打开hello.lua,鼠标点击行号右边的空白处加入断点:

insertBreakPoint.png

5.从ZeroBrane Studio的菜单栏开启Debugger Server:

startDebuggerServer.png

6.切换回XCode,运行HelloLua iOS测试例,触发断点(Windows环境下切换回Visual Studio 2012):

enterBreakPoint.png

7.通过debug工具栏,进行step in, step out, step over, continue等相应操作。此处需要注意,ZeroBrane有个地方比较奇怪,以local visibleSize = cc.Director:getInstance():getVisibleSize()这行函数为例,需要step over三次才能走到下一行函数,可能是因为此处有两个函数调用。

debugBar.png

8.点击View->Watch Window,打开Watch Window,添加要观察的变量:

watchWindow.png

watchValue.png

9.点击View->Stack Window,还可以看到相应的堆栈信息:

stackInfo.png

Android真机调试

测试环境
  • ZeroBrane Studio (0.39 for mac; MobDebug 0.542)
  • Android Developer Tools
  • HTC G17

Android(IPhoneIPad)真机调试的流程和iOS模拟器调试基本相同,主要的区别在于hello.lua中debugger调用的指令,如下:

local function main()
    ...
    require('mobdebug').start('192.168.1.110')
    require "hello2"
    cclog("result is " .. myadd(1, 1))
    ...
end

其中,192.168.1.110为PC的IP地址,测试手机的wifi IP需要与PC的IP地址同一网段,否则无法调试。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值