OK I tried a few things and learned a few things.
First, the odd thing is, walking down about 3 levels of nodes, it’s only the last level where I start to get “method-less objects”. Not the earlier ones.
So in the node walking, I added some casts to CCNode, that got me through there. No more dying on getting the last child.
Of course, when my code then tries to set the color on the resulting object, it fails with missing setColor method. So I added a cast to CCSprite.
And that works. But why?
I am guessing, that the wrapper objects have their derived identity, and stick around as long as they are referenced in Lua. And that even if I get them through another interface (that is just an array of objects), I get the “derived” wrapped object. But then if they aren’t referenced, they might (or might not be garbage collected, and later when I get them through the array-of-objects interface, I only get the “base” wrapped object, not the full “derived” one.
Does that sound right? Is that how tolua works? (I’ve used SWIG but not tolua.)
So how heavyweight are these wrapper objects? Derived vs. base? At this point, I’m doing a lot of making child arrays, getting element, casting, and so on to walk down a path of nodes to get a child sprite. It’s starting to tingle my garbage-collection spider sense. I’m wondering if I shouldn’t just use closures or maybe store an additional reference in some other objects so I don’t have to look them up. (I was hoping lookups would avoid extra storage.)
How do people normally walk down a tree of nodes, in Lua, to get a specific one? (Say fourth child of first child of third child of a node?)