raw_action.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. local p = premake
  2. p.raw = { }
  3. local raw = p.raw
  4. local gvisited = { }
  5. function raw.workspace(wks)
  6. if not gvisited[wks.global] then
  7. gvisited[wks.global] = true
  8. raw.printTable({ global = wks.global })
  9. end
  10. end
  11. function raw.printTable(t, i)
  12. i = i or 0
  13. placement = raw._createPlacement(t)
  14. raw._printTableRecursive(t, i, placement)
  15. end
  16. function raw._printTableRecursive(t, i, placement)
  17. elements = { }
  18. for k, v in pairs(t) do
  19. table.insert(elements, { key = k, value = v })
  20. end
  21. table.sort(elements, function(a, b)
  22. local n1 = type(a.key) == "number"
  23. local n2 = type(b.key) == "number"
  24. if n1 ~= n2 then
  25. return n1
  26. end
  27. local k1 = n1 and a.key or raw._encode(a.key)
  28. local k2 = n2 and b.key or raw._encode(b.key)
  29. return k1 < k2
  30. end)
  31. for _, elem in ipairs(elements) do
  32. p = placement[elem.value]
  33. if p and elem.key == p.key and t == p.parent then
  34. _p(i, "%s", raw._encode(elem.key) .. ': ' .. raw._encode(elem.value) .. ' {')
  35. raw._printTableRecursive(elem.value, i + 1, placement)
  36. _p(i, '} # ' .. raw._encode(elem.key))
  37. else
  38. _p(i, "%s", raw._encode(elem.key) .. ': ' .. raw._encode(elem.value))
  39. end
  40. end
  41. end
  42. function raw._createPlacement(tbl)
  43. placement = { }
  44. placementList = { tbl }
  45. while #placementList ~= 0 do
  46. parentList = { }
  47. for _, parent in ipairs(placementList) do
  48. for k, v in pairs(parent) do
  49. if type(v) == "table" and not placement[v] then
  50. table.insert(parentList, v)
  51. placement[v] = {
  52. parent = parent,
  53. key = k
  54. }
  55. end
  56. end
  57. end
  58. placementList = parentList
  59. end
  60. return placement
  61. end
  62. function raw._encode(v)
  63. if type(v) == "string" then
  64. return '"' .. v .. '"'
  65. else
  66. return tostring(v)
  67. end
  68. end