new table.for_each while iterators get sorted out

This commit is contained in:
ThePhD 2015-05-15 12:41:45 -04:00
parent bd4492b85b
commit 542d2a813e
3 changed files with 15 additions and 2 deletions

View File

@ -74,7 +74,7 @@ public:
}
operator function() const {
return get<function>();
return get<function>();
}
operator std::string() const {

View File

@ -92,4 +92,4 @@ public:
};
} // sol
#endif // SOL_REFERENCE_HPP
#endif // SOL_REFERENCE_HPP

View File

@ -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);