wrap_Joint.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * Copyright (c) 2006-2009 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. // LOVE
  21. #include "wrap_Joint.h"
  22. #include <common/StringMap.h>
  23. namespace love
  24. {
  25. namespace physics
  26. {
  27. namespace box2d
  28. {
  29. Joint * luax_checkjoint(lua_State * L, int idx)
  30. {
  31. return luax_checktype<Joint>(L, idx, "Joint", PHYSICS_JOINT_T);
  32. }
  33. int w_Joint_getType(lua_State * L)
  34. {
  35. Joint * t = luax_checkjoint(L, 1);
  36. const char * type = "";
  37. Joint::getConstant(t->getType(), type);
  38. lua_pushstring(L, type);
  39. return 1;
  40. }
  41. int w_Joint_getAnchors(lua_State * L)
  42. {
  43. Joint * t = luax_checkjoint(L, 1);
  44. lua_remove(L, 1);
  45. return t->getAnchors(L);
  46. }
  47. int w_Joint_getReactionForce(lua_State * L)
  48. {
  49. Joint * t = luax_checkjoint(L, 1);
  50. lua_remove(L, 1);
  51. return t->getReactionForce(L);
  52. }
  53. int w_Joint_getReactionTorque(lua_State * L)
  54. {
  55. Joint * t = luax_checkjoint(L, 1);
  56. lua_pushnumber(L, t->getReactionTorque());
  57. return 1;
  58. }
  59. int w_Joint_setCollideConnected(lua_State * L)
  60. {
  61. Joint * t = luax_checkjoint(L, 1);
  62. bool arg1 = luax_toboolean(L, 2);
  63. t->setCollideConnected(arg1);
  64. return 0;
  65. }
  66. int w_Joint_getCollideConnected(lua_State * L)
  67. {
  68. Joint * t = luax_checkjoint(L, 1);
  69. luax_pushboolean(L, t->getCollideConnected());
  70. return 1;
  71. }
  72. int w_Joint_destroy(lua_State * L)
  73. {
  74. Proxy * p = (Proxy *)lua_touserdata(L, 1);
  75. p->own = false;
  76. Joint * t = (Joint *)p->data;
  77. t->release();
  78. return 0;
  79. }
  80. static const luaL_Reg functions[] = {
  81. { "getType", w_Joint_getType },
  82. { "getAnchors", w_Joint_getAnchors },
  83. { "getReactionForce", w_Joint_getReactionForce },
  84. { "getReactionTorque", w_Joint_getReactionTorque },
  85. { "setCollideConnected", w_Joint_setCollideConnected },
  86. { "getCollideConnected", w_Joint_getCollideConnected },
  87. { "destroy", w_Joint_destroy },
  88. { 0, 0 }
  89. };
  90. int luaopen_joint(lua_State * L)
  91. {
  92. return luax_register_type(L, "Joint", functions);
  93. }
  94. } // box2d
  95. } // physics
  96. } // love