wrap_DistanceJoint.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_DistanceJoint.h"
  21. namespace love
  22. {
  23. namespace physics
  24. {
  25. namespace box2d
  26. {
  27. DistanceJoint *luax_checkdistancejoint(lua_State *L, int idx)
  28. {
  29. DistanceJoint *j = luax_checktype<DistanceJoint>(L, idx, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T);
  30. if (!j->isValid())
  31. luaL_error(L, "Attempt to use destroyed joint.");
  32. return j;
  33. }
  34. int w_DistanceJoint_setLength(lua_State *L)
  35. {
  36. DistanceJoint *t = luax_checkdistancejoint(L, 1);
  37. float arg1 = (float)luaL_checknumber(L, 2);
  38. t->setLength(arg1);
  39. return 0;
  40. }
  41. int w_DistanceJoint_getLength(lua_State *L)
  42. {
  43. DistanceJoint *t = luax_checkdistancejoint(L, 1);
  44. lua_pushnumber(L, t->getLength());
  45. return 1;
  46. }
  47. int w_DistanceJoint_setFrequency(lua_State *L)
  48. {
  49. DistanceJoint *t = luax_checkdistancejoint(L, 1);
  50. float arg1 = (float)luaL_checknumber(L, 2);
  51. t->setFrequency(arg1);
  52. return 0;
  53. }
  54. int w_DistanceJoint_getFrequency(lua_State *L)
  55. {
  56. DistanceJoint *t = luax_checkdistancejoint(L, 1);
  57. lua_pushnumber(L, t->getFrequency());
  58. return 1;
  59. }
  60. int w_DistanceJoint_setDampingRatio(lua_State *L)
  61. {
  62. DistanceJoint *t = luax_checkdistancejoint(L, 1);
  63. float arg1 = (float)luaL_checknumber(L, 2);
  64. t->setDampingRatio(arg1);
  65. return 0;
  66. }
  67. int w_DistanceJoint_getDampingRatio(lua_State *L)
  68. {
  69. DistanceJoint *t = luax_checkdistancejoint(L, 1);
  70. lua_pushnumber(L, t->getDampingRatio());
  71. return 1;
  72. }
  73. static const luaL_Reg functions[] =
  74. {
  75. { "setLength", w_DistanceJoint_setLength },
  76. { "getLength", w_DistanceJoint_getLength },
  77. { "setFrequency", w_DistanceJoint_setFrequency },
  78. { "getFrequency", w_DistanceJoint_getFrequency },
  79. { "setDampingRatio", w_DistanceJoint_setDampingRatio },
  80. { "getDampingRatio", w_DistanceJoint_getDampingRatio },
  81. // From Joint.
  82. { "getType", w_Joint_getType },
  83. { "getBodies", w_Joint_getBodies },
  84. { "getAnchors", w_Joint_getAnchors },
  85. { "getReactionForce", w_Joint_getReactionForce },
  86. { "getReactionTorque", w_Joint_getReactionTorque },
  87. { "getCollideConnected", w_Joint_getCollideConnected },
  88. { "setUserData", w_Joint_setUserData },
  89. { "getUserData", w_Joint_getUserData },
  90. { "destroy", w_Joint_destroy },
  91. { 0, 0 }
  92. };
  93. extern "C" int luaopen_distancejoint(lua_State *L)
  94. {
  95. return luax_register_type(L, "DistanceJoint", functions);
  96. }
  97. } // box2d
  98. } // physics
  99. } // love