gravitowl

[OnlineTurtle] Turtle Script

Jan 15th, 2021 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. json = require "json"
  2. local ws, err = http.websocket("ws://localhost:8080")
  3.  
  4. if err then
  5. print(err)
  6.  
  7. elseif ws then
  8. print("> CONNECTED")
  9.  
  10. while true do
  11. local message = ws.receive()
  12. print(message)
  13. local obj = json.decode(message)
  14. if obj.type == "eval" then
  15. local func = load(obj['function'])
  16. local result = func()
  17. ws.send(json.encode(result))
  18. print("> EVAL "..tostring(result))
  19.  
  20. end
  21. end
  22. ws.close()
  23. end
Add Comment
Please, Sign In to add comment