forked from Brodur/Serialization-Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialutils.lua
More file actions
31 lines (26 loc) · 764 Bytes
/
Copy pathserialutils.lua
File metadata and controls
31 lines (26 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--- Serial Utils
-- Utility functions to save and load tables from files.
-- @Author: Brodur
-- @Version: 1.0
local sz = require("serialization")
local io = require("io")
local serialutils = {}
--- Save
-- Save the contents of given table to a file.
-- @param tbl The table to save.
-- @param dir Where to save the table.
function serialutils.save(tbl, dir)
file = io.open(dir, "w")
file:write(sz.serialize(tbl))
file:close()
end
--- Load
-- Loads the serialized database from file.
-- @param dir The directory where the database is located.
-- @return The parsed serial table.
function serialutils.load(dir)
str = ""
for line in io.lines(dir) do str = str .. line end
return sz.unserialize(str)
end
return serialutils