lua_Rectangle.cpp 29 KB

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