phase out peripheral.lookup

This commit is contained in:
kepler155c@gmail.com
2019-03-08 16:26:18 -05:00
parent 9392fe47f8
commit 3192dc52d7
4 changed files with 11 additions and 40 deletions

View File

@@ -1,34 +1,7 @@
local class = require('class')
local Event = require('event')
local Map = require('map')
local Socket = require('socket')
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 Proxy = require('proxy')
local Swarm = class()
function Swarm:init(args)
@@ -63,7 +36,7 @@ function Swarm:run(fn)
if not member.socket then
member.handler = Event.addRoutine(function()
local s, m = pcall(function()
member.turtle, member.socket = hijackTurtle(id)
member.turtle, member.socket = Proxy.create(id, 'turtle')
fn(member)
end)

View File

@@ -20,20 +20,20 @@ Use this turtle for machine crafting.
--]]
local Event = require('event')
local Peripheral = require('peripheral')
local Util = require('util')
local device = _G.device
local fs = _G.fs
local os = _G.os
local peripheral = _G.peripheral
local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/brewArray.lua'
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
end

View File

@@ -16,20 +16,20 @@ Use this turtle for machine crafting.
--]]
local Event = require('event')
local Peripheral = require('peripheral')
local Util = require('util')
local device = _G.device
local fs = _G.fs
local os = _G.os
local peripheral = _G.peripheral
local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/miloFurni.lua'
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
end

View File

@@ -1,15 +1,13 @@
_G.requireInjector(_ENV)
local GPS = require('gps')
local Util = require('util')
local Peripheral = require('peripheral')
local Point = require('point')
local Proxy = require('proxy')
local os = _G.os
local args = { ... }
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
error('failed to connect')
@@ -46,4 +44,4 @@ while true do
end
os.sleep(.5)
end
end