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); return create(Get(), h);
} }
virtual Module* load(std::string modulePath) { virtual Module* reload(std::string lib) {
Module* m = dynamicLoad(modulePath);
return load(m); 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) { virtual Module* load(Module* m) {
@@ -157,11 +168,12 @@ namespace Archimedes {
if(h) { if(h) {
dlclose(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++) { for(auto it = runOrder.begin(); it != runOrder.end(); it++) {

View File

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

View File

@@ -18,6 +18,9 @@ Ollama::~Ollama() {
curl = nullptr; curl = nullptr;
} }
curl_global_cleanup(); curl_global_cleanup();
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
im->releaseContext(ImGui::GetCurrentContext());
} }
} }
@@ -36,7 +39,7 @@ void Ollama::onLoad() {
std::abort(); std::abort();
} }
ImGui::SetCurrentContext(im->getContext()); ImGui::SetCurrentContext(im->aquireContext());
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init(); curl = curl_easy_init();