From 0bbbacf161aa0f4bd4869d108f56d85f9c5ec8e6 Mon Sep 17 00:00:00 2001 From: myk002 Date: Tue, 2 Aug 2022 18:40:50 -0700 Subject: [PATCH] extend the docs and examples in skeleton.cpp --- plugins/examples/skeleton.cpp | 221 +++++++++++++++++++++------------- 1 file changed, 134 insertions(+), 87 deletions(-) diff --git a/plugins/examples/skeleton.cpp b/plugins/examples/skeleton.cpp index 7d5936f6d..e1f552d31 100644 --- a/plugins/examples/skeleton.cpp +++ b/plugins/examples/skeleton.cpp @@ -1,65 +1,71 @@ -// This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D +// This is an example plugin that just documents and implements all the plugin +// callbacks and features. You can compile it, load it, run it, and see the +// debug messages get printed to the console. +// +// See the other example plugins in this directory for plugins that are +// configured for specific use cases (but don't come with as many comments as +// this one does). + +#include +#include + +#include "df/world.h" -// some headers required for a plugin. Nothing special, just the basics. #include "Core.h" -#include -#include -#include -#include -// If you need to save data per-world: -//#include "modules/Persistence.h" +#include "Debug.h" +#include "LuaTools.h" +#include "PluginManager.h" -// DF data structure definition headers -#include "DataDefs.h" -//#include "df/world.h" +#include "modules/Persistence.h" +#include "modules/World.h" -// our own, empty header. -#include "skeleton.h" +using std::string; +using std::vector; using namespace DFHack; -using namespace df::enums; -// Expose the plugin name to the DFHack core, as well as metadata like the DFHack version. -// The name string provided must correspond to the filename - +// Expose the plugin name to the DFHack core, as well as metadata like the +// DFHack version that this plugin was compiled with. This macro provides a +// variable for the plugin name as const char * plugin_name. +// The name provided must correspond to the filename -- // skeleton.plug.so, skeleton.plug.dylib, or skeleton.plug.dll in this case DFHACK_PLUGIN("skeleton"); -// The identifier declared with this macro (ie. enabled) can be specified by the user -// and subsequently used to manage the plugin's operations. -// This will also be tracked by `plug`; when true the plugin will be shown as enabled. -DFHACK_PLUGIN_IS_ENABLED(enabled); +// The identifier declared with this macro (i.e. is_enabled) is used to track +// whether the plugin is in an "enabled" state. If you don't need enablement +// for your plugin, you don't need this line. This variable will also be read +// by the `plug` builtin command; when true the plugin will be shown as enabled. +DFHACK_PLUGIN_IS_ENABLED(is_enabled); // Any globals a plugin requires (e.g. world) should be listed here. // For example, this line expands to "using df::global::world" and prevents the -// plugin from being loaded if df::global::world is null (i.e. missing from symbols.xml): -// +// plugin from being loaded if df::global::world is null (i.e. missing from +// symbols.xml). REQUIRE_GLOBAL(world); -// You may want some compile time debugging options -// one easy system just requires you to cache the color_ostream &out into a global debug variable -//#define P_DEBUG 1 -//uint16_t maxTickFreq = 1200; //maybe you want to use some events +// logging levels can be dynamically controlled with the `debugfilter` command. +namespace DFHack { + // for configuration-related logging + DBG_DECLARE(skeleton, status, DebugCategory::LINFO); + // for logging during the periodic scan + DBG_DECLARE(skeleton, cycle, DebugCategory::LINFO); +} -command_result command_callback1(color_ostream &out, std::vector ¶meters); +command_result command_callback1(color_ostream &out, vector ¶meters); +// run when the plugin is loaded DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { - commands.push_back(PluginCommand("skeleton", - "~54 character description of plugin", //to use one line in the ``[DFHack]# ls`` output - command_callback1, - false, - "example usage" - " skeleton