nngn
|
Table iteration. More...
Go to the source code of this file.
Classes | |
class | nngn::lua::detail::table_iter_base< CRTP, T > |
CRTP base for table iterators. More... | |
class | nngn::lua::detail::table_iter< T > |
lua_next -based table iterator. More... | |
class | nngn::lua::detail::table_seq_iter< T > |
ipairs -style table iterator. More... | |
Namespaces | |
namespace | nngn |
namespace | nngn::lua |
namespace | nngn::lua::detail |
Functions | |
template<typename CRTP , typename T > | |
bool | nngn::lua::detail::operator== (const table_iter_base< CRTP, T > &lhs, const table_iter_base< CRTP, T > &rhs) |
template<typename T > | |
auto | nngn::lua::ipairs (const T &table) |
Simple wrapper for a table value, returns ipairs -style iterators. | |
Table iteration.
Basic input iterators are available for very simple table iteration. Since it uses the Lua stack, this is only suitable for simple range for
loops which do not leave values on the stack at the end of each iteration (or other cases, if you know what you are doing). The objects on the stack are automatically managed by the iterators and should not be moved. Their scope is limited to the for
loop (or similar construct), (stack) references held after it will dangle.
The stack positions above the key/value can be manipulated freely inside the loop body, including before the iterators are dereferenced. In particular, nested iteration is supported.
Example lua_next
-based iteration:
Example ipairs
-style iteration:
Nested example: