lua - Returning tables of objects from C++, adopt policy -


using luabind, create table of objects c++

luabind::object create_table(lua_state *l) {   luabind::object result = luabind::newtable(l);   int index = 1;   ( ... ) {     lua_object *o = new lua_object( ... );     result[ index ++ ] = o;   }   return result; } 

i register function as

module(l) [   def("create_table", &create_table) ] 

and lua_object as

class_<lua_object> reg("object"); reg   .def(constructor<float,float>())   ; module(l) [ reg ]; 

how can tell luabind take ownership of objects stored in table ( new lua_object( ... ) )? work around?

thanks -

replace

result[ index ++ ] = o 

with

result[ index ++ ] = luabind::object(l, o, luabind::adopt(luabind::result)); 

on side note, don't have register create_table raw(_1) policy?


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -