phase out peripheral.lookup
This commit is contained in:
@@ -1,34 +1,7 @@
|
|||||||
local class = require('class')
|
local class = require('class')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local Map = require('map')
|
local Map = require('map')
|
||||||
local Socket = require('socket')
|
local Proxy = require('proxy')
|
||||||
|
|
||||||
local function hijackTurtle(remoteId)
|
|
||||||
local socket, msg = Socket.connect(remoteId, 188)
|
|
||||||
|
|
||||||
if not socket then
|
|
||||||
error(msg)
|
|
||||||
end
|
|
||||||
|
|
||||||
socket.co = coroutine.running()
|
|
||||||
|
|
||||||
socket:write('turtle')
|
|
||||||
local methods = socket:read() or error('Timed out')
|
|
||||||
|
|
||||||
local hijack = { }
|
|
||||||
for _,method in pairs(methods) do
|
|
||||||
hijack[method] = function(...)
|
|
||||||
socket:write({ method, ... })
|
|
||||||
local resp = socket:read()
|
|
||||||
if not resp then
|
|
||||||
error('timed out: ' .. method)
|
|
||||||
end
|
|
||||||
return table.unpack(resp)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return hijack, socket
|
|
||||||
end
|
|
||||||
|
|
||||||
local Swarm = class()
|
local Swarm = class()
|
||||||
function Swarm:init(args)
|
function Swarm:init(args)
|
||||||
@@ -63,7 +36,7 @@ function Swarm:run(fn)
|
|||||||
if not member.socket then
|
if not member.socket then
|
||||||
member.handler = Event.addRoutine(function()
|
member.handler = Event.addRoutine(function()
|
||||||
local s, m = pcall(function()
|
local s, m = pcall(function()
|
||||||
member.turtle, member.socket = hijackTurtle(id)
|
member.turtle, member.socket = Proxy.create(id, 'turtle')
|
||||||
|
|
||||||
fn(member)
|
fn(member)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -20,20 +20,20 @@ Use this turtle for machine crafting.
|
|||||||
--]]
|
--]]
|
||||||
|
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local Peripheral = require('peripheral')
|
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
|
local peripheral = _G.peripheral
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local STARTUP_FILE = 'usr/autorun/brewArray.lua'
|
local STARTUP_FILE = 'usr/autorun/brewArray.lua'
|
||||||
|
|
||||||
local function equip(side, item, rawName)
|
local function equip(side, item, rawName)
|
||||||
local equipped = Peripheral.lookup('side/' .. side)
|
local equipped = peripheral.getType(side)
|
||||||
|
|
||||||
if equipped and equipped.type == item then
|
if equipped == item then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -16,20 +16,20 @@ Use this turtle for machine crafting.
|
|||||||
--]]
|
--]]
|
||||||
|
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local Peripheral = require('peripheral')
|
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
|
local peripheral = _G.peripheral
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local STARTUP_FILE = 'usr/autorun/miloFurni.lua'
|
local STARTUP_FILE = 'usr/autorun/miloFurni.lua'
|
||||||
|
|
||||||
local function equip(side, item, rawName)
|
local function equip(side, item, rawName)
|
||||||
local equipped = Peripheral.lookup('side/' .. side)
|
local equipped = peripheral.getType(side)
|
||||||
|
|
||||||
if equipped and equipped.type == item then
|
if equipped == item then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
_G.requireInjector(_ENV)
|
|
||||||
|
|
||||||
local GPS = require('gps')
|
local GPS = require('gps')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
local Peripheral = require('peripheral')
|
|
||||||
local Point = require('point')
|
local Point = require('point')
|
||||||
|
local Proxy = require('proxy')
|
||||||
|
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
|
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
local remoteId = args[1] or error('mobFollow <remote id>')
|
local remoteId = args[1] or error('mobFollow <remote id>')
|
||||||
local ni = Peripheral.lookup(remoteId .. '://name/neuralInterface')
|
local ni = Proxy.create(remoteId, 'device/neuralInterface')
|
||||||
|
|
||||||
if not ni then
|
if not ni then
|
||||||
error('failed to connect')
|
error('failed to connect')
|
||||||
|
|||||||
Reference in New Issue
Block a user