if not goroutine then
  os.loadAPI("apis/goroutine")
  goroutine.launch()  
  print("unexplained error launching goroutine!")
else
  print("goroutine initialized")
end

local loaded={["goroutine"]=true}

local function doLoad(api)
  if not loaded[api] then
    local file=fs.open("apis/"..api,"r")
    local line=file.readLine()
    file.close()
    if line:upper():match("^--DEPENDS .*") then
      for mode,targ in string.gmatch(line,"(%w%w%w):([%S]+)") do
        mode=mode:upper()
        if mode=="REQ" or mode=="USE" then
          if not loaded[targ] then
            if not doLoad(targ) then
              if mode=="REQ" then
                print("loading "..api.." failed, couldn't load required "..targ.."!")            
                return false
              end
            end
          end
        else
          print("unknown dependency mode '"..mode.."' in api "..api.."!")
        end
      end
    end
    write("loading api '"..api.."...")
    if os.loadAPI("apis/"..api) then
      print("success!")
      loaded[api]=true
    end
  end
  return loaded[api]
end

for _,api in pairs(fs.list("/apis/")) do
  doLoad(api)
end

--release this table
loaded=nil

--update path
shell.setPath(shell.path()..":/programs/")