Move get_dfhack_version() to a separate namespace and add a few other version-related functions

develop
lethosor 2015-04-02 16:37:58 -04:00
parent 9b6d8d2799
commit 786581689f
10 changed files with 33 additions and 11 deletions

@ -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)

@ -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)
{

@ -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; }
}
}

@ -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");

@ -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;
}

@ -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;
}

@ -1 +1,7 @@
const char *get_dfhack_version();
namespace DFHack {
namespace Version {
const char *dfhack_version();
const char *df_version();
const char *dfhack_release();
}
}

@ -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<std::string> _plugin_globals;\
DFhackDataExport std::vector<std::string>* plugin_globals = &_plugin_globals; \

@ -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());
}
};

@ -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()