Advertisement
Guest User

getdocs

a guest
Nov 25th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. local args = {...}
  2.  
  3. --*nothing* default
  4. --simple
  5. --verbos
  6. --both (default and verbos)
  7.  
  8. periphType = peripheral.getType(args[1])
  9. periph = peripheral.wrap(args[1])
  10. tableish = periph.getAdvancedMethodsData()
  11. if args[2] == "simple" then
  12.     io.output(periphType.. "_simple_documentation.txt")
  13. elseif args[2] == "verbos" then
  14.     io.output(periphType.. "_verbos_documentation.txt")
  15. elseif args[2] == "both" then
  16.     io.output(periphType.. "_combined_documentation.txt")
  17. else
  18.     io.output(periphType.. "_documentation.txt")
  19. end
  20.  
  21. for k, v in pairs(tableish) do
  22.     io.write(k.."()")
  23.     i = 1
  24.     if args[2] == "simple" then
  25.         for l, b in pairs(v) do -- FOR 1 has 3 pairs
  26.                                 --| returnTypes
  27.                                 --| description
  28.                                 --| args
  29.             if i == 1 or i == 3 then
  30.                 for a, n in pairs(b) do  -- FOR 2 has varying amount of pairs
  31.                     if i == 3 then
  32.                         if args[2] == "verbos" or args[2] == "both" then
  33.                         else
  34.                             if n["optional"] then
  35.                                 io.write(n["type"].. " (".. n["name"].. ")")
  36.                             else
  37.                                 io.write(n["type"].. " [".. n["name"].. "]")
  38.                             end
  39.                             io.write(", ")
  40.                         end
  41.                     end
  42.                 end
  43.             end
  44.             i = i+1
  45.         end
  46.         io.write(")")
  47.         io.write("\n")
  48.     else
  49.         for l, b in pairs(v) do -- FOR 1 has 3 pairs
  50.                                 --| returnTypes
  51.                                 --| description
  52.                                 --| args
  53.             io.write("\n")
  54.             if i == 1 or i == 3 then
  55.                 io.write("  "..l..":")
  56.                 for a, n in pairs(b) do  -- FOR 2 has varying amount of pairs
  57.                     io.write("\n")
  58.                     if i == 3 then
  59.                         if args[2] == "verbos" or args[2] == "both" then
  60.                             --io.write("   ".. a.. ": ")
  61.                             for s, m in pairs(n) do -- FOR 3 has 6 pairs
  62.                                 -- name
  63.                                 -- optional
  64.                                 -- type
  65.                                 -- description
  66.                                 -- nullable
  67.                                 -- vararg
  68.                                 io.write("    ".. tostring(s).. ": ".. tostring(m))
  69.                                 io.write("\n")
  70.                             end
  71.                         else
  72.                             if n["optional"] then
  73.                                 io.write("    ".. n["type"].. " (".. n["name"].. ")")
  74.                             else
  75.                                 io.write("    ".. n["type"].. " [".. n["name"].. "]")
  76.                             end
  77.                         end
  78.                     else
  79.                         io.write("   ".. a.. ": ".. n)
  80.                     end
  81.                 end
  82.             else
  83.                 io.write("  "..l..": ".. b)
  84.             end
  85.             i = i+1
  86.             io.write("\n")
  87.         end
  88.         io.write("\n")
  89.     end
  90. end
  91. io.flush()
  92. io.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement