| 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 | |
|---|
| 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, unsigned int count, void* values) const |
|---|
| 65 | { |
|---|
| 66 | (dynamic_cast<T*>(object)->*(functionPointer))(); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | /** |
|---|
| 70 | * @returns a _new_ Copy of this Executor |
|---|
| 71 | */ |
|---|
| 72 | virtual Executor* clone () const |
|---|
| 73 | { |
|---|
| 74 | return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer)); |
|---|
| 75 | } |
|---|
| 76 | }; |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | /////////// |
|---|
| 81 | //// 1 //// |
|---|
| 82 | /////////// |
|---|
| 83 | //! Executes a Function with a lua_state* parameter. |
|---|
| 84 | template<class T, typename type0> class ExecutorLua1 : public Executor |
|---|
| 85 | { |
|---|
| 86 | public: |
|---|
| 87 | /** |
|---|
| 88 | * @brief Constructor of a ExecutorXML |
|---|
| 89 | * @param function a Function to call |
|---|
| 90 | */ |
|---|
| 91 | ExecutorLua0(void(T::*function)(type0)) |
|---|
| 92 | : Executor(ExecutorParamType<type0>()) |
|---|
| 93 | { |
|---|
| 94 | this->functionPointer = function; |
|---|
| 95 | this->functorType = Executor_Objective | Executor_NoLoadString; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | /** |
|---|
| 99 | * @brief executes the Command on BaseObject |
|---|
| 100 | * @param object the BaseObject to execute this Executor on |
|---|
| 101 | * @param loadString ignored in this case |
|---|
| 102 | */ |
|---|
| 103 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
|---|
| 104 | { |
|---|
| 105 | PRINTF(1)("no usefull executor\n"); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | virtual void operator()(BaseObject* object, unsigned int count, void* values) const |
|---|
| 109 | { |
|---|
| 110 | lua_state* state = (lua_state*)values; |
|---|
| 111 | |
|---|
| 112 | (dynamic_cast<T*>(object)->*(functionPointer))(fromLua<type0>(state, 1)); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | /** |
|---|
| 116 | * @returns a _new_ Copy of this Executor |
|---|
| 117 | */ |
|---|
| 118 | virtual Executor* clone () const |
|---|
| 119 | { |
|---|
| 120 | return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer)); |
|---|
| 121 | } |
|---|
| 122 | }; |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | /////////// |
|---|
| 127 | //// 2 //// |
|---|
| 128 | /////////// |
|---|
| 129 | //! Executes a Function with a lua_state* parameter. |
|---|
| 130 | template<class T, typename type0, typename type1> class ExecutorLua1 : public Executor |
|---|
| 131 | { |
|---|
| 132 | public: |
|---|
| 133 | /** |
|---|
| 134 | * @brief Constructor of a ExecutorXML |
|---|
| 135 | * @param function a Function to call |
|---|
| 136 | */ |
|---|
| 137 | ExecutorLua0(void(T::*function)(type0, type1)) |
|---|
| 138 | : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>()) |
|---|
| 139 | { |
|---|
| 140 | this->functionPointer = function; |
|---|
| 141 | this->functorType = Executor_Objective | Executor_NoLoadString; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | /** |
|---|
| 145 | * @brief executes the Command on BaseObject |
|---|
| 146 | * @param object the BaseObject to execute this Executor on |
|---|
| 147 | * @param loadString ignored in this case |
|---|
| 148 | */ |
|---|
| 149 | virtual void operator()(BaseObject* object, const SubString& = SubString()) const |
|---|
| 150 | { |
|---|
| 151 | PRINTF(1)("no usefull executor\n"); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | virtual void operator()(BaseObject* object, unsigned int count, void* values) const |
|---|
| 155 | { |
|---|
| 156 | lua_state* state = (lua_state*)values; |
|---|
| 157 | |
|---|
| 158 | (dynamic_cast<T*>(object)->*(functionPointer))( |
|---|
| 159 | fromLua<type0>(state, 1), |
|---|
| 160 | fromLua<type1>(state, 2) ); |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | /** |
|---|
| 164 | * @returns a _new_ Copy of this Executor |
|---|
| 165 | */ |
|---|
| 166 | virtual Executor* clone () const |
|---|
| 167 | { |
|---|
| 168 | return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer)); |
|---|
| 169 | } |
|---|
| 170 | }; |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | #endif /* _EXECUTOR_SPECIALS_H */ |
|---|