|
|
@ -41,30 +41,38 @@ namespace DFHack
|
|
|
|
class PluginManager;
|
|
|
|
class PluginManager;
|
|
|
|
enum command_result
|
|
|
|
enum command_result
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
CR_WOULD_BREAK = -2,
|
|
|
|
CR_NOT_IMPLEMENTED = -1,
|
|
|
|
CR_NOT_IMPLEMENTED = -1,
|
|
|
|
CR_FAILURE = 0,
|
|
|
|
CR_FAILURE = 0,
|
|
|
|
CR_OK = 1
|
|
|
|
CR_OK = 1
|
|
|
|
};
|
|
|
|
};
|
|
|
|
struct PluginCommand
|
|
|
|
struct PluginCommand
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/// create a command with a name, description, function pointer to its code
|
|
|
|
|
|
|
|
/// and saying if it needs an interactive terminal
|
|
|
|
|
|
|
|
/// Most commands shouldn't require an interactive terminal!
|
|
|
|
PluginCommand(const char * _name,
|
|
|
|
PluginCommand(const char * _name,
|
|
|
|
const char * _description,
|
|
|
|
const char * _description,
|
|
|
|
command_result (*function_)(Core *, std::vector <std::string> &)
|
|
|
|
command_result (*function_)(Core *, std::vector <std::string> &),
|
|
|
|
|
|
|
|
bool interactive_ = false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name = _name;
|
|
|
|
name = _name;
|
|
|
|
description = _description;
|
|
|
|
description = _description;
|
|
|
|
function = function_;
|
|
|
|
function = function_;
|
|
|
|
|
|
|
|
interactive = interactive_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PluginCommand (const PluginCommand & rhs)
|
|
|
|
PluginCommand (const PluginCommand & rhs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name = rhs.name;
|
|
|
|
name = rhs.name;
|
|
|
|
description = rhs.description;
|
|
|
|
description = rhs.description;
|
|
|
|
function = rhs.function;
|
|
|
|
function = rhs.function;
|
|
|
|
|
|
|
|
interactive = rhs.interactive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::string name;
|
|
|
|
std::string name;
|
|
|
|
std::string description;
|
|
|
|
std::string description;
|
|
|
|
command_result (*function)(Core *, std::vector <std::string> &);
|
|
|
|
command_result (*function)(Core *, std::vector <std::string> &);
|
|
|
|
|
|
|
|
bool interactive;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
class Plugin
|
|
|
|
class Plugin
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -83,7 +91,7 @@ namespace DFHack
|
|
|
|
bool load();
|
|
|
|
bool load();
|
|
|
|
bool unload();
|
|
|
|
bool unload();
|
|
|
|
bool reload();
|
|
|
|
bool reload();
|
|
|
|
command_result invoke( std::string & command, std::vector <std::string> & parameters );
|
|
|
|
command_result invoke( std::string & command, std::vector <std::string> & parameters, bool interactive );
|
|
|
|
plugin_state getState () const;
|
|
|
|
plugin_state getState () const;
|
|
|
|
const PluginCommand& operator[] (std::size_t index) const
|
|
|
|
const PluginCommand& operator[] (std::size_t index) const
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -123,7 +131,7 @@ namespace DFHack
|
|
|
|
// PUBLIC METHODS
|
|
|
|
// PUBLIC METHODS
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
Plugin *getPluginByName (const std::string & name);
|
|
|
|
Plugin *getPluginByName (const std::string & name);
|
|
|
|
command_result InvokeCommand( std::string & command, std::vector <std::string> & parameters );
|
|
|
|
command_result InvokeCommand( std::string & command, std::vector <std::string> & parameters, bool interactive = true );
|
|
|
|
Plugin* operator[] (std::size_t index)
|
|
|
|
Plugin* operator[] (std::size_t index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(index >= all_plugins.size())
|
|
|
|
if(index >= all_plugins.size())
|
|
|
|