diff options
author | ShadowNinja <shadowninja@minetest.net> | 2014-10-24 15:01:46 -0400 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2014-10-24 16:45:10 -0400 |
commit | 796aa3870d5cd45696cb253024aa75e8bbc2b462 (patch) | |
tree | ea17e9c6e87af555427f1ec9c8ce9bce2be66c57 /worldedit/compatibility.lua | |
parent | 70c24c9501c691d85bbe267ee79547fb490e6c00 (diff) |
Clean up serialization
* Adds a header to serialized data (to make version checking sane).
* Removes the duplicate deserialization for `worldedit.deserialize` and `worldedit.allocate`.
* Optimizes `worldedit.deserialize` by only deserializing the data once.
* Makes some fields optional.
* Cleans up the comments and a little of the code style.
Diffstat (limited to 'worldedit/compatibility.lua')
-rw-r--r-- | worldedit/compatibility.lua | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/worldedit/compatibility.lua b/worldedit/compatibility.lua index ff3447f..e44e43b 100644 --- a/worldedit/compatibility.lua +++ b/worldedit/compatibility.lua @@ -2,7 +2,9 @@ worldedit = worldedit or {} local minetest = minetest --local copy of global
worldedit.allocate_old = worldedit.allocate
+
worldedit.deserialize_old = worldedit.deserialize
+
worldedit.metasave = function(pos1, pos2, filename)
local file, err = io.open(filename, "wb")
if err then return 0 end
@@ -11,6 +13,7 @@ worldedit.metasave = function(pos1, pos2, filename) file:close()
return count
end
+
worldedit.metaload = function(originpos, filename)
filename = minetest.get_worldpath() .. "/schems/" .. file .. ".wem"
local file, err = io.open(filename, "wb")
@@ -18,6 +21,16 @@ worldedit.metaload = function(originpos, filename) local data = file:read("*a")
return worldedit.deserialize(originpos, data)
end
+
worldedit.scale = function(pos1, pos2, factor)
return worldedit.stretch(pos1, pos2, factor, factor, factor)
-end
\ No newline at end of file +end
+
+worldedit.valueversion = function(value)
+ local version = worldedit.read_header(value)
+ if not version or version > worldedit.LATEST_SERIALIZATION_VERSION then
+ return 0
+ end
+ return version
+end
+
|