MCPcopy Create free account
hub / github.com/ThePhD/sol2 / my_next

Function my_next

examples/source/pairs_with_raw_functions.cpp:29–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27};
28
29int 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
52int my_pairs(lua_State* L) {
53 my_thing& mt = sol::stack::get<my_thing>(L, 1);

Callers

nothing calls this directly

Calls 2

pushFunction · 0.85
push_referenceFunction · 0.85

Tested by

no test coverage detected