Advertisement
massacring

MassaPeripheralLib

May 26th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. local function tlength(T)
  2.     local count = 0
  3.     for _ in pairs(T) do count = count + 1 end
  4.     return count
  5. end
  6.  
  7. local function getOnePeripheral(type, filter)
  8.     local peripherals = { peripheral.find(type, filter) }
  9.     if not (tlength(peripherals) == 1) then error("You need exactly one "..type.." attached.", 0) end
  10.     for _, peripheral in pairs(peripherals) do
  11.         return peripheral
  12.     end
  13. end
  14.  
  15. local function getPeripheralTypes()
  16.     local peripherals = {}
  17.     for key, value in pairs(peripheral.getNames()) do
  18.         local _peripheral = peripheral.getType(value)
  19.         table.insert(peripherals, _peripheral)
  20.     end
  21.     return peripherals
  22. end
  23.  
  24. return { getOnePeripheral = getOnePeripheral, getPeripheralTypes = getPeripheralTypes }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement