Posted 30 July 2013 - 06:35 AM
I came to the forums to share this little tidbit. I figured it could be of some use, seeing as how the modem's remoteXYZ() API didn't include a way to wrap remote peripherals.
Insert this somewhere in your script and call md.wrapRemote("name"). Make sure to setup which side the modem is on!
Insert this somewhere in your script and call md.wrapRemote("name"). Make sure to setup which side the modem is on!
-- Wrap modem
-- Make sure to change the side
local md = peripheral.wrap("back")
assert(md)
-- Networked Peripheral Wrapper system
local net_mt = {}
local net_mtf = {}
function net_mtf:__call(...)
md.callRemote(self.pname, self.name, ...)
end
function net_mt:__index(k)
local func = {}
func.name = k
func.pname = self.name
setmetatable(func, net_mtf)
return func
end
md.wrapRemote = function(name)
assert(net_mt)
local wrapped = {}
wrapped.name = name
setmetatable(wrapped, net_mt)
return wrapped
end
-- USAGE: md.wrapRemote("perhipheral_N")