| 27 | }; |
| 28 | |
| 29 | int my_next(lua_State* L) { |
| 30 | // this gets called |
| 31 | // to start the first iteration, and every |
| 32 | // iteration there after |
| 33 | // the state you passed in pairs is argument 1 |
| 34 | // the key value is argument 2 |
| 35 | // we do not care about the key value here |
| 36 | lua_iterator_state& it_state |
| 37 | = sol::stack::get<sol::user<lua_iterator_state>>(L, 1); |
| 38 | auto& it = it_state.it; |
| 39 | if (it == it_state.last) { |
| 40 | return sol::stack::push(L, sol::lua_nil); |
| 41 | } |
| 42 | auto itderef = *it; |
| 43 | // 2 values are returned (pushed onto the stack): |
| 44 | // the key and the value |
| 45 | // the state is left alone |
| 46 | int pushed = sol::stack::push(L, itderef.first); |
| 47 | pushed += sol::stack::push_reference(L, itderef.second); |
| 48 | std::advance(it, 1); |
| 49 | return pushed; |
| 50 | } |
| 51 | |
| 52 | int my_pairs(lua_State* L) { |
| 53 | my_thing& mt = sol::stack::get<my_thing>(L, 1); |
nothing calls this directly
no test coverage detected