Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1194


Ignore:
Timestamp:
Apr 27, 2008, 4:54:31 PM (16 years ago)
Author:
landauf
Message:

tcl can now initialize itself by loading the *.tcl files from media/tcl

Location:
code/branches/console/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/CommandExecutor.cc

    r1189 r1194  
    339339    }
    340340
     341    const CommandEvaluation& CommandExecutor::getLastEvaluation()
     342    {
     343        return CommandExecutor::getInstance().evaluation_;
     344    }
     345
    341346    Executor& CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)
    342347    {
     
    385390    bool CommandExecutor::execute(const CommandEvaluation& evaluation)
    386391    {
    387 std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n";
    388392        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    389393
    390394        if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_)
    391395        {
     396std::cout << "CE_execute (evaluation): " << evaluation.evaluatedExecutor_->getName() << " " << evaluation.param_[0] << " " << evaluation.param_[1] << " " << evaluation.param_[2] << " " << evaluation.param_[3] << " " << evaluation.param_[4] << std::endl;
    392397            (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]);
    393398            return true;
    394399        }
    395400
     401std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n";
    396402        switch (evaluation.state_)
    397403        {
     
    643649            lastToken = lastToken.substr(0, lastToken.size() - 1);
    644650            CommandExecutor::getEvaluation().tokens_.pop_back();
    645             CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " "));
     651            CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " ", "", true, '\0', false, '\0', false, '\0', '\0', false, '\0'));
    646652        }
    647653
  • code/branches/console/src/core/CommandExecutor.h

    r1187 r1194  
    142142            static CommandEvaluation evaluate(const std::string& command);
    143143
     144            static const CommandEvaluation& getLastEvaluation();
     145
    144146            static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);
    145147            static ExecutorStatic* getConsoleCommandShortcut(const std::string& name);
  • code/branches/console/src/core/TclBind.cc

    r1189 r1194  
    3737namespace orxonox
    3838{
    39     ConsoleCommandShortcutExtern(tcl, AccessLevel::None);
     39    ConsoleCommandShortcutGeneric(tcl, createExecutor(createFunctor(&TclBind::tcl), "tcl", AccessLevel::None));
    4040
    41     void Tcl_puts(Tcl::object const &args)
     41    TclBind::TclBind()
     42    {
     43        this->interpreter_ = 0;
     44        this->bSetTclLibPath_ = false;
     45    }
     46
     47    TclBind::~TclBind()
     48    {
     49        if (this->interpreter_)
     50            delete this->interpreter_;
     51    }
     52
     53    TclBind& TclBind::getInstance()
     54    {
     55        static TclBind instance;
     56        return instance;
     57    }
     58
     59    void TclBind::setDataPath(const std::string& datapath)
     60    {
     61        this->tclLibPath_ = datapath + "/tcl";
     62        this->bSetTclLibPath_ = true;
     63
     64        this->createTclInterpreter();
     65    }
     66
     67    void TclBind::createTclInterpreter()
     68    {
     69        if (this->bSetTclLibPath_ && !this->interpreter_)
     70        {
     71            this->interpreter_ = new Tcl::interpreter(this->tclLibPath_);
     72            this->interpreter_->def("puts", TclBind::puts, Tcl::variadic());
     73            this->interpreter_->def("execute", TclBind::execute, Tcl::variadic());
     74            this->interpreter_->eval("proc unknown {args} { return [execute $args] }");
     75        }
     76    }
     77
     78    void TclBind::createNewTclInterpreter()
     79    {
     80        if (this->interpreter_)
     81        {
     82            delete this->interpreter_;
     83            this->interpreter_ = 0;
     84        }
     85
     86        this->createTclInterpreter();
     87    }
     88
     89    void TclBind::puts(Tcl::object const &args)
    4290    {
    4391        COUT(0) << args.get() << std::endl;
    4492    }
    4593
    46     std::string Tcl_execute(Tcl::object const &args)
     94    std::string TclBind::execute(Tcl::object const &args)
    4795    {
    4896std::cout << "Tcl_execute: args: " << args.get() << std::endl;
     
    52100            command = command.substr(1, command.size() - 2);
    53101
    54         CommandEvaluation evaluation = CommandExecutor::evaluate(command);
    55 
    56         if (!CommandExecutor::execute(evaluation))
     102        if (!CommandExecutor::execute(command))
    57103            COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl;
    58104
    59         if (evaluation.hasReturnvalue())
    60             return evaluation.getReturnvalue().toString();
     105        if (CommandExecutor::getLastEvaluation().hasReturnvalue())
     106            return CommandExecutor::getLastEvaluation().getReturnvalue().toString();
    61107
    62108        return "";
    63109    }
    64110
    65     std::string tcl(const std::string& tclcode)
     111    std::string TclBind::tcl(const std::string& tclcode)
    66112    {
    67113        try
    68114        {
    69             static Tcl::interpreter i;
    70             i.def("puts", Tcl_puts, Tcl::variadic());
    71             i.def("execute", Tcl_execute, Tcl::variadic());
    72             i.eval("proc unknown {args} { return [execute $args] }");
    73             std::string output = i.eval(tclcode);
     115            std::string output = TclBind::getInstance().interpreter_->eval(tclcode);
    74116            if (output != "")
    75117                COUT(0) << "tcl> " << output << std::endl;
  • code/branches/console/src/core/TclBind.h

    r1188 r1194  
    3434namespace orxonox
    3535{
    36     Tcl::interpreter* createNewInterpreter();
    37     void Tcl_puts(Tcl::object const &args);
    38     std::string Tcl_execute(Tcl::object const &args);
    39     std::string tcl(const std::string& tclcode);
     36    class TclBind
     37    {
     38        public:
     39            static TclBind& getInstance();
     40
     41            void setDataPath(const std::string& datapath);
     42            void createTclInterpreter();
     43            void createNewTclInterpreter();
     44
     45            static void puts(Tcl::object const &args);
     46            static std::string execute(Tcl::object const &args);
     47            static std::string tcl(const std::string& tclcode);
     48
     49        private:
     50            TclBind();
     51            TclBind(const TclBind& other);
     52            ~TclBind();
     53
     54            Tcl::interpreter* interpreter_;
     55            std::string tclLibPath_;
     56            bool bSetTclLibPath_;
     57    };
    4058}
    4159
  • code/branches/console/src/cpptcl/CppTcl.cc

    r1151 r1194  
    859859}
    860860
     861interpreter::interpreter(string const &libpath)
     862{
     863     interp_ =  Tcl_CreateInterp();
     864     owner_ = true;
     865
     866     try
     867     {
     868        this->eval("set tcl_library " + libpath);
     869        Tcl_Init(this->interp_);
     870     } catch (...) {}
     871}
     872
    861873interpreter::interpreter(Tcl_Interp *interp, bool owner)
    862874{
  • code/branches/console/src/cpptcl/CppTcl.h

    r1151 r1194  
    7070public:
    7171     result(Tcl_Interp *interp);
    72      
     72
    7373     operator bool() const;
    7474     operator double() const;
     
    171171               throw tcl_error("Too few arguments.");
    172172          }
    173          
     173
    174174          std::string methodName(Tcl_GetString(objv[1]));
    175175
     
    468468public:
    469469     interpreter();
     470     interpreter(std::string const &libpath);
    470471     interpreter(Tcl_Interp *, bool owner = true);
    471472     ~interpreter();
    472      
     473
    473474     void make_safe();
    474      
     475
    475476     Tcl_Interp * get() const { return interp_; }
    476477
    477      // free function definitions     
    478      
     478     // free function definitions
     479
    479480     template <typename R>
    480481     void def(std::string const &name, R (*f)(),
     
    633634     }
    634635
    635      // free script evaluation     
     636     // free script evaluation
    636637     details::result eval(std::string const &script);
    637638     details::result eval(std::istream &s);
     
    837838          throw tcl_error(interp_);
    838839     }
    839  
     840
    840841     return details::result(interp_);
    841842}
  • code/branches/console/src/orxonox/GraphicsEngine.cc

    r1178 r1194  
    4444#include "core/ConfigValueIncludes.h"
    4545#include "core/Debug.h"
     46#include "core/TclBind.h"
    4647
    4748
     
    112113    SetConfigValue(ogreLogLevelNormal_  , 4).description("Corresponding orxonox debug level for ogre Normal");
    113114    SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");
     115
     116    TclBind::getInstance().setDataPath(this->dataPath_);
    114117  }
    115118
Note: See TracChangeset for help on using the changeset viewer.