lua_Touch.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Touch.h"
  4. #include "Touch.h"
  5. namespace gameplay
  6. {
  7. void luaRegister_Touch()
  8. {
  9. const luaL_Reg lua_members[] =
  10. {
  11. {NULL, NULL}
  12. };
  13. const luaL_Reg lua_statics[] =
  14. {
  15. {"MAX_TOUCH_POINTS", lua_Touch_static_MAX_TOUCH_POINTS},
  16. {NULL, NULL}
  17. };
  18. std::vector<std::string> scopePath;
  19. gameplay::ScriptUtil::registerClass("Touch", lua_members, NULL, lua_Touch__gc, lua_statics, scopePath);
  20. }
  21. static Touch* getInstance(lua_State* state)
  22. {
  23. void* userdata = luaL_checkudata(state, 1, "Touch");
  24. luaL_argcheck(state, userdata != NULL, 1, "'Touch' expected.");
  25. return (Touch*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  26. }
  27. int lua_Touch__gc(lua_State* state)
  28. {
  29. // Get the number of parameters.
  30. int paramCount = lua_gettop(state);
  31. // Attempt to match the parameters to a valid binding.
  32. switch (paramCount)
  33. {
  34. case 1:
  35. {
  36. if ((lua_type(state, 1) == LUA_TUSERDATA))
  37. {
  38. void* userdata = luaL_checkudata(state, 1, "Touch");
  39. luaL_argcheck(state, userdata != NULL, 1, "'Touch' expected.");
  40. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  41. if (object->owns)
  42. {
  43. Touch* instance = (Touch*)object->instance;
  44. SAFE_DELETE(instance);
  45. }
  46. return 0;
  47. }
  48. lua_pushstring(state, "lua_Touch__gc - Failed to match the given parameters to a valid function signature.");
  49. lua_error(state);
  50. break;
  51. }
  52. default:
  53. {
  54. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  55. lua_error(state);
  56. break;
  57. }
  58. }
  59. return 0;
  60. }
  61. int lua_Touch_static_MAX_TOUCH_POINTS(lua_State* state)
  62. {
  63. // Validate the number of parameters.
  64. if (lua_gettop(state) > 0)
  65. {
  66. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  67. lua_error(state);
  68. }
  69. unsigned int result = Touch::MAX_TOUCH_POINTS;
  70. // Push the return value onto the stack.
  71. lua_pushunsigned(state, result);
  72. return 1;
  73. }
  74. }