lua: fix enabling/disabling (#2745)

This commit is contained in:
Quentin 2024-02-21 13:05:01 +01:00 committed by GitHub
parent 2d55470e10
commit cde5563204
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -180,10 +180,12 @@ namespace big
const auto module_path = module->module_path(); const auto module_path = module->module_path();
// unload module // unload module
{
std::lock_guard guard(m_disabled_module_lock); std::lock_guard guard(m_disabled_module_lock);
std::erase_if(m_disabled_modules, [module_id](auto& module) { std::erase_if(m_disabled_modules, [module_id](auto& module) {
return module_id == module->module_id(); return module_id == module->module_id();
}); });
}
const auto new_module_path = move_file_relative_to_folder(m_disabled_scripts_folder.get_path(), m_scripts_folder.get_path(), module_path); const auto new_module_path = move_file_relative_to_folder(m_disabled_scripts_folder.get_path(), m_scripts_folder.get_path(), module_path);
if (new_module_path) if (new_module_path)
@ -202,10 +204,12 @@ namespace big
const auto module_path = module->module_path(); const auto module_path = module->module_path();
// unload module // unload module
{
std::lock_guard guard(m_disabled_module_lock); std::lock_guard guard(m_disabled_module_lock);
std::erase_if(m_modules, [module_id](auto& module) { std::erase_if(m_modules, [module_id](auto& module) {
return module_id == module->module_id(); return module_id == module->module_id();
}); });
}
const auto new_module_path = move_file_relative_to_folder(m_scripts_folder.get_path(), m_disabled_scripts_folder.get_path(), module_path); const auto new_module_path = move_file_relative_to_folder(m_scripts_folder.get_path(), m_disabled_scripts_folder.get_path(), module_path);
if (new_module_path) if (new_module_path)
@ -219,10 +223,14 @@ namespace big
void lua_manager::unload_module(rage::joaat_t module_id) void lua_manager::unload_module(rage::joaat_t module_id)
{ {
std::lock_guard guard(m_module_lock); std::lock_guard guard(m_module_lock);
std::erase_if(m_modules, [module_id](auto& module) { std::erase_if(m_modules, [module_id](auto& module) {
return module_id == module->module_id(); return module_id == module->module_id();
}); });
std::lock_guard guard2(m_disabled_module_lock);
std::erase_if(m_disabled_modules, [module_id](auto& module) {
return module_id == module->module_id();
});
} }
std::weak_ptr<lua_module> lua_manager::load_module(const std::filesystem::path& module_path) std::weak_ptr<lua_module> lua_manager::load_module(const std::filesystem::path& module_path)