aboutsummaryrefslogtreecommitdiff
path: root/builtin/common/serialize.lua
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2015-02-21 13:16:18 -0500
committerShadowNinja <shadowninja@minetest.net>2015-02-21 13:16:18 -0500
commitcd4324e5a800f12d4bbfea07a47d78e04eace920 (patch)
tree82075960fddceedda958b5c3f36498b4c38f1c42 /builtin/common/serialize.lua
parent47d9b4d9aa80e0268501b8eb927b37ee3660c503 (diff)
downloadminetest-cd4324e5a800f12d4bbfea07a47d78e04eace920.tar.gz
minetest-cd4324e5a800f12d4bbfea07a47d78e04eace920.tar.bz2
minetest-cd4324e5a800f12d4bbfea07a47d78e04eace920.zip
Fix serialization of floating point numbers
Diffstat (limited to 'builtin/common/serialize.lua')
-rw-r--r--builtin/common/serialize.lua11
1 files changed, 10 insertions, 1 deletions
diff --git a/builtin/common/serialize.lua b/builtin/common/serialize.lua
index 24b2a12ee..90b8b2ad6 100644
--- a/builtin/common/serialize.lua
+++ b/builtin/common/serialize.lua
@@ -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 = {}