lua_MeshBatch.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_MeshBatch.h"
  4. #include "Base.h"
  5. #include "MeshBatch.h"
  6. #include "lua_MeshPrimitiveType.h"
  7. namespace gameplay
  8. {
  9. void luaRegister_MeshBatch()
  10. {
  11. const luaL_Reg lua_members[] =
  12. {
  13. {"draw", lua_MeshBatch_draw},
  14. {"finish", lua_MeshBatch_finish},
  15. {"getCapacity", lua_MeshBatch_getCapacity},
  16. {"getMaterial", lua_MeshBatch_getMaterial},
  17. {"setCapacity", lua_MeshBatch_setCapacity},
  18. {"start", lua_MeshBatch_start},
  19. {NULL, NULL}
  20. };
  21. const luaL_Reg lua_statics[] =
  22. {
  23. {"create", lua_MeshBatch_static_create},
  24. {NULL, NULL}
  25. };
  26. std::vector<std::string> scopePath;
  27. ScriptUtil::registerClass("MeshBatch", lua_members, NULL, lua_MeshBatch__gc, lua_statics, scopePath);
  28. }
  29. static MeshBatch* getInstance(lua_State* state)
  30. {
  31. void* userdata = luaL_checkudata(state, 1, "MeshBatch");
  32. luaL_argcheck(state, userdata != NULL, 1, "'MeshBatch' expected.");
  33. return (MeshBatch*)((ScriptUtil::LuaObject*)userdata)->instance;
  34. }
  35. int lua_MeshBatch__gc(lua_State* state)
  36. {
  37. // Get the number of parameters.
  38. int paramCount = lua_gettop(state);
  39. // Attempt to match the parameters to a valid binding.
  40. switch (paramCount)
  41. {
  42. case 1:
  43. {
  44. if ((lua_type(state, 1) == LUA_TUSERDATA))
  45. {
  46. void* userdata = luaL_checkudata(state, 1, "MeshBatch");
  47. luaL_argcheck(state, userdata != NULL, 1, "'MeshBatch' expected.");
  48. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  49. if (object->owns)
  50. {
  51. MeshBatch* instance = (MeshBatch*)object->instance;
  52. SAFE_DELETE(instance);
  53. }
  54. return 0;
  55. }
  56. else
  57. {
  58. lua_pushstring(state, "lua_MeshBatch__gc - Failed to match the given parameters to a valid function signature.");
  59. lua_error(state);
  60. }
  61. break;
  62. }
  63. default:
  64. {
  65. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  66. lua_error(state);
  67. break;
  68. }
  69. }
  70. return 0;
  71. }
  72. int lua_MeshBatch_draw(lua_State* state)
  73. {
  74. // Get the number of parameters.
  75. int paramCount = lua_gettop(state);
  76. // Attempt to match the parameters to a valid binding.
  77. switch (paramCount)
  78. {
  79. case 1:
  80. {
  81. if ((lua_type(state, 1) == LUA_TUSERDATA))
  82. {
  83. MeshBatch* instance = getInstance(state);
  84. instance->draw();
  85. return 0;
  86. }
  87. else
  88. {
  89. lua_pushstring(state, "lua_MeshBatch_draw - Failed to match the given parameters to a valid function signature.");
  90. lua_error(state);
  91. }
  92. break;
  93. }
  94. default:
  95. {
  96. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  97. lua_error(state);
  98. break;
  99. }
  100. }
  101. return 0;
  102. }
  103. int lua_MeshBatch_finish(lua_State* state)
  104. {
  105. // Get the number of parameters.
  106. int paramCount = lua_gettop(state);
  107. // Attempt to match the parameters to a valid binding.
  108. switch (paramCount)
  109. {
  110. case 1:
  111. {
  112. if ((lua_type(state, 1) == LUA_TUSERDATA))
  113. {
  114. MeshBatch* instance = getInstance(state);
  115. instance->finish();
  116. return 0;
  117. }
  118. else
  119. {
  120. lua_pushstring(state, "lua_MeshBatch_finish - Failed to match the given parameters to a valid function signature.");
  121. lua_error(state);
  122. }
  123. break;
  124. }
  125. default:
  126. {
  127. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  128. lua_error(state);
  129. break;
  130. }
  131. }
  132. return 0;
  133. }
  134. int lua_MeshBatch_getCapacity(lua_State* state)
  135. {
  136. // Get the number of parameters.
  137. int paramCount = lua_gettop(state);
  138. // Attempt to match the parameters to a valid binding.
  139. switch (paramCount)
  140. {
  141. case 1:
  142. {
  143. if ((lua_type(state, 1) == LUA_TUSERDATA))
  144. {
  145. MeshBatch* instance = getInstance(state);
  146. unsigned int result = instance->getCapacity();
  147. // Push the return value onto the stack.
  148. lua_pushunsigned(state, result);
  149. return 1;
  150. }
  151. else
  152. {
  153. lua_pushstring(state, "lua_MeshBatch_getCapacity - Failed to match the given parameters to a valid function signature.");
  154. lua_error(state);
  155. }
  156. break;
  157. }
  158. default:
  159. {
  160. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  161. lua_error(state);
  162. break;
  163. }
  164. }
  165. return 0;
  166. }
  167. int lua_MeshBatch_getMaterial(lua_State* state)
  168. {
  169. // Get the number of parameters.
  170. int paramCount = lua_gettop(state);
  171. // Attempt to match the parameters to a valid binding.
  172. switch (paramCount)
  173. {
  174. case 1:
  175. {
  176. if ((lua_type(state, 1) == LUA_TUSERDATA))
  177. {
  178. MeshBatch* instance = getInstance(state);
  179. void* returnPtr = (void*)instance->getMaterial();
  180. if (returnPtr)
  181. {
  182. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  183. object->instance = returnPtr;
  184. object->owns = false;
  185. luaL_getmetatable(state, "Material");
  186. lua_setmetatable(state, -2);
  187. }
  188. else
  189. {
  190. lua_pushnil(state);
  191. }
  192. return 1;
  193. }
  194. else
  195. {
  196. lua_pushstring(state, "lua_MeshBatch_getMaterial - Failed to match the given parameters to a valid function signature.");
  197. lua_error(state);
  198. }
  199. break;
  200. }
  201. default:
  202. {
  203. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  204. lua_error(state);
  205. break;
  206. }
  207. }
  208. return 0;
  209. }
  210. int lua_MeshBatch_setCapacity(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 2:
  218. {
  219. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  220. lua_type(state, 2) == LUA_TNUMBER)
  221. {
  222. // Get parameter 1 off the stack.
  223. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  224. MeshBatch* instance = getInstance(state);
  225. instance->setCapacity(param1);
  226. return 0;
  227. }
  228. else
  229. {
  230. lua_pushstring(state, "lua_MeshBatch_setCapacity - Failed to match the given parameters to a valid function signature.");
  231. lua_error(state);
  232. }
  233. break;
  234. }
  235. default:
  236. {
  237. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  238. lua_error(state);
  239. break;
  240. }
  241. }
  242. return 0;
  243. }
  244. int lua_MeshBatch_start(lua_State* state)
  245. {
  246. // Get the number of parameters.
  247. int paramCount = lua_gettop(state);
  248. // Attempt to match the parameters to a valid binding.
  249. switch (paramCount)
  250. {
  251. case 1:
  252. {
  253. if ((lua_type(state, 1) == LUA_TUSERDATA))
  254. {
  255. MeshBatch* instance = getInstance(state);
  256. instance->start();
  257. return 0;
  258. }
  259. else
  260. {
  261. lua_pushstring(state, "lua_MeshBatch_start - Failed to match the given parameters to a valid function signature.");
  262. lua_error(state);
  263. }
  264. break;
  265. }
  266. default:
  267. {
  268. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  269. lua_error(state);
  270. break;
  271. }
  272. }
  273. return 0;
  274. }
  275. int lua_MeshBatch_static_create(lua_State* state)
  276. {
  277. // Get the number of parameters.
  278. int paramCount = lua_gettop(state);
  279. // Attempt to match the parameters to a valid binding.
  280. switch (paramCount)
  281. {
  282. case 4:
  283. {
  284. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  285. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  286. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
  287. lua_type(state, 4) == LUA_TBOOLEAN)
  288. {
  289. // Get parameter 1 off the stack.
  290. VertexFormat* param1 = ScriptUtil::getObjectPointer<VertexFormat>(1, "VertexFormat", true);
  291. // Get parameter 2 off the stack.
  292. Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
  293. // Get parameter 3 off the stack.
  294. const char* param3 = ScriptUtil::getString(3, false);
  295. // Get parameter 4 off the stack.
  296. bool param4 = ScriptUtil::luaCheckBool(state, 4);
  297. void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4);
  298. if (returnPtr)
  299. {
  300. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  301. object->instance = returnPtr;
  302. object->owns = true;
  303. luaL_getmetatable(state, "MeshBatch");
  304. lua_setmetatable(state, -2);
  305. }
  306. else
  307. {
  308. lua_pushnil(state);
  309. }
  310. return 1;
  311. }
  312. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  313. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  314. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL) &&
  315. lua_type(state, 4) == LUA_TBOOLEAN)
  316. {
  317. // Get parameter 1 off the stack.
  318. VertexFormat* param1 = ScriptUtil::getObjectPointer<VertexFormat>(1, "VertexFormat", true);
  319. // Get parameter 2 off the stack.
  320. Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
  321. // Get parameter 3 off the stack.
  322. Material* param3 = ScriptUtil::getObjectPointer<Material>(3, "Material", false);
  323. // Get parameter 4 off the stack.
  324. bool param4 = ScriptUtil::luaCheckBool(state, 4);
  325. void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4);
  326. if (returnPtr)
  327. {
  328. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  329. object->instance = returnPtr;
  330. object->owns = true;
  331. luaL_getmetatable(state, "MeshBatch");
  332. lua_setmetatable(state, -2);
  333. }
  334. else
  335. {
  336. lua_pushnil(state);
  337. }
  338. return 1;
  339. }
  340. else
  341. {
  342. lua_pushstring(state, "lua_MeshBatch_static_create - Failed to match the given parameters to a valid function signature.");
  343. lua_error(state);
  344. }
  345. break;
  346. }
  347. case 5:
  348. {
  349. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  350. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  351. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
  352. lua_type(state, 4) == LUA_TBOOLEAN &&
  353. lua_type(state, 5) == LUA_TNUMBER)
  354. {
  355. // Get parameter 1 off the stack.
  356. VertexFormat* param1 = ScriptUtil::getObjectPointer<VertexFormat>(1, "VertexFormat", true);
  357. // Get parameter 2 off the stack.
  358. Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
  359. // Get parameter 3 off the stack.
  360. const char* param3 = ScriptUtil::getString(3, false);
  361. // Get parameter 4 off the stack.
  362. bool param4 = ScriptUtil::luaCheckBool(state, 4);
  363. // Get parameter 5 off the stack.
  364. unsigned int param5 = (unsigned int)luaL_checkunsigned(state, 5);
  365. void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4, param5);
  366. if (returnPtr)
  367. {
  368. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  369. object->instance = returnPtr;
  370. object->owns = true;
  371. luaL_getmetatable(state, "MeshBatch");
  372. lua_setmetatable(state, -2);
  373. }
  374. else
  375. {
  376. lua_pushnil(state);
  377. }
  378. return 1;
  379. }
  380. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  381. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  382. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL) &&
  383. lua_type(state, 4) == LUA_TBOOLEAN &&
  384. lua_type(state, 5) == LUA_TNUMBER)
  385. {
  386. // Get parameter 1 off the stack.
  387. VertexFormat* param1 = ScriptUtil::getObjectPointer<VertexFormat>(1, "VertexFormat", true);
  388. // Get parameter 2 off the stack.
  389. Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
  390. // Get parameter 3 off the stack.
  391. Material* param3 = ScriptUtil::getObjectPointer<Material>(3, "Material", false);
  392. // Get parameter 4 off the stack.
  393. bool param4 = ScriptUtil::luaCheckBool(state, 4);
  394. // Get parameter 5 off the stack.
  395. unsigned int param5 = (unsigned int)luaL_checkunsigned(state, 5);
  396. void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4, param5);
  397. if (returnPtr)
  398. {
  399. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  400. object->instance = returnPtr;
  401. object->owns = true;
  402. luaL_getmetatable(state, "MeshBatch");
  403. lua_setmetatable(state, -2);
  404. }
  405. else
  406. {
  407. lua_pushnil(state);
  408. }
  409. return 1;
  410. }
  411. else
  412. {
  413. lua_pushstring(state, "lua_MeshBatch_static_create - Failed to match the given parameters to a valid function signature.");
  414. lua_error(state);
  415. }
  416. break;
  417. }
  418. case 6:
  419. {
  420. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  421. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  422. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
  423. lua_type(state, 4) == LUA_TBOOLEAN &&
  424. lua_type(state, 5) == LUA_TNUMBER &&
  425. lua_type(state, 6) == LUA_TNUMBER)
  426. {
  427. // Get parameter 1 off the stack.
  428. VertexFormat* param1 = ScriptUtil::getObjectPointer<VertexFormat>(1, "VertexFormat", true);
  429. // Get parameter 2 off the stack.
  430. Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
  431. // Get parameter 3 off the stack.
  432. const char* param3 = ScriptUtil::getString(3, false);
  433. // Get parameter 4 off the stack.
  434. bool param4 = ScriptUtil::luaCheckBool(state, 4);
  435. // Get parameter 5 off the stack.
  436. unsigned int param5 = (unsigned int)luaL_checkunsigned(state, 5);
  437. // Get parameter 6 off the stack.
  438. unsigned int param6 = (unsigned int)luaL_checkunsigned(state, 6);
  439. void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4, param5, param6);
  440. if (returnPtr)
  441. {
  442. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  443. object->instance = returnPtr;
  444. object->owns = true;
  445. luaL_getmetatable(state, "MeshBatch");
  446. lua_setmetatable(state, -2);
  447. }
  448. else
  449. {
  450. lua_pushnil(state);
  451. }
  452. return 1;
  453. }
  454. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  455. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  456. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL) &&
  457. lua_type(state, 4) == LUA_TBOOLEAN &&
  458. lua_type(state, 5) == LUA_TNUMBER &&
  459. lua_type(state, 6) == LUA_TNUMBER)
  460. {
  461. // Get parameter 1 off the stack.
  462. VertexFormat* param1 = ScriptUtil::getObjectPointer<VertexFormat>(1, "VertexFormat", true);
  463. // Get parameter 2 off the stack.
  464. Mesh::PrimitiveType param2 = (Mesh::PrimitiveType)lua_enumFromString_MeshPrimitiveType(luaL_checkstring(state, 2));
  465. // Get parameter 3 off the stack.
  466. Material* param3 = ScriptUtil::getObjectPointer<Material>(3, "Material", false);
  467. // Get parameter 4 off the stack.
  468. bool param4 = ScriptUtil::luaCheckBool(state, 4);
  469. // Get parameter 5 off the stack.
  470. unsigned int param5 = (unsigned int)luaL_checkunsigned(state, 5);
  471. // Get parameter 6 off the stack.
  472. unsigned int param6 = (unsigned int)luaL_checkunsigned(state, 6);
  473. void* returnPtr = (void*)MeshBatch::create(*param1, param2, param3, param4, param5, param6);
  474. if (returnPtr)
  475. {
  476. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  477. object->instance = returnPtr;
  478. object->owns = true;
  479. luaL_getmetatable(state, "MeshBatch");
  480. lua_setmetatable(state, -2);
  481. }
  482. else
  483. {
  484. lua_pushnil(state);
  485. }
  486. return 1;
  487. }
  488. else
  489. {
  490. lua_pushstring(state, "lua_MeshBatch_static_create - Failed to match the given parameters to a valid function signature.");
  491. lua_error(state);
  492. }
  493. break;
  494. }
  495. default:
  496. {
  497. lua_pushstring(state, "Invalid number of parameters (expected 4, 5 or 6).");
  498. lua_error(state);
  499. break;
  500. }
  501. }
  502. return 0;
  503. }
  504. }