| 28 | } |
| 29 | |
| 30 | bool ScriptModuleManager::Load(const std::string& name, const std::string& path) |
| 31 | { |
| 32 | if (m_Modules.count(name)) { |
| 33 | TN_ERROR("Module '%s' is already loaded.", name.c_str()); |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | auto dll = std::make_unique<DLL>(path.c_str()); |
| 38 | if (!dll->IsValid()) { |
| 39 | TN_WARN("Module '%s': DLL '%s' not found, scripting disabled.", name.c_str(), path.c_str()); |
| 40 | return false; |
| 41 | } |
| 42 | void* regSym = dll->GetSymbol("RegisterComponents"); |
| 43 | if (!regSym) { |
| 44 | TN_ERROR("'%s' has no RegisterComponents symbol.", path.c_str()); |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | reinterpret_cast<void(*)()>(regSym)(); |
| 49 | PropagateImGuiContext(dll.get()); |
| 50 | |
| 51 | std::vector<std::string> names; |
| 52 | void* namesSym = dll->GetSymbol("GetComponentNames"); |
| 53 | if (namesSym) { |
| 54 | using GetNamesFn = const std::vector<std::string>&(*)(); |
| 55 | names = reinterpret_cast<GetNamesFn>(namesSym)(); |
| 56 | } |
| 57 | |
| 58 | m_Modules.emplace(name, LoadedModule{ name, path, std::move(dll), std::move(names) }); |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | void ScriptModuleManager::Reload(const std::string& name, World* world) |
| 63 | { |
no test coverage detected