lua_PhysicsCollisionObject.cpp 22 KB

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