Advertisement
whitaleedee

write table to file

Sep 28th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. local p = peripheral.wrap("left")
  2. local tbl = p.getAvailableItems()
  3. local filename = "test"
  4.  
  5. local file = fs.open(filename, "w")
  6. local nLnCnt = 1
  7. function printTable(pTbl, nCnt)
  8. for k,v in pairs(pTbl) do
  9. if type(v) == "table" then
  10. file.writeLine(getSpacer(nCnt)..k)
  11. printTable(v, nCnt+1)
  12. else
  13. sv = tostring(v)
  14. file.writeLine(getSpacer(nCnt)..k.." - "..sv)
  15. nLnCnt = nLnCnt+1
  16. end
  17. if nLnCnt >= 15 or nCnt == 0 then
  18. nLnCnt = 1
  19. end
  20. end
  21. end
  22.  
  23. function getSpacer(nCnt)
  24. local spr = ""
  25. local max = tonumber(nCnt)
  26. for n = 1,max do
  27. spr = spr.." "
  28. end
  29.  
  30. return spr
  31. end
  32.  
  33. printTable(tbl,0)
  34. file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement