Advertisement
Bunny83

modem.wrap()

Apr 6th, 2013
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. -- bios.lua
  2. -- Bunny83: Added wrap function for wired modems
  3. peripheral.wrap = function( _sSide )
  4.    if peripheral.isPresent( _sSide ) then
  5.       local tMethods = peripheral.getMethods( _sSide )
  6.       local tResult = {}
  7.       for n,sMethod in ipairs( tMethods ) do
  8.          tResult[sMethod] = function( ... )
  9.             return peripheral.call( _sSide, sMethod, ... )
  10.          end
  11.       end
  12.       if peripheral.getType(_sSide) == "modem" and not tResult.isWireless() then
  13.          tResult.wrap = function( _sName )
  14.             if tResult.isPresentRemote( _sName ) then
  15.                local tMethods2 = tResult.getMethodsRemote( _sName )
  16.                local tResult2 = {}
  17.                for n,sMethod in ipairs( tMethods2 ) do
  18.                   tResult2[sMethod] = function( ... )
  19.                      return tResult.callRemote( _sName, sMethod, ... )
  20.                   end
  21.                end
  22.                return tResult2
  23.             end
  24.             return nil
  25.          end
  26.       end
  27.       return tResult
  28.    end
  29.    return nil
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement