Tero’s C++ Scripting – cppt
Tero’s C++ Scripting lets you write a script
#!/usr/local/bin/cppt cout << "Hello World!" << endl;
and just run it
$ chmod a+x hello.cc $ ./hello.cc Hello World!
Features
Tero’s C++ Scripting
-
Runs your scripts in real C++, using GNU g++ compiler
-
You can just write commands
-
If needed, Tero’s C++ Scripting adds #include, main() and return
-
Coder can also write the whole thing himself
-
-
Free software under the GPL, the GNU General Public License, version 2
-
Simplicity of bash, power of C++.
C++ as a Scripting Language
Syntax of C++ is very clear if you compare it to scripting languages such as perl and bash. The best examples are if and test constructions in bash, or function (sub) definitions in perl and bash.
C++ scales well. Probably most programs in the world start with “hello world”. But they grow. If you start with C++, you can keep improving the same program instead of starting from scratch when your prototype is ready.
C++ is precise. It requires you to declare your variables and it does strong typing. With PHP, you always get a program if you just write something – but not necessarily the program you were thinking of. With C++, typos give an error, not a program that does something else.
C++ can be easy. Using C++ constructs and not C, you can create understandable, simple and short programs. With convience functions (see “Future” below), it can be even easier. For example, vectors and strings are easy to use. C++ is a full featured language, so it can give you enough rope to hang yourself with. Resist the temptation of the dark side of pointers and char arrays!
Download and Install
Download cppt-latest.tar.gz. (Beta version)
Uncompress
$ tar -xf cppt*.tar.gz $ cd cppt*
Install requirements. This command is for Ubuntu Dapper, substitute installation command with a different one if you are using another distribution.
$ sudo apt-get install g++ libboost-doc $ sudo apt-get install libboost-regex-dev libboost-filesystem-dev
Compile
$ make
Install
$ sudo cp cppt /usr/local/bin/
Enjoy!
Writing Your First Script
If you have ever written a shell script in bash, you probably know this already.
Write a program to a text file
$ nano foo.cc
#!/usr/local/bin/cppt cout << "Hello Tero's C++ Scripting World!" << endl;
Save it with ctrl-X y enter.
Make it runnable
$ chmod a+x foo.cc
Run it
$ ./foo.cc Hello Tero's C++ Scripting World!
Future
Provide convience functions to do typical script things.
string contents = readFile("tero.txt"); writeFile("tero2.txt", "Foo bar this is some text"); string cmd="ls /etc/"; systemExec(cmd+">output.txt"); // C++ string support cout << regReplace("Tero's C++ System", "S.*m", "Scripting") << endl;
If you need those functions now, you can view the source code of Tero’s C++ Scripting. Remember that GPL license requires you to use the same license for your work and mention the source if you copy any code.
Contribute
Testing
Does this run on Mac? BSD? Windows? If you run an operating system other than Ubuntu Linux, tell me this works on your system.
Packagers Wanted
You can help by packaging Tero’s C++ Scripting for your distribution. Most wanted are 1) Ubuntu or Debian 2) Fedora or Redhat 3) Mandriva, SuSe, Gentoo, anything else.
When you package
-
Optional: Email me what distribution you are working on, I’ll keep it reserved (tell anyone asking) for two weeks
-
Publish your package on your homepage – so that it’s immidiately available
-
Email me, I’ll copy it to Tero’s C++ scripting homepage or link to it
-
Submit it to distribution of choice.
Links and Syndication
Freshmeat page of Tero’s C++ Scripting http://freshmeat.net/projects/cppt/.
Syndicate
Feedback
I’m looking forward to hearing from you!
You can use the quick feedback form to send me feedback or email: karvinen+cppt at iki.fi
One Response to Tero’s C++ Scripting – cppt