Add: serializer_type
This commit is contained in:
parent
d895624689
commit
e70923c8fc
20
colddb.lua
20
colddb.lua
|
@ -1,5 +1,8 @@
|
||||||
colddb = {}
|
colddb = {}
|
||||||
|
|
||||||
|
colddb.serializers = {}
|
||||||
|
colddb.serializers.default = 0
|
||||||
|
|
||||||
function colddb.Colddb(dir)
|
function colddb.Colddb(dir)
|
||||||
if not minetest.mkdir(dir) then
|
if not minetest.mkdir(dir) then
|
||||||
error(string.format("%s is not a directory.", dir))
|
error(string.format("%s is not a directory.", dir))
|
||||||
|
@ -13,6 +16,9 @@ function colddb.Colddb(dir)
|
||||||
local add_to_mem_pool = true
|
local add_to_mem_pool = true
|
||||||
local async = async.Async()
|
local async = async.Async()
|
||||||
local use_async = true
|
local use_async = true
|
||||||
|
local serializer = minetest.serialize
|
||||||
|
local deserializer = minetest.deserialize
|
||||||
|
local serializer_type = colddb.serializers.default
|
||||||
|
|
||||||
async.priority(150, 250)
|
async.priority(150, 250)
|
||||||
|
|
||||||
|
@ -58,6 +64,18 @@ function colddb.Colddb(dir)
|
||||||
use_async = value
|
use_async = value
|
||||||
end
|
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 function file_exists(name)
|
||||||
local f = io.open(string.format("%s/%s.cold", directory, name), "r")
|
local f = io.open(string.format("%s/%s.cold", directory, name), "r")
|
||||||
if f ~= nil then
|
if f ~= nil then
|
||||||
|
@ -91,7 +109,7 @@ function colddb.Colddb(dir)
|
||||||
local function load_table(name)
|
local function load_table(name)
|
||||||
local f = io.open(string.format("%s/%s.cold", directory, name), "r")
|
local f = io.open(string.format("%s/%s.cold", directory, name), "r")
|
||||||
if f then
|
if f then
|
||||||
local data = minetest.deserialize(f:read("*a"))
|
local data = deserializer(f:read("*a"))
|
||||||
f:close()
|
f:close()
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user