1 | /*! |
---|
2 | * @file executor.h |
---|
3 | * Definition of a on-screen-shell |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _EXECUTOR_SPECIALS_H |
---|
7 | #define _EXECUTOR_SPECIALS_H |
---|
8 | |
---|
9 | #include "executor.h" |
---|
10 | #include "compiler.h" |
---|
11 | #include "debug.h" |
---|
12 | #include "luaincl.h" |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | template<typename type> type fromLua(lua_State* state, int index) { PRINTF(1)("NOT IMPLEMENTED\n"); }; |
---|
17 | template<> bool fromLua<bool>(lua_State* state, int index); |
---|
18 | template<> int fromLua<int>(lua_State* state, int index); |
---|
19 | template<> unsigned int fromLua<unsigned int>(lua_State* state, int index); |
---|
20 | template<> float fromLua<float>(lua_State* state, int index); |
---|
21 | template<> char fromLua<char>(lua_State* state, int index); |
---|
22 | template<> const std::string& fromLua<const std::string&>(lua_State* state, int index); |
---|
23 | |
---|
24 | |
---|
25 | template<typename type> void toLua(lua_State* state, type value) { PRINTF(1)("NOT IMPLEMENTED\n"); }; |
---|
26 | template<> void toLua<bool>(lua_State* state, bool value); |
---|
27 | template<> void toLua<int>(lua_State* state, int value); |
---|
28 | template<> void toLua<unsigned int>(lua_State* state, unsigned int value); |
---|
29 | template<> void toLua<float>(lua_State* state, float value); |
---|
30 | template<> void toLua<char>(lua_State* state, char value); |
---|
31 | template<> void toLua<const std::string&>(lua_State* state, const std::string& value); |
---|
32 | |
---|
33 | // FORWARD DECLARATION |
---|
34 | |
---|
35 | |
---|
36 | /////////// |
---|
37 | //// 0 //// |
---|
38 | /////////// |
---|
39 | //! Executes a Function with a lua_State* parameter. |
---|
40 | template<class T> class ExecutorLua0 : public Executor |
---|
41 | { |
---|
42 | public: |
---|
43 | /** |
---|
44 | * @brief Constructor of a ExecutorXML |
---|
45 | * @param function a Function to call |
---|
46 | */ |
---|
47 | ExecutorLua0(void(T::*function)()) |
---|
48 | : Executor() |
---|
49 | { |
---|
50 | this->functionPointer = function; |
---|
51 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * @brief executes the Command on BaseObject |
---|
56 | * @param object the BaseObject to execute this Executor on |
---|
57 | * @param loadString ignored in this case |
---|
58 | */ |
---|
59 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
60 | { |
---|
61 | PRINTF(1)("no usefull executor\n"); |
---|
62 | } |
---|
63 | |
---|
64 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
65 | { |
---|
66 | (dynamic_cast<T*>(object)->*(functionPointer))(); |
---|
67 | count = 0; |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * @returns a _new_ Copy of this Executor |
---|
72 | */ |
---|
73 | virtual Executor* clone () const |
---|
74 | { |
---|
75 | return new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer)); |
---|
76 | } |
---|
77 | private: |
---|
78 | void (T::*functionPointer)(); |
---|
79 | }; |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | /////////// |
---|
84 | //// 1 //// |
---|
85 | /////////// |
---|
86 | //! Executes a Function with a lua_State* parameter. |
---|
87 | template<class T, typename type0> class ExecutorLua1 : public Executor |
---|
88 | { |
---|
89 | public: |
---|
90 | /** |
---|
91 | * @brief Constructor of a ExecutorXML |
---|
92 | * @param function a Function to call |
---|
93 | */ |
---|
94 | ExecutorLua1(void(T::*function)(type0)) |
---|
95 | : Executor(ExecutorParamType<type0>()) |
---|
96 | { |
---|
97 | this->functionPointer = function; |
---|
98 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * @brief executes the Command on BaseObject |
---|
103 | * @param object the BaseObject to execute this Executor on |
---|
104 | * @param loadString ignored in this case |
---|
105 | */ |
---|
106 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
107 | { |
---|
108 | PRINTF(1)("no usefull executor\n"); |
---|
109 | } |
---|
110 | |
---|
111 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
112 | { |
---|
113 | lua_State* state = (lua_State*)values; |
---|
114 | count = 0; |
---|
115 | |
---|
116 | (dynamic_cast<T*>(object)->*(functionPointer))(fromLua<type0>(state, 1)); |
---|
117 | } |
---|
118 | |
---|
119 | /** |
---|
120 | * @returns a _new_ Copy of this Executor |
---|
121 | */ |
---|
122 | virtual Executor* clone () const |
---|
123 | { |
---|
124 | return new ExecutorLua1<T, type0>((this->functionPointer)); |
---|
125 | } |
---|
126 | private: |
---|
127 | void (T::*functionPointer)(type0); |
---|
128 | }; |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | /////////// |
---|
133 | //// 2 //// |
---|
134 | /////////// |
---|
135 | //! Executes a Function with a lua_State* parameter. |
---|
136 | template<class T, typename type0, typename type1> class ExecutorLua2 : public Executor |
---|
137 | { |
---|
138 | public: |
---|
139 | /** |
---|
140 | * @brief Constructor of a ExecutorXML |
---|
141 | * @param function a Function to call |
---|
142 | */ |
---|
143 | ExecutorLua2(void(T::*function)(type0, type1)) |
---|
144 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>()) |
---|
145 | { |
---|
146 | this->functionPointer = function; |
---|
147 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
148 | } |
---|
149 | |
---|
150 | /** |
---|
151 | * @brief executes the Command on BaseObject |
---|
152 | * @param object the BaseObject to execute this Executor on |
---|
153 | * @param loadString ignored in this case |
---|
154 | */ |
---|
155 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
156 | { |
---|
157 | PRINTF(1)("no usefull executor\n"); |
---|
158 | } |
---|
159 | |
---|
160 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
161 | { |
---|
162 | lua_State* state = (lua_State*)values; |
---|
163 | count = 0; |
---|
164 | |
---|
165 | (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
166 | fromLua<type0>(state, 1), |
---|
167 | fromLua<type1>(state, 2) ); |
---|
168 | } |
---|
169 | |
---|
170 | /** |
---|
171 | * @returns a _new_ Copy of this Executor |
---|
172 | */ |
---|
173 | virtual Executor* clone () const |
---|
174 | { |
---|
175 | return new ExecutorLua2<T, type0, type1>(this->functionPointer); |
---|
176 | } |
---|
177 | private: |
---|
178 | void (T::*functionPointer)(type0, type1); |
---|
179 | }; |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | //////////////////// |
---|
188 | ///// WITH RET ///// |
---|
189 | //////////////////// |
---|
190 | |
---|
191 | |
---|
192 | /////////// |
---|
193 | //// 0 //// |
---|
194 | /////////// |
---|
195 | //! Executes a Function with a lua_State* parameter. |
---|
196 | template<class T, typename ret> class ExecutorLua0ret : public Executor |
---|
197 | { |
---|
198 | public: |
---|
199 | /** |
---|
200 | * @brief Constructor of a ExecutorXML |
---|
201 | * @param function a Function to call |
---|
202 | */ |
---|
203 | ExecutorLua0ret(ret (T::*function)()) |
---|
204 | : Executor() |
---|
205 | { |
---|
206 | this->functionPointer = function; |
---|
207 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
208 | } |
---|
209 | |
---|
210 | /** |
---|
211 | * @brief executes the Command on BaseObject |
---|
212 | * @param object the BaseObject to execute this Executor on |
---|
213 | * @param loadString ignored in this case |
---|
214 | */ |
---|
215 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
216 | { |
---|
217 | PRINTF(1)("no usefull executor\n"); |
---|
218 | } |
---|
219 | |
---|
220 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
221 | { |
---|
222 | lua_State* state = (lua_State*)values; |
---|
223 | count = 1; |
---|
224 | |
---|
225 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))()); |
---|
226 | } |
---|
227 | |
---|
228 | /** |
---|
229 | * @returns a _new_ Copy of this Executor |
---|
230 | */ |
---|
231 | virtual Executor* clone () const |
---|
232 | { |
---|
233 | return new ExecutorLua0ret<T, ret>(this->functionPointer); |
---|
234 | } |
---|
235 | private: |
---|
236 | ret (T::*functionPointer)(); |
---|
237 | }; |
---|
238 | |
---|
239 | |
---|
240 | |
---|
241 | /////////// |
---|
242 | //// 1 //// |
---|
243 | /////////// |
---|
244 | //! Executes a Function with a lua_State* parameter. |
---|
245 | template<class T, typename ret, typename type0> class ExecutorLua1ret : public Executor |
---|
246 | { |
---|
247 | public: |
---|
248 | /** |
---|
249 | * @brief Constructor of a ExecutorXML |
---|
250 | * @param function a Function to call |
---|
251 | */ |
---|
252 | ExecutorLua1ret(ret (T::*function)(type0)) |
---|
253 | : Executor(ExecutorParamType<type0>()) |
---|
254 | { |
---|
255 | this->functionPointer = function; |
---|
256 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
257 | } |
---|
258 | |
---|
259 | /** |
---|
260 | * @brief executes the Command on BaseObject |
---|
261 | * @param object the BaseObject to execute this Executor on |
---|
262 | * @param loadString ignored in this case |
---|
263 | */ |
---|
264 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
265 | { |
---|
266 | PRINTF(1)("no usefull executor\n"); |
---|
267 | } |
---|
268 | |
---|
269 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
270 | { |
---|
271 | lua_State* state = (lua_State*)values; |
---|
272 | count = 1; |
---|
273 | |
---|
274 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
275 | fromLua<type0>(state, 1))); |
---|
276 | } |
---|
277 | |
---|
278 | /** |
---|
279 | * @returns a _new_ Copy of this Executor |
---|
280 | */ |
---|
281 | virtual Executor* clone () const |
---|
282 | { |
---|
283 | return new ExecutorLua1ret<T, ret, type0>(this->functionPointer); |
---|
284 | } |
---|
285 | private: |
---|
286 | ret (T::*functionPointer)(type0); |
---|
287 | }; |
---|
288 | |
---|
289 | /////////// |
---|
290 | //// 2 //// |
---|
291 | /////////// |
---|
292 | //! Executes a Function with a lua_State* parameter. |
---|
293 | template<class T, typename ret, typename type0, typename type1> class ExecutorLua2ret : public Executor |
---|
294 | { |
---|
295 | public: |
---|
296 | /** |
---|
297 | * @brief Constructor of a ExecutorXML |
---|
298 | * @param function a Function to call |
---|
299 | */ |
---|
300 | ExecutorLua2ret(ret (T::*function)(type0, type1)) |
---|
301 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>()) |
---|
302 | { |
---|
303 | this->functionPointer = function; |
---|
304 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
305 | } |
---|
306 | |
---|
307 | /** |
---|
308 | * @brief executes the Command on BaseObject |
---|
309 | * @param object the BaseObject to execute this Executor on |
---|
310 | * @param loadString ignored in this case |
---|
311 | */ |
---|
312 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
313 | { |
---|
314 | PRINTF(1)("no usefull executor\n"); |
---|
315 | } |
---|
316 | |
---|
317 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
318 | { |
---|
319 | lua_State* state = (lua_State*)values; |
---|
320 | count = 1; |
---|
321 | |
---|
322 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
323 | fromLua<type0>(state, 1), |
---|
324 | fromLua<type1>(state, 2) )); |
---|
325 | } |
---|
326 | |
---|
327 | /** |
---|
328 | * @returns a _new_ Copy of this Executor |
---|
329 | */ |
---|
330 | virtual Executor* clone () const |
---|
331 | { |
---|
332 | return new ExecutorLua2ret<T, ret, type0, type1>(this->functionPointer); |
---|
333 | } |
---|
334 | private: |
---|
335 | ret (T::*functionPointer)(type0, type1); |
---|
336 | }; |
---|
337 | |
---|
338 | |
---|
339 | |
---|
340 | |
---|
341 | |
---|
342 | |
---|
343 | |
---|
344 | #endif /* _EXECUTOR_SPECIALS_H */ |
---|