Luabind:std::map 的 return_stl_iterator
有没有办法将STL迭代器返回到std::map(例如std::map
示例类的 Luabind 定义:
class_<SomeClass>( "SomeClass" )
.property( "items", &SomeClass::GetItems, return_stl_iterator )
GetItems()
返回对 std::map
容器的 const 引用。
当像这样在 Lua 中访问它时:
for item in some_class.items do
...
end
Luabind 抛出一个 std::runtime_error 说“尝试使用未注册的类”。迭代 std::map
是不可能的吗? (文档说所有具有 begin()
和 end()
的容器都可以工作...)
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::map
s not possible? (the documentation says that all containers having begin()
and end()
work...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览源代码后,我发现 Luabind return_stl_iterator 策略仅支持直接引用所需数据类型的迭代器。不支持关联容器的迭代器(永远不会访问
first
和second
)。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
andsecond
are never accessed).也许“未注册的类”是
std::pair
。你可以尝试用 Luabind 注册一下看看它是否有效吗?Perhaps the "unregistered class" is
std::pair<const std::string, int>
. Can you try registering that with Luabind and see if it works then?