From 3357b0a0ecc4d36ccd3c2668e9d55aaaefedf4df Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 30 Dec 2011 23:15:31 -0700 Subject: All variants of for each loop are tested and work --- src/gamestate.cpp | 18 ++++++++++++++---- src/variable.cpp | 5 +++++ src/variable.h | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 4af49aa..dcae848 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -428,8 +428,6 @@ void GameState::parse( const AstBranch::NodeList &lCode ) Variable y = popDeref(); Variable x = pop(); deref( x ) += y; -// VariableRef r = x.getVariableRef(); -// setVariable( r.sName, getVariable( r.sName, r.sid ) + y, r.sid ); } break; @@ -438,8 +436,6 @@ void GameState::parse( const AstBranch::NodeList &lCode ) Variable y = popDeref(); Variable x = pop(); deref( x ) -= y; -// VariableRef r = x.getVariableRef(); -// setVariable( r.sName, getVariable( r.sName, r.sid ) - y, r.sid ); } break; @@ -618,6 +614,20 @@ void GameState::parse( const AstBranch::NodeList &lCode ) parse( rDo ); } } + else if( vIn.getType() == Variable::tList ) + { + if( bUseKey ) + { + throw Bu::ExceptionBase("You cannot use key:value pairs as iterators in a for each loop iterating over a list."); + } + const Variable::VariableList &rList = vIn.getList(); + for( Variable::VariableList::const_iterator i = + rList.begin(); i; i++ ) + { + setVariable( vrValue.sName, *i, vrValue.sid ); + parse( rDo ); + } + } } break; diff --git a/src/variable.cpp b/src/variable.cpp index 0ce9793..5296848 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -113,6 +113,11 @@ Variable *Variable::getVariablePtr() const return pValue; } +const Variable::VariableList &Variable::getList() const +{ + return *lValue; +} + const Variable::VariableHash &Variable::getHash() const { return *hValue; diff --git a/src/variable.h b/src/variable.h index 22a1b26..8741b28 100644 --- a/src/variable.h +++ b/src/variable.h @@ -61,6 +61,7 @@ public: Bu::String getString() const; VariableRef getVariableRef() const; Variable *getVariablePtr() const; + const VariableList &getList() const; const VariableHash &getHash() const; Variable to( Type e ) const; -- cgit v1.2.3