Changeset 1446 for code/branches/network/src/core/TclBind.cc
- Timestamp:
- May 28, 2008, 5:30:11 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/core/TclBind.cc
r1214 r1446 33 33 #include "CommandExecutor.h" 34 34 #include "Debug.h" 35 #include "TclThreadManager.h" 35 36 #include "TclBind.h" 37 #include "util/String.h" 36 38 37 39 namespace orxonox 38 40 { 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")); 40 43 41 44 TclBind::TclBind() … … 70 73 { 71 74 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; } 77 91 } 78 92 } … … 89 103 } 90 104 91 void TclBind::puts(Tcl::object const &args)105 std::string TclBind::tcl_query(Tcl::object const &args) 92 106 { 93 COUT(0) << args.get() << std::endl; 94 } 107 COUT(4) << "Tcl_query: " << args.get() << std::endl; 95 108 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()); 103 110 104 111 if (!CommandExecutor::execute(command, false)) 112 { 105 113 COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl; 114 } 106 115 107 116 if (CommandExecutor::getLastEvaluation().hasReturnvalue()) … … 111 120 } 112 121 113 void TclBind:: execute(Tcl::object const &args)122 void TclBind::tcl_execute(Tcl::object const &args) 114 123 { 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 } 115 131 } 116 132 … … 121 137 std::string output = TclBind::getInstance().interpreter_->eval(tclcode); 122 138 if (output != "") 139 { 123 140 COUT(0) << "tcl> " << output << std::endl; 141 } 124 142 return output; 125 143 } 126 144 catch (Tcl::tcl_error const &e) 127 { 128 COUT(1) << "tcl> Error: " << e.what() << std::endl; 129 } 145 { COUT(1) << "tcl> Error: " << e.what() << std::endl; } 130 146 catch (std::exception const &e) 131 { 132 COUT(1) << "Error while executing tcl: " << e.what() << std::endl; 133 } 147 { COUT(1) << "Error while executing Tcl: " << e.what() << std::endl; } 134 148 135 149 return ""; 150 } 151 152 void TclBind::bgerror(std::string error) 153 { 154 COUT(1) << "Tcl background error: " << stripEnclosingBraces(error) << std::endl; 136 155 } 137 156 … … 144 163 } 145 164 catch (Tcl::tcl_error const &e) 146 { 147 COUT(1) << "Error: " << e.what() << std::endl; 148 } 165 { COUT(1) << "Tcl error: " << e.what() << std::endl; } 149 166 catch (std::exception const &e) 150 { 151 COUT(1) << "Error while executing tcl: " << e.what() << std::endl; 152 } 167 { COUT(1) << "Error while executing Tcl: " << e.what() << std::endl; } 153 168 154 169 return false;
Note: See TracChangeset
for help on using the changeset viewer.