summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/functionjoin.cpp36
-rw-r--r--src/functionjoin.h16
-rw-r--r--src/functionkeys.cpp32
-rw-r--r--src/functionkeys.h16
-rw-r--r--src/functionstring.cpp17
-rw-r--r--src/functionstring.h16
-rw-r--r--src/game.cpp6
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>
6using namespace Bu;
7
8FunctionJoin::FunctionJoin()
9{
10}
11
12FunctionJoin::~FunctionJoin()
13{
14}
15
16void 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
6class FunctionJoin : public Function
7{
8public:
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>
6using namespace Bu;
7
8FunctionKeys::FunctionKeys()
9{
10}
11
12FunctionKeys::~FunctionKeys()
13{
14}
15
16void 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
6class FunctionKeys : public Function
7{
8public:
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
5FunctionString::FunctionString()
6{
7}
8
9FunctionString::~FunctionString()
10{
11}
12
13void 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
6class FunctionString : public Function
7{
8public:
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
12Game::Game() 15Game::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
25Game::~Game() 31Game::~Game()