Moved Lua versioning globals logic (DiagnosticUtils.cpp -> ProductInfo.cpp), string...
authorMarc Cannon <vyhdycokio@gmail.com>
Wed, 2 Jan 2013 03:58:21 +0000 (03:58 +0000)
committerMarc Cannon <vyhdycokio@gmail.com>
Wed, 2 Jan 2013 03:58:21 +0000 (03:58 +0000)
src/DiagnosticsUtil.cpp
src/ProductInfo.cpp

index f73ddea..c068c7c 100644 (file)
@@ -172,83 +172,6 @@ void DiagnosticsUtil::SetInputType( const CString &sType )
        g_sInputType = sType;
 }
 
-/* XXX: this seems pretty weighty to have here. Maybe it should
- * be moved to ProductInfo since it deals with versioning... */
-namespace
-{
-       enum Version
-       {
-               VERSION_ALPHA,
-               VERSION_BETA,
-               VERSION_GAMMA,
-               VERSION_OMEGA,
-               NUM_VERSIONS,
-               VERSION_INVALID
-       };
-
-       static const CString VersionNames[] =
-       {
-               "alpha",
-               "beta",
-               "gamma",
-               "omega"
-       };
-
-       int ToToken( Version t )
-       {
-               return t * 100;
-       }
-
-       /* This is a dumb implementation to get the transition done;
-        * clean up later. */
-       int GetVersionTokenFromBuildInfo()
-       {
-               CString sVersion = ProductInfo::GetVersion();
-               sVersion.MakeLower();
-
-               Version ver = VERSION_INVALID;
-
-               if( sVersion.find("alpha") != string::npos )
-                       ver = VERSION_ALPHA;
-               else if( sVersion.find("beta") != string::npos )
-                       ver = VERSION_BETA;
-               else if( sVersion.find("gamma") != string::npos
-                       || sVersion.find("rc") != string::npos )
-                       ver = VERSION_GAMMA;
-               else
-                       ver = VERSION_OMEGA;
-
-               unsigned iVersion = 0;
-
-               if( sscanf(sVersion, "%*[A-Za-z] %d", &iVersion) != 1 )
-                       LOG->Warn( "GetVersionTokenFromBuildInfo(): couldn't parse version string \"%s\"", sVersion.c_str() );
-
-               unsigned iToken = ToToken(ver) + iVersion;
-               return iToken;
-       }
-}
-
-// set OPENITG LUA variables from here
-void SetProgramGlobals( lua_State* L )
-{
-       /* Boolean flag that says this engine is OpenITG */
-       LUA->SetGlobal( "OPENITG", true );
-
-       /* Integer flag that allows for new Lua bindings to be used without
-        * breaking older engine builds; see below for tokens and values. */
-       LUA->SetGlobal( "OPENITG_VERSION", GetVersionTokenFromBuildInfo() );
-
-       /* Tokens to compare the above values against */
-       FOREACH_ENUM( Version, NUM_VERSIONS, v )
-       {
-               CString s = VersionNames[v];
-               s.MakeUpper();
-               LUA->SetGlobal( "VERSION_" + s, ToToken(v) );
-       }
-}
-
-REGISTER_WITH_LUA_FUNCTION( SetProgramGlobals );
-
 // LUA bindings for diagnostics functions
 
 #include "LuaFunctions.h"
index a58a68f..1091274 100644 (file)
@@ -1,15 +1,36 @@
+#include "global.h" // also pulls in config.h
 #include "StdString.h"
 #include "ProductInfo.h"
 
-#if HAVE_CONFIG_H
-       #include "config.h"
-#else
 /* XXX: workaround until the Windows build can pull Git versioning. */
+#if !defined(HAVE_CONFIG_H)
        #define BUILD_VERSION "beta3 DEV"
        #define BUILD_DATE "unknown date"
        #define BUILD_REVISION_TAG "unknown revision"
 #endif
 
+/*
+ * Helpers
+ */
+
+namespace
+{
+       const CString GetPlatform()
+       {
+       #if defined(ITG_ARCADE)
+               return "AC";
+       #elif defined(XBOX)
+               return "CS";
+       #else
+               return "PC";
+       #endif
+       }
+}
+
+/*
+ * Version strings and getters
+ */
+
 #define VERSION_STRING( id, value ) \
        static const CString g_s##id = CString( value ); \
        const CString& ProductInfo::Get##id() { return g_s##id; }
@@ -22,23 +43,90 @@ VERSION_STRING( BuildRevision, BUILD_REVISION_TAG );
 
 VERSION_STRING( CrashReportURL, "<to be determined>" );
 
+VERSION_STRING( FullVersion, g_sName + " " + GetPlatform() + " " + g_sVersion );
+
+#undef VERSION_STRING
+
+/*
+ * Lua version helpers
+ */
+
+#include "RageLog.h"
+#include "LuaManager.h"
+#include "EnumHelper.h"
+
 namespace
 {
-       const CString GetPlatform()
+       enum Version
        {
-       #if defined(ITG_ARCADE)
-               return "AC";
-       #elif defined(XBOX)
-               return "CS";
-       #else
-               return "PC";
-       #endif
+               VERSION_ALPHA,
+               VERSION_BETA,
+               VERSION_GAMMA,
+               VERSION_OMEGA,
+               NUM_VERSIONS,
+               VERSION_INVALID
+       };
+
+       static const CString VersionNames[] =
+       {
+               "alpha",
+               "beta",
+               "gamma",
+               "omega"
+       };
+
+       int ToToken( Version t )
+       {
+               return t * 100;
+       }
+
+       /* This is a dumb implementation to get the transition done;
+        * clean up later. */
+       int GetVersionTokenFromBuildInfo()
+       {
+               CString sVersion = ProductInfo::GetVersion();
+               sVersion.MakeLower();
+
+               Version ver = VERSION_INVALID;
+
+               if( sVersion.find("alpha") != CString::npos )
+                       ver = VERSION_ALPHA;
+               else if( sVersion.find("beta") != CString::npos )
+                       ver = VERSION_BETA;
+               else if( sVersion.find("gamma") != CString::npos || sVersion.find("rc") != CString::npos )
+                       ver = VERSION_GAMMA;
+               else
+                       ver = VERSION_OMEGA;
+
+               unsigned iVersion = 0;
+
+               if( sscanf(sVersion, "%*[A-Za-z] %d", &iVersion) != 1 )
+                       LOG->Warn( "GetVersionTokenFromBuildInfo(): couldn't parse version string \"%s\"", sVersion.c_str() );
+
+               unsigned iToken = ToToken(ver) + iVersion;
+               return iToken;
        }
 }
 
-VERSION_STRING( FullVersion, g_sName + " " + GetPlatform() + " " + g_sVersion );
+void SetVersionGlobals( lua_State* L )
+{
+       /* Boolean flag that says this engine is OpenITG */
+       LUA->SetGlobal( "OPENITG", true );
 
-#undef VERSION_STRING
+       /* Integer flag that allows for new Lua bindings to be used without
+        * breaking older engine builds; see below for tokens and values. */
+       LUA->SetGlobal( "OPENITG_VERSION", GetVersionTokenFromBuildInfo() );
+
+       /* Tokens to compare the above values against */
+       FOREACH_ENUM( Version, NUM_VERSIONS, v )
+       {
+               CString s = VersionNames[v];
+               s.MakeUpper();
+               LUA->SetGlobal( "VERSION_" + s, ToToken(v) );
+       }
+}
+
+REGISTER_WITH_LUA_FUNCTION( SetVersionGlobals );
 
 /*
  * (c) 2013 Marc Cannon