Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1214 for code/trunk/src/core


Ignore:
Timestamp:
May 2, 2008, 9:23:30 PM (17 years ago)
Author:
landauf
Message:

merged console-branch back to trunk.
IMPORTANT: update your media directory!

you need TCL to compile. TCL is available here: http://www.tcl.tk/
another option is to check out https://svn.orxonox.net/ogre/tcl8.5.2/ and compile it by yourself. makefiles are in the 'macosx', 'unix' and 'win' subfolders.
FindTCL.cmake searches in the usual locations and in ../libs/tcl8.5.2/

the orxonox console can be activated with numpad-enter. whatever you enter will be parsed by TCL. if TCL doesn't know a command, it gets executed by orxonox.

simple tcl commands are: "puts text" to write "text" into the console, "expr 1+1" to calculate the result of the given expression. just try it by yourself with "puts [expr 1+1]".
[x] means: evaluate x and use the returnvalue as an argument. in this case the returned value is "2" and the resulting command therefore "puts 2".

you can combine orxonox and tcl commands. a simple orxonox command is "log text" that writes text into the console and the logfile. test it with "log [expr 1+1]" to write "2" into all output channels of orxonox. something more advanced: "log [clock seconds]" writes the seconds since 1970 into the logfile. feel free to combine both: "log [clock seconds]: 1+1 is [expr 1+1]"

TCL uses variables. to set a new variable, use "set varname value". you can use the variable wherever you want with $varname. with this we can make the above command a bit more elegant:
set myexpression 1+1
log [clock seconds]: $myexpression is [expr $myexpression]

read more about tcl in the wiki: http://wiki.tcl.tk/

Location:
code/trunk/src/core
Files:
8 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/CMakeLists.txt

    r1209 r1214  
    2828  tolua/tolua_bind.cc
    2929#tolua/tolua_bind.h
     30  TclBind.cc
    3031)
    3132
     
    4950
    5051TARGET_LINK_LIBRARIES(core
     52  cpptcl
    5153  ${Lua_LIBRARIES}
    5254  ${OIS_LIBRARIES}
  • code/trunk/src/core/CommandExecutor.cc

    r1059 r1214  
    3636#include "Executor.h"
    3737#include "ConfigValueContainer.h"
     38#include "TclBind.h"
    3839
    3940#define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE "set"
     
    236237            if (this->shortcut_)
    237238            {
    238                 if (this->shortcut_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " "))
    239                 {
    240                     this->bEvaluatedParams_ = true;
    241                     this->evaluatedExecutor_ = this->shortcut_;
     239                if (this->tokens_.size() <= 1)
     240                {
     241                    if (this->shortcut_->evaluate(this->getAdditionalParameter(), this->param_, " "))
     242                    {
     243                        this->bEvaluatedParams_ = true;
     244                        this->evaluatedExecutor_ = this->shortcut_;
     245                    }
     246                }
     247                else if (this->tokens_.size() > 1)
     248                {
     249                    if (this->shortcut_->evaluate(this->tokens_.subSet(1).join() + this->getAdditionalParameter(), this->param_, " "))
     250                    {
     251                        this->bEvaluatedParams_ = true;
     252                        this->evaluatedExecutor_ = this->shortcut_;
     253                    }
    242254                }
    243255            }
     
    247259            if (this->function_)
    248260            {
    249                 if (this->function_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " "))
    250                 {
    251                     this->bEvaluatedParams_ = true;
    252                     this->evaluatedExecutor_ = this->function_;
     261                if (this->tokens_.size() <= 2)
     262                {
     263                    if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " "))
     264                    {
     265                        this->bEvaluatedParams_ = true;
     266                        this->evaluatedExecutor_ = this->function_;
     267                    }
     268                }
     269                else if (this->tokens_.size() > 2)
     270                {
     271                    if (this->function_->evaluate(this->tokens_.subSet(2).join() + this->getAdditionalParameter(), this->param_, " "))
     272                    {
     273                        this->bEvaluatedParams_ = true;
     274                        this->evaluatedExecutor_ = this->function_;
     275                    }
    253276                }
    254277            }
     
    266289        if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
    267290            return this->param_[index];
     291
     292        return MT_null;
     293    }
     294
     295    bool CommandEvaluation::hasReturnvalue() const
     296    {
     297        if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
     298        {
     299            if (this->shortcut_)
     300                return this->shortcut_->hasReturnvalue();
     301        }
     302        else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
     303        {
     304            if (this->function_)
     305                return this->function_->hasReturnvalue();
     306        }
    268307
    269308        return MT_null;
     
    297336
    298337    CommandEvaluation& CommandExecutor::getEvaluation()
     338    {
     339        return CommandExecutor::getInstance().evaluation_;
     340    }
     341
     342    const CommandEvaluation& CommandExecutor::getLastEvaluation()
    299343    {
    300344        return CommandExecutor::getInstance().evaluation_;
     
    336380    }
    337381
    338     bool CommandExecutor::execute(const std::string& command)
    339     {
    340         std::string strippedCommand = stripEnclosingQuotes(command);
    341 
    342         SubString tokensIO(strippedCommand, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    343         if (tokensIO.size() >= 2)
    344         {
    345             if (tokensIO[tokensIO.size() - 2] == ">")
    346             {
    347                 bool success = CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join());
    348                 write(tokensIO[tokensIO.size() - 1], CommandExecutor::getEvaluation().getReturnvalue());
    349                 return success;
    350             }
    351             else if (tokensIO[tokensIO.size() - 2] == "<")
    352             {
    353                 std::string input = read(tokensIO[tokensIO.size() - 1]);
    354                 if (input == "" || input.size() == 0)
    355                     return CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join());
    356                 else
    357                     return CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join() + " " + input);
    358             }
    359         }
    360 
    361 
    362         SubString tokensPipeline(strippedCommand, "|", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    363         if (tokensPipeline.size() > 1)
    364         {
    365             bool success = true;
    366             std::string returnValue = "";
    367             for (int i = tokensPipeline.size() - 1; i >= 0; i--)
    368             {
    369                 if (returnValue == "" || returnValue.size() == 0)
    370                 {
    371                     //CommandEvaluation evaluation = CommandExecutor::evaluate(tokens[i]);
    372                     if (!CommandExecutor::execute(tokensPipeline[i]))
    373                         success = false;
    374                 }
    375                 else
    376                 {
    377                     //CommandEvaluation evaluation = CommandExecutor::evaluate(tokens[i] + " " + returnValue);
    378                     if (!CommandExecutor::execute(tokensPipeline[i] + " " + returnValue))
    379                         success = false;
    380                 }
    381 
    382                 //CommandExecutor::execute(evaluation);
    383                 //returnValue = evaluation.getReturnvalue();
    384                 returnValue = CommandExecutor::getEvaluation().getReturnvalue().toString();
    385             }
    386             return success;
    387         }
    388 
    389         if ((CommandExecutor::getEvaluation().processedCommand_ != strippedCommand) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
    390             CommandExecutor::parse(strippedCommand);
    391 
    392         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        }
    393395    }
    394396
     
    400402        if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_)
    401403        {
     404std::cout << "CE_execute (evaluation): " << evaluation.evaluatedExecutor_->getName() << " " << evaluation.param_[0] << " " << evaluation.param_[1] << " " << evaluation.param_[2] << " " << evaluation.param_[3] << " " << evaluation.param_[4] << std::endl;
    402405            (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]);
    403         }
    404 
     406            return true;
     407        }
     408
     409std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n";
    405410        switch (evaluation.state_)
    406411        {
     
    645650    {
    646651        CommandExecutor::parse(command, true);
     652
     653        if (CommandExecutor::getEvaluation().tokens_.size() > 0)
     654        {
     655            std::string lastToken;
     656            lastToken = CommandExecutor::getEvaluation().tokens_[CommandExecutor::getEvaluation().tokens_.size() - 1];
     657            lastToken = lastToken.substr(0, lastToken.size() - 1);
     658            CommandExecutor::getEvaluation().tokens_.pop_back();
     659            CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " ", "", true, '\0', false, '\0', false, '\0', '\0', false, '\0'));
     660        }
     661
    647662        CommandExecutor::getEvaluation().evaluateParams();
    648663        return CommandExecutor::getEvaluation();
     
    10821097        CommandExecutor::getEvaluation().additionalParameter_ = "";
    10831098
     1099        CommandExecutor::getEvaluation().bEvaluatedParams_ = false;
     1100        CommandExecutor::getEvaluation().evaluatedExecutor_ = 0;
     1101
    10841102        CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear();
    10851103        CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear();
  • code/trunk/src/core/CommandExecutor.h

    r1064 r1214  
    9595            void evaluateParams();
    9696
     97            bool hasReturnvalue() const;
    9798            MultiTypeMath getReturnvalue() const;
    9899
     
    130131    {
    131132        public:
    132             static bool execute(const std::string& command);
     133            static bool execute(const std::string& command, bool useTcl = true);
    133134            static bool execute(const CommandEvaluation& evaluation);
    134135
     
    140141
    141142            static CommandEvaluation evaluate(const std::string& command);
     143
     144            static const CommandEvaluation& getLastEvaluation();
    142145
    143146            static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);
  • code/trunk/src/core/CorePrereqs.h

    r1062 r1214  
    139139  template <class T>
    140140  class SubclassIdentifier;
     141  class TclBind;
    141142  class Tickable;
    142143  template <class T, class O>
  • code/trunk/src/core/Functor.h

    r1064 r1214  
    284284#define FUNCTOR_EVALUATE_PARAM0
    285285#define FUNCTOR_EVALUATE_PARAM1 \
    286     if (index == 0) param = (P1)param
     286    if (index == 0) { P1 temp = param; param = temp; }
    287287#define FUNCTOR_EVALUATE_PARAM2 \
    288     if (index == 0) param = (P1)param; \
    289     else if (index == 1) param = (P2)param
     288    if (index == 0) { P1 temp = param; param = temp; } \
     289    else if (index == 1) { P2 temp = param; param = temp; }
    290290#define FUNCTOR_EVALUATE_PARAM3 \
    291     if (index == 0) param = (P1)param; \
    292     else if (index == 1) param = (P2)param; \
    293     else if (index == 2) param = (P3)param
     291    if (index == 0) { P1 temp = param; param = temp; } \
     292    else if (index == 1) { P2 temp = param; param = temp; } \
     293    else if (index == 2) { P3 temp = param; param = temp; }
    294294#define FUNCTOR_EVALUATE_PARAM4 \
    295     if (index == 0) param = (P1)param; \
    296     else if (index == 1) param = (P2)param; \
    297     else if (index == 2) param = (P3)param; \
    298     else if (index == 3) param = (P4)param
     295    if (index == 0) { P1 temp = param; param = temp; } \
     296    else if (index == 1) { P2 temp = param; param = temp; } \
     297    else if (index == 2) { P3 temp = param; param = temp; } \
     298    else if (index == 3) { P4 temp = param; param = temp; }
    299299#define FUNCTOR_EVALUATE_PARAM5 \
    300     if (index == 0) param = (P1)param; \
    301     else if (index == 1) param = (P2)param; \
    302     else if (index == 2) param = (P3)param; \
    303     else if (index == 3) param = (P4)param; \
    304     else if (index == 4) param = (P5)param
     300    if (index == 0) { P1 temp = param; param = temp; } \
     301    else if (index == 1) { P2 temp = param; param = temp; } \
     302    else if (index == 2) { P3 temp = param; param = temp; } \
     303    else if (index == 3) { P4 temp = param; param = temp; } \
     304    else if (index == 4) { P5 temp = param; param = temp; }
    305305
    306306
  • code/trunk/src/core/InputBuffer.cc

    r1066 r1214  
    3939    {
    4040        //this->bActivated_ = false;
    41         this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"().:,;_-+*/=!?<>[|]";
     41        this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^";
    4242        this->keyboard_ = InputManager::getSingleton().getKeyboard();
    4343        this->buffer_ = "";
    4444
    4545        //this->keyboard_->setEventCallback(this);
     46    }
     47
     48    InputBuffer::InputBuffer(const std::string allowedChars)
     49    {
     50        //this->bActivated_ = false;
     51        this->allowedChars_ = allowedChars;
     52        this->keyboard_ = InputManager::getSingleton().getKeyboard();
     53        this->buffer_ = "";
    4654    }
    4755/*
  • code/trunk/src/core/InputBuffer.h

    r1066 r1214  
    5959        public:
    6060            InputBuffer();
     61            InputBuffer(const std::string allowedChars);
    6162
    6263            template <class T>
  • code/trunk/src/core/InputHandler.cc

    r1066 r1214  
    8585      InputHandlerGame::callListeners(e);
    8686    }
    87     else if (e.key == OIS::KC_NUMPADENTER)
     87    else if (e.key == OIS::KC_UNASSIGNED || e.key == OIS::KC_NUMPADENTER)
    8888    {
    8989      InputManager::getSingleton().setInputMode(IM_KEYBOARD);
Note: See TracChangeset for help on using the changeset viewer.