Advertisement
melzneni

CC_Std

Oct 23rd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1.  
  2. function printTable(tbl)
  3. print("{")
  4. printTableIndex(tbl, "\t", {})
  5. print("}")
  6. end
  7.  
  8. function printTableIndex(tbl, before, alreadyUsed)
  9. for i, v in pairs(tbl) do
  10. if type(v) == "table" then
  11. if tableContainsValue(alreadyUsed, v) then
  12. print(before .. i .. ":", "alreadyUsed");
  13. else
  14. print(before .. i .. ": {");
  15. table.insert(alreadyUsed, v)
  16. printTableIndex(v, before .. "\t", alreadyUsed)
  17. print(before .. "}")
  18. end
  19. else
  20. print(before .. i .. ":", v);
  21. end
  22. end
  23. end
  24.  
  25. function tableContainsValue(table, value)
  26. for i, v in pairs(table) do
  27. if v == value then return true end
  28. end
  29. return false
  30. end
  31.  
  32.  
  33. return {
  34. printTable=printTable
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement