Index: code/branches/resource2/src/core/GUIManager.cc
===================================================================
--- code/branches/resource2/src/core/GUIManager.cc	(revision 5660)
+++ code/branches/resource2/src/core/GUIManager.cc	(revision 5661)
@@ -27,10 +27,4 @@
  *
  */
-
-/**
-@file
-@brief
-    Implementation of the GUIManager class.
-*/
 
 #include "GUIManager.h"
@@ -60,4 +54,5 @@
 #include "Clock.h"
 #include "LuaState.h"
+#include "Resource.h"
 
 namespace orxonox
@@ -115,6 +110,6 @@
 
         // setup scripting
-        scriptModule_.reset(new LuaScriptModule());
-        luaState_ = scriptModule_->getLuaState();
+        luaState_.reset(new LuaState());
+        scriptModule_.reset(new LuaScriptModule(luaState_->getInternalLuaState()));
 
         // Create our own logger to specify the filepath
@@ -129,38 +124,15 @@
         guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
 
-        // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place
-        LuaState::openToluaInterfaces(this->luaState_);
-
-        // initialise the basic lua code
-        this->loadLuaCode();
-    }
-
-    /**
-    @brief
-        Destructor of the GUIManager
-
+        // Initialise the basic lua code
+        rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua", "GUI");
+        this->luaState_->doFile("InitialiseGUI.lua", "GUI", false);
+    }
+
+    /**
+    @brief
         Basically shuts down CEGUI (member smart pointers) but first unloads our Tolua modules.
     */
     GUIManager::~GUIManager()
     {
-        // destroy our own tolua interfaces
-        LuaState::closeToluaInterfaces(this->luaState_);
-    }
-
-    /**
-    @brief
-        Calls main Lua script
-    @todo
-        This function calls the main Lua script for our GUI.
-
-        Additionally we set the datapath variable in Lua. This is needed so Lua can access the data used for the GUI.
-    */
-    void GUIManager::loadLuaCode()
-    {
-        // set datapath for GUI data
-        lua_pushfstring(this->scriptModule_->getLuaState(), Core::getDataPathString().c_str());
-        lua_setglobal(this->scriptModule_->getLuaState(), "datapath");
-        // call main Lua script
-        this->scriptModule_->executeScriptFile("loadGUI_3.lua", "GUI");
     }
 
@@ -209,16 +181,5 @@
     void GUIManager::executeCode(const std::string& str)
     {
-        try
-        {
-            this->scriptModule_->executeString(str);
-        }
-        catch (const CEGUI::Exception& ex)
-        {
-            COUT(2) << "CEGUI Error: \"" << ex.getMessage() << "\" while executing code \"" << str << "\"" << std::endl;
-        }
-        catch (...)
-        {
-            COUT(2) << "Couldn't execute GUI related Lua code due to unknown reasons." << std::endl;
-        }
+        this->luaState_->doString(str, rootFileInfo_);
     }
 
@@ -234,5 +195,5 @@
     void GUIManager::showGUI(const std::string& name)
     {
-        this->executeCode(std::string("showGUI(\"") + name + "\")");
+        this->luaState_->doString("showGUI(\"" + name + "\")", rootFileInfo_);
     }
 
Index: code/branches/resource2/src/core/GUIManager.h
===================================================================
--- code/branches/resource2/src/core/GUIManager.h	(revision 5660)
+++ code/branches/resource2/src/core/GUIManager.h	(revision 5661)
@@ -28,10 +28,4 @@
  */
 
-/**
-@file
-@brief
-    Declaration of the GUIManager class.
-*/
-
 #ifndef _GUIManager_H__
 #define _GUIManager_H__
@@ -43,4 +37,5 @@
 #include <CEGUIForwardRefs.h>
 #include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
 
 #include "util/OgreForwardRefs.h"
@@ -80,6 +75,4 @@
         GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
 
-        void loadLuaCode();
-
         // keyHandler functions
         void keyPressed (const KeyEvent& evt);
@@ -93,10 +86,11 @@
 
         scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_;  //!< CEGUI's interface to the Ogre Engine
+        scoped_ptr<LuaState>                 luaState_;     //!< LuaState, access point to the Lua engine
         scoped_ptr<CEGUI::LuaScriptModule>   scriptModule_; //!< CEGUI's script module to use Lua
         scoped_ptr<CEGUI::System>            guiSystem_;    //!< CEGUI's main system
+        shared_ptr<ResourceInfo>             rootFileInfo_; //!< Resource information about the root script
         Ogre::RenderWindow*      renderWindow_;     //!< Ogre's render window to give CEGUI access to it
         CEGUI::ResourceProvider* resourceProvider_; //!< CEGUI's resource provider
         CEGUI::Logger*           ceguiLogger_;      //!< CEGUI's logger to be able to log CEGUI errors in our log
-        lua_State*               luaState_;         //!< Lua state, access point to the Lua engine
 
         static GUIManager*       singletonPtr_s;    //!< Singleton reference to GUIManager
Index: code/branches/resource2/src/core/LuaState.cc
===================================================================
--- code/branches/resource2/src/core/LuaState.cc	(revision 5660)
+++ code/branches/resource2/src/core/LuaState.cc	(revision 5661)
@@ -147,8 +147,4 @@
             sourceFileInfo_ = sourceFileInfo;
 
-        //if (!bIsRunning_)
-        //{
-        //    bIsRunning_ = true;
-
         int error = 0;
 #if LUA_VERSION_NUM != 501
@@ -163,5 +159,5 @@
         // execute the chunk
         if (error == 0)
-            error = lua_pcall(luaState_, 0, 0, 0);
+            error = lua_pcall(luaState_, 0, 1, 0);
         if (error != 0)
         {
@@ -170,12 +166,9 @@
                 origin = " originating from " + sourceFileInfo_->filename;
             COUT(2) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl;
-        }
-
-        //    bIsRunning_ = false;
-        //}
-        //else
-        //{
-        //    COUT(2) << "Warning: LuaState do function called while running!" << std::endl;
-        //}
+            // return value is nil
+            lua_pushnil(luaState_);
+        }
+        // push return value because it will get lost since the return value of this function is void
+        lua_setglobal(luaState_, "LuaStateReturnValue");
 
         // Load the old info again
@@ -191,4 +184,13 @@
     {
         OutputHandler::getOutStream().setOutputLevel(level) << message << std::endl;
+    }
+
+    bool LuaState::fileExists(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+    {
+        shared_ptr<ResourceInfo> info =  this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
+        if (info == NULL)
+            return false;
+        else
+            return true;
     }
 
Index: code/branches/resource2/src/core/LuaState.h
===================================================================
--- code/branches/resource2/src/core/LuaState.h	(revision 5660)
+++ code/branches/resource2/src/core/LuaState.h	(revision 5661)
@@ -59,9 +59,10 @@
         void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
 
-        void includeFile(const std::string& filename, const std::string& resourceGroup = "Genreal", bool bSearchOtherPaths = true); // tolua_export
+        void includeFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
         void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
 
         void luaPrint(const std::string& str); // tolua_export
         void luaLog(unsigned int level, const std::string& message); // tolua_export
+        bool fileExists(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
 
         const std::stringstream& getOutput() const { return output_; }
