lua_Material.cpp 27 KB

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