-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.lua
More file actions
48 lines (41 loc) · 1.05 KB
/
main.lua
File metadata and controls
48 lines (41 loc) · 1.05 KB
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
local function printTable(t,offset)
offset = offset or ''
for i,v in pairs(t) do
if(type(v)=='table') then
print(offset ..i ..' :')
printTable(v,offset..'\t')
else
print(offset ..i ..' : '..tostring(v))
end
end
end
local tableToBeSaved = {
i_am_boolean = true,
name = 'myTable',
randomNumbers = {},
point = {
x=0, y=0, z=0, label = 'originPoint'
}
}
for i=1,10 do
table.insert(tableToBeSaved.randomNumbers,math.random(50))
end
local tableIO = require('tableIO')
--Saving table to .lua file
tableIO.save(tableToBeSaved,'savedTable.lua')
local p = io.open('savedTable.txt','w')
--Getting string selrialization and writing it
p:write(tableIO.tableToString(tableToBeSaved))
p:close()
--Getting back the string serialization
p = io.open('savedTable.txt','r')
local str = p:read('*all')
p:close()
--Getting .lua table with require
local tableRead = require 'savedTable'
--Geting table from deserialization
local tableRead2 = tableIO.stringToTable(str)
print('\nTable from .lua')
printTable(tableRead)
print('\nTable from .txt')
printTable(tableRead2)