summaryrefslogtreecommitdiff
path: root/library/PluginManager.cpp
diff options
context:
space:
mode:
authorPetr Mrázek2011-06-25 08:05:17 +0200
committerPetr Mrázek2011-06-25 08:05:17 +0200
commit722531f590a9f099b671c641d4c5afe3a2658b20 (patch)
tree3c8115d78f53e7ea1ade8245b3a465c694a894a7 /library/PluginManager.cpp
parent6fd7d42f0093ec5d057f35cd0a652c9ad254fc30 (diff)
downloaddfhack-722531f590a9f099b671c641d4c5afe3a2658b20.tar.gz
dfhack-722531f590a9f099b671c641d4c5afe3a2658b20.tar.bz2
dfhack-722531f590a9f099b671c641d4c5afe3a2658b20.tar.xz
Added destructor code for PluginManager, console color reset funstion.
Diffstat (limited to 'library/PluginManager.cpp')
-rw-r--r--library/PluginManager.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp
index bfee5423..072c6bae 100644
--- a/library/PluginManager.cpp
+++ b/library/PluginManager.cpp
@@ -119,7 +119,10 @@ Plugin::Plugin(Core * core, const std::string & file)
Plugin::~Plugin()
{
if(loaded)
+ {
+ plugin_shutdown(&Core::getInstance());
ClosePlugin(plugin_lib);
+ }
}
bool Plugin::isLoaded()
@@ -143,9 +146,10 @@ PluginManager::PluginManager(Core * core)
if(hasEnding(filez[i],searchstr))
{
Plugin * p = new Plugin(core, path + filez[i]);
- for(int j = 0; j < p->commands.size();j++)
+ Plugin & pr = *p;
+ for(int j = 0; j < pr.size();j++)
{
- commands[p->commands[j].name] = &p->commands[j];
+ commands[p->commands[j].name] = &pr[j];
}
all_plugins.push_back(p);
}
@@ -154,28 +158,32 @@ PluginManager::PluginManager(Core * core)
PluginManager::~PluginManager()
{
-
+ commands.clear();
+ for(int i = 0; i < all_plugins.size();i++)
+ {
+ delete all_plugins[i];
+ }
+ all_plugins.clear();
}
+
Plugin *PluginManager::getPluginByName (const std::string & name)
{
-
+ for(int i = 0; i < all_plugins.size(); i++)
+ {
+ if(name == all_plugins[i]->name)
+ return all_plugins[i];
+ }
+ return 0;
}
+
+// FIXME: handle name collisions...
command_result PluginManager::InvokeCommand( std::string & command, std::vector <std::string> & parameters)
{
Core * c = &Core::getInstance();
- map <string, PluginCommand *>::iterator iter = commands.find(command);
+ map <string, const PluginCommand *>::iterator iter = commands.find(command);
if(iter != commands.end())
{
return iter->second->function(c,parameters);
}
return CR_NOT_IMPLEMENTED;
}
-/*
-for (map <string, int (*)(Core *)>::iterator iter = plugins.begin(); iter != plugins.end(); iter++)
-{
- dfout << iter->first << endl;
-}
-*/
-/*
-
-*/ \ No newline at end of file