Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1198


Ignore:
Timestamp:
Apr 27, 2008, 10:22:32 PM (17 years ago)
Author:
landauf
Message:

CommandExecutor uses Tcl

Location:
code/branches/console/src/core
Files:
5 edited

Legend:

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

    r1194 r1198  
    3636#include "Executor.h"
    3737#include "ConfigValueContainer.h"
     38#include "TclBind.h"
    3839
    3940#define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE "set"
     
    379380    }
    380381
    381     bool CommandExecutor::execute(const std::string& command)
    382     {
    383         if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
    384             CommandExecutor::parse(command);
    385 
    386         return CommandExecutor::execute(CommandExecutor::getEvaluation());
     382    bool CommandExecutor::execute(const std::string& command, bool useTcl)
     383    {
     384        if (useTcl)
     385        {
     386            return TclBind::eval(command);
     387        }
     388        else
     389        {
     390            if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
     391                CommandExecutor::parse(command);
     392
     393            return CommandExecutor::execute(CommandExecutor::getEvaluation());
     394        }
    387395    }
    388396
  • code/branches/console/src/core/CommandExecutor.h

    r1194 r1198  
    131131    {
    132132        public:
    133             static bool execute(const std::string& command);
     133            static bool execute(const std::string& command, bool useTcl = true);
    134134            static bool execute(const CommandEvaluation& evaluation);
    135135
  • code/branches/console/src/core/CorePrereqs.h

    r1062 r1198  
    139139  template <class T>
    140140  class SubclassIdentifier;
     141  class TclBind;
    141142  class Tickable;
    142143  template <class T, class O>
  • code/branches/console/src/core/TclBind.cc

    r1194 r1198  
    7171            this->interpreter_ = new Tcl::interpreter(this->tclLibPath_);
    7272            this->interpreter_->def("puts", TclBind::puts, Tcl::variadic());
     73            this->interpreter_->def("orxonox", TclBind::orxonox, Tcl::variadic());
    7374            this->interpreter_->def("execute", TclBind::execute, Tcl::variadic());
    74             this->interpreter_->eval("proc unknown {args} { return [execute $args] }");
     75            this->interpreter_->eval("proc unknown {args} { return [orxonox $args] }");
     76            this->interpreter_->eval("rename exit tclexit; proc exit {} { orxonox exit }");
    7577        }
    7678    }
     
    9294    }
    9395
    94     std::string TclBind::execute(Tcl::object const &args)
     96    std::string TclBind::orxonox(Tcl::object const &args)
    9597    {
    9698std::cout << "Tcl_execute: args: " << args.get() << std::endl;
     
    100102            command = command.substr(1, command.size() - 2);
    101103
    102         if (!CommandExecutor::execute(command))
     104        if (!CommandExecutor::execute(command, false))
    103105            COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl;
    104106
     
    107109
    108110        return "";
     111    }
     112
     113    void TclBind::execute(Tcl::object const &args)
     114    {
    109115    }
    110116
     
    129135        return "";
    130136    }
     137
     138    bool TclBind::eval(const std::string& tclcode)
     139    {
     140        try
     141        {
     142            TclBind::getInstance().interpreter_->eval(tclcode);
     143            return true;
     144        }
     145        catch (Tcl::tcl_error const &e)
     146        {
     147            COUT(1) << "Error: " << e.what() << std::endl;
     148        }
     149        catch (std::exception const &e)
     150        {
     151            COUT(1) << "Error while executing tcl: " << e.what() << std::endl;
     152        }
     153
     154        return false;
     155    }
    131156}
  • code/branches/console/src/core/TclBind.h

    r1194 r1198  
    3030#define _TclBind_H__
    3131
     32#include "CorePrereqs.h"
     33
    3234#include "cpptcl/CppTcl.h"
    3335
     
    4446
    4547            static void puts(Tcl::object const &args);
    46             static std::string execute(Tcl::object const &args);
     48            static void execute(Tcl::object const &args);
     49            static std::string orxonox(Tcl::object const &args);
    4750            static std::string tcl(const std::string& tclcode);
     51            static bool TclBind::eval(const std::string& tclcode);
    4852
    4953        private:
Note: See TracChangeset for help on using the changeset viewer.