diff options
author | HybridDog <3192173+HybridDog@users.noreply.github.com> | 2020-04-22 16:43:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-22 16:43:48 +0200 |
commit | 5355cb1d87f60bc5548a8a9311e597b9c6046013 (patch) | |
tree | c5aabae94525edead5e5ae8ee854bde2520e6ee1 /builtin/common/serialize.lua | |
parent | 4361bfcb4da0b6f9de74c7de9f2d08084877713e (diff) | |
download | minetest-5355cb1d87f60bc5548a8a9311e597b9c6046013.tar.gz minetest-5355cb1d87f60bc5548a8a9311e597b9c6046013.tar.bz2 minetest-5355cb1d87f60bc5548a8a9311e597b9c6046013.zip |
minetest.serialize: Reversible number serialization (#9722)
* minetest.serialize: Reversible number to string conversion
The %a format is not supported in Lua 5.1.
This commit also adds two tests for number serialization.
Diffstat (limited to 'builtin/common/serialize.lua')
-rw-r--r-- | builtin/common/serialize.lua | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/builtin/common/serialize.lua b/builtin/common/serialize.lua index 163aa67ad..300b394c6 100644 --- a/builtin/common/serialize.lua +++ b/builtin/common/serialize.lua @@ -120,15 +120,8 @@ function core.serialize(x) 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 + -- Serialize numbers reversibly with string.format + return string.format("%.17g", x) elseif tp == "table" then local vals = {} local idx_dumped = {} |