thread.lua 573 B

1234567891011121314151617181920212223
  1. local function setChannel(channel, value)
  2. channel:clear()
  3. channel:push(value)
  4. end
  5. local socket = require("socket")
  6. local unitID = ...
  7. local client = socket.tcp()
  8. client:connect("localhost",1337)
  9. client:send("flosama\n{\"PositionStream\":{\"target\":{\"Selected\":["..unitID.."]}}}\n")
  10. repeat
  11. local received = client:receive('*l')
  12. local channel = love.thread.getChannel('info')
  13. local ending = love.thread.getChannel('kill'):pop();
  14. print(ending);
  15. channel:performAtomic(setChannel, received)
  16. until (received == nil or ending ~= nil)