diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-01-18 23:58:30 -0700 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-01-18 23:58:30 -0700 |
| commit | 3232d0069421a1585e7e42f503c1ed7b1910891c (patch) | |
| tree | 0d2c5ed5e24a9ffeb3c1b3c08528971a8a3d587e /src | |
| parent | 0bdd1441fc95f70f2f86c89c20eb866a9ca2787b (diff) | |
| download | stage-3232d0069421a1585e7e42f503c1ed7b1910891c.tar.gz stage-3232d0069421a1585e7e42f503c1ed7b1910891c.tar.bz2 stage-3232d0069421a1585e7e42f503c1ed7b1910891c.tar.xz stage-3232d0069421a1585e7e42f503c1ed7b1910891c.zip | |
Added functions join, string, and keys.
Diffstat (limited to 'src')
| -rw-r--r-- | src/functionjoin.cpp | 36 | ||||
| -rw-r--r-- | src/functionjoin.h | 16 | ||||
| -rw-r--r-- | src/functionkeys.cpp | 32 | ||||
| -rw-r--r-- | src/functionkeys.h | 16 | ||||
| -rw-r--r-- | src/functionstring.cpp | 17 | ||||
| -rw-r--r-- | src/functionstring.h | 16 | ||||
| -rw-r--r-- | src/game.cpp | 6 |
7 files changed, 139 insertions, 0 deletions
diff --git a/src/functionjoin.cpp b/src/functionjoin.cpp new file mode 100644 index 0000000..71ee879 --- /dev/null +++ b/src/functionjoin.cpp | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | #include "functionjoin.h" | ||
| 2 | |||
| 3 | #include "gamestate.h" | ||
| 4 | |||
| 5 | #include <bu/sio.h> | ||
| 6 | using namespace Bu; | ||
| 7 | |||
| 8 | FunctionJoin::FunctionJoin() | ||
| 9 | { | ||
| 10 | } | ||
| 11 | |||
| 12 | FunctionJoin::~FunctionJoin() | ||
| 13 | { | ||
| 14 | } | ||
| 15 | |||
| 16 | void FunctionJoin::call( class GameState &gState ) | ||
| 17 | { | ||
| 18 | Variable vSep = gState.popDeref().to( Variable::tString ); | ||
| 19 | Variable vLst = gState.popDeref(); | ||
| 20 | |||
| 21 | if( vLst.getType() != Variable::tList ) | ||
| 22 | throw Bu::ExceptionBase("First parameter of join must be a list."); | ||
| 23 | |||
| 24 | Bu::String sOut; | ||
| 25 | for( Variable::VariableArray::const_iterator i = vLst.getList().begin(); | ||
| 26 | i; i++ ) | ||
| 27 | { | ||
| 28 | if( i != vLst.getList().begin() ) | ||
| 29 | sOut += vSep.getString(); | ||
| 30 | sOut += (*i).to( Variable::tString ).getString(); | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | gState.push( sOut ); | ||
| 35 | } | ||
| 36 | |||
diff --git a/src/functionjoin.h b/src/functionjoin.h new file mode 100644 index 0000000..7c46e7f --- /dev/null +++ b/src/functionjoin.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #ifndef FUNCTION_JOIN_H | ||
| 2 | #define FUNCTION_JOIN_H | ||
| 3 | |||
| 4 | #include "function.h" | ||
| 5 | |||
| 6 | class FunctionJoin : public Function | ||
| 7 | { | ||
| 8 | public: | ||
| 9 | FunctionJoin(); | ||
| 10 | virtual ~FunctionJoin(); | ||
| 11 | |||
| 12 | virtual Bu::String getName() const { return "join"; } | ||
| 13 | virtual void call( class GameState &gState ); | ||
| 14 | }; | ||
| 15 | |||
| 16 | #endif | ||
diff --git a/src/functionkeys.cpp b/src/functionkeys.cpp new file mode 100644 index 0000000..12c1098 --- /dev/null +++ b/src/functionkeys.cpp | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #include "functionkeys.h" | ||
| 2 | |||
| 3 | #include "gamestate.h" | ||
| 4 | |||
| 5 | #include <bu/sio.h> | ||
| 6 | using namespace Bu; | ||
| 7 | |||
| 8 | FunctionKeys::FunctionKeys() | ||
| 9 | { | ||
| 10 | } | ||
| 11 | |||
| 12 | FunctionKeys::~FunctionKeys() | ||
| 13 | { | ||
| 14 | } | ||
| 15 | |||
| 16 | void FunctionKeys::call( class GameState &gState ) | ||
| 17 | { | ||
| 18 | Variable vDict = gState.popDeref(); | ||
| 19 | |||
| 20 | if( vDict.getType() != Variable::tDictionary ) | ||
| 21 | throw Bu::ExceptionBase("Parameter to keys must be a dictionary."); | ||
| 22 | |||
| 23 | Variable vLst( Variable::tList ); | ||
| 24 | for( Variable::VariableHash::const_iterator i = vDict.getHash().begin(); | ||
| 25 | i; i++ ) | ||
| 26 | { | ||
| 27 | vLst += i.getKey(); | ||
| 28 | } | ||
| 29 | |||
| 30 | gState.push( vLst ); | ||
| 31 | } | ||
| 32 | |||
diff --git a/src/functionkeys.h b/src/functionkeys.h new file mode 100644 index 0000000..ccc3bdd --- /dev/null +++ b/src/functionkeys.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #ifndef FUNCTION_KEYS_H | ||
| 2 | #define FUNCTION_KEYS_H | ||
| 3 | |||
| 4 | #include "function.h" | ||
| 5 | |||
| 6 | class FunctionKeys : public Function | ||
| 7 | { | ||
| 8 | public: | ||
| 9 | FunctionKeys(); | ||
| 10 | virtual ~FunctionKeys(); | ||
| 11 | |||
| 12 | virtual Bu::String getName() const { return "keys"; } | ||
| 13 | virtual void call( class GameState &gState ); | ||
| 14 | }; | ||
| 15 | |||
| 16 | #endif | ||
diff --git a/src/functionstring.cpp b/src/functionstring.cpp new file mode 100644 index 0000000..ca5a3aa --- /dev/null +++ b/src/functionstring.cpp | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #include "functionstring.h" | ||
| 2 | |||
| 3 | #include "gamestate.h" | ||
| 4 | |||
| 5 | FunctionString::FunctionString() | ||
| 6 | { | ||
| 7 | } | ||
| 8 | |||
| 9 | FunctionString::~FunctionString() | ||
| 10 | { | ||
| 11 | } | ||
| 12 | |||
| 13 | void FunctionString::call( class GameState &gState ) | ||
| 14 | { | ||
| 15 | gState.push( gState.popDeref().to( Variable::tString ) ); | ||
| 16 | } | ||
| 17 | |||
diff --git a/src/functionstring.h b/src/functionstring.h new file mode 100644 index 0000000..36e4f51 --- /dev/null +++ b/src/functionstring.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #ifndef FUNCTION_STRING_H | ||
| 2 | #define FUNCTION_STRING_H | ||
| 3 | |||
| 4 | #include "function.h" | ||
| 5 | |||
| 6 | class FunctionString : public Function | ||
| 7 | { | ||
| 8 | public: | ||
| 9 | FunctionString(); | ||
| 10 | virtual ~FunctionString(); | ||
| 11 | |||
| 12 | virtual Bu::String getName() const { return "string"; } | ||
| 13 | virtual void call( class GameState &gState ); | ||
| 14 | }; | ||
| 15 | |||
| 16 | #endif | ||
diff --git a/src/game.cpp b/src/game.cpp index 4971c4b..37989bd 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
| @@ -8,6 +8,9 @@ | |||
| 8 | #include "functioninteger.h" | 8 | #include "functioninteger.h" |
| 9 | #include "functionfloat.h" | 9 | #include "functionfloat.h" |
| 10 | #include "functiondebugstring.h" | 10 | #include "functiondebugstring.h" |
| 11 | #include "functionstring.h" | ||
| 12 | #include "functionjoin.h" | ||
| 13 | #include "functionkeys.h" | ||
| 11 | 14 | ||
| 12 | Game::Game() | 15 | Game::Game() |
| 13 | { | 16 | { |
| @@ -20,6 +23,9 @@ Game::Game() | |||
| 20 | addFunction( new FunctionInteger() ); | 23 | addFunction( new FunctionInteger() ); |
| 21 | addFunction( new FunctionFloat() ); | 24 | addFunction( new FunctionFloat() ); |
| 22 | addFunction( new FunctionDebugString() ); | 25 | addFunction( new FunctionDebugString() ); |
| 26 | addFunction( new FunctionString() ); | ||
| 27 | addFunction( new FunctionJoin() ); | ||
| 28 | addFunction( new FunctionKeys() ); | ||
| 23 | } | 29 | } |
| 24 | 30 | ||
| 25 | Game::~Game() | 31 | Game::~Game() |
