I’m working from cocos2d-1.0.1-x-0.10.0
I’ve run in to some troubles when trying to call certain functions from lua, such as retain, release, retainCount etc.
I think the easiest way to show you the issue is by an example. I took the base HelloLua project and I replaced the hello.lua code with this:
local t = cocos2d.CCNode:new()
Creating a new node works.
Setting the rotation works.
Once we get to the t:retainCount() we can start seeing some issues. If you actually did a print of the retain count returned it would be something like 15 (it might be different for you). So I looked into a little bit deeper!
I put a break point in xcode on line 4935 in LuaCocos2d.cpp.
That line contains the casting calls to get the user type from the lua object passed from lua.
Looks like this:
@ cocos2d::CCObject* self = (cocos2d::CCObject**) tolua_tousertype;@
But if you step over that line and look a little bit closer at the**self* object you’ll see some strange things.
Here is a portion of the printout in gbd of the self object:
self 'cocos2d::CCNode' * 0x781de1c
cocos2d::SelectorProtocol 'cocos2d::SelectorProtocol' * 0x781de1c
cocos2d::CCObject 'cocos2d::CCObject' * 0x781de20
m_nZOrder int 0
m_fVertexZ float 0
m_fRotation float 0
m_fScaleX float 123
m_fScaleY float 1
You can see that the rotation has suddenly become 0, and the ScaleX somehow got the 123 value that used to be set in the rotation. Somehow all the values have been sort of “pushed down”. This really messes with the object and can also effect functions that can be called on the object. For instance if you also set a break point on when the retain or release is called through lua you will see that it doesn’t actually even go in to the proper CCObject::retain or CCObject::release functions.
Hopefully someone can figure this out because it’s really causing me issues. Thanks!