Index: code/branches/resource/src/core/TclBind.cc
===================================================================
--- code/branches/resource/src/core/TclBind.cc	(revision 3359)
+++ code/branches/resource/src/core/TclBind.cc	(revision 3360)
@@ -104,25 +104,36 @@
     Tcl::interpreter* TclBind::createTclInterpreter()
     {
-        Tcl::interpreter* interpreter;
+        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())
-            interpreter = new Tcl::interpreter(std::string(ORXONOX_DEP_LIB_PATH) + "/tcl");
+            return (std::string(ORXONOX_DEP_LIB_PATH) + "/tcl");
         else
-            interpreter = new Tcl::interpreter(Core::getRootPathString() + "lib/tcl");
+            return (Core::getRootPathString() + "lib/tcl");
 #else
-        interpreter = new Tcl::interpreter();
+        return "";
 #endif
-        try
-        {
-            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;   }
-        catch (std::exception const &e)
-        {   COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl;   }
-        catch (...)
-        {   COUT(1) << "Error while creating Tcl-interpreter." << std::endl;   }
-
-        return interpreter;
     }
 
Index: code/branches/resource/src/core/TclBind.h
===================================================================
--- code/branches/resource/src/core/TclBind.h	(revision 3359)
+++ code/branches/resource/src/core/TclBind.h	(revision 3360)
@@ -50,4 +50,6 @@
             void setDataPath(const std::string& datapath);
             const std::string& getTclDataPath() const { return this->tclDataPath_; }
+            static std::string getTclLibraryPath();
+
             void initializeTclInterpreter();
             static Tcl::interpreter* createTclInterpreter();
Index: code/branches/resource/src/core/TclThreadManager.cc
===================================================================
--- code/branches/resource/src/core/TclThreadManager.cc	(revision 3359)
+++ code/branches/resource/src/core/TclThreadManager.cc	(revision 3360)
@@ -54,4 +54,5 @@
     SetConsoleCommand(TclThreadManager, execute, false).argumentCompleter(0, autocompletion::tclthreads());
     SetConsoleCommand(TclThreadManager, query,   false).argumentCompleter(0, autocompletion::tclthreads());
+    SetConsoleCommand(TclThreadManager, source,  false).argumentCompleter(0, autocompletion::tclthreads());
 
     /**
@@ -242,42 +243,5 @@
         newbundle->interpreter_ = TclBind::createTclInterpreter();
 
-        // Initialize the new interpreter
-        try
-        {
-            std::string id_string = getConvertedValue<unsigned int, std::string>(id);
-
-            // Define the functions which are implemented in C++
-            newbundle->interpreter_->def("::orxonox::execute",      TclThreadManager::tcl_execute,      Tcl::variadic());
-            newbundle->interpreter_->def("::orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());
-            newbundle->interpreter_->def("::orxonox::query",        TclThreadManager::tcl_query,        Tcl::variadic());
-            newbundle->interpreter_->def("::orxonox::crossquery",   TclThreadManager::tcl_crossquery,   Tcl::variadic());
-            newbundle->interpreter_->def("::orxonox::running",      TclThreadManager::tcl_running);
-
-            // Create threadspecific shortcuts for the functions above
-            newbundle->interpreter_->def("execute",      TclThreadManager::tcl_execute,      Tcl::variadic());
-            newbundle->interpreter_->def("crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());
-            newbundle->interpreter_->eval("proc query      {args}    { ::orxonox::query " + id_string + " $args }");
-            newbundle->interpreter_->eval("proc crossquery {id args} { ::orxonox::crossquery " + id_string + " $id $args }");
-            newbundle->interpreter_->eval("proc running    {}        { return [::orxonox::running " + id_string + "] }");
-
-            // Define a variable containing the thread id
-            newbundle->interpreter_->eval("set id " + id_string);
-
-            // Use our own exit function to avoid shutting down the whole program instead of just the interpreter
-            newbundle->interpreter_->eval("rename exit ::tcl::exit");
-            newbundle->interpreter_->eval("proc exit {} { execute TclThreadManager destroy " + id_string + " }");
-
-            // Redefine some native functions
-            newbundle->interpreter_->eval("rename while ::tcl::while");
-            newbundle->interpreter_->eval("rename ::orxonox::while while");
-            newbundle->interpreter_->eval("rename for ::tcl::for");
-            newbundle->interpreter_->eval("rename ::orxonox::for for");
-        }
-        catch (const Tcl::tcl_error& e)
-        {   newbundle->interpreter_ = 0; COUT(1) << "Tcl error while creating Tcl-interpreter (" << id << "): " << e.what() << std::endl;   }
-        catch (const std::exception& e)
-        {   newbundle->interpreter_ = 0; COUT(1) << "Error while creating Tcl-interpreter (" << id << "): " << e.what() << std::endl;   }
-        catch (...)
-        {   newbundle->interpreter_ = 0; COUT(1) << "An error occurred while creating a new Tcl-interpreter (" << id << ")" << std::endl;   }
+        TclThreadManager::initialize(newbundle);
 
         {
@@ -288,4 +252,46 @@
 
         return newbundle->interpreter_;
+    }
+
+    void TclThreadManager::initialize(TclInterpreterBundle* bundle)
+    {
+        std::string id_string = getConvertedValue<unsigned int, std::string>(bundle->id_);
+
+        // Initialize the new interpreter
+        try
+        {
+            // Define the functions which are implemented in C++
+            bundle->interpreter_->def("::orxonox::execute",      TclThreadManager::tcl_execute,      Tcl::variadic());
+            bundle->interpreter_->def("::orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());
+            bundle->interpreter_->def("::orxonox::query",        TclThreadManager::tcl_query,        Tcl::variadic());
+            bundle->interpreter_->def("::orxonox::crossquery",   TclThreadManager::tcl_crossquery,   Tcl::variadic());
+            bundle->interpreter_->def("::orxonox::running",      TclThreadManager::tcl_running);
+
+            // Create threadspecific shortcuts for the functions above
+            bundle->interpreter_->def("execute",      TclThreadManager::tcl_execute,      Tcl::variadic());
+            bundle->interpreter_->def("crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());
+            bundle->interpreter_->eval("proc query      {args}    { ::orxonox::query " + id_string + " $args }");
+            bundle->interpreter_->eval("proc crossquery {id args} { ::orxonox::crossquery " + id_string + " $id $args }");
+            bundle->interpreter_->eval("proc running    {}        { return [::orxonox::running " + id_string + "] }");
+
+            // Define a variable containing the thread id
+            bundle->interpreter_->eval("set id " + id_string);
+
+            // Use our own exit function to avoid shutting down the whole program instead of just the interpreter
+            bundle->interpreter_->eval("rename exit ::tcl::exit");
+            bundle->interpreter_->eval("proc exit {} { execute TclThreadManager destroy " + id_string + " }");
+
+            // Redefine some native functions
+            bundle->interpreter_->eval("rename while ::tcl::while");
+            bundle->interpreter_->eval("rename ::orxonox::while while");
+            bundle->interpreter_->eval("rename for ::tcl::for");
+            bundle->interpreter_->eval("rename ::orxonox::for for");
+        }
+        catch (const Tcl::tcl_error& e)
+        {   bundle->interpreter_ = 0; COUT(1) << "Tcl error while creating Tcl-interpreter (" << id_string << "): " << e.what() << std::endl;   }
+        catch (const std::exception& e)
+        {   bundle->interpreter_ = 0; COUT(1) << "Error while creating Tcl-interpreter (" << id_string << "): " << e.what() << std::endl;   }
+        catch (...)
+        {   bundle->interpreter_ = 0; COUT(1) << "An error occurred while creating a new Tcl-interpreter (" << id_string << ")" << std::endl;   }
     }
 
@@ -403,5 +409,5 @@
             {
                 // This query would lead to a deadlock - return with an error
-                this->error("Error: Circular query (" + this->dumpList(source_bundle->queriers_.getList()) + " " + getConvertedValue<unsigned int, std::string>(source_bundle->id_) \
+                TclThreadManager::error("Error: Circular query (" + this->dumpList(source_bundle->queriers_.getList()) + " " + getConvertedValue<unsigned int, std::string>(source_bundle->id_) \
                             + " -> " + getConvertedValue<unsigned int, std::string>(target_bundle->id_) \
                             + "), couldn't query Tcl-interpreter with ID " + getConvertedValue<unsigned int, std::string>(target_bundle->id_) \
@@ -439,7 +445,7 @@
                     {
                         // It's a query to the CommandExecutor
-                        this->debug("TclThread_query -> CE: " + command);
+                        TclThreadManager::debug("TclThread_query -> CE: " + command);
                         if (!CommandExecutor::execute(command, false))
-                            this->error("Error: Can't execute command \"" + command + "\"!");
+                            TclThreadManager::error("Error: Can't execute command \"" + command + "\"!");
 
                         if (CommandExecutor::getLastEvaluation().hasReturnvalue())
@@ -449,7 +455,7 @@
                     {
                         // It's a query to a Tcl interpreter
-                        this->debug("TclThread_query: " + command);
-
-                        output = this->eval(target_bundle, command);
+                        TclThreadManager::debug("TclThread_query: " + command);
+
+                        output = TclThreadManager::eval(target_bundle, command, "query");
                     }
 
@@ -468,5 +474,5 @@
                     // This happens if the main thread tries to query a busy interpreter
                     // To avoid a lock of the main thread, we simply don't proceed with the query in this case
-                    this->error("Error: Couldn't query Tcl-interpreter with ID " + getConvertedValue<unsigned int, std::string>(target_bundle->id_) + ", interpreter is busy right now.");
+                    TclThreadManager::error("Error: Couldn't query Tcl-interpreter with ID " + getConvertedValue<unsigned int, std::string>(target_bundle->id_) + ", interpreter is busy right now.");
                 }
             }
@@ -475,4 +481,12 @@
 
         return output;
+    }
+
+    /**
+        @brief Creates a non-interactive Tcl-interpreter which executes a file.
+    */
+    void TclThreadManager::source(const std::string& file)
+    {
+        boost::thread(boost::bind(&sourceThread, file));
     }
 
@@ -506,5 +520,5 @@
         else
         {
-            this->error("Error: No Tcl-interpreter with ID " + getConvertedValue<unsigned int, std::string>(id) + " existing.");
+            TclThreadManager::error("Error: No Tcl-interpreter with ID " + getConvertedValue<unsigned int, std::string>(id) + " existing.");
             return 0;
         }
@@ -548,5 +562,5 @@
     void TclThreadManager::error(const std::string& error)
     {
-        this->messageQueue_->push_back("error " + error);
+        TclThreadManager::getInstance().messageQueue_->push_back("error " + error);
     }
 
@@ -556,5 +570,5 @@
     void TclThreadManager::debug(const std::string& error)
     {
-        this->messageQueue_->push_back("debug " + error);
+        TclThreadManager::getInstance().messageQueue_->push_back("debug " + error);
     }
 
@@ -565,5 +579,5 @@
         Errors are reported through the @ref error function.
     */
-    std::string TclThreadManager::eval(TclInterpreterBundle* bundle, const std::string& command)
+    std::string TclThreadManager::eval(TclInterpreterBundle* bundle, const std::string& command, const std::string& action)
     {
         Tcl_Interp* interpreter = bundle->interpreter_->get();
@@ -574,5 +588,5 @@
         if (cc != TCL_OK)
         {
-            this->error("Tcl error (execute, ID " + getConvertedValue<unsigned int, std::string>(bundle->id_) + "): " + static_cast<std::string>(result));
+            TclThreadManager::error("Tcl error (" + action + ", ID " + getConvertedValue<unsigned int, std::string>(bundle->id_) + "): " + static_cast<std::string>(result));
             return "";
         }
@@ -594,9 +608,70 @@
     void tclThread(TclInterpreterBundle* bundle, std::string command)
     {
-        TclThreadManager::getInstance().debug("TclThread_execute: " + command);
-
-        TclThreadManager::getInstance().eval(bundle, command);
+        TclThreadManager::debug("TclThread_execute: " + command);
+
+        TclThreadManager::eval(bundle, command, "execute");
 
         bundle->lock_->unlock();
     }
+
+    /**
+        @brief The main function of a non-interactive source thread. Executes the file.
+        @param file The name of the file that should be executed by the non-interactive interpreter.
+    */
+    void sourceThread(std::string file)
+    {
+        TclThreadManager::debug("TclThread_source: " + file);
+
+        // Prepare the command-line arguments
+        int argc = 2;
+        char* argv[argc];
+        argv[0] = "tclthread";
+        argv[1] = const_cast<char*>(file.c_str());
+
+        // Start the Tcl-command Tcl_Main with the Tcl_OrxonoxAppInit hook
+        Tcl_Main(argc, argv, Tcl_OrxonoxAppInit);
+
+//        Tcl::object object(file);
+//        int cc = Tcl_FSEvalFile(bundle->interpreter_->get(), object.get_object());
+//        Tcl::details::result result(bundle->interpreter_->get());
+//        if (cc != TCL_OK)
+//            TclThreadManager::error("Tcl error (source, ID " + getConvertedValue<unsigned int, std::string>(bundle->id_) + "): " + static_cast<std::string>(result));
+//
+//        // Unlock the mutex
+//        bundle->lock_->unlock();
+    }
+
+    /**
+        @brief A tcl-init hook to inject the non-interactive Tcl-interpreter into the TclThreadManager.
+    */
+    int Tcl_OrxonoxAppInit(Tcl_Interp* interp)
+    {
+        // Create a new interpreter bundle
+        unsigned int id = TclThreadManager::create();
+        TclInterpreterBundle* bundle = TclThreadManager::getInstance().getInterpreterBundle(id);
+
+        // Replace the default interpreter in the bundle with the non-interactive one (passed as an argument to this function)
+        if (bundle->interpreter_)
+            delete bundle->interpreter_;
+        bundle->interpreter_ = new Tcl::interpreter(interp, true);
+
+        // Initialize the non-interactive interpreter (like in @ref TclBind::createTclInterpreter but exception safe)
+        std::string libpath = TclBind::getTclLibraryPath();
+        if (libpath != "")
+            TclThreadManager::eval(bundle, "set tcl_library \"" + libpath + "\"", "source");
+        int cc = Tcl_Init(interp);
+        TclThreadManager::eval(bundle, "source \"" + TclBind::getInstance().getTclDataPath() + "/init.tcl\"", "source");
+
+        // Initialize the non-interactive interpreter also with the thread-specific stuff
+        TclThreadManager::initialize(bundle);
+
+        // Lock the mutex (this will be locked until the thread finishes - no chance to interact with the interpreter)
+        bundle->lock_->lock();
+
+        // Return to Tcl_Main
+        if (!bundle->interpreter_)
+            return TCL_ERROR;
+        else
+            return cc;
+    }
 }
Index: code/branches/resource/src/core/TclThreadManager.h
===================================================================
--- code/branches/resource/src/core/TclThreadManager.h	(revision 3359)
+++ code/branches/resource/src/core/TclThreadManager.h	(revision 3360)
@@ -39,4 +39,6 @@
 #include "OrxonoxClass.h"
 
+class Tcl_Interp;
+
 namespace orxonox
 {
@@ -45,4 +47,6 @@
         friend class TclBind;
         friend _CoreExport void tclThread(TclInterpreterBundle* bundle, std::string command);
+        friend _CoreExport void sourceThread(std::string file);
+        friend _CoreExport int Tcl_OrxonoxAppInit(Tcl_Interp* interp);
 
         public:
@@ -57,7 +61,8 @@
             static void              execute(unsigned int target_id, const std::string& command);
             static std::string       query(unsigned int target_id, const std::string& command);
+            static void              source(const std::string& file);
 
-            void error(const std::string& error);
-            void debug(const std::string& error);
+            static void error(const std::string& error);
+            static void debug(const std::string& error);
 
             void update(const Clock& time);
@@ -78,5 +83,6 @@
             std::string dumpList(const std::list<unsigned int>& list);
 
-            std::string eval(TclInterpreterBundle* bundle, const std::string& command);
+            static void initialize(TclInterpreterBundle* bundle);
+            static std::string eval(TclInterpreterBundle* bundle, const std::string& command, const std::string& action);
 
             static TclThreadManager* singletonPtr_s;                            ///< Singleton pointer
@@ -90,4 +96,6 @@
 
     _CoreExport void tclThread(TclInterpreterBundle* bundle, std::string command);
+    _CoreExport void sourceThread(std::string file);
+    _CoreExport int Tcl_OrxonoxAppInit(Tcl_Interp* interp);
 }
 
Index: code/branches/resource/src/cpptcl/changes_orxonox.diff
===================================================================
--- code/branches/resource/src/cpptcl/changes_orxonox.diff	(revision 3359)
+++ code/branches/resource/src/cpptcl/changes_orxonox.diff	(revision 3360)
@@ -28,31 +28,2 @@
            Tcl_SetResult(interp, const_cast<char*>(e.what()), TCL_VOLATILE);
            return TCL_ERROR;
-@@ -858,6 +858,18 @@
-      owner_ = true;
- }
- 
-+interpreter::interpreter(string const &libpath)
-+{
-+     interp_ =  Tcl_CreateInterp();
-+     owner_ = true;
-+
-+     try
-+     {
-+        this->eval("set tcl_library \"" + libpath + "\"");
-+        Tcl_Init(this->interp_);
-+     } catch (...) {}
-+}
-+
- interpreter::interpreter(Tcl_Interp *interp, bool owner)
- {
-      interp_ =  interp;
---- cpptcl.h	Wed Jan 28 20:56:11 2009
-+++ cpptcl.h	Sat Jan 24 12:52:54 2009
-@@ -467,6 +467,7 @@
- {
- public:
-      interpreter();
-+     interpreter(std::string const &libpath);
-      interpreter(Tcl_Interp *, bool owner = true);
-      ~interpreter();
-      
Index: code/branches/resource/src/cpptcl/cpptcl.cc
===================================================================
--- code/branches/resource/src/cpptcl/cpptcl.cc	(revision 3359)
+++ code/branches/resource/src/cpptcl/cpptcl.cc	(revision 3360)
@@ -859,16 +859,4 @@
 }
 
-interpreter::interpreter(string const &libpath)
-{
-     interp_ =  Tcl_CreateInterp();
-     owner_ = true;
-
-     try
-     {
-        this->eval("set tcl_library \"" + libpath + "\"");
-        Tcl_Init(this->interp_);
-     } catch (...) {}
-}
-
 interpreter::interpreter(Tcl_Interp *interp, bool owner)
 {
Index: code/branches/resource/src/cpptcl/cpptcl.h
===================================================================
--- code/branches/resource/src/cpptcl/cpptcl.h	(revision 3359)
+++ code/branches/resource/src/cpptcl/cpptcl.h	(revision 3360)
@@ -468,5 +468,4 @@
 public:
      interpreter();
-     interpreter(std::string const &libpath);
      interpreter(Tcl_Interp *, bool owner = true);
      ~interpreter();
