-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialize.lua
85 lines (65 loc) · 2.16 KB
/
serialize.lua
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--[[****************************************************************/
/* __/\\\________/\\\____/\\\\\\\\\________/\\\\\\\\\_____ */
/* _\/\\\_____/\\\//___/\\\///////\\\____/\\\///////\\\___ */
/* _\/\\\__/\\\//_____\/\\\_____\/\\\___\///______\//\\\__ */
/* _\/\\\\\\//\\\_____\/\\\\\\\\\\\/______________/\\\/___ */
/* _\/\\\//_\//\\\____\/\\\//////\\\___________/\\\//_____ */
/* _\/\\\____\//\\\___\/\\\____\//\\\_______/\\\//________ */
/* _\/\\\_____\//\\\__\/\\\_____\//\\\____/\\\/___________ */
/* _\/\\\______\//\\\_\/\\\______\//\\\__/\\\\\\\\\\\\\\\_ */
/* _\///________\///__\///________\///__\///////////////__ */
/* */
/****************************************************************--]]
--[[
* @file serialize.lua
* @path -
* @version 2
*
* @date 30.09.2011
* @author KR2
*
* @brief serializaten and deserialization
*
example:
require 'serialize'
t_original = {'one','two','three','four', { 'five', 'six', 'seven'}, 'eight' }
serialize.serialize(t_original,"test")
print "Saved"
testDes = serialize.deserialize("test")
print (testDes[1])
print (testDes[2])
print (testDes[3])
print (testDes[5][2])
print "done"
--]]
module(..., package.seeall)
fsH = require 'fileSystemHelper'
require 'persistence'
local logicDir = "/userdata/logic/" -- root path for serialization files
local fileExt = ".lser" -- root path for serialization files
if _G._isSimulation then
logicDir = "C:\\logic\\"
end
--- serializes preverable tabels
-- key is as well the filename with the extention fileExt
-- @param what tabel or variable
-- @param key key sting for storing and restoring
--
function serialize(what,key)
local dir = logicDir .. key .. fileExt
if (io.open(dir) == nil) then
fsH.mkfile(logicDir,key .. fileExt)
end
persistence.store(dir, what)
end
--- dezerializes stuff and returns it
-- @param key of the stuff to dezerilize
-- @return the stuff dezerilized
--
function deserialize(key)
local dir = logicDir .. key .. fileExt
if (io.open(dir) == nil) then
return nil
end
return persistence.load(dir)
end