lua_PhysicsCollisionObject.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_PhysicsCollisionObject.h"
  4. #include "Base.h"
  5. #include "Game.h"
  6. #include "Node.h"
  7. #include "PhysicsCollisionObject.h"
  8. #include "PhysicsController.h"
  9. #include "ScriptListener.h"
  10. #include "lua_PhysicsCollisionObjectCollisionListenerEventType.h"
  11. #include "lua_PhysicsCollisionObjectType.h"
  12. #include "lua_PhysicsCollisionShapeType.h"
  13. namespace gameplay
  14. {
  15. void luaRegister_PhysicsCollisionObject()
  16. {
  17. const luaL_Reg lua_members[] =
  18. {
  19. {"addCollisionListener", lua_PhysicsCollisionObject_addCollisionListener},
  20. {"collidesWith", lua_PhysicsCollisionObject_collidesWith},
  21. {"getCollisionShape", lua_PhysicsCollisionObject_getCollisionShape},
  22. {"getNode", lua_PhysicsCollisionObject_getNode},
  23. {"getShapeType", lua_PhysicsCollisionObject_getShapeType},
  24. {"getType", lua_PhysicsCollisionObject_getType},
  25. {"isDynamic", lua_PhysicsCollisionObject_isDynamic},
  26. {"isEnabled", lua_PhysicsCollisionObject_isEnabled},
  27. {"isKinematic", lua_PhysicsCollisionObject_isKinematic},
  28. {"removeCollisionListener", lua_PhysicsCollisionObject_removeCollisionListener},
  29. {"setEnabled", lua_PhysicsCollisionObject_setEnabled},
  30. {NULL, NULL}
  31. };
  32. const luaL_Reg* lua_statics = NULL;
  33. std::vector<std::string> scopePath;
  34. ScriptUtil::registerClass("PhysicsCollisionObject", lua_members, NULL, lua_PhysicsCollisionObject__gc, lua_statics, scopePath);
  35. }
  36. static PhysicsCollisionObject* getInstance(lua_State* state)
  37. {
  38. void* userdata = luaL_checkudata(state, 1, "PhysicsCollisionObject");
  39. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsCollisionObject' expected.");
  40. return (PhysicsCollisionObject*)((ScriptUtil::LuaObject*)userdata)->instance;
  41. }
  42. int lua_PhysicsCollisionObject__gc(lua_State* state)
  43. {
  44. // Get the number of parameters.
  45. int paramCount = lua_gettop(state);
  46. // Attempt to match the parameters to a valid binding.
  47. switch (paramCount)
  48. {
  49. case 1:
  50. {
  51. if ((lua_type(state, 1) == LUA_TUSERDATA))
  52. {
  53. void* userdata = luaL_checkudata(state, 1, "PhysicsCollisionObject");
  54. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsCollisionObject' expected.");
  55. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  56. if (object->owns)
  57. {
  58. PhysicsCollisionObject* instance = (PhysicsCollisionObject*)object->instance;
  59. SAFE_DELETE(instance);
  60. }
  61. return 0;
  62. }
  63. else
  64. {
  65. lua_pushstring(state, "lua_PhysicsCollisionObject__gc - Failed to match the given parameters to a valid function signature.");
  66. lua_error(state);
  67. }
  68. break;
  69. }
  70. default:
  71. {
  72. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  73. lua_error(state);
  74. break;
  75. }
  76. }
  77. return 0;
  78. }
  79. int lua_PhysicsCollisionObject_addCollisionListener(lua_State* state)
  80. {
  81. // Get the number of parameters.
  82. int paramCount = lua_gettop(state);
  83. // Attempt to match the parameters to a valid binding.
  84. switch (paramCount)
  85. {
  86. case 2:
  87. {
  88. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  89. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  90. {
  91. // Get parameter 1 off the stack.
  92. PhysicsCollisionObject::CollisionListener* param1 = ScriptUtil::getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
  93. PhysicsCollisionObject* instance = getInstance(state);
  94. instance->addCollisionListener(param1);
  95. return 0;
  96. }
  97. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  98. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  99. {
  100. // Get parameter 1 off the stack.
  101. const char* param1 = ScriptUtil::getString(2, false);
  102. PhysicsCollisionObject* instance = getInstance(state);
  103. instance->addCollisionListener(param1);
  104. return 0;
  105. }
  106. else
  107. {
  108. lua_pushstring(state, "lua_PhysicsCollisionObject_addCollisionListener - Failed to match the given parameters to a valid function signature.");
  109. lua_error(state);
  110. }
  111. break;
  112. }
  113. case 3:
  114. {
  115. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  116. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  117. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  118. {
  119. // Get parameter 1 off the stack.
  120. PhysicsCollisionObject::CollisionListener* param1 = ScriptUtil::getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
  121. // Get parameter 2 off the stack.
  122. PhysicsCollisionObject* param2 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
  123. PhysicsCollisionObject* instance = getInstance(state);
  124. instance->addCollisionListener(param1, param2);
  125. return 0;
  126. }
  127. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  128. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  129. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  130. {
  131. // Get parameter 1 off the stack.
  132. const char* param1 = ScriptUtil::getString(2, false);
  133. // Get parameter 2 off the stack.
  134. PhysicsCollisionObject* param2 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
  135. PhysicsCollisionObject* instance = getInstance(state);
  136. instance->addCollisionListener(param1, param2);
  137. return 0;
  138. }
  139. else
  140. {
  141. lua_pushstring(state, "lua_PhysicsCollisionObject_addCollisionListener - Failed to match the given parameters to a valid function signature.");
  142. lua_error(state);
  143. }
  144. break;
  145. }
  146. default:
  147. {
  148. lua_pushstring(state, "Invalid number of parameters (expected 2 or 3).");
  149. lua_error(state);
  150. break;
  151. }
  152. }
  153. return 0;
  154. }
  155. int lua_PhysicsCollisionObject_collidesWith(lua_State* state)
  156. {
  157. // Get the number of parameters.
  158. int paramCount = lua_gettop(state);
  159. // Attempt to match the parameters to a valid binding.
  160. switch (paramCount)
  161. {
  162. case 2:
  163. {
  164. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  165. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  166. {
  167. // Get parameter 1 off the stack.
  168. PhysicsCollisionObject* param1 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(2, "PhysicsCollisionObject", false);
  169. PhysicsCollisionObject* instance = getInstance(state);
  170. bool result = instance->collidesWith(param1);
  171. // Push the return value onto the stack.
  172. lua_pushboolean(state, result);
  173. return 1;
  174. }
  175. else
  176. {
  177. lua_pushstring(state, "lua_PhysicsCollisionObject_collidesWith - Failed to match the given parameters to a valid function signature.");
  178. lua_error(state);
  179. }
  180. break;
  181. }
  182. default:
  183. {
  184. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  185. lua_error(state);
  186. break;
  187. }
  188. }
  189. return 0;
  190. }
  191. int lua_PhysicsCollisionObject_getCollisionShape(lua_State* state)
  192. {
  193. // Get the number of parameters.
  194. int paramCount = lua_gettop(state);
  195. // Attempt to match the parameters to a valid binding.
  196. switch (paramCount)
  197. {
  198. case 1:
  199. {
  200. if ((lua_type(state, 1) == LUA_TUSERDATA))
  201. {
  202. PhysicsCollisionObject* instance = getInstance(state);
  203. void* returnPtr = (void*)instance->getCollisionShape();
  204. if (returnPtr)
  205. {
  206. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  207. object->instance = returnPtr;
  208. object->owns = false;
  209. luaL_getmetatable(state, "PhysicsCollisionShape");
  210. lua_setmetatable(state, -2);
  211. }
  212. else
  213. {
  214. lua_pushnil(state);
  215. }
  216. return 1;
  217. }
  218. else
  219. {
  220. lua_pushstring(state, "lua_PhysicsCollisionObject_getCollisionShape - Failed to match the given parameters to a valid function signature.");
  221. lua_error(state);
  222. }
  223. break;
  224. }
  225. default:
  226. {
  227. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  228. lua_error(state);
  229. break;
  230. }
  231. }
  232. return 0;
  233. }
  234. int lua_PhysicsCollisionObject_getNode(lua_State* state)
  235. {
  236. // Get the number of parameters.
  237. int paramCount = lua_gettop(state);
  238. // Attempt to match the parameters to a valid binding.
  239. switch (paramCount)
  240. {
  241. case 1:
  242. {
  243. if ((lua_type(state, 1) == LUA_TUSERDATA))
  244. {
  245. PhysicsCollisionObject* instance = getInstance(state);
  246. void* returnPtr = (void*)instance->getNode();
  247. if (returnPtr)
  248. {
  249. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  250. object->instance = returnPtr;
  251. object->owns = false;
  252. luaL_getmetatable(state, "Node");
  253. lua_setmetatable(state, -2);
  254. }
  255. else
  256. {
  257. lua_pushnil(state);
  258. }
  259. return 1;
  260. }
  261. else
  262. {
  263. lua_pushstring(state, "lua_PhysicsCollisionObject_getNode - Failed to match the given parameters to a valid function signature.");
  264. lua_error(state);
  265. }
  266. break;
  267. }
  268. default:
  269. {
  270. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  271. lua_error(state);
  272. break;
  273. }
  274. }
  275. return 0;
  276. }
  277. int lua_PhysicsCollisionObject_getShapeType(lua_State* state)
  278. {
  279. // Get the number of parameters.
  280. int paramCount = lua_gettop(state);
  281. // Attempt to match the parameters to a valid binding.
  282. switch (paramCount)
  283. {
  284. case 1:
  285. {
  286. if ((lua_type(state, 1) == LUA_TUSERDATA))
  287. {
  288. PhysicsCollisionObject* instance = getInstance(state);
  289. PhysicsCollisionShape::Type result = instance->getShapeType();
  290. // Push the return value onto the stack.
  291. lua_pushstring(state, lua_stringFromEnum_PhysicsCollisionShapeType(result));
  292. return 1;
  293. }
  294. else
  295. {
  296. lua_pushstring(state, "lua_PhysicsCollisionObject_getShapeType - Failed to match the given parameters to a valid function signature.");
  297. lua_error(state);
  298. }
  299. break;
  300. }
  301. default:
  302. {
  303. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  304. lua_error(state);
  305. break;
  306. }
  307. }
  308. return 0;
  309. }
  310. int lua_PhysicsCollisionObject_getType(lua_State* state)
  311. {
  312. // Get the number of parameters.
  313. int paramCount = lua_gettop(state);
  314. // Attempt to match the parameters to a valid binding.
  315. switch (paramCount)
  316. {
  317. case 1:
  318. {
  319. if ((lua_type(state, 1) == LUA_TUSERDATA))
  320. {
  321. PhysicsCollisionObject* instance = getInstance(state);
  322. PhysicsCollisionObject::Type result = instance->getType();
  323. // Push the return value onto the stack.
  324. lua_pushstring(state, lua_stringFromEnum_PhysicsCollisionObjectType(result));
  325. return 1;
  326. }
  327. else
  328. {
  329. lua_pushstring(state, "lua_PhysicsCollisionObject_getType - Failed to match the given parameters to a valid function signature.");
  330. lua_error(state);
  331. }
  332. break;
  333. }
  334. default:
  335. {
  336. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  337. lua_error(state);
  338. break;
  339. }
  340. }
  341. return 0;
  342. }
  343. int lua_PhysicsCollisionObject_isDynamic(lua_State* state)
  344. {
  345. // Get the number of parameters.
  346. int paramCount = lua_gettop(state);
  347. // Attempt to match the parameters to a valid binding.
  348. switch (paramCount)
  349. {
  350. case 1:
  351. {
  352. if ((lua_type(state, 1) == LUA_TUSERDATA))
  353. {
  354. PhysicsCollisionObject* instance = getInstance(state);
  355. bool result = instance->isDynamic();
  356. // Push the return value onto the stack.
  357. lua_pushboolean(state, result);
  358. return 1;
  359. }
  360. else
  361. {
  362. lua_pushstring(state, "lua_PhysicsCollisionObject_isDynamic - Failed to match the given parameters to a valid function signature.");
  363. lua_error(state);
  364. }
  365. break;
  366. }
  367. default:
  368. {
  369. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  370. lua_error(state);
  371. break;
  372. }
  373. }
  374. return 0;
  375. }
  376. int lua_PhysicsCollisionObject_isEnabled(lua_State* state)
  377. {
  378. // Get the number of parameters.
  379. int paramCount = lua_gettop(state);
  380. // Attempt to match the parameters to a valid binding.
  381. switch (paramCount)
  382. {
  383. case 1:
  384. {
  385. if ((lua_type(state, 1) == LUA_TUSERDATA))
  386. {
  387. PhysicsCollisionObject* instance = getInstance(state);
  388. bool result = instance->isEnabled();
  389. // Push the return value onto the stack.
  390. lua_pushboolean(state, result);
  391. return 1;
  392. }
  393. else
  394. {
  395. lua_pushstring(state, "lua_PhysicsCollisionObject_isEnabled - Failed to match the given parameters to a valid function signature.");
  396. lua_error(state);
  397. }
  398. break;
  399. }
  400. default:
  401. {
  402. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  403. lua_error(state);
  404. break;
  405. }
  406. }
  407. return 0;
  408. }
  409. int lua_PhysicsCollisionObject_isKinematic(lua_State* state)
  410. {
  411. // Get the number of parameters.
  412. int paramCount = lua_gettop(state);
  413. // Attempt to match the parameters to a valid binding.
  414. switch (paramCount)
  415. {
  416. case 1:
  417. {
  418. if ((lua_type(state, 1) == LUA_TUSERDATA))
  419. {
  420. PhysicsCollisionObject* instance = getInstance(state);
  421. bool result = instance->isKinematic();
  422. // Push the return value onto the stack.
  423. lua_pushboolean(state, result);
  424. return 1;
  425. }
  426. else
  427. {
  428. lua_pushstring(state, "lua_PhysicsCollisionObject_isKinematic - Failed to match the given parameters to a valid function signature.");
  429. lua_error(state);
  430. }
  431. break;
  432. }
  433. default:
  434. {
  435. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  436. lua_error(state);
  437. break;
  438. }
  439. }
  440. return 0;
  441. }
  442. int lua_PhysicsCollisionObject_removeCollisionListener(lua_State* state)
  443. {
  444. // Get the number of parameters.
  445. int paramCount = lua_gettop(state);
  446. // Attempt to match the parameters to a valid binding.
  447. switch (paramCount)
  448. {
  449. case 2:
  450. {
  451. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  452. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  453. {
  454. // Get parameter 1 off the stack.
  455. PhysicsCollisionObject::CollisionListener* param1 = ScriptUtil::getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
  456. PhysicsCollisionObject* instance = getInstance(state);
  457. instance->removeCollisionListener(param1);
  458. return 0;
  459. }
  460. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  461. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  462. {
  463. // Get parameter 1 off the stack.
  464. const char* param1 = ScriptUtil::getString(2, false);
  465. PhysicsCollisionObject* instance = getInstance(state);
  466. instance->removeCollisionListener(param1);
  467. return 0;
  468. }
  469. else
  470. {
  471. lua_pushstring(state, "lua_PhysicsCollisionObject_removeCollisionListener - Failed to match the given parameters to a valid function signature.");
  472. lua_error(state);
  473. }
  474. break;
  475. }
  476. case 3:
  477. {
  478. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  479. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  480. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  481. {
  482. // Get parameter 1 off the stack.
  483. PhysicsCollisionObject::CollisionListener* param1 = ScriptUtil::getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
  484. // Get parameter 2 off the stack.
  485. PhysicsCollisionObject* param2 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
  486. PhysicsCollisionObject* instance = getInstance(state);
  487. instance->removeCollisionListener(param1, param2);
  488. return 0;
  489. }
  490. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  491. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  492. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  493. {
  494. // Get parameter 1 off the stack.
  495. const char* param1 = ScriptUtil::getString(2, false);
  496. // Get parameter 2 off the stack.
  497. PhysicsCollisionObject* param2 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
  498. PhysicsCollisionObject* instance = getInstance(state);
  499. instance->removeCollisionListener(param1, param2);
  500. return 0;
  501. }
  502. else
  503. {
  504. lua_pushstring(state, "lua_PhysicsCollisionObject_removeCollisionListener - Failed to match the given parameters to a valid function signature.");
  505. lua_error(state);
  506. }
  507. break;
  508. }
  509. default:
  510. {
  511. lua_pushstring(state, "Invalid number of parameters (expected 2 or 3).");
  512. lua_error(state);
  513. break;
  514. }
  515. }
  516. return 0;
  517. }
  518. int lua_PhysicsCollisionObject_setEnabled(lua_State* state)
  519. {
  520. // Get the number of parameters.
  521. int paramCount = lua_gettop(state);
  522. // Attempt to match the parameters to a valid binding.
  523. switch (paramCount)
  524. {
  525. case 2:
  526. {
  527. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  528. lua_type(state, 2) == LUA_TBOOLEAN)
  529. {
  530. // Get parameter 1 off the stack.
  531. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  532. PhysicsCollisionObject* instance = getInstance(state);
  533. instance->setEnabled(param1);
  534. return 0;
  535. }
  536. else
  537. {
  538. lua_pushstring(state, "lua_PhysicsCollisionObject_setEnabled - Failed to match the given parameters to a valid function signature.");
  539. lua_error(state);
  540. }
  541. break;
  542. }
  543. default:
  544. {
  545. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  546. lua_error(state);
  547. break;
  548. }
  549. }
  550. return 0;
  551. }
  552. }