wrap_Physics.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /**
  2. * Copyright (c) 2006-2022 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_Physics.h"
  22. #include "wrap_World.h"
  23. #include "wrap_Contact.h"
  24. #include "wrap_Body.h"
  25. #include "wrap_Fixture.h"
  26. #include "wrap_Shape.h"
  27. #include "wrap_CircleShape.h"
  28. #include "wrap_PolygonShape.h"
  29. #include "wrap_EdgeShape.h"
  30. #include "wrap_ChainShape.h"
  31. #include "wrap_Joint.h"
  32. #include "wrap_MouseJoint.h"
  33. #include "wrap_DistanceJoint.h"
  34. #include "wrap_PrismaticJoint.h"
  35. #include "wrap_RevoluteJoint.h"
  36. #include "wrap_PulleyJoint.h"
  37. #include "wrap_GearJoint.h"
  38. #include "wrap_FrictionJoint.h"
  39. #include "wrap_WeldJoint.h"
  40. #include "wrap_WheelJoint.h"
  41. #include "wrap_RopeJoint.h"
  42. #include "wrap_MotorJoint.h"
  43. namespace love
  44. {
  45. namespace physics
  46. {
  47. namespace box2d
  48. {
  49. #define instance() (Module::getInstance<Physics>(Module::M_PHYSICS))
  50. int w_newWorld(lua_State *L)
  51. {
  52. float gx = (float)luaL_optnumber(L, 1, 0);
  53. float gy = (float)luaL_optnumber(L, 2, 0);
  54. bool sleep = luax_optboolean(L, 3, true);
  55. World *w;
  56. luax_catchexcept(L, [&](){ w = instance()->newWorld(gx, gy, sleep); });
  57. luax_pushtype(L, w);
  58. w->release();
  59. return 1;
  60. }
  61. int w_newBody(lua_State *L)
  62. {
  63. World *world = luax_checkworld(L, 1);
  64. float x = (float)luaL_optnumber(L, 2, 0.0);
  65. float y = (float)luaL_optnumber(L, 3, 0.0);
  66. Body::Type btype = Body::BODY_STATIC;
  67. const char *typestr = lua_isnoneornil(L, 4) ? 0 : lua_tostring(L, 4);
  68. if (typestr && !Body::getConstant(typestr, btype))
  69. return luax_enumerror(L, "Body type", Body::getConstants(btype), typestr);
  70. Body *body;
  71. luax_catchexcept(L, [&](){ body = instance()->newBody(world, x, y, btype); });
  72. luax_pushtype(L, body);
  73. body->release();
  74. return 1;
  75. }
  76. int w_newFixture(lua_State *L)
  77. {
  78. Body *body = luax_checkbody(L, 1);
  79. Shape *shape = luax_checkshape(L, 2);
  80. float density = (float)luaL_optnumber(L, 3, 1.0f);
  81. Fixture *fixture;
  82. luax_catchexcept(L, [&](){ fixture = instance()->newFixture(body, shape, density); });
  83. luax_pushtype(L, fixture);
  84. fixture->release();
  85. return 1;
  86. }
  87. int w_newCircleShape(lua_State *L)
  88. {
  89. int top = lua_gettop(L);
  90. if (top == 1)
  91. {
  92. float radius = (float)luaL_checknumber(L, 1);
  93. CircleShape *shape;
  94. luax_catchexcept(L, [&](){ shape = instance()->newCircleShape(radius); });
  95. luax_pushtype(L, shape);
  96. shape->release();
  97. return 1;
  98. }
  99. else if (top == 3)
  100. {
  101. float x = (float)luaL_checknumber(L, 1);
  102. float y = (float)luaL_checknumber(L, 2);
  103. float radius = (float)luaL_checknumber(L, 3);
  104. CircleShape *shape;
  105. luax_catchexcept(L, [&](){ shape = instance()->newCircleShape(x, y, radius); });
  106. luax_pushtype(L, shape);
  107. shape->release();
  108. return 1;
  109. }
  110. else
  111. return luaL_error(L, "Incorrect number of parameters");
  112. }
  113. int w_newRectangleShape(lua_State *L)
  114. {
  115. int top = lua_gettop(L);
  116. if (top == 2)
  117. {
  118. float w = (float)luaL_checknumber(L, 1);
  119. float h = (float)luaL_checknumber(L, 2);
  120. PolygonShape *shape;
  121. luax_catchexcept(L, [&](){ shape = instance()->newRectangleShape(w, h); });
  122. luax_pushtype(L, shape);
  123. shape->release();
  124. return 1;
  125. }
  126. else if (top == 4 || top == 5)
  127. {
  128. float x = (float)luaL_checknumber(L, 1);
  129. float y = (float)luaL_checknumber(L, 2);
  130. float w = (float)luaL_checknumber(L, 3);
  131. float h = (float)luaL_checknumber(L, 4);
  132. float angle = (float)luaL_optnumber(L, 5, 0);
  133. PolygonShape *shape;
  134. luax_catchexcept(L, [&](){ shape = instance()->newRectangleShape(x, y, w, h, angle); });
  135. luax_pushtype(L, shape);
  136. shape->release();
  137. return 1;
  138. }
  139. else
  140. return luaL_error(L, "Incorrect number of parameters");
  141. }
  142. int w_newEdgeShape(lua_State *L)
  143. {
  144. float x1 = (float)luaL_checknumber(L, 1);
  145. float y1 = (float)luaL_checknumber(L, 2);
  146. float x2 = (float)luaL_checknumber(L, 3);
  147. float y2 = (float)luaL_checknumber(L, 4);
  148. bool oneSided = luax_optboolean(L, 5, false);
  149. EdgeShape *shape;
  150. luax_catchexcept(L, [&](){ shape = instance()->newEdgeShape(x1, y1, x2, y2, oneSided); });
  151. luax_pushtype(L, shape);
  152. shape->release();
  153. return 1;
  154. }
  155. int w_newPolygonShape(lua_State *L)
  156. {
  157. int ret = 0;
  158. luax_catchexcept(L, [&](){ ret = instance()->newPolygonShape(L); });
  159. return ret;
  160. }
  161. int w_newChainShape(lua_State *L)
  162. {
  163. int ret = 0;
  164. luax_catchexcept(L, [&](){ ret = instance()->newChainShape(L); });
  165. return ret;
  166. }
  167. int w_newDistanceJoint(lua_State *L)
  168. {
  169. Body *body1 = luax_checkbody(L, 1);
  170. Body *body2 = luax_checkbody(L, 2);
  171. float x1 = (float)luaL_checknumber(L, 3);
  172. float y1 = (float)luaL_checknumber(L, 4);
  173. float x2 = (float)luaL_checknumber(L, 5);
  174. float y2 = (float)luaL_checknumber(L, 6);
  175. bool collideConnected = luax_optboolean(L, 7, false);
  176. DistanceJoint *j;
  177. luax_catchexcept(L, [&]() {
  178. j = instance()->newDistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);
  179. });
  180. luax_pushtype(L, j);
  181. j->release();
  182. return 1;
  183. }
  184. int w_newMouseJoint(lua_State *L)
  185. {
  186. Body *body = luax_checkbody(L, 1);
  187. float x = (float)luaL_checknumber(L, 2);
  188. float y = (float)luaL_checknumber(L, 3);
  189. MouseJoint *j;
  190. luax_catchexcept(L, [&](){ j = instance()->newMouseJoint(body, x, y); });
  191. luax_pushtype(L, j);
  192. j->release();
  193. return 1;
  194. }
  195. int w_newRevoluteJoint(lua_State *L)
  196. {
  197. Body *body1 = luax_checkbody(L, 1);
  198. Body *body2 = luax_checkbody(L, 2);
  199. float xA = (float)luaL_checknumber(L, 3);
  200. float yA = (float)luaL_checknumber(L, 4);
  201. float xB, yB;
  202. bool collideConnected;
  203. if (lua_gettop(L) >= 6)
  204. {
  205. xB = (float)luaL_checknumber(L, 5);
  206. yB = (float)luaL_checknumber(L, 6);
  207. collideConnected = luax_optboolean(L, 7, false);
  208. }
  209. else
  210. {
  211. xB = xA;
  212. yB = yA;
  213. collideConnected = luax_optboolean(L, 5, false);
  214. }
  215. RevoluteJoint *j;
  216. luax_catchexcept(L, [&]() {
  217. if (lua_gettop(L) >= 8)
  218. {
  219. float referenceAngle = (float)luaL_checknumber(L, 8);
  220. j = instance()->newRevoluteJoint(body1, body2, xA, yA, xB, yB, collideConnected, referenceAngle);
  221. }
  222. else
  223. j = instance()->newRevoluteJoint(body1, body2, xA, yA, xB, yB, collideConnected);
  224. });
  225. luax_pushtype(L, j);
  226. j->release();
  227. return 1;
  228. }
  229. int w_newPrismaticJoint(lua_State *L)
  230. {
  231. Body *body1 = luax_checkbody(L, 1);
  232. Body *body2 = luax_checkbody(L, 2);
  233. float xA = (float)luaL_checknumber(L, 3);
  234. float yA = (float)luaL_checknumber(L, 4);
  235. float xB, yB, ax, ay;
  236. bool collideConnected;
  237. if (lua_gettop(L) >= 8)
  238. {
  239. xB = (float)luaL_checknumber(L, 5);
  240. yB = (float)luaL_checknumber(L, 6);
  241. ax = (float)luaL_checknumber(L, 7);
  242. ay = (float)luaL_checknumber(L, 8);
  243. collideConnected = luax_optboolean(L, 9, false);
  244. }
  245. else
  246. {
  247. xB = xA;
  248. yB = yA;
  249. ax = (float)luaL_checknumber(L, 5);
  250. ay = (float)luaL_checknumber(L, 6);
  251. collideConnected = luax_optboolean(L, 7, false);
  252. }
  253. PrismaticJoint *j;
  254. luax_catchexcept(L, [&]() {
  255. if (lua_gettop(L) >= 10)
  256. {
  257. float referenceAngle = (float)luaL_checknumber(L, 10);
  258. j = instance()->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected, referenceAngle);
  259. }
  260. else
  261. j = instance()->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
  262. });
  263. luax_pushtype(L, j);
  264. j->release();
  265. return 1;
  266. }
  267. int w_newPulleyJoint(lua_State *L)
  268. {
  269. Body *body1 = luax_checkbody(L, 1);
  270. Body *body2 = luax_checkbody(L, 2);
  271. float gx1 = (float)luaL_checknumber(L, 3);
  272. float gy1 = (float)luaL_checknumber(L, 4);
  273. float gx2 = (float)luaL_checknumber(L, 5);
  274. float gy2 = (float)luaL_checknumber(L, 6);
  275. float x1 = (float)luaL_checknumber(L, 7);
  276. float y1 = (float)luaL_checknumber(L, 8);
  277. float x2 = (float)luaL_checknumber(L, 9);
  278. float y2 = (float)luaL_checknumber(L, 10);
  279. float ratio = (float)luaL_optnumber(L, 11, 1.0);
  280. bool collideConnected = luax_optboolean(L, 12, true); // PulleyJoints default to colliding connected bodies, see b2PulleyJoint.h
  281. PulleyJoint *j;
  282. luax_catchexcept(L, [&]() {
  283. j = instance()->newPulleyJoint(body1, body2, b2Vec2(gx1,gy1), b2Vec2(gx2,gy2), b2Vec2(x1,y1), b2Vec2(x2,y2), ratio, collideConnected);
  284. });
  285. luax_pushtype(L, j);
  286. j->release();
  287. return 1;
  288. }
  289. int w_newGearJoint(lua_State *L)
  290. {
  291. Joint *joint1 = luax_checkjoint(L, 1);
  292. Joint *joint2 = luax_checkjoint(L, 2);
  293. float ratio = (float)luaL_optnumber(L, 3, 1.0);
  294. bool collideConnected = luax_optboolean(L, 4, false);
  295. GearJoint *j;
  296. luax_catchexcept(L, [&]() {
  297. j = instance()->newGearJoint(joint1, joint2, ratio, collideConnected);
  298. });
  299. luax_pushtype(L, j);
  300. j->release();
  301. return 1;
  302. }
  303. int w_newFrictionJoint(lua_State *L)
  304. {
  305. Body *body1 = luax_checkbody(L, 1);
  306. Body *body2 = luax_checkbody(L, 2);
  307. float xA = (float)luaL_checknumber(L, 3);
  308. float yA = (float)luaL_checknumber(L, 4);
  309. float xB, yB;
  310. bool collideConnected;
  311. if (lua_gettop(L) >= 6)
  312. {
  313. xB = (float)luaL_checknumber(L, 5);
  314. yB = (float)luaL_checknumber(L, 6);
  315. collideConnected = luax_optboolean(L, 7, false);
  316. }
  317. else
  318. {
  319. xB = xA;
  320. yB = yA;
  321. collideConnected = luax_optboolean(L, 5, false);
  322. }
  323. FrictionJoint *j;
  324. luax_catchexcept(L, [&]() {
  325. j = instance()->newFrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);
  326. });
  327. luax_pushtype(L, j);
  328. j->release();
  329. return 1;
  330. }
  331. int w_newWeldJoint(lua_State *L)
  332. {
  333. Body *body1 = luax_checkbody(L, 1);
  334. Body *body2 = luax_checkbody(L, 2);
  335. float xA = (float)luaL_checknumber(L, 3);
  336. float yA = (float)luaL_checknumber(L, 4);
  337. float xB, yB;
  338. bool collideConnected;
  339. if (lua_gettop(L) >= 6)
  340. {
  341. xB = (float)luaL_checknumber(L, 5);
  342. yB = (float)luaL_checknumber(L, 6);
  343. collideConnected = luax_optboolean(L, 7, false);
  344. }
  345. else
  346. {
  347. xB = xA;
  348. yB = yA;
  349. collideConnected = luax_optboolean(L, 5, false);
  350. }
  351. WeldJoint *j;
  352. luax_catchexcept(L, [&]() {
  353. if (lua_gettop(L) >= 8)
  354. {
  355. float referenceAngle = (float)luaL_checknumber(L, 8);
  356. j = instance()->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected, referenceAngle);
  357. }
  358. else
  359. j = instance()->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);
  360. });
  361. luax_pushtype(L, j);
  362. j->release();
  363. return 1;
  364. }
  365. int w_newWheelJoint(lua_State *L)
  366. {
  367. Body *body1 = luax_checkbody(L, 1);
  368. Body *body2 = luax_checkbody(L, 2);
  369. float xA = (float)luaL_checknumber(L, 3);
  370. float yA = (float)luaL_checknumber(L, 4);
  371. float xB, yB, ax, ay;
  372. bool collideConnected;
  373. if (lua_gettop(L) >= 8)
  374. {
  375. xB = (float)luaL_checknumber(L, 5);
  376. yB = (float)luaL_checknumber(L, 6);
  377. ax = (float)luaL_checknumber(L, 7);
  378. ay = (float)luaL_checknumber(L, 8);
  379. collideConnected = luax_optboolean(L, 9, false);
  380. }
  381. else
  382. {
  383. xB = xA;
  384. yB = yA;
  385. ax = (float)luaL_checknumber(L, 5);
  386. ay = (float)luaL_checknumber(L, 6);
  387. collideConnected = luax_optboolean(L, 7, false);
  388. }
  389. WheelJoint *j;
  390. luax_catchexcept(L, [&]() {
  391. j = instance()->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
  392. });
  393. luax_pushtype(L, j);
  394. j->release();
  395. return 1;
  396. }
  397. int w_newRopeJoint(lua_State *L)
  398. {
  399. Body *body1 = luax_checkbody(L, 1);
  400. Body *body2 = luax_checkbody(L, 2);
  401. float x1 = (float)luaL_checknumber(L, 3);
  402. float y1 = (float)luaL_checknumber(L, 4);
  403. float x2 = (float)luaL_checknumber(L, 5);
  404. float y2 = (float)luaL_checknumber(L, 6);
  405. float maxLength = (float)luaL_checknumber(L, 7);
  406. bool collideConnected = luax_optboolean(L, 8, false);
  407. RopeJoint *j;
  408. luax_catchexcept(L, [&]() {
  409. j = instance()->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
  410. });
  411. luax_pushtype(L, j);
  412. j->release();
  413. return 1;
  414. }
  415. int w_newMotorJoint(lua_State *L)
  416. {
  417. Body *body1 = luax_checkbody(L, 1);
  418. Body *body2 = luax_checkbody(L, 2);
  419. MotorJoint *j = 0;
  420. if (!lua_isnoneornil(L, 3))
  421. {
  422. float correctionFactor = (float)luaL_checknumber(L, 3);
  423. bool collideConnected = luax_optboolean(L, 4, false);
  424. luax_catchexcept(L, [&]() {
  425. j = instance()->newMotorJoint(body1, body2, correctionFactor, collideConnected);
  426. });
  427. }
  428. else
  429. {
  430. luax_catchexcept(L, [&](){ j = instance()->newMotorJoint(body1, body2); });
  431. }
  432. luax_pushtype(L, j);
  433. j->release();
  434. return 1;
  435. }
  436. int w_getDistance(lua_State *L)
  437. {
  438. return instance()->getDistance(L);
  439. }
  440. int w_setMeter(lua_State *L)
  441. {
  442. float arg1 = (float) luaL_checknumber(L, 1);
  443. luax_catchexcept(L, [&](){ Physics::setMeter(arg1); });
  444. return 0;
  445. }
  446. int w_getMeter(lua_State *L)
  447. {
  448. lua_pushinteger(L, Physics::getMeter());
  449. return 1;
  450. }
  451. int w_computeLinearStiffness(lua_State *L)
  452. {
  453. float frequency = (float)luaL_checknumber(L, 1);
  454. float dampingRatio = (float)luaL_checknumber(L, 2);
  455. Body *body1 = luax_checkbody(L, 3);
  456. b2Body *other = 0;
  457. if (lua_isnoneornil(L, 4))
  458. other = body1->getWorld()->getGroundBody();
  459. else
  460. other = luax_checkbody(L, 4)->body;
  461. float stiffness, damping;
  462. Physics::computeLinearStiffness(stiffness, damping, frequency, dampingRatio, body1->body, other);
  463. lua_pushnumber(L, stiffness);
  464. lua_pushnumber(L, damping);
  465. return 2;
  466. }
  467. int w_computeLinearFrequency(lua_State *L)
  468. {
  469. float stiffness = (float)luaL_checknumber(L, 1);
  470. float damping = (float)luaL_checknumber(L, 2);
  471. Body *body1 = luax_checkbody(L, 3);
  472. b2Body *other = 0;
  473. if (lua_isnoneornil(L, 4))
  474. other = body1->getWorld()->getGroundBody();
  475. else
  476. other = luax_checkbody(L, 4)->body;
  477. float frequency, dampingRatio;
  478. Physics::computeLinearFrequency(frequency, dampingRatio, stiffness, damping, body1->body, other);
  479. lua_pushnumber(L, frequency);
  480. lua_pushnumber(L, dampingRatio);
  481. return 2;
  482. }
  483. int w_computeAngularStiffness(lua_State *L)
  484. {
  485. float frequency = (float)luaL_checknumber(L, 1);
  486. float dampingRatio = (float)luaL_checknumber(L, 2);
  487. Body *body1 = luax_checkbody(L, 3);
  488. b2Body *other = 0;
  489. if (lua_isnoneornil(L, 4))
  490. other = body1->getWorld()->getGroundBody();
  491. else
  492. other = luax_checkbody(L, 4)->body;
  493. float stiffness, damping;
  494. Physics::computeAngularStiffness(stiffness, damping, frequency, dampingRatio, body1->body, other);
  495. lua_pushnumber(L, stiffness);
  496. lua_pushnumber(L, damping);
  497. return 2;
  498. }
  499. int w_computeAngularFrequency(lua_State *L)
  500. {
  501. float stiffness = (float)luaL_checknumber(L, 1);
  502. float damping = (float)luaL_checknumber(L, 2);
  503. Body *body1 = luax_checkbody(L, 3);
  504. b2Body *other = 0;
  505. if (lua_isnoneornil(L, 4))
  506. other = body1->getWorld()->getGroundBody();
  507. else
  508. other = luax_checkbody(L, 4)->body;
  509. float frequency, dampingRatio;
  510. Physics::computeAngularFrequency(frequency, dampingRatio, stiffness, damping, body1->body, other);
  511. lua_pushnumber(L, frequency);
  512. lua_pushnumber(L, dampingRatio);
  513. return 2;
  514. }
  515. // List of functions to wrap.
  516. static const luaL_Reg functions[] =
  517. {
  518. { "newWorld", w_newWorld },
  519. { "newBody", w_newBody },
  520. { "newFixture", w_newFixture },
  521. { "newCircleShape", w_newCircleShape },
  522. { "newRectangleShape", w_newRectangleShape },
  523. { "newPolygonShape", w_newPolygonShape },
  524. { "newEdgeShape", w_newEdgeShape },
  525. { "newChainShape", w_newChainShape },
  526. { "newDistanceJoint", w_newDistanceJoint },
  527. { "newMouseJoint", w_newMouseJoint },
  528. { "newRevoluteJoint", w_newRevoluteJoint },
  529. { "newPrismaticJoint", w_newPrismaticJoint },
  530. { "newPulleyJoint", w_newPulleyJoint },
  531. { "newGearJoint", w_newGearJoint },
  532. { "newFrictionJoint", w_newFrictionJoint },
  533. { "newWeldJoint", w_newWeldJoint },
  534. { "newWheelJoint", w_newWheelJoint },
  535. { "newRopeJoint", w_newRopeJoint },
  536. { "newMotorJoint", w_newMotorJoint },
  537. { "getDistance", w_getDistance },
  538. { "getMeter", w_getMeter },
  539. { "setMeter", w_setMeter },
  540. { "computeLinearStiffness", w_computeLinearStiffness },
  541. { "computeLinearFrequency", w_computeLinearFrequency },
  542. { "computeAngularStiffness", w_computeAngularStiffness },
  543. { "computeAngularFrequency", w_computeAngularFrequency },
  544. { 0, 0 },
  545. };
  546. static const lua_CFunction types[] =
  547. {
  548. luaopen_world,
  549. luaopen_contact,
  550. luaopen_body,
  551. luaopen_fixture,
  552. luaopen_shape,
  553. luaopen_circleshape,
  554. luaopen_polygonshape,
  555. luaopen_edgeshape,
  556. luaopen_chainshape,
  557. luaopen_joint,
  558. luaopen_mousejoint,
  559. luaopen_distancejoint,
  560. luaopen_prismaticjoint,
  561. luaopen_revolutejoint,
  562. luaopen_pulleyjoint,
  563. luaopen_gearjoint,
  564. luaopen_frictionjoint,
  565. luaopen_weldjoint,
  566. luaopen_wheeljoint,
  567. luaopen_ropejoint,
  568. luaopen_motorjoint,
  569. 0
  570. };
  571. extern "C" int luaopen_love_physics(lua_State *L)
  572. {
  573. Physics *instance = instance();
  574. if (instance == nullptr)
  575. {
  576. luax_catchexcept(L, [&](){ instance = new Physics(); });
  577. }
  578. else
  579. instance->retain();
  580. WrappedModule w;
  581. w.module = instance;
  582. w.name = "physics";
  583. w.type = &Module::type;
  584. w.functions = functions;
  585. w.types = types;
  586. return luax_register_module(L, w);
  587. }
  588. } // box2d
  589. } // physics
  590. } // love