Changeset 6412 for code/branches/pickup2/src/libraries/core/LuaState.cc
- Timestamp:
- Dec 25, 2009, 1:18:03 PM (15 years ago)
- Location:
- code/branches/pickup2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2
- Property svn:mergeinfo changed
-
code/branches/pickup2/src/libraries/core/LuaState.cc
r5929 r6412 86 86 } 87 87 88 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths) 89 { 90 shared_ptr<ResourceInfo> sourceInfo; 91 if (resourceGroup != "NoResourceGroupProvided") 92 sourceInfo = Resource::getInfo(filename, resourceGroup); 93 94 // Continue search if not explicitely forbidden 95 if (bSearchOtherPaths && sourceInfo == NULL) 96 { 97 // Call might be relative to the file currently being processed 98 sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename, sourceFileInfo_->group); 99 if (sourceInfo == NULL) 100 { 101 // Maybe find something in the same group but in the root path 102 sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group); 103 } 104 } 88 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename) 89 { 90 // Look in the current directory first 91 shared_ptr<ResourceInfo> sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename); 92 // Continue search in root directories 93 if (sourceInfo == NULL && !sourceFileInfo_->path.empty()) 94 sourceInfo = Resource::getInfo(filename); 105 95 return sourceInfo; 106 96 } 107 97 108 void LuaState::includeFile(const std::string& filename , const std::string& resourceGroup, bool bSearchOtherPaths)109 { 110 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename , resourceGroup, bSearchOtherPaths);98 void LuaState::includeFile(const std::string& filename) 99 { 100 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename); 111 101 if (sourceInfo != NULL) 112 this->includeString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo); 113 else 114 COUT(2) << "LuaState: Cannot include file '" << filename << "' in resource group '" 115 << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl; 116 } 117 118 void LuaState::includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo) 102 this->includeString(Resource::open(sourceInfo)->getAsString(), sourceInfo); 103 else 104 COUT(2) << "LuaState: Cannot include file '" << filename << "'." << std::endl; 105 } 106 107 void LuaState::includeString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo) 119 108 { 120 109 // Parse string with provided include parser (otherwise don't preparse at all) … … 128 117 } 129 118 130 void LuaState::doFile(const std::string& filename , const std::string& resourceGroup, bool bSearchOtherPaths)131 { 132 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename , resourceGroup, bSearchOtherPaths);119 void LuaState::doFile(const std::string& filename) 120 { 121 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename); 133 122 if (sourceInfo != NULL) 134 this->doString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo); 135 else 136 COUT(2) << "LuaState: Cannot do file '" << filename << "' in resource group '" 137 << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl; 138 } 139 140 void LuaState::doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo) 141 { 142 // Save the oold source file info 123 this->doString(Resource::open(sourceInfo)->getAsString(), sourceInfo); 124 else 125 COUT(2) << "LuaState: Cannot do file '" << filename << "'." << std::endl; 126 } 127 128 void LuaState::doString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo) 129 { 130 // Save the old source file info 143 131 shared_ptr<ResourceInfo> oldSourceFileInfo = sourceFileInfo_; 144 132 // Only override if sourceFileInfo provides useful information … … 164 152 if (sourceFileInfo != NULL) 165 153 origin = " originating from " + sourceFileInfo_->filename; 166 COUT( 2) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl;154 COUT(1) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl; 167 155 // return value is nil 168 156 lua_pushnil(luaState_); … … 182 170 void LuaState::luaLog(unsigned int level, const std::string& message) 183 171 { 184 OutputHandler::getOutStream( ).setOutputLevel(level) << message << std::endl;185 } 186 187 bool LuaState::fileExists(const std::string& filename , const std::string& resourceGroup, bool bSearchOtherPaths)188 { 189 shared_ptr<ResourceInfo> info = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);172 OutputHandler::getOutStream(level) << message << std::endl; 173 } 174 175 bool LuaState::fileExists(const std::string& filename) 176 { 177 shared_ptr<ResourceInfo> info = this->getFileInfo(filename); 190 178 if (info == NULL) 191 179 return false; … … 263 251 } 264 252 } 253 254 255 LuaFunctor::LuaFunctor(const std::string& code, LuaState* luaState) 256 { 257 this->code_ = code; 258 this->lua_ = luaState; 259 } 260 261 void LuaFunctor::operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) 262 { 263 lua_->doString(this->code_); 264 } 265 265 }
Note: See TracChangeset
for help on using the changeset viewer.