mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
new table.for_each while iterators get sorted out
This commit is contained in:
parent
bd4492b85b
commit
542d2a813e
|
@ -74,7 +74,7 @@ public:
|
|||
}
|
||||
|
||||
operator function() const {
|
||||
return get<function>();
|
||||
return get<function>();
|
||||
}
|
||||
|
||||
operator std::string() const {
|
||||
|
|
|
@ -92,4 +92,4 @@ public:
|
|||
};
|
||||
} // sol
|
||||
|
||||
#endif // SOL_REFERENCE_HPP
|
||||
#endif // SOL_REFERENCE_HPP
|
||||
|
|
|
@ -98,6 +98,19 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
template<typename Fx>
|
||||
void for_each(Fx&& fx) const {
|
||||
push();
|
||||
stack::push(state(), nil);
|
||||
while (lua_next(this->state(), -2)) {
|
||||
sol::object key(state(), -2);
|
||||
sol::object value(state(), -1);
|
||||
fx(key, value);
|
||||
lua_pop(state(), 1);
|
||||
}
|
||||
pop();
|
||||
}
|
||||
|
||||
size_t size() const {
|
||||
push();
|
||||
return lua_rawlen(state(), -1);
|
||||
|
|
Loading…
Reference in New Issue
Block a user