lua_Gesture.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Gesture.h"
  4. #include "Gesture.h"
  5. namespace gameplay
  6. {
  7. void luaRegister_Gesture()
  8. {
  9. const luaL_Reg lua_members[] =
  10. {
  11. {NULL, NULL}
  12. };
  13. const luaL_Reg lua_statics[] =
  14. {
  15. {"SWIPE_DIRECTION_DOWN", lua_Gesture_static_SWIPE_DIRECTION_DOWN},
  16. {"SWIPE_DIRECTION_LEFT", lua_Gesture_static_SWIPE_DIRECTION_LEFT},
  17. {"SWIPE_DIRECTION_RIGHT", lua_Gesture_static_SWIPE_DIRECTION_RIGHT},
  18. {"SWIPE_DIRECTION_UP", lua_Gesture_static_SWIPE_DIRECTION_UP},
  19. {NULL, NULL}
  20. };
  21. std::vector<std::string> scopePath;
  22. ScriptUtil::registerClass("Gesture", lua_members, NULL, lua_Gesture__gc, lua_statics, scopePath);
  23. }
  24. static Gesture* getInstance(lua_State* state)
  25. {
  26. void* userdata = luaL_checkudata(state, 1, "Gesture");
  27. luaL_argcheck(state, userdata != NULL, 1, "'Gesture' expected.");
  28. return (Gesture*)((ScriptUtil::LuaObject*)userdata)->instance;
  29. }
  30. int lua_Gesture__gc(lua_State* state)
  31. {
  32. // Get the number of parameters.
  33. int paramCount = lua_gettop(state);
  34. // Attempt to match the parameters to a valid binding.
  35. switch (paramCount)
  36. {
  37. case 1:
  38. {
  39. if ((lua_type(state, 1) == LUA_TUSERDATA))
  40. {
  41. void* userdata = luaL_checkudata(state, 1, "Gesture");
  42. luaL_argcheck(state, userdata != NULL, 1, "'Gesture' expected.");
  43. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  44. if (object->owns)
  45. {
  46. Gesture* instance = (Gesture*)object->instance;
  47. SAFE_DELETE(instance);
  48. }
  49. return 0;
  50. }
  51. else
  52. {
  53. lua_pushstring(state, "lua_Gesture__gc - Failed to match the given parameters to a valid function signature.");
  54. lua_error(state);
  55. }
  56. break;
  57. }
  58. default:
  59. {
  60. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  61. lua_error(state);
  62. break;
  63. }
  64. }
  65. return 0;
  66. }
  67. int lua_Gesture_static_SWIPE_DIRECTION_DOWN(lua_State* state)
  68. {
  69. // Validate the number of parameters.
  70. if (lua_gettop(state) > 0)
  71. {
  72. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  73. lua_error(state);
  74. }
  75. int result = Gesture::SWIPE_DIRECTION_DOWN;
  76. // Push the return value onto the stack.
  77. lua_pushinteger(state, result);
  78. return 1;
  79. }
  80. int lua_Gesture_static_SWIPE_DIRECTION_LEFT(lua_State* state)
  81. {
  82. // Validate the number of parameters.
  83. if (lua_gettop(state) > 0)
  84. {
  85. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  86. lua_error(state);
  87. }
  88. int result = Gesture::SWIPE_DIRECTION_LEFT;
  89. // Push the return value onto the stack.
  90. lua_pushinteger(state, result);
  91. return 1;
  92. }
  93. int lua_Gesture_static_SWIPE_DIRECTION_RIGHT(lua_State* state)
  94. {
  95. // Validate the number of parameters.
  96. if (lua_gettop(state) > 0)
  97. {
  98. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  99. lua_error(state);
  100. }
  101. int result = Gesture::SWIPE_DIRECTION_RIGHT;
  102. // Push the return value onto the stack.
  103. lua_pushinteger(state, result);
  104. return 1;
  105. }
  106. int lua_Gesture_static_SWIPE_DIRECTION_UP(lua_State* state)
  107. {
  108. // Validate the number of parameters.
  109. if (lua_gettop(state) > 0)
  110. {
  111. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  112. lua_error(state);
  113. }
  114. int result = Gesture::SWIPE_DIRECTION_UP;
  115. // Push the return value onto the stack.
  116. lua_pushinteger(state, result);
  117. return 1;
  118. }
  119. }