local ae2=peripheral.wrap("top")
local ecran=peripheral.wrap("left")

--local liste=peripheral.getMethods("top")
--local i=1
ecran.clear()
ecran.setTextScale(0.5)
ecran.setCursorPos(1,1)
--while liste[i] do
--	ecran.write(liste[i])
--	i=i+1
--	ecran.setCursorPos(1,i)
--end
function print_r ( t ) 
    local print_r_cache={}
    local function sub_print_r(t,indent)
        if (print_r_cache[tostring(t)]) then
            print(indent.."*"..tostring(t))
        else
            print_r_cache[tostring(t)]=true
            if (type(t)=="table") then
                for pos,val in pairs(t) do
                    if (type(val)=="table") then
                        print(indent.."["..pos.."] => "..tostring(t).." {")
                        sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
                        print(indent..string.rep(" ",string.len(pos)+6).."}")
                    else
                        print(indent.."["..pos.."] => "..tostring(val))
                    end
                end
            else
                print(indent..tostring(t))
            end
        end
    end
    sub_print_r(t,"  ")
end


function demande(item,qte,slot)
	fc=ae2.getItemDetail(item)
	info=fc.all()
	-- nom avec accent !!
	-- info.name
	if (info.qty<qte) then
		print("Craft "..info.qty..'/'..qte)
		liste=ae2.requestCrafting(item,qte-info.qty)
		while info.qty<qte do
			fc=ae2.getItemDetail(item)
			info=fc.all()
			print("Craft "..info.qty..'/'..qte)
			os.sleep(1)
		end
	end
	liste=ae2.exportItem(item,"down",qte,slot)
end

ressource={id="minecraft:stone"}
--ressource={id="minecraft:reeds"}
demande(ressource,10,2)
