Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8030 for code


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
Location:
code/branches/usability/src/libraries/core/command
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/src/libraries/core/command/CommandEvaluation.h

    r7401 r8030  
    7070
    7171        @remarks execCommand_ and hintCommand_ can be different in this case: There are multiple
    72         commands avaliable, let's say "tcl", "tclexecute", and "tclquery". The user enters
    73         "tcl", which is already a valid command. Now execCommand_ points to the "tcl"-command,
    74         but hintCommand_ still points to the autocompletion command of CommandExecutor, because
    75         the auto-completion list must still return the three possible commands, "tcl tclexecute tclquery"
    76         because the user may want to execute "tclquery" and needs auto-completion.
     72        commands avaliable, let's say "tcl" and "TclThreadManager". The user enters "tcl", which
     73        is already a valid command. Now execCommand_ points to the "tcl"-command, but hintCommand_
     74        still points to the autocompletion command of CommandExecutor, because the auto-completion
     75        list must still return the two possible commands, "tcl TclThreadManager" because the user
     76        may want to write "TclThreadManager ..." and needs auto-completion.
    7777
    7878        @see See @ref CommandExecutorExample "this description" for an example.
  • code/branches/usability/src/libraries/core/command/ConsoleCommandCompilation.cc

    r7401 r8030  
    4646namespace orxonox
    4747{
    48     SetConsoleCommand("source", source).argumentCompleter(0, autocompletion::files());
     48//    SetConsoleCommand("source", source).argumentCompleter(0, autocompletion::files());  // disabled because we use the implementation in Tcl
    4949    SetConsoleCommand("echo", echo);
    50     SetConsoleCommand("puts", puts);
    51 
    52     SetConsoleCommand("read", read).argumentCompleter(0, autocompletion::files());
    53     SetConsoleCommand("append", append).argumentCompleter(0, autocompletion::files());
    54     SetConsoleCommand("write", write).argumentCompleter(0, autocompletion::files());
     50//    SetConsoleCommand("puts", puts);                                                    // disabled because we use the implementation in Tcl
     51
     52//    SetConsoleCommand("read", read).argumentCompleter(0, autocompletion::files());      // disabled because we use the implementation in Tcl
     53//    SetConsoleCommand("append", append).argumentCompleter(0, autocompletion::files());  // disabled because we use the implementation in Tcl
     54//    SetConsoleCommand("write", write).argumentCompleter(0, autocompletion::files());    // disabled because we use the implementation in Tcl
    5555
    5656    SetConsoleCommand("calculate", calculate);
  • code/branches/usability/src/libraries/core/command/Shell.cc

    r7401 r8030  
    4646{
    4747    SetConsoleCommand("log",     OutputHandler::log    );
    48     SetConsoleCommand("error",   OutputHandler::error  );
    49     SetConsoleCommand("warning", OutputHandler::warning);
    50     SetConsoleCommand("info",    OutputHandler::info   );
    51     SetConsoleCommand("debug",   OutputHandler::debug  );
     48    SetConsoleCommand("error",   OutputHandler::error  ).hide();
     49    SetConsoleCommand("warning", OutputHandler::warning).hide();
     50    SetConsoleCommand("info",    OutputHandler::info   ).hide();
     51    SetConsoleCommand("debug",   OutputHandler::debug  ).hide();
    5252
    5353    unsigned int Shell::cacheSize_s;
  • 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
  • code/branches/usability/src/libraries/core/command/TclBind.h

    r7401 r8030  
    126126            TclBind(const TclBind& other);      ///< Copy-constructor, not implemented
    127127
     128            static std::string tcl_helper(Tcl::object const &args, bool bQuery);
     129
    128130            Tcl::interpreter* interpreter_;     ///< The wrapped Tcl interpreter
    129131            std::string tclDataPath_;           ///< The path to the directory that contains the Orxonox-specific Tcl-files
  • code/branches/usability/src/libraries/core/command/TclThreadManager.cc

    r7401 r8030  
    5555    const float TCLTHREADMANAGER_MAX_CPU_USAGE = 0.50f;
    5656
    57     SetConsoleCommand("tclexecute", &TclThreadManager::execute).argumentCompleter(0, autocompletion::tclthreads());
    58     SetConsoleCommand("tclquery",   &TclThreadManager::query  ).argumentCompleter(0, autocompletion::tclthreads());
    5957    SetConsoleCommand("TclThreadManager", "create",  &TclThreadManager::create);
    6058    SetConsoleCommand("TclThreadManager", "destroy", &TclThreadManager::destroy).argumentCompleter(0, autocompletion::tclthreads());
Note: See TracChangeset for help on using the changeset viewer.