Advanced Strategic Command
luacommandwriter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 
10 #include "luacommandwriter.h"
11 
12 #include <boost/regex.hpp>
13 #include <boost/algorithm/string/split.hpp>
14 #include <boost/algorithm/string/classification.hpp>
15 
17 {
18  typedef vector< ASCString > Split_vector_type;
19 
20  Split_vector_type splitVec; // #2: Search for tokens
21  boost::algorithm::split( splitVec, string, boost::algorithm::is_any_of("\n") ); // SplitVec == { "hello abc","ABC","aBc goodbye" }
22 
23  for ( Split_vector_type::iterator i = splitVec.begin(); i != splitVec.end(); ++i ) {
24  printCommand( *i );
25  }
26 }
27 
29  outputLine("-- get handle to active map \n");
30  outputLine("map = asc.getActiveMap() \n");
31 }
32 
33 LuaCommandWriter :: LuaCommandWriter ( ) : commandCounter(0) {
34 }
35 
37  if ( command.find('\n') != ASCString::npos ) {
38  splitString(command);
39  } else {
40  outputLine("r = asc." + command + "\n" );
41  outputLine("if r:successful()==false then asc.displayActionError(r, \"command " + ASCString::toString(++commandCounter) + "\") end \n" );
42  }
43 };
44 
46  outputLine("\n--" + comment + "\n" );
47 };
48 
49 
50 
51 LuaCommandFileWriter :: LuaCommandFileWriter ( const ASCString& filename ) : stream ( filename, tnstream::writing )
52 {
53  writeHeader();
54 }
55 
56 void LuaCommandFileWriter :: outputLine( const ASCString& line )
57 {
58  stream.writeString( line, false );
59 }
60 
LuaCommandFileWriter(const ASCString &filename)
The interface for all kinds of IO stream.
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
virtual void outputLine(const ASCString &line)=0
void splitString(const ASCString &string)
virtual void writeString(const string &pc, bool binary=true)
writes the C++ String pc to the stream.
Definition: basestrm.cpp:545
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
tn_file_buf_stream stream
virtual void printComment(const ASCString &comment)
void line(int x1, int y1, int x2, int y2, Uint8 actcol)
draws a simple line on the screen. Not very fast...
Definition: basegfx.cpp:181
virtual void printCommand(const ASCString &command)