[Orxonox-commit 3342] r8030 - code/branches/usability/src/libraries/core/command
landauf at orxonox.net
landauf at orxonox.net
Sun Mar 6 13:42:26 CET 2011
Author: landauf
Date: 2011-03-06 13:42:26 +0100 (Sun, 06 Mar 2011)
New Revision: 8030
Modified:
code/branches/usability/src/libraries/core/command/CommandEvaluation.h
code/branches/usability/src/libraries/core/command/ConsoleCommandCompilation.cc
code/branches/usability/src/libraries/core/command/Shell.cc
code/branches/usability/src/libraries/core/command/TclBind.cc
code/branches/usability/src/libraries/core/command/TclBind.h
code/branches/usability/src/libraries/core/command/TclThreadManager.cc
Log:
- 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
Modified: code/branches/usability/src/libraries/core/command/CommandEvaluation.h
===================================================================
--- code/branches/usability/src/libraries/core/command/CommandEvaluation.h 2011-03-06 12:38:49 UTC (rev 8029)
+++ code/branches/usability/src/libraries/core/command/CommandEvaluation.h 2011-03-06 12:42:26 UTC (rev 8030)
@@ -69,11 +69,11 @@
time, for example to return an error message if it doesn't work.
@remarks execCommand_ and hintCommand_ can be different in this case: There are multiple
- commands avaliable, let's say "tcl", "tclexecute", and "tclquery". The user enters
- "tcl", which is already a valid command. Now execCommand_ points to the "tcl"-command,
- but hintCommand_ still points to the autocompletion command of CommandExecutor, because
- the auto-completion list must still return the three possible commands, "tcl tclexecute tclquery"
- because the user may want to execute "tclquery" and needs auto-completion.
+ commands avaliable, let's say "tcl" and "TclThreadManager". The user enters "tcl", which
+ is already a valid command. Now execCommand_ points to the "tcl"-command, but hintCommand_
+ still points to the autocompletion command of CommandExecutor, because the auto-completion
+ list must still return the two possible commands, "tcl TclThreadManager" because the user
+ may want to write "TclThreadManager ..." and needs auto-completion.
@see See @ref CommandExecutorExample "this description" for an example.
*/
Modified: code/branches/usability/src/libraries/core/command/ConsoleCommandCompilation.cc
===================================================================
--- code/branches/usability/src/libraries/core/command/ConsoleCommandCompilation.cc 2011-03-06 12:38:49 UTC (rev 8029)
+++ code/branches/usability/src/libraries/core/command/ConsoleCommandCompilation.cc 2011-03-06 12:42:26 UTC (rev 8030)
@@ -45,13 +45,13 @@
namespace orxonox
{
- SetConsoleCommand("source", source).argumentCompleter(0, autocompletion::files());
+// SetConsoleCommand("source", source).argumentCompleter(0, autocompletion::files()); // disabled because we use the implementation in Tcl
SetConsoleCommand("echo", echo);
- SetConsoleCommand("puts", puts);
+// SetConsoleCommand("puts", puts); // disabled because we use the implementation in Tcl
- SetConsoleCommand("read", read).argumentCompleter(0, autocompletion::files());
- SetConsoleCommand("append", append).argumentCompleter(0, autocompletion::files());
- SetConsoleCommand("write", write).argumentCompleter(0, autocompletion::files());
+// SetConsoleCommand("read", read).argumentCompleter(0, autocompletion::files()); // disabled because we use the implementation in Tcl
+// SetConsoleCommand("append", append).argumentCompleter(0, autocompletion::files()); // disabled because we use the implementation in Tcl
+// SetConsoleCommand("write", write).argumentCompleter(0, autocompletion::files()); // disabled because we use the implementation in Tcl
SetConsoleCommand("calculate", calculate);
Modified: code/branches/usability/src/libraries/core/command/Shell.cc
===================================================================
--- code/branches/usability/src/libraries/core/command/Shell.cc 2011-03-06 12:38:49 UTC (rev 8029)
+++ code/branches/usability/src/libraries/core/command/Shell.cc 2011-03-06 12:42:26 UTC (rev 8030)
@@ -45,10 +45,10 @@
namespace orxonox
{
SetConsoleCommand("log", OutputHandler::log );
- SetConsoleCommand("error", OutputHandler::error );
- SetConsoleCommand("warning", OutputHandler::warning);
- SetConsoleCommand("info", OutputHandler::info );
- SetConsoleCommand("debug", OutputHandler::debug );
+ SetConsoleCommand("error", OutputHandler::error ).hide();
+ SetConsoleCommand("warning", OutputHandler::warning).hide();
+ SetConsoleCommand("info", OutputHandler::info ).hide();
+ SetConsoleCommand("debug", OutputHandler::debug ).hide();
unsigned int Shell::cacheSize_s;
Modified: code/branches/usability/src/libraries/core/command/TclBind.cc
===================================================================
--- code/branches/usability/src/libraries/core/command/TclBind.cc 2011-03-06 12:38:49 UTC (rev 8029)
+++ code/branches/usability/src/libraries/core/command/TclBind.cc 2011-03-06 12:42:26 UTC (rev 8030)
@@ -44,7 +44,7 @@
namespace orxonox
{
SetConsoleCommand("tcl", &TclBind::tcl);
- SetConsoleCommand("bgerror", &TclBind::bgerror);
+ SetConsoleCommand("bgerror", &TclBind::bgerror).hide();
TclBind* TclBind::singletonPtr_s = 0;
@@ -90,15 +90,16 @@
this->interpreter_ = this->createTclInterpreter();
this->interpreter_->def("::orxonox::query", TclBind::tcl_query, Tcl::variadic());
+ this->interpreter_->def("::orxonox::execute", TclBind::tcl_execute, Tcl::variadic());
this->interpreter_->def("::orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic());
- this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic());
this->interpreter_->def("::orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());
try
{
- this->interpreter_->eval("proc query {args} { ::orxonox::query $args }");
+ this->interpreter_->def("query", TclBind::tcl_query, Tcl::variadic());
+ this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic());
this->interpreter_->eval("proc crossquery {id args} { ::orxonox::crossquery 0 $id $args }");
- this->interpreter_->eval("proc crossexecute {id args} { ::orxonox::crossquery 0 $id $args }");
+ this->interpreter_->eval("proc crossexecute {id args} { ::orxonox::crossexecute 0 $id $args }");
this->interpreter_->eval("proc running {} { return 1 }");
this->interpreter_->eval("set id 0");
this->interpreter_->eval("rename exit ::tcl::exit; proc exit {} { execute exit }");
@@ -153,12 +154,35 @@
std::string TclBind::tcl_query(Tcl::object const &args)
{
COUT(4) << "Tcl_query: " << args.get() << std::endl;
+ return TclBind::tcl_helper(args, true);
+ }
+ /**
+ @brief Callback: Used to send an Orxonox-command from Tcl to the CommandExecutor.
+ */
+ void TclBind::tcl_execute(Tcl::object const &args)
+ {
+ COUT(4) << "Tcl_execute: " << args.get() << std::endl;
+ TclBind::tcl_helper(args, false);
+ }
+
+ /**
+ @brief Helper function, used by tcl_query() and tcl_execute().
+ */
+ std::string TclBind::tcl_helper(Tcl::object const &args, bool bQuery)
+ {
const std::string& command = stripEnclosingBraces(args.get());
int error;
+ std::string result;
+
CommandEvaluation evaluation = CommandExecutor::evaluate(command);
- const std::string& result = evaluation.query(&error);
+
+ if (bQuery)
+ result = evaluation.query(&error).getString();
+ else
+ error = evaluation.execute();
+
switch (error)
{
case CommandExecutor::Error: COUT(1) << "Error: Can't execute command \"" << command << "\", command doesn't exist. (B)" << std::endl; break;
@@ -174,20 +198,6 @@
}
/**
- @brief Callback: Used to send an Orxonox-command from Tcl to the CommandExecutor.
- */
- void TclBind::tcl_execute(Tcl::object const &args)
- {
- COUT(4) << "Tcl_execute: " << args.get() << std::endl;
- const std::string& command = stripEnclosingBraces(args.get());
-
- if (CommandExecutor::execute(command, false))
- {
- COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl;
- }
- }
-
- /**
@brief Console command, executes Tcl code. Can be used to bind Tcl-commands to a key, because native
Tcl-commands can not be evaluated and are thus not supported by the key-binder.
*/
@@ -197,15 +207,10 @@
{
try
{
- const std::string& output = TclBind::getInstance().interpreter_->eval("uplevel #0 " + tclcode);
- if (!output.empty())
- {
- COUT(0) << "tcl> " << output << std::endl;
- }
- return output;
+ return TclBind::getInstance().interpreter_->eval("uplevel #0 " + tclcode);
}
catch (Tcl::tcl_error const &e)
- { COUT(1) << "tcl> Error: " << e.what() << std::endl; }
+ { COUT(1) << "Tcl error: " << e.what() << std::endl; }
}
return "";
Modified: code/branches/usability/src/libraries/core/command/TclBind.h
===================================================================
--- code/branches/usability/src/libraries/core/command/TclBind.h 2011-03-06 12:38:49 UTC (rev 8029)
+++ code/branches/usability/src/libraries/core/command/TclBind.h 2011-03-06 12:42:26 UTC (rev 8030)
@@ -125,6 +125,8 @@
private:
TclBind(const TclBind& other); ///< Copy-constructor, not implemented
+ static std::string tcl_helper(Tcl::object const &args, bool bQuery);
+
Tcl::interpreter* interpreter_; ///< The wrapped Tcl interpreter
std::string tclDataPath_; ///< The path to the directory that contains the Orxonox-specific Tcl-files
bool bSetTclDataPath_; ///< True if tclDataPath_ was defined (after a call to setDataPath())
Modified: code/branches/usability/src/libraries/core/command/TclThreadManager.cc
===================================================================
--- code/branches/usability/src/libraries/core/command/TclThreadManager.cc 2011-03-06 12:38:49 UTC (rev 8029)
+++ code/branches/usability/src/libraries/core/command/TclThreadManager.cc 2011-03-06 12:42:26 UTC (rev 8030)
@@ -54,8 +54,6 @@
{
const float TCLTHREADMANAGER_MAX_CPU_USAGE = 0.50f;
- SetConsoleCommand("tclexecute", &TclThreadManager::execute).argumentCompleter(0, autocompletion::tclthreads());
- SetConsoleCommand("tclquery", &TclThreadManager::query ).argumentCompleter(0, autocompletion::tclthreads());
SetConsoleCommand("TclThreadManager", "create", &TclThreadManager::create);
SetConsoleCommand("TclThreadManager", "destroy", &TclThreadManager::destroy).argumentCompleter(0, autocompletion::tclthreads());
SetConsoleCommand("TclThreadManager", "execute", &TclThreadManager::execute).argumentCompleter(0, autocompletion::tclthreads());
More information about the Orxonox-commit
mailing list