lua_Rectangle.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  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. lua_pushstring(state, "lua_Rectangle__gc - Failed to match the given parameters to a valid function signature.");
  65. lua_error(state);
  66. break;
  67. }
  68. default:
  69. {
  70. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  71. lua_error(state);
  72. break;
  73. }
  74. }
  75. return 0;
  76. }
  77. int lua_Rectangle__init(lua_State* state)
  78. {
  79. // Get the number of parameters.
  80. int paramCount = lua_gettop(state);
  81. // Attempt to match the parameters to a valid binding.
  82. switch (paramCount)
  83. {
  84. case 0:
  85. {
  86. void* returnPtr = (void*)new Rectangle();
  87. if (returnPtr)
  88. {
  89. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  90. object->instance = returnPtr;
  91. object->owns = true;
  92. luaL_getmetatable(state, "Rectangle");
  93. lua_setmetatable(state, -2);
  94. }
  95. else
  96. {
  97. lua_pushnil(state);
  98. }
  99. return 1;
  100. break;
  101. }
  102. case 1:
  103. {
  104. do
  105. {
  106. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  107. {
  108. // Get parameter 1 off the stack.
  109. bool param1Valid;
  110. ScriptUtil::LuaArray<Rectangle> param1 = ScriptUtil::getObjectPointer<Rectangle>(1, "Rectangle", true, &param1Valid);
  111. if (!param1Valid)
  112. break;
  113. void* returnPtr = (void*)new Rectangle(*param1);
  114. if (returnPtr)
  115. {
  116. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  117. object->instance = returnPtr;
  118. object->owns = true;
  119. luaL_getmetatable(state, "Rectangle");
  120. lua_setmetatable(state, -2);
  121. }
  122. else
  123. {
  124. lua_pushnil(state);
  125. }
  126. return 1;
  127. }
  128. } while (0);
  129. lua_pushstring(state, "lua_Rectangle__init - Failed to match the given parameters to a valid function signature.");
  130. lua_error(state);
  131. break;
  132. }
  133. case 2:
  134. {
  135. do
  136. {
  137. if (lua_type(state, 1) == LUA_TNUMBER &&
  138. lua_type(state, 2) == LUA_TNUMBER)
  139. {
  140. // Get parameter 1 off the stack.
  141. float param1 = (float)luaL_checknumber(state, 1);
  142. // Get parameter 2 off the stack.
  143. float param2 = (float)luaL_checknumber(state, 2);
  144. void* returnPtr = (void*)new Rectangle(param1, param2);
  145. if (returnPtr)
  146. {
  147. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  148. object->instance = returnPtr;
  149. object->owns = true;
  150. luaL_getmetatable(state, "Rectangle");
  151. lua_setmetatable(state, -2);
  152. }
  153. else
  154. {
  155. lua_pushnil(state);
  156. }
  157. return 1;
  158. }
  159. } while (0);
  160. lua_pushstring(state, "lua_Rectangle__init - Failed to match the given parameters to a valid function signature.");
  161. lua_error(state);
  162. break;
  163. }
  164. case 4:
  165. {
  166. do
  167. {
  168. if (lua_type(state, 1) == LUA_TNUMBER &&
  169. lua_type(state, 2) == LUA_TNUMBER &&
  170. lua_type(state, 3) == LUA_TNUMBER &&
  171. lua_type(state, 4) == LUA_TNUMBER)
  172. {
  173. // Get parameter 1 off the stack.
  174. float param1 = (float)luaL_checknumber(state, 1);
  175. // Get parameter 2 off the stack.
  176. float param2 = (float)luaL_checknumber(state, 2);
  177. // Get parameter 3 off the stack.
  178. float param3 = (float)luaL_checknumber(state, 3);
  179. // Get parameter 4 off the stack.
  180. float param4 = (float)luaL_checknumber(state, 4);
  181. void* returnPtr = (void*)new Rectangle(param1, param2, param3, param4);
  182. if (returnPtr)
  183. {
  184. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  185. object->instance = returnPtr;
  186. object->owns = true;
  187. luaL_getmetatable(state, "Rectangle");
  188. lua_setmetatable(state, -2);
  189. }
  190. else
  191. {
  192. lua_pushnil(state);
  193. }
  194. return 1;
  195. }
  196. } while (0);
  197. lua_pushstring(state, "lua_Rectangle__init - Failed to match the given parameters to a valid function signature.");
  198. lua_error(state);
  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. lua_pushstring(state, "lua_Rectangle_bottom - Failed to match the given parameters to a valid function signature.");
  228. lua_error(state);
  229. break;
  230. }
  231. default:
  232. {
  233. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  234. lua_error(state);
  235. break;
  236. }
  237. }
  238. return 0;
  239. }
  240. int lua_Rectangle_contains(lua_State* state)
  241. {
  242. // Get the number of parameters.
  243. int paramCount = lua_gettop(state);
  244. // Attempt to match the parameters to a valid binding.
  245. switch (paramCount)
  246. {
  247. case 2:
  248. {
  249. do
  250. {
  251. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  252. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  253. {
  254. // Get parameter 1 off the stack.
  255. bool param1Valid;
  256. ScriptUtil::LuaArray<Rectangle> param1 = ScriptUtil::getObjectPointer<Rectangle>(2, "Rectangle", true, &param1Valid);
  257. if (!param1Valid)
  258. break;
  259. Rectangle* instance = getInstance(state);
  260. bool result = instance->contains(*param1);
  261. // Push the return value onto the stack.
  262. lua_pushboolean(state, result);
  263. return 1;
  264. }
  265. } while (0);
  266. lua_pushstring(state, "lua_Rectangle_contains - Failed to match the given parameters to a valid function signature.");
  267. lua_error(state);
  268. break;
  269. }
  270. case 3:
  271. {
  272. do
  273. {
  274. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  275. lua_type(state, 2) == LUA_TNUMBER &&
  276. lua_type(state, 3) == LUA_TNUMBER)
  277. {
  278. // Get parameter 1 off the stack.
  279. float param1 = (float)luaL_checknumber(state, 2);
  280. // Get parameter 2 off the stack.
  281. float param2 = (float)luaL_checknumber(state, 3);
  282. Rectangle* instance = getInstance(state);
  283. bool result = instance->contains(param1, param2);
  284. // Push the return value onto the stack.
  285. lua_pushboolean(state, result);
  286. return 1;
  287. }
  288. } while (0);
  289. lua_pushstring(state, "lua_Rectangle_contains - Failed to match the given parameters to a valid function signature.");
  290. lua_error(state);
  291. break;
  292. }
  293. case 5:
  294. {
  295. do
  296. {
  297. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  298. lua_type(state, 2) == LUA_TNUMBER &&
  299. lua_type(state, 3) == LUA_TNUMBER &&
  300. lua_type(state, 4) == LUA_TNUMBER &&
  301. lua_type(state, 5) == LUA_TNUMBER)
  302. {
  303. // Get parameter 1 off the stack.
  304. float param1 = (float)luaL_checknumber(state, 2);
  305. // Get parameter 2 off the stack.
  306. float param2 = (float)luaL_checknumber(state, 3);
  307. // Get parameter 3 off the stack.
  308. float param3 = (float)luaL_checknumber(state, 4);
  309. // Get parameter 4 off the stack.
  310. float param4 = (float)luaL_checknumber(state, 5);
  311. Rectangle* instance = getInstance(state);
  312. bool result = instance->contains(param1, param2, param3, param4);
  313. // Push the return value onto the stack.
  314. lua_pushboolean(state, result);
  315. return 1;
  316. }
  317. } while (0);
  318. lua_pushstring(state, "lua_Rectangle_contains - Failed to match the given parameters to a valid function signature.");
  319. lua_error(state);
  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. lua_pushstring(state, "lua_Rectangle_inflate - Failed to match the given parameters to a valid function signature.");
  377. lua_error(state);
  378. break;
  379. }
  380. default:
  381. {
  382. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  383. lua_error(state);
  384. break;
  385. }
  386. }
  387. return 0;
  388. }
  389. int lua_Rectangle_intersects(lua_State* state)
  390. {
  391. // Get the number of parameters.
  392. int paramCount = lua_gettop(state);
  393. // Attempt to match the parameters to a valid binding.
  394. switch (paramCount)
  395. {
  396. case 2:
  397. {
  398. do
  399. {
  400. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  401. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  402. {
  403. // Get parameter 1 off the stack.
  404. bool param1Valid;
  405. ScriptUtil::LuaArray<Rectangle> param1 = ScriptUtil::getObjectPointer<Rectangle>(2, "Rectangle", true, &param1Valid);
  406. if (!param1Valid)
  407. break;
  408. Rectangle* instance = getInstance(state);
  409. bool result = instance->intersects(*param1);
  410. // Push the return value onto the stack.
  411. lua_pushboolean(state, result);
  412. return 1;
  413. }
  414. } while (0);
  415. lua_pushstring(state, "lua_Rectangle_intersects - Failed to match the given parameters to a valid function signature.");
  416. lua_error(state);
  417. break;
  418. }
  419. case 5:
  420. {
  421. do
  422. {
  423. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  424. lua_type(state, 2) == LUA_TNUMBER &&
  425. lua_type(state, 3) == LUA_TNUMBER &&
  426. lua_type(state, 4) == LUA_TNUMBER &&
  427. lua_type(state, 5) == LUA_TNUMBER)
  428. {
  429. // Get parameter 1 off the stack.
  430. float param1 = (float)luaL_checknumber(state, 2);
  431. // Get parameter 2 off the stack.
  432. float param2 = (float)luaL_checknumber(state, 3);
  433. // Get parameter 3 off the stack.
  434. float param3 = (float)luaL_checknumber(state, 4);
  435. // Get parameter 4 off the stack.
  436. float param4 = (float)luaL_checknumber(state, 5);
  437. Rectangle* instance = getInstance(state);
  438. bool result = instance->intersects(param1, param2, param3, param4);
  439. // Push the return value onto the stack.
  440. lua_pushboolean(state, result);
  441. return 1;
  442. }
  443. } while (0);
  444. lua_pushstring(state, "lua_Rectangle_intersects - Failed to match the given parameters to a valid function signature.");
  445. lua_error(state);
  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. lua_pushstring(state, "lua_Rectangle_isEmpty - Failed to match the given parameters to a valid function signature.");
  475. lua_error(state);
  476. break;
  477. }
  478. default:
  479. {
  480. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  481. lua_error(state);
  482. break;
  483. }
  484. }
  485. return 0;
  486. }
  487. int lua_Rectangle_left(lua_State* state)
  488. {
  489. // Get the number of parameters.
  490. int paramCount = lua_gettop(state);
  491. // Attempt to match the parameters to a valid binding.
  492. switch (paramCount)
  493. {
  494. case 1:
  495. {
  496. if ((lua_type(state, 1) == LUA_TUSERDATA))
  497. {
  498. Rectangle* instance = getInstance(state);
  499. float result = instance->left();
  500. // Push the return value onto the stack.
  501. lua_pushnumber(state, result);
  502. return 1;
  503. }
  504. lua_pushstring(state, "lua_Rectangle_left - Failed to match the given parameters to a valid function signature.");
  505. lua_error(state);
  506. break;
  507. }
  508. default:
  509. {
  510. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  511. lua_error(state);
  512. break;
  513. }
  514. }
  515. return 0;
  516. }
  517. int lua_Rectangle_right(lua_State* state)
  518. {
  519. // Get the number of parameters.
  520. int paramCount = lua_gettop(state);
  521. // Attempt to match the parameters to a valid binding.
  522. switch (paramCount)
  523. {
  524. case 1:
  525. {
  526. if ((lua_type(state, 1) == LUA_TUSERDATA))
  527. {
  528. Rectangle* instance = getInstance(state);
  529. float result = instance->right();
  530. // Push the return value onto the stack.
  531. lua_pushnumber(state, result);
  532. return 1;
  533. }
  534. lua_pushstring(state, "lua_Rectangle_right - Failed to match the given parameters to a valid function signature.");
  535. lua_error(state);
  536. break;
  537. }
  538. default:
  539. {
  540. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  541. lua_error(state);
  542. break;
  543. }
  544. }
  545. return 0;
  546. }
  547. int lua_Rectangle_set(lua_State* state)
  548. {
  549. // Get the number of parameters.
  550. int paramCount = lua_gettop(state);
  551. // Attempt to match the parameters to a valid binding.
  552. switch (paramCount)
  553. {
  554. case 2:
  555. {
  556. do
  557. {
  558. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  559. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  560. {
  561. // Get parameter 1 off the stack.
  562. bool param1Valid;
  563. ScriptUtil::LuaArray<Rectangle> param1 = ScriptUtil::getObjectPointer<Rectangle>(2, "Rectangle", true, &param1Valid);
  564. if (!param1Valid)
  565. break;
  566. Rectangle* instance = getInstance(state);
  567. instance->set(*param1);
  568. return 0;
  569. }
  570. } while (0);
  571. lua_pushstring(state, "lua_Rectangle_set - Failed to match the given parameters to a valid function signature.");
  572. lua_error(state);
  573. break;
  574. }
  575. case 5:
  576. {
  577. do
  578. {
  579. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  580. lua_type(state, 2) == LUA_TNUMBER &&
  581. lua_type(state, 3) == LUA_TNUMBER &&
  582. lua_type(state, 4) == LUA_TNUMBER &&
  583. lua_type(state, 5) == LUA_TNUMBER)
  584. {
  585. // Get parameter 1 off the stack.
  586. float param1 = (float)luaL_checknumber(state, 2);
  587. // Get parameter 2 off the stack.
  588. float param2 = (float)luaL_checknumber(state, 3);
  589. // Get parameter 3 off the stack.
  590. float param3 = (float)luaL_checknumber(state, 4);
  591. // Get parameter 4 off the stack.
  592. float param4 = (float)luaL_checknumber(state, 5);
  593. Rectangle* instance = getInstance(state);
  594. instance->set(param1, param2, param3, param4);
  595. return 0;
  596. }
  597. } while (0);
  598. lua_pushstring(state, "lua_Rectangle_set - Failed to match the given parameters to a valid function signature.");
  599. lua_error(state);
  600. break;
  601. }
  602. default:
  603. {
  604. lua_pushstring(state, "Invalid number of parameters (expected 2 or 5).");
  605. lua_error(state);
  606. break;
  607. }
  608. }
  609. return 0;
  610. }
  611. int lua_Rectangle_setPosition(lua_State* state)
  612. {
  613. // Get the number of parameters.
  614. int paramCount = lua_gettop(state);
  615. // Attempt to match the parameters to a valid binding.
  616. switch (paramCount)
  617. {
  618. case 3:
  619. {
  620. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  621. lua_type(state, 2) == LUA_TNUMBER &&
  622. lua_type(state, 3) == LUA_TNUMBER)
  623. {
  624. // Get parameter 1 off the stack.
  625. float param1 = (float)luaL_checknumber(state, 2);
  626. // Get parameter 2 off the stack.
  627. float param2 = (float)luaL_checknumber(state, 3);
  628. Rectangle* instance = getInstance(state);
  629. instance->setPosition(param1, param2);
  630. return 0;
  631. }
  632. lua_pushstring(state, "lua_Rectangle_setPosition - Failed to match the given parameters to a valid function signature.");
  633. lua_error(state);
  634. break;
  635. }
  636. default:
  637. {
  638. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  639. lua_error(state);
  640. break;
  641. }
  642. }
  643. return 0;
  644. }
  645. int lua_Rectangle_static_combine(lua_State* state)
  646. {
  647. // Get the number of parameters.
  648. int paramCount = lua_gettop(state);
  649. // Attempt to match the parameters to a valid binding.
  650. switch (paramCount)
  651. {
  652. case 3:
  653. {
  654. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  655. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  656. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  657. {
  658. // Get parameter 1 off the stack.
  659. bool param1Valid;
  660. ScriptUtil::LuaArray<Rectangle> param1 = ScriptUtil::getObjectPointer<Rectangle>(1, "Rectangle", true, &param1Valid);
  661. if (!param1Valid)
  662. {
  663. lua_pushstring(state, "Failed to convert parameter 1 to type 'Rectangle'.");
  664. lua_error(state);
  665. }
  666. // Get parameter 2 off the stack.
  667. bool param2Valid;
  668. ScriptUtil::LuaArray<Rectangle> param2 = ScriptUtil::getObjectPointer<Rectangle>(2, "Rectangle", true, &param2Valid);
  669. if (!param2Valid)
  670. {
  671. lua_pushstring(state, "Failed to convert parameter 2 to type 'Rectangle'.");
  672. lua_error(state);
  673. }
  674. // Get parameter 3 off the stack.
  675. bool param3Valid;
  676. ScriptUtil::LuaArray<Rectangle> param3 = ScriptUtil::getObjectPointer<Rectangle>(3, "Rectangle", false, &param3Valid);
  677. if (!param3Valid)
  678. {
  679. lua_pushstring(state, "Failed to convert parameter 3 to type 'Rectangle'.");
  680. lua_error(state);
  681. }
  682. Rectangle::combine(*param1, *param2, param3);
  683. return 0;
  684. }
  685. lua_pushstring(state, "lua_Rectangle_static_combine - Failed to match the given parameters to a valid function signature.");
  686. lua_error(state);
  687. break;
  688. }
  689. default:
  690. {
  691. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  692. lua_error(state);
  693. break;
  694. }
  695. }
  696. return 0;
  697. }
  698. int lua_Rectangle_static_empty(lua_State* state)
  699. {
  700. // Get the number of parameters.
  701. int paramCount = lua_gettop(state);
  702. // Attempt to match the parameters to a valid binding.
  703. switch (paramCount)
  704. {
  705. case 0:
  706. {
  707. void* returnPtr = (void*)&(Rectangle::empty());
  708. if (returnPtr)
  709. {
  710. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  711. object->instance = returnPtr;
  712. object->owns = false;
  713. luaL_getmetatable(state, "Rectangle");
  714. lua_setmetatable(state, -2);
  715. }
  716. else
  717. {
  718. lua_pushnil(state);
  719. }
  720. return 1;
  721. break;
  722. }
  723. default:
  724. {
  725. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  726. lua_error(state);
  727. break;
  728. }
  729. }
  730. return 0;
  731. }
  732. int lua_Rectangle_top(lua_State* state)
  733. {
  734. // Get the number of parameters.
  735. int paramCount = lua_gettop(state);
  736. // Attempt to match the parameters to a valid binding.
  737. switch (paramCount)
  738. {
  739. case 1:
  740. {
  741. if ((lua_type(state, 1) == LUA_TUSERDATA))
  742. {
  743. Rectangle* instance = getInstance(state);
  744. float result = instance->top();
  745. // Push the return value onto the stack.
  746. lua_pushnumber(state, result);
  747. return 1;
  748. }
  749. lua_pushstring(state, "lua_Rectangle_top - Failed to match the given parameters to a valid function signature.");
  750. lua_error(state);
  751. break;
  752. }
  753. default:
  754. {
  755. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  756. lua_error(state);
  757. break;
  758. }
  759. }
  760. return 0;
  761. }
  762. int lua_Rectangle_width(lua_State* state)
  763. {
  764. // Validate the number of parameters.
  765. if (lua_gettop(state) > 2)
  766. {
  767. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  768. lua_error(state);
  769. }
  770. Rectangle* instance = getInstance(state);
  771. if (lua_gettop(state) == 2)
  772. {
  773. // Get parameter 2 off the stack.
  774. float param2 = (float)luaL_checknumber(state, 2);
  775. instance->width = param2;
  776. return 0;
  777. }
  778. else
  779. {
  780. float result = instance->width;
  781. // Push the return value onto the stack.
  782. lua_pushnumber(state, result);
  783. return 1;
  784. }
  785. }
  786. int lua_Rectangle_x(lua_State* state)
  787. {
  788. // Validate the number of parameters.
  789. if (lua_gettop(state) > 2)
  790. {
  791. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  792. lua_error(state);
  793. }
  794. Rectangle* instance = getInstance(state);
  795. if (lua_gettop(state) == 2)
  796. {
  797. // Get parameter 2 off the stack.
  798. float param2 = (float)luaL_checknumber(state, 2);
  799. instance->x = param2;
  800. return 0;
  801. }
  802. else
  803. {
  804. float result = instance->x;
  805. // Push the return value onto the stack.
  806. lua_pushnumber(state, result);
  807. return 1;
  808. }
  809. }
  810. int lua_Rectangle_y(lua_State* state)
  811. {
  812. // Validate the number of parameters.
  813. if (lua_gettop(state) > 2)
  814. {
  815. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  816. lua_error(state);
  817. }
  818. Rectangle* instance = getInstance(state);
  819. if (lua_gettop(state) == 2)
  820. {
  821. // Get parameter 2 off the stack.
  822. float param2 = (float)luaL_checknumber(state, 2);
  823. instance->y = param2;
  824. return 0;
  825. }
  826. else
  827. {
  828. float result = instance->y;
  829. // Push the return value onto the stack.
  830. lua_pushnumber(state, result);
  831. return 1;
  832. }
  833. }
  834. }