support open os command line programs

This commit is contained in:
kepler155c@gmail.com
2019-04-07 10:09:47 -04:00
parent 737ac095de
commit 4f9bd8eb0f
9 changed files with 146 additions and 65 deletions

View File

@@ -17,53 +17,59 @@ end
function Peripheral.addDevice(deviceList, side)
local name = side
local ptype = Peripheral.getType(side)
pcall(function()
local ptype = Peripheral.getType(side)
local dev = Peripheral.wrap(side)
if not ptype then
return
end
if ptype == 'modem' then
if not Peripheral.call(name, 'isWireless') then
-- ptype = 'wireless_modem'
-- else
ptype = 'wired_modem'
if not ptype or not dev then
return
end
end
local sides = {
front = true,
back = true,
top = true,
bottom = true,
left = true,
right = true
}
if sides[name] then
local i = 1
local uniqueName = ptype
while deviceList[uniqueName] do
uniqueName = ptype .. '_' .. i
i = i + 1
if ptype == 'modem' then
if not Peripheral.call(name, 'isWireless') then
-- ptype = 'wireless_modem'
-- else
ptype = 'wired_modem'
if dev.getMetadata then
-- avoid open computer relays being registered
-- as 'wired_modem'
ptype = dev.getMetadata().name or 'wired_modem'
end
end
end
name = uniqueName
end
-- this can randomly fail
if not deviceList[name] then
pcall(function()
deviceList[name] = Peripheral.wrap(side)
end)
local sides = {
front = true,
back = true,
top = true,
bottom = true,
left = true,
right = true
}
if deviceList[name] then
Util.merge(deviceList[name], {
name = name,
type = ptype,
side = side,
})
if sides[name] then
local i = 1
local uniqueName = ptype
while deviceList[uniqueName] do
uniqueName = ptype .. '_' .. i
i = i + 1
end
name = uniqueName
end
end
-- this can randomly fail
if not deviceList[name] then
deviceList[name] = dev
if deviceList[name] then
Util.merge(deviceList[name], {
name = name,
type = ptype,
side = side,
})
end
end
end)
return deviceList[name]
end
@@ -117,4 +123,4 @@ function Peripheral.get(args)
end
end
return Peripheral
return Peripheral