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