Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/script_trigger/src/cpptcl/details/dispatchers.h @ 2092

Last change on this file since 2092 was 1214, checked in by landauf, 17 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: 5.7 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// the dispatch class is used to execute the callback functor and to
14// capture its return value
15// further dispatch<void> specialization ignores the res
16
17template <typename R>
18struct dispatch
19{
20     template <class Functor>
21     static void do_dispatch(Tcl_Interp *interp, Functor f)
22     {
23          R res = f();
24          set_result(interp, res);
25     }
26
27     template <typename T1, class Functor>
28     static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1)
29     {
30          R res = f(t1);
31          set_result(interp, res);
32     }
33
34     template <typename T1, typename T2, class Functor>
35     static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1, T2 t2)
36     {
37          R res = f(t1, t2);
38          set_result(interp, res);
39     }
40
41     template <typename T1, typename T2, typename T3, class Functor>
42     static void do_dispatch(Tcl_Interp *interp, Functor f,
43          T1 t1, T2 t2, T3 t3)
44     {
45          R res = f(t1, t2, t3);
46          set_result(interp, res);
47     }
48
49     template <typename T1, typename T2, typename T3, typename T4,
50          class Functor>
51     static void do_dispatch(Tcl_Interp *interp, Functor f,
52          T1 t1, T2 t2, T3 t3, T4 t4)
53     {
54          R res = f(t1, t2, t3, t4);
55          set_result(interp, res);
56     }
57
58     template <typename T1, typename T2, typename T3, typename T4,
59          typename T5, class Functor>
60     static void do_dispatch(Tcl_Interp *interp, Functor f,
61          T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
62     {
63          R res = f(t1, t2, t3, t4, t5);
64          set_result(interp, res);
65     }
66
67     template <typename T1, typename T2, typename T3, typename T4,
68          typename T5, typename T6, class Functor>
69     static void do_dispatch(Tcl_Interp *interp, Functor f,
70          T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
71     {
72          R res = f(t1, t2, t3, t4, t5, t6);
73          set_result(interp, res);
74     }
75
76     template <typename T1, typename T2, typename T3, typename T4,
77          typename T5, typename T6, typename T7, class Functor>
78     static void do_dispatch(Tcl_Interp *interp, Functor f,
79          T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
80     {
81          R res = f(t1, t2, t3, t4, t5, t6, t7);
82          set_result(interp, res);
83     }
84
85     template <typename T1, typename T2, typename T3, typename T4,
86          typename T5, typename T6, typename T7, typename T8, class Functor>
87     static void do_dispatch(Tcl_Interp *interp, Functor f,
88          T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
89     {
90          R res = f(t1, t2, t3, t4, t5, t6, t7, t8);
91          set_result(interp, res);
92     }
93
94     template <typename T1, typename T2, typename T3, typename T4,
95          typename T5, typename T6, typename T7, typename T8, typename T9,
96          class Functor>
97     static void do_dispatch(Tcl_Interp *interp, Functor f,
98          T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9)
99     {
100          R res = f(t1, t2, t3, t4, t5, t6, t7, t8, t9);
101          set_result(interp, res);
102     }
103};
104
105template <>
106struct dispatch<void>
107{
108     template <class Functor>
109     static void do_dispatch(Tcl_Interp *, Functor f)
110     {
111          f();
112     }
113
114     template <typename T1, class Functor>
115     static void do_dispatch(Tcl_Interp *, Functor f, T1 t1)
116     {
117          f(t1);
118     }
119
120     template <typename T1, typename T2, class Functor>
121     static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2)
122     {
123          f(t1, t2);
124     }
125
126     template <typename T1, typename T2, typename T3, class Functor>
127     static void do_dispatch(Tcl_Interp *, Functor f,
128          T1 t1, T2 t2, T3 t3)
129     {
130          f(t1, t2, t3);
131     }
132
133     template <typename T1, typename T2, typename T3, typename T4,
134          class Functor>
135     static void do_dispatch(Tcl_Interp *, Functor f,
136          T1 t1, T2 t2, T3 t3, T4 t4)
137     {
138          f(t1, t2, t3, t4);
139     }
140
141     template <typename T1, typename T2, typename T3, typename T4,
142          typename T5, class Functor>
143     static void do_dispatch(Tcl_Interp *, Functor f,
144          T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
145     {
146          f(t1, t2, t3, t4, t5);
147     }
148
149     template <typename T1, typename T2, typename T3, typename T4,
150          typename T5, typename T6, class Functor>
151     static void do_dispatch(Tcl_Interp *, Functor f,
152          T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
153     {
154          f(t1, t2, t3, t4, t5, t6);
155     }
156
157     template <typename T1, typename T2, typename T3, typename T4,
158          typename T5, typename T6, typename T7, class Functor>
159     static void do_dispatch(Tcl_Interp *, Functor f,
160          T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
161     {
162          f(t1, t2, t3, t4, t5, t6, t7);
163     }
164
165     template <typename T1, typename T2, typename T3, typename T4,
166          typename T5, typename T6, typename T7, typename T8, class Functor>
167     static void do_dispatch(Tcl_Interp *, Functor f,
168          T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
169     {
170          f(t1, t2, t3, t4, t5, t6, t7, t8);
171     }
172
173     template <typename T1, typename T2, typename T3, typename T4,
174          typename T5, typename T6, typename T7, typename T8, typename T9,
175          class Functor>
176     static void do_dispatch(Tcl_Interp *, Functor f,
177          T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9)
178     {
179          f(t1, t2, t3, t4, t5, t6, t7, t8, t9);
180     }
181};
Note: See TracBrowser for help on using the repository browser.