Changeset 1194 for code/branches/console/src
- Timestamp:
- Apr 27, 2008, 4:54:31 PM (17 years ago)
- Location:
- code/branches/console/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/CommandExecutor.cc
r1189 r1194 339 339 } 340 340 341 const CommandEvaluation& CommandExecutor::getLastEvaluation() 342 { 343 return CommandExecutor::getInstance().evaluation_; 344 } 345 341 346 Executor& CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor) 342 347 { … … 385 390 bool CommandExecutor::execute(const CommandEvaluation& evaluation) 386 391 { 387 std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n";388 392 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 389 393 390 394 if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_) 391 395 { 396 std::cout << "CE_execute (evaluation): " << evaluation.evaluatedExecutor_->getName() << " " << evaluation.param_[0] << " " << evaluation.param_[1] << " " << evaluation.param_[2] << " " << evaluation.param_[3] << " " << evaluation.param_[4] << std::endl; 392 397 (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]); 393 398 return true; 394 399 } 395 400 401 std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n"; 396 402 switch (evaluation.state_) 397 403 { … … 643 649 lastToken = lastToken.substr(0, lastToken.size() - 1); 644 650 CommandExecutor::getEvaluation().tokens_.pop_back(); 645 CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " " ));651 CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " ", "", true, '\0', false, '\0', false, '\0', '\0', false, '\0')); 646 652 } 647 653 -
code/branches/console/src/core/CommandExecutor.h
r1187 r1194 142 142 static CommandEvaluation evaluate(const std::string& command); 143 143 144 static const CommandEvaluation& getLastEvaluation(); 145 144 146 static Executor& addConsoleCommandShortcut(ExecutorStatic* executor); 145 147 static ExecutorStatic* getConsoleCommandShortcut(const std::string& name); -
code/branches/console/src/core/TclBind.cc
r1189 r1194 37 37 namespace orxonox 38 38 { 39 ConsoleCommandShortcut Extern(tcl, AccessLevel::None);39 ConsoleCommandShortcutGeneric(tcl, createExecutor(createFunctor(&TclBind::tcl), "tcl", AccessLevel::None)); 40 40 41 void Tcl_puts(Tcl::object const &args) 41 TclBind::TclBind() 42 { 43 this->interpreter_ = 0; 44 this->bSetTclLibPath_ = false; 45 } 46 47 TclBind::~TclBind() 48 { 49 if (this->interpreter_) 50 delete this->interpreter_; 51 } 52 53 TclBind& TclBind::getInstance() 54 { 55 static TclBind instance; 56 return instance; 57 } 58 59 void TclBind::setDataPath(const std::string& datapath) 60 { 61 this->tclLibPath_ = datapath + "/tcl"; 62 this->bSetTclLibPath_ = true; 63 64 this->createTclInterpreter(); 65 } 66 67 void TclBind::createTclInterpreter() 68 { 69 if (this->bSetTclLibPath_ && !this->interpreter_) 70 { 71 this->interpreter_ = new Tcl::interpreter(this->tclLibPath_); 72 this->interpreter_->def("puts", TclBind::puts, Tcl::variadic()); 73 this->interpreter_->def("execute", TclBind::execute, Tcl::variadic()); 74 this->interpreter_->eval("proc unknown {args} { return [execute $args] }"); 75 } 76 } 77 78 void TclBind::createNewTclInterpreter() 79 { 80 if (this->interpreter_) 81 { 82 delete this->interpreter_; 83 this->interpreter_ = 0; 84 } 85 86 this->createTclInterpreter(); 87 } 88 89 void TclBind::puts(Tcl::object const &args) 42 90 { 43 91 COUT(0) << args.get() << std::endl; 44 92 } 45 93 46 std::string Tcl _execute(Tcl::object const &args)94 std::string TclBind::execute(Tcl::object const &args) 47 95 { 48 96 std::cout << "Tcl_execute: args: " << args.get() << std::endl; … … 52 100 command = command.substr(1, command.size() - 2); 53 101 54 CommandEvaluation evaluation = CommandExecutor::evaluate(command); 55 56 if (!CommandExecutor::execute(evaluation)) 102 if (!CommandExecutor::execute(command)) 57 103 COUT(1) << "Error: Can't execute command \"" << command << "\"!" << std::endl; 58 104 59 if ( evaluation.hasReturnvalue())60 return evaluation.getReturnvalue().toString();105 if (CommandExecutor::getLastEvaluation().hasReturnvalue()) 106 return CommandExecutor::getLastEvaluation().getReturnvalue().toString(); 61 107 62 108 return ""; 63 109 } 64 110 65 std::string tcl(const std::string& tclcode)111 std::string TclBind::tcl(const std::string& tclcode) 66 112 { 67 113 try 68 114 { 69 static Tcl::interpreter i; 70 i.def("puts", Tcl_puts, Tcl::variadic()); 71 i.def("execute", Tcl_execute, Tcl::variadic()); 72 i.eval("proc unknown {args} { return [execute $args] }"); 73 std::string output = i.eval(tclcode); 115 std::string output = TclBind::getInstance().interpreter_->eval(tclcode); 74 116 if (output != "") 75 117 COUT(0) << "tcl> " << output << std::endl; -
code/branches/console/src/core/TclBind.h
r1188 r1194 34 34 namespace orxonox 35 35 { 36 Tcl::interpreter* createNewInterpreter(); 37 void Tcl_puts(Tcl::object const &args); 38 std::string Tcl_execute(Tcl::object const &args); 39 std::string tcl(const std::string& tclcode); 36 class TclBind 37 { 38 public: 39 static TclBind& getInstance(); 40 41 void setDataPath(const std::string& datapath); 42 void createTclInterpreter(); 43 void createNewTclInterpreter(); 44 45 static void puts(Tcl::object const &args); 46 static std::string execute(Tcl::object const &args); 47 static std::string tcl(const std::string& tclcode); 48 49 private: 50 TclBind(); 51 TclBind(const TclBind& other); 52 ~TclBind(); 53 54 Tcl::interpreter* interpreter_; 55 std::string tclLibPath_; 56 bool bSetTclLibPath_; 57 }; 40 58 } 41 59 -
code/branches/console/src/cpptcl/CppTcl.cc
r1151 r1194 859 859 } 860 860 861 interpreter::interpreter(string const &libpath) 862 { 863 interp_ = Tcl_CreateInterp(); 864 owner_ = true; 865 866 try 867 { 868 this->eval("set tcl_library " + libpath); 869 Tcl_Init(this->interp_); 870 } catch (...) {} 871 } 872 861 873 interpreter::interpreter(Tcl_Interp *interp, bool owner) 862 874 { -
code/branches/console/src/cpptcl/CppTcl.h
r1151 r1194 70 70 public: 71 71 result(Tcl_Interp *interp); 72 72 73 73 operator bool() const; 74 74 operator double() const; … … 171 171 throw tcl_error("Too few arguments."); 172 172 } 173 173 174 174 std::string methodName(Tcl_GetString(objv[1])); 175 175 … … 468 468 public: 469 469 interpreter(); 470 interpreter(std::string const &libpath); 470 471 interpreter(Tcl_Interp *, bool owner = true); 471 472 ~interpreter(); 472 473 473 474 void make_safe(); 474 475 475 476 Tcl_Interp * get() const { return interp_; } 476 477 477 // free function definitions 478 478 // free function definitions 479 479 480 template <typename R> 480 481 void def(std::string const &name, R (*f)(), … … 633 634 } 634 635 635 // free script evaluation 636 // free script evaluation 636 637 details::result eval(std::string const &script); 637 638 details::result eval(std::istream &s); … … 837 838 throw tcl_error(interp_); 838 839 } 839 840 840 841 return details::result(interp_); 841 842 } -
code/branches/console/src/orxonox/GraphicsEngine.cc
r1178 r1194 44 44 #include "core/ConfigValueIncludes.h" 45 45 #include "core/Debug.h" 46 #include "core/TclBind.h" 46 47 47 48 … … 112 113 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 113 114 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 115 116 TclBind::getInstance().setDataPath(this->dataPath_); 114 117 } 115 118
Note: See TracChangeset
for help on using the changeset viewer.