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.
 
 
 

65 lines
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. #include <lol/msg>
  17. class demo : public lol::entity
  18. {
  19. public:
  20. virtual bool init_game() override
  21. {
  22. // Choose URL that works with CORS (cross-origin resource sharing)
  23. client.get("https://api.github.com/");
  24. return true;
  25. }
  26. virtual void tick_game(float seconds) override
  27. {
  28. entity::tick_game(seconds);
  29. switch (client.get_status())
  30. {
  31. case lol::net::http::status::success:
  32. lol::msg::info("downloaded %d bytes: %s\n",
  33. (int)client.get_result().size(),
  34. client.get_result().c_str());
  35. client.reset();
  36. break;
  37. case lol::net::http::status::error:
  38. lol::msg::info("error downloading %s\n", client.get_url().c_str());
  39. client.reset();
  40. break;
  41. default:
  42. break;
  43. }
  44. }
  45. lol::net::http::client client;
  46. };
  47. int main(int argc, char **argv)
  48. {
  49. lol::sys::init(argc, argv);
  50. lol::Application app("Tutorial 17: HTTP", lol::ivec2(800, 600), 60.0f);
  51. auto p = new demo();
  52. app.Run();
  53. return 0;
  54. }