mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 16:13:46 +01:00
Fix serialization of floating point numbers
This commit is contained in:
parent
47d9b4d9aa
commit
cd4324e5a8
@ -115,11 +115,20 @@ function core.serialize(x)
|
||||
function dump_val(x)
|
||||
local tp = type(x)
|
||||
if x == nil then return "nil"
|
||||
elseif tp == "number" then return string.format("%d", x)
|
||||
elseif tp == "string" then return string.format("%q", x)
|
||||
elseif tp == "boolean" then return x and "true" or "false"
|
||||
elseif tp == "function" then
|
||||
return string.format("loadstring(%q)", string.dump(x))
|
||||
elseif tp == "number" then
|
||||
-- Serialize integers with string.format to prevent
|
||||
-- scientific notation, which doesn't preserve
|
||||
-- precision and breaks things like node position
|
||||
-- hashes. Serialize floats normally.
|
||||
if math.floor(x) == x then
|
||||
return string.format("%d", x)
|
||||
else
|
||||
return tostring(x)
|
||||
end
|
||||
elseif tp == "table" then
|
||||
local vals = {}
|
||||
local idx_dumped = {}
|
||||
|
Loading…
Reference in New Issue
Block a user