lua_Material.cpp 26 KB

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