wrap_MouseJoint.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * Copyright (c) 2006-2015 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_MouseJoint.h"
  21. namespace love
  22. {
  23. namespace physics
  24. {
  25. namespace box2d
  26. {
  27. MouseJoint *luax_checkmousejoint(lua_State *L, int idx)
  28. {
  29. MouseJoint *j = luax_checktype<MouseJoint>(L, idx, "MouseJoint", PHYSICS_MOUSE_JOINT_T);
  30. if (!j->isValid())
  31. luaL_error(L, "Attempt to use destroyed joint.");
  32. return j;
  33. }
  34. int w_MouseJoint_setTarget(lua_State *L)
  35. {
  36. MouseJoint *t = luax_checkmousejoint(L, 1);
  37. float x = (float)luaL_checknumber(L, 2);
  38. float y = (float)luaL_checknumber(L, 3);
  39. t->setTarget(x, y);
  40. return 0;
  41. }
  42. int w_MouseJoint_getTarget(lua_State *L)
  43. {
  44. MouseJoint *t = luax_checkmousejoint(L, 1);
  45. lua_remove(L, 1);
  46. return t->getTarget(L);
  47. }
  48. int w_MouseJoint_setMaxForce(lua_State *L)
  49. {
  50. MouseJoint *t = luax_checkmousejoint(L, 1);
  51. float f = (float)luaL_checknumber(L, 2);
  52. t->setMaxForce(f);
  53. return 0;
  54. }
  55. int w_MouseJoint_getMaxForce(lua_State *L)
  56. {
  57. MouseJoint *t = luax_checkmousejoint(L, 1);
  58. lua_pushnumber(L, t->getMaxForce());
  59. return 1;
  60. }
  61. int w_MouseJoint_setFrequency(lua_State *L)
  62. {
  63. MouseJoint *t = luax_checkmousejoint(L, 1);
  64. float arg1 = (float)luaL_checknumber(L, 2);
  65. t->setFrequency(arg1);
  66. return 0;
  67. }
  68. int w_MouseJoint_getFrequency(lua_State *L)
  69. {
  70. MouseJoint *t = luax_checkmousejoint(L, 1);
  71. lua_pushnumber(L, t->getFrequency());
  72. return 1;
  73. }
  74. int w_MouseJoint_setDampingRatio(lua_State *L)
  75. {
  76. MouseJoint *t = luax_checkmousejoint(L, 1);
  77. float arg1 = (float)luaL_checknumber(L, 2);
  78. t->setDampingRatio(arg1);
  79. return 0;
  80. }
  81. int w_MouseJoint_getDampingRatio(lua_State *L)
  82. {
  83. MouseJoint *t = luax_checkmousejoint(L, 1);
  84. lua_pushnumber(L, t->getDampingRatio());
  85. return 1;
  86. }
  87. static const luaL_Reg functions[] =
  88. {
  89. { "setTarget", w_MouseJoint_setTarget },
  90. { "getTarget", w_MouseJoint_getTarget },
  91. { "setMaxForce", w_MouseJoint_setMaxForce },
  92. { "getMaxForce", w_MouseJoint_getMaxForce },
  93. { "setFrequency", w_MouseJoint_setFrequency },
  94. { "getFrequency", w_MouseJoint_getFrequency },
  95. { "setDampingRatio", w_MouseJoint_setDampingRatio },
  96. { "getDampingRatio", w_MouseJoint_getDampingRatio },
  97. // From Joint.
  98. { "getType", w_Joint_getType },
  99. { "getBodies", w_Joint_getBodies },
  100. { "getAnchors", w_Joint_getAnchors },
  101. { "getReactionForce", w_Joint_getReactionForce },
  102. { "getReactionTorque", w_Joint_getReactionTorque },
  103. { "getCollideConnected", w_Joint_getCollideConnected },
  104. { "setUserData", w_Joint_setUserData },
  105. { "getUserData", w_Joint_getUserData },
  106. { "destroy", w_Joint_destroy },
  107. { "isDestroyed", w_Joint_isDestroyed },
  108. { 0, 0 }
  109. };
  110. extern "C" int luaopen_mousejoint(lua_State *L)
  111. {
  112. return luax_register_type(L, "MouseJoint", functions);
  113. }
  114. } // box2d
  115. } // physics
  116. } // love