lua_Rectangle.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Rectangle.h"
  4. #include "Base.h"
  5. #include "Rectangle.h"
  6. namespace gameplay
  7. {
  8. void luaRegister_Rectangle()
  9. {
  10. const luaL_Reg lua_members[] =
  11. {
  12. {"bottom", lua_Rectangle_bottom},
  13. {"contains", lua_Rectangle_contains},
  14. {"height", lua_Rectangle_height},
  15. {"inflate", lua_Rectangle_inflate},
  16. {"intersects", lua_Rectangle_intersects},
  17. {"isEmpty", lua_Rectangle_isEmpty},
  18. {"left", lua_Rectangle_left},
  19. {"right", lua_Rectangle_right},
  20. {"set", lua_Rectangle_set},
  21. {"setPosition", lua_Rectangle_setPosition},
  22. {"top", lua_Rectangle_top},
  23. {"width", lua_Rectangle_width},
  24. {"x", lua_Rectangle_x},
  25. {"y", lua_Rectangle_y},
  26. {NULL, NULL}
  27. };
  28. const luaL_Reg lua_statics[] =
  29. {
  30. {"combine", lua_Rectangle_static_combine},
  31. {"empty", lua_Rectangle_static_empty},
  32. {"intersect", lua_Rectangle_static_intersect},
  33. {NULL, NULL}
  34. };
  35. std::vector<std::string> scopePath;
  36. gameplay::ScriptUtil::registerClass("Rectangle", lua_members, lua_Rectangle__init, lua_Rectangle__gc, lua_statics, scopePath);
  37. }
  38. static Rectangle* getInstance(lua_State* state)
  39. {
  40. void* userdata = luaL_checkudata(state, 1, "Rectangle");
  41. luaL_argcheck(state, userdata != NULL, 1, "'Rectangle' expected.");
  42. return (Rectangle*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  43. }
  44. int lua_Rectangle__gc(lua_State* state)
  45. {
  46. // Get the number of parameters.
  47. int paramCount = lua_gettop(state);
  48. // Attempt to match the parameters to a valid binding.
  49. switch (paramCount)
  50. {
  51. case 1:
  52. {
  53. if ((lua_type(state, 1) == LUA_TUSERDATA))
  54. {
  55. void* userdata = luaL_checkudata(state, 1, "Rectangle");
  56. luaL_argcheck(state, userdata != NULL, 1, "'Rectangle' expected.");
  57. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  58. if (object->owns)
  59. {
  60. Rectangle* instance = (Rectangle*)object->instance;
  61. SAFE_DELETE(instance);
  62. }
  63. return 0;
  64. }
  65. lua_pushstring(state, "lua_Rectangle__gc - Failed to match the given parameters to a valid function signature.");
  66. lua_error(state);
  67. break;
  68. }
  69. default:
  70. {
  71. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  72. lua_error(state);
  73. break;
  74. }
  75. }
  76. return 0;
  77. }
  78. int lua_Rectangle__init(lua_State* state)
  79. {
  80. // Get the number of parameters.
  81. int paramCount = lua_gettop(state);
  82. // Attempt to match the parameters to a valid binding.
  83. switch (paramCount)
  84. {
  85. case 0:
  86. {
  87. void* returnPtr = (void*)new Rectangle();
  88. if (returnPtr)
  89. {
  90. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  91. object->instance = returnPtr;
  92. object->owns = true;
  93. luaL_getmetatable(state, "Rectangle");
  94. lua_setmetatable(state, -2);
  95. }
  96. else
  97. {
  98. lua_pushnil(state);
  99. }
  100. return 1;
  101. break;
  102. }
  103. case 1:
  104. {
  105. do
  106. {
  107. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  108. {
  109. // Get parameter 1 off the stack.
  110. bool param1Valid;
  111. gameplay::ScriptUtil::LuaArray<Rectangle> param1 = gameplay::ScriptUtil::getObjectPointer<Rectangle>(1, "Rectangle", true, &param1Valid);
  112. if (!param1Valid)
  113. break;
  114. void* returnPtr = (void*)new Rectangle(*param1);
  115. if (returnPtr)
  116. {
  117. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  118. object->instance = returnPtr;
  119. object->owns = true;
  120. luaL_getmetatable(state, "Rectangle");
  121. lua_setmetatable(state, -2);
  122. }
  123. else
  124. {
  125. lua_pushnil(state);
  126. }
  127. return 1;
  128. }
  129. } while (0);
  130. lua_pushstring(state, "lua_Rectangle__init - Failed to match the given parameters to a valid function signature.");
  131. lua_error(state);
  132. break;
  133. }
  134. case 2:
  135. {
  136. do
  137. {
  138. if (lua_type(state, 1) == LUA_TNUMBER &&
  139. lua_type(state, 2) == LUA_TNUMBER)
  140. {
  141. // Get parameter 1 off the stack.
  142. float param1 = (float)luaL_checknumber(state, 1);
  143. // Get parameter 2 off the stack.
  144. float param2 = (float)luaL_checknumber(state, 2);
  145. void* returnPtr = (void*)new Rectangle(param1, param2);
  146. if (returnPtr)
  147. {
  148. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  149. object->instance = returnPtr;
  150. object->owns = true;
  151. luaL_getmetatable(state, "Rectangle");
  152. lua_setmetatable(state, -2);
  153. }
  154. else
  155. {
  156. lua_pushnil(state);
  157. }
  158. return 1;
  159. }
  160. } while (0);
  161. lua_pushstring(state, "lua_Rectangle__init - Failed to match the given parameters to a valid function signature.");
  162. lua_error(state);
  163. break;
  164. }
  165. case 4:
  166. {
  167. do
  168. {
  169. if (lua_type(state, 1) == LUA_TNUMBER &&
  170. lua_type(state, 2) == LUA_TNUMBER &&
  171. lua_type(state, 3) == LUA_TNUMBER &&
  172. lua_type(state, 4) == LUA_TNUMBER)
  173. {
  174. // Get parameter 1 off the stack.
  175. float param1 = (float)luaL_checknumber(state, 1);
  176. // Get parameter 2 off the stack.
  177. float param2 = (float)luaL_checknumber(state, 2);
  178. // Get parameter 3 off the stack.
  179. float param3 = (float)luaL_checknumber(state, 3);
  180. // Get parameter 4 off the stack.
  181. float param4 = (float)luaL_checknumber(state, 4);
  182. void* returnPtr = (void*)new Rectangle(param1, param2, param3, param4);
  183. if (returnPtr)
  184. {
  185. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  186. object->instance = returnPtr;
  187. object->owns = true;
  188. luaL_getmetatable(state, "Rectangle");
  189. lua_setmetatable(state, -2);
  190. }
  191. else
  192. {
  193. lua_pushnil(state);
  194. }
  195. return 1;
  196. }
  197. } while (0);
  198. lua_pushstring(state, "lua_Rectangle__init - Failed to match the given parameters to a valid function signature.");
  199. lua_error(state);
  200. break;
  201. }
  202. default:
  203. {
  204. lua_pushstring(state, "Invalid number of parameters (expected 0, 1, 2 or 4).");
  205. lua_error(state);
  206. break;
  207. }
  208. }
  209. return 0;
  210. }
  211. int lua_Rectangle_bottom(lua_State* state)
  212. {
  213. // Get the number of parameters.
  214. int paramCount = lua_gettop(state);
  215. // Attempt to match the parameters to a valid binding.
  216. switch (paramCount)
  217. {
  218. case 1:
  219. {
  220. if ((lua_type(state, 1) == LUA_TUSERDATA))
  221. {
  222. Rectangle* instance = getInstance(state);
  223. float result = instance->bottom();
  224. // Push the return value onto the stack.
  225. lua_pushnumber(state, result);
  226. return 1;
  227. }
  228. lua_pushstring(state, "lua_Rectangle_bottom - Failed to match the given parameters to a valid function signature.");
  229. lua_error(state);
  230. break;
  231. }
  232. default:
  233. {
  234. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  235. lua_error(state);
  236. break;
  237. }
  238. }
  239. return 0;
  240. }
  241. int lua_Rectangle_contains(lua_State* state)
  242. {
  243. // Get the number of parameters.
  244. int paramCount = lua_gettop(state);
  245. // Attempt to match the parameters to a valid binding.
  246. switch (paramCount)
  247. {
  248. case 2:
  249. {
  250. do
  251. {
  252. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  253. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  254. {
  255. // Get parameter 1 off the stack.
  256. bool param1Valid;
  257. gameplay::ScriptUtil::LuaArray<Rectangle> param1 = gameplay::ScriptUtil::getObjectPointer<Rectangle>(2, "Rectangle", true, &param1Valid);
  258. if (!param1Valid)
  259. break;
  260. Rectangle* instance = getInstance(state);
  261. bool result = instance->contains(*param1);
  262. // Push the return value onto the stack.
  263. lua_pushboolean(state, result);
  264. return 1;
  265. }
  266. } while (0);
  267. lua_pushstring(state, "lua_Rectangle_contains - Failed to match the given parameters to a valid function signature.");
  268. lua_error(state);
  269. break;
  270. }
  271. case 3:
  272. {
  273. do
  274. {
  275. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  276. lua_type(state, 2) == LUA_TNUMBER &&
  277. lua_type(state, 3) == LUA_TNUMBER)
  278. {
  279. // Get parameter 1 off the stack.
  280. float param1 = (float)luaL_checknumber(state, 2);
  281. // Get parameter 2 off the stack.
  282. float param2 = (float)luaL_checknumber(state, 3);
  283. Rectangle* instance = getInstance(state);
  284. bool result = instance->contains(param1, param2);
  285. // Push the return value onto the stack.
  286. lua_pushboolean(state, result);
  287. return 1;
  288. }
  289. } while (0);
  290. lua_pushstring(state, "lua_Rectangle_contains - Failed to match the given parameters to a valid function signature.");
  291. lua_error(state);
  292. break;
  293. }
  294. case 5:
  295. {
  296. do
  297. {
  298. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  299. lua_type(state, 2) == LUA_TNUMBER &&
  300. lua_type(state, 3) == LUA_TNUMBER &&
  301. lua_type(state, 4) == LUA_TNUMBER &&
  302. lua_type(state, 5) == LUA_TNUMBER)
  303. {
  304. // Get parameter 1 off the stack.
  305. float param1 = (float)luaL_checknumber(state, 2);
  306. // Get parameter 2 off the stack.
  307. float param2 = (float)luaL_checknumber(state, 3);
  308. // Get parameter 3 off the stack.
  309. float param3 = (float)luaL_checknumber(state, 4);
  310. // Get parameter 4 off the stack.
  311. float param4 = (float)luaL_checknumber(state, 5);
  312. Rectangle* instance = getInstance(state);
  313. bool result = instance->contains(param1, param2, param3, param4);
  314. // Push the return value onto the stack.
  315. lua_pushboolean(state, result);
  316. return 1;
  317. }
  318. } while (0);
  319. lua_pushstring(state, "lua_Rectangle_contains - Failed to match the given parameters to a valid function signature.");
  320. lua_error(state);
  321. break;
  322. }
  323. default:
  324. {
  325. lua_pushstring(state, "Invalid number of parameters (expected 2, 3 or 5).");
  326. lua_error(state);
  327. break;
  328. }
  329. }
  330. return 0;
  331. }
  332. int lua_Rectangle_height(lua_State* state)
  333. {
  334. // Validate the number of parameters.
  335. if (lua_gettop(state) > 2)
  336. {
  337. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  338. lua_error(state);
  339. }
  340. Rectangle* instance = getInstance(state);
  341. if (lua_gettop(state) == 2)
  342. {
  343. // Get parameter 2 off the stack.
  344. float param2 = (float)luaL_checknumber(state, 2);
  345. instance->height = param2;
  346. return 0;
  347. }
  348. else
  349. {
  350. float result = instance->height;
  351. // Push the return value onto the stack.
  352. lua_pushnumber(state, result);
  353. return 1;
  354. }
  355. }
  356. int lua_Rectangle_inflate(lua_State* state)
  357. {
  358. // Get the number of parameters.
  359. int paramCount = lua_gettop(state);
  360. // Attempt to match the parameters to a valid binding.
  361. switch (paramCount)
  362. {
  363. case 3:
  364. {
  365. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  366. lua_type(state, 2) == LUA_TNUMBER &&
  367. lua_type(state, 3) == LUA_TNUMBER)
  368. {
  369. // Get parameter 1 off the stack.
  370. float param1 = (float)luaL_checknumber(state, 2);
  371. // Get parameter 2 off the stack.
  372. float param2 = (float)luaL_checknumber(state, 3);
  373. Rectangle* instance = getInstance(state);
  374. instance->inflate(param1, param2);
  375. return 0;
  376. }
  377. lua_pushstring(state, "lua_Rectangle_inflate - Failed to match the given parameters to a valid function signature.");
  378. lua_error(state);
  379. break;
  380. }
  381. default:
  382. {
  383. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  384. lua_error(state);
  385. break;
  386. }
  387. }
  388. return 0;
  389. }
  390. int lua_Rectangle_intersects(lua_State* state)
  391. {
  392. // Get the number of parameters.
  393. int paramCount = lua_gettop(state);
  394. // Attempt to match the parameters to a valid binding.
  395. switch (paramCount)
  396. {
  397. case 2:
  398. {
  399. do
  400. {
  401. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  402. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  403. {
  404. // Get parameter 1 off the stack.
  405. bool param1Valid;
  406. gameplay::ScriptUtil::LuaArray<Rectangle> param1 = gameplay::ScriptUtil::getObjectPointer<Rectangle>(2, "Rectangle", true, &param1Valid);
  407. if (!param1Valid)
  408. break;
  409. Rectangle* instance = getInstance(state);
  410. bool result = instance->intersects(*param1);
  411. // Push the return value onto the stack.
  412. lua_pushboolean(state, result);
  413. return 1;
  414. }
  415. } while (0);
  416. lua_pushstring(state, "lua_Rectangle_intersects - Failed to match the given parameters to a valid function signature.");
  417. lua_error(state);
  418. break;
  419. }
  420. case 5:
  421. {
  422. do
  423. {
  424. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  425. lua_type(state, 2) == LUA_TNUMBER &&
  426. lua_type(state, 3) == LUA_TNUMBER &&
  427. lua_type(state, 4) == LUA_TNUMBER &&
  428. lua_type(state, 5) == LUA_TNUMBER)
  429. {
  430. // Get parameter 1 off the stack.
  431. float param1 = (float)luaL_checknumber(state, 2);
  432. // Get parameter 2 off the stack.
  433. float param2 = (float)luaL_checknumber(state, 3);
  434. // Get parameter 3 off the stack.
  435. float param3 = (float)luaL_checknumber(state, 4);
  436. // Get parameter 4 off the stack.
  437. float param4 = (float)luaL_checknumber(state, 5);
  438. Rectangle* instance = getInstance(state);
  439. bool result = instance->intersects(param1, param2, param3, param4);
  440. // Push the return value onto the stack.
  441. lua_pushboolean(state, result);
  442. return 1;
  443. }
  444. } while (0);
  445. lua_pushstring(state, "lua_Rectangle_intersects - Failed to match the given parameters to a valid function signature.");
  446. lua_error(state);
  447. break;
  448. }
  449. default:
  450. {
  451. lua_pushstring(state, "Invalid number of parameters (expected 2 or 5).");
  452. lua_error(state);
  453. break;
  454. }
  455. }
  456. return 0;
  457. }
  458. int lua_Rectangle_isEmpty(lua_State* state)
  459. {
  460. // Get the number of parameters.
  461. int paramCount = lua_gettop(state);
  462. // Attempt to match the parameters to a valid binding.
  463. switch (paramCount)
  464. {
  465. case 1:
  466. {
  467. if ((lua_type(state, 1) == LUA_TUSERDATA))
  468. {
  469. Rectangle* instance = getInstance(state);
  470. bool result = instance->isEmpty();
  471. // Push the return value onto the stack.
  472. lua_pushboolean(state, result);
  473. return 1;
  474. }
  475. lua_pushstring(state, "lua_Rectangle_isEmpty - Failed to match the given parameters to a valid function signature.");
  476. lua_error(state);
  477. break;
  478. }
  479. default:
  480. {
  481. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  482. lua_error(state);
  483. break;
  484. }
  485. }
  486. return 0;
  487. }
  488. int lua_Rectangle_left(lua_State* state)
  489. {
  490. // Get the number of parameters.
  491. int paramCount = lua_gettop(state);
  492. // Attempt to match the parameters to a valid binding.
  493. switch (paramCount)
  494. {
  495. case 1:
  496. {
  497. if ((lua_type(state, 1) == LUA_TUSERDATA))
  498. {
  499. Rectangle* instance = getInstance(state);
  500. float result = instance->left();
  501. // Push the return value onto the stack.
  502. lua_pushnumber(state, result);
  503. return 1;
  504. }
  505. lua_pushstring(state, "lua_Rectangle_left - Failed to match the given parameters to a valid function signature.");
  506. lua_error(state);
  507. break;
  508. }
  509. default:
  510. {
  511. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  512. lua_error(state);
  513. break;
  514. }
  515. }
  516. return 0;
  517. }
  518. int lua_Rectangle_right(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 1:
  526. {
  527. if ((lua_type(state, 1) == LUA_TUSERDATA))
  528. {
  529. Rectangle* instance = getInstance(state);
  530. float result = instance->right();
  531. // Push the return value onto the stack.
  532. lua_pushnumber(state, result);
  533. return 1;
  534. }
  535. lua_pushstring(state, "lua_Rectangle_right - Failed to match the given parameters to a valid function signature.");
  536. lua_error(state);
  537. break;
  538. }
  539. default:
  540. {
  541. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  542. lua_error(state);
  543. break;
  544. }
  545. }
  546. return 0;
  547. }
  548. int lua_Rectangle_set(lua_State* state)
  549. {
  550. // Get the number of parameters.
  551. int paramCount = lua_gettop(state);
  552. // Attempt to match the parameters to a valid binding.
  553. switch (paramCount)
  554. {
  555. case 2:
  556. {
  557. do
  558. {
  559. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  560. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  561. {
  562. // Get parameter 1 off the stack.
  563. bool param1Valid;
  564. gameplay::ScriptUtil::LuaArray<Rectangle> param1 = gameplay::ScriptUtil::getObjectPointer<Rectangle>(2, "Rectangle", true, &param1Valid);
  565. if (!param1Valid)
  566. break;
  567. Rectangle* instance = getInstance(state);
  568. instance->set(*param1);
  569. return 0;
  570. }
  571. } while (0);
  572. lua_pushstring(state, "lua_Rectangle_set - Failed to match the given parameters to a valid function signature.");
  573. lua_error(state);
  574. break;
  575. }
  576. case 5:
  577. {
  578. do
  579. {
  580. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  581. lua_type(state, 2) == LUA_TNUMBER &&
  582. lua_type(state, 3) == LUA_TNUMBER &&
  583. lua_type(state, 4) == LUA_TNUMBER &&
  584. lua_type(state, 5) == LUA_TNUMBER)
  585. {
  586. // Get parameter 1 off the stack.
  587. float param1 = (float)luaL_checknumber(state, 2);
  588. // Get parameter 2 off the stack.
  589. float param2 = (float)luaL_checknumber(state, 3);
  590. // Get parameter 3 off the stack.
  591. float param3 = (float)luaL_checknumber(state, 4);
  592. // Get parameter 4 off the stack.
  593. float param4 = (float)luaL_checknumber(state, 5);
  594. Rectangle* instance = getInstance(state);
  595. instance->set(param1, param2, param3, param4);
  596. return 0;
  597. }
  598. } while (0);
  599. lua_pushstring(state, "lua_Rectangle_set - Failed to match the given parameters to a valid function signature.");
  600. lua_error(state);
  601. break;
  602. }
  603. default:
  604. {
  605. lua_pushstring(state, "Invalid number of parameters (expected 2 or 5).");
  606. lua_error(state);
  607. break;
  608. }
  609. }
  610. return 0;
  611. }
  612. int lua_Rectangle_setPosition(lua_State* state)
  613. {
  614. // Get the number of parameters.
  615. int paramCount = lua_gettop(state);
  616. // Attempt to match the parameters to a valid binding.
  617. switch (paramCount)
  618. {
  619. case 3:
  620. {
  621. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  622. lua_type(state, 2) == LUA_TNUMBER &&
  623. lua_type(state, 3) == LUA_TNUMBER)
  624. {
  625. // Get parameter 1 off the stack.
  626. float param1 = (float)luaL_checknumber(state, 2);
  627. // Get parameter 2 off the stack.
  628. float param2 = (float)luaL_checknumber(state, 3);
  629. Rectangle* instance = getInstance(state);
  630. instance->setPosition(param1, param2);
  631. return 0;
  632. }
  633. lua_pushstring(state, "lua_Rectangle_setPosition - Failed to match the given parameters to a valid function signature.");
  634. lua_error(state);
  635. break;
  636. }
  637. default:
  638. {
  639. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  640. lua_error(state);
  641. break;
  642. }
  643. }
  644. return 0;
  645. }
  646. int lua_Rectangle_static_combine(lua_State* state)
  647. {
  648. // Get the number of parameters.
  649. int paramCount = lua_gettop(state);
  650. // Attempt to match the parameters to a valid binding.
  651. switch (paramCount)
  652. {
  653. case 3:
  654. {
  655. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  656. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  657. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  658. {
  659. // Get parameter 1 off the stack.
  660. bool param1Valid;
  661. gameplay::ScriptUtil::LuaArray<Rectangle> param1 = gameplay::ScriptUtil::getObjectPointer<Rectangle>(1, "Rectangle", true, &param1Valid);
  662. if (!param1Valid)
  663. {
  664. lua_pushstring(state, "Failed to convert parameter 1 to type 'Rectangle'.");
  665. lua_error(state);
  666. }
  667. // Get parameter 2 off the stack.
  668. bool param2Valid;
  669. gameplay::ScriptUtil::LuaArray<Rectangle> param2 = gameplay::ScriptUtil::getObjectPointer<Rectangle>(2, "Rectangle", true, &param2Valid);
  670. if (!param2Valid)
  671. {
  672. lua_pushstring(state, "Failed to convert parameter 2 to type 'Rectangle'.");
  673. lua_error(state);
  674. }
  675. // Get parameter 3 off the stack.
  676. bool param3Valid;
  677. gameplay::ScriptUtil::LuaArray<Rectangle> param3 = gameplay::ScriptUtil::getObjectPointer<Rectangle>(3, "Rectangle", false, &param3Valid);
  678. if (!param3Valid)
  679. {
  680. lua_pushstring(state, "Failed to convert parameter 3 to type 'Rectangle'.");
  681. lua_error(state);
  682. }
  683. Rectangle::combine(*param1, *param2, param3);
  684. return 0;
  685. }
  686. lua_pushstring(state, "lua_Rectangle_static_combine - Failed to match the given parameters to a valid function signature.");
  687. lua_error(state);
  688. break;
  689. }
  690. default:
  691. {
  692. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  693. lua_error(state);
  694. break;
  695. }
  696. }
  697. return 0;
  698. }
  699. int lua_Rectangle_static_empty(lua_State* state)
  700. {
  701. // Get the number of parameters.
  702. int paramCount = lua_gettop(state);
  703. // Attempt to match the parameters to a valid binding.
  704. switch (paramCount)
  705. {
  706. case 0:
  707. {
  708. void* returnPtr = (void*)&(Rectangle::empty());
  709. if (returnPtr)
  710. {
  711. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  712. object->instance = returnPtr;
  713. object->owns = false;
  714. luaL_getmetatable(state, "Rectangle");
  715. lua_setmetatable(state, -2);
  716. }
  717. else
  718. {
  719. lua_pushnil(state);
  720. }
  721. return 1;
  722. break;
  723. }
  724. default:
  725. {
  726. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  727. lua_error(state);
  728. break;
  729. }
  730. }
  731. return 0;
  732. }
  733. int lua_Rectangle_static_intersect(lua_State* state)
  734. {
  735. // Get the number of parameters.
  736. int paramCount = lua_gettop(state);
  737. // Attempt to match the parameters to a valid binding.
  738. switch (paramCount)
  739. {
  740. case 3:
  741. {
  742. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  743. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  744. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  745. {
  746. // Get parameter 1 off the stack.
  747. bool param1Valid;
  748. gameplay::ScriptUtil::LuaArray<Rectangle> param1 = gameplay::ScriptUtil::getObjectPointer<Rectangle>(1, "Rectangle", true, &param1Valid);
  749. if (!param1Valid)
  750. {
  751. lua_pushstring(state, "Failed to convert parameter 1 to type 'Rectangle'.");
  752. lua_error(state);
  753. }
  754. // Get parameter 2 off the stack.
  755. bool param2Valid;
  756. gameplay::ScriptUtil::LuaArray<Rectangle> param2 = gameplay::ScriptUtil::getObjectPointer<Rectangle>(2, "Rectangle", true, &param2Valid);
  757. if (!param2Valid)
  758. {
  759. lua_pushstring(state, "Failed to convert parameter 2 to type 'Rectangle'.");
  760. lua_error(state);
  761. }
  762. // Get parameter 3 off the stack.
  763. bool param3Valid;
  764. gameplay::ScriptUtil::LuaArray<Rectangle> param3 = gameplay::ScriptUtil::getObjectPointer<Rectangle>(3, "Rectangle", false, &param3Valid);
  765. if (!param3Valid)
  766. {
  767. lua_pushstring(state, "Failed to convert parameter 3 to type 'Rectangle'.");
  768. lua_error(state);
  769. }
  770. bool result = Rectangle::intersect(*param1, *param2, param3);
  771. // Push the return value onto the stack.
  772. lua_pushboolean(state, result);
  773. return 1;
  774. }
  775. lua_pushstring(state, "lua_Rectangle_static_intersect - Failed to match the given parameters to a valid function signature.");
  776. lua_error(state);
  777. break;
  778. }
  779. default:
  780. {
  781. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  782. lua_error(state);
  783. break;
  784. }
  785. }
  786. return 0;
  787. }
  788. int lua_Rectangle_top(lua_State* state)
  789. {
  790. // Get the number of parameters.
  791. int paramCount = lua_gettop(state);
  792. // Attempt to match the parameters to a valid binding.
  793. switch (paramCount)
  794. {
  795. case 1:
  796. {
  797. if ((lua_type(state, 1) == LUA_TUSERDATA))
  798. {
  799. Rectangle* instance = getInstance(state);
  800. float result = instance->top();
  801. // Push the return value onto the stack.
  802. lua_pushnumber(state, result);
  803. return 1;
  804. }
  805. lua_pushstring(state, "lua_Rectangle_top - Failed to match the given parameters to a valid function signature.");
  806. lua_error(state);
  807. break;
  808. }
  809. default:
  810. {
  811. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  812. lua_error(state);
  813. break;
  814. }
  815. }
  816. return 0;
  817. }
  818. int lua_Rectangle_width(lua_State* state)
  819. {
  820. // Validate the number of parameters.
  821. if (lua_gettop(state) > 2)
  822. {
  823. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  824. lua_error(state);
  825. }
  826. Rectangle* instance = getInstance(state);
  827. if (lua_gettop(state) == 2)
  828. {
  829. // Get parameter 2 off the stack.
  830. float param2 = (float)luaL_checknumber(state, 2);
  831. instance->width = param2;
  832. return 0;
  833. }
  834. else
  835. {
  836. float result = instance->width;
  837. // Push the return value onto the stack.
  838. lua_pushnumber(state, result);
  839. return 1;
  840. }
  841. }
  842. int lua_Rectangle_x(lua_State* state)
  843. {
  844. // Validate the number of parameters.
  845. if (lua_gettop(state) > 2)
  846. {
  847. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  848. lua_error(state);
  849. }
  850. Rectangle* instance = getInstance(state);
  851. if (lua_gettop(state) == 2)
  852. {
  853. // Get parameter 2 off the stack.
  854. float param2 = (float)luaL_checknumber(state, 2);
  855. instance->x = param2;
  856. return 0;
  857. }
  858. else
  859. {
  860. float result = instance->x;
  861. // Push the return value onto the stack.
  862. lua_pushnumber(state, result);
  863. return 1;
  864. }
  865. }
  866. int lua_Rectangle_y(lua_State* state)
  867. {
  868. // Validate the number of parameters.
  869. if (lua_gettop(state) > 2)
  870. {
  871. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  872. lua_error(state);
  873. }
  874. Rectangle* instance = getInstance(state);
  875. if (lua_gettop(state) == 2)
  876. {
  877. // Get parameter 2 off the stack.
  878. float param2 = (float)luaL_checknumber(state, 2);
  879. instance->y = param2;
  880. return 0;
  881. }
  882. else
  883. {
  884. float result = instance->y;
  885. // Push the return value onto the stack.
  886. lua_pushnumber(state, result);
  887. return 1;
  888. }
  889. }
  890. }