Changeset 9752 in orxonox.OLD for branches/new_class_id
- Timestamp:
- Sep 17, 2006, 2:43:41 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/util/executor
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/executor/executor.h
r9748 r9752 17 17 18 18 /** @returns the Type of an Argument taken by the Executor */ 19 template<typename type> MT_Type ExecutorParamType() { return MT_EXT1; }; 20 template<> MT_Type ExecutorParamType<bool>(); 21 template<> MT_Type ExecutorParamType<int>(); 22 template<> MT_Type ExecutorParamType<unsigned int>(); 23 template<> MT_Type ExecutorParamType<float>(); 24 template<> MT_Type ExecutorParamType<char>(); 25 template<> MT_Type ExecutorParamType<const std::string&>(); 19 template<typename type> inline MT_Type ExecutorParamType() { return MT_EXT1; }; 20 /** @returns the Type of an Argument taken by the Executor in this case MT_BOOL */ 21 template<> inline MT_Type ExecutorParamType<bool>() { return MT_BOOL; }; 22 /** @returns the Type of an Argument taken by the Executor in this case MT_INT*/ 23 template<> inline MT_Type ExecutorParamType<int>() { return MT_INT; }; 24 /** @returns the Type of an Argument taken by the Executor in this case MT_UINT*/ 25 template<> inline MT_Type ExecutorParamType<unsigned int>() { return MT_UINT; }; 26 /** @returns the Type of an Argument taken by the Executor in this case MT_FLOAT*/ 27 template<> inline MT_Type ExecutorParamType<float>() { return MT_FLOAT; }; 28 /** @returns the Type of an Argument taken by the Executor in this case MT_CHAR*/ 29 template<> inline MT_Type ExecutorParamType<char>() { return MT_CHAR; }; 30 /** @returns the Type of an Argument taken by the Executor in this case MT_STRING*/ 31 template<> inline MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; }; 26 32 27 33 //////////////// -
branches/new_class_id/src/lib/util/executor/executor_lua_state.cc
r9748 r9752 22 22 std::string temp[7]; 23 23 24 /**25 * @brief Converts a lua_State into any type.26 * @param state the State to get the value from.27 * @param index the position inside of the lua_State to get the value from.28 * @returns The value if found.29 */30 template<typename type> type fromLua(lua_State* state, int index) { type *obj = Lunar<type>::check(state, 1); lua_remove(state, 1); return obj;};31 /**32 * @brief Converts a lua_State into any type.33 * @param state the State to get the value from.34 * @param index the position inside of the lua_State to get the value from.35 * @returns The value if found.36 */37 template<> bool fromLua<bool>(lua_State* state, int index) { return lua_toboolean(state, index); };38 /**39 * @brief Converts a lua_State into any type.40 * @param state the State to get the value from.41 * @param index the position inside of the lua_State to get the value from.42 * @returns The value if found.43 */44 template<> int fromLua<int>(lua_State* state, int index) { return (int)lua_tonumber(state, index); };45 /**46 * @brief Converts a lua_State into any type.47 * @param state the State to get the value from.48 * @param index the position inside of the lua_State to get the value from.49 * @returns The value if found.50 */51 template<> unsigned int fromLua<unsigned int>(lua_State* state, int index) { return (unsigned int)lua_tonumber(state, index); };52 /**53 * @brief Converts a lua_State into any type.54 * @param state the State to get the value from.55 * @param index the position inside of the lua_State to get the value from.56 * @returns The value if found.57 */58 template<> float fromLua<float>(lua_State* state, int index) { return (float)lua_tonumber(state, index); };59 /**60 * @brief Converts a lua_State into any type.61 * @param state the State to get the value from.62 * @param index the position inside of the lua_State to get the value from.63 * @returns The value if found.64 */65 template<> char fromLua<char>(lua_State* state, int index) { return (char)lua_tonumber(state, index); };66 /**67 * @brief Converts a lua_State into any type.68 * @param state the State to get the value from.69 * @param index the position inside of the lua_State to get the value from.70 * @returns The value if found.71 */72 template<> const std::string& fromLua<const std::string&>(lua_State* state, int index) { temp[index] = lua_tostring(state, index); return temp[index]; };73 24 25 template<typename type> inline type fromLua(lua_State* state, int index) { type *obj = Lunar<type>::check(state, 1); lua_remove(state, 1); return obj; }; 74 26 75 76 77 /**78 * @brief writes a value into a lua_State.79 * @param state the state to write into.80 * @param value the Value of type to write into the State.81 */82 27 template<typename type> void toLua(lua_State* state, type value) { Lunar<type>::push(state, value, false); }; 83 /** 84 * @brief writes a value into a lua_State. 85 * @param state the state to write into. 86 * @param value the Value of type to write into the State. 87 */ 88 template<> void toLua<bool>(lua_State* state, bool value) { lua_pushboolean(state, (int) value); }; 89 /** 90 * @brief writes a value into a lua_State. 91 * @param state the state to write into. 92 * @param value the Value of type to write into the State. 93 */ 94 template<> void toLua<int>(lua_State* state, int value) { lua_pushnumber(state, (lua_Number) value); }; 95 /** 96 * @brief writes a value into a lua_State. 97 * @param state the state to write into. 98 * @param value the Value of type to write into the State. 99 */ 100 template<> void toLua<unsigned int>(lua_State* state, unsigned int value){ lua_pushnumber(state, (lua_Number) value); }; 101 /** 102 * @brief writes a value into a lua_State. 103 * @param state the state to write into. 104 * @param value the Value of type to write into the State. 105 */ 106 template<> void toLua<float>(lua_State* state, float value) { lua_pushnumber(state, (lua_Number) value); }; 107 /** 108 * @brief writes a value into a lua_State. 109 * @param state the state to write into. 110 * @param value the Value of type to write into the State. 111 */ 112 template<> void toLua<char>(lua_State* state, char value) { lua_pushnumber(state, (lua_Number) value); }; 113 /** 114 * @brief writes a value into a lua_State. 115 * @param state the state to write into. 116 * @param value the Value of type to write into the State. 117 */ 118 template<> void toLua<const std::string&>(lua_State* state, const std::string& value) { lua_pushstring (state, value.c_str()); } 28 /** @see template<typename type> inline type fromLua(lua_State* state, int index) */ 29 template<> inline const std::string& fromLua<const std::string&>(lua_State* state, int index) { temp[index] = lua_tostring(state, index); return temp[index]; }; -
branches/new_class_id/src/lib/util/executor/executor_lua_state.h
r9748 r9752 35 35 #define FUNCTOR_CALL_TYPE lua_State* 36 36 37 /** 38 * @brief Converts a lua_State into any type. 39 * @param state the State to get the value from. 40 * @param index the position inside of the lua_State to get the value from. 41 * @returns The value if found. 42 */ 37 43 template<typename type> type fromLua(lua_State* state, int index); 38 template<> bool fromLua<bool>(lua_State* state, int index); 39 template<> int fromLua<int>(lua_State* state, int index); 40 template<> unsigned int fromLua<unsigned int>(lua_State* state, int index); 41 template<> float fromLua<float>(lua_State* state, int index); 42 template<> char fromLua<char>(lua_State* state, int index); 43 template<> const std::string& fromLua<const std::string&>(lua_State* state, int index); 44 /** @see template<typename type> inline type fromLua(lua_State* state, int index) */ 45 template<> inline bool fromLua<bool>(lua_State* state, int index) { return lua_toboolean(state, index); }; 46 /** @see template<typename type> inline type fromLua(lua_State* state, int index) */ 47 template<> inline int fromLua<int>(lua_State* state, int index) { return (int)lua_tonumber(state, index); }; 48 /** @see template<typename type> inline type fromLua(lua_State* state, int index) */ 49 template<> inline unsigned int fromLua<unsigned int>(lua_State* state, int index) { return (unsigned int)lua_tonumber(state, index); }; 50 /** @see template<typename type> inline type fromLua(lua_State* state, int index) */ 51 template<> inline float fromLua<float>(lua_State* state, int index) { return (float)lua_tonumber(state, index); }; 52 /** @see template<typename type> inline type fromLua(lua_State* state, int index) */ 53 template<> inline char fromLua<char>(lua_State* state, int index) { return (char)lua_tonumber(state, index); }; 44 54 55 56 /** 57 * @brief writes a value into a lua_State. 58 * @param state the state to write into. 59 * @param value the Value of type to write into the State. 60 */ 45 61 template<typename type> void toLua(lua_State* state, type value); 46 template<> void toLua<bool>(lua_State* state, bool value); 47 template<> void toLua<int>(lua_State* state, int value); 48 template<> void toLua<unsigned int>(lua_State* state, unsigned int value); 49 template<> void toLua<float>(lua_State* state, float value); 50 template<> void toLua<char>(lua_State* state, char value); 51 template<> void toLua<const std::string&>(lua_State* state, const std::string& value); 62 /** @see template<typename type> void toLua(lua_State* state, type value) */ 63 template<> inline void toLua<bool>(lua_State* state, bool value) { lua_pushboolean(state, (int) value); }; 64 /** @see template<typename type> void toLua(lua_State* state, type value) */ 65 template<> inline void toLua<int>(lua_State* state, int value) { lua_pushnumber(state, (lua_Number) value); }; 66 /** @see template<typename type> void toLua(lua_State* state, type value) */ 67 template<> inline void toLua<unsigned int>(lua_State* state, unsigned int value){ lua_pushnumber(state, (lua_Number) value); }; 68 /** @see template<typename type> void toLua(lua_State* state, type value) */ 69 template<> inline void toLua<float>(lua_State* state, float value) { lua_pushnumber(state, (lua_Number) value); }; 70 /** @see template<typename type> void toLua(lua_State* state, type value) */ 71 template<> inline void toLua<char>(lua_State* state, char value) { lua_pushnumber(state, (lua_Number) value); }; 72 /** @see template<typename type> void toLua(lua_State* state, type value) */ 73 template<> inline void toLua<const std::string&>(lua_State* state, const std::string& value) { lua_pushstring (state, value.c_str()); } 74 75 52 76 53 77 //! A Class, that evaluates a lua_State and converts indices into different Types.
Note: See TracChangeset
for help on using the changeset viewer.