diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2011-12-30 23:07:59 -0700 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2011-12-30 23:07:59 -0700 |
| commit | 70076bb00bdedb57405ed2ef27e2fec172e2f38a (patch) | |
| tree | 4339853d972427b02bb4d51a88bcb665ba61307a /src | |
| parent | 8bcb83035607371a2326374665e9cc56c662a783 (diff) | |
| download | stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.tar.gz stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.tar.bz2 stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.tar.xz stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.zip | |
Well, +=, -= on dictionaries/lists works now.
Diffstat (limited to 'src')
| -rw-r--r-- | src/functiondisplay.cpp | 8 | ||||
| -rw-r--r-- | src/gamestate.cpp | 10 | ||||
| -rw-r--r-- | src/variable.cpp | 71 |
3 files changed, 81 insertions, 8 deletions
diff --git a/src/functiondisplay.cpp b/src/functiondisplay.cpp index 4790844..ab37a08 100644 --- a/src/functiondisplay.cpp +++ b/src/functiondisplay.cpp | |||
| @@ -15,10 +15,12 @@ FunctionDisplay::~FunctionDisplay() | |||
| 15 | 15 | ||
| 16 | void FunctionDisplay::call( class GameState &gState ) | 16 | void FunctionDisplay::call( class GameState &gState ) |
| 17 | { | 17 | { |
| 18 | Bu::String s = gState.popDeref().to( Variable::tString ).getString(); | 18 | // Bu::String s = gState.popDeref().to( Variable::tString ).getString(); |
| 19 | 19 | ||
| 20 | sio << format( s ) << sio.nl; | 20 | // sio << format( s ) << sio.nl; |
| 21 | // sio << "Display: " << v << sio.nl; | 21 | |
| 22 | Variable v = gState.popDeref(); | ||
| 23 | sio << "Display: " << v << sio.nl; | ||
| 22 | } | 24 | } |
| 23 | 25 | ||
| 24 | Bu::String FunctionDisplay::format( const Bu::String &sSrc ) | 26 | Bu::String FunctionDisplay::format( const Bu::String &sSrc ) |
diff --git a/src/gamestate.cpp b/src/gamestate.cpp index bd3e638..4af49aa 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp | |||
| @@ -427,8 +427,9 @@ void GameState::parse( const AstBranch::NodeList &lCode ) | |||
| 427 | { | 427 | { |
| 428 | Variable y = popDeref(); | 428 | Variable y = popDeref(); |
| 429 | Variable x = pop(); | 429 | Variable x = pop(); |
| 430 | VariableRef r = x.getVariableRef(); | 430 | deref( x ) += y; |
| 431 | setVariable( r.sName, getVariable( r.sName, r.sid ) + y, r.sid ); | 431 | // VariableRef r = x.getVariableRef(); |
| 432 | // setVariable( r.sName, getVariable( r.sName, r.sid ) + y, r.sid ); | ||
| 432 | } | 433 | } |
| 433 | break; | 434 | break; |
| 434 | 435 | ||
| @@ -436,8 +437,9 @@ void GameState::parse( const AstBranch::NodeList &lCode ) | |||
| 436 | { | 437 | { |
| 437 | Variable y = popDeref(); | 438 | Variable y = popDeref(); |
| 438 | Variable x = pop(); | 439 | Variable x = pop(); |
| 439 | VariableRef r = x.getVariableRef(); | 440 | deref( x ) -= y; |
| 440 | setVariable( r.sName, getVariable( r.sName, r.sid ) - y, r.sid ); | 441 | // VariableRef r = x.getVariableRef(); |
| 442 | // setVariable( r.sName, getVariable( r.sName, r.sid ) - y, r.sid ); | ||
| 441 | } | 443 | } |
| 442 | break; | 444 | break; |
| 443 | 445 | ||
diff --git a/src/variable.cpp b/src/variable.cpp index 1100c84..0ce9793 100644 --- a/src/variable.cpp +++ b/src/variable.cpp | |||
| @@ -363,8 +363,77 @@ Variable &Variable::operator+=( const Variable &rhs ) | |||
| 363 | return *this; | 363 | return *this; |
| 364 | } | 364 | } |
| 365 | 365 | ||
| 366 | Variable &Variable::operator-=( const Variable &rhs ) | ||
| 367 | { | ||
| 368 | switch( eType ) | ||
| 369 | { | ||
| 370 | case tNull: | ||
| 371 | throw VariableException("You cannot subtract nulls."); | ||
| 372 | |||
| 373 | case tBool: | ||
| 374 | throw VariableException("You cannot subtract bools."); | ||
| 375 | |||
| 376 | case tInt: | ||
| 377 | switch( rhs.eType ) | ||
| 378 | { | ||
| 379 | case tInt: | ||
| 380 | iValue -= rhs.iValue; | ||
| 381 | break; | ||
| 382 | |||
| 383 | case tFloat: | ||
| 384 | { | ||
| 385 | double dTmp = iValue; | ||
| 386 | eType = tFloat; | ||
| 387 | fValue = dTmp - rhs.fValue; | ||
| 388 | } | ||
| 389 | break; | ||
| 390 | |||
| 391 | default: | ||
| 392 | throw VariableException("Int -= invalid..."); | ||
| 393 | } | ||
| 394 | break; | ||
| 395 | |||
| 396 | case tFloat: | ||
| 397 | switch( rhs.eType ) | ||
| 398 | { | ||
| 399 | case tInt: | ||
| 400 | fValue -= rhs.iValue; | ||
| 401 | break; | ||
| 402 | |||
| 403 | case tFloat: | ||
| 404 | fValue -= rhs.fValue; | ||
| 405 | break; | ||
| 406 | |||
| 407 | default: | ||
| 408 | throw VariableException("Int += invalid..."); | ||
| 409 | } | ||
| 410 | break; | ||
| 411 | |||
| 412 | case tString: | ||
| 413 | throw VariableException("You cannot subtract strings."); | ||
| 414 | break; | ||
| 415 | |||
| 416 | case tSituation: | ||
| 417 | throw VariableException("You cannot subtract situations."); | ||
| 418 | break; | ||
| 419 | |||
| 420 | case tVariable: | ||
| 421 | throw VariableException("You cannot subtract variable names."); | ||
| 422 | break; | ||
| 423 | |||
| 424 | case tList: | ||
| 425 | (*lValue).erase( rhs ); | ||
| 426 | break; | ||
| 427 | |||
| 428 | case tDictionary: | ||
| 429 | (*hValue).erase( rhs ); | ||
| 430 | break; | ||
| 431 | } | ||
| 432 | |||
| 433 | return *this; | ||
| 434 | } | ||
| 435 | |||
| 366 | /* | 436 | /* |
| 367 | Variable &Variable::operator-=( const Variable &rhs ); | ||
| 368 | Variable &Variable::operator*=( const Variable &rhs ); | 437 | Variable &Variable::operator*=( const Variable &rhs ); |
| 369 | Variable &Variable::operator/=( const Variable &rhs ); | 438 | Variable &Variable::operator/=( const Variable &rhs ); |
| 370 | */ | 439 | */ |
