Ok, so I dug a bit more into the tolua code integration. The issue are the lines:
cocos2d::CCMutableArray* tolua_ret = (cocos2d::CCMutableArray*) self->getChildren();
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cocos2d::CCMutableArray");
in
/* method: getChildren of class cocos2d::CCNode */
#ifndef TOLUA_DISABLE_tolua_Cocos2d_cocos2d_CCNode_getChildren00
static int tolua_Cocos2d_cocos2d_CCNode_getChildren00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cocos2d::CCNode",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cocos2d::CCNode* self = (cocos2d::CCNode*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'getChildren'", NULL);
#endif
{
cocos2d::CCMutableArray* tolua_ret = (cocos2d::CCMutableArray*) self->getChildren();
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cocos2d::CCMutableArray");
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'getChildren'.",&tolua_err);
return 0;
#endif
}
It declares the result of getChildren as “cocos2d::CCMutableArray<CCNode*>” but that type isn’t registered with tolua
Only CCMutableArray_CCObject*_ and CCMutableArray_CCSpriteFrame*_ are registered
So we need to add the CCMutableArray’s classes for other object types…
I also tried changing the getChildren() line to this
cocos2d::CCMutableArray* tolua_ret = (cocos2d::CCMutableArray*) self->getChildren();
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cocos2d::CCMutableArray");
and then doing something like this in the code
children = self.cc.__CCNode__:getChildren()
print("children")
print(children:count())
for i=0,children:count()-1,1 do
local object = children:getObjectAtIndex(i)
print(tolua.type(object))
obj2 = tolua.cast(object, 'cocos2d::CCNode')
print(tolua.type(obj2))
print(obj2:getPosition().x)
end
but then I get a EXC_BAD_ACCESS error when running getPosition() so I think tolua.cast is probably causing some problems…