mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Deprecate function support in core.[de]serialize
This commit is contained in:
parent
f2ea4a4565
commit
dd2e45ee82
5 changed files with 78 additions and 22 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue