View difference between Paste ID: 1P67gv7p and R05Sgk9K
SHOW: | | - or go back to the newest paste.
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
  outFile = fs.open(peripheral.getType(side), "w")
37
  for name,data in pairs(info) do
38
    args = {}
39
    for _,arg in pairs(data.args) do
40
      table.insert(args, argName(arg))
41
    end
42
    outFile.write(name.."("..table.concat(args,",")..")")
43
    print(name.."("..table.concat(args,",")..")")
44
  end
45
  outFile.close()
46
else --must be 2 or more
47
  outFile = fs.open(peripheral.getType(side)..name,"w")
48
  for name,data in pairs(info) do
49
    if args[2]:lower() == name:lower() then
50
      print(name..": "..data.description)
51
      print("source: " .. data.source) 
52
      print("returns: "..string.lower(table.concat(data.returnTypes,',')))
53
      outFile.write(name..": "..data.description)
54
      outFile.write("source: " .. data.source)
55
      outFile.write("returns: "..string.lower(table.concat(data.returnTypes,',')))
56
      if #data.args > 0 then
57
        print("args: ")
58
        outFile.write("args: ")
59
        for _,arg in ipairs(data.args) do
60
          print(" - ("..arg.type:lower()..")"..argName(arg)..": "..arg.description)   
61
          outFile.write(" - ("..arg.type:lower()..")"..argName(arg)..": "..arg.description)   
62
        end
63
      end
64
    end
65
  end
66
  outFile.close()
67
end