From 9b6d8d27992d1ff1136cd58dceb5e85d5afd361e Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 1 Apr 2015 17:50:16 -0400 Subject: [PATCH] Allow dev plugins to be skipped on startup --- library/PluginManager.cpp | 8 ++++++++ library/include/PluginManager.h | 13 ++++++++++--- plugins/devel/CMakeLists.txt | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index e0b45d79d..75ed0d4ec 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -230,6 +230,7 @@ bool Plugin::load(color_ostream &con) plugin_check_symbol("plugin_self") plugin_check_symbol("plugin_init") plugin_check_symbol("plugin_globals") + plugin_check_symbol("plugin_dev") 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"); @@ -240,6 +241,13 @@ bool Plugin::load(color_ostream &con) plugin_abort_load; return false; } + bool *plug_dev = (bool*)LookupPlugin(plug, "plugin_dev"); + if (*plug_dev && getenv("DFHACK_NO_DEV_PLUGINS")) + { + con.print("Skipping dev plugin: %s\n", *plug_name); + plugin_abort_load; + return false; + } *plug_self = this; RefAutolock lock(access); plugin_init = (command_result (*)(color_ostream &, std::vector &)) LookupPlugin(plug, "plugin_init"); diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index befc030ff..603342d66 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -271,13 +271,20 @@ namespace DFHack } }; -/// You have to have this in every plugin you write - just once. Ideally on top of the main file. -#define DFHACK_PLUGIN(plugin_name) \ +#define DFHACK_PLUGIN_AUX(plugin_name, is_dev) \ DFhackDataExport const char * name = plugin_name;\ DFhackDataExport const char * version = get_dfhack_version();\ DFhackDataExport Plugin *plugin_self = NULL;\ std::vector _plugin_globals;\ - DFhackDataExport std::vector* plugin_globals = &_plugin_globals; + DFhackDataExport std::vector* plugin_globals = &_plugin_globals; \ + DFhackDataExport bool plugin_dev = is_dev; + +/// You have to include DFHACK_PLUGIN("plugin_name") in every plugin you write - just once. Ideally at the top of the main file. +#ifdef DEV_PLUGIN +#define DFHACK_PLUGIN(plugin_name) DFHACK_PLUGIN_AUX(plugin_name, true) +#else +#define DFHACK_PLUGIN(plugin_name) DFHACK_PLUGIN_AUX(plugin_name, false) +#endif #define DFHACK_PLUGIN_IS_ENABLED(varname) \ DFhackDataExport bool plugin_is_enabled = false; \ diff --git a/plugins/devel/CMakeLists.txt b/plugins/devel/CMakeLists.txt index 733d00179..e03d4c4b7 100644 --- a/plugins/devel/CMakeLists.txt +++ b/plugins/devel/CMakeLists.txt @@ -2,6 +2,7 @@ IF(UNIX) DFHACK_PLUGIN(vectors vectors.cpp) endif() +ADD_DEFINITIONS(-DDEV_PLUGIN) #DFHACK_PLUGIN(autolabor2 autolabor2.cpp) DFHACK_PLUGIN(buildprobe buildprobe.cpp) DFHACK_PLUGIN(counters counters.cpp)