[4838] | 1 | /*! |
---|
[5632] | 2 | * @file executor.h |
---|
[5068] | 3 | * Definition of a on-screen-shell |
---|
[5391] | 4 | */ |
---|
[1853] | 5 | |
---|
[8271] | 6 | #ifndef _EXECUTOR_LUA_H |
---|
| 7 | #define _EXECUTOR_LUA_H |
---|
[1853] | 8 | |
---|
[5651] | 9 | #include "executor.h" |
---|
[7711] | 10 | #include "compiler.h" |
---|
[8271] | 11 | #include "debug.h" |
---|
[8051] | 12 | #include "luaincl.h" |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | |
---|
[8408] | 16 | template<typename type> type fromLua(lua_State* state, int index); |
---|
[8271] | 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); |
---|
[8051] | 23 | |
---|
[8408] | 24 | template<typename type> void toLua(lua_State* state, type value); |
---|
[8271] | 25 | template<> void toLua<bool>(lua_State* state, bool value); |
---|
| 26 | template<> void toLua<int>(lua_State* state, int value); |
---|
| 27 | template<> void toLua<unsigned int>(lua_State* state, unsigned int value); |
---|
| 28 | template<> void toLua<float>(lua_State* state, float value); |
---|
| 29 | template<> void toLua<char>(lua_State* state, char value); |
---|
| 30 | template<> void toLua<const std::string&>(lua_State* state, const std::string& value); |
---|
[8057] | 31 | |
---|
[4838] | 32 | // FORWARD DECLARATION |
---|
[3543] | 33 | |
---|
[8271] | 34 | /////////////////////// |
---|
| 35 | ///// WITHOUT RET ///// |
---|
| 36 | /////////////////////// |
---|
[8051] | 37 | |
---|
| 38 | /////////// |
---|
| 39 | //// 0 //// |
---|
| 40 | /////////// |
---|
[8271] | 41 | //! Executes a Function with a lua_State* parameter. |
---|
[8051] | 42 | template<class T> class ExecutorLua0 : public Executor |
---|
[5170] | 43 | { |
---|
[8057] | 44 | public: |
---|
| 45 | /** |
---|
| 46 | * @brief Constructor of a ExecutorXML |
---|
| 47 | * @param function a Function to call |
---|
| 48 | */ |
---|
| 49 | ExecutorLua0(void(T::*function)()) |
---|
| 50 | : Executor() |
---|
| 51 | { |
---|
| 52 | this->functionPointer = function; |
---|
| 53 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 54 | } |
---|
[8051] | 55 | |
---|
[8057] | 56 | /** |
---|
| 57 | * @brief executes the Command on BaseObject |
---|
| 58 | * @param object the BaseObject to execute this Executor on |
---|
| 59 | * @param loadString ignored in this case |
---|
| 60 | */ |
---|
| 61 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 62 | { |
---|
| 63 | PRINTF(1)("no usefull executor\n"); |
---|
| 64 | } |
---|
[8051] | 65 | |
---|
[8271] | 66 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
[8057] | 67 | { |
---|
| 68 | (dynamic_cast<T*>(object)->*(functionPointer))(); |
---|
[8271] | 69 | count = 0; |
---|
[8057] | 70 | } |
---|
[8051] | 71 | |
---|
[8057] | 72 | /** |
---|
| 73 | * @returns a _new_ Copy of this Executor |
---|
| 74 | */ |
---|
| 75 | virtual Executor* clone () const |
---|
| 76 | { |
---|
[8271] | 77 | return new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer)); |
---|
[8057] | 78 | } |
---|
[8271] | 79 | private: |
---|
| 80 | void (T::*functionPointer)(); |
---|
[8051] | 81 | }; |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | /////////// |
---|
| 86 | //// 1 //// |
---|
| 87 | /////////// |
---|
[8271] | 88 | //! Executes a Function with a lua_State* parameter. |
---|
[8051] | 89 | template<class T, typename type0> class ExecutorLua1 : public Executor |
---|
| 90 | { |
---|
[5170] | 91 | public: |
---|
[8057] | 92 | /** |
---|
| 93 | * @brief Constructor of a ExecutorXML |
---|
| 94 | * @param function a Function to call |
---|
| 95 | */ |
---|
[8271] | 96 | ExecutorLua1(void(T::*function)(type0)) |
---|
[8057] | 97 | : Executor(ExecutorParamType<type0>()) |
---|
[5651] | 98 | { |
---|
| 99 | this->functionPointer = function; |
---|
[5652] | 100 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
[5651] | 101 | } |
---|
[5164] | 102 | |
---|
[8057] | 103 | /** |
---|
| 104 | * @brief executes the Command on BaseObject |
---|
| 105 | * @param object the BaseObject to execute this Executor on |
---|
| 106 | * @param loadString ignored in this case |
---|
| 107 | */ |
---|
| 108 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 109 | { |
---|
| 110 | PRINTF(1)("no usefull executor\n"); |
---|
| 111 | } |
---|
| 112 | |
---|
[8271] | 113 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
[8057] | 114 | { |
---|
[8271] | 115 | lua_State* state = (lua_State*)values; |
---|
| 116 | count = 0; |
---|
[8057] | 117 | |
---|
| 118 | (dynamic_cast<T*>(object)->*(functionPointer))(fromLua<type0>(state, 1)); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * @returns a _new_ Copy of this Executor |
---|
| 123 | */ |
---|
| 124 | virtual Executor* clone () const |
---|
| 125 | { |
---|
[8271] | 126 | return new ExecutorLua1<T, type0>((this->functionPointer)); |
---|
[8057] | 127 | } |
---|
[8271] | 128 | private: |
---|
| 129 | void (T::*functionPointer)(type0); |
---|
[8057] | 130 | }; |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | /////////// |
---|
| 135 | //// 2 //// |
---|
| 136 | /////////// |
---|
[8271] | 137 | //! Executes a Function with a lua_State* parameter. |
---|
| 138 | template<class T, typename type0, typename type1> class ExecutorLua2 : public Executor |
---|
[8057] | 139 | { |
---|
| 140 | public: |
---|
| 141 | /** |
---|
| 142 | * @brief Constructor of a ExecutorXML |
---|
| 143 | * @param function a Function to call |
---|
| 144 | */ |
---|
[8271] | 145 | ExecutorLua2(void(T::*function)(type0, type1)) |
---|
[8057] | 146 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>()) |
---|
| 147 | { |
---|
| 148 | this->functionPointer = function; |
---|
| 149 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | /** |
---|
[7331] | 153 | * @brief executes the Command on BaseObject |
---|
[5651] | 154 | * @param object the BaseObject to execute this Executor on |
---|
| 155 | * @param loadString ignored in this case |
---|
[8057] | 156 | */ |
---|
[7474] | 157 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
[5135] | 158 | { |
---|
[8051] | 159 | PRINTF(1)("no usefull executor\n"); |
---|
[5145] | 160 | } |
---|
[5113] | 161 | |
---|
[8271] | 162 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
[8035] | 163 | { |
---|
[8271] | 164 | lua_State* state = (lua_State*)values; |
---|
| 165 | count = 0; |
---|
[8051] | 166 | |
---|
[8057] | 167 | (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
| 168 | fromLua<type0>(state, 1), |
---|
| 169 | fromLua<type1>(state, 2) ); |
---|
[8035] | 170 | } |
---|
| 171 | |
---|
[8057] | 172 | /** |
---|
[8051] | 173 | * @returns a _new_ Copy of this Executor |
---|
[8057] | 174 | */ |
---|
[8051] | 175 | virtual Executor* clone () const |
---|
| 176 | { |
---|
[8271] | 177 | return new ExecutorLua2<T, type0, type1>(this->functionPointer); |
---|
[8051] | 178 | } |
---|
[8271] | 179 | private: |
---|
| 180 | void (T::*functionPointer)(type0, type1); |
---|
[8051] | 181 | }; |
---|
[5632] | 182 | |
---|
[5326] | 183 | |
---|
[8711] | 184 | /////////// |
---|
| 185 | //// 3 //// |
---|
| 186 | /////////// |
---|
| 187 | //! Executes a Function with a lua_State* parameter. |
---|
| 188 | template<class T, typename type0, typename type1, typename type2> class ExecutorLua3 : public Executor |
---|
| 189 | { |
---|
| 190 | public: |
---|
| 191 | /** |
---|
| 192 | * @brief Constructor of a ExecutorXML |
---|
| 193 | * @param function a Function to call |
---|
| 194 | */ |
---|
| 195 | ExecutorLua3(void(T::*function)(type0, type1, type2)) |
---|
| 196 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>()) |
---|
| 197 | { |
---|
| 198 | this->functionPointer = function; |
---|
| 199 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 200 | } |
---|
[8057] | 201 | |
---|
[8711] | 202 | /** |
---|
| 203 | * @brief executes the Command on BaseObject |
---|
| 204 | * @param object the BaseObject to execute this Executor on |
---|
| 205 | * @param loadString ignored in this case |
---|
| 206 | */ |
---|
| 207 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 208 | { |
---|
| 209 | PRINTF(1)("no usefull executor\n"); |
---|
| 210 | } |
---|
[8271] | 211 | |
---|
[8711] | 212 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
| 213 | { |
---|
| 214 | lua_State* state = (lua_State*)values; |
---|
| 215 | count = 0; |
---|
[8271] | 216 | |
---|
[8711] | 217 | (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
| 218 | fromLua<type0>(state, 1), |
---|
| 219 | fromLua<type1>(state, 2), |
---|
| 220 | fromLua<type2>(state, 3) ); |
---|
| 221 | } |
---|
[8271] | 222 | |
---|
[8711] | 223 | /** |
---|
| 224 | * @returns a _new_ Copy of this Executor |
---|
| 225 | */ |
---|
| 226 | virtual Executor* clone () const |
---|
| 227 | { |
---|
| 228 | return new ExecutorLua3<T, type0, type1, type2>(this->functionPointer); |
---|
| 229 | } |
---|
| 230 | private: |
---|
| 231 | void (T::*functionPointer)(type0, type1, type2); |
---|
| 232 | }; |
---|
[8271] | 233 | |
---|
[8711] | 234 | |
---|
[8831] | 235 | /////////// |
---|
| 236 | //// 4 //// |
---|
| 237 | /////////// |
---|
| 238 | //! Executes a Function with a lua_State* parameter. |
---|
| 239 | template<class T, typename type0, typename type1, typename type2, typename type3> class ExecutorLua4 : public Executor |
---|
| 240 | { |
---|
| 241 | public: |
---|
| 242 | /** |
---|
| 243 | * @brief Constructor of a ExecutorXML |
---|
| 244 | * @param function a Function to call |
---|
| 245 | */ |
---|
| 246 | ExecutorLua4(void(T::*function)(type0, type1, type2, type3)) |
---|
| 247 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>()) |
---|
| 248 | { |
---|
| 249 | this->functionPointer = function; |
---|
| 250 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 251 | } |
---|
[8711] | 252 | |
---|
[8831] | 253 | /** |
---|
| 254 | * @brief executes the Command on BaseObject |
---|
| 255 | * @param object the BaseObject to execute this Executor on |
---|
| 256 | * @param loadString ignored in this case |
---|
| 257 | */ |
---|
| 258 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 259 | { |
---|
| 260 | PRINTF(1)("no usefull executor\n"); |
---|
| 261 | } |
---|
[8711] | 262 | |
---|
[8831] | 263 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
| 264 | { |
---|
| 265 | lua_State* state = (lua_State*)values; |
---|
| 266 | count = 0; |
---|
[8711] | 267 | |
---|
[8831] | 268 | (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
| 269 | fromLua<type0>(state, 1), |
---|
| 270 | fromLua<type1>(state, 2), |
---|
| 271 | fromLua<type2>(state, 3), |
---|
| 272 | fromLua<type3>(state, 4) ); |
---|
| 273 | } |
---|
[8711] | 274 | |
---|
[8831] | 275 | /** |
---|
| 276 | * @returns a _new_ Copy of this Executor |
---|
| 277 | */ |
---|
| 278 | virtual Executor* clone () const |
---|
| 279 | { |
---|
| 280 | return new ExecutorLua4<T, type0, type1, type2, type3>(this->functionPointer); |
---|
| 281 | } |
---|
| 282 | private: |
---|
| 283 | void (T::*functionPointer)(type0, type1, type2, type3); |
---|
| 284 | }; |
---|
| 285 | |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | |
---|
[8271] | 289 | //////////////////// |
---|
| 290 | ///// WITH RET ///// |
---|
| 291 | //////////////////// |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | /////////// |
---|
| 295 | //// 0 //// |
---|
| 296 | /////////// |
---|
| 297 | //! Executes a Function with a lua_State* parameter. |
---|
| 298 | template<class T, typename ret> class ExecutorLua0ret : public Executor |
---|
| 299 | { |
---|
| 300 | public: |
---|
| 301 | /** |
---|
| 302 | * @brief Constructor of a ExecutorXML |
---|
| 303 | * @param function a Function to call |
---|
| 304 | */ |
---|
| 305 | ExecutorLua0ret(ret (T::*function)()) |
---|
| 306 | : Executor() |
---|
| 307 | { |
---|
| 308 | this->functionPointer = function; |
---|
| 309 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 310 | } |
---|
[8711] | 311 | |
---|
[8271] | 312 | /** |
---|
| 313 | * @brief executes the Command on BaseObject |
---|
| 314 | * @param object the BaseObject to execute this Executor on |
---|
| 315 | * @param loadString ignored in this case |
---|
| 316 | */ |
---|
| 317 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 318 | { |
---|
| 319 | PRINTF(1)("no usefull executor\n"); |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
| 323 | { |
---|
| 324 | lua_State* state = (lua_State*)values; |
---|
| 325 | count = 1; |
---|
| 326 | |
---|
| 327 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))()); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | /** |
---|
| 331 | * @returns a _new_ Copy of this Executor |
---|
| 332 | */ |
---|
| 333 | virtual Executor* clone () const |
---|
| 334 | { |
---|
| 335 | return new ExecutorLua0ret<T, ret>(this->functionPointer); |
---|
| 336 | } |
---|
| 337 | private: |
---|
| 338 | ret (T::*functionPointer)(); |
---|
| 339 | }; |
---|
| 340 | |
---|
| 341 | |
---|
| 342 | |
---|
| 343 | /////////// |
---|
| 344 | //// 1 //// |
---|
| 345 | /////////// |
---|
| 346 | //! Executes a Function with a lua_State* parameter. |
---|
| 347 | template<class T, typename ret, typename type0> class ExecutorLua1ret : public Executor |
---|
| 348 | { |
---|
| 349 | public: |
---|
| 350 | /** |
---|
| 351 | * @brief Constructor of a ExecutorXML |
---|
| 352 | * @param function a Function to call |
---|
| 353 | */ |
---|
| 354 | ExecutorLua1ret(ret (T::*function)(type0)) |
---|
| 355 | : Executor(ExecutorParamType<type0>()) |
---|
| 356 | { |
---|
| 357 | this->functionPointer = function; |
---|
| 358 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | /** |
---|
| 362 | * @brief executes the Command on BaseObject |
---|
| 363 | * @param object the BaseObject to execute this Executor on |
---|
| 364 | * @param loadString ignored in this case |
---|
| 365 | */ |
---|
| 366 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 367 | { |
---|
| 368 | PRINTF(1)("no usefull executor\n"); |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
| 372 | { |
---|
| 373 | lua_State* state = (lua_State*)values; |
---|
| 374 | count = 1; |
---|
| 375 | |
---|
| 376 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
| 377 | fromLua<type0>(state, 1))); |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | /** |
---|
| 381 | * @returns a _new_ Copy of this Executor |
---|
| 382 | */ |
---|
| 383 | virtual Executor* clone () const |
---|
| 384 | { |
---|
| 385 | return new ExecutorLua1ret<T, ret, type0>(this->functionPointer); |
---|
| 386 | } |
---|
| 387 | private: |
---|
| 388 | ret (T::*functionPointer)(type0); |
---|
| 389 | }; |
---|
| 390 | |
---|
| 391 | /////////// |
---|
| 392 | //// 2 //// |
---|
| 393 | /////////// |
---|
| 394 | //! Executes a Function with a lua_State* parameter. |
---|
| 395 | template<class T, typename ret, typename type0, typename type1> class ExecutorLua2ret : public Executor |
---|
| 396 | { |
---|
| 397 | public: |
---|
| 398 | /** |
---|
| 399 | * @brief Constructor of a ExecutorXML |
---|
| 400 | * @param function a Function to call |
---|
| 401 | */ |
---|
| 402 | ExecutorLua2ret(ret (T::*function)(type0, type1)) |
---|
| 403 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>()) |
---|
| 404 | { |
---|
| 405 | this->functionPointer = function; |
---|
| 406 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | /** |
---|
| 410 | * @brief executes the Command on BaseObject |
---|
| 411 | * @param object the BaseObject to execute this Executor on |
---|
| 412 | * @param loadString ignored in this case |
---|
| 413 | */ |
---|
| 414 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 415 | { |
---|
| 416 | PRINTF(1)("no usefull executor\n"); |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
| 420 | { |
---|
| 421 | lua_State* state = (lua_State*)values; |
---|
| 422 | count = 1; |
---|
| 423 | |
---|
| 424 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
| 425 | fromLua<type0>(state, 1), |
---|
| 426 | fromLua<type1>(state, 2) )); |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | /** |
---|
| 430 | * @returns a _new_ Copy of this Executor |
---|
| 431 | */ |
---|
| 432 | virtual Executor* clone () const |
---|
| 433 | { |
---|
| 434 | return new ExecutorLua2ret<T, ret, type0, type1>(this->functionPointer); |
---|
| 435 | } |
---|
| 436 | private: |
---|
| 437 | ret (T::*functionPointer)(type0, type1); |
---|
| 438 | }; |
---|
| 439 | |
---|
[8815] | 440 | |
---|
[8808] | 441 | /////////// |
---|
[8815] | 442 | //// 3 //// |
---|
| 443 | /////////// |
---|
| 444 | //! Executes a Function with a lua_State* parameter. |
---|
| 445 | template<class T, typename ret, typename type0, typename type1, typename type2> class ExecutorLua3ret : public Executor |
---|
| 446 | { |
---|
| 447 | public: |
---|
| 448 | /** |
---|
| 449 | * @brief Constructor of a ExecutorXML |
---|
| 450 | * @param function a Function to call |
---|
| 451 | */ |
---|
| 452 | ExecutorLua3ret(ret (T::*function)(type0, type1, type2)) |
---|
| 453 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>()) |
---|
| 454 | { |
---|
| 455 | this->functionPointer = function; |
---|
| 456 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | /** |
---|
| 460 | * @brief executes the Command on BaseObject |
---|
| 461 | * @param object the BaseObject to execute this Executor on |
---|
| 462 | * @param loadString ignored in this case |
---|
| 463 | */ |
---|
| 464 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 465 | { |
---|
| 466 | PRINTF(1)("no usefull executor\n"); |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
| 470 | { |
---|
| 471 | lua_State* state = (lua_State*)values; |
---|
[8822] | 472 | count = 1; |
---|
[8815] | 473 | |
---|
| 474 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
| 475 | fromLua<type0>(state, 1), |
---|
[8822] | 476 | fromLua<type1>(state, 2), |
---|
| 477 | fromLua<type2>(state, 3) )); |
---|
[8815] | 478 | } |
---|
| 479 | |
---|
| 480 | /** |
---|
| 481 | * @returns a _new_ Copy of this Executor |
---|
| 482 | */ |
---|
| 483 | virtual Executor* clone () const |
---|
| 484 | { |
---|
| 485 | return new ExecutorLua3ret<T, ret, type0, type1, type2>(this->functionPointer); |
---|
| 486 | } |
---|
| 487 | private: |
---|
| 488 | ret (T::*functionPointer)(type0, type1, type2); |
---|
| 489 | }; |
---|
| 490 | |
---|
[8829] | 491 | |
---|
[8815] | 492 | /////////// |
---|
[8829] | 493 | //// 4 //// |
---|
| 494 | /////////// |
---|
| 495 | //! Executes a Function with a lua_State* parameter. |
---|
| 496 | template<class T, typename ret, typename type0, typename type1, typename type2, typename type3> class ExecutorLua4ret : public Executor |
---|
| 497 | { |
---|
| 498 | public: |
---|
| 499 | /** |
---|
| 500 | * @brief Constructor of a ExecutorXML |
---|
| 501 | * @param function a Function to call |
---|
| 502 | */ |
---|
| 503 | ExecutorLua4ret(ret (T::*function)(type0, type1, type2, type3)) |
---|
| 504 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>()) |
---|
| 505 | { |
---|
| 506 | this->functionPointer = function; |
---|
| 507 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | /** |
---|
| 511 | * @brief executes the Command on BaseObject |
---|
| 512 | * @param object the BaseObject to execute this Executor on |
---|
| 513 | * @param loadString ignored in this case |
---|
| 514 | */ |
---|
| 515 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 516 | { |
---|
| 517 | PRINTF(1)("no usefull executor\n"); |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
| 521 | { |
---|
| 522 | lua_State* state = (lua_State*)values; |
---|
| 523 | count = 1; |
---|
| 524 | |
---|
| 525 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
| 526 | fromLua<type0>(state, 1), |
---|
| 527 | fromLua<type1>(state, 2), |
---|
| 528 | fromLua<type2>(state, 3), |
---|
| 529 | fromLua<type3>(state, 4) )); |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | /** |
---|
| 533 | * @returns a _new_ Copy of this Executor |
---|
| 534 | */ |
---|
| 535 | virtual Executor* clone () const |
---|
| 536 | { |
---|
| 537 | return new ExecutorLua4ret<T, ret, type0, type1, type2, type3>(this->functionPointer); |
---|
| 538 | } |
---|
| 539 | private: |
---|
| 540 | ret (T::*functionPointer)(type0, type1, type2, type3); |
---|
| 541 | }; |
---|
| 542 | |
---|
| 543 | /////////// |
---|
[8830] | 544 | //// 5 //// |
---|
| 545 | /////////// |
---|
| 546 | //! Executes a Function with a lua_State* parameter. |
---|
| 547 | template<class T, typename ret, typename type0, typename type1, typename type2, typename type3, typename type4> class ExecutorLua5ret : public Executor |
---|
| 548 | { |
---|
| 549 | public: |
---|
| 550 | /** |
---|
| 551 | * @brief Constructor of a ExecutorXML |
---|
| 552 | * @param function a Function to call |
---|
| 553 | */ |
---|
| 554 | ExecutorLua5ret(ret (T::*function)(type0, type1, type2, type3, type4)) |
---|
| 555 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), ExecutorParamType<type2>(), ExecutorParamType<type3>(), ExecutorParamType<type4>()) |
---|
| 556 | { |
---|
| 557 | this->functionPointer = function; |
---|
| 558 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 559 | } |
---|
| 560 | |
---|
| 561 | /** |
---|
| 562 | * @brief executes the Command on BaseObject |
---|
| 563 | * @param object the BaseObject to execute this Executor on |
---|
| 564 | * @param loadString ignored in this case |
---|
| 565 | */ |
---|
| 566 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 567 | { |
---|
| 568 | PRINTF(1)("no usefull executor\n"); |
---|
| 569 | } |
---|
| 570 | |
---|
| 571 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
| 572 | { |
---|
| 573 | lua_State* state = (lua_State*)values; |
---|
| 574 | count = 1; |
---|
| 575 | |
---|
| 576 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
| 577 | fromLua<type0>(state, 1), |
---|
| 578 | fromLua<type1>(state, 2), |
---|
| 579 | fromLua<type2>(state, 3), |
---|
| 580 | fromLua<type3>(state, 4), |
---|
| 581 | fromLua<type4>(state, 5) )); |
---|
| 582 | } |
---|
| 583 | |
---|
| 584 | /** |
---|
| 585 | * @returns a _new_ Copy of this Executor |
---|
| 586 | */ |
---|
| 587 | virtual Executor* clone () const |
---|
| 588 | { |
---|
| 589 | return new ExecutorLua5ret<T, ret, type0, type1, type2, type3, type4>(this->functionPointer); |
---|
| 590 | } |
---|
| 591 | private: |
---|
| 592 | ret (T::*functionPointer)(type0, type1, type2, type3, type4); |
---|
| 593 | }; |
---|
| 594 | |
---|
| 595 | /////////// |
---|
[8808] | 596 | //// 6 //// |
---|
| 597 | /////////// |
---|
| 598 | //! Executes a Function with a lua_State* parameter. |
---|
| 599 | template<class T, typename ret, typename type0, typename type1, typename type2, typename type3, typename type4, typename type5> class ExecutorLua6ret : public Executor |
---|
| 600 | { |
---|
| 601 | public: |
---|
| 602 | /** |
---|
| 603 | * @brief Constructor of a ExecutorXML |
---|
| 604 | * @param function a Function to call |
---|
| 605 | */ |
---|
| 606 | ExecutorLua6ret(ret (T::*function)(type0, type1, type2, type3, type4, type5)) |
---|
| 607 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), |
---|
| 608 | ExecutorParamType<type2>(), ExecutorParamType<type3>(), |
---|
| 609 | ExecutorParamType<type4>(), ExecutorParamType<type5>()) |
---|
| 610 | { |
---|
| 611 | this->functionPointer = function; |
---|
| 612 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 613 | } |
---|
| 614 | |
---|
| 615 | /** |
---|
| 616 | * @brief executes the Command on BaseObject |
---|
| 617 | * @param object the BaseObject to execute this Executor on |
---|
| 618 | * @param loadString ignored in this case |
---|
| 619 | */ |
---|
| 620 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 621 | { |
---|
| 622 | PRINTF(1)("no usefull executor\n"); |
---|
| 623 | } |
---|
| 624 | |
---|
| 625 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
| 626 | { |
---|
| 627 | lua_State* state = (lua_State*)values; |
---|
| 628 | count = 1; |
---|
| 629 | |
---|
| 630 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
| 631 | fromLua<type0>(state, 1), |
---|
| 632 | fromLua<type1>(state, 2), |
---|
| 633 | fromLua<type2>(state, 3), |
---|
| 634 | fromLua<type3>(state, 4), |
---|
| 635 | fromLua<type4>(state, 5), |
---|
| 636 | fromLua<type5>(state, 6) )); |
---|
| 637 | } |
---|
| 638 | |
---|
| 639 | /** |
---|
| 640 | * @returns a _new_ Copy of this Executor |
---|
| 641 | */ |
---|
| 642 | virtual Executor* clone () const |
---|
| 643 | { |
---|
| 644 | return new ExecutorLua6ret<T, ret, type0, type1, type2, type3, type4, type5>(this->functionPointer); |
---|
| 645 | } |
---|
| 646 | private: |
---|
| 647 | ret (T::*functionPointer)(type0, type1, type2, type3, type4, type5); |
---|
| 648 | }; |
---|
| 649 | |
---|
| 650 | /////////// |
---|
| 651 | //// 7 //// |
---|
| 652 | /////////// |
---|
| 653 | //! Executes a Function with a lua_State* parameter. |
---|
| 654 | template<class T, typename ret, typename type0, typename type1, typename type2, typename type3, typename type4, typename type5, typename type6> class ExecutorLua7ret : public Executor |
---|
| 655 | { |
---|
| 656 | public: |
---|
| 657 | /** |
---|
| 658 | * @brief Constructor of a ExecutorXML |
---|
| 659 | * @param function a Function to call |
---|
| 660 | */ |
---|
| 661 | ExecutorLua7ret(ret (T::*function)(type0, type1, type2, type3, type4, type5, type6)) |
---|
| 662 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>(), |
---|
| 663 | ExecutorParamType<type2>(), ExecutorParamType<type3>(), |
---|
| 664 | ExecutorParamType<type4>(), ExecutorParamType<type5>(), |
---|
| 665 | ExecutorParamType<type6>()) |
---|
| 666 | { |
---|
| 667 | this->functionPointer = function; |
---|
| 668 | this->functorType = Executor_Objective | Executor_NoLoadString; |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | /** |
---|
| 672 | * @brief executes the Command on BaseObject |
---|
| 673 | * @param object the BaseObject to execute this Executor on |
---|
| 674 | * @param loadString ignored in this case |
---|
| 675 | */ |
---|
| 676 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
---|
| 677 | { |
---|
| 678 | PRINTF(1)("no usefull executor\n"); |
---|
| 679 | } |
---|
| 680 | |
---|
| 681 | virtual void operator()(BaseObject* object, int& count, void* values) const |
---|
| 682 | { |
---|
| 683 | lua_State* state = (lua_State*)values; |
---|
| 684 | count = 1; |
---|
| 685 | |
---|
| 686 | toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))( |
---|
| 687 | fromLua<type0>(state, 1), |
---|
| 688 | fromLua<type1>(state, 2), |
---|
| 689 | fromLua<type2>(state, 3), |
---|
| 690 | fromLua<type3>(state, 4), |
---|
| 691 | fromLua<type4>(state, 5), |
---|
[8830] | 692 | fromLua<type5>(state, 6), |
---|
| 693 | fromLua<type6>(state, 7) )); |
---|
[8808] | 694 | } |
---|
| 695 | |
---|
| 696 | /** |
---|
| 697 | * @returns a _new_ Copy of this Executor |
---|
| 698 | */ |
---|
| 699 | virtual Executor* clone () const |
---|
| 700 | { |
---|
| 701 | return new ExecutorLua7ret<T, ret, type0, type1, type2, type3, type4, type5, type6>(this->functionPointer); |
---|
| 702 | } |
---|
| 703 | private: |
---|
| 704 | ret (T::*functionPointer)(type0, type1, type2, type3, type4, type5, type6); |
---|
| 705 | }; |
---|
| 706 | |
---|
| 707 | |
---|
[8271] | 708 | #endif /* _EXECUTOR_LUA_H */ |
---|