Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local api = {}
- function api.findPeripherals(filter)
- local peripheralObjects = {}
- for _, name in pairs(peripheral.getNames()) do
- local type = name
- local i = name:find("_")
- if i then
- type = name:sub(1, i - 1)
- end
- if filter == nil or string.lower(type) == string.lower(filter) then
- table.insert(peripheralObjects,
- instantiateClass("Peripheral", name)
- )
- end
- end
- return toTurtiArray(peripheralObjects)
- end
- function api.wrapPeripheral(side)
- return instantiateClass("Peripheral", side)
- end
- local PERIPHERAL_CLASS_TYPE = {
- key = "Peripheral",
- to_string = function(p, context)
- return "Peripheral(" .. context.name .. ")"
- end,
- methods = {
- call = function(p, context, ...)
- return peripheral.call(context.name, ...)
- end,
- getName = function(p, context)
- return peripheral.getName(peripheral.wrap(context.name))
- end
- },
- getters = {
- name = function(p, context)
- return context.name
- end
- },
- init = function(p, name)
- return { name = name }
- end
- }
- return {
- name = "betterPeripherals",
- api = api,
- classes = {
- PERIPHERAL_CLASS_TYPE
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement