
-- magic() - Calls a method on an attached device
-- Params: methodName[, args1[, argsN, ...]]
magic = setmetatable( {}, { __index = function( table, func )
  for idx, side in ipairs({ "left", "right", "top", "bottom", "back", "front" }) do
    if peripheral.isPresent( side ) then
      for idx2, method in ipairs( peripheral.getMethods( side ) ) do
        if method == func then
          return function( ... )
            peripheral.call( side, method, ... )
          end
        end
      end
    end
  end
  return function( ... )
    error("Error.")
  end
end } )

-- find() - find a device of this type and return a wrapper to it
-- Params: deviceType
function find(type) 
	for idx, side in ipairs({"top", "left", "right", "bottom", "front", "back"}) do
		if(peripheral.getType(side) == type) then
			return peripheral.wrap(side)
		end
	end
	return nil
end

-- getVersion() - returns a string that describes this version of the API
function getVersion()
	return "0.1a"
end
