Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/TclBind.cc @ 1151

Last change on this file since 1151 was 1151, checked in by landauf, 16 years ago

added cpptcl and some first tests

File size: 1.1 KB
Line 
1#include <iostream>
2#include <string>
3
4#include "ConsoleCommand.h"
5#include "Debug.h"
6#include "cpptcl/CppTcl.h"
7#include "TclBind.h"
8
9namespace orxonox
10{
11    ConsoleCommandShortcutExtern(test, AccessLevel::None);
12    ConsoleCommandShortcutExtern(tcl, AccessLevel::None);
13
14    void hello()
15    {
16        std::cout << "Hello C++/Tcl!" << std::endl;
17    }
18
19    void test()
20    {
21        Tcl::interpreter i;
22        i.def("hello", hello);
23
24        std::string script = "for {set i 0} {$i != 4} {incr i} { hello }";
25
26        i.eval(script);
27    }
28
29    std::string tcl(const std::string& tclcode)
30    {
31        try
32        {
33            static Tcl::interpreter i;
34            std::string output = i.eval(tclcode);
35            COUT(0) << "tcl> " << output << std::endl;
36            return output;
37        }
38        catch (Tcl::tcl_error const &e)
39        {
40            COUT(1) << "Error: Tcl: " << e.what() << std::endl;
41        }
42        catch (std::exception const &e)
43        {
44            COUT(1) << "Error while executing tcl: " << e.what() << std::endl;
45        }
46
47        return "";
48    }
49}
Note: See TracBrowser for help on using the repository browser.