Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/new_class_id: removed all the base of Executor.
Now it is purely Templated :), since it is not needed otherwise

@note: The Explicit Specializations may not be Templatet and defined in the header, that is why still there exist some cc-file

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