local storage = minetest.get_mod_storage()


local data = {}

--register a table, the content of which is stored
mob_spawning_director.intramodcom.register_for_storage = function(key, tab)
	--registering non-tables would make it so they would be copies, not
	--references making them immutable by the user program
	assert(type(tab) == "table",
		"Cannot register non-table values to be handled by storage")
	
	--this function gets called after load time so data may contain something
	--loaded from mod storage
	if data[key]
	then
		--tab is no longer needed since it's replaced by a loaded table
		tab = data[key]
	else
		data[key] = tab
	end
	--return whatever table gets stored.
	--It's a reference so the data it contains is both visible
	--and mutable by the functions here and the user program
	return tab
end




local function save()
	--convert data from table form to string
	local data = minetest.serialize(data)
	storage:set_string("data", data)
end
minetest.register_on_shutdown(save)


local function load()
	local loaddata = storage:get_string("data")
	if loaddata ~= ""
	then
		--convert back to table
		data = minetest.deserialize(loaddata)	
	end
end
load()



