1. Compile vector. PKG
Class vector {tolua_template_bind (T, String, ccsprite *) // Add the container type void clear (); int size () Const; const T & operator [] (INT index) const; T & operator [] (INT index); void push_back (T Val); vector ();~ Vector ();};Ii. Generate the bound file and use the excerpt generated by tolua ++
... #ifdef __cplusplus tolua_cclass(tolua_S,"vector_CCSprite__","vector<CCSprite*>","",tolua_collect_vector_CCSprite__); #else tolua_cclass(tolua_S,"vector_CCSprite__","vector<CCSprite*>","",NULL); #endif tolua_beginmodule(tolua_S,"vector_CCSprite__"); tolua_function(tolua_S,"clear",tolua_Lottery_vector_CCSprite___clear00); tolua_function(tolua_S,"size",tolua_Lottery_vector_CCSprite___size00); tolua_function(tolua_S,".geti",tolua_Lottery_vector_CCSprite____geti00); tolua_function(tolua_S,".seti",tolua_Lottery_vector_CCSprite____seti00); tolua_function(tolua_S,".geti",tolua_Lottery_vector_CCSprite____geti01); tolua_function(tolua_S,"push_back",tolua_Lottery_vector_CCSprite___push_back00); tolua_function(tolua_S,"new",tolua_Lottery_vector_CCSprite___new00); tolua_function(tolua_S,"new_local",tolua_Lottery_vector_CCSprite___new00_local); tolua_function(tolua_S,".call",tolua_Lottery_vector_CCSprite___new00_local); tolua_function(tolua_S,"delete",tolua_Lottery_vector_CCSprite___delete00); tolua_endmodule(tolua_S); ...
3. Use in Lua
Local string_vector = vector_string _: new_local () string_vector: push_back ("hello") string_vector: push_back ("world") cclog (string_vector [0] .. "".. string_vector [1]) Local ccsprite_vector = vector_ccsprite __: new_local () // note that the pointer type is _ ccsprite_vector: push_back (ccsprite: Create ("image") ccsprite_vector: push_back (ccsprite: Create ("image "))
Lua uses a vector container