Files
ATM10_CC_Codes/create_peripheral_debug.lua
T

44 lines
1.2 KiB
Lua

-- Writes all attached peripheral types, methods and Block Reader data to a file.
local outputName = "create_debug.txt"
local output = assert(fs.open(outputName, "w"))
local function writeLine(text)
text = tostring(text or "")
output.writeLine(text)
print(text)
end
local names = peripheral.getNames()
table.sort(names)
writeLine("CREATE PERIPHERAL DEBUG")
writeLine("Computer ID: " .. os.getComputerID())
writeLine("Peripherals: " .. #names)
writeLine("")
for _, name in ipairs(names) do
local types = { peripheral.getType(name) }
local methods = peripheral.getMethods(name) or {}
table.sort(methods)
writeLine(("[%s]"):format(name))
writeLine("Types: " .. table.concat(types, ", "))
writeLine("Methods: " .. table.concat(methods, ", "))
local hasBlockData = false
for _, method in ipairs(methods) do
if method == "getBlockData" then hasBlockData = true end
end
if hasBlockData then
local ok, data = pcall(peripheral.call, name, "getBlockData")
writeLine("getBlockData OK: " .. tostring(ok))
writeLine(ok and textutils.serialize(data) or tostring(data))
end
writeLine("")
end
output.close()
print("Fertig: " .. outputName)