lua_Model.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Model.h"
  4. #include "Base.h"
  5. #include "Game.h"
  6. #include "MeshPart.h"
  7. #include "Model.h"
  8. #include "Node.h"
  9. #include "Pass.h"
  10. #include "Ref.h"
  11. #include "Scene.h"
  12. #include "Technique.h"
  13. namespace gameplay
  14. {
  15. void luaRegister_Model()
  16. {
  17. const luaL_Reg lua_members[] =
  18. {
  19. {"addRef", lua_Model_addRef},
  20. {"draw", lua_Model_draw},
  21. {"getMaterial", lua_Model_getMaterial},
  22. {"getMesh", lua_Model_getMesh},
  23. {"getMeshPartCount", lua_Model_getMeshPartCount},
  24. {"getNode", lua_Model_getNode},
  25. {"getRefCount", lua_Model_getRefCount},
  26. {"getSkin", lua_Model_getSkin},
  27. {"hasMaterial", lua_Model_hasMaterial},
  28. {"release", lua_Model_release},
  29. {"setMaterial", lua_Model_setMaterial},
  30. {NULL, NULL}
  31. };
  32. const luaL_Reg lua_statics[] =
  33. {
  34. {"create", lua_Model_static_create},
  35. {NULL, NULL}
  36. };
  37. std::vector<std::string> scopePath;
  38. ScriptUtil::registerClass("Model", lua_members, NULL, lua_Model__gc, lua_statics, scopePath);
  39. }
  40. static Model* getInstance(lua_State* state)
  41. {
  42. void* userdata = luaL_checkudata(state, 1, "Model");
  43. luaL_argcheck(state, userdata != NULL, 1, "'Model' expected.");
  44. return (Model*)((ScriptUtil::LuaObject*)userdata)->instance;
  45. }
  46. int lua_Model__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, "Model");
  58. luaL_argcheck(state, userdata != NULL, 1, "'Model' expected.");
  59. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  60. if (object->owns)
  61. {
  62. Model* instance = (Model*)object->instance;
  63. SAFE_RELEASE(instance);
  64. }
  65. return 0;
  66. }
  67. else
  68. {
  69. lua_pushstring(state, "lua_Model__gc - Failed to match the given parameters to a valid function signature.");
  70. lua_error(state);
  71. }
  72. break;
  73. }
  74. default:
  75. {
  76. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  77. lua_error(state);
  78. break;
  79. }
  80. }
  81. return 0;
  82. }
  83. int lua_Model_addRef(lua_State* state)
  84. {
  85. // Get the number of parameters.
  86. int paramCount = lua_gettop(state);
  87. // Attempt to match the parameters to a valid binding.
  88. switch (paramCount)
  89. {
  90. case 1:
  91. {
  92. if ((lua_type(state, 1) == LUA_TUSERDATA))
  93. {
  94. Model* instance = getInstance(state);
  95. instance->addRef();
  96. return 0;
  97. }
  98. else
  99. {
  100. lua_pushstring(state, "lua_Model_addRef - Failed to match the given parameters to a valid function signature.");
  101. lua_error(state);
  102. }
  103. break;
  104. }
  105. default:
  106. {
  107. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  108. lua_error(state);
  109. break;
  110. }
  111. }
  112. return 0;
  113. }
  114. int lua_Model_draw(lua_State* state)
  115. {
  116. // Get the number of parameters.
  117. int paramCount = lua_gettop(state);
  118. // Attempt to match the parameters to a valid binding.
  119. switch (paramCount)
  120. {
  121. case 1:
  122. {
  123. if ((lua_type(state, 1) == LUA_TUSERDATA))
  124. {
  125. Model* instance = getInstance(state);
  126. instance->draw();
  127. return 0;
  128. }
  129. else
  130. {
  131. lua_pushstring(state, "lua_Model_draw - Failed to match the given parameters to a valid function signature.");
  132. lua_error(state);
  133. }
  134. break;
  135. }
  136. case 2:
  137. {
  138. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  139. lua_type(state, 2) == LUA_TBOOLEAN)
  140. {
  141. // Get parameter 1 off the stack.
  142. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  143. Model* instance = getInstance(state);
  144. instance->draw(param1);
  145. return 0;
  146. }
  147. else
  148. {
  149. lua_pushstring(state, "lua_Model_draw - Failed to match the given parameters to a valid function signature.");
  150. lua_error(state);
  151. }
  152. break;
  153. }
  154. default:
  155. {
  156. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  157. lua_error(state);
  158. break;
  159. }
  160. }
  161. return 0;
  162. }
  163. int lua_Model_getMaterial(lua_State* state)
  164. {
  165. // Get the number of parameters.
  166. int paramCount = lua_gettop(state);
  167. // Attempt to match the parameters to a valid binding.
  168. switch (paramCount)
  169. {
  170. case 1:
  171. {
  172. if ((lua_type(state, 1) == LUA_TUSERDATA))
  173. {
  174. Model* instance = getInstance(state);
  175. void* returnPtr = (void*)instance->getMaterial();
  176. if (returnPtr)
  177. {
  178. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  179. object->instance = returnPtr;
  180. object->owns = false;
  181. luaL_getmetatable(state, "Material");
  182. lua_setmetatable(state, -2);
  183. }
  184. else
  185. {
  186. lua_pushnil(state);
  187. }
  188. return 1;
  189. }
  190. else
  191. {
  192. lua_pushstring(state, "lua_Model_getMaterial - Failed to match the given parameters to a valid function signature.");
  193. lua_error(state);
  194. }
  195. break;
  196. }
  197. case 2:
  198. {
  199. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  200. lua_type(state, 2) == LUA_TNUMBER)
  201. {
  202. // Get parameter 1 off the stack.
  203. int param1 = (int)luaL_checkint(state, 2);
  204. Model* instance = getInstance(state);
  205. void* returnPtr = (void*)instance->getMaterial(param1);
  206. if (returnPtr)
  207. {
  208. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  209. object->instance = returnPtr;
  210. object->owns = false;
  211. luaL_getmetatable(state, "Material");
  212. lua_setmetatable(state, -2);
  213. }
  214. else
  215. {
  216. lua_pushnil(state);
  217. }
  218. return 1;
  219. }
  220. else
  221. {
  222. lua_pushstring(state, "lua_Model_getMaterial - Failed to match the given parameters to a valid function signature.");
  223. lua_error(state);
  224. }
  225. break;
  226. }
  227. default:
  228. {
  229. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  230. lua_error(state);
  231. break;
  232. }
  233. }
  234. return 0;
  235. }
  236. int lua_Model_getMesh(lua_State* state)
  237. {
  238. // Get the number of parameters.
  239. int paramCount = lua_gettop(state);
  240. // Attempt to match the parameters to a valid binding.
  241. switch (paramCount)
  242. {
  243. case 1:
  244. {
  245. if ((lua_type(state, 1) == LUA_TUSERDATA))
  246. {
  247. Model* instance = getInstance(state);
  248. void* returnPtr = (void*)instance->getMesh();
  249. if (returnPtr)
  250. {
  251. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  252. object->instance = returnPtr;
  253. object->owns = false;
  254. luaL_getmetatable(state, "Mesh");
  255. lua_setmetatable(state, -2);
  256. }
  257. else
  258. {
  259. lua_pushnil(state);
  260. }
  261. return 1;
  262. }
  263. else
  264. {
  265. lua_pushstring(state, "lua_Model_getMesh - Failed to match the given parameters to a valid function signature.");
  266. lua_error(state);
  267. }
  268. break;
  269. }
  270. default:
  271. {
  272. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  273. lua_error(state);
  274. break;
  275. }
  276. }
  277. return 0;
  278. }
  279. int lua_Model_getMeshPartCount(lua_State* state)
  280. {
  281. // Get the number of parameters.
  282. int paramCount = lua_gettop(state);
  283. // Attempt to match the parameters to a valid binding.
  284. switch (paramCount)
  285. {
  286. case 1:
  287. {
  288. if ((lua_type(state, 1) == LUA_TUSERDATA))
  289. {
  290. Model* instance = getInstance(state);
  291. unsigned int result = instance->getMeshPartCount();
  292. // Push the return value onto the stack.
  293. lua_pushunsigned(state, result);
  294. return 1;
  295. }
  296. else
  297. {
  298. lua_pushstring(state, "lua_Model_getMeshPartCount - Failed to match the given parameters to a valid function signature.");
  299. lua_error(state);
  300. }
  301. break;
  302. }
  303. default:
  304. {
  305. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  306. lua_error(state);
  307. break;
  308. }
  309. }
  310. return 0;
  311. }
  312. int lua_Model_getNode(lua_State* state)
  313. {
  314. // Get the number of parameters.
  315. int paramCount = lua_gettop(state);
  316. // Attempt to match the parameters to a valid binding.
  317. switch (paramCount)
  318. {
  319. case 1:
  320. {
  321. if ((lua_type(state, 1) == LUA_TUSERDATA))
  322. {
  323. Model* instance = getInstance(state);
  324. void* returnPtr = (void*)instance->getNode();
  325. if (returnPtr)
  326. {
  327. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  328. object->instance = returnPtr;
  329. object->owns = false;
  330. luaL_getmetatable(state, "Node");
  331. lua_setmetatable(state, -2);
  332. }
  333. else
  334. {
  335. lua_pushnil(state);
  336. }
  337. return 1;
  338. }
  339. else
  340. {
  341. lua_pushstring(state, "lua_Model_getNode - Failed to match the given parameters to a valid function signature.");
  342. lua_error(state);
  343. }
  344. break;
  345. }
  346. default:
  347. {
  348. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  349. lua_error(state);
  350. break;
  351. }
  352. }
  353. return 0;
  354. }
  355. int lua_Model_getRefCount(lua_State* state)
  356. {
  357. // Get the number of parameters.
  358. int paramCount = lua_gettop(state);
  359. // Attempt to match the parameters to a valid binding.
  360. switch (paramCount)
  361. {
  362. case 1:
  363. {
  364. if ((lua_type(state, 1) == LUA_TUSERDATA))
  365. {
  366. Model* instance = getInstance(state);
  367. unsigned int result = instance->getRefCount();
  368. // Push the return value onto the stack.
  369. lua_pushunsigned(state, result);
  370. return 1;
  371. }
  372. else
  373. {
  374. lua_pushstring(state, "lua_Model_getRefCount - Failed to match the given parameters to a valid function signature.");
  375. lua_error(state);
  376. }
  377. break;
  378. }
  379. default:
  380. {
  381. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  382. lua_error(state);
  383. break;
  384. }
  385. }
  386. return 0;
  387. }
  388. int lua_Model_getSkin(lua_State* state)
  389. {
  390. // Get the number of parameters.
  391. int paramCount = lua_gettop(state);
  392. // Attempt to match the parameters to a valid binding.
  393. switch (paramCount)
  394. {
  395. case 1:
  396. {
  397. if ((lua_type(state, 1) == LUA_TUSERDATA))
  398. {
  399. Model* instance = getInstance(state);
  400. void* returnPtr = (void*)instance->getSkin();
  401. if (returnPtr)
  402. {
  403. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  404. object->instance = returnPtr;
  405. object->owns = false;
  406. luaL_getmetatable(state, "MeshSkin");
  407. lua_setmetatable(state, -2);
  408. }
  409. else
  410. {
  411. lua_pushnil(state);
  412. }
  413. return 1;
  414. }
  415. else
  416. {
  417. lua_pushstring(state, "lua_Model_getSkin - Failed to match the given parameters to a valid function signature.");
  418. lua_error(state);
  419. }
  420. break;
  421. }
  422. default:
  423. {
  424. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  425. lua_error(state);
  426. break;
  427. }
  428. }
  429. return 0;
  430. }
  431. int lua_Model_hasMaterial(lua_State* state)
  432. {
  433. // Get the number of parameters.
  434. int paramCount = lua_gettop(state);
  435. // Attempt to match the parameters to a valid binding.
  436. switch (paramCount)
  437. {
  438. case 2:
  439. {
  440. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  441. lua_type(state, 2) == LUA_TNUMBER)
  442. {
  443. // Get parameter 1 off the stack.
  444. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  445. Model* instance = getInstance(state);
  446. bool result = instance->hasMaterial(param1);
  447. // Push the return value onto the stack.
  448. lua_pushboolean(state, result);
  449. return 1;
  450. }
  451. else
  452. {
  453. lua_pushstring(state, "lua_Model_hasMaterial - Failed to match the given parameters to a valid function signature.");
  454. lua_error(state);
  455. }
  456. break;
  457. }
  458. default:
  459. {
  460. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  461. lua_error(state);
  462. break;
  463. }
  464. }
  465. return 0;
  466. }
  467. int lua_Model_release(lua_State* state)
  468. {
  469. // Get the number of parameters.
  470. int paramCount = lua_gettop(state);
  471. // Attempt to match the parameters to a valid binding.
  472. switch (paramCount)
  473. {
  474. case 1:
  475. {
  476. if ((lua_type(state, 1) == LUA_TUSERDATA))
  477. {
  478. Model* instance = getInstance(state);
  479. instance->release();
  480. return 0;
  481. }
  482. else
  483. {
  484. lua_pushstring(state, "lua_Model_release - Failed to match the given parameters to a valid function signature.");
  485. lua_error(state);
  486. }
  487. break;
  488. }
  489. default:
  490. {
  491. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  492. lua_error(state);
  493. break;
  494. }
  495. }
  496. return 0;
  497. }
  498. int lua_Model_setMaterial(lua_State* state)
  499. {
  500. // Get the number of parameters.
  501. int paramCount = lua_gettop(state);
  502. // Attempt to match the parameters to a valid binding.
  503. switch (paramCount)
  504. {
  505. case 2:
  506. {
  507. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  508. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  509. {
  510. // Get parameter 1 off the stack.
  511. ScriptUtil::LuaArray<Material> param1 = ScriptUtil::getObjectPointer<Material>(2, "Material", false);
  512. Model* instance = getInstance(state);
  513. instance->setMaterial(param1);
  514. return 0;
  515. }
  516. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  517. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  518. {
  519. // Get parameter 1 off the stack.
  520. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  521. Model* instance = getInstance(state);
  522. void* returnPtr = (void*)instance->setMaterial(param1);
  523. if (returnPtr)
  524. {
  525. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  526. object->instance = returnPtr;
  527. object->owns = false;
  528. luaL_getmetatable(state, "Material");
  529. lua_setmetatable(state, -2);
  530. }
  531. else
  532. {
  533. lua_pushnil(state);
  534. }
  535. return 1;
  536. }
  537. else
  538. {
  539. lua_pushstring(state, "lua_Model_setMaterial - Failed to match the given parameters to a valid function signature.");
  540. lua_error(state);
  541. }
  542. break;
  543. }
  544. case 3:
  545. {
  546. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  547. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  548. lua_type(state, 3) == LUA_TNUMBER)
  549. {
  550. // Get parameter 1 off the stack.
  551. ScriptUtil::LuaArray<Material> param1 = ScriptUtil::getObjectPointer<Material>(2, "Material", false);
  552. // Get parameter 2 off the stack.
  553. int param2 = (int)luaL_checkint(state, 3);
  554. Model* instance = getInstance(state);
  555. instance->setMaterial(param1, param2);
  556. return 0;
  557. }
  558. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  559. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  560. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  561. {
  562. // Get parameter 1 off the stack.
  563. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  564. // Get parameter 2 off the stack.
  565. ScriptUtil::LuaArray<const char> param2 = ScriptUtil::getString(3, false);
  566. Model* instance = getInstance(state);
  567. void* returnPtr = (void*)instance->setMaterial(param1, param2);
  568. if (returnPtr)
  569. {
  570. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  571. object->instance = returnPtr;
  572. object->owns = false;
  573. luaL_getmetatable(state, "Material");
  574. lua_setmetatable(state, -2);
  575. }
  576. else
  577. {
  578. lua_pushnil(state);
  579. }
  580. return 1;
  581. }
  582. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  583. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  584. lua_type(state, 3) == LUA_TNUMBER)
  585. {
  586. // Get parameter 1 off the stack.
  587. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  588. // Get parameter 2 off the stack.
  589. int param2 = (int)luaL_checkint(state, 3);
  590. Model* instance = getInstance(state);
  591. void* returnPtr = (void*)instance->setMaterial(param1, param2);
  592. if (returnPtr)
  593. {
  594. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  595. object->instance = returnPtr;
  596. object->owns = false;
  597. luaL_getmetatable(state, "Material");
  598. lua_setmetatable(state, -2);
  599. }
  600. else
  601. {
  602. lua_pushnil(state);
  603. }
  604. return 1;
  605. }
  606. else
  607. {
  608. lua_pushstring(state, "lua_Model_setMaterial - Failed to match the given parameters to a valid function signature.");
  609. lua_error(state);
  610. }
  611. break;
  612. }
  613. case 4:
  614. {
  615. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  616. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  617. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
  618. (lua_type(state, 4) == LUA_TSTRING || lua_type(state, 4) == LUA_TNIL))
  619. {
  620. // Get parameter 1 off the stack.
  621. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  622. // Get parameter 2 off the stack.
  623. ScriptUtil::LuaArray<const char> param2 = ScriptUtil::getString(3, false);
  624. // Get parameter 3 off the stack.
  625. ScriptUtil::LuaArray<const char> param3 = ScriptUtil::getString(4, false);
  626. Model* instance = getInstance(state);
  627. void* returnPtr = (void*)instance->setMaterial(param1, param2, param3);
  628. if (returnPtr)
  629. {
  630. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  631. object->instance = returnPtr;
  632. object->owns = false;
  633. luaL_getmetatable(state, "Material");
  634. lua_setmetatable(state, -2);
  635. }
  636. else
  637. {
  638. lua_pushnil(state);
  639. }
  640. return 1;
  641. }
  642. else
  643. {
  644. lua_pushstring(state, "lua_Model_setMaterial - Failed to match the given parameters to a valid function signature.");
  645. lua_error(state);
  646. }
  647. break;
  648. }
  649. case 5:
  650. {
  651. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  652. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  653. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
  654. (lua_type(state, 4) == LUA_TSTRING || lua_type(state, 4) == LUA_TNIL) &&
  655. lua_type(state, 5) == LUA_TNUMBER)
  656. {
  657. // Get parameter 1 off the stack.
  658. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  659. // Get parameter 2 off the stack.
  660. ScriptUtil::LuaArray<const char> param2 = ScriptUtil::getString(3, false);
  661. // Get parameter 3 off the stack.
  662. ScriptUtil::LuaArray<const char> param3 = ScriptUtil::getString(4, false);
  663. // Get parameter 4 off the stack.
  664. int param4 = (int)luaL_checkint(state, 5);
  665. Model* instance = getInstance(state);
  666. void* returnPtr = (void*)instance->setMaterial(param1, param2, param3, param4);
  667. if (returnPtr)
  668. {
  669. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  670. object->instance = returnPtr;
  671. object->owns = false;
  672. luaL_getmetatable(state, "Material");
  673. lua_setmetatable(state, -2);
  674. }
  675. else
  676. {
  677. lua_pushnil(state);
  678. }
  679. return 1;
  680. }
  681. else
  682. {
  683. lua_pushstring(state, "lua_Model_setMaterial - Failed to match the given parameters to a valid function signature.");
  684. lua_error(state);
  685. }
  686. break;
  687. }
  688. default:
  689. {
  690. lua_pushstring(state, "Invalid number of parameters (expected 2, 3, 4 or 5).");
  691. lua_error(state);
  692. break;
  693. }
  694. }
  695. return 0;
  696. }
  697. int lua_Model_static_create(lua_State* state)
  698. {
  699. // Get the number of parameters.
  700. int paramCount = lua_gettop(state);
  701. // Attempt to match the parameters to a valid binding.
  702. switch (paramCount)
  703. {
  704. case 1:
  705. {
  706. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL))
  707. {
  708. // Get parameter 1 off the stack.
  709. ScriptUtil::LuaArray<Mesh> param1 = ScriptUtil::getObjectPointer<Mesh>(1, "Mesh", false);
  710. void* returnPtr = (void*)Model::create(param1);
  711. if (returnPtr)
  712. {
  713. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  714. object->instance = returnPtr;
  715. object->owns = true;
  716. luaL_getmetatable(state, "Model");
  717. lua_setmetatable(state, -2);
  718. }
  719. else
  720. {
  721. lua_pushnil(state);
  722. }
  723. return 1;
  724. }
  725. else
  726. {
  727. lua_pushstring(state, "lua_Model_static_create - Failed to match the given parameters to a valid function signature.");
  728. lua_error(state);
  729. }
  730. break;
  731. }
  732. default:
  733. {
  734. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  735. lua_error(state);
  736. break;
  737. }
  738. }
  739. return 0;
  740. }
  741. }