Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This program is written for computercraft
- -- Retrieves a table of all components, then displays then on the screen one at a time
- -- Press any key to go to the next peripheral
- -- Finds devices connected to the computer, wraps them
- local function getDevices(deviceType) -- This function was taken from https://github.com/sandalle/minecraft_bigreactor_control and has been modified by https://github.com/Sanwi
- local deviceName = nil
- local deviceIndex = 1
- local deviceList, deviceNames = {}, {} -- Empty array, which grows as we need
- local peripheralList = peripheral.getNames() -- Get table of connected peripherals
- for peripheralIndex = 1, #peripheralList do -- Log every device found
- if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == deviceType) then -- Log devices found which match deviceType and which device index we give them
- deviceNames[deviceIndex] = peripheralList[peripheralIndex]
- deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
- deviceIndex = deviceIndex + 1
- end
- end -- for peripheralIndex = 1, #peripheralList do
- return deviceList, deviceNames
- end
- -- Prints functions available for deviceType
- local function printPerFunctions(deviceType)
- local deviceList,deviceNames = getDevices(deviceType)
- for k,v in pairs(deviceList[1]) do -- For first wrapped machine table
- print(k) -- Print the name of the function
- end
- end
- local function printAdvancedMethods(deviceType)
- local deviceList, deviceNames = getDevices(deviceType)
- if deviceList[1].getAdvancedMethodsData then
- for k,v in pairs(deviceList[1].getAdvancedMethodsData()) do -- For each method returned for this device
- print("\nMethod Name: "..tostring(k)) -- String of method name
- if type(v) == "table" then
- for k2,v2 in pairs(v) do
- if k2 == "returnTypes" then
- if v2[1] then
- print("returns: "..tostring(v2[1]))
- end
- elseif k2 == "args" then
- print("args: ")
- for k3,v3 in pairs(v2) do -- For each arg
- for k4,v4 in pairs(v3) do
- print(tostring(k4).." : "..tostring(v4))
- end
- print("\n")
- end
- elseif k2 == "description" then
- print(tostring(v2))
- else
- print(tostring(v2))
- end
- end
- else
- print("k: "..k)
- print("v: "..v)
- end
- print("\nPress any key to continue")
- local event, key = os.pullEvent("key")
- end
- end
- end
- local function printPerTypes()
- local allPers = peripheral.getNames()
- local perTypeAnchor = ""
- for i=1, #allPers do
- if allPers[i] ~= perTypeAnchor then -- Iterate for each peripheral
- perTypeAnchor = allPers[i]
- local type = peripheral.getType(allPers[i]) -- Get peripheral type
- -- List all functions for this peripheral
- print("\nName: "..type)
- printPerFunctions(type)
- -- Wait for key input
- print("\nPress N for next device, or M for advanced methods data")
- local event, key = os.pullEvent("key")
- if key == 50 then
- printAdvancedMethods(type)
- end
- end
- end
- end
- local monitorList, monitorNames = getDevices("monitor")
- term.redirect(monitorList[1])
- term.clear()
- term.setCursorPos(1,1)
- printPerTypes()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement