Fix infinite loop with circular dependencies.
This commit is contained in:
parent
22030aa96c
commit
c6eda04dea
67
init.lua
67
init.lua
|
@ -33,38 +33,51 @@ local csm_order = false
|
||||||
-- Recalculate the CSM loading order
|
-- Recalculate the CSM loading order
|
||||||
-- TODO: Make this nicer
|
-- TODO: Make this nicer
|
||||||
local function recalc_csm_order()
|
local function recalc_csm_order()
|
||||||
local loaded = {[':init'] = true, [':cleanup'] = true}
|
local loaded = {}
|
||||||
local not_loaded = {}
|
local staging = {}
|
||||||
local order = {':init'}
|
local order = {':init'}
|
||||||
for k, v in pairs(sscsm.registered_csms) do
|
local unsatisfied = {}
|
||||||
if k:sub(1, 1) ~= ':' then
|
for name, def in pairs(sscsm.registered_csms) do
|
||||||
table.insert(not_loaded, v)
|
assert(name == def.name)
|
||||||
end
|
if name:sub(1, 1) == ':' then
|
||||||
end
|
loaded[name] = true
|
||||||
while #not_loaded > 0 do
|
elseif not def.depends or #def.depends == 0 then
|
||||||
local def = not_loaded[1]
|
loaded[name] = true
|
||||||
local g = not def.depends or #def.depends == 0
|
table.insert(staging, name)
|
||||||
if not g then
|
else
|
||||||
g = true
|
unsatisfied[name] = {}
|
||||||
for _, mod in ipairs(def.depends) do
|
for _, mod in ipairs(def.depends) do
|
||||||
if not sscsm.registered_csms[mod] then
|
if mod:sub(1, 1) ~= ':' then
|
||||||
minetest.log('error', '[SSCSM] SSCSM "' .. def.name ..
|
unsatisfied[name][mod] = true
|
||||||
'" has an unsatisfied dependency: ' .. mod)
|
end
|
||||||
g = false
|
end
|
||||||
break
|
end
|
||||||
elseif not loaded[mod] then
|
end
|
||||||
table.insert(not_loaded, def)
|
while #staging > 0 do
|
||||||
g = false
|
local name = staging[1]
|
||||||
break
|
for name2, u in pairs(unsatisfied) do
|
||||||
|
if u[name] then
|
||||||
|
u[name] = nil
|
||||||
|
if #u == 0 then
|
||||||
|
table.insert(staging, name2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if g then
|
table.insert(order, name)
|
||||||
table.insert(order, def.name)
|
table.remove(staging, 1)
|
||||||
loaded[def.name] = true
|
end
|
||||||
|
|
||||||
|
for name, u in pairs(unsatisfied) do
|
||||||
|
if next(u) then
|
||||||
|
local msg = 'SSCSM "' .. name .. '" has unsatisfied dependencies: '
|
||||||
|
local n = false
|
||||||
|
for dep, _ in pairs(u) do
|
||||||
|
if n then msg = msg .. ', ' else n = true end
|
||||||
|
msg = msg .. '"' .. dep .. '"'
|
||||||
|
end
|
||||||
|
minetest.log('error', msg)
|
||||||
end
|
end
|
||||||
table.remove(not_loaded, 1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set csm_order
|
-- Set csm_order
|
||||||
|
@ -157,7 +170,7 @@ minetest.after(1, function()
|
||||||
|
|
||||||
sscsm.register({
|
sscsm.register({
|
||||||
name = 'sscsm:testing_cmds',
|
name = 'sscsm:testing_cmds',
|
||||||
file = modpath .. '/sscsm_testing.lua'
|
file = modpath .. '/sscsm_testing.lua',
|
||||||
})
|
})
|
||||||
|
|
||||||
sscsm.register({
|
sscsm.register({
|
||||||
|
@ -169,7 +182,7 @@ minetest.after(1, function()
|
||||||
sscsm.register({
|
sscsm.register({
|
||||||
name = 'sscsm:badtest',
|
name = 'sscsm:badtest',
|
||||||
code = 'error("Oops, badtest loaded!")',
|
code = 'error("Oops, badtest loaded!")',
|
||||||
depends = {':init', ':cleanup', 'bad_mod'}
|
depends = {':init', ':cleanup', 'bad_mod', ':bad2', 'bad3'},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue