Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/executor/executor_lua.h @ 9734

Last change on this file since 9734 was 9734, checked in by bensch, 18 years ago

new_class_id: better constructs for the Executor.

File size: 15.0 KB
Line 
1/*!
2 * @file executor.h
3 * Definition of a on-screen-shell
4 */
5
6#ifndef _EXECUTOR_LUA_H
7#define _EXECUTOR_LUA_H
8
9#include "executor.h"
10#include "compiler.h"
11#include "debug.h"
12#include "luaincl.h"
13
14
15
16template<typename type> type fromLua(lua_State* state, int index);
17template<> bool fromLua<bool>(lua_State* state, int index);
18template<> int fromLua<int>(lua_State* state, int index);
19template<> unsigned int fromLua<unsigned int>(lua_State* state, int index);
20template<> float fromLua<float>(lua_State* state, int index);
21template<> char fromLua<char>(lua_State* state, int index);
22template<> const std::string& fromLua<const std::string&>(lua_State* state, int index);
23
24template<typename type> void toLua(lua_State* state, type value);
25template<> void toLua<bool>(lua_State* state, bool value);
26template<> void toLua<int>(lua_State* state, int value);
27template<> void toLua<unsigned int>(lua_State* state, unsigned int value);
28template<> void toLua<float>(lua_State* state, float value);
29template<> void toLua<char>(lua_State* state, char value);
30template<> void toLua<const std::string&>(lua_State* state, const std::string& value);
31
32// FORWARD DECLARATION
33
34///////////////////////
35///// WITHOUT RET /////
36///////////////////////
37
38///////////
39//// 0 ////
40///////////
41//! Executes a Function with a lua_State* parameter.
42template<class T> class ExecutorLua0 : public Executor<lua_State*>
43{
44public:
45  /**
46  * @brief Constructor of a ExecutorXML
47  * @param function a Function to call
48   */
49  ExecutorLua0(void(T::*function)())
50      : Executor<lua_State*>(false)
51  {
52    this->functionPointer = function;
53  }
54
55
56  virtual void operator()(BaseObject* object, lua_State*& state) const
57  {
58    (dynamic_cast<T*>(object)->*(functionPointer))();
59  }
60
61  /**
62   * @returns a _new_ Copy of this Executor
63   */
64  virtual Executor<lua_State*>* clone () const
65  {
66    return new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));
67  }
68private:
69  void          (T::*functionPointer)();
70};
71
72
73
74///////////
75//// 1 ////
76///////////
77//! Executes a Function with a lua_State* parameter.
78template<class T, typename type0> class ExecutorLua1 : public Executor<lua_State*>
79{
80public:
81  /**
82  * @brief Constructor of a ExecutorXML
83  * @param function a Function to call
84   */
85  ExecutorLua1(void(T::*function)(type0))
86      : Executor<lua_State*>(false, ExecutorParamType<type0>())
87  {
88    this->functionPointer = function;
89  }
90
91  virtual void operator()(BaseObject* object, lua_State*& state) const
92  {
93    (dynamic_cast<T*>(object)->*(functionPointer))(fromLua<type0>(state, 1));
94  }
95
96  /**
97   * @returns a _new_ Copy of this Executor
98   */
99  virtual Executor<lua_State*>* clone () const
100  {
101    return new ExecutorLua1<T, type0>((this->functionPointer));
102  }
103private:
104  void          (T::*functionPointer)(type0);
105};
106
107
108
109///////////
110//// 2 ////
111///////////
112//! Executes a Function with a lua_State* parameter.
113template<class T, typename type0, typename type1> class ExecutorLua2 : public Executor<lua_State*>
114{
115public:
116  /**
117  * @brief Constructor of a ExecutorXML
118  * @param function a Function to call
119   */
120  ExecutorLua2(void(T::*function)(type0, type1))
121      : Executor<lua_State*>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>())
122  {
123    this->functionPointer = function;
124  }
125
126  virtual void operator()(BaseObject* object, lua_State*& state) const
127  {
128    (dynamic_cast<T*>(object)->*(functionPointer))(
129      fromLua<type0>(state, 1),
130      fromLua<type1>(state, 2) );
131  }
132
133  /**
134   * @returns a _new_ Copy of this Executor
135   */
136  virtual Executor<lua_State*>* clone () const
137  {
138    return new ExecutorLua2<T, type0, type1>(this->functionPointer);
139  }
140private:
141  void          (T::*functionPointer)(type0, type1);
142};
143
144
145///////////
146//// 3 ////
147///////////
148//! Executes a Function with a lua_State* parameter.
149template<class T, typename type0, typename type1, typename type2> class ExecutorLua3 : public Executor<lua_State*>
150{
151public:
152  /**
153  * @brief Constructor of a ExecutorXML
154  * @param function a Function to call
155   */
156  ExecutorLua3(void(T::*function)(type0, type1, type2))
157      : Executor<lua_State*>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>())
158  {
159    this->functionPointer = function;
160  }
161
162
163  virtual void operator()(BaseObject* object, lua_State*& state) const
164  {
165    (dynamic_cast<T*>(object)->*(functionPointer))(
166      fromLua<type0>(state, 1),
167      fromLua<type1>(state, 2),
168      fromLua<type2>(state, 3) );
169  }
170
171  /**
172   * @returns a _new_ Copy of this Executor
173   */
174  virtual Executor<lua_State*>* clone () const
175  {
176    return new ExecutorLua3<T, type0, type1, type2>(this->functionPointer);
177  }
178private:
179  void          (T::*functionPointer)(type0, type1, type2);
180};
181
182
183///////////
184//// 4 ////
185///////////
186//! Executes a Function with a lua_State* parameter.
187template<class T, typename type0, typename type1, typename type2, typename type3> class ExecutorLua4 : public Executor<lua_State*>
188{
189public:
190  /**
191  * @brief Constructor of a ExecutorXML
192  * @param function a Function to call
193   */
194  ExecutorLua4(void(T::*function)(type0, type1, type2, type3))
195      : Executor<lua_State*>(false, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>())
196  {
197    this->functionPointer = function;
198  }
199
200  virtual void operator()(BaseObject* object, lua_State*& state) const
201  {
202    (dynamic_cast<T*>(object)->*(functionPointer))(
203      fromLua<type0>(state, 1),
204      fromLua<type1>(state, 2),
205      fromLua<type2>(state, 3),
206      fromLua<type3>(state, 4) );
207  }
208
209  /**
210   * @returns a _new_ Copy of this Executor
211   */
212  virtual Executor<lua_State*>* clone () const
213  {
214    return new ExecutorLua4<T, type0, type1, type2, type3>(this->functionPointer);
215  }
216private:
217  void          (T::*functionPointer)(type0, type1, type2, type3);
218};
219
220
221
222
223////////////////////
224///// WITH RET /////
225////////////////////
226
227
228///////////
229//// 0 ////
230///////////
231//! Executes a Function with a lua_State* parameter.
232template<class T, typename ret> class ExecutorLua0ret : public Executor<lua_State*>
233{
234public:
235  /**
236  * @brief Constructor of a ExecutorXML
237  * @param function a Function to call
238   */
239  ExecutorLua0ret(ret (T::*function)())
240      : Executor<lua_State*>(true)
241  {
242    this->functionPointer = function;
243  }
244
245  virtual void operator()(BaseObject* object, lua_State*& state) const
246  {
247    toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))());
248  }
249
250  /**
251   * @returns a _new_ Copy of this Executor
252   */
253  virtual Executor<lua_State*>* clone () const
254  {
255    return new ExecutorLua0ret<T, ret>(this->functionPointer);
256  }
257private:
258  ret           (T::*functionPointer)();
259};
260
261
262
263///////////
264//// 1 ////
265///////////
266//! Executes a Function with a lua_State* parameter.
267template<class T, typename ret, typename type0> class ExecutorLua1ret : public Executor<lua_State*>
268{
269public:
270  /**
271  * @brief Constructor of a ExecutorXML
272  * @param function a Function to call
273   */
274  ExecutorLua1ret(ret (T::*function)(type0))
275      : Executor<lua_State*>(true, ExecutorParamType<type0>())
276  {
277    this->functionPointer = function;
278  }
279
280  virtual void operator()(BaseObject* object, lua_State*& state) const
281  {
282    toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
283                 fromLua<type0>(state, 1)));
284  }
285
286  /**
287   * @returns a _new_ Copy of this Executor
288   */
289  virtual Executor<lua_State*>* clone () const
290  {
291    return new ExecutorLua1ret<T, ret, type0>(this->functionPointer);
292  }
293private:
294  ret           (T::*functionPointer)(type0);
295};
296
297///////////
298//// 2 ////
299///////////
300//! Executes a Function with a lua_State* parameter.
301template<class T, typename ret, typename type0, typename type1> class ExecutorLua2ret : public Executor<lua_State*>
302{
303public:
304  /**
305  * @brief Constructor of a ExecutorXML
306  * @param function a Function to call
307   */
308  ExecutorLua2ret(ret (T::*function)(type0, type1))
309      : Executor<lua_State*>(true, ExecutorParamType<type0>(), ExecutorParamType<type1>())
310  {
311    this->functionPointer = function;
312  }
313
314  virtual void operator()(BaseObject* object, lua_State*& state) const
315  {
316    toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
317                 fromLua<type0>(state, 1),
318                 fromLua<type1>(state, 2) ));
319  }
320
321  /**
322   * @returns a _new_ Copy of this Executor
323   */
324  virtual Executor<lua_State*>* clone () const
325  {
326    return new ExecutorLua2ret<T, ret, type0, type1>(this->functionPointer);
327  }
328private:
329  ret           (T::*functionPointer)(type0, type1);
330};
331
332
333///////////
334//// 3 ////
335///////////
336//! Executes a Function with a lua_State* parameter.
337template<class T, typename ret, typename type0, typename type1, typename type2> class ExecutorLua3ret : public Executor<lua_State*>
338{
339public:
340  /**
341  * @brief Constructor of a ExecutorXML
342  * @param function a Function to call
343   */
344  ExecutorLua3ret(ret (T::*function)(type0, type1, type2))
345      : Executor<lua_State*>(true, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>())
346  {
347    this->functionPointer = function;
348  }
349
350  virtual void operator()(BaseObject* object, lua_State*& state) const
351  {
352    toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
353                 fromLua<type0>(state, 1),
354                 fromLua<type1>(state, 2),
355                 fromLua<type2>(state, 3) ));
356  }
357
358  /**
359   * @returns a _new_ Copy of this Executor
360   */
361  virtual Executor<lua_State*>* clone () const
362  {
363    return new ExecutorLua3ret<T, ret, type0, type1, type2>(this->functionPointer);
364  }
365private:
366  ret          (T::*functionPointer)(type0, type1, type2);
367};
368
369
370///////////
371//// 4 ////
372///////////
373//! Executes a Function with a lua_State* parameter.
374template<class T, typename ret, typename type0, typename type1, typename type2, typename type3> class ExecutorLua4ret : public Executor<lua_State*>
375{
376public:
377  /**
378  * @brief Constructor of a ExecutorXML
379  * @param function a Function to call
380   */
381  ExecutorLua4ret(ret (T::*function)(type0, type1, type2, type3))
382      : Executor<lua_State*>(true, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>())
383  {
384    this->functionPointer = function;
385  }
386
387  virtual void operator()(BaseObject* object, lua_State*& state) const
388  {
389    toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
390                 fromLua<type0>(state, 1),
391                 fromLua<type1>(state, 2),
392                 fromLua<type2>(state, 3),
393                 fromLua<type3>(state, 4) ));
394  }
395
396  /**
397   * @returns a _new_ Copy of this Executor
398   */
399  virtual Executor<lua_State*>* clone () const
400  {
401    return new ExecutorLua4ret<T, ret, type0, type1, type2, type3>(this->functionPointer);
402  }
403private:
404  ret          (T::*functionPointer)(type0, type1, type2, type3);
405};
406
407///////////
408//// 5 ////
409///////////
410//! Executes a Function with a lua_State* parameter.
411template<class T, typename ret, typename type0, typename type1, typename type2, typename type3, typename type4> class ExecutorLua5ret : public Executor<lua_State*>
412{
413public:
414  /**
415  * @brief Constructor of a ExecutorXML
416  * @param function a Function to call
417   */
418  ExecutorLua5ret(ret (T::*function)(type0, type1, type2, type3, type4))
419      : Executor<lua_State*>(true, ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>())
420  {
421    this->functionPointer = function;
422  }
423
424  virtual void operator()(BaseObject* object, lua_State*& state) const
425  {
426    toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
427                 fromLua<type0>(state, 1),
428                 fromLua<type1>(state, 2),
429                 fromLua<type2>(state, 3),
430                 fromLua<type3>(state, 4),
431                 fromLua<type4>(state, 5) ));
432  }
433
434  /**
435   * @returns a _new_ Copy of this Executor
436   */
437  virtual Executor<lua_State*>* clone () const
438  {
439    return new ExecutorLua5ret<T, ret, type0, type1, type2, type3, type4>(this->functionPointer);
440  }
441private:
442  ret          (T::*functionPointer)(type0, type1, type2, type3, type4);
443};
444
445///////////
446//// 6 ////
447///////////
448//! Executes a Function with a lua_State* parameter.
449template<class T, typename ret, typename type0, typename type1, typename type2, typename type3, typename type4, typename type5> class ExecutorLua6ret : public Executor<lua_State*>
450{
451public:
452  /**
453  * @brief Constructor of a ExecutorXML
454  * @param function a Function to call
455   */
456  ExecutorLua6ret(ret (T::*function)(type0, type1, type2, type3, type4, type5))
457      : Executor<lua_State*>(true, ExecutorParamType<type0>(), ExecutorParamType<type1>(),
458                             ExecutorParamType<type2>(), ExecutorParamType<type3>(),
459                             ExecutorParamType<type4>(), ExecutorParamType<type5>())
460  {
461    this->functionPointer = function;
462  }
463
464  virtual void operator()(BaseObject* object, lua_State*& state) const
465  {
466    toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
467                 fromLua<type0>(state, 1),
468                 fromLua<type1>(state, 2),
469                 fromLua<type2>(state, 3),
470                 fromLua<type3>(state, 4),
471                 fromLua<type4>(state, 5),
472                 fromLua<type5>(state, 6) ));
473  }
474
475  /**
476            * @returns a _new_ Copy of this Executor
477   */
478  virtual Executor<lua_State*>* clone () const
479  {
480    return new ExecutorLua6ret<T, ret, type0, type1, type2, type3, type4, type5>(this->functionPointer);
481  }
482private:
483  ret           (T::*functionPointer)(type0, type1, type2, type3, type4, type5);
484};
485
486///////////
487//// 7 ////
488///////////
489//! Executes a Function with a lua_State* parameter.
490template<class T, typename ret, typename type0, typename type1, typename type2, typename type3, typename type4, typename type5, typename type6> class ExecutorLua7ret : public Executor<lua_State*>
491{
492public:
493  /**
494  * @brief Constructor of a ExecutorXML
495  * @param function a Function to call
496   */
497  ExecutorLua7ret(ret (T::*function)(type0, type1, type2, type3, type4, type5, type6))
498      : Executor<lua_State*>(true, ExecutorParamType<type0>(), ExecutorParamType<type1>(),
499                             ExecutorParamType<type2>(), ExecutorParamType<type3>(),
500                             ExecutorParamType<type4>(), ExecutorParamType<type5>(),
501                             ExecutorParamType<type6>())
502  {
503    this->functionPointer = function;
504  }
505
506  virtual void operator()(BaseObject* object, lua_State*& state) const
507  {
508    toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
509                 fromLua<type0>(state, 1),
510                 fromLua<type1>(state, 2),
511                 fromLua<type2>(state, 3),
512                 fromLua<type3>(state, 4),
513                 fromLua<type4>(state, 5),
514                 fromLua<type5>(state, 6),
515                 fromLua<type6>(state, 7) ));
516  }
517
518  /**
519            * @returns a _new_ Copy of this Executor
520   */
521  virtual Executor<lua_State*>* clone () const
522  {
523    return new ExecutorLua7ret<T, ret, type0, type1, type2, type3, type4, type5, type6>(this->functionPointer);
524  }
525private:
526  ret           (T::*functionPointer)(type0, type1, type2, type3, type4, type5, type6);
527};
528
529
530#endif /* _EXECUTOR_LUA_H */
Note: See TracBrowser for help on using the repository browser.