I want to use CCArray to pass array of objects between lua and c**.
Unfortunately, when I add objects to CCArray in Lua, they are unusable afterwards.
Simple test:
<pre>
local arr = cocos2d.CCArray:array
for i = 1, 10 do
local test1 = ogs.OGSScrollTableEntry:newEntry — <- this is just a CCNode with few additional methods
local spriteTest1 = cocos2d.CCSprite:spriteWithFile
spriteTest1:setPosition)
spriteTest1:setTag
test1:setPosition)
test1:addChild
arr:insertObject
end
local testObj = arr:objectAtIndex
cocos2d.CCLuaLog)
cocos2d.CCLuaLog.x) — <- attempt to call method ‘getPosition’
cocos2d.CCLuaLog))
</pre>

I’ve tried to just pass the array to c** and deal with it there, but I get the same error.
After I cast the object from array to OGSScollTableEntry I cannot use any of the CCNode methods.

What’s wrong?

How can I pass an array of objects from Lua to c++?

My current workaround is to create CCArray when instantiating object and adding entries one by one from Lua. It works this way.

While you get object from CCArray, what function objectAtIndex returned is CCObject, you should cast it to the very type.

local testObj = tolua.cast(arr:objectAtIndex(1), “CCNode”) — cast it to CCNode, or other type you want
local x, y = testObj:getPosition() — getPosition returned two number - x and y
CCLuaLog(" pos:“…x…”,"…y)