41#ifndef NNGN_LUA_ITER_H
42#define NNGN_LUA_ITER_H
52template<
typename CRTP,
typename T>
54 const table_iter_base<CRTP, T> &lhs,
55 const table_iter_base<CRTP, T> &rhs);
58template<
typename CRTP,
typename T>
59class table_iter_base : std::input_iterator_tag {
70 CRTP &
pre_inc(
void) {
return static_cast<CRTP&
>(++(*this)); }
71 CRTP
post_inc(
void) {
return static_cast<CRTP&
>((*this)++); }
110template<
typename CRTP,
typename T>
112 return static_cast<CRTP*
>(
this)->
next();
115template<
typename CRTP,
typename T>
117 auto ret =
static_cast<CRTP
>(*this);
126 lua.push(std::tuple{
nil,
nil});
133 assert(this->key_idx == lua.top() - 1);
136 this->
table =
nullptr;
143 return {{lua, this->key_idx}, {lua, this->key_idx + 1}};
157 assert(this->value_idx == lua.top());
159 if(lua.push((*this->table)[++this->i]).is_nil()) {
161 this->
table =
nullptr;
169 return {this->
i, {lua, this->value_idx}};
172template<
typename CRTP,
typename T>
177 return lhs.table == rhs.table;
180template<
typename CRTP>
182 return {
static_cast<const CRTP*
>(
this)};
185template<
typename CRTP>
187 return {
static_cast<const CRTP*
>(
this)};
190template<
typename CRTP>
195template<
typename CRTP>
200static_assert(std::input_iterator<table_iter<table_view>>);
201static_assert(std::input_iterator<table_seq_iter<table_view>>);
229 auto begin(
void)
const {
return this->t.ibegin(); }
230 auto end(
void)
const {
return this->t.iend(); }
table_seq_iter< const CRTP > iend(void) const
Sentinel for ibegin.
Definition iter.h:196
table_iter< const CRTP > begin(void) const
lua_next-based iteration.
Definition iter.h:181
table_seq_iter< const CRTP > ibegin(void) const
ipairs-style iteration.
Definition iter.h:186
table_iter< const CRTP > end(void) const
Sentinel for begin.
Definition iter.h:191
CRTP base for table iterators.
Definition lua.h:169
CRTP post_inc(void)
Definition iter.h:71
CRTP & pre_inc(void)
Definition iter.h:70
table_iter_base & operator++(void)
Definition iter.h:111
friend bool operator==(const table_iter_base &lhs, const table_iter_base &rhs)
Definition iter.h:173
std::ptrdiff_t difference_type
Definition iter.h:61
table_iter_base(void)=default
table_iter_base operator++(int)
Definition iter.h:116
table_iter_base(T *table_)
Definition iter.h:63
lua_next-based table iterator.
Definition lua.h:170
table_iter & next(void)
Definition iter.h:131
table_iter operator++(int)
Definition iter.h:85
table_iter & operator++(void)
Definition iter.h:84
value_type operator*(void) const
Definition iter.h:141
int key_idx
Definition iter.h:89
friend base
Definition iter.h:87
std::pair< value_view, value_view > value_type
Definition iter.h:81
table_iter(T *table)
Definition iter.h:123
ipairs-style table iterator.
Definition lua.h:171
friend base
Definition iter.h:104
int value_idx
Definition iter.h:107
std::pair< lua_Integer, value_view > value_type
Definition iter.h:98
table_seq_iter & operator++(void)
Definition iter.h:101
table_seq_iter operator++(int)
Definition iter.h:102
lua_Integer i
Definition iter.h:106
table_seq_iter(T *table)
Definition iter.h:147
table_seq_iter & next(void)
Definition iter.h:155
value_type operator*(void) const
Definition iter.h:167
T push(auto &&x) const
Pushes a value onto the stack.
Definition state.h:235
int top(void) const
Definition state.h:109
int index(void) const
Lua stack index.
Definition value.h:28
state_view state(void) const
Definition value.h:24
assert
Definition debug.lua:3
function DEMO text end
Definition demo0.lua:6
map next
Definition demo1.lua:80
for i
Definition font.lua:5
bool operator==(const table_iter_base< CRTP, T > &lhs, const table_iter_base< CRTP, T > &rhs)
Definition iter.h:173
Definition lua_audio.cpp:19
constexpr struct nngn::lua::nil_type nil
auto ipairs(const T &table)
Simple wrapper for a table value, returns ipairs-style iterators.
Definition iter.h:227
constexpr const R * begin(const T< R > &v)
Definition vec.h:207
Owning reference to a table on the stack, popped when destroyed.
Definition table.h:172
Operations on table values.