unloadExcept
Definition
-- @/lua/common/extensions.lua:338
local function unloadExcept(...)
-- log('I', logTag, "unloadExcept called...")
local exceptionList = {}
if #{...} > 1 then
for k,array in pairs({...}) do
for i, v in pairs(array) do
table.insert(exceptionList, v)
end
end
else
exceptionList = ... or {}
end
-- IMPORTANT: Expand the exception list to include their dependencies.
local expandedExceptionDict = {}
for _,mName in ipairs(exceptionList) do
expandedExceptionDict[mName] = true
end
local numToExclude = #exceptionList
local prevNumExcluded = 1
while true do
for i = prevNumExcluded, numToExclude do
local mName = exceptionList[i]
local m = luaMods[mName] or resolvedNameToModule[mName] or resolvedNormalizedNameToModule[mName]
if m and m.dependencies then
for _, depName in ipairs(m.dependencies) do
if not expandedExceptionDict[depName] then
table.insert(exceptionList, depName)
expandedExceptionDict[depName] = true
end
end
end
end
if numToExclude == #exceptionList then break end
prevNumExcluded = numToExclude + 1
numToExclude = #exceptionList
end
-- Now process the EXPANDED exception list to get the list of modules that need to be unloaded.
local modulesToUnload = {}
for i = #resolvedModules, 1, -1 do
-- check if its null because a previous unload may have also unloaded child extensions e.g. scenario unloads
-- its extensions so the entry for those extensions here would be null
if resolvedModules[i] then
local moduleName = resolvedModules[i].__extensionName__
if not expandedExceptionDict[moduleName] then
table.insert(modulesToUnload, moduleName)
end
end
end
if not tableIsEmpty(modulesToUnload) then
unloadInternal(modulesToUnload)
end
resolveDependencies()
end
Callers
@/lua/common/extensions.lua
-- unload all extension modules
unloadExcept()
@/lua/ge/main.lua
function unloadAutoExtensions()
extensions.unloadExcept(manualUnloadExtensions)
end
local endCallback = function ()
extensions.unloadExcept(manualUnloadExtensions)