博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cocos2dx tolua传递参数分析
阅读量:4217 次
发布时间:2019-05-26

本文共 2927 字,大约阅读时间需要 9 分钟。

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_addChild02static 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>

转载地址:http://yxsmi.baihongyu.com/

你可能感兴趣的文章
Python学习笔记——爬虫之Scrapy框架
查看>>
Python学习笔记——爬虫之Scrapy项目实战
查看>>
Python学习笔记——爬虫之通过Fiddler进行手机抓包
查看>>
Python学习笔记——爬虫之Scrapy-Redis分布式组件
查看>>
Python学习笔记——爬虫之Scrapy-Redis实战
查看>>
Python学习笔记——大数据之Spark简介与环境搭建
查看>>
Python学习笔记——大数据之SPARK核心
查看>>
Python学习笔记——大数据之Pyspark与notebook使用matplotlib
查看>>
Python学习笔记——云计算
查看>>
Python学习笔记——运维和Shell
查看>>
Python学习笔记——nginx
查看>>
Python学习笔记——自动化部署
查看>>
Python学习笔记——多任务-协程
查看>>
Python学习笔记——WSGI、mini-web框架
查看>>
Python学习笔记——闭包、装饰器
查看>>
Python学习笔记——mini-web框架 添加路由、MySQL功能
查看>>
Python学习笔记——mini-web框架 添加log日志、路由支持正则
查看>>
Python学习笔记——元类、实现ORM
查看>>
Python学习笔记——Celery
查看>>
Python学习笔记——数据分析之Matplotlib绘图
查看>>