1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-15 01:25:20 +02:00

Deprecate function support in core.[de]serialize

This commit is contained in:
Lars Müller
2025-04-23 21:39:27 +02:00
committed by GitHub
parent f2ea4a4565
commit dd2e45ee82
5 changed files with 78 additions and 22 deletions

View File

@@ -190,7 +190,33 @@ local function serialize(value, write)
dump(value)
end
-- Whether `value` recursively contains a function
local function contains_function(value)
local seen = {}
local function check(val)
if type(val) == "function" then
return true
end
if type(val) == "table" then
if seen[val] then
return false
end
seen[val] = true
for k, v in pairs(val) do
if check(k) or check(v) then
return true
end
end
end
return false
end
return check(value)
end
function core.serialize(value)
if contains_function(value) then
core.log("deprecated", "Support for dumping functions in `core.serialize` is deprecated.")
end
local rope = {}
serialize(value, function(text)
-- Faster than table.insert(rope, text) on PUC Lua 5.1