forked from knd/luatoml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.lua
44 lines (39 loc) · 990 Bytes
/
driver.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
-- TOML FILES
-- simple example
-- path = "./tests/simple.toml"
-- medium example
-- path = "./tests/medium.toml"
-- hard example
local path = "./tests/ecg.toml"
-- LOAD LIBRARY
local toml = require("luatoml")
-- READ FILE CONTENT
local file = io.open(path, "r")
local content = file:read("*all")
-- CONVERT TOML FORMAT TO LUA OBJECT
local luaObj = toml.load(content)
-- JSON PRINT TO CONSOLE TO SEE WHAT OUR LUA OBJECT LOOKS LIKE
local indent = -2
local function print_table(t)
indent = indent + 2
for k, v in pairs(t) do
if type(v) == "table" then
for i = 1, indent, 1 do
io.write(" ")
end
io.write(string.format("table: %s\n", k))
print_table(v)
for i = 1, indent, 1 do
io.write(" ")
end
io.write(string.format("end of table: %s\n", k))
else
for i = 1, indent, 1 do
io.write(" ")
end
io.write(string.format("%s = %s\n", k, v))
end
end
indent = indent - 2
end
print_table(luaObj)