lua_Bundle.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Bundle.h"
  4. #include "Base.h"
  5. #include "Bundle.h"
  6. #include "FileSystem.h"
  7. #include "Game.h"
  8. #include "Joint.h"
  9. #include "MeshPart.h"
  10. #include "Ref.h"
  11. #include "Scene.h"
  12. namespace gameplay
  13. {
  14. void luaRegister_Bundle()
  15. {
  16. const luaL_Reg lua_members[] =
  17. {
  18. {"addRef", lua_Bundle_addRef},
  19. {"contains", lua_Bundle_contains},
  20. {"getObjectCount", lua_Bundle_getObjectCount},
  21. {"getObjectId", lua_Bundle_getObjectId},
  22. {"getRefCount", lua_Bundle_getRefCount},
  23. {"getVersionMajor", lua_Bundle_getVersionMajor},
  24. {"getVersionMinor", lua_Bundle_getVersionMinor},
  25. {"loadFont", lua_Bundle_loadFont},
  26. {"loadMesh", lua_Bundle_loadMesh},
  27. {"loadNode", lua_Bundle_loadNode},
  28. {"loadScene", lua_Bundle_loadScene},
  29. {"release", lua_Bundle_release},
  30. {NULL, NULL}
  31. };
  32. const luaL_Reg lua_statics[] =
  33. {
  34. {"create", lua_Bundle_static_create},
  35. {NULL, NULL}
  36. };
  37. std::vector<std::string> scopePath;
  38. gameplay::ScriptUtil::registerClass("Bundle", lua_members, NULL, lua_Bundle__gc, lua_statics, scopePath);
  39. }
  40. static Bundle* getInstance(lua_State* state)
  41. {
  42. void* userdata = luaL_checkudata(state, 1, "Bundle");
  43. luaL_argcheck(state, userdata != NULL, 1, "'Bundle' expected.");
  44. return (Bundle*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  45. }
  46. int lua_Bundle__gc(lua_State* state)
  47. {
  48. // Get the number of parameters.
  49. int paramCount = lua_gettop(state);
  50. // Attempt to match the parameters to a valid binding.
  51. switch (paramCount)
  52. {
  53. case 1:
  54. {
  55. if ((lua_type(state, 1) == LUA_TUSERDATA))
  56. {
  57. void* userdata = luaL_checkudata(state, 1, "Bundle");
  58. luaL_argcheck(state, userdata != NULL, 1, "'Bundle' expected.");
  59. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  60. if (object->owns)
  61. {
  62. Bundle* instance = (Bundle*)object->instance;
  63. SAFE_RELEASE(instance);
  64. }
  65. return 0;
  66. }
  67. lua_pushstring(state, "lua_Bundle__gc - Failed to match the given parameters to a valid function signature.");
  68. lua_error(state);
  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_Bundle_addRef(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. Bundle* instance = getInstance(state);
  92. instance->addRef();
  93. return 0;
  94. }
  95. lua_pushstring(state, "lua_Bundle_addRef - Failed to match the given parameters to a valid function signature.");
  96. lua_error(state);
  97. break;
  98. }
  99. default:
  100. {
  101. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  102. lua_error(state);
  103. break;
  104. }
  105. }
  106. return 0;
  107. }
  108. int lua_Bundle_contains(lua_State* state)
  109. {
  110. // Get the number of parameters.
  111. int paramCount = lua_gettop(state);
  112. // Attempt to match the parameters to a valid binding.
  113. switch (paramCount)
  114. {
  115. case 2:
  116. {
  117. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  118. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  119. {
  120. // Get parameter 1 off the stack.
  121. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  122. Bundle* instance = getInstance(state);
  123. bool result = instance->contains(param1);
  124. // Push the return value onto the stack.
  125. lua_pushboolean(state, result);
  126. return 1;
  127. }
  128. lua_pushstring(state, "lua_Bundle_contains - Failed to match the given parameters to a valid function signature.");
  129. lua_error(state);
  130. break;
  131. }
  132. default:
  133. {
  134. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  135. lua_error(state);
  136. break;
  137. }
  138. }
  139. return 0;
  140. }
  141. int lua_Bundle_getObjectCount(lua_State* state)
  142. {
  143. // Get the number of parameters.
  144. int paramCount = lua_gettop(state);
  145. // Attempt to match the parameters to a valid binding.
  146. switch (paramCount)
  147. {
  148. case 1:
  149. {
  150. if ((lua_type(state, 1) == LUA_TUSERDATA))
  151. {
  152. Bundle* instance = getInstance(state);
  153. unsigned int result = instance->getObjectCount();
  154. // Push the return value onto the stack.
  155. lua_pushunsigned(state, result);
  156. return 1;
  157. }
  158. lua_pushstring(state, "lua_Bundle_getObjectCount - Failed to match the given parameters to a valid function signature.");
  159. lua_error(state);
  160. break;
  161. }
  162. default:
  163. {
  164. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  165. lua_error(state);
  166. break;
  167. }
  168. }
  169. return 0;
  170. }
  171. int lua_Bundle_getObjectId(lua_State* state)
  172. {
  173. // Get the number of parameters.
  174. int paramCount = lua_gettop(state);
  175. // Attempt to match the parameters to a valid binding.
  176. switch (paramCount)
  177. {
  178. case 2:
  179. {
  180. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  181. lua_type(state, 2) == LUA_TNUMBER)
  182. {
  183. // Get parameter 1 off the stack.
  184. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  185. Bundle* instance = getInstance(state);
  186. const char* result = instance->getObjectId(param1);
  187. // Push the return value onto the stack.
  188. lua_pushstring(state, result);
  189. return 1;
  190. }
  191. lua_pushstring(state, "lua_Bundle_getObjectId - Failed to match the given parameters to a valid function signature.");
  192. lua_error(state);
  193. break;
  194. }
  195. default:
  196. {
  197. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  198. lua_error(state);
  199. break;
  200. }
  201. }
  202. return 0;
  203. }
  204. int lua_Bundle_getRefCount(lua_State* state)
  205. {
  206. // Get the number of parameters.
  207. int paramCount = lua_gettop(state);
  208. // Attempt to match the parameters to a valid binding.
  209. switch (paramCount)
  210. {
  211. case 1:
  212. {
  213. if ((lua_type(state, 1) == LUA_TUSERDATA))
  214. {
  215. Bundle* instance = getInstance(state);
  216. unsigned int result = instance->getRefCount();
  217. // Push the return value onto the stack.
  218. lua_pushunsigned(state, result);
  219. return 1;
  220. }
  221. lua_pushstring(state, "lua_Bundle_getRefCount - Failed to match the given parameters to a valid function signature.");
  222. lua_error(state);
  223. break;
  224. }
  225. default:
  226. {
  227. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  228. lua_error(state);
  229. break;
  230. }
  231. }
  232. return 0;
  233. }
  234. int lua_Bundle_getVersionMajor(lua_State* state)
  235. {
  236. // Get the number of parameters.
  237. int paramCount = lua_gettop(state);
  238. // Attempt to match the parameters to a valid binding.
  239. switch (paramCount)
  240. {
  241. case 1:
  242. {
  243. if ((lua_type(state, 1) == LUA_TUSERDATA))
  244. {
  245. Bundle* instance = getInstance(state);
  246. unsigned int result = instance->getVersionMajor();
  247. // Push the return value onto the stack.
  248. lua_pushunsigned(state, result);
  249. return 1;
  250. }
  251. lua_pushstring(state, "lua_Bundle_getVersionMajor - Failed to match the given parameters to a valid function signature.");
  252. lua_error(state);
  253. break;
  254. }
  255. default:
  256. {
  257. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  258. lua_error(state);
  259. break;
  260. }
  261. }
  262. return 0;
  263. }
  264. int lua_Bundle_getVersionMinor(lua_State* state)
  265. {
  266. // Get the number of parameters.
  267. int paramCount = lua_gettop(state);
  268. // Attempt to match the parameters to a valid binding.
  269. switch (paramCount)
  270. {
  271. case 1:
  272. {
  273. if ((lua_type(state, 1) == LUA_TUSERDATA))
  274. {
  275. Bundle* instance = getInstance(state);
  276. unsigned int result = instance->getVersionMinor();
  277. // Push the return value onto the stack.
  278. lua_pushunsigned(state, result);
  279. return 1;
  280. }
  281. lua_pushstring(state, "lua_Bundle_getVersionMinor - Failed to match the given parameters to a valid function signature.");
  282. lua_error(state);
  283. break;
  284. }
  285. default:
  286. {
  287. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  288. lua_error(state);
  289. break;
  290. }
  291. }
  292. return 0;
  293. }
  294. int lua_Bundle_loadFont(lua_State* state)
  295. {
  296. // Get the number of parameters.
  297. int paramCount = lua_gettop(state);
  298. // Attempt to match the parameters to a valid binding.
  299. switch (paramCount)
  300. {
  301. case 2:
  302. {
  303. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  304. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  305. {
  306. // Get parameter 1 off the stack.
  307. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  308. Bundle* instance = getInstance(state);
  309. void* returnPtr = (void*)instance->loadFont(param1);
  310. if (returnPtr)
  311. {
  312. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  313. object->instance = returnPtr;
  314. object->owns = true;
  315. luaL_getmetatable(state, "Font");
  316. lua_setmetatable(state, -2);
  317. }
  318. else
  319. {
  320. lua_pushnil(state);
  321. }
  322. return 1;
  323. }
  324. lua_pushstring(state, "lua_Bundle_loadFont - Failed to match the given parameters to a valid function signature.");
  325. lua_error(state);
  326. break;
  327. }
  328. default:
  329. {
  330. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  331. lua_error(state);
  332. break;
  333. }
  334. }
  335. return 0;
  336. }
  337. int lua_Bundle_loadMesh(lua_State* state)
  338. {
  339. // Get the number of parameters.
  340. int paramCount = lua_gettop(state);
  341. // Attempt to match the parameters to a valid binding.
  342. switch (paramCount)
  343. {
  344. case 2:
  345. {
  346. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  347. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  348. {
  349. // Get parameter 1 off the stack.
  350. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  351. Bundle* instance = getInstance(state);
  352. void* returnPtr = (void*)instance->loadMesh(param1);
  353. if (returnPtr)
  354. {
  355. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  356. object->instance = returnPtr;
  357. object->owns = true;
  358. luaL_getmetatable(state, "Mesh");
  359. lua_setmetatable(state, -2);
  360. }
  361. else
  362. {
  363. lua_pushnil(state);
  364. }
  365. return 1;
  366. }
  367. lua_pushstring(state, "lua_Bundle_loadMesh - Failed to match the given parameters to a valid function signature.");
  368. lua_error(state);
  369. break;
  370. }
  371. default:
  372. {
  373. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  374. lua_error(state);
  375. break;
  376. }
  377. }
  378. return 0;
  379. }
  380. int lua_Bundle_loadNode(lua_State* state)
  381. {
  382. // Get the number of parameters.
  383. int paramCount = lua_gettop(state);
  384. // Attempt to match the parameters to a valid binding.
  385. switch (paramCount)
  386. {
  387. case 2:
  388. {
  389. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  390. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  391. {
  392. // Get parameter 1 off the stack.
  393. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  394. Bundle* instance = getInstance(state);
  395. void* returnPtr = (void*)instance->loadNode(param1);
  396. if (returnPtr)
  397. {
  398. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  399. object->instance = returnPtr;
  400. object->owns = true;
  401. luaL_getmetatable(state, "Node");
  402. lua_setmetatable(state, -2);
  403. }
  404. else
  405. {
  406. lua_pushnil(state);
  407. }
  408. return 1;
  409. }
  410. lua_pushstring(state, "lua_Bundle_loadNode - Failed to match the given parameters to a valid function signature.");
  411. lua_error(state);
  412. break;
  413. }
  414. default:
  415. {
  416. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  417. lua_error(state);
  418. break;
  419. }
  420. }
  421. return 0;
  422. }
  423. int lua_Bundle_loadScene(lua_State* state)
  424. {
  425. // Get the number of parameters.
  426. int paramCount = lua_gettop(state);
  427. // Attempt to match the parameters to a valid binding.
  428. switch (paramCount)
  429. {
  430. case 1:
  431. {
  432. if ((lua_type(state, 1) == LUA_TUSERDATA))
  433. {
  434. Bundle* instance = getInstance(state);
  435. void* returnPtr = (void*)instance->loadScene();
  436. if (returnPtr)
  437. {
  438. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  439. object->instance = returnPtr;
  440. object->owns = true;
  441. luaL_getmetatable(state, "Scene");
  442. lua_setmetatable(state, -2);
  443. }
  444. else
  445. {
  446. lua_pushnil(state);
  447. }
  448. return 1;
  449. }
  450. lua_pushstring(state, "lua_Bundle_loadScene - Failed to match the given parameters to a valid function signature.");
  451. lua_error(state);
  452. break;
  453. }
  454. case 2:
  455. {
  456. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  457. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  458. {
  459. // Get parameter 1 off the stack.
  460. const char* param1 = gameplay::ScriptUtil::getString(2, false);
  461. Bundle* instance = getInstance(state);
  462. void* returnPtr = (void*)instance->loadScene(param1);
  463. if (returnPtr)
  464. {
  465. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  466. object->instance = returnPtr;
  467. object->owns = true;
  468. luaL_getmetatable(state, "Scene");
  469. lua_setmetatable(state, -2);
  470. }
  471. else
  472. {
  473. lua_pushnil(state);
  474. }
  475. return 1;
  476. }
  477. lua_pushstring(state, "lua_Bundle_loadScene - Failed to match the given parameters to a valid function signature.");
  478. lua_error(state);
  479. break;
  480. }
  481. default:
  482. {
  483. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  484. lua_error(state);
  485. break;
  486. }
  487. }
  488. return 0;
  489. }
  490. int lua_Bundle_release(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. Bundle* instance = getInstance(state);
  502. instance->release();
  503. return 0;
  504. }
  505. lua_pushstring(state, "lua_Bundle_release - Failed to match the given parameters to a valid function signature.");
  506. lua_error(state);
  507. break;
  508. }
  509. default:
  510. {
  511. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  512. lua_error(state);
  513. break;
  514. }
  515. }
  516. return 0;
  517. }
  518. int lua_Bundle_static_create(lua_State* state)
  519. {
  520. // Get the number of parameters.
  521. int paramCount = lua_gettop(state);
  522. // Attempt to match the parameters to a valid binding.
  523. switch (paramCount)
  524. {
  525. case 1:
  526. {
  527. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  528. {
  529. // Get parameter 1 off the stack.
  530. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  531. void* returnPtr = (void*)Bundle::create(param1);
  532. if (returnPtr)
  533. {
  534. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  535. object->instance = returnPtr;
  536. object->owns = true;
  537. luaL_getmetatable(state, "Bundle");
  538. lua_setmetatable(state, -2);
  539. }
  540. else
  541. {
  542. lua_pushnil(state);
  543. }
  544. return 1;
  545. }
  546. lua_pushstring(state, "lua_Bundle_static_create - Failed to match the given parameters to a valid function signature.");
  547. lua_error(state);
  548. break;
  549. }
  550. default:
  551. {
  552. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  553. lua_error(state);
  554. break;
  555. }
  556. }
  557. return 0;
  558. }
  559. }