1function print_table(node)
2 local cache, stack, output = {},{},{}
3 local depth = 1
4 local output_str = "{\n"
5
6 while true do
7 local size = 0
8 for k,v in pairs(node) do
9 size = size + 1
10 end
11
12 local cur_index = 1
13 for k,v in pairs(node) do
14 if (cache[node] == nil) or (cur_index >= cache[node]) then
15
16 if (string.find(output_str,"}",output_str:len())) then
17 output_str = output_str .. ",\n"
18 elseif not (string.find(output_str,"\n",output_str:len())) then
19 output_str = output_str .. "\n"
20 end
21
22 -- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge strings
23 table.insert(output,output_str)
24 output_str = ""
25
26 local key
27 if (type(k) == "number" or type(k) == "boolean") then
28 key = "["..tostring(k).."]"
29 else
30 key = "['"..tostring(k).."']"
31 end
32
33 if (type(v) == "number" or type(v) == "boolean") then
34 output_str = output_str .. string.rep('\t',depth) .. key .. " = "..tostring(v)
35 elseif (type(v) == "table") then
36 output_str = output_str .. string.rep('\t',depth) .. key .. " = {\n"
37 table.insert(stack,node)
38 table.insert(stack,v)
39 cache[node] = cur_index+1
40 break
41 else
42 output_str = output_str .. string.rep('\t',depth) .. key .. " = '"..tostring(v).."'"
43 end
44
45 if (cur_index == size) then
46 output_str = output_str .. "\n" .. string.rep('\t',depth-1) .. "}"
47 else
48 output_str = output_str .. ","
49 end
50 else
51 -- close the table
52 if (cur_index == size) then
53 output_str = output_str .. "\n" .. string.rep('\t',depth-1) .. "}"
54 end
55 end
56
57 cur_index = cur_index + 1
58 end
59
60 if (size == 0) then
61 output_str = output_str .. "\n" .. string.rep('\t',depth-1) .. "}"
62 end
63
64 if (#stack > 0) then
65 node = stack[#stack]
66 stack[#stack] = nil
67 depth = cache[node] == nil and depth + 1 or depth - 1
68 else
69 break
70 end
71 end
72
73 -- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge strings
74 table.insert(output,output_str)
75 output_str = table.concat(output)
76
77 print(output_str)
78end
79
1function print_table(node)
2 local cache, stack, output = {},{},{}
3 local depth = 1
4 local output_str = "{\n"
5
6 while true do
7 local size = 0
8 for k,v in pairs(node) do
9 size = size + 1
10 end
11
12 local cur_index = 1
13 for k,v in pairs(node) do
14 if (cache[node] == nil) or (cur_index >= cache[node]) then
15
16 if (string.find(output_str,"}",output_str:len())) then
17 output_str = output_str .. ",\n"
18 elseif not (string.find(output_str,"\n",output_str:len())) then
19 output_str = output_str .. "\n"
20 end
21
22 -- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge strings
23 table.insert(output,output_str)
24 output_str = ""
25
26 local key
27 if (type(k) == "number" or type(k) == "boolean") then
28 key = "["..tostring(k).."]"
29 else
30 key = "['"..tostring(k).."']"
31 end
32
33 if (type(v) == "number" or type(v) == "boolean") then
34 output_str = output_str .. string.rep('\t',depth) .. key .. " = "..tostring(v)
35 elseif (type(v) == "table") then
36 output_str = output_str .. string.rep('\t',depth) .. key .. " = {\n"
37 table.insert(stack,node)
38 table.insert(stack,v)
39 cache[node] = cur_index+1
40 break
41 else
42 output_str = output_str .. string.rep('\t',depth) .. key .. " = '"..tostring(v).."'"
43 end
44
45 if (cur_index == size) then
46 output_str = output_str .. "\n" .. string.rep('\t',depth-1) .. "}"
47 else
48 output_str = output_str .. ","
49 end
50 else
51 -- close the table
52 if (cur_index == size) then
53 output_str = output_str .. "\n" .. string.rep('\t',depth-1) .. "}"
54 end
55 end
56
57 cur_index = cur_index + 1
58 end
59
60 if (size == 0) then
61 output_str = output_str .. "\n" .. string.rep('\t',depth-1) .. "}"
62 end
63
64 if (#stack > 0) then
65 node = stack[#stack]
66 stack[#stack] = nil
67 depth = cache[node] == nil and depth + 1 or depth - 1
68 else
69 break
70 end
71 end
72
73 -- This is necessary for working with HUGE tables otherwise we run out of memory using concat on huge strings
74 table.insert(output,output_str)
75 output_str = table.concat(output)
76
77 print(output_str)
78end
79
1function dump(o)
2 if type(o) == 'table' then
3 local s = '{ '
4 for k,v in pairs(o) do
5 if type(k) ~= 'number' then k = '"'..k..'"' end
6 s = s .. '['..k..'] = ' .. dump(v) .. ','
7 end
8 return s .. '} '
9 else
10 return tostring(o)
11 end
12end
1--You need to use this {} and put them in a varible
2local Table = {13,"1hihihi",
3-- u can even do tis
4{122,222}}