forked from minetest-mods/mesecons
Luacontroller: Fix remove_functions
stack overflow bug
This commit is contained in:
parent
4249ed4986
commit
6cae381c27
@ -229,23 +229,35 @@ end
|
|||||||
|
|
||||||
local function remove_functions(x)
|
local function remove_functions(x)
|
||||||
local tp = type(x)
|
local tp = type(x)
|
||||||
if tp == "table" then
|
if tp == "function" then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Make sure to not serialize the same table multiple times, otherwise
|
||||||
|
-- writing mem.test = mem in the LuaController will lead to infinite recursion
|
||||||
|
local seen = {}
|
||||||
|
|
||||||
|
local function rfuncs(x)
|
||||||
|
if seen[x] then return end
|
||||||
|
seen[x] = true
|
||||||
|
if type(x) ~= "table" then return end
|
||||||
|
|
||||||
for key, value in pairs(x) do
|
for key, value in pairs(x) do
|
||||||
local key_t, val_t = type(key), type(value)
|
if type(key) == "function" or type(value) == "function" then
|
||||||
if key_t == "function" or val_t == "function" then
|
|
||||||
x[key] = nil
|
x[key] = nil
|
||||||
else
|
else
|
||||||
if key_t == "table" then
|
if type(key) == "table" then
|
||||||
remove_functions(key)
|
rfuncs(key)
|
||||||
end
|
end
|
||||||
if val_t == "table" then
|
if type(value) == "table" then
|
||||||
remove_functions(value)
|
rfuncs(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif tp == "function" then
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rfuncs(x)
|
||||||
|
|
||||||
return x
|
return x
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user