This repository has been archived by the owner on Jun 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
raw_action.lua
75 lines (67 loc) · 1.99 KB
/
raw_action.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
premake.raw = { }
local raw = premake.raw
local gvisited = { }
function raw.solution(sln)
if not gvisited[sln.global] then
gvisited[sln.global] = true
raw.printTable({ global = sln.global })
end
end
function raw.printTable(t, i)
i = i or 0
placement = raw._createPlacement(t)
raw._printTableRecursive(t, i, placement)
end
function raw._printTableRecursive(t, i, placement)
elements = { }
for k, v in pairs(t) do
table.insert(elements, { key = k, value = v })
end
table.sort(elements, function(a, b)
local n1 = type(a.key) == "number"
local n2 = type(b.key) == "number"
if n1 ~= n2 then
return n1
end
local k1 = n1 and a.key or raw._encode(a.key)
local k2 = n2 and b.key or raw._encode(b.key)
return k1 < k2
end)
for _, elem in ipairs(elements) do
p = placement[elem.value]
if p and elem.key == p.key and t == p.parent then
_p(i, "%s", raw._encode(elem.key) .. ': ' .. raw._encode(elem.value) .. ' {')
raw._printTableRecursive(elem.value, i + 1, placement)
_p(i, '} # ' .. raw._encode(elem.key))
else
_p(i, "%s", raw._encode(elem.key) .. ': ' .. raw._encode(elem.value))
end
end
end
function raw._createPlacement(tbl)
placement = { }
placementList = { tbl }
while #placementList ~= 0 do
parentList = { }
for _, parent in ipairs(placementList) do
for k, v in pairs(parent) do
if type(v) == "table" and not placement[v] then
table.insert(parentList, v)
placement[v] = {
parent = parent,
key = k
}
end
end
end
placementList = parentList
end
return placement
end
function raw._encode(v)
if type(v) == "string" then
return '"' .. v .. '"'
else
return tostring(v)
end
end