Add: serializer_type

This commit is contained in:
Coder12a 2019-05-23 10:22:53 -05:00
parent d895624689
commit e70923c8fc

View File

@ -1,5 +1,8 @@
colddb = {}
colddb.serializers = {}
colddb.serializers.default = 0
function colddb.Colddb(dir)
if not minetest.mkdir(dir) then
error(string.format("%s is not a directory.", dir))
@ -13,6 +16,9 @@ function colddb.Colddb(dir)
local add_to_mem_pool = true
local async = async.Async()
local use_async = true
local serializer = minetest.serialize
local deserializer = minetest.deserialize
local serializer_type = colddb.serializers.default
async.priority(150, 250)
@ -58,6 +64,18 @@ function colddb.Colddb(dir)
use_async = value
end
self.get_serializer_type = function(value)
return serializer_type
end
self.set_serializer_type = function(value)
serializer_type = value
if serializer_type == colddb.serializers.default then
serializer = minetest.serialize
deserializer = minetest.deserialize
end
end
local function file_exists(name)
local f = io.open(string.format("%s/%s.cold", directory, name), "r")
if f ~= nil then
@ -91,7 +109,7 @@ function colddb.Colddb(dir)
local function load_table(name)
local f = io.open(string.format("%s/%s.cold", directory, name), "r")
if f then
local data = minetest.deserialize(f:read("*a"))
local data = deserializer(f:read("*a"))
f:close()
return data
end