summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Mueller <appgurulars@gmx.de>2022-08-17 18:48:55 +0200
committersfan5 <sfan5@live.de>2022-09-14 13:48:06 +0200
commit129aef758ece753e684aa494e5471045a996ac8f (patch)
tree13e3199674d8c8c97c1fbc53dec4573555c42518
parent94f55cf406dddcfd4d3507e9da7f64e5de021ee4 (diff)
downloadminetest-129aef758ece753e684aa494e5471045a996ac8f.tar.gz
minetest-129aef758ece753e684aa494e5471045a996ac8f.tar.bz2
minetest-129aef758ece753e684aa494e5471045a996ac8f.zip
Serialize: Restore forward compatibility
-rw-r--r--builtin/common/serialize.lua19
1 files changed, 14 insertions, 5 deletions
diff --git a/builtin/common/serialize.lua b/builtin/common/serialize.lua
index 06eb181e0..afa63b362 100644
--- a/builtin/common/serialize.lua
+++ b/builtin/common/serialize.lua
@@ -70,6 +70,9 @@ local function serialize(value, write)
local type_ = type(object)
-- Object must appear more than once. If it is a string, the reference has to be shorter than the string.
if count >= 2 and (type_ ~= "string" or #reference + 5 < #object) then
+ if refnum == 1 then
+ write"local _={};" -- initialize reference table
+ end
write"_["
write(reference)
write("]=")
@@ -106,7 +109,15 @@ local function serialize(value, write)
end
local type_ = type(value)
if type_ == "number" then
- return write(string_format("%.17g", value))
+ if value ~= value then -- nan
+ return write"0/0"
+ elseif value == math_huge then
+ return write"1/0"
+ elseif value == -math_huge then
+ return write"-1/0"
+ else
+ return write(string_format("%.17g", value))
+ end
end
-- Reference types: table, function and string
local ref = references[value]
@@ -190,8 +201,6 @@ end
local function dummy_func() end
-local nan = (0/0)^1 -- +nan
-
function core.deserialize(str, safe)
-- Backwards compatibility
if str == nil then
@@ -206,8 +215,8 @@ function core.deserialize(str, safe)
local func, err = loadstring(str)
if not func then return nil, err end
- -- math.huge is serialized to inf, NaNs are serialized to nan by Lua
- local env = {inf = math_huge, nan = nan, _ = {}}
+ -- math.huge was serialized to inf and NaNs to nan by Lua in Minetest 5.6, so we have to support this here
+ local env = {inf = math_huge, nan = 0/0}
if safe then
env.loadstring = dummy_func
else