CMastar

Open Peripheral Explorer

Feb 10th, 2014
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. function APILoader(apiName, apiPastebin) -- Used across several programs - but we can't use it from an API, because then how would we load it?
  2.         os.unloadAPI(apiName)
  3.         if fs.exists(apiName)
  4.         then
  5.                 os.loadAPI(apiName)
  6.         else
  7.                 shell.run("pastebin","get",apiPastebin,apiName)
  8.                 os.loadAPI(apiName)
  9.         end
  10. end
  11.  
  12. APILoader("commonFunctions","x5Ve1KSK")
  13.  
  14. function main()
  15.     print("Welcome to the Open Peripherals Method Explorer")
  16.     print("Version: RC1")
  17.     print("Developed by CMaster")
  18.     print("Distributed under the CC-BY-SA v4.0 license")
  19.     print("Bring bug reports to the Open Peripheral Explorer thread on the ComputerCraft Forums")
  20.     print("Press enter to begin")
  21.     read()
  22.     continue = true
  23.     while continue do
  24.         periphToView = peripheral.wrap(commonFunctions.selectPeripheral())
  25.         term.clear()
  26.         if periphToView == nil
  27.         then
  28.             print()
  29.             print("Not an actual peripheral. Please Reselect.")
  30.             print("Enter to continue...")
  31.             read()
  32.         else
  33.             if periphToView["getAdvancedMethodsData"] == nil
  34.             then
  35.                 print()
  36.                 print("Not an OpenPeripherals Peripheral")
  37.                 print("Enter to continue...")
  38.                 read()
  39.             else
  40.                 pickMethod(periphToView)
  41.             end
  42.         end
  43.     end
  44.  
  45. end
  46.  
  47. function toggle()
  48.     cont = false
  49. end
  50.  
  51. function pickMethod(periph)
  52.     methods = periph.getAdvancedMethodsData()
  53.     methodList = {}
  54.     for k, v in pairs(methods) do
  55.         table.insert(methodList,{["text"] = k, ["func"] = displayMethod, ["params"] = {v}})
  56.     end
  57.     cont = true
  58.     table.insert(methodList,{["text"] = "Back to Peripheral Select", ["func"] = toggle })
  59.     while cont do
  60.         commonFunctions.menu(methodList,"Select method to view")
  61.     end
  62. end
  63.  
  64. function displayMethod(methodList)
  65.     term.clear()
  66.     term.setCursorPos(1,1)
  67.     print("Method Overview for " .. methodList.name)
  68.     print("Description: " .. methodList.description)
  69.     rType = ""
  70.     for k, v in pairs(methodList.returnTypes) do
  71.         rType = rType .. v .. ", "
  72.     end
  73.     print("Returns as: " .. rType )
  74.     print("Arguments:")
  75.     for k,v in pairs(methodList.args) do
  76.         if v.optional == "true" then
  77.             opt = " (optional) "
  78.         else
  79.             opt = " "
  80.         end
  81.         print(v.type .. " " .. v.name .. opt .. ": " .. v.description)
  82.     end
  83.     print("Enter to return")
  84.     read()
  85. end
  86.  
  87. print(main())
Advertisement
Add Comment
Please, Sign In to add comment