lua_Gesture.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. gameplay::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*)((gameplay::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. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  44. if (object->owns)
  45. {
  46. Gesture* instance = (Gesture*)object->instance;
  47. SAFE_DELETE(instance);
  48. }
  49. return 0;
  50. }
  51. lua_pushstring(state, "lua_Gesture__gc - Failed to match the given parameters to a valid function signature.");
  52. lua_error(state);
  53. break;
  54. }
  55. default:
  56. {
  57. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  58. lua_error(state);
  59. break;
  60. }
  61. }
  62. return 0;
  63. }
  64. int lua_Gesture_static_SWIPE_DIRECTION_DOWN(lua_State* state)
  65. {
  66. // Validate the number of parameters.
  67. if (lua_gettop(state) > 0)
  68. {
  69. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  70. lua_error(state);
  71. }
  72. int result = Gesture::SWIPE_DIRECTION_DOWN;
  73. // Push the return value onto the stack.
  74. lua_pushinteger(state, result);
  75. return 1;
  76. }
  77. int lua_Gesture_static_SWIPE_DIRECTION_LEFT(lua_State* state)
  78. {
  79. // Validate the number of parameters.
  80. if (lua_gettop(state) > 0)
  81. {
  82. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  83. lua_error(state);
  84. }
  85. int result = Gesture::SWIPE_DIRECTION_LEFT;
  86. // Push the return value onto the stack.
  87. lua_pushinteger(state, result);
  88. return 1;
  89. }
  90. int lua_Gesture_static_SWIPE_DIRECTION_RIGHT(lua_State* state)
  91. {
  92. // Validate the number of parameters.
  93. if (lua_gettop(state) > 0)
  94. {
  95. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  96. lua_error(state);
  97. }
  98. int result = Gesture::SWIPE_DIRECTION_RIGHT;
  99. // Push the return value onto the stack.
  100. lua_pushinteger(state, result);
  101. return 1;
  102. }
  103. int lua_Gesture_static_SWIPE_DIRECTION_UP(lua_State* state)
  104. {
  105. // Validate the number of parameters.
  106. if (lua_gettop(state) > 0)
  107. {
  108. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  109. lua_error(state);
  110. }
  111. int result = Gesture::SWIPE_DIRECTION_UP;
  112. // Push the return value onto the stack.
  113. lua_pushinteger(state, result);
  114. return 1;
  115. }
  116. }