Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Applied changes to the real sandbox this time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/src/libraries/core/LuaState.cc

    r5759 r5782  
    3030#include "LuaState.h"
    3131
     32#include <boost/filesystem.hpp>
    3233#include <tolua/tolua++.h>
    3334extern "C" {
     
    3839#include "util/Debug.h"
    3940#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;
    7573
    7674        // Push 'this' pointer
     
    8785    }
    8886
    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)
    9088    {
    9189        shared_ptr<ResourceInfo> sourceInfo;
    92         if (resourceGroup != "NoResourceGroupProvided")
    93             sourceInfo = Resource::getInfo(filename, resourceGroup);
     90        sourceInfo = this->getFileInfo(filename);
    9491
    9592        // Continue search if not explicitely forbidden
     
    9794        {
    9895            // 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);
    10097            if (sourceInfo == NULL)
    10198            {
    10299                // Maybe find something in the same group but in the root path
    103                 sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group);
     100                sourceInfo = this->getFileInfo(filename);
    104101            }
    105102        }
     
    107104    }
    108105
    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);
    112132        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;
    117136    }
    118137
     
    129148    }
    130149
    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);
    134153        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;
    139157    }
    140158
     
    186204    }
    187205
    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);
    191209        if (info == NULL)
    192210            return false;
Note: See TracChangeset for help on using the changeset viewer.