- Timestamp:
- Mar 6, 2011, 1:42:26 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability/src/libraries/core/command/TclBind.cc
r7401 r8030 45 45 { 46 46 SetConsoleCommand("tcl", &TclBind::tcl); 47 SetConsoleCommand("bgerror", &TclBind::bgerror) ;47 SetConsoleCommand("bgerror", &TclBind::bgerror).hide(); 48 48 49 49 TclBind* TclBind::singletonPtr_s = 0; … … 91 91 92 92 this->interpreter_->def("::orxonox::query", TclBind::tcl_query, Tcl::variadic()); 93 this->interpreter_->def("::orxonox::execute", TclBind::tcl_execute, Tcl::variadic()); 93 94 this->interpreter_->def("::orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic()); 94 this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic());95 95 this->interpreter_->def("::orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic()); 96 96 97 97 try 98 98 { 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()); 100 101 this->interpreter_->eval("proc crossquery {id args} { ::orxonox::crossquery 0 $id $args }"); 101 this->interpreter_->eval("proc crossexecute {id args} { ::orxonox::cross query0 $id $args }");102 this->interpreter_->eval("proc crossexecute {id args} { ::orxonox::crossexecute 0 $id $args }"); 102 103 this->interpreter_->eval("proc running {} { return 1 }"); 103 104 this->interpreter_->eval("set id 0"); … … 154 155 { 155 156 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 { 157 174 const std::string& command = stripEnclosingBraces(args.get()); 158 175 159 176 int error; 177 std::string result; 178 160 179 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 162 186 switch (error) 163 187 { … … 175 199 176 200 /** 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 /**191 201 @brief Console command, executes Tcl code. Can be used to bind Tcl-commands to a key, because native 192 202 Tcl-commands can not be evaluated and are thus not supported by the key-binder. … … 198 208 try 199 209 { 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); 206 211 } 207 212 catch (Tcl::tcl_error const &e) 208 { COUT(1) << " tcl> Error: " << e.what() << std::endl; }213 { COUT(1) << "Tcl error: " << e.what() << std::endl; } 209 214 } 210 215
Note: See TracChangeset
for help on using the changeset viewer.