Changeset 3370 for code/trunk/src/core/TclBind.cc
- Timestamp:
- Jul 30, 2009, 2:10:44 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/resource (added) merged: 3328,3336-3340,3342-3350,3352-3366
- Property svn:mergeinfo changed
-
code/trunk/src/core/TclBind.cc
r3318 r3370 33 33 #include <cpptcl/cpptcl.h> 34 34 35 #include "SpecialConfig.h" 35 36 #include "util/Debug.h" 36 37 #include "util/StringUtils.h" 37 38 #include "CommandExecutor.h" 38 39 #include "ConsoleCommand.h" 40 #include "Core.h" 39 41 #include "TclThreadManager.h" 40 42 … … 44 46 SetConsoleCommandShortcut(TclBind, bgerror); 45 47 46 TclBind* TclBind::singleton Ref_s = 0;48 TclBind* TclBind::singletonPtr_s = 0; 47 49 48 50 TclBind::TclBind(const std::string& datapath) 49 51 { 50 assert(singletonRef_s == 0);51 singletonRef_s = this;52 52 this->interpreter_ = 0; 53 this->bSetTcl LibPath_ = false;53 this->bSetTclDataPath_ = false; 54 54 this->setDataPath(datapath); 55 55 } … … 59 59 if (this->interpreter_) 60 60 delete this->interpreter_; 61 singletonRef_s = 0;62 61 } 63 62 … … 65 64 { 66 65 // String has POSIX slashes 67 this->tclLibPath_ = datapath + "tcl" + TCL_VERSION + '/'; 68 this->bSetTclLibPath_ = true; 69 70 this->createTclInterpreter(); 71 } 72 73 void TclBind::createTclInterpreter() 74 { 75 if (this->bSetTclLibPath_ && !this->interpreter_) 76 { 77 this->interpreter_ = new Tcl::interpreter(this->tclLibPath_); 78 this->interpreter_->def("orxonox::query", TclBind::tcl_query, Tcl::variadic()); 79 this->interpreter_->def("orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic()); 66 this->tclDataPath_ = datapath + "tcl" + '/'; 67 this->bSetTclDataPath_ = true; 68 69 this->initializeTclInterpreter(); 70 } 71 72 void TclBind::initializeTclInterpreter() 73 { 74 if (this->bSetTclDataPath_ && !this->interpreter_) 75 { 76 this->interpreter_ = this->createTclInterpreter(); 77 78 this->interpreter_->def("::orxonox::query", TclBind::tcl_query, Tcl::variadic()); 79 this->interpreter_->def("::orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic()); 80 80 this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic()); 81 this->interpreter_->def(" orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());81 this->interpreter_->def("::orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic()); 82 82 83 83 try 84 84 { 85 this->interpreter_->eval("proc query args { orxonox::query [join $args] }"); 86 this->interpreter_->eval("proc crossquery {id args} { orxonox::crossquery 0 $id [join $args] }"); 87 this->interpreter_->eval("proc crossexecute {id args} { orxonox::crossquery 0 $id [join $args] }"); 85 this->interpreter_->eval("proc query {args} { ::orxonox::query $args }"); 86 this->interpreter_->eval("proc crossquery {id args} { ::orxonox::crossquery 0 $id $args }"); 87 this->interpreter_->eval("proc crossexecute {id args} { ::orxonox::crossquery 0 $id $args }"); 88 this->interpreter_->eval("proc running {} { return 1 }"); 88 89 this->interpreter_->eval("set id 0"); 89 this->interpreter_->eval("rename exit tcl::exit; proc exit {} { execute exit }"); 90 this->interpreter_->eval("redef_puts"); 90 this->interpreter_->eval("rename exit ::tcl::exit; proc exit {} { execute exit }"); 91 91 } 92 92 catch (Tcl::tcl_error const &e) … … 94 94 catch (std::exception const &e) 95 95 { COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl; } 96 } 97 } 98 99 void TclBind::createNewTclInterpreter() 100 { 101 if (this->interpreter_) 102 { 103 delete this->interpreter_; 104 this->interpreter_ = 0; 105 } 106 107 this->createTclInterpreter(); 96 catch (...) 97 { COUT(1) << "Error while creating Tcl-interpreter." << std::endl; } 98 } 99 } 100 101 Tcl::interpreter* TclBind::createTclInterpreter() 102 { 103 Tcl::interpreter* interpreter = new Tcl::interpreter(); 104 std::string libpath = TclBind::getTclLibraryPath(); 105 106 try 107 { 108 if (libpath != "") 109 interpreter->eval("set tcl_library \"" + libpath + "\""); 110 111 Tcl_Init(interpreter->get()); 112 113 interpreter->eval("source \"" + TclBind::getInstance().tclDataPath_ + "/init.tcl\""); 114 } 115 catch (Tcl::tcl_error const &e) 116 { COUT(1) << "Tcl error while creating Tcl-interpreter: " << e.what() << std::endl; COUT(1) << "Error: Tcl isn't properly initialized. Orxonox might possibly not work like that." << std::endl; } 117 catch (std::exception const &e) 118 { COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl; COUT(1) << "Error: Tcl isn't properly initialized. Orxonox might possibly not work like that." << std::endl; } 119 catch (...) 120 { COUT(1) << "Error while creating Tcl-interpreter." << std::endl; COUT(1) << "Error: Tcl isn't properly initialized. Orxonox might possibly not work like that." << std::endl; } 121 122 return interpreter; 123 } 124 125 std::string TclBind::getTclLibraryPath() 126 { 127 #ifdef DEPENDENCY_PACKAGE_ENABLE 128 if (Core::isDevelopmentRun()) 129 return (std::string(ORXONOX_DEP_LIB_PATH) + "/tcl"); 130 else 131 return (Core::getRootPathString() + "lib/tcl"); 132 #else 133 return ""; 134 #endif 108 135 } 109 136 … … 142 169 try 143 170 { 144 std::string output = TclBind::getInstance().interpreter_->eval( tclcode);171 std::string output = TclBind::getInstance().interpreter_->eval("uplevel #0 " + tclcode); 145 172 if (output != "") 146 173 {
Note: See TracChangeset
for help on using the changeset viewer.