Index: code/trunk/src/core/TclBind.cc
===================================================================
--- code/trunk/src/core/TclBind.cc	(revision 3318)
+++ code/trunk/src/core/TclBind.cc	(revision 3370)
@@ -33,8 +33,10 @@
 #include <cpptcl/cpptcl.h>
 
+#include "SpecialConfig.h"
 #include "util/Debug.h"
 #include "util/StringUtils.h"
 #include "CommandExecutor.h"
 #include "ConsoleCommand.h"
+#include "Core.h"
 #include "TclThreadManager.h"
 
@@ -44,12 +46,10 @@
     SetConsoleCommandShortcut(TclBind, bgerror);
 
-    TclBind* TclBind::singletonRef_s = 0;
+    TclBind* TclBind::singletonPtr_s = 0;
 
     TclBind::TclBind(const std::string& datapath)
     {
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
         this->interpreter_ = 0;
-        this->bSetTclLibPath_ = false;
+        this->bSetTclDataPath_ = false;
         this->setDataPath(datapath);
     }
@@ -59,5 +59,4 @@
         if (this->interpreter_)
             delete this->interpreter_;
-        singletonRef_s = 0;
     }
 
@@ -65,28 +64,29 @@
     {
         // String has POSIX slashes
-        this->tclLibPath_ = datapath + "tcl" + TCL_VERSION + '/';
-        this->bSetTclLibPath_ = true;
-
-        this->createTclInterpreter();
-    }
-
-    void TclBind::createTclInterpreter()
-    {
-        if (this->bSetTclLibPath_ && !this->interpreter_)
-        {
-            this->interpreter_ = new Tcl::interpreter(this->tclLibPath_);
-            this->interpreter_->def("orxonox::query", TclBind::tcl_query, Tcl::variadic());
-            this->interpreter_->def("orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic());
+        this->tclDataPath_ = datapath + "tcl" + '/';
+        this->bSetTclDataPath_ = true;
+
+        this->initializeTclInterpreter();
+    }
+
+    void TclBind::initializeTclInterpreter()
+    {
+        if (this->bSetTclDataPath_ && !this->interpreter_)
+        {
+            this->interpreter_ = this->createTclInterpreter();
+
+            this->interpreter_->def("::orxonox::query", TclBind::tcl_query, 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());
+            this->interpreter_->def("::orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());
 
             try
             {
-                this->interpreter_->eval("proc query args { orxonox::query [join $args] }");
-                this->interpreter_->eval("proc crossquery {id args} { orxonox::crossquery 0 $id [join $args] }");
-                this->interpreter_->eval("proc crossexecute {id args} { orxonox::crossquery 0 $id [join $args] }");
+                this->interpreter_->eval("proc query        {args}    { ::orxonox::query $args }");
+                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 running      {}        { return 1 }");
                 this->interpreter_->eval("set id 0");
-                this->interpreter_->eval("rename exit tcl::exit; proc exit {} { execute exit }");
-                this->interpreter_->eval("redef_puts");
+                this->interpreter_->eval("rename exit ::tcl::exit; proc exit {} { execute exit }");
             }
             catch (Tcl::tcl_error const &e)
@@ -94,16 +94,43 @@
             catch (std::exception const &e)
             {   COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl;   }
-        }
-    }
-
-    void TclBind::createNewTclInterpreter()
-    {
-        if (this->interpreter_)
-        {
-            delete this->interpreter_;
-            this->interpreter_ = 0;
-        }
-
-        this->createTclInterpreter();
+            catch (...)
+            {   COUT(1) << "Error while creating Tcl-interpreter." << std::endl;   }
+        }
+    }
+
+    Tcl::interpreter* TclBind::createTclInterpreter()
+    {
+        Tcl::interpreter* interpreter = new Tcl::interpreter();
+        std::string libpath = TclBind::getTclLibraryPath();
+
+        try
+        {
+            if (libpath != "")
+                interpreter->eval("set tcl_library \"" + libpath + "\"");
+
+            Tcl_Init(interpreter->get());
+
+            interpreter->eval("source \"" + TclBind::getInstance().tclDataPath_ + "/init.tcl\"");
+        }
+        catch (Tcl::tcl_error const &e)
+        {   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;   }
+        catch (std::exception const &e)
+        {   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;   }
+        catch (...)
+        {   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;   }
+
+        return interpreter;
+    }
+
+    std::string TclBind::getTclLibraryPath()
+    {
+#ifdef DEPENDENCY_PACKAGE_ENABLE
+        if (Core::isDevelopmentRun())
+            return (std::string(ORXONOX_DEP_LIB_PATH) + "/tcl");
+        else
+            return (Core::getRootPathString() + "lib/tcl");
+#else
+        return "";
+#endif
     }
 
@@ -142,5 +169,5 @@
             try
             {
-                std::string output = TclBind::getInstance().interpreter_->eval(tclcode);
+                std::string output = TclBind::getInstance().interpreter_->eval("uplevel #0 " + tclcode);
                 if (output != "")
                 {
