Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 24, 2009, 11:02:42 AM (15 years ago)
Author:
rgrieder
Message:

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/LuaState.cc

    r5774 r5781  
    3030#include "LuaState.h"
    3131
    32 #include <boost/filesystem.hpp>
    3332#include <tolua/tolua++.h>
    3433extern "C" {
     
    3938#include "util/Debug.h"
    4039#include "Core.h"
     40#include "Resource.h"
    4141#include "ToluaBindCore.h"
    4242
     
    7171        // Create dummy file info
    7272        sourceFileInfo_.reset(new ResourceInfo());
     73        sourceFileInfo_->group = "General";
     74        sourceFileInfo_->size = 0;
    7375
    7476        // Push 'this' pointer
     
    8587    }
    8688
    87     shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, bool bSearchOtherPaths)
     89    shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
    8890    {
    8991        shared_ptr<ResourceInfo> sourceInfo;
    90         sourceInfo = this->getFileInfo(filename);
     92        if (resourceGroup != "NoResourceGroupProvided")
     93            sourceInfo = Resource::getInfo(filename, resourceGroup);
    9194
    9295        // Continue search if not explicitely forbidden
     
    9497        {
    9598            // Call might be relative to the file currently being processed
    96             sourceInfo = this->getFileInfo(sourceFileInfo_->path + filename);
     99            sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename, sourceFileInfo_->group);
    97100            if (sourceInfo == NULL)
    98101            {
    99102                // Maybe find something in the same group but in the root path
    100                 sourceInfo = this->getFileInfo(filename);
     103                sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group);
    101104            }
    102105        }
     
    104107    }
    105108
    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);
     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);
    132112        if (sourceInfo != NULL)
    133             this->includeString(this->loadFile(sourceInfo->filename), sourceInfo);
    134         else
    135             COUT(2) << "LuaState: Cannot include file '" << filename << std::endl;
     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;
    136117    }
    137118
     
    148129    }
    149130
    150     void LuaState::doFile(const std::string& filename, bool bSearchOtherPaths)
    151     {
    152         shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, bSearchOtherPaths);
     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);
    153134        if (sourceInfo != NULL)
    154             this->doString(this->loadFile(sourceInfo->filename), sourceInfo);
    155         else
    156             COUT(2) << "LuaState: Cannot do file '" << filename << std::endl;
     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;
    157139    }
    158140
     
    204186    }
    205187
    206     bool LuaState::fileExists(const std::string& filename, bool bSearchOtherPaths)
    207     {
    208         shared_ptr<ResourceInfo> info =  this->getFileInfo(filename, bSearchOtherPaths);
     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);
    209191        if (info == NULL)
    210192            return false;
Note: See TracChangeset for help on using the changeset viewer.