Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 28, 2008, 5:30:11 AM (16 years ago)
Author:
landauf
Message:

merged console branch into network branch

after several heavy troubles it compiles, but there is still a bug I couldn't fix: orxonox crashes as soon as one presses a key after opening the console… maybe someone else sees the problem?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/core/TclBind.cc

    r1214 r1446  
    3333#include "CommandExecutor.h"
    3434#include "Debug.h"
     35#include "TclThreadManager.h"
    3536#include "TclBind.h"
     37#include "util/String.h"
    3638
    3739namespace orxonox
    3840{
    39     ConsoleCommandShortcutGeneric(tcl, createExecutor(createFunctor(&TclBind::tcl), "tcl", AccessLevel::None));
     41    SetConsoleCommandShortcutGeneric(tcl, createConsoleCommand(createFunctor(&TclBind::tcl), "tcl"));
     42    SetConsoleCommandShortcutGeneric(bgerror, createConsoleCommand(createFunctor(&TclBind::bgerror), "bgerror"));
    4043
    4144    TclBind::TclBind()
     
    7073        {
    7174            this->interpreter_ = new Tcl::interpreter(this->tclLibPath_);
    72             this->interpreter_->def("puts", TclBind::puts, Tcl::variadic());
    73             this->interpreter_->def("orxonox", TclBind::orxonox, Tcl::variadic());
    74             this->interpreter_->def("execute", TclBind::execute, Tcl::variadic());
    75             this->interpreter_->eval("proc unknown {args} { return [orxonox $args] }");
    76             this->interpreter_->eval("rename exit tclexit; proc exit {} { orxonox exit }");
     75            this->interpreter_->def("orxonox::query", TclBind::tcl_query, Tcl::variadic());
     76            this->interpreter_->def("orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic());
     77            this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic());
     78
     79            try
     80            {
     81                this->interpreter_->eval("proc query args { orxonox::query $args }");
     82                this->interpreter_->eval("proc crossquery {id args} { orxonox::crossquery 0 $id $args }");
     83                this->interpreter_->eval("set id 0");
     84                this->interpreter_->eval("rename exit tcl::exit; proc exit {} { execute exit }");
     85                this->interpreter_->eval("redef_puts");
     86            }
     87            catch (Tcl::tcl_error const &e)
     88            {   COUT(1) << "Tcl error while creating Tcl-interpreter: " << e.what() << std::endl;   }
     89            catch (std::exception const &e)
     90            {   COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl;   }
    7791        }
    7892    }
     
    89103    }
    90104
    91     void TclBind::puts(Tcl::object const &args)
     105    std::string TclBind::tcl_query(Tcl::object const &args)
    92106    {
    93         COUT(0) << args.get() << std::endl;
    94     }
     107        COUT(4) << "Tcl_query: " << args.get() << std::endl;
    95108
    96     std::string TclBind::orxonox(Tcl::object const &args)
    97     {
    98 std::cout << "Tcl_execute: args: " << args.get() << std::endl;
    99         std::string command = args.get();
    100 
    101         if (command.size() >= 2 && command[0] == '{' && command[command.size() - 1] == '}')
    102             command = command.substr(1, command.size() - 2);
     109        std::string command = stripEnclosingBraces(args.get());
    103110
    104111        if (!CommandExecutor::execute(command, false))
     112        {
    105113            COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl;
     114        }
    106115
    107116        if (CommandExecutor::getLastEvaluation().hasReturnvalue())
     
    111120    }
    112121
    113     void TclBind::execute(Tcl::object const &args)
     122    void TclBind::tcl_execute(Tcl::object const &args)
    114123    {
     124        COUT(4) << "Tcl_execute: " << args.get() << std::endl;
     125        std::string command = stripEnclosingBraces(args.get());
     126
     127        if (!CommandExecutor::execute(command, false))
     128        {
     129            COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl;
     130        }
    115131    }
    116132
     
    121137            std::string output = TclBind::getInstance().interpreter_->eval(tclcode);
    122138            if (output != "")
     139            {
    123140                COUT(0) << "tcl> " << output << std::endl;
     141            }
    124142            return output;
    125143        }
    126144        catch (Tcl::tcl_error const &e)
    127         {
    128             COUT(1) << "tcl> Error: " << e.what() << std::endl;
    129         }
     145        {   COUT(1) << "tcl> Error: " << e.what() << std::endl;   }
    130146        catch (std::exception const &e)
    131         {
    132             COUT(1) << "Error while executing tcl: " << e.what() << std::endl;
    133         }
     147        {   COUT(1) << "Error while executing Tcl: " << e.what() << std::endl;   }
    134148
    135149        return "";
     150    }
     151
     152    void TclBind::bgerror(std::string error)
     153    {
     154        COUT(1) << "Tcl background error: " << stripEnclosingBraces(error) << std::endl;
    136155    }
    137156
     
    144163        }
    145164        catch (Tcl::tcl_error const &e)
    146         {
    147             COUT(1) << "Error: " << e.what() << std::endl;
    148         }
     165        {   COUT(1) << "Tcl error: " << e.what() << std::endl;   }
    149166        catch (std::exception const &e)
    150         {
    151             COUT(1) << "Error while executing tcl: " << e.what() << std::endl;
    152         }
     167        {   COUT(1) << "Error while executing Tcl: " << e.what() << std::endl;   }
    153168
    154169        return false;
Note: See TracChangeset for help on using the changeset viewer.