Created
February 8, 2014 18:20
-
-
Save boq/8887832 to your computer and use it in GitHub Desktop.
openp/docs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Made by SinZ and boq | |
--]] | |
local args = {...} | |
if #args == 0 then | |
print("usage: docs <side> (function)") | |
return | |
end | |
local side = args[1] | |
local p = peripheral.wrap(side) | |
if not p then | |
print("No peripheral on '" .. side .. "'") | |
return | |
end | |
if not p.getAdvancedMethodsData then | |
print("Peripheral '" .. peripheral.getType(side) .. "' is not OpenPeripheral(TM)") | |
return | |
end | |
local info = p.getAdvancedMethodsData() | |
function argName(arg) | |
if arg.vararg then | |
return arg.name.."..." | |
elseif arg.optional then | |
return arg.name.."?" | |
else | |
return arg.name | |
end | |
end | |
if #args == 1 then | |
for name,data in pairs(info) do | |
args = {} | |
for _,arg in pairs(data.args) do | |
table.insert(args, argName(arg)) | |
end | |
print(name.."("..table.concat(args,",")..")") | |
end | |
else --must be 2 or more | |
for name,data in pairs(info) do | |
if args[2]:lower() == name:lower() then | |
print(name..": "..data.description) | |
print("returns: "..string.lower(table.concat(data.returnTypes,','))) | |
if #data.args > 0 then | |
print("args: ") | |
for _,arg in ipairs(data.args) do | |
print(" - ("..arg.type:lower()..")"..argName(arg)..": "..arg.description) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment