webthread.lua 613 B

123456789101112131415161718192021222324
  1. require("love.system")
  2. local args = {}
  3. require("love.thread")
  4. local to_channel = select(1,...)
  5. local from_channel = select(2,...)
  6. local request = require("Engine.luajit-request")
  7. local json = require("Engine.JSON")
  8. while true do
  9. local req = to_channel:demand()
  10. if type(req) == "table" then
  11. local url = req[1]
  12. local args = json:decode(req[2])
  13. local out, errorcode, errorstr, errline = request.send(url,args)
  14. from_channel:push(json:encode({ url, out, errorcode, errorstr, errline }))
  15. elseif type(req) == "string" then
  16. if req == "shutdown" then
  17. break --Job done.
  18. end
  19. end
  20. end