首页 技术 正文
技术 2022年11月20日
0 收藏 791 点赞 2,400 浏览 2758 个字
cocos2dx tolua传递参数分析:
tolua_Cocos2d_CCNode_addChild00 == void CCNode::addChild(CCNode *child)
tolua_Cocos2d_CCNode_addChild01 == void CCNode::addChild(CCNode *child, int zOrder)
tolua_Cocos2d_CCNode_addChild02 == void CCNode::addChild(CCNode *child, int zOrder, int tag)上面是使用tolua把C++转到lua。上面三个分别相应不同的參数个数。我们这里分析一下最后一个:
/* method: addChild of class CCNode */
#ifndef TOLUA_DISABLE_tolua_Cocos2d_CCNode_addChild02
static int tolua_Cocos2d_CCNode_addChild02(lua_State* tolua_S)
{
tolua_Error tolua_err;
//这里推断參数是否合法,仅仅能推断參数类型是否合法。假设參数类型检查不通过,就会报错
if (
!tolua_isusertype(tolua_S,1,"CCNode",0,&tolua_err) ||
!tolua_isusertype(tolua_S,2,"CCNode",0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnumber(tolua_S,4,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,5,&tolua_err)
)
goto tolua_lerror;
else
{
//比如:middleBg:addChild(testSprite, Z_ORDER_1, 200)
//我们传递进来的參数和以下的一一相应
//这里能够清楚的看到传入參数的次序,第一是middleBg ...
CCNode* self = (CCNode*) tolua_tousertype(tolua_S,1,0); -- middleBg -- 1
CCNode* child = ((CCNode*) tolua_tousertype(tolua_S,2,0)); -- testSprite -- 2
int zOrder = ((int) tolua_tonumber(tolua_S,3,0)); -- Z_ORDER_1 -- 3
int tag = ((int) tolua_tonumber(tolua_S,4,0)); -- 200 -- 4
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'addChild'", NULL);
#endif
{
//这里就把testSprite加到了middleBg
self->addChild(child,zOrder,tag);
}
}
return 0;
tolua_lerror:
return tolua_Cocos2d_CCNode_addChild01(tolua_S);
}
#endif //#ifndef TOLUA_DISABLE样例:
//middleBg:addChild(testSprite, Z_ORDER_1, 200) 在传递參数中,我们没有对Z_ORDER_1赋值,即为nil,则就
//出现了以下的错误。看下这里argument #3 ,表明是第三个參数错误,而这里我们明明是第二个參数。看下上面的分析
//我想大家应该明确了。通过这样的方法,我们以后查找这类问题。就会方便非常多。03-31 10:09:50.499: D/cocos2d-x debug info(3169): LUA ERROR: [string "xxxxxxxxxxxxx..."]:171: error in function 'addChild'.
03-31 10:09:50.499: D/cocos2d-x debug info(3169): argument #3 is 'nil'; '[no object]' expected.
03-31 10:09:50.499: D/cocos2d-x debug info(3169): stack traceback:
03-31 10:09:50.499: D/cocos2d-x debug info(3169): [C]: in function 'addChild'
03-31 10:09:50.499: D/cocos2d-x debug info(3169): [string "xxxxxxxxxxxxx..."]:171: in function 'initMiddle'
03-31 10:09:50.499: D/cocos2d-x debug info(3169): [string "xxxxxxxxxxxxx..."]:35: in function 'initUI'
03-31 10:09:50.499: D/cocos2d-x debug info(3169): [string "xxxxxxxxxxxxx..."]:27: in function 'ctor'
03-31 10:09:50.499: D/cocos2d-x debug info(3169): [string "xxxxxxxxxxxxx"]:34: in function 'create'
03-31 10:09:50.499: D/cocos2d-x debug info(3169): [string "xxxxxxxxxxxxx"]:38: in function 'new'
03-31 10:09:50.499: D/cocos2d-x debug info(3169): [string "xxxxxxxxxxxxx"]:44: in function 'pushScene'
03-31 10:09:50.499: D/cocos2d-x debug info(3169): [string "xxxxxxxxxxxxx"]:309: in function 'callBack'
03-31 10:09:50.499: D/cocos2d-x debug info(3169): [string "xxxxxxxxxxxxx"]:653: in function <[string "xxxxxxxxxxxxx"]:651>

版权声明:原创文章,转载请注明出处。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,964
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781