[Orxonox-commit 1910] r6627 - code/branches/gamestate/src/libraries/core

rgrieder at orxonox.net rgrieder at orxonox.net
Sun Mar 28 19:45:40 CEST 2010


Author: rgrieder
Date: 2010-03-28 19:45:40 +0200 (Sun, 28 Mar 2010)
New Revision: 6627

Modified:
   code/branches/gamestate/src/libraries/core/LuaState.cc
   code/branches/gamestate/src/libraries/core/LuaState.h
Log:
Added Lua debugging support for XML embedded Lua code (even steps into 'include' calls).
The debugger will simply display the output of the Lua tag parser.
Just write 'pause(message)' within a Lua tag and the debugger will be called.

Modified: code/branches/gamestate/src/libraries/core/LuaState.cc
===================================================================
--- code/branches/gamestate/src/libraries/core/LuaState.cc	2010-03-28 17:16:12 UTC (rev 6626)
+++ code/branches/gamestate/src/libraries/core/LuaState.cc	2010-03-28 17:45:40 UTC (rev 6627)
@@ -139,6 +139,10 @@
             // Provide lua_load with the filename for debug purposes
             // The '@' is a Lua convention to identify the chunk name as filename
             chunkname = '@' + sourceFileInfo->filename;
+            
+            // Also fill a map with the actual source code. This is just for the include* commands
+            // where the content of sourceFileInfo->filename doesn't match 'code'
+            this->sourceCodeMap_[sourceFileInfo->filename] = code;
         }
         else
         {
@@ -173,6 +177,10 @@
 
         // Load the old info again
         sourceFileInfo_ = oldSourceFileInfo;
+
+        // Delete source code entry
+        if (sourceFileInfo != NULL)
+            this->sourceCodeMap_.erase(sourceFileInfo->filename);
     }
 
     void LuaState::luaPrint(const std::string& str)
@@ -197,6 +205,11 @@
     //! Returns the content of a file
     std::string LuaState::getSourceCode(const std::string& filename)
     {
+        // Try the internal map first to get the actual Lua code
+        // and not just some pseudo Lua-XML code when using include* commands
+        std::map<std::string, std::string>::const_iterator it = this->sourceCodeMap_.find(filename);
+        if (it != this->sourceCodeMap_.end())
+            return it->second;
         shared_ptr<ResourceInfo> info = Resource::getInfo(filename);
         if (info == NULL)
             return "";

Modified: code/branches/gamestate/src/libraries/core/LuaState.h
===================================================================
--- code/branches/gamestate/src/libraries/core/LuaState.h	2010-03-28 17:16:12 UTC (rev 6626)
+++ code/branches/gamestate/src/libraries/core/LuaState.h	2010-03-28 17:45:40 UTC (rev 6627)
@@ -114,6 +114,7 @@
         lua_State* luaState_;
         bool bIsRunning_;
         shared_ptr<ResourceInfo> sourceFileInfo_;
+        std::map<std::string, std::string> sourceCodeMap_;
         std::string (*includeParseFunction_)(const std::string&);
 
         typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap;




More information about the Orxonox-commit mailing list