wrap_WheelJoint.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. * Copyright (c) 2006-2016 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_WheelJoint.h"
  21. namespace love
  22. {
  23. namespace physics
  24. {
  25. namespace box2d
  26. {
  27. WheelJoint *luax_checkwheeljoint(lua_State *L, int idx)
  28. {
  29. WheelJoint *j = luax_checktype<WheelJoint>(L, idx);
  30. if (!j->isValid())
  31. luaL_error(L, "Attempt to use destroyed joint.");
  32. return j;
  33. }
  34. int w_WheelJoint_getJointTranslation(lua_State *L)
  35. {
  36. WheelJoint *t = luax_checkwheeljoint(L, 1);
  37. lua_pushnumber(L, t->getJointTranslation());
  38. return 1;
  39. }
  40. int w_WheelJoint_getJointSpeed(lua_State *L)
  41. {
  42. WheelJoint *t = luax_checkwheeljoint(L, 1);
  43. lua_pushnumber(L, t->getJointSpeed());
  44. return 1;
  45. }
  46. int w_WheelJoint_setMotorEnabled(lua_State *L)
  47. {
  48. WheelJoint *t = luax_checkwheeljoint(L, 1);
  49. bool arg1 = luax_toboolean(L, 2);
  50. t->setMotorEnabled(arg1);
  51. return 0;
  52. }
  53. int w_WheelJoint_isMotorEnabled(lua_State *L)
  54. {
  55. WheelJoint *t = luax_checkwheeljoint(L, 1);
  56. luax_pushboolean(L, t->isMotorEnabled());
  57. return 1;
  58. }
  59. int w_WheelJoint_setMotorSpeed(lua_State *L)
  60. {
  61. WheelJoint *t = luax_checkwheeljoint(L, 1);
  62. float arg1 = (float)luaL_checknumber(L, 2);
  63. t->setMotorSpeed(arg1);
  64. return 0;
  65. }
  66. int w_WheelJoint_getMotorSpeed(lua_State *L)
  67. {
  68. WheelJoint *t = luax_checkwheeljoint(L, 1);
  69. lua_pushnumber(L, t->getMotorSpeed());
  70. return 1;
  71. }
  72. int w_WheelJoint_setMaxMotorTorque(lua_State *L)
  73. {
  74. WheelJoint *t = luax_checkwheeljoint(L, 1);
  75. float arg1 = (float)luaL_checknumber(L, 2);
  76. t->setMaxMotorTorque(arg1);
  77. return 0;
  78. }
  79. int w_WheelJoint_getMaxMotorTorque(lua_State *L)
  80. {
  81. WheelJoint *t = luax_checkwheeljoint(L, 1);
  82. lua_pushnumber(L, t->getMaxMotorTorque());
  83. return 1;
  84. }
  85. int w_WheelJoint_getMotorTorque(lua_State *L)
  86. {
  87. WheelJoint *t = luax_checkwheeljoint(L, 1);
  88. float inv_dt = (float)luaL_checknumber(L, 2);
  89. lua_pushnumber(L, t->getMotorTorque(inv_dt));
  90. return 1;
  91. }
  92. int w_WheelJoint_setSpringFrequency(lua_State *L)
  93. {
  94. WheelJoint *t = luax_checkwheeljoint(L, 1);
  95. float arg1 = (float)luaL_checknumber(L, 2);
  96. t->setSpringFrequency(arg1);
  97. return 0;
  98. }
  99. int w_WheelJoint_getSpringFrequency(lua_State *L)
  100. {
  101. WheelJoint *t = luax_checkwheeljoint(L, 1);
  102. lua_pushnumber(L, t->getSpringFrequency());
  103. return 1;
  104. }
  105. int w_WheelJoint_setSpringDampingRatio(lua_State *L)
  106. {
  107. WheelJoint *t = luax_checkwheeljoint(L, 1);
  108. float arg1 = (float)luaL_checknumber(L, 2);
  109. t->setSpringDampingRatio(arg1);
  110. return 0;
  111. }
  112. int w_WheelJoint_getSpringDampingRatio(lua_State *L)
  113. {
  114. WheelJoint *t = luax_checkwheeljoint(L, 1);
  115. lua_pushnumber(L, t->getSpringDampingRatio());
  116. return 1;
  117. }
  118. int w_WheelJoint_getAxis(lua_State *L)
  119. {
  120. WheelJoint *t = luax_checkwheeljoint(L, 1);
  121. lua_remove(L, 1);
  122. return t->getAxis(L);
  123. }
  124. static const luaL_Reg w_WheelJoint_functions[] =
  125. {
  126. { "getJointTranslation", w_WheelJoint_getJointTranslation },
  127. { "getJointSpeed", w_WheelJoint_getJointSpeed },
  128. { "setMotorEnabled", w_WheelJoint_setMotorEnabled },
  129. { "isMotorEnabled", w_WheelJoint_isMotorEnabled },
  130. { "setMotorSpeed", w_WheelJoint_setMotorSpeed },
  131. { "getMotorSpeed", w_WheelJoint_getMotorSpeed },
  132. { "setMaxMotorTorque", w_WheelJoint_setMaxMotorTorque },
  133. { "getMaxMotorTorque", w_WheelJoint_getMaxMotorTorque },
  134. { "getMotorTorque", w_WheelJoint_getMotorTorque },
  135. { "setSpringFrequency", w_WheelJoint_setSpringFrequency },
  136. { "getSpringFrequency", w_WheelJoint_getSpringFrequency },
  137. { "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
  138. { "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
  139. { "getAxis", w_WheelJoint_getAxis },
  140. { 0, 0 }
  141. };
  142. extern "C" int luaopen_wheeljoint(lua_State *L)
  143. {
  144. return luax_register_type(L, WheelJoint::type, "WheelJoint", w_Joint_functions, w_WheelJoint_functions, nullptr);
  145. }
  146. } // box2d
  147. } // physics
  148. } // love