lua_Game.cpp 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Game.h"
  4. #include "Base.h"
  5. #include "FileSystem.h"
  6. #include "FrameBuffer.h"
  7. #include "Game.h"
  8. #include "Platform.h"
  9. #include "RenderState.h"
  10. #include "SceneLoader.h"
  11. #include "lua_GameClearFlags.h"
  12. #include "lua_GameState.h"
  13. #include "lua_GamepadGamepadEvent.h"
  14. #include "lua_KeyboardKeyEvent.h"
  15. #include "lua_MouseMouseEvent.h"
  16. #include "lua_TouchTouchEvent.h"
  17. namespace gameplay
  18. {
  19. void luaRegister_Game()
  20. {
  21. const luaL_Reg lua_members[] =
  22. {
  23. {"clear", lua_Game_clear},
  24. {"displayKeyboard", lua_Game_displayKeyboard},
  25. {"exit", lua_Game_exit},
  26. {"frame", lua_Game_frame},
  27. {"gamepadEvent", lua_Game_gamepadEvent},
  28. {"getAIController", lua_Game_getAIController},
  29. {"getAccelerometerValues", lua_Game_getAccelerometerValues},
  30. {"getAnimationController", lua_Game_getAnimationController},
  31. {"getAudioController", lua_Game_getAudioController},
  32. {"getAudioListener", lua_Game_getAudioListener},
  33. {"getConfig", lua_Game_getConfig},
  34. {"getFrameRate", lua_Game_getFrameRate},
  35. {"getGamepad", lua_Game_getGamepad},
  36. {"getGamepadCount", lua_Game_getGamepadCount},
  37. {"getHeight", lua_Game_getHeight},
  38. {"getPhysicsController", lua_Game_getPhysicsController},
  39. {"getScriptController", lua_Game_getScriptController},
  40. {"getState", lua_Game_getState},
  41. {"getViewport", lua_Game_getViewport},
  42. {"getWidth", lua_Game_getWidth},
  43. {"hasMouse", lua_Game_hasMouse},
  44. {"isCursorVisible", lua_Game_isCursorVisible},
  45. {"isInitialized", lua_Game_isInitialized},
  46. {"isMouseCaptured", lua_Game_isMouseCaptured},
  47. {"isMultiTouch", lua_Game_isMultiTouch},
  48. {"keyEvent", lua_Game_keyEvent},
  49. {"menuEvent", lua_Game_menuEvent},
  50. {"mouseEvent", lua_Game_mouseEvent},
  51. {"pause", lua_Game_pause},
  52. {"resume", lua_Game_resume},
  53. {"run", lua_Game_run},
  54. {"schedule", lua_Game_schedule},
  55. {"setCursorVisible", lua_Game_setCursorVisible},
  56. {"setMouseCaptured", lua_Game_setMouseCaptured},
  57. {"setMultiTouch", lua_Game_setMultiTouch},
  58. {"setViewport", lua_Game_setViewport},
  59. {"touchEvent", lua_Game_touchEvent},
  60. {NULL, NULL}
  61. };
  62. const luaL_Reg lua_statics[] =
  63. {
  64. {"getAbsoluteTime", lua_Game_static_getAbsoluteTime},
  65. {"getGameTime", lua_Game_static_getGameTime},
  66. {"getInstance", lua_Game_static_getInstance},
  67. {"isVsync", lua_Game_static_isVsync},
  68. {"setVsync", lua_Game_static_setVsync},
  69. {NULL, NULL}
  70. };
  71. std::vector<std::string> scopePath;
  72. ScriptUtil::registerClass("Game", lua_members, NULL, lua_Game__gc, lua_statics, scopePath);
  73. }
  74. static Game* getInstance(lua_State* state)
  75. {
  76. void* userdata = luaL_checkudata(state, 1, "Game");
  77. luaL_argcheck(state, userdata != NULL, 1, "'Game' expected.");
  78. return (Game*)((ScriptUtil::LuaObject*)userdata)->instance;
  79. }
  80. int lua_Game__gc(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 1:
  88. {
  89. if ((lua_type(state, 1) == LUA_TUSERDATA))
  90. {
  91. void* userdata = luaL_checkudata(state, 1, "Game");
  92. luaL_argcheck(state, userdata != NULL, 1, "'Game' expected.");
  93. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  94. if (object->owns)
  95. {
  96. Game* instance = (Game*)object->instance;
  97. SAFE_DELETE(instance);
  98. }
  99. return 0;
  100. }
  101. else
  102. {
  103. lua_pushstring(state, "lua_Game__gc - Failed to match the given parameters to a valid function signature.");
  104. lua_error(state);
  105. }
  106. break;
  107. }
  108. default:
  109. {
  110. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  111. lua_error(state);
  112. break;
  113. }
  114. }
  115. return 0;
  116. }
  117. int lua_Game_clear(lua_State* state)
  118. {
  119. // Get the number of parameters.
  120. int paramCount = lua_gettop(state);
  121. // Attempt to match the parameters to a valid binding.
  122. switch (paramCount)
  123. {
  124. case 5:
  125. {
  126. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  127. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  128. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
  129. lua_type(state, 4) == LUA_TNUMBER &&
  130. lua_type(state, 5) == LUA_TNUMBER)
  131. {
  132. // Get parameter 1 off the stack.
  133. Game::ClearFlags param1 = (Game::ClearFlags)lua_enumFromString_GameClearFlags(luaL_checkstring(state, 2));
  134. // Get parameter 2 off the stack.
  135. Vector4* param2 = ScriptUtil::getObjectPointer<Vector4>(3, "Vector4", true);
  136. // Get parameter 3 off the stack.
  137. float param3 = (float)luaL_checknumber(state, 4);
  138. // Get parameter 4 off the stack.
  139. int param4 = (int)luaL_checkint(state, 5);
  140. Game* instance = getInstance(state);
  141. instance->clear(param1, *param2, param3, param4);
  142. return 0;
  143. }
  144. else
  145. {
  146. lua_pushstring(state, "lua_Game_clear - Failed to match the given parameters to a valid function signature.");
  147. lua_error(state);
  148. }
  149. break;
  150. }
  151. default:
  152. {
  153. lua_pushstring(state, "Invalid number of parameters (expected 5).");
  154. lua_error(state);
  155. break;
  156. }
  157. }
  158. return 0;
  159. }
  160. int lua_Game_displayKeyboard(lua_State* state)
  161. {
  162. // Get the number of parameters.
  163. int paramCount = lua_gettop(state);
  164. // Attempt to match the parameters to a valid binding.
  165. switch (paramCount)
  166. {
  167. case 2:
  168. {
  169. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  170. lua_type(state, 2) == LUA_TBOOLEAN)
  171. {
  172. // Get parameter 1 off the stack.
  173. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  174. Game* instance = getInstance(state);
  175. instance->displayKeyboard(param1);
  176. return 0;
  177. }
  178. else
  179. {
  180. lua_pushstring(state, "lua_Game_displayKeyboard - Failed to match the given parameters to a valid function signature.");
  181. lua_error(state);
  182. }
  183. break;
  184. }
  185. default:
  186. {
  187. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  188. lua_error(state);
  189. break;
  190. }
  191. }
  192. return 0;
  193. }
  194. int lua_Game_exit(lua_State* state)
  195. {
  196. // Get the number of parameters.
  197. int paramCount = lua_gettop(state);
  198. // Attempt to match the parameters to a valid binding.
  199. switch (paramCount)
  200. {
  201. case 1:
  202. {
  203. if ((lua_type(state, 1) == LUA_TUSERDATA))
  204. {
  205. Game* instance = getInstance(state);
  206. instance->exit();
  207. return 0;
  208. }
  209. else
  210. {
  211. lua_pushstring(state, "lua_Game_exit - Failed to match the given parameters to a valid function signature.");
  212. lua_error(state);
  213. }
  214. break;
  215. }
  216. default:
  217. {
  218. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  219. lua_error(state);
  220. break;
  221. }
  222. }
  223. return 0;
  224. }
  225. int lua_Game_frame(lua_State* state)
  226. {
  227. // Get the number of parameters.
  228. int paramCount = lua_gettop(state);
  229. // Attempt to match the parameters to a valid binding.
  230. switch (paramCount)
  231. {
  232. case 1:
  233. {
  234. if ((lua_type(state, 1) == LUA_TUSERDATA))
  235. {
  236. Game* instance = getInstance(state);
  237. instance->frame();
  238. return 0;
  239. }
  240. else
  241. {
  242. lua_pushstring(state, "lua_Game_frame - Failed to match the given parameters to a valid function signature.");
  243. lua_error(state);
  244. }
  245. break;
  246. }
  247. default:
  248. {
  249. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  250. lua_error(state);
  251. break;
  252. }
  253. }
  254. return 0;
  255. }
  256. int lua_Game_gamepadEvent(lua_State* state)
  257. {
  258. // Get the number of parameters.
  259. int paramCount = lua_gettop(state);
  260. // Attempt to match the parameters to a valid binding.
  261. switch (paramCount)
  262. {
  263. case 3:
  264. {
  265. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  266. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  267. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  268. {
  269. // Get parameter 1 off the stack.
  270. Gamepad::GamepadEvent param1 = (Gamepad::GamepadEvent)lua_enumFromString_GamepadGamepadEvent(luaL_checkstring(state, 2));
  271. // Get parameter 2 off the stack.
  272. Gamepad* param2 = ScriptUtil::getObjectPointer<Gamepad>(3, "Gamepad", false);
  273. Game* instance = getInstance(state);
  274. instance->gamepadEvent(param1, param2);
  275. return 0;
  276. }
  277. else
  278. {
  279. lua_pushstring(state, "lua_Game_gamepadEvent - Failed to match the given parameters to a valid function signature.");
  280. lua_error(state);
  281. }
  282. break;
  283. }
  284. default:
  285. {
  286. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  287. lua_error(state);
  288. break;
  289. }
  290. }
  291. return 0;
  292. }
  293. int lua_Game_getAIController(lua_State* state)
  294. {
  295. // Get the number of parameters.
  296. int paramCount = lua_gettop(state);
  297. // Attempt to match the parameters to a valid binding.
  298. switch (paramCount)
  299. {
  300. case 1:
  301. {
  302. if ((lua_type(state, 1) == LUA_TUSERDATA))
  303. {
  304. Game* instance = getInstance(state);
  305. void* returnPtr = (void*)instance->getAIController();
  306. if (returnPtr)
  307. {
  308. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  309. object->instance = returnPtr;
  310. object->owns = false;
  311. luaL_getmetatable(state, "AIController");
  312. lua_setmetatable(state, -2);
  313. }
  314. else
  315. {
  316. lua_pushnil(state);
  317. }
  318. return 1;
  319. }
  320. else
  321. {
  322. lua_pushstring(state, "lua_Game_getAIController - Failed to match the given parameters to a valid function signature.");
  323. lua_error(state);
  324. }
  325. break;
  326. }
  327. default:
  328. {
  329. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  330. lua_error(state);
  331. break;
  332. }
  333. }
  334. return 0;
  335. }
  336. int lua_Game_getAccelerometerValues(lua_State* state)
  337. {
  338. // Get the number of parameters.
  339. int paramCount = lua_gettop(state);
  340. // Attempt to match the parameters to a valid binding.
  341. switch (paramCount)
  342. {
  343. case 3:
  344. {
  345. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  346. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
  347. (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA))
  348. {
  349. // Get parameter 1 off the stack.
  350. float* param1 = ScriptUtil::getFloatPointer(2);
  351. // Get parameter 2 off the stack.
  352. float* param2 = ScriptUtil::getFloatPointer(3);
  353. Game* instance = getInstance(state);
  354. instance->getAccelerometerValues(param1, param2);
  355. return 0;
  356. }
  357. else
  358. {
  359. lua_pushstring(state, "lua_Game_getAccelerometerValues - Failed to match the given parameters to a valid function signature.");
  360. lua_error(state);
  361. }
  362. break;
  363. }
  364. default:
  365. {
  366. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  367. lua_error(state);
  368. break;
  369. }
  370. }
  371. return 0;
  372. }
  373. int lua_Game_getAnimationController(lua_State* state)
  374. {
  375. // Get the number of parameters.
  376. int paramCount = lua_gettop(state);
  377. // Attempt to match the parameters to a valid binding.
  378. switch (paramCount)
  379. {
  380. case 1:
  381. {
  382. if ((lua_type(state, 1) == LUA_TUSERDATA))
  383. {
  384. Game* instance = getInstance(state);
  385. void* returnPtr = (void*)instance->getAnimationController();
  386. if (returnPtr)
  387. {
  388. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  389. object->instance = returnPtr;
  390. object->owns = false;
  391. luaL_getmetatable(state, "AnimationController");
  392. lua_setmetatable(state, -2);
  393. }
  394. else
  395. {
  396. lua_pushnil(state);
  397. }
  398. return 1;
  399. }
  400. else
  401. {
  402. lua_pushstring(state, "lua_Game_getAnimationController - Failed to match the given parameters to a valid function signature.");
  403. lua_error(state);
  404. }
  405. break;
  406. }
  407. default:
  408. {
  409. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  410. lua_error(state);
  411. break;
  412. }
  413. }
  414. return 0;
  415. }
  416. int lua_Game_getAudioController(lua_State* state)
  417. {
  418. // Get the number of parameters.
  419. int paramCount = lua_gettop(state);
  420. // Attempt to match the parameters to a valid binding.
  421. switch (paramCount)
  422. {
  423. case 1:
  424. {
  425. if ((lua_type(state, 1) == LUA_TUSERDATA))
  426. {
  427. Game* instance = getInstance(state);
  428. void* returnPtr = (void*)instance->getAudioController();
  429. if (returnPtr)
  430. {
  431. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  432. object->instance = returnPtr;
  433. object->owns = false;
  434. luaL_getmetatable(state, "AudioController");
  435. lua_setmetatable(state, -2);
  436. }
  437. else
  438. {
  439. lua_pushnil(state);
  440. }
  441. return 1;
  442. }
  443. else
  444. {
  445. lua_pushstring(state, "lua_Game_getAudioController - Failed to match the given parameters to a valid function signature.");
  446. lua_error(state);
  447. }
  448. break;
  449. }
  450. default:
  451. {
  452. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  453. lua_error(state);
  454. break;
  455. }
  456. }
  457. return 0;
  458. }
  459. int lua_Game_getAudioListener(lua_State* state)
  460. {
  461. // Get the number of parameters.
  462. int paramCount = lua_gettop(state);
  463. // Attempt to match the parameters to a valid binding.
  464. switch (paramCount)
  465. {
  466. case 1:
  467. {
  468. if ((lua_type(state, 1) == LUA_TUSERDATA))
  469. {
  470. Game* instance = getInstance(state);
  471. void* returnPtr = (void*)instance->getAudioListener();
  472. if (returnPtr)
  473. {
  474. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  475. object->instance = returnPtr;
  476. object->owns = false;
  477. luaL_getmetatable(state, "AudioListener");
  478. lua_setmetatable(state, -2);
  479. }
  480. else
  481. {
  482. lua_pushnil(state);
  483. }
  484. return 1;
  485. }
  486. else
  487. {
  488. lua_pushstring(state, "lua_Game_getAudioListener - Failed to match the given parameters to a valid function signature.");
  489. lua_error(state);
  490. }
  491. break;
  492. }
  493. default:
  494. {
  495. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  496. lua_error(state);
  497. break;
  498. }
  499. }
  500. return 0;
  501. }
  502. int lua_Game_getConfig(lua_State* state)
  503. {
  504. // Get the number of parameters.
  505. int paramCount = lua_gettop(state);
  506. // Attempt to match the parameters to a valid binding.
  507. switch (paramCount)
  508. {
  509. case 1:
  510. {
  511. if ((lua_type(state, 1) == LUA_TUSERDATA))
  512. {
  513. Game* instance = getInstance(state);
  514. void* returnPtr = (void*)instance->getConfig();
  515. if (returnPtr)
  516. {
  517. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  518. object->instance = returnPtr;
  519. object->owns = false;
  520. luaL_getmetatable(state, "Properties");
  521. lua_setmetatable(state, -2);
  522. }
  523. else
  524. {
  525. lua_pushnil(state);
  526. }
  527. return 1;
  528. }
  529. else
  530. {
  531. lua_pushstring(state, "lua_Game_getConfig - Failed to match the given parameters to a valid function signature.");
  532. lua_error(state);
  533. }
  534. break;
  535. }
  536. default:
  537. {
  538. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  539. lua_error(state);
  540. break;
  541. }
  542. }
  543. return 0;
  544. }
  545. int lua_Game_getFrameRate(lua_State* state)
  546. {
  547. // Get the number of parameters.
  548. int paramCount = lua_gettop(state);
  549. // Attempt to match the parameters to a valid binding.
  550. switch (paramCount)
  551. {
  552. case 1:
  553. {
  554. if ((lua_type(state, 1) == LUA_TUSERDATA))
  555. {
  556. Game* instance = getInstance(state);
  557. unsigned int result = instance->getFrameRate();
  558. // Push the return value onto the stack.
  559. lua_pushunsigned(state, result);
  560. return 1;
  561. }
  562. else
  563. {
  564. lua_pushstring(state, "lua_Game_getFrameRate - Failed to match the given parameters to a valid function signature.");
  565. lua_error(state);
  566. }
  567. break;
  568. }
  569. default:
  570. {
  571. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  572. lua_error(state);
  573. break;
  574. }
  575. }
  576. return 0;
  577. }
  578. int lua_Game_getGamepad(lua_State* state)
  579. {
  580. // Get the number of parameters.
  581. int paramCount = lua_gettop(state);
  582. // Attempt to match the parameters to a valid binding.
  583. switch (paramCount)
  584. {
  585. case 2:
  586. {
  587. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  588. lua_type(state, 2) == LUA_TNUMBER)
  589. {
  590. // Get parameter 1 off the stack.
  591. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  592. Game* instance = getInstance(state);
  593. void* returnPtr = (void*)instance->getGamepad(param1);
  594. if (returnPtr)
  595. {
  596. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  597. object->instance = returnPtr;
  598. object->owns = false;
  599. luaL_getmetatable(state, "Gamepad");
  600. lua_setmetatable(state, -2);
  601. }
  602. else
  603. {
  604. lua_pushnil(state);
  605. }
  606. return 1;
  607. }
  608. else
  609. {
  610. lua_pushstring(state, "lua_Game_getGamepad - Failed to match the given parameters to a valid function signature.");
  611. lua_error(state);
  612. }
  613. break;
  614. }
  615. default:
  616. {
  617. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  618. lua_error(state);
  619. break;
  620. }
  621. }
  622. return 0;
  623. }
  624. int lua_Game_getGamepadCount(lua_State* state)
  625. {
  626. // Get the number of parameters.
  627. int paramCount = lua_gettop(state);
  628. // Attempt to match the parameters to a valid binding.
  629. switch (paramCount)
  630. {
  631. case 1:
  632. {
  633. if ((lua_type(state, 1) == LUA_TUSERDATA))
  634. {
  635. Game* instance = getInstance(state);
  636. unsigned int result = instance->getGamepadCount();
  637. // Push the return value onto the stack.
  638. lua_pushunsigned(state, result);
  639. return 1;
  640. }
  641. else
  642. {
  643. lua_pushstring(state, "lua_Game_getGamepadCount - Failed to match the given parameters to a valid function signature.");
  644. lua_error(state);
  645. }
  646. break;
  647. }
  648. default:
  649. {
  650. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  651. lua_error(state);
  652. break;
  653. }
  654. }
  655. return 0;
  656. }
  657. int lua_Game_getHeight(lua_State* state)
  658. {
  659. // Get the number of parameters.
  660. int paramCount = lua_gettop(state);
  661. // Attempt to match the parameters to a valid binding.
  662. switch (paramCount)
  663. {
  664. case 1:
  665. {
  666. if ((lua_type(state, 1) == LUA_TUSERDATA))
  667. {
  668. Game* instance = getInstance(state);
  669. unsigned int result = instance->getHeight();
  670. // Push the return value onto the stack.
  671. lua_pushunsigned(state, result);
  672. return 1;
  673. }
  674. else
  675. {
  676. lua_pushstring(state, "lua_Game_getHeight - Failed to match the given parameters to a valid function signature.");
  677. lua_error(state);
  678. }
  679. break;
  680. }
  681. default:
  682. {
  683. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  684. lua_error(state);
  685. break;
  686. }
  687. }
  688. return 0;
  689. }
  690. int lua_Game_getPhysicsController(lua_State* state)
  691. {
  692. // Get the number of parameters.
  693. int paramCount = lua_gettop(state);
  694. // Attempt to match the parameters to a valid binding.
  695. switch (paramCount)
  696. {
  697. case 1:
  698. {
  699. if ((lua_type(state, 1) == LUA_TUSERDATA))
  700. {
  701. Game* instance = getInstance(state);
  702. void* returnPtr = (void*)instance->getPhysicsController();
  703. if (returnPtr)
  704. {
  705. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  706. object->instance = returnPtr;
  707. object->owns = false;
  708. luaL_getmetatable(state, "PhysicsController");
  709. lua_setmetatable(state, -2);
  710. }
  711. else
  712. {
  713. lua_pushnil(state);
  714. }
  715. return 1;
  716. }
  717. else
  718. {
  719. lua_pushstring(state, "lua_Game_getPhysicsController - Failed to match the given parameters to a valid function signature.");
  720. lua_error(state);
  721. }
  722. break;
  723. }
  724. default:
  725. {
  726. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  727. lua_error(state);
  728. break;
  729. }
  730. }
  731. return 0;
  732. }
  733. int lua_Game_getScriptController(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 1:
  741. {
  742. if ((lua_type(state, 1) == LUA_TUSERDATA))
  743. {
  744. Game* instance = getInstance(state);
  745. void* returnPtr = (void*)instance->getScriptController();
  746. if (returnPtr)
  747. {
  748. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  749. object->instance = returnPtr;
  750. object->owns = false;
  751. luaL_getmetatable(state, "ScriptController");
  752. lua_setmetatable(state, -2);
  753. }
  754. else
  755. {
  756. lua_pushnil(state);
  757. }
  758. return 1;
  759. }
  760. else
  761. {
  762. lua_pushstring(state, "lua_Game_getScriptController - Failed to match the given parameters to a valid function signature.");
  763. lua_error(state);
  764. }
  765. break;
  766. }
  767. default:
  768. {
  769. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  770. lua_error(state);
  771. break;
  772. }
  773. }
  774. return 0;
  775. }
  776. int lua_Game_getState(lua_State* state)
  777. {
  778. // Get the number of parameters.
  779. int paramCount = lua_gettop(state);
  780. // Attempt to match the parameters to a valid binding.
  781. switch (paramCount)
  782. {
  783. case 1:
  784. {
  785. if ((lua_type(state, 1) == LUA_TUSERDATA))
  786. {
  787. Game* instance = getInstance(state);
  788. Game::State result = instance->getState();
  789. // Push the return value onto the stack.
  790. lua_pushstring(state, lua_stringFromEnum_GameState(result));
  791. return 1;
  792. }
  793. else
  794. {
  795. lua_pushstring(state, "lua_Game_getState - Failed to match the given parameters to a valid function signature.");
  796. lua_error(state);
  797. }
  798. break;
  799. }
  800. default:
  801. {
  802. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  803. lua_error(state);
  804. break;
  805. }
  806. }
  807. return 0;
  808. }
  809. int lua_Game_getViewport(lua_State* state)
  810. {
  811. // Get the number of parameters.
  812. int paramCount = lua_gettop(state);
  813. // Attempt to match the parameters to a valid binding.
  814. switch (paramCount)
  815. {
  816. case 1:
  817. {
  818. if ((lua_type(state, 1) == LUA_TUSERDATA))
  819. {
  820. Game* instance = getInstance(state);
  821. void* returnPtr = (void*)&(instance->getViewport());
  822. if (returnPtr)
  823. {
  824. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  825. object->instance = returnPtr;
  826. object->owns = false;
  827. luaL_getmetatable(state, "Rectangle");
  828. lua_setmetatable(state, -2);
  829. }
  830. else
  831. {
  832. lua_pushnil(state);
  833. }
  834. return 1;
  835. }
  836. else
  837. {
  838. lua_pushstring(state, "lua_Game_getViewport - Failed to match the given parameters to a valid function signature.");
  839. lua_error(state);
  840. }
  841. break;
  842. }
  843. default:
  844. {
  845. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  846. lua_error(state);
  847. break;
  848. }
  849. }
  850. return 0;
  851. }
  852. int lua_Game_getWidth(lua_State* state)
  853. {
  854. // Get the number of parameters.
  855. int paramCount = lua_gettop(state);
  856. // Attempt to match the parameters to a valid binding.
  857. switch (paramCount)
  858. {
  859. case 1:
  860. {
  861. if ((lua_type(state, 1) == LUA_TUSERDATA))
  862. {
  863. Game* instance = getInstance(state);
  864. unsigned int result = instance->getWidth();
  865. // Push the return value onto the stack.
  866. lua_pushunsigned(state, result);
  867. return 1;
  868. }
  869. else
  870. {
  871. lua_pushstring(state, "lua_Game_getWidth - Failed to match the given parameters to a valid function signature.");
  872. lua_error(state);
  873. }
  874. break;
  875. }
  876. default:
  877. {
  878. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  879. lua_error(state);
  880. break;
  881. }
  882. }
  883. return 0;
  884. }
  885. int lua_Game_hasMouse(lua_State* state)
  886. {
  887. // Get the number of parameters.
  888. int paramCount = lua_gettop(state);
  889. // Attempt to match the parameters to a valid binding.
  890. switch (paramCount)
  891. {
  892. case 1:
  893. {
  894. if ((lua_type(state, 1) == LUA_TUSERDATA))
  895. {
  896. Game* instance = getInstance(state);
  897. bool result = instance->hasMouse();
  898. // Push the return value onto the stack.
  899. lua_pushboolean(state, result);
  900. return 1;
  901. }
  902. else
  903. {
  904. lua_pushstring(state, "lua_Game_hasMouse - Failed to match the given parameters to a valid function signature.");
  905. lua_error(state);
  906. }
  907. break;
  908. }
  909. default:
  910. {
  911. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  912. lua_error(state);
  913. break;
  914. }
  915. }
  916. return 0;
  917. }
  918. int lua_Game_isCursorVisible(lua_State* state)
  919. {
  920. // Get the number of parameters.
  921. int paramCount = lua_gettop(state);
  922. // Attempt to match the parameters to a valid binding.
  923. switch (paramCount)
  924. {
  925. case 1:
  926. {
  927. if ((lua_type(state, 1) == LUA_TUSERDATA))
  928. {
  929. Game* instance = getInstance(state);
  930. bool result = instance->isCursorVisible();
  931. // Push the return value onto the stack.
  932. lua_pushboolean(state, result);
  933. return 1;
  934. }
  935. else
  936. {
  937. lua_pushstring(state, "lua_Game_isCursorVisible - Failed to match the given parameters to a valid function signature.");
  938. lua_error(state);
  939. }
  940. break;
  941. }
  942. default:
  943. {
  944. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  945. lua_error(state);
  946. break;
  947. }
  948. }
  949. return 0;
  950. }
  951. int lua_Game_isInitialized(lua_State* state)
  952. {
  953. // Get the number of parameters.
  954. int paramCount = lua_gettop(state);
  955. // Attempt to match the parameters to a valid binding.
  956. switch (paramCount)
  957. {
  958. case 1:
  959. {
  960. if ((lua_type(state, 1) == LUA_TUSERDATA))
  961. {
  962. Game* instance = getInstance(state);
  963. bool result = instance->isInitialized();
  964. // Push the return value onto the stack.
  965. lua_pushboolean(state, result);
  966. return 1;
  967. }
  968. else
  969. {
  970. lua_pushstring(state, "lua_Game_isInitialized - Failed to match the given parameters to a valid function signature.");
  971. lua_error(state);
  972. }
  973. break;
  974. }
  975. default:
  976. {
  977. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  978. lua_error(state);
  979. break;
  980. }
  981. }
  982. return 0;
  983. }
  984. int lua_Game_isMouseCaptured(lua_State* state)
  985. {
  986. // Get the number of parameters.
  987. int paramCount = lua_gettop(state);
  988. // Attempt to match the parameters to a valid binding.
  989. switch (paramCount)
  990. {
  991. case 1:
  992. {
  993. if ((lua_type(state, 1) == LUA_TUSERDATA))
  994. {
  995. Game* instance = getInstance(state);
  996. bool result = instance->isMouseCaptured();
  997. // Push the return value onto the stack.
  998. lua_pushboolean(state, result);
  999. return 1;
  1000. }
  1001. else
  1002. {
  1003. lua_pushstring(state, "lua_Game_isMouseCaptured - Failed to match the given parameters to a valid function signature.");
  1004. lua_error(state);
  1005. }
  1006. break;
  1007. }
  1008. default:
  1009. {
  1010. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  1011. lua_error(state);
  1012. break;
  1013. }
  1014. }
  1015. return 0;
  1016. }
  1017. int lua_Game_isMultiTouch(lua_State* state)
  1018. {
  1019. // Get the number of parameters.
  1020. int paramCount = lua_gettop(state);
  1021. // Attempt to match the parameters to a valid binding.
  1022. switch (paramCount)
  1023. {
  1024. case 1:
  1025. {
  1026. if ((lua_type(state, 1) == LUA_TUSERDATA))
  1027. {
  1028. Game* instance = getInstance(state);
  1029. bool result = instance->isMultiTouch();
  1030. // Push the return value onto the stack.
  1031. lua_pushboolean(state, result);
  1032. return 1;
  1033. }
  1034. else
  1035. {
  1036. lua_pushstring(state, "lua_Game_isMultiTouch - Failed to match the given parameters to a valid function signature.");
  1037. lua_error(state);
  1038. }
  1039. break;
  1040. }
  1041. default:
  1042. {
  1043. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  1044. lua_error(state);
  1045. break;
  1046. }
  1047. }
  1048. return 0;
  1049. }
  1050. int lua_Game_keyEvent(lua_State* state)
  1051. {
  1052. // Get the number of parameters.
  1053. int paramCount = lua_gettop(state);
  1054. // Attempt to match the parameters to a valid binding.
  1055. switch (paramCount)
  1056. {
  1057. case 3:
  1058. {
  1059. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  1060. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  1061. lua_type(state, 3) == LUA_TNUMBER)
  1062. {
  1063. // Get parameter 1 off the stack.
  1064. Keyboard::KeyEvent param1 = (Keyboard::KeyEvent)lua_enumFromString_KeyboardKeyEvent(luaL_checkstring(state, 2));
  1065. // Get parameter 2 off the stack.
  1066. int param2 = (int)luaL_checkint(state, 3);
  1067. Game* instance = getInstance(state);
  1068. instance->keyEvent(param1, param2);
  1069. return 0;
  1070. }
  1071. else
  1072. {
  1073. lua_pushstring(state, "lua_Game_keyEvent - Failed to match the given parameters to a valid function signature.");
  1074. lua_error(state);
  1075. }
  1076. break;
  1077. }
  1078. default:
  1079. {
  1080. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  1081. lua_error(state);
  1082. break;
  1083. }
  1084. }
  1085. return 0;
  1086. }
  1087. int lua_Game_menuEvent(lua_State* state)
  1088. {
  1089. // Get the number of parameters.
  1090. int paramCount = lua_gettop(state);
  1091. // Attempt to match the parameters to a valid binding.
  1092. switch (paramCount)
  1093. {
  1094. case 1:
  1095. {
  1096. if ((lua_type(state, 1) == LUA_TUSERDATA))
  1097. {
  1098. Game* instance = getInstance(state);
  1099. instance->menuEvent();
  1100. return 0;
  1101. }
  1102. else
  1103. {
  1104. lua_pushstring(state, "lua_Game_menuEvent - Failed to match the given parameters to a valid function signature.");
  1105. lua_error(state);
  1106. }
  1107. break;
  1108. }
  1109. default:
  1110. {
  1111. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  1112. lua_error(state);
  1113. break;
  1114. }
  1115. }
  1116. return 0;
  1117. }
  1118. int lua_Game_mouseEvent(lua_State* state)
  1119. {
  1120. // Get the number of parameters.
  1121. int paramCount = lua_gettop(state);
  1122. // Attempt to match the parameters to a valid binding.
  1123. switch (paramCount)
  1124. {
  1125. case 5:
  1126. {
  1127. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  1128. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  1129. lua_type(state, 3) == LUA_TNUMBER &&
  1130. lua_type(state, 4) == LUA_TNUMBER &&
  1131. lua_type(state, 5) == LUA_TNUMBER)
  1132. {
  1133. // Get parameter 1 off the stack.
  1134. Mouse::MouseEvent param1 = (Mouse::MouseEvent)lua_enumFromString_MouseMouseEvent(luaL_checkstring(state, 2));
  1135. // Get parameter 2 off the stack.
  1136. int param2 = (int)luaL_checkint(state, 3);
  1137. // Get parameter 3 off the stack.
  1138. int param3 = (int)luaL_checkint(state, 4);
  1139. // Get parameter 4 off the stack.
  1140. int param4 = (int)luaL_checkint(state, 5);
  1141. Game* instance = getInstance(state);
  1142. bool result = instance->mouseEvent(param1, param2, param3, param4);
  1143. // Push the return value onto the stack.
  1144. lua_pushboolean(state, result);
  1145. return 1;
  1146. }
  1147. else
  1148. {
  1149. lua_pushstring(state, "lua_Game_mouseEvent - Failed to match the given parameters to a valid function signature.");
  1150. lua_error(state);
  1151. }
  1152. break;
  1153. }
  1154. default:
  1155. {
  1156. lua_pushstring(state, "Invalid number of parameters (expected 5).");
  1157. lua_error(state);
  1158. break;
  1159. }
  1160. }
  1161. return 0;
  1162. }
  1163. int lua_Game_pause(lua_State* state)
  1164. {
  1165. // Get the number of parameters.
  1166. int paramCount = lua_gettop(state);
  1167. // Attempt to match the parameters to a valid binding.
  1168. switch (paramCount)
  1169. {
  1170. case 1:
  1171. {
  1172. if ((lua_type(state, 1) == LUA_TUSERDATA))
  1173. {
  1174. Game* instance = getInstance(state);
  1175. instance->pause();
  1176. return 0;
  1177. }
  1178. else
  1179. {
  1180. lua_pushstring(state, "lua_Game_pause - Failed to match the given parameters to a valid function signature.");
  1181. lua_error(state);
  1182. }
  1183. break;
  1184. }
  1185. default:
  1186. {
  1187. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  1188. lua_error(state);
  1189. break;
  1190. }
  1191. }
  1192. return 0;
  1193. }
  1194. int lua_Game_resume(lua_State* state)
  1195. {
  1196. // Get the number of parameters.
  1197. int paramCount = lua_gettop(state);
  1198. // Attempt to match the parameters to a valid binding.
  1199. switch (paramCount)
  1200. {
  1201. case 1:
  1202. {
  1203. if ((lua_type(state, 1) == LUA_TUSERDATA))
  1204. {
  1205. Game* instance = getInstance(state);
  1206. instance->resume();
  1207. return 0;
  1208. }
  1209. else
  1210. {
  1211. lua_pushstring(state, "lua_Game_resume - Failed to match the given parameters to a valid function signature.");
  1212. lua_error(state);
  1213. }
  1214. break;
  1215. }
  1216. default:
  1217. {
  1218. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  1219. lua_error(state);
  1220. break;
  1221. }
  1222. }
  1223. return 0;
  1224. }
  1225. int lua_Game_run(lua_State* state)
  1226. {
  1227. // Get the number of parameters.
  1228. int paramCount = lua_gettop(state);
  1229. // Attempt to match the parameters to a valid binding.
  1230. switch (paramCount)
  1231. {
  1232. case 1:
  1233. {
  1234. if ((lua_type(state, 1) == LUA_TUSERDATA))
  1235. {
  1236. Game* instance = getInstance(state);
  1237. int result = instance->run();
  1238. // Push the return value onto the stack.
  1239. lua_pushinteger(state, result);
  1240. return 1;
  1241. }
  1242. else
  1243. {
  1244. lua_pushstring(state, "lua_Game_run - Failed to match the given parameters to a valid function signature.");
  1245. lua_error(state);
  1246. }
  1247. break;
  1248. }
  1249. default:
  1250. {
  1251. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  1252. lua_error(state);
  1253. break;
  1254. }
  1255. }
  1256. return 0;
  1257. }
  1258. int lua_Game_schedule(lua_State* state)
  1259. {
  1260. // Get the number of parameters.
  1261. int paramCount = lua_gettop(state);
  1262. // Attempt to match the parameters to a valid binding.
  1263. switch (paramCount)
  1264. {
  1265. case 3:
  1266. {
  1267. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  1268. lua_type(state, 2) == LUA_TNUMBER &&
  1269. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  1270. {
  1271. // Get parameter 1 off the stack.
  1272. float param1 = (float)luaL_checknumber(state, 2);
  1273. // Get parameter 2 off the stack.
  1274. const char* param2 = ScriptUtil::getString(3, false);
  1275. Game* instance = getInstance(state);
  1276. instance->schedule(param1, param2);
  1277. return 0;
  1278. }
  1279. else
  1280. {
  1281. lua_pushstring(state, "lua_Game_schedule - Failed to match the given parameters to a valid function signature.");
  1282. lua_error(state);
  1283. }
  1284. break;
  1285. }
  1286. default:
  1287. {
  1288. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  1289. lua_error(state);
  1290. break;
  1291. }
  1292. }
  1293. return 0;
  1294. }
  1295. int lua_Game_setCursorVisible(lua_State* state)
  1296. {
  1297. // Get the number of parameters.
  1298. int paramCount = lua_gettop(state);
  1299. // Attempt to match the parameters to a valid binding.
  1300. switch (paramCount)
  1301. {
  1302. case 2:
  1303. {
  1304. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  1305. lua_type(state, 2) == LUA_TBOOLEAN)
  1306. {
  1307. // Get parameter 1 off the stack.
  1308. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  1309. Game* instance = getInstance(state);
  1310. instance->setCursorVisible(param1);
  1311. return 0;
  1312. }
  1313. else
  1314. {
  1315. lua_pushstring(state, "lua_Game_setCursorVisible - Failed to match the given parameters to a valid function signature.");
  1316. lua_error(state);
  1317. }
  1318. break;
  1319. }
  1320. default:
  1321. {
  1322. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  1323. lua_error(state);
  1324. break;
  1325. }
  1326. }
  1327. return 0;
  1328. }
  1329. int lua_Game_setMouseCaptured(lua_State* state)
  1330. {
  1331. // Get the number of parameters.
  1332. int paramCount = lua_gettop(state);
  1333. // Attempt to match the parameters to a valid binding.
  1334. switch (paramCount)
  1335. {
  1336. case 2:
  1337. {
  1338. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  1339. lua_type(state, 2) == LUA_TBOOLEAN)
  1340. {
  1341. // Get parameter 1 off the stack.
  1342. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  1343. Game* instance = getInstance(state);
  1344. instance->setMouseCaptured(param1);
  1345. return 0;
  1346. }
  1347. else
  1348. {
  1349. lua_pushstring(state, "lua_Game_setMouseCaptured - Failed to match the given parameters to a valid function signature.");
  1350. lua_error(state);
  1351. }
  1352. break;
  1353. }
  1354. default:
  1355. {
  1356. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  1357. lua_error(state);
  1358. break;
  1359. }
  1360. }
  1361. return 0;
  1362. }
  1363. int lua_Game_setMultiTouch(lua_State* state)
  1364. {
  1365. // Get the number of parameters.
  1366. int paramCount = lua_gettop(state);
  1367. // Attempt to match the parameters to a valid binding.
  1368. switch (paramCount)
  1369. {
  1370. case 2:
  1371. {
  1372. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  1373. lua_type(state, 2) == LUA_TBOOLEAN)
  1374. {
  1375. // Get parameter 1 off the stack.
  1376. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  1377. Game* instance = getInstance(state);
  1378. instance->setMultiTouch(param1);
  1379. return 0;
  1380. }
  1381. else
  1382. {
  1383. lua_pushstring(state, "lua_Game_setMultiTouch - Failed to match the given parameters to a valid function signature.");
  1384. lua_error(state);
  1385. }
  1386. break;
  1387. }
  1388. default:
  1389. {
  1390. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  1391. lua_error(state);
  1392. break;
  1393. }
  1394. }
  1395. return 0;
  1396. }
  1397. int lua_Game_setViewport(lua_State* state)
  1398. {
  1399. // Get the number of parameters.
  1400. int paramCount = lua_gettop(state);
  1401. // Attempt to match the parameters to a valid binding.
  1402. switch (paramCount)
  1403. {
  1404. case 2:
  1405. {
  1406. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  1407. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  1408. {
  1409. // Get parameter 1 off the stack.
  1410. Rectangle* param1 = ScriptUtil::getObjectPointer<Rectangle>(2, "Rectangle", true);
  1411. Game* instance = getInstance(state);
  1412. instance->setViewport(*param1);
  1413. return 0;
  1414. }
  1415. else
  1416. {
  1417. lua_pushstring(state, "lua_Game_setViewport - Failed to match the given parameters to a valid function signature.");
  1418. lua_error(state);
  1419. }
  1420. break;
  1421. }
  1422. default:
  1423. {
  1424. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  1425. lua_error(state);
  1426. break;
  1427. }
  1428. }
  1429. return 0;
  1430. }
  1431. int lua_Game_static_getAbsoluteTime(lua_State* state)
  1432. {
  1433. // Get the number of parameters.
  1434. int paramCount = lua_gettop(state);
  1435. // Attempt to match the parameters to a valid binding.
  1436. switch (paramCount)
  1437. {
  1438. case 0:
  1439. {
  1440. double result = Game::getAbsoluteTime();
  1441. // Push the return value onto the stack.
  1442. lua_pushnumber(state, result);
  1443. return 1;
  1444. break;
  1445. }
  1446. default:
  1447. {
  1448. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  1449. lua_error(state);
  1450. break;
  1451. }
  1452. }
  1453. return 0;
  1454. }
  1455. int lua_Game_static_getGameTime(lua_State* state)
  1456. {
  1457. // Get the number of parameters.
  1458. int paramCount = lua_gettop(state);
  1459. // Attempt to match the parameters to a valid binding.
  1460. switch (paramCount)
  1461. {
  1462. case 0:
  1463. {
  1464. double result = Game::getGameTime();
  1465. // Push the return value onto the stack.
  1466. lua_pushnumber(state, result);
  1467. return 1;
  1468. break;
  1469. }
  1470. default:
  1471. {
  1472. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  1473. lua_error(state);
  1474. break;
  1475. }
  1476. }
  1477. return 0;
  1478. }
  1479. int lua_Game_static_getInstance(lua_State* state)
  1480. {
  1481. // Get the number of parameters.
  1482. int paramCount = lua_gettop(state);
  1483. // Attempt to match the parameters to a valid binding.
  1484. switch (paramCount)
  1485. {
  1486. case 0:
  1487. {
  1488. void* returnPtr = (void*)Game::getInstance();
  1489. if (returnPtr)
  1490. {
  1491. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  1492. object->instance = returnPtr;
  1493. object->owns = false;
  1494. luaL_getmetatable(state, "Game");
  1495. lua_setmetatable(state, -2);
  1496. }
  1497. else
  1498. {
  1499. lua_pushnil(state);
  1500. }
  1501. return 1;
  1502. break;
  1503. }
  1504. default:
  1505. {
  1506. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  1507. lua_error(state);
  1508. break;
  1509. }
  1510. }
  1511. return 0;
  1512. }
  1513. int lua_Game_static_isVsync(lua_State* state)
  1514. {
  1515. // Get the number of parameters.
  1516. int paramCount = lua_gettop(state);
  1517. // Attempt to match the parameters to a valid binding.
  1518. switch (paramCount)
  1519. {
  1520. case 0:
  1521. {
  1522. bool result = Game::isVsync();
  1523. // Push the return value onto the stack.
  1524. lua_pushboolean(state, result);
  1525. return 1;
  1526. break;
  1527. }
  1528. default:
  1529. {
  1530. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  1531. lua_error(state);
  1532. break;
  1533. }
  1534. }
  1535. return 0;
  1536. }
  1537. int lua_Game_static_setVsync(lua_State* state)
  1538. {
  1539. // Get the number of parameters.
  1540. int paramCount = lua_gettop(state);
  1541. // Attempt to match the parameters to a valid binding.
  1542. switch (paramCount)
  1543. {
  1544. case 1:
  1545. {
  1546. if (lua_type(state, 1) == LUA_TBOOLEAN)
  1547. {
  1548. // Get parameter 1 off the stack.
  1549. bool param1 = ScriptUtil::luaCheckBool(state, 1);
  1550. Game::setVsync(param1);
  1551. return 0;
  1552. }
  1553. else
  1554. {
  1555. lua_pushstring(state, "lua_Game_static_setVsync - Failed to match the given parameters to a valid function signature.");
  1556. lua_error(state);
  1557. }
  1558. break;
  1559. }
  1560. default:
  1561. {
  1562. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  1563. lua_error(state);
  1564. break;
  1565. }
  1566. }
  1567. return 0;
  1568. }
  1569. int lua_Game_touchEvent(lua_State* state)
  1570. {
  1571. // Get the number of parameters.
  1572. int paramCount = lua_gettop(state);
  1573. // Attempt to match the parameters to a valid binding.
  1574. switch (paramCount)
  1575. {
  1576. case 5:
  1577. {
  1578. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  1579. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  1580. lua_type(state, 3) == LUA_TNUMBER &&
  1581. lua_type(state, 4) == LUA_TNUMBER &&
  1582. lua_type(state, 5) == LUA_TNUMBER)
  1583. {
  1584. // Get parameter 1 off the stack.
  1585. Touch::TouchEvent param1 = (Touch::TouchEvent)lua_enumFromString_TouchTouchEvent(luaL_checkstring(state, 2));
  1586. // Get parameter 2 off the stack.
  1587. int param2 = (int)luaL_checkint(state, 3);
  1588. // Get parameter 3 off the stack.
  1589. int param3 = (int)luaL_checkint(state, 4);
  1590. // Get parameter 4 off the stack.
  1591. unsigned int param4 = (unsigned int)luaL_checkunsigned(state, 5);
  1592. Game* instance = getInstance(state);
  1593. instance->touchEvent(param1, param2, param3, param4);
  1594. return 0;
  1595. }
  1596. else
  1597. {
  1598. lua_pushstring(state, "lua_Game_touchEvent - Failed to match the given parameters to a valid function signature.");
  1599. lua_error(state);
  1600. }
  1601. break;
  1602. }
  1603. default:
  1604. {
  1605. lua_pushstring(state, "Invalid number of parameters (expected 5).");
  1606. lua_error(state);
  1607. break;
  1608. }
  1609. }
  1610. return 0;
  1611. }
  1612. }