Advertisement
Te-ki

MethodsLister

Mar 29th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. -- MethodsLister by Teki
  2. local advanced = false
  3. local docs = false
  4.  
  5. if not fs.exists("methods/") then
  6.     fs.makeDir("methods/")
  7. end
  8.  
  9. local methodsList = ""
  10. local filepath
  11.  
  12. function getMethodsBySide(side)
  13.     for i,v in ipairs(peripheral.getMethods(side)) do
  14.         methodsList = methodsList .. i .. ". " .. v .. "\n"
  15.         if v == "getAdvancedMethodsData" then advanced = true end
  16.         if v == "getDocs" then docs = true end
  17.     end
  18. end
  19.  
  20. function getAdvancedMethodsDataBySide(side)
  21.     local wrapped = peripheral.wrap(side)
  22.     local advancedMethods = wrapped.getAdvancedMethodsData()
  23.     methodsList = methodsList .. textutils.serialize(advancedMethods)
  24. end
  25.  
  26. function getDocsBySide(side)
  27.     local wrapped = peripheral.wrap(side)
  28.     local advancedMethods = wrapped.getDocs()
  29.     methodsList = methodsList .. textutils.serialize(advancedMethods)
  30. end
  31.  
  32. function Save(side)
  33.     filePath = "methods/" .. peripheral.getType(side)
  34.     savedFile = fs.open(filePath, "w")
  35.     savedFile.write(textutils.serialize(methodsList):gsub("\\", ""))
  36.     savedFile.flush()
  37.     savedFile.close()
  38.  
  39. end
  40.  
  41. local sides = peripheral.getNames()
  42.  
  43. for i=1,#sides do
  44.     advanced = false
  45.     docs = false
  46.     getMethodsBySide(sides[i])
  47.     if advanced then
  48.         getAdvancedMethodsDataBySide(sides[i])
  49.         advanced = false
  50.     end
  51.     if docs then
  52.         getDocsBySide(sides[i])
  53.         docs = false
  54.     end
  55.     Save(sides[i])
  56.     methodsList = ""
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement