wrap_Android.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Copyright (c) 2006-2014 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #include "wrap_Android.h"
  21. #include "wrap_DisplayMetrics.h"
  22. namespace love
  23. {
  24. namespace android
  25. {
  26. static Android *instance = nullptr;
  27. int w_getDisplayMetrics(lua_State *L)
  28. {
  29. DisplayMetrics *metrics = 0;
  30. EXCEPT_GUARD(metrics = instance->getDisplayMetrics();)
  31. luax_pushtype(L, "DisplayMetrics", ANDROID_DISPLAY_METRICS_T, metrics);
  32. return 1;
  33. }
  34. // List of functions to wrap.
  35. static const luaL_Reg functions[] =
  36. {
  37. { "getDisplayMetrics", w_getDisplayMetrics },
  38. { 0, 0 }
  39. };
  40. // Types for this module.
  41. static const lua_CFunction types[] =
  42. {
  43. luaopen_displaymetrics,
  44. 0
  45. };
  46. extern "C" int luaopen_love_android(lua_State *L)
  47. {
  48. if (instance == 0)
  49. {
  50. EXCEPT_GUARD(instance = new Android();)
  51. }
  52. else
  53. instance->retain();
  54. WrappedModule w;
  55. w.module = instance;
  56. w.name = "android";
  57. w.flags = MODULE_T;
  58. w.functions = functions;
  59. w.types = types;
  60. int n = luax_register_module(L, w);
  61. return n;
  62. }
  63. } // android
  64. } // love