lua_Material.cpp 26 KB

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