From 542d2a813e4f659ae9e881fa95ed5427b36342ba Mon Sep 17 00:00:00 2001 From: ThePhD Date: Fri, 15 May 2015 12:41:45 -0400 Subject: [PATCH] new table.for_each while iterators get sorted out --- sol/proxy.hpp | 2 +- sol/reference.hpp | 2 +- sol/table.hpp | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/sol/proxy.hpp b/sol/proxy.hpp index 4c46804b..47d9b0cb 100644 --- a/sol/proxy.hpp +++ b/sol/proxy.hpp @@ -74,7 +74,7 @@ public: } operator function() const { - return get(); + return get(); } operator std::string() const { diff --git a/sol/reference.hpp b/sol/reference.hpp index 6e081e5c..0f2f786e 100644 --- a/sol/reference.hpp +++ b/sol/reference.hpp @@ -92,4 +92,4 @@ public: }; } // sol -#endif // SOL_REFERENCE_HPP +#endif // SOL_REFERENCE_HPP diff --git a/sol/table.hpp b/sol/table.hpp index 6a4967d6..daef8ebf 100644 --- a/sol/table.hpp +++ b/sol/table.hpp @@ -98,6 +98,19 @@ public: return *this; } + template + 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);