Search code examples
c++lualuabind

Luabind: return_stl_iterator for std::map


Is there any way to return an STL iterator to a std::map (e.g. std::map<const std::string, int>)?

Luabind definition for an example class:

class_<SomeClass>( "SomeClass" )
  .property( "items", &SomeClass::GetItems, return_stl_iterator )

GetItems() returns a const reference to a std::map container.

When accessing it in Lua like this:

for item in some_class.items do
  ...
end

Luabind throws a std::runtime_error saying "Trying to use unregistered class". Is iterating over std::maps not possible? (the documentation says that all containers having begin() and end() work...)


Solution

  • After browsing the source code I discovered that the Luabind return_stl_iterator policy only supports iterators that reference the wanted datatype directly. Iterators for associative containers are not supported (first and second are never accessed).