[Orxonox-commit 1908] r6625 - code/branches/gamestate/src/libraries/core

rgrieder at orxonox.net rgrieder at orxonox.net
Sun Mar 28 15:21:45 CEST 2010


Author: rgrieder
Date: 2010-03-28 15:21:44 +0200 (Sun, 28 Mar 2010)
New Revision: 6625

Modified:
   code/branches/gamestate/src/libraries/core/LuaState.cc
   code/branches/gamestate/src/libraries/core/Resource.cc
   code/branches/gamestate/src/libraries/core/Resource.h
Log:
Lua debugger working perfectly by supplying the fully qualified filename to the lua_load function.
Usage: write pause(message) to any line in your lua code and a self explaining command line debugger will open in the console.
Important note: Turn off the IOConsole (--noIOConsole) or the lua debugger will not work!!!

Modified: code/branches/gamestate/src/libraries/core/LuaState.cc
===================================================================
--- code/branches/gamestate/src/libraries/core/LuaState.cc	2010-03-27 16:51:54 UTC (rev 6624)
+++ code/branches/gamestate/src/libraries/core/LuaState.cc	2010-03-28 13:21:44 UTC (rev 6625)
@@ -133,14 +133,27 @@
         if (sourceFileInfo != NULL)
             sourceFileInfo_ = sourceFileInfo;
 
+        std::string chunkname;
+        if (sourceFileInfo != NULL && !sourceFileInfo->fileSystemPath.empty())
+        {
+            // Provide lua_load with the filename for debug purposes
+            // The '@' is a Lua convention to identify the chunk name as filename
+            chunkname = '@' + sourceFileInfo->fileSystemPath;
+        }
+        else
+        {
+            // Use the beginning of the code string to identify the chunk
+            chunkname = code.substr(0, 80);
+        }
+
         int error = 0;
 #if LUA_VERSION_NUM != 501
         LoadS ls;
         ls.s = code.c_str();
         ls.size = code.size();
-        error = lua_load(luaState_, &orxonox::LuaState::lua_Chunkreader, &ls, code.c_str());
+        error = lua_load(luaState_, &orxonox::LuaState::lua_Chunkreader, &ls, chunkname.c_str());
 #else
-        error = luaL_loadstring(luaState_, code.c_str());
+        error = luaL_loadbuffer(luaState_, code.c_str(), code.size(), chunkname.c_str());
 #endif
 
         // execute the chunk

Modified: code/branches/gamestate/src/libraries/core/Resource.cc
===================================================================
--- code/branches/gamestate/src/libraries/core/Resource.cc	2010-03-27 16:51:54 UTC (rev 6624)
+++ code/branches/gamestate/src/libraries/core/Resource.cc	2010-03-28 13:21:44 UTC (rev 6625)
@@ -28,7 +28,9 @@
 
 #include "Resource.h"
 
+#include <boost/filesystem/path.hpp>
 #include <OgreException.h>
+#include <OgreFileSystem.h>
 #include <OgreResourceGroupManager.h>
 
 namespace orxonox
@@ -88,6 +90,12 @@
                 ptr->basename = it->basename;
                 ptr->group = group;
                 ptr->size = it->uncompressedSize;
+                if (dynamic_cast<Ogre::FileSystemArchive*>(it->archive) != NULL)
+                {
+                    boost::filesystem::path base(it->archive->getName());
+                    base /= it->filename;
+                    ptr->fileSystemPath = base.string();
+                }
                 return ptr;
             }
         }

Modified: code/branches/gamestate/src/libraries/core/Resource.h
===================================================================
--- code/branches/gamestate/src/libraries/core/Resource.h	2010-03-27 16:51:54 UTC (rev 6624)
+++ code/branches/gamestate/src/libraries/core/Resource.h	2010-03-28 13:21:44 UTC (rev 6625)
@@ -56,6 +56,8 @@
         std::string group;
         //! Uncompressed size
         size_t size;
+        //! Absolute file path ("" for files not on filesystem)
+        std::string fileSystemPath;
     };
 
     /** Provides simple functions to easily access the Ogre::ResourceGroupManager.




More information about the Orxonox-commit mailing list