CCMutableArray<CCStringToStringDictionary*>* casting

CCMutableArray<CCStringToStringDictionary*>* casting
0.0 0


Working with the latest cocos2d-x.

I have a class with a .pkg file that returns an array of type CCMutableArray<CCStringToStringDictionary*>*
CCMutableArray<CCStringToStringDictionary*>* getMyArray()

But when I use that in lua the returned object doesn’t get all the normal CCMutableArray functions like count(). I’m forced to cast the returned object using tolua.cast.

I saw in CCMutablArray.pkg there is a TOLUA_TEMPLATE_BIND, which lists CCObject**, CCSpriteFrame**, CCFiniteTimeAction* only. So I added in CCStringToStringDictionary* there and rebuilt the lua pkgs.

The problem is that the function getObjectAtIndex() for my array is now returning a number instead of an object!

For example:
local myArray = foo:getMyArray() print("count", myArray:count()) -- prints "56", good! print("object", myArrag:getObjectAtIndex(0)) -- print "0" as a number value, bad!
I know that the objects in myArray are CCStringToStringDictionary* objects, so when I print it out I should be getting user data.

With the exact same code as above, but adding in a cast to CCMutableArray<CCObject*>, it will work.
local myArray = foo:getMyArray() print("count", myArray:count()) -- prints "56", good! myArray = tolua.cast(myarray, "CCMutableArray<CCObject*>") print("object", myArrag:getObjectAtIndex(0)) -- prints "userdata: 0x0ece5308", good!

BUT! If I try casting to CCMutableArray<CCStringToStringDictionary*> instead, it prints “0” like in the first example.


I’ve had a similar problem. I ended up changing the function that returns the array to:

CCMutableArray<CCMutableDictionary<std::string, CCString*>> getMyArray();

And then at the top of CCMutableArray.pkg:

TOLUA_TEMPLATE_BIND(T, CCObject**, CCSpriteFrame**, CCFiniteTimeAction**, CCMutableDictionary<std::string, CCString*>**)

So basically replacing the CCStringToStringDictionary typedef with the original type.

Then in CCMutableDictionary.pkg I changed the top to:

TOLUA_TEMPLATE_BIND(K V, std::string CCObject**, std::string CCString**)

That works for me.