This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Qix's profile picture

Wrapper Snippet For Remote Peripherals

Started by Qix, 30 July 2013 - 04:35 AM
Qix #1
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!


-- 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")
Dlcruz129 #2
Posted 31 July 2013 - 01:16 AM
Awesome!
GopherAtl #3
Posted 31 July 2013 - 02:24 AM
Ehrum. Dunno how to break this to you, but… peripheral.wrap works fine with remote peripheral names.
jesusthekiller #4
Posted 31 July 2013 - 04:32 AM
Gopher is right…
Qix #5
Posted 31 July 2013 - 06:40 AM
Ehrum. Dunno how to break this to you, but… peripheral.wrap works fine with remote peripheral names.

Wat, since when? I couldn't get it to work. :|

/wastedthread
jay5476 #6
Posted 11 August 2013 - 08:02 AM
also this is more a program that does, not a tutorial on how to