2

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...)

stschindler
  • 937
  • 7
  • 28

2 Answers2

3

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).

stschindler
  • 937
  • 7
  • 28
2

Perhaps the "unregistered class" is std::pair<const std::string, int>. Can you try registering that with Luabind and see if it works then?

John Zwinck
  • 239,568
  • 38
  • 324
  • 436