Changeset 8057 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Jun 1, 2006, 1:30:11 PM (18 years ago)
- Location:
- trunk/src/lib/util/executor
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/executor/executor_lua.cc
r8051 r8057 18 18 #include "executor_lua.h" 19 19 20 template<> bool fromLua<bool>(lua_state* state ) { return lua_tonumber(state); };21 template<> int fromLua<int>(lua_state* state );22 template<> unsigned int fromLua<unsigned int>(lua_state* state );23 template<> float fromLua<float>(lua_state* state );24 template<> char fromLua<char>(lua_state* state );25 template<> const std::string& fromLua<const std::string&>(lua_state* state );20 template<> bool fromLua<bool>(lua_state* state, int index) { return lua_toboolean(state, index); }; 21 template<> int fromLua<int>(lua_state* state, int index) { return (int)lua_toumber(state, index); }; 22 template<> unsigned int fromLua<unsigned int>(lua_state* state, int index) { return (unsigned int)lua_tonumber(state, index); }; 23 template<> float fromLua<float>(lua_state* state, int index) { return (float)lua_tonumber(state, index); }; 24 template<> char fromLua<char>(lua_state* state, int index) { reutnr (char)lua_tonumber(state, index); }; 25 template<> const std::string& fromLua<const std::string&>(lua_state* state, int index) { return lua_tostring(state, index); }; 26 26 27 28 29 template<> void toLua<bool>(lua_state* state, bool value) { lua_pushboolean(state, (int) value); }; 30 template<> void toLua<int>(lua_state* state, int value) { lua_pushnumber(state, (lua_Number) value); }; 31 template<> void toLua<unsigned int>(lua_state* state, unsigned int value){ lua_pushnumber(state, (lua_Number) value); }; 32 template<> void toLua<float>(lua_state* state, float value) { lua_pushnumber(state, (lua_Number) value); }; 33 template<> void toLua<char>(lua_state* state, char value) { lua_pushnumber(state, (lua_Number) value); }; 34 template<> void toLua<const std::string&>(lua_state* state, const std::string& value) {lua_pushstring (state, value.c_str()); } -
trunk/src/lib/util/executor/executor_lua.h
r8051 r8057 14 14 15 15 16 template<typename type> type fromLua(lua_state* state) { PRINTF(1)("NOT IMPLEMENTED\n"); }; 17 template<> bool fromLua<bool>(lua_state* state); 18 template<> int fromLua<int>(lua_state* state); 19 template<> unsigned int fromLua<unsigned int>(lua_state* state); 20 template<> float fromLua<float>(lua_state* state); 21 template<> char fromLua<char>(lua_state* state); 22 template<> const std::string& fromLua<const std::string&>(lua_state* state); 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); 23 32 24 33 // FORWARD DECLARATION … … 31 40 template<class T> class ExecutorLua0 : public Executor 32 41 { 33 public:34 /**35 * @brief Constructor of a ExecutorXML36 * @param function a Function to call37 */38 ExecutorLua0(void(T::*function)())39 : Executor()40 {41 this->functionPointer = function;42 this->functorType = Executor_Objective | Executor_NoLoadString;43 }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 } 44 53 45 /**46 * @brief executes the Command on BaseObject47 * @param object the BaseObject to execute this Executor on48 * @param loadString ignored in this case49 */50 virtual void operator()(BaseObject* object, const SubString& = SubString()) const51 {52 PRINTF(1)("no usefull executor\n");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 } 54 63 55 virtual void operator()(BaseObject* object, unsigned int count, void* values) const56 {57 (dynamic_cast<T*>(object)->*(functionPointer))();58 }64 virtual void operator()(BaseObject* object, unsigned int count, void* values) const 65 { 66 (dynamic_cast<T*>(object)->*(functionPointer))(); 67 } 59 68 60 /**61 * @returns a _new_ Copy of this Executor62 */63 virtual Executor* clone () const64 {65 return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));66 }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 } 67 76 }; 68 77 … … 76 85 { 77 86 public: 78 /**79 * @brief Constructor of a ExecutorXML80 * @param function a Function to call81 */87 /** 88 * @brief Constructor of a ExecutorXML 89 * @param function a Function to call 90 */ 82 91 ExecutorLua0(void(T::*function)(type0)) 83 : Executor(ExecutorParamType<type0>())92 : Executor(ExecutorParamType<type0>()) 84 93 { 85 94 this->functionPointer = function; … … 87 96 } 88 97 89 /**90 * @brief executes the Command on BaseObject91 * @param object the BaseObject to execute this Executor on92 * @param loadString ignored in this case93 */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 */ 94 103 virtual void operator()(BaseObject* object, const SubString& = SubString()) const 95 104 { … … 100 109 { 101 110 lua_state* state = (lua_state*)values; 102 type0 value0 = lua_pop values103 111 104 (dynamic_cast<T*>(object)->*(functionPointer))( );112 (dynamic_cast<T*>(object)->*(functionPointer))(fromLua<type0>(state, 1)); 105 113 } 106 114 107 /**108 * @returns a _new_ Copy of this Executor109 */115 /** 116 * @returns a _new_ Copy of this Executor 117 */ 110 118 virtual Executor* clone () const 111 119 { … … 115 123 116 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 117 174 #endif /* _EXECUTOR_SPECIALS_H */
Note: See TracChangeset
for help on using the changeset viewer.