Changeset 5782 for sandbox/src/libraries/core/LuaState.cc
- Timestamp:
- Sep 24, 2009, 11:32:39 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/src/libraries/core/LuaState.cc
r5759 r5782 30 30 #include "LuaState.h" 31 31 32 #include <boost/filesystem.hpp> 32 33 #include <tolua/tolua++.h> 33 34 extern "C" { … … 38 39 #include "util/Debug.h" 39 40 #include "Core.h" 40 #include "Resource.h"41 41 #include "ToluaBindCore.h" 42 42 … … 71 71 // Create dummy file info 72 72 sourceFileInfo_.reset(new ResourceInfo()); 73 sourceFileInfo_->group = "General";74 sourceFileInfo_->size = 0;75 73 76 74 // Push 'this' pointer … … 87 85 } 88 86 89 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, const std::string& resourceGroup,bool bSearchOtherPaths)87 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, bool bSearchOtherPaths) 90 88 { 91 89 shared_ptr<ResourceInfo> sourceInfo; 92 if (resourceGroup != "NoResourceGroupProvided") 93 sourceInfo = Resource::getInfo(filename, resourceGroup); 90 sourceInfo = this->getFileInfo(filename); 94 91 95 92 // Continue search if not explicitely forbidden … … 97 94 { 98 95 // Call might be relative to the file currently being processed 99 sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename, sourceFileInfo_->group);96 sourceInfo = this->getFileInfo(sourceFileInfo_->path + filename); 100 97 if (sourceInfo == NULL) 101 98 { 102 99 // Maybe find something in the same group but in the root path 103 sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group);100 sourceInfo = this->getFileInfo(filename); 104 101 } 105 102 } … … 107 104 } 108 105 109 void LuaState::includeFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths) 110 { 111 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths); 106 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename) 107 { 108 boost::filesystem::path filepath = Core::getDataPath() / "lua" / filename; 109 if (boost::filesystem::exists(filepath)) 110 { 111 shared_ptr<ResourceInfo> info(new ResourceInfo()); 112 info->filename = filepath.string(); 113 info->path = filepath.branch_path().string(); 114 info->basename = filepath.leaf(); 115 return info; 116 } 117 else 118 return shared_ptr<ResourceInfo>(); 119 } 120 121 std::string LuaState::loadFile(const std::string& filename) 122 { 123 std::ifstream file(filename.c_str()); 124 std::ostringstream oss; 125 oss << file.rdbuf(); 126 return oss.str(); 127 } 128 129 void LuaState::includeFile(const std::string& filename, bool bSearchOtherPaths) 130 { 131 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, bSearchOtherPaths); 112 132 if (sourceInfo != NULL) 113 this->includeString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo); 114 else 115 COUT(2) << "LuaState: Cannot include file '" << filename << "' in resource group '" 116 << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl; 133 this->includeString(this->loadFile(sourceInfo->filename), sourceInfo); 134 else 135 COUT(2) << "LuaState: Cannot include file '" << filename << std::endl; 117 136 } 118 137 … … 129 148 } 130 149 131 void LuaState::doFile(const std::string& filename, const std::string& resourceGroup,bool bSearchOtherPaths)132 { 133 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup,bSearchOtherPaths);150 void LuaState::doFile(const std::string& filename, bool bSearchOtherPaths) 151 { 152 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, bSearchOtherPaths); 134 153 if (sourceInfo != NULL) 135 this->doString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo); 136 else 137 COUT(2) << "LuaState: Cannot do file '" << filename << "' in resource group '" 138 << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl; 154 this->doString(this->loadFile(sourceInfo->filename), sourceInfo); 155 else 156 COUT(2) << "LuaState: Cannot do file '" << filename << std::endl; 139 157 } 140 158 … … 186 204 } 187 205 188 bool LuaState::fileExists(const std::string& filename, const std::string& resourceGroup,bool bSearchOtherPaths)189 { 190 shared_ptr<ResourceInfo> info = this->getFileInfo(filename, resourceGroup,bSearchOtherPaths);206 bool LuaState::fileExists(const std::string& filename, bool bSearchOtherPaths) 207 { 208 shared_ptr<ResourceInfo> info = this->getFileInfo(filename, bSearchOtherPaths); 191 209 if (info == NULL) 192 210 return false;
Note: See TracChangeset
for help on using the changeset viewer.