/** Go to the next entry in the table. \return Returns true if the iteration is done. **/ bool LuaStackTableIterator::Next() { // This function is only active if Reset() has been called head. luaplus_assert( IsValid() ); // This is a local helper variable so we don't waste space in the class // definition. LuaState* state = m_tableObj.GetState(); // Do any stack management operations. if ( m_autoStackManagement ) { state->SetTop( m_startStackIndex + 1 ); } else { // If this luaplus_assert fires, then you left something on the stack. luaplus_assert( state->GetTop() == m_startStackIndex + 1 ); } // Do the Lua table iteration. if ( state->Next( m_tableObj ) == 0 ) { // Invalidate the iterator. m_startStackIndex = -1; return false; } // The iterator is still valid. return true; }
/** Start iteration at the beginning of the table. **/ void LuaStackTableIterator::Reset() { // Start afresh... LuaState* state = m_tableObj.GetState(); m_startStackIndex = state->GetTop(); // Push the head stack entry. state->PushNil(); // Start the iteration. If the return value is 0, then the iterator // will be invalid. if ( state->Next( m_tableObj ) == 0 ) m_startStackIndex = -1; }