From 786581689fc8db1bf258dd4057a6a879f895c3af Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 2 Apr 2015 16:37:58 -0400 Subject: [PATCH] Move get_dfhack_version() to a separate namespace and add a few other version-related functions --- library/CMakeLists.txt | 6 +++++- library/Core.cpp | 2 +- library/DFHackVersion.cpp | 8 +++++++- library/LuaTools.cpp | 6 +++++- library/PluginManager.cpp | 5 +++-- library/RemoteTools.cpp | 2 +- library/include/DFHackVersion.h | 8 +++++++- library/include/PluginManager.h | 2 +- plugins/devel/vshook.cpp | 2 +- plugins/ruby/ruby.cpp | 3 ++- 10 files changed, 33 insertions(+), 11 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 69bf4d63a..44f91a570 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -251,7 +251,11 @@ ELSE(WIN32) ENDIF() ADD_LIBRARY(dfhack-version STATIC DFHackVersion.cpp) -SET_TARGET_PROPERTIES(dfhack-version PROPERTIES COMPILE_DEFINITIONS DFHACK_VERSION="${DFHACK_VERSION}") +SET_PROPERTY(TARGET dfhack-version APPEND PROPERTY COMPILE_DEFINITIONS + DFHACK_VERSION="${DFHACK_VERSION}" + DF_VERSION="${DF_VERSION}" + DFHACK_RELEASE="${DFHACK_RELEASE}" +) ADD_LIBRARY(dfhack SHARED ${PROJECT_SOURCES}) ADD_DEPENDENCIES(dfhack generate_headers) diff --git a/library/Core.cpp b/library/Core.cpp index 4606179d0..19b94719d 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -498,7 +498,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, v " reload PLUGIN|all - Reload a plugin or all loaded plugins.\n" ); - con.print("\nDFHack version %s.\n", get_dfhack_version()); + con.print("\nDFHack version %s.\n", Version::dfhack_version()); } else if (parts.size() == 1) { diff --git a/library/DFHackVersion.cpp b/library/DFHackVersion.cpp index 4f82d3638..2929201d4 100644 --- a/library/DFHackVersion.cpp +++ b/library/DFHackVersion.cpp @@ -1,2 +1,8 @@ #include "DFHackVersion.h" -const char *get_dfhack_version() { return DFHACK_VERSION; } +namespace DFHack { + namespace Version { + const char *dfhack_version() { return DFHACK_VERSION; } + const char *df_version() { return DF_VERSION; } + const char *dfhack_release() { return DFHACK_RELEASE; } + } +} diff --git a/library/LuaTools.cpp b/library/LuaTools.cpp index b883ea5b9..94c67828b 100644 --- a/library/LuaTools.cpp +++ b/library/LuaTools.cpp @@ -1588,8 +1588,12 @@ lua_State *DFHack::Lua::Open(color_ostream &out, lua_State *state) lua_rawsetp(state, LUA_REGISTRYINDEX, &DFHACK_BASE_G_TOKEN); lua_setfield(state, -2, "BASE_G"); - lua_pushstring(state, get_dfhack_version()); + lua_pushstring(state, Version::dfhack_version()); lua_setfield(state, -2, "VERSION"); + lua_pushstring(state, Version::df_version()); + lua_setfield(state, -2, "DF_VERSION"); + lua_pushstring(state, Version::dfhack_release()); + lua_setfield(state, -2, "RELEASE"); lua_pushboolean(state, IsCoreContext(state)); lua_setfield(state, -2, "is_core_context"); diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index 75ed0d4ec..b04733ee7 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -234,10 +234,11 @@ bool Plugin::load(color_ostream &con) const char ** plug_name =(const char ** ) LookupPlugin(plug, "name"); const char ** plug_version =(const char ** ) LookupPlugin(plug, "version"); Plugin **plug_self = (Plugin**)LookupPlugin(plug, "plugin_self"); - if (strcmp(get_dfhack_version(), *plug_version) != 0) + const char *dfhack_version = Version::dfhack_version(); + if (strcmp(dfhack_version, *plug_version) != 0) { con.printerr("Plugin %s was not built for this version of DFHack.\n" - "Plugin: %s, DFHack: %s\n", *plug_name, *plug_version, get_dfhack_version()); + "Plugin: %s, DFHack: %s\n", *plug_name, *plug_version, dfhack_version); plugin_abort_load; return false; } diff --git a/library/RemoteTools.cpp b/library/RemoteTools.cpp index d065dfa5e..77374ea0c 100644 --- a/library/RemoteTools.cpp +++ b/library/RemoteTools.cpp @@ -361,7 +361,7 @@ void DFHack::describeUnit(BasicUnitInfo *info, df::unit *unit, static command_result GetVersion(color_ostream &stream, const EmptyMessage *, StringMessage *out) { - out->set_value(get_dfhack_version()); + out->set_value(Version::dfhack_version()); return CR_OK; } diff --git a/library/include/DFHackVersion.h b/library/include/DFHackVersion.h index aead35369..315ddf885 100644 --- a/library/include/DFHackVersion.h +++ b/library/include/DFHackVersion.h @@ -1 +1,7 @@ -const char *get_dfhack_version(); +namespace DFHack { + namespace Version { + const char *dfhack_version(); + const char *df_version(); + const char *dfhack_release(); + } +} diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index 603342d66..cded965b0 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -273,7 +273,7 @@ namespace DFHack #define DFHACK_PLUGIN_AUX(plugin_name, is_dev) \ DFhackDataExport const char * name = plugin_name;\ - DFhackDataExport const char * version = get_dfhack_version();\ + DFhackDataExport const char * version = DFHack::Version::dfhack_version();\ DFhackDataExport Plugin *plugin_self = NULL;\ std::vector _plugin_globals;\ DFhackDataExport std::vector* plugin_globals = &_plugin_globals; \ diff --git a/plugins/devel/vshook.cpp b/plugins/devel/vshook.cpp index f866b8675..a0e2a5e59 100644 --- a/plugins/devel/vshook.cpp +++ b/plugins/devel/vshook.cpp @@ -34,7 +34,7 @@ struct title_hook : df::viewscreen_titlest { Screen::Pen pen(' ',COLOR_WHITE,COLOR_BLACK); Screen::paintString(pen, 0, 0, "DFHack "); - Screen::paintString(pen, 7, 0, get_dfhack_version()); + Screen::paintString(pen, 7, 0, Version::dfhack_version()); } }; diff --git a/plugins/ruby/ruby.cpp b/plugins/ruby/ruby.cpp index f27fbc3dd..af9ed3bc6 100644 --- a/plugins/ruby/ruby.cpp +++ b/plugins/ruby/ruby.cpp @@ -486,7 +486,8 @@ static VALUE rb_cDFHack; // df-dfhack version (eg "0.34.11-r2") static VALUE rb_dfversion(VALUE self) { - return rb_str_new(get_dfhack_version(), strlen(get_dfhack_version())); + const char *dfhack_version = Version::dfhack_version(); + return rb_str_new(dfhack_version, strlen(dfhack_version)); } // enable/disable calls to DFHack.onupdate()