Changeset 956
- Timestamp:
- Mar 30, 2008, 4:03:19 AM (17 years ago)
- Location:
- code/branches/script
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/script/cmake/FindLua.cmake
r954 r956 23 23 /usr/local/lib) 24 24 25 ADD_DEFINITIONS(-DLUA_VERSION=51)26 27 25 IF (NOT Lua_LIBRARIES AND Lua_INCLUDE_DIR) 28 26 FIND_PATH(Lua_INCLUDE_DIR lua.h … … 42 40 43 41 SET(Lua_LIBRARIES ${Lua_LIBRARIES} ${Lua_LIBRARY}) 44 ADD_DEFINITIONS(-DLUA_VERSION=50)45 42 46 43 ENDIF (NOT Lua_LIBRARIES AND Lua_INCLUDE_DIR) -
code/branches/script/src/orxonox/script/Script.cc
r954 r956 27 27 28 28 #include "Script.h" 29 30 #include <fstream> 31 29 32 extern "C" { 30 33 #include "lualib.h" … … 37 40 Script::Script() 38 41 { 42 fileLines_ = std::list<std::string>(); 43 39 44 state_ = lua_open(); 40 #if L ua_VERSION == 5145 #if LUA_VERSION_NUM == 501 41 46 luaL_openlibs(state_); 42 47 #else … … 55 60 } 56 61 62 /** 63 @brief Loads the specified file line by line 64 @param filename The filename of the file 65 */ 66 void Script::loadFile(std::string filename) 67 { 68 std::ifstream file; 69 file.open(filename.c_str(), std::fstream::in); 70 71 if (!file.is_open()) 72 { 73 // some error msg 74 } 75 76 char line[1024]; 77 78 while (file.good() && !file.eof()) 79 { 80 file.getline(line, 1024); 81 this->fileLines_.push_back(line); 82 } 83 84 // The last line is useless 85 this->fileLines_.pop_back(); 86 87 file.close(); 88 } 89 90 /** 91 @brief Parses the level file to correct Lua code 92 */ 93 void Script::xmlToLua() 94 { 95 // We will iterate through all the lines and replace things. 96 std::list<std::string>::iterator it; 97 for(it = this->fileLines_.begin(); it != this->fileLines_.end(); ++it) 98 { 99 int pos = (*it).find("<?lua"); 100 while (pos < (int)(*it).length()) 101 { 102 // We found a lua tag 103 std::string front = (*it).substr(0,pos); 104 std::string back = (*it).substr(pos + 5); 105 (*it) = front + "]])" + back; 106 pos = (*it).find("<?lua"); 107 } 108 109 pos = (*it).find("?>"); 110 while (pos < (int)(*it).length()) 111 { 112 // We found a lua tag 113 std::string front = (*it).substr(0,pos); 114 std::string back = (*it).substr(pos + 2); 115 (*it) = front + "print([[" + back; 116 pos = (*it).find("?>"); 117 } 118 } 119 this->fileLines_.push_front("print([["); 120 this->fileLines_.push_back("]])"); 121 } 122 57 123 } -
code/branches/script/src/orxonox/script/Script.h
r954 r956 12 12 } 13 13 14 #include <list> 15 #include <string> 16 14 17 namespace orxonox 15 18 { … … 20 23 ~Script(); 21 24 25 void loadFile(std::string filename); 26 void xmlToLua(); 27 22 28 inline lua_State* getLuaState() { return state_; }; 23 29 24 30 private: 31 32 //std::list<std::string>& getLevelFileLines(); 33 34 std::list<std::string> fileLines_; 25 35 lua_State* state_; 26 36
Note: See TracChangeset
for help on using the changeset viewer.