lua_PhysicsCollisionObject.cpp 19 KB

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