reload lingering modules by name

This commit is contained in:
2025-04-21 11:53:08 -05:00
parent d253ebb197
commit 8f528c7f95
3 changed files with 24 additions and 10 deletions

View File

@@ -138,9 +138,20 @@ namespace Archimedes {
return create(Get(), h);
}
virtual Module* load(std::string modulePath) {
Module* m = dynamicLoad(modulePath);
return load(m);
virtual Module* reload(std::string lib) {
for(std::string s : runOrder) {
if(s == lib) {
return modules[lib];
}
}
return modules.find(lib) != modules.end() ? load(modules[lib]) : nullptr;
}
virtual Module* load(std::string moduleNameOrPath) {
Module* m = reload(moduleNameOrPath);
return m != nullptr ? m : dynamicLoad(moduleNameOrPath);
}
virtual Module* load(Module* m) {
@@ -157,11 +168,12 @@ namespace Archimedes {
if(h) {
dlclose(h);
}
return nullptr;
return modules[*it];
}
}
modules[*m] = m;
if(modules.find(*m) == modules.end())
modules[*m] = m;
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {

View File

@@ -25,13 +25,13 @@ namespace Archimedes {
virtual void run() {}
virtual bool onEvent(const Event& e) { return false; }
virtual void onLoad() {};
virtual void onLoad() {}
virtual void onUnload() {}
operator std::string() const { return name; }
void* getHandle() { return handle; }
//std::any getData(std::string s) { return data[s.c_str()]; };
protected:
std::string name;
@@ -42,7 +42,6 @@ namespace Archimedes {
std::unordered_map<std::string, std::variant<std::string, Module*>> exts;
std::unordered_map<std::string, Module*> moduleInstances;
//std::unordered_map<std::string, std::any> data;
};
}