You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

64 line
1.6 KiB

  1. //
  2. // Lol Engine — HTTP client sample
  3. //
  4. // Copyright © 2016—2020 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #if HAVE_CONFIG_H
  13. # include "config.h"
  14. #endif
  15. #include <lol/engine.h>
  16. class demo : public lol::entity
  17. {
  18. public:
  19. virtual bool init_game() override
  20. {
  21. // Choose URL that works with CORS (cross-origin resource sharing)
  22. client.get("https://api.github.com/");
  23. return true;
  24. }
  25. virtual void tick_game(float seconds) override
  26. {
  27. entity::tick_game(seconds);
  28. switch (client.get_status())
  29. {
  30. case lol::net::http::status::success:
  31. lol::msg::info("downloaded %d bytes: %s\n",
  32. (int)client.get_result().size(),
  33. client.get_result().c_str());
  34. client.reset();
  35. break;
  36. case lol::net::http::status::error:
  37. lol::msg::info("error downloading %s\n", client.get_url().c_str());
  38. client.reset();
  39. break;
  40. default:
  41. break;
  42. }
  43. }
  44. lol::net::http::client client;
  45. };
  46. int main(int argc, char **argv)
  47. {
  48. lol::sys::init(argc, argv);
  49. lol::Application app("Tutorial 17: HTTP", lol::ivec2(800, 600), 60.0f);
  50. auto p = new demo();
  51. app.Run();
  52. return 0;
  53. }