wrap_Shape.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #include "wrap_Shape.h"
  21. namespace love
  22. {
  23. namespace physics
  24. {
  25. namespace box2d
  26. {
  27. Shape * luax_checkshape(lua_State * L, int idx)
  28. {
  29. return luax_checktype<Shape>(L, idx, "Shape", PHYSICS_SHAPE_T);
  30. }
  31. int w_Shape_getType(lua_State * L)
  32. {
  33. Shape * t = luax_checkshape(L, 1);
  34. lua_pushinteger(L, t->getType());
  35. return 1;
  36. }
  37. int w_Shape_setFriction(lua_State * L)
  38. {
  39. Shape * t = luax_checkshape(L, 1);
  40. float arg1 = (float)luaL_checknumber(L, 2);
  41. t->setFriction(arg1);
  42. return 0;
  43. }
  44. int w_Shape_setRestitution(lua_State * L)
  45. {
  46. Shape * t = luax_checkshape(L, 1);
  47. float arg1 = (float)luaL_checknumber(L, 2);
  48. t->setRestitution(arg1);
  49. return 0;
  50. }
  51. int w_Shape_setDensity(lua_State * L)
  52. {
  53. Shape * t = luax_checkshape(L, 1);
  54. float arg1 = (float)luaL_checknumber(L, 2);
  55. t->setDensity(arg1);
  56. return 0;
  57. }
  58. int w_Shape_setSensor(lua_State * L)
  59. {
  60. Shape * t = luax_checkshape(L, 1);
  61. bool arg1 = luax_toboolean(L, 2);
  62. t->setSensor(arg1);
  63. return 0;
  64. }
  65. int w_Shape_getFriction(lua_State * L)
  66. {
  67. Shape * t = luax_checkshape(L, 1);
  68. lua_pushnumber(L, t->getFriction());
  69. return 1;
  70. }
  71. int w_Shape_getRestituion(lua_State * L)
  72. {
  73. Shape * t = luax_checkshape(L, 1);
  74. lua_pushnumber(L, t->getRestituion());
  75. return 1;
  76. }
  77. int w_Shape_getDensity(lua_State * L)
  78. {
  79. Shape * t = luax_checkshape(L, 1);
  80. lua_pushnumber(L, t->getDensity());
  81. return 1;
  82. }
  83. int w_Shape_isSensor(lua_State * L)
  84. {
  85. Shape * t = luax_checkshape(L, 1);
  86. luax_pushboolean(L, t->isSensor());
  87. return 1;
  88. }
  89. int w_Shape_getBody(lua_State * L)
  90. {
  91. Shape * t = luax_checkshape(L, 1);
  92. Body * body = t->getBody();
  93. if(body == 0)
  94. return 0;
  95. luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body);
  96. return 1;
  97. }
  98. int w_Shape_testPoint(lua_State * L)
  99. {
  100. Shape * t = luax_checkshape(L, 1);
  101. float x = (float)luaL_checknumber(L, 2);
  102. float y = (float)luaL_checknumber(L, 3);
  103. luax_pushboolean(L, t->testPoint(x, y));
  104. return 1;
  105. }
  106. int w_Shape_testSegment(lua_State * L)
  107. {
  108. Shape * t = luax_checkshape(L, 1);
  109. return t->testSegment(L);
  110. }
  111. int w_Shape_setFilterData(lua_State * L)
  112. {
  113. Shape * t = luax_checkshape(L, 1);
  114. int v[3];
  115. v[0] = luaL_checkint(L, 2);
  116. v[1] = luaL_checkint(L, 3);
  117. v[2] = luaL_checkint(L, 4);
  118. t->setFilterData(v);
  119. return 0;
  120. }
  121. int w_Shape_getFilterData(lua_State * L)
  122. {
  123. Shape * t = luax_checkshape(L, 1);
  124. int v[3];
  125. t->getFilterData(v);
  126. lua_pushinteger(L, v[0]);
  127. lua_pushinteger(L, v[1]);
  128. lua_pushinteger(L, v[2]);
  129. return 3;
  130. }
  131. int w_Shape_setData(lua_State * L)
  132. {
  133. Shape * t = luax_checkshape(L, 1);
  134. lua_remove(L, 1);
  135. return t->setData(L);
  136. }
  137. int w_Shape_getData(lua_State * L)
  138. {
  139. Shape * t = luax_checkshape(L, 1);
  140. lua_remove(L, 1);
  141. return t->getData(L);
  142. }
  143. int w_Shape_getBoundingBox(lua_State * L)
  144. {
  145. Shape * t = luax_checkshape(L, 1);
  146. lua_remove(L, 1);
  147. return t->getBoundingBox(L);
  148. }
  149. static const luaL_Reg functions[] = {
  150. { "getType", w_Shape_getType },
  151. { "setFriction", w_Shape_setFriction },
  152. { "setRestitution", w_Shape_setRestitution },
  153. { "setDensity", w_Shape_setDensity },
  154. { "setSensor", w_Shape_setSensor },
  155. { "getFriction", w_Shape_getFriction },
  156. { "getRestituion", w_Shape_getRestituion },
  157. { "getDensity", w_Shape_getDensity },
  158. { "isSensor", w_Shape_isSensor },
  159. { "testPoint", w_Shape_testPoint },
  160. { "testSegment", w_Shape_testSegment },
  161. { "setFilterData", w_Shape_setFilterData },
  162. { "getFilterData", w_Shape_getFilterData },
  163. { "setData", w_Shape_setData },
  164. { "getData", w_Shape_getData },
  165. { "getBoundingBox", w_Shape_getBoundingBox },
  166. { 0, 0 }
  167. };
  168. int luaopen_shape(lua_State * L)
  169. {
  170. return luax_register_type(L, "Shape", functions);
  171. }
  172. } // box2d
  173. } // physics
  174. } // love