Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 6, 2011, 1:42:26 PM (14 years ago)
Author:
landauf
Message:
  • TclBind: consistent definitions of query and execute binds
  • TclBind: fixed wrong binding of crossexecute
  • removed redundant console output of the "tcl" command
  • removed tclquery and tclexecute console commands (they were just shortcuts for TclThreadManager query/execute)
  • the following tcl helper commands are now hidden in the console: error, warning, info, debug, bgerror
  • removed old console commands which shadow functions of Tcl or are unnecessary with Tcl: puts, source, read, write, append
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/src/libraries/core/command/TclBind.cc

    r7401 r8030  
    4545{
    4646    SetConsoleCommand("tcl", &TclBind::tcl);
    47     SetConsoleCommand("bgerror", &TclBind::bgerror);
     47    SetConsoleCommand("bgerror", &TclBind::bgerror).hide();
    4848
    4949    TclBind* TclBind::singletonPtr_s = 0;
     
    9191
    9292            this->interpreter_->def("::orxonox::query", TclBind::tcl_query, Tcl::variadic());
     93            this->interpreter_->def("::orxonox::execute", TclBind::tcl_execute, Tcl::variadic());
    9394            this->interpreter_->def("::orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic());
    94             this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic());
    9595            this->interpreter_->def("::orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());
    9696
    9797            try
    9898            {
    99                 this->interpreter_->eval("proc query        {args}    { ::orxonox::query $args }");
     99                this->interpreter_->def("query", TclBind::tcl_query, Tcl::variadic());
     100                this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic());
    100101                this->interpreter_->eval("proc crossquery   {id args} { ::orxonox::crossquery 0 $id $args }");
    101                 this->interpreter_->eval("proc crossexecute {id args} { ::orxonox::crossquery 0 $id $args }");
     102                this->interpreter_->eval("proc crossexecute {id args} { ::orxonox::crossexecute 0 $id $args }");
    102103                this->interpreter_->eval("proc running      {}        { return 1 }");
    103104                this->interpreter_->eval("set id 0");
     
    154155    {
    155156        COUT(4) << "Tcl_query: " << args.get() << std::endl;
    156 
     157        return TclBind::tcl_helper(args, true);
     158    }
     159
     160    /**
     161        @brief Callback: Used to send an Orxonox-command from Tcl to the CommandExecutor.
     162    */
     163    void TclBind::tcl_execute(Tcl::object const &args)
     164    {
     165        COUT(4) << "Tcl_execute: " << args.get() << std::endl;
     166        TclBind::tcl_helper(args, false);
     167    }
     168
     169    /**
     170        @brief Helper function, used by tcl_query() and tcl_execute().
     171    */
     172    std::string TclBind::tcl_helper(Tcl::object const &args, bool bQuery)
     173    {
    157174        const std::string& command = stripEnclosingBraces(args.get());
    158175
    159176        int error;
     177        std::string result;
     178
    160179        CommandEvaluation evaluation = CommandExecutor::evaluate(command);
    161         const std::string& result = evaluation.query(&error);
     180
     181        if (bQuery)
     182            result = evaluation.query(&error).getString();
     183        else
     184            error = evaluation.execute();
     185
    162186        switch (error)
    163187        {
     
    175199
    176200    /**
    177         @brief Callback: Used to send an Orxonox-command from Tcl to the CommandExecutor.
    178     */
    179     void TclBind::tcl_execute(Tcl::object const &args)
    180     {
    181         COUT(4) << "Tcl_execute: " << args.get() << std::endl;
    182         const std::string& command = stripEnclosingBraces(args.get());
    183 
    184         if (CommandExecutor::execute(command, false))
    185         {
    186             COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl;
    187         }
    188     }
    189 
    190     /**
    191201        @brief Console command, executes Tcl code. Can be used to bind Tcl-commands to a key, because native
    192202        Tcl-commands can not be evaluated and are thus not supported by the key-binder.
     
    198208            try
    199209            {
    200                 const std::string& output = TclBind::getInstance().interpreter_->eval("uplevel #0 " + tclcode);
    201                 if (!output.empty())
    202                 {
    203                     COUT(0) << "tcl> " << output << std::endl;
    204                 }
    205                 return output;
     210                return TclBind::getInstance().interpreter_->eval("uplevel #0 " + tclcode);
    206211            }
    207212            catch (Tcl::tcl_error const &e)
    208             {   COUT(1) << "tcl> Error: " << e.what() << std::endl;   }
     213            {   COUT(1) << "Tcl error: " << e.what() << std::endl;   }
    209214        }
    210215
Note: See TracChangeset for help on using the changeset viewer.