Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 3:54:20 PM (17 years ago)
Author:
rgrieder
Message:
  • @everyone: Do not create a branch until I've added the svn:eol-style property correctly. Otherwise this would cost me another 4 hours or so when we want to merge back.
  • merged network branch back to trunk
  • I had to omit the changes from last evening concerning the line endings
  • might not work yet because of the line endings
  • @beni: script branch is the only branch still open. you probably will have to apply a patch because of inconsistent new lines
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/TclBind.cc

    r1214 r1502  
    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()
     
    5962    void TclBind::setDataPath(const std::string& datapath)
    6063    {
    61         this->tclLibPath_ = datapath + "/tcl";
     64        this->tclLibPath_ = datapath + "/tcl" + TCL_VERSION + "/";
    6265        this->bSetTclLibPath_ = true;
    6366
     
    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
    117133    std::string TclBind::tcl(const std::string& tclcode)
    118134    {
    119         try
     135        if (TclBind::getInstance().interpreter_)
    120136        {
    121             std::string output = TclBind::getInstance().interpreter_->eval(tclcode);
    122             if (output != "")
    123                 COUT(0) << "tcl> " << output << std::endl;
    124             return output;
    125         }
    126         catch (Tcl::tcl_error const &e)
    127         {
    128             COUT(1) << "tcl> Error: " << e.what() << std::endl;
    129         }
    130         catch (std::exception const &e)
    131         {
    132             COUT(1) << "Error while executing tcl: " << e.what() << std::endl;
     137            try
     138            {
     139                std::string output = TclBind::getInstance().interpreter_->eval(tclcode);
     140                if (output != "")
     141                {
     142                    COUT(0) << "tcl> " << output << std::endl;
     143                }
     144                return output;
     145            }
     146            catch (Tcl::tcl_error const &e)
     147            {   COUT(1) << "tcl> Error: " << e.what() << std::endl;   }
     148            catch (std::exception const &e)
     149            {   COUT(1) << "Error while executing Tcl: " << e.what() << std::endl;   }
    133150        }
    134151
    135152        return "";
     153    }
     154
     155    void TclBind::bgerror(std::string error)
     156    {
     157        COUT(1) << "Tcl background error: " << stripEnclosingBraces(error) << std::endl;
    136158    }
    137159
     
    144166        }
    145167        catch (Tcl::tcl_error const &e)
    146         {
    147             COUT(1) << "Error: " << e.what() << std::endl;
    148         }
     168        {   COUT(1) << "Tcl error: " << e.what() << std::endl;   }
    149169        catch (std::exception const &e)
    150         {
    151             COUT(1) << "Error while executing tcl: " << e.what() << std::endl;
    152         }
     170        {   COUT(1) << "Error while executing Tcl: " << e.what() << std::endl;   }
    153171
    154172        return false;
Note: See TracChangeset for help on using the changeset viewer.