void LuaTableIterator::toNextElement() { auto ret = lua_next(_luaState, -2); _hasElement = ret != 0; if (_hasElement) { LuaValue key; key.setReference(UniqueLuaReference::create(_luaState, -2)); LuaValue value; value.setReference(UniqueLuaReference::create(_luaState, -1)); _currentVal = std::make_pair(key, value); // Remove value from stack lua_pop(_luaState, 1); } }
bool popValue(lua_State* luaState, LuaValue& target, int stackposition, bool remove) { if (!internal::isValidIndex(luaState, stackposition)) { return false; } target.setReference(UniqueLuaReference::create(luaState, stackposition)); if (remove) { lua_remove(luaState, stackposition); } return true; }