PlowmanPlow

ComputerCraft - Method Documentation

Apr 29th, 2017
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.   Made by SinZ and boq
  3. --]]
  4. local args = {...}
  5. if #args == 0 then
  6.   print("usage: docs <side> (function)")
  7.   return
  8. end
  9.  
  10. local side = args[1]
  11. local p = peripheral.wrap(side)
  12.  
  13. if not p then
  14.   print("No peripheral on '" .. side .. "'")
  15.   return
  16. end
  17.  
  18. if not p.getAdvancedMethodsData then
  19.  print("Peripheral '" .. peripheral.getType(side) .. "' is not OpenPeripheral(TM)")
  20.  return
  21. end
  22.  
  23. local info = p.getAdvancedMethodsData()
  24.  
  25. function argName(arg)
  26.   if arg.vararg then
  27.     return arg.name.."..."
  28.   elseif arg.optional then
  29.     return arg.name.."?"
  30.   else
  31.     return arg.name
  32.   end
  33. end
  34.  
  35. if #args == 1 then
  36.   for name,data in pairs(info) do
  37.     args = {}
  38.     for _,arg in pairs(data.args) do
  39.       table.insert(args, argName(arg))
  40.     end
  41.     print(name.."("..table.concat(args,",")..")")
  42.   end
  43. else --must be 2 or more
  44.   for name,data in pairs(info) do
  45.     if args[2]:lower() == name:lower() then
  46.       print(name..": "..data.description)
  47.       print("source: " .. data.source)
  48.       print("returns: "..string.lower(data.returnTypes))
  49.       if #data.args > 0 then
  50.         print("args: ")
  51.         for _,arg in ipairs(data.args) do
  52.           print(" - ("..arg.type:lower() .. ")"..argName(arg)..": "..arg.description)
  53.         end
  54.       end
  55.     end
  56.   end
  57. end
RAW Paste Data