Here's a helper function I use to get a script array from an application-registered type which returns an std::vector:
engine->RegisterObjectMethod("MyScene", "array<MySprite@>@ FindSprites(const string& in) const", asFUNCTION(FindSprites), asCALL_CDECL_OBJLAST);
CScriptArray* FindSprites(const std::string& name, MyScene* scene)
{
std::vector<MySprite*> sprites = scene->FindSprites(name);
asIObjectType* objectType = MyWrapper_GetEngineObjectTypeFromDecl("array<MySprite@>");
CScriptArray* scriptArray = CScriptArray::Create(objectType, sprites.size());
for (uint i = 0; i < sprites.size(); ++i)
{
void* ptr = sprites[i];
scriptArray->SetValue(i, &ptr);
}
return scriptArray; // don't delete array because script will now have a refcount of 1 to it, and will take care of the memory from here
}
And here's one which lets you give a script array, yet pass that to an application-registered type which expects a vector:
engine->RegisterObjectMethod("MySprite", "void SetOffsets(const array<MyVec2> &in)", asFUNCTION(SetOffsets), asCALL_CDECL_OBJLAST);
void SetOffsets(CScriptArray& offsets, MySprite* sprite)
{
const uint arraySize = offsets.GetSize();
std::vector<MyVec2> offsets(arraySize);
for (uint arrayIdx = 0; arrayIdx < arraySize; ++arrayIdx)
{
const MyVec2* pos = static_cast<const MyVec2*>(offsets.At(arrayIdx));
offsets[arrayIdx].Set( *pos );
}
sprite->SetOffsets(offsets);
}