[Orxonox-commit 932] r5655 - in code/branches/resource2/src: core orxonox orxonox/gamestates

rgrieder at orxonox.net rgrieder at orxonox.net
Mon Aug 17 16:41:03 CEST 2009


Author: rgrieder
Date: 2009-08-17 16:41:03 +0200 (Mon, 17 Aug 2009)
New Revision: 5655

Added:
   code/branches/resource2/src/core/ToluaInterface.h
Modified:
   code/branches/resource2/src/core/Core.cc
   code/branches/resource2/src/core/LuaState.cc
   code/branches/resource2/src/core/LuaState.h
   code/branches/resource2/src/orxonox/Main.cc
   code/branches/resource2/src/orxonox/gamestates/GSRoot.cc
Log:
Added static DeclareToluaInterface macro to ease up tolua intefaces for modules.

Modified: code/branches/resource2/src/core/Core.cc
===================================================================
--- code/branches/resource2/src/core/Core.cc	2009-08-17 14:37:10 UTC (rev 5654)
+++ code/branches/resource2/src/core/Core.cc	2009-08-17 14:41:03 UTC (rev 5655)
@@ -77,7 +77,6 @@
 #include "Shell.h"
 #include "TclBind.h"
 #include "TclThreadManager.h"
-#include "ToluaBindCore.h"
 #include "input/InputManager.h"
 
 namespace orxonox
@@ -266,8 +265,6 @@
         if (limitToCPU > 0)
             setThreadAffinity(static_cast<unsigned int>(limitToCPU));
 #endif
-        // Add tolua interface
-        LuaState::addToluaInterface(&tolua_Core_open, "Core");
 
         // Manage ini files and set the default settings file (usually orxonox.ini)
         this->configFileManager_.reset(new ConfigFileManager());

Modified: code/branches/resource2/src/core/LuaState.cc
===================================================================
--- code/branches/resource2/src/core/LuaState.cc	2009-08-17 14:37:10 UTC (rev 5654)
+++ code/branches/resource2/src/core/LuaState.cc	2009-08-17 14:41:03 UTC (rev 5655)
@@ -38,12 +38,16 @@
 #include "util/Debug.h"
 #include "Core.h"
 #include "Resource.h"
+#include "ToluaBindCore.h"
 
 namespace orxonox
 {
     LuaState::ToluaInterfaceMap LuaState::toluaInterfaces_s;
     std::vector<LuaState*> LuaState::instances_s;
 
+    // Do this after declaring toluaInterfaces_s and instances_s to avoid larger problems
+    DeclareToluaInterface(Core);
+
     LuaState::LuaState()
         : bIsRunning_(false)
         , includeParseFunction_(NULL)

Modified: code/branches/resource2/src/core/LuaState.h
===================================================================
--- code/branches/resource2/src/core/LuaState.h	2009-08-17 14:37:10 UTC (rev 5654)
+++ code/branches/resource2/src/core/LuaState.h	2009-08-17 14:41:03 UTC (rev 5655)
@@ -39,6 +39,7 @@
 #include <boost/shared_ptr.hpp>
 
 #include "util/ScopeGuard.h"
+#include "ToluaInterface.h"
 
 // tolua_begin
 namespace orxonox

Added: code/branches/resource2/src/core/ToluaInterface.h
===================================================================
--- code/branches/resource2/src/core/ToluaInterface.h	                        (rev 0)
+++ code/branches/resource2/src/core/ToluaInterface.h	2009-08-17 14:41:03 UTC (rev 5655)
@@ -0,0 +1,45 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+ at file
+    This is required because tolua would parse this macro in LuaState.h and fail
+*/
+
+#ifndef _ToluaInterface_H__
+#define _ToluaInterface_H__
+
+#include "CorePrereqs.h"
+#include <boost/preprocessor/cat.hpp>
+
+// Macro for declaring a tolua interface of a library/module
+#define DeclareToluaInterface(libraryName) \
+    static bool BOOST_PP_CAT(bDummy##libraryName, __LINE__) = orxonox::LuaState::addToluaInterface(&tolua_##libraryName##_open, #libraryName); \
+    static Loki::ScopeGuardImpl1<bool (*)(const std::string&), std::string> BOOST_PP_CAT(dummy##libraryName, __LINE__)(&orxonox::LuaState::removeToluaInterface, #libraryName)
+
+#endif /* _ToluaInterface_H__ */


Property changes on: code/branches/resource2/src/core/ToluaInterface.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: code/branches/resource2/src/orxonox/Main.cc
===================================================================
--- code/branches/resource2/src/orxonox/Main.cc	2009-08-17 14:37:10 UTC (rev 5654)
+++ code/branches/resource2/src/orxonox/Main.cc	2009-08-17 14:41:03 UTC (rev 5655)
@@ -47,6 +47,8 @@
 #include "util/Exception.h"
 #include "core/CommandLine.h"
 #include "core/Game.h"
+#include "core/LuaState.h"
+#include "ToluaBindOrxonox.h"
 
 SetCommandLineSwitch(console).information("Start in console mode (text IO only)");
 // Shortcuts for easy direct loading
@@ -55,6 +57,8 @@
 SetCommandLineSwitch(dedicated).information("Start in dedicated server mode");
 SetCommandLineSwitch(standalone).information("Start in standalone mode");
 
+DeclareToluaInterface(Orxonox);
+
 /*
 @brief
     Main method. Game starts here (except for static initialisations).

Modified: code/branches/resource2/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/resource2/src/orxonox/gamestates/GSRoot.cc	2009-08-17 14:37:10 UTC (rev 5654)
+++ code/branches/resource2/src/orxonox/gamestates/GSRoot.cc	2009-08-17 14:41:03 UTC (rev 5655)
@@ -32,9 +32,7 @@
 #include "core/ConsoleCommand.h"
 #include "core/Game.h"
 #include "core/GameMode.h"
-#include "core/LuaState.h"
 #include "network/NetworkFunction.h"
-#include "ToluaBindOrxonox.h"
 #include "tools/Timer.h"
 #include "interfaces/TimeFactorListener.h"
 #include "interfaces/Tickable.h"
@@ -52,9 +50,6 @@
     {
         this->ccSetTimeFactor_ = 0;
         this->ccPause_ = 0;
-
-        // Tell LuaBind about all tolua interfaces
-        LuaState::addToluaInterface(&tolua_Orxonox_open, "Orxonox");
     }
 
     GSRoot::~GSRoot()




More information about the Orxonox-commit mailing list