Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/cpptcl/details/conversions.h @ 1214

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

merged console-branch back to trunk.
IMPORTANT: update your media directory!

you need TCL to compile. TCL is available here: http://www.tcl.tk/
another option is to check out https://svn.orxonox.net/ogre/tcl8.5.2/ and compile it by yourself. makefiles are in the 'macosx', 'unix' and 'win' subfolders.
FindTCL.cmake searches in the usual locations and in ../libs/tcl8.5.2/

the orxonox console can be activated with numpad-enter. whatever you enter will be parsed by TCL. if TCL doesn't know a command, it gets executed by orxonox.

simple tcl commands are: "puts text" to write "text" into the console, "expr 1+1" to calculate the result of the given expression. just try it by yourself with "puts [expr 1+1]".
[x] means: evaluate x and use the returnvalue as an argument. in this case the returned value is "2" and the resulting command therefore "puts 2".

you can combine orxonox and tcl commands. a simple orxonox command is "log text" that writes text into the console and the logfile. test it with "log [expr 1+1]" to write "2" into all output channels of orxonox. something more advanced: "log [clock seconds]" writes the seconds since 1970 into the logfile. feel free to combine both: "log [clock seconds]: 1+1 is [expr 1+1]"

TCL uses variables. to set a new variable, use "set varname value". you can use the variable wherever you want with $varname. with this we can make the above command a bit more elegant:
set myexpression 1+1
log [clock seconds]: $myexpression is [expr $myexpression]

read more about tcl in the wiki: http://wiki.tcl.tk/

File size: 2.1 KB
Line 
1//
2// Copyright (C) 2004-2006, Maciej Sobczak
3//
4// Permission to copy, use, modify, sell and distribute this software
5// is granted provided this copyright notice appears in all copies.
6// This software is provided "as is" without express or implied
7// warranty, and with no claim as to its suitability for any purpose.
8//
9
10// Note: this file is not supposed to be a stand-alone header
11
12
13// helper functor for converting Tcl objects to the given type
14// (it is a struct instead of function,
15// because I need to partially specialize it)
16
17template <typename T>
18struct tcl_cast;
19
20template <typename T>
21struct tcl_cast<T*>
22{
23     static T * from(Tcl_Interp *, Tcl_Obj *obj)
24     {
25          std::string s(Tcl_GetString(obj));
26          if (s.size() == 0)
27          {
28               throw tcl_error("Expected pointer value, got empty string.");
29          }
30
31          if (s[0] != 'p')
32          {
33               throw tcl_error("Expected pointer value.");
34          }
35
36          std::istringstream ss(s);
37          char dummy;
38          void *p;
39          ss >> dummy >> p;
40
41          return static_cast<T*>(p);
42     }
43};
44
45// the following partial specialization is to strip reference
46// (it returns a temporary object of the underlying type, which
47// can be bound to the const-ref parameter of the actual function)
48
49template <typename T>
50struct tcl_cast<T const &>
51{
52     static T from(Tcl_Interp *interp, Tcl_Obj *obj)
53     {
54          return tcl_cast<T>::from(interp, obj);
55     }
56};
57
58
59// the following specializations are implemented
60
61template <>
62struct tcl_cast<int>
63{
64     static int from(Tcl_Interp *, Tcl_Obj *);
65};
66
67template <>
68struct tcl_cast<long>
69{
70     static long from(Tcl_Interp *, Tcl_Obj *);
71};
72
73template <>
74struct tcl_cast<bool>
75{
76     static bool from(Tcl_Interp *, Tcl_Obj *);
77};
78
79template <>
80struct tcl_cast<double>
81{
82     static double from(Tcl_Interp *, Tcl_Obj *);
83};
84
85template <>
86struct tcl_cast<std::string>
87{
88     static std::string from(Tcl_Interp *, Tcl_Obj *);
89};
90
91template <>
92struct tcl_cast<char const *>
93{
94     static char const * from(Tcl_Interp *, Tcl_Obj *);
95};
96
97template <>
98struct tcl_cast<object>
99{
100     static object from(Tcl_Interp *, Tcl_Obj *);
101};
Note: See TracBrowser for help on using the repository browser.