53 lines
1.6 KiB
Lua
53 lines
1.6 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
|
|
local hasInventoryList = false
|
|
for _, method in ipairs(methods) do
|
|
if method == "getBlockData" then hasBlockData = true end
|
|
if method == "list" then hasInventoryList = 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
|
|
if hasInventoryList then
|
|
local okSize, size = pcall(peripheral.call, name, "size")
|
|
local okList, items = pcall(peripheral.call, name, "list")
|
|
writeLine("Inventory size: " .. (okSize and tostring(size) or "ERROR"))
|
|
writeLine("Inventory list OK: " .. tostring(okList))
|
|
writeLine(okList and textutils.serialize(items) or tostring(items))
|
|
end
|
|
writeLine("")
|
|
end
|
|
|
|
output.close()
|
|
print("Fertig: " .. outputName)
|