Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/cpptcl/details/callbacks.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: 7.8 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
13template <typename R>
14class callback0 : public callback_base
15{
16     typedef R (*functor_type)();
17     
18public:
19     callback0(functor_type f) : f_(f) {}
20     
21     virtual void invoke(Tcl_Interp *interp,
22          int, Tcl_Obj * CONST [],
23          policies const &)
24     {
25          dispatch<R>::do_dispatch(interp, f_);
26     }
27
28private:
29     functor_type f_;
30};
31
32template <typename R, typename T1>
33class callback1 : public callback_base
34{
35     typedef R (*functor_type)(T1);
36     
37public:
38     callback1(functor_type f) : f_(f) {}
39     
40     virtual void invoke(Tcl_Interp *interp,
41          int objc, Tcl_Obj * CONST objv[],
42          policies const &)
43     {
44          check_params_no(objc, 2);
45         
46          dispatch<R>::template do_dispatch<T1>(interp, f_,
47               tcl_cast<T1>::from(interp, objv[1]));
48     }
49
50private:
51     functor_type f_;
52};
53
54template <typename R, typename T1, typename T2>
55class callback2 : public callback_base
56{
57     typedef R (*functor_type)(T1, T2);
58     
59public:
60     callback2(functor_type f) : f_(f) {}
61     
62     virtual void invoke(Tcl_Interp *interp,
63          int objc, Tcl_Obj * CONST objv[],
64          policies const &)
65     {
66          check_params_no(objc, 3);
67         
68          dispatch<R>::template do_dispatch<T1, T2>(interp, f_,
69               tcl_cast<T1>::from(interp, objv[1]),
70               tcl_cast<T2>::from(interp, objv[2]));
71     }
72
73private:
74     functor_type f_;
75};
76
77template <typename R, typename T1, typename T2, typename T3>
78class callback3 : public callback_base
79{
80     typedef R (*functor_type)(T1, T2, T3);
81     
82public:
83     callback3(functor_type f) : f_(f) {}
84     
85     virtual void invoke(Tcl_Interp *interp,
86          int objc, Tcl_Obj * CONST objv[],
87          policies const &)
88     {
89          check_params_no(objc, 4);
90         
91          dispatch<R>::template do_dispatch<T1, T2, T3>(interp, f_,
92               tcl_cast<T1>::from(interp, objv[1]),
93               tcl_cast<T2>::from(interp, objv[2]),
94               tcl_cast<T3>::from(interp, objv[3]));
95     }
96
97private:
98     functor_type f_;
99};
100
101template <typename R, typename T1, typename T2, typename T3, typename T4>
102class callback4 : public callback_base
103{
104     typedef R (*functor_type)(T1, T2, T3, T4);
105     
106public:
107     callback4(functor_type f) : f_(f) {}
108     
109     virtual void invoke(Tcl_Interp *interp,
110          int objc, Tcl_Obj * CONST objv[],
111          policies const &)
112     {
113          check_params_no(objc, 5);
114         
115          dispatch<R>::template do_dispatch<T1, T2, T3, T4>(interp, f_,
116               tcl_cast<T1>::from(interp, objv[1]),
117               tcl_cast<T2>::from(interp, objv[2]),
118               tcl_cast<T3>::from(interp, objv[3]),
119               tcl_cast<T4>::from(interp, objv[4]));
120     }
121
122private:
123     functor_type f_;
124};
125
126template <typename R, typename T1, typename T2, typename T3, typename T4,
127     typename T5>
128class callback5 : public callback_base
129{
130     typedef R (*functor_type)(T1, T2, T3, T4, T5);
131     
132public:
133     callback5(functor_type f) : f_(f) {}
134     
135     virtual void invoke(Tcl_Interp *interp,
136          int objc, Tcl_Obj * CONST objv[],
137          policies const &)
138     {
139          check_params_no(objc, 6);
140         
141          dispatch<R>::template do_dispatch<T1, T2, T3, T4, T5>(interp, f_,
142               tcl_cast<T1>::from(interp, objv[1]),
143               tcl_cast<T2>::from(interp, objv[2]),
144               tcl_cast<T3>::from(interp, objv[3]),
145               tcl_cast<T4>::from(interp, objv[4]),
146               tcl_cast<T5>::from(interp, objv[5]));
147     }
148
149private:
150     functor_type f_;
151};
152
153template <typename R, typename T1, typename T2, typename T3, typename T4,
154     typename T5, typename T6>
155class callback6 : public callback_base
156{
157     typedef R (*functor_type)(T1, T2, T3, T4, T5, T6);
158     
159public:
160     callback6(functor_type f) : f_(f) {}
161     
162     virtual void invoke(Tcl_Interp *interp,
163          int objc, Tcl_Obj * CONST objv[],
164          policies const &)
165     {
166          check_params_no(objc, 7);
167         
168          dispatch<R>::template do_dispatch<T1, T2, T3, T4, T5, T6>(
169               interp, f_,
170               tcl_cast<T1>::from(interp, objv[1]),
171               tcl_cast<T2>::from(interp, objv[2]),
172               tcl_cast<T3>::from(interp, objv[3]),
173               tcl_cast<T4>::from(interp, objv[4]),
174               tcl_cast<T5>::from(interp, objv[5]),
175               tcl_cast<T6>::from(interp, objv[6]));
176     }
177
178private:
179     functor_type f_;
180};
181
182template <typename R, typename T1, typename T2, typename T3, typename T4,
183     typename T5, typename T6, typename T7>
184class callback7 : public callback_base
185{
186     typedef R (*functor_type)(T1, T2, T3, T4, T5, T6, T7);
187     
188public:
189     callback7(functor_type f) : f_(f) {}
190     
191     virtual void invoke(Tcl_Interp *interp,
192          int objc, Tcl_Obj * CONST objv[],
193          policies const &)
194     {
195          check_params_no(objc, 8);
196         
197          dispatch<R>::template do_dispatch<T1, T2, T3, T4, T5, T6, T7>(
198               interp, f_,
199               tcl_cast<T1>::from(interp, objv[1]),
200               tcl_cast<T2>::from(interp, objv[2]),
201               tcl_cast<T3>::from(interp, objv[3]),
202               tcl_cast<T4>::from(interp, objv[4]),
203               tcl_cast<T5>::from(interp, objv[5]),
204               tcl_cast<T6>::from(interp, objv[6]),
205               tcl_cast<T7>::from(interp, objv[7]));
206     }
207
208private:
209     functor_type f_;
210};
211
212template <typename R, typename T1, typename T2, typename T3, typename T4,
213     typename T5, typename T6, typename T7, typename T8>
214class callback8 : public callback_base
215{
216     typedef R (*functor_type)(T1, T2, T3, T4, T5, T6, T7, T8);
217     
218public:
219     callback8(functor_type f) : f_(f) {}
220     
221     virtual void invoke(Tcl_Interp *interp,
222          int objc, Tcl_Obj * CONST objv[],
223          policies const &)
224     {
225          check_params_no(objc, 9);
226         
227          dispatch<R>::template do_dispatch<T1, T2, T3, T4, T5, T6, T7, T8>(
228               interp, f_,
229               tcl_cast<T1>::from(interp, objv[1]),
230               tcl_cast<T2>::from(interp, objv[2]),
231               tcl_cast<T3>::from(interp, objv[3]),
232               tcl_cast<T4>::from(interp, objv[4]),
233               tcl_cast<T5>::from(interp, objv[5]),
234               tcl_cast<T6>::from(interp, objv[6]),
235               tcl_cast<T7>::from(interp, objv[7]),
236               tcl_cast<T8>::from(interp, objv[8]));
237     }
238
239private:
240     functor_type f_;
241};
242
243template <typename R, typename T1, typename T2, typename T3, typename T4,
244     typename T5, typename T6, typename T7, typename T8, typename T9>
245class callback9 : public callback_base
246{
247     typedef R (*functor_type)(T1, T2, T3, T4, T5, T6, T7, T8, T9);
248     
249public:
250     callback9(functor_type f) : f_(f) {}
251     
252     virtual void invoke(Tcl_Interp *interp,
253          int objc, Tcl_Obj * CONST objv[],
254          policies const &)
255     {
256          check_params_no(objc, 10);
257         
258          dispatch<R>::template do_dispatch<
259               T1, T2, T3, T4, T5, T6, T7, T8, T9>(interp, f_,
260               tcl_cast<T1>::from(interp, objv[1]),
261               tcl_cast<T2>::from(interp, objv[2]),
262               tcl_cast<T3>::from(interp, objv[3]),
263               tcl_cast<T4>::from(interp, objv[4]),
264               tcl_cast<T5>::from(interp, objv[5]),
265               tcl_cast<T6>::from(interp, objv[6]),
266               tcl_cast<T7>::from(interp, objv[7]),
267               tcl_cast<T8>::from(interp, objv[8]),
268               tcl_cast<T9>::from(interp, objv[9]));
269     }
270
271private:
272     functor_type f_;
273};
Note: See TracBrowser for help on using the repository browser.