diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-02-08 09:29:50 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-02-08 09:29:50 -0700 |
commit | 33b6c34a20545222088f645bbc3cc5610f7cc782 (patch) | |
tree | cd530153cf2acd92a6fd969fa5186e975775373d | |
parent | 98c5559c40c17d6dbf402f88fc8274b31657a1df (diff) | |
download | stage-33b6c34a20545222088f645bbc3cc5610f7cc782.tar.gz stage-33b6c34a20545222088f645bbc3cc5610f7cc782.tar.bz2 stage-33b6c34a20545222088f645bbc3cc5610f7cc782.tar.xz stage-33b6c34a20545222088f645bbc3cc5610f7cc782.zip |
Added function count().
Diffstat (limited to '')
-rw-r--r-- | src/functioncount.cpp | 35 | ||||
-rw-r--r-- | src/functioncount.h | 16 | ||||
-rw-r--r-- | src/game.cpp | 2 | ||||
-rw-r--r-- | tests/test.stage | 4 |
4 files changed, 56 insertions, 1 deletions
diff --git a/src/functioncount.cpp b/src/functioncount.cpp new file mode 100644 index 0000000..f879238 --- /dev/null +++ b/src/functioncount.cpp | |||
@@ -0,0 +1,35 @@ | |||
1 | #include "functioncount.h" | ||
2 | |||
3 | #include "gamestate.h" | ||
4 | |||
5 | FunctionCount::FunctionCount() | ||
6 | { | ||
7 | } | ||
8 | |||
9 | FunctionCount::~FunctionCount() | ||
10 | { | ||
11 | } | ||
12 | |||
13 | void FunctionCount::call( class GameState &gState ) | ||
14 | { | ||
15 | Variable v = gState.popDeref(); | ||
16 | switch( v.getType() ) | ||
17 | { | ||
18 | case Variable::tList: | ||
19 | gState.push( (int64_t)v.getList().getSize() ); | ||
20 | break; | ||
21 | |||
22 | case Variable::tDictionary: | ||
23 | gState.push( (int64_t)v.getHash().getSize() ); | ||
24 | break; | ||
25 | |||
26 | case Variable::tString: | ||
27 | gState.push( (int64_t)v.getString().getSize() ); | ||
28 | break; | ||
29 | |||
30 | default: | ||
31 | gState.push( Variable( Variable::tNull ) ); | ||
32 | break; | ||
33 | } | ||
34 | } | ||
35 | |||
diff --git a/src/functioncount.h b/src/functioncount.h new file mode 100644 index 0000000..24f9e4e --- /dev/null +++ b/src/functioncount.h | |||
@@ -0,0 +1,16 @@ | |||
1 | #ifndef FUNCTION_COUNT_H | ||
2 | #define FUNCTION_COUNT_H | ||
3 | |||
4 | #include "function.h" | ||
5 | |||
6 | class FunctionCount : public Function | ||
7 | { | ||
8 | public: | ||
9 | FunctionCount(); | ||
10 | virtual ~FunctionCount(); | ||
11 | |||
12 | virtual Bu::String getName() const { return "count"; } | ||
13 | virtual void call( class GameState &gState ); | ||
14 | }; | ||
15 | |||
16 | #endif | ||
diff --git a/src/game.cpp b/src/game.cpp index 19a31f7..05c5eca 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
@@ -9,6 +9,7 @@ | |||
9 | #include "functionstring.h" | 9 | #include "functionstring.h" |
10 | #include "functionjoin.h" | 10 | #include "functionjoin.h" |
11 | #include "functionkeys.h" | 11 | #include "functionkeys.h" |
12 | #include "functioncount.h" | ||
12 | 13 | ||
13 | Game::Game() | 14 | Game::Game() |
14 | { | 15 | { |
@@ -22,6 +23,7 @@ Game::Game() | |||
22 | addFunction( new FunctionString() ); | 23 | addFunction( new FunctionString() ); |
23 | addFunction( new FunctionJoin() ); | 24 | addFunction( new FunctionJoin() ); |
24 | addFunction( new FunctionKeys() ); | 25 | addFunction( new FunctionKeys() ); |
26 | addFunction( new FunctionCount() ); | ||
25 | } | 27 | } |
26 | 28 | ||
27 | Game::~Game() | 29 | Game::~Game() |
diff --git a/tests/test.stage b/tests/test.stage index cc765a4..dc7ad7e 100644 --- a/tests/test.stage +++ b/tests/test.stage | |||
@@ -24,8 +24,10 @@ situation <<start>> | |||
24 | { | 24 | { |
25 | if true then | 25 | if true then |
26 | { | 26 | { |
27 | getVal(); | 27 | getVal(); |
28 | } | 28 | } |
29 | |||
30 | display( count( "global.stuff" ) ); | ||
29 | } | 31 | } |
30 | 32 | ||
31 | enter | 33 | enter |