lua_Material.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. {"getParameter", lua_Material_getParameter},
  25. {"getRefCount", lua_Material_getRefCount},
  26. {"getStateBlock", lua_Material_getStateBlock},
  27. {"getTechnique", lua_Material_getTechnique},
  28. {"getTechniqueByIndex", lua_Material_getTechniqueByIndex},
  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_getParameter(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_TSTRING || lua_type(state, 2) == LUA_TNIL))
  129. {
  130. // Get parameter 1 off the stack.
  131. const char* param1 = ScriptUtil::getString(2, false);
  132. Material* instance = getInstance(state);
  133. void* returnPtr = (void*)instance->getParameter(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, "MaterialParameter");
  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_getParameter - 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_getRefCount(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 1:
  172. {
  173. if ((lua_type(state, 1) == LUA_TUSERDATA))
  174. {
  175. Material* instance = getInstance(state);
  176. unsigned int result = instance->getRefCount();
  177. // Push the return value onto the stack.
  178. lua_pushunsigned(state, result);
  179. return 1;
  180. }
  181. else
  182. {
  183. lua_pushstring(state, "lua_Material_getRefCount - Failed to match the given parameters to a valid function signature.");
  184. lua_error(state);
  185. }
  186. break;
  187. }
  188. default:
  189. {
  190. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  191. lua_error(state);
  192. break;
  193. }
  194. }
  195. return 0;
  196. }
  197. int lua_Material_getStateBlock(lua_State* state)
  198. {
  199. // Get the number of parameters.
  200. int paramCount = lua_gettop(state);
  201. // Attempt to match the parameters to a valid binding.
  202. switch (paramCount)
  203. {
  204. case 1:
  205. {
  206. if ((lua_type(state, 1) == LUA_TUSERDATA))
  207. {
  208. Material* instance = getInstance(state);
  209. void* returnPtr = (void*)instance->getStateBlock();
  210. if (returnPtr)
  211. {
  212. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  213. object->instance = returnPtr;
  214. object->owns = false;
  215. luaL_getmetatable(state, "RenderStateStateBlock");
  216. lua_setmetatable(state, -2);
  217. }
  218. else
  219. {
  220. lua_pushnil(state);
  221. }
  222. return 1;
  223. }
  224. else
  225. {
  226. lua_pushstring(state, "lua_Material_getStateBlock - Failed to match the given parameters to a valid function signature.");
  227. lua_error(state);
  228. }
  229. break;
  230. }
  231. default:
  232. {
  233. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  234. lua_error(state);
  235. break;
  236. }
  237. }
  238. return 0;
  239. }
  240. int lua_Material_getTechnique(lua_State* state)
  241. {
  242. // Get the number of parameters.
  243. int paramCount = lua_gettop(state);
  244. // Attempt to match the parameters to a valid binding.
  245. switch (paramCount)
  246. {
  247. case 1:
  248. {
  249. if ((lua_type(state, 1) == LUA_TUSERDATA))
  250. {
  251. Material* instance = getInstance(state);
  252. void* returnPtr = (void*)instance->getTechnique();
  253. if (returnPtr)
  254. {
  255. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  256. object->instance = returnPtr;
  257. object->owns = false;
  258. luaL_getmetatable(state, "Technique");
  259. lua_setmetatable(state, -2);
  260. }
  261. else
  262. {
  263. lua_pushnil(state);
  264. }
  265. return 1;
  266. }
  267. else
  268. {
  269. lua_pushstring(state, "lua_Material_getTechnique - Failed to match the given parameters to a valid function signature.");
  270. lua_error(state);
  271. }
  272. break;
  273. }
  274. case 2:
  275. {
  276. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  277. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  278. {
  279. // Get parameter 1 off the stack.
  280. const char* param1 = ScriptUtil::getString(2, false);
  281. Material* instance = getInstance(state);
  282. void* returnPtr = (void*)instance->getTechnique(param1);
  283. if (returnPtr)
  284. {
  285. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  286. object->instance = returnPtr;
  287. object->owns = false;
  288. luaL_getmetatable(state, "Technique");
  289. lua_setmetatable(state, -2);
  290. }
  291. else
  292. {
  293. lua_pushnil(state);
  294. }
  295. return 1;
  296. }
  297. else
  298. {
  299. lua_pushstring(state, "lua_Material_getTechnique - Failed to match the given parameters to a valid function signature.");
  300. lua_error(state);
  301. }
  302. break;
  303. }
  304. default:
  305. {
  306. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  307. lua_error(state);
  308. break;
  309. }
  310. }
  311. return 0;
  312. }
  313. int lua_Material_getTechniqueByIndex(lua_State* state)
  314. {
  315. // Get the number of parameters.
  316. int paramCount = lua_gettop(state);
  317. // Attempt to match the parameters to a valid binding.
  318. switch (paramCount)
  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->getTechniqueByIndex(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
  344. {
  345. lua_pushstring(state, "lua_Material_getTechniqueByIndex - Failed to match the given parameters to a valid function signature.");
  346. lua_error(state);
  347. }
  348. break;
  349. }
  350. default:
  351. {
  352. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  353. lua_error(state);
  354. break;
  355. }
  356. }
  357. return 0;
  358. }
  359. int lua_Material_getTechniqueCount(lua_State* state)
  360. {
  361. // Get the number of parameters.
  362. int paramCount = lua_gettop(state);
  363. // Attempt to match the parameters to a valid binding.
  364. switch (paramCount)
  365. {
  366. case 1:
  367. {
  368. if ((lua_type(state, 1) == LUA_TUSERDATA))
  369. {
  370. Material* instance = getInstance(state);
  371. unsigned int result = instance->getTechniqueCount();
  372. // Push the return value onto the stack.
  373. lua_pushunsigned(state, result);
  374. return 1;
  375. }
  376. else
  377. {
  378. lua_pushstring(state, "lua_Material_getTechniqueCount - Failed to match the given parameters to a valid function signature.");
  379. lua_error(state);
  380. }
  381. break;
  382. }
  383. default:
  384. {
  385. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  386. lua_error(state);
  387. break;
  388. }
  389. }
  390. return 0;
  391. }
  392. int lua_Material_release(lua_State* state)
  393. {
  394. // Get the number of parameters.
  395. int paramCount = lua_gettop(state);
  396. // Attempt to match the parameters to a valid binding.
  397. switch (paramCount)
  398. {
  399. case 1:
  400. {
  401. if ((lua_type(state, 1) == LUA_TUSERDATA))
  402. {
  403. Material* instance = getInstance(state);
  404. instance->release();
  405. return 0;
  406. }
  407. else
  408. {
  409. lua_pushstring(state, "lua_Material_release - Failed to match the given parameters to a valid function signature.");
  410. lua_error(state);
  411. }
  412. break;
  413. }
  414. default:
  415. {
  416. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  417. lua_error(state);
  418. break;
  419. }
  420. }
  421. return 0;
  422. }
  423. int lua_Material_setParameterAutoBinding(lua_State* state)
  424. {
  425. // Get the number of parameters.
  426. int paramCount = lua_gettop(state);
  427. // Attempt to match the parameters to a valid binding.
  428. switch (paramCount)
  429. {
  430. case 3:
  431. {
  432. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  433. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  434. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  435. {
  436. // Get parameter 1 off the stack.
  437. const char* param1 = ScriptUtil::getString(2, false);
  438. // Get parameter 2 off the stack.
  439. RenderState::AutoBinding param2 = (RenderState::AutoBinding)lua_enumFromString_RenderStateAutoBinding(luaL_checkstring(state, 3));
  440. Material* instance = getInstance(state);
  441. instance->setParameterAutoBinding(param1, param2);
  442. return 0;
  443. }
  444. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  445. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  446. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  447. {
  448. // Get parameter 1 off the stack.
  449. const char* param1 = ScriptUtil::getString(2, false);
  450. // Get parameter 2 off the stack.
  451. const char* param2 = ScriptUtil::getString(3, false);
  452. Material* instance = getInstance(state);
  453. instance->setParameterAutoBinding(param1, param2);
  454. return 0;
  455. }
  456. else
  457. {
  458. lua_pushstring(state, "lua_Material_setParameterAutoBinding - Failed to match the given parameters to a valid function signature.");
  459. lua_error(state);
  460. }
  461. break;
  462. }
  463. default:
  464. {
  465. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  466. lua_error(state);
  467. break;
  468. }
  469. }
  470. return 0;
  471. }
  472. int lua_Material_setStateBlock(lua_State* state)
  473. {
  474. // Get the number of parameters.
  475. int paramCount = lua_gettop(state);
  476. // Attempt to match the parameters to a valid binding.
  477. switch (paramCount)
  478. {
  479. case 2:
  480. {
  481. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  482. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  483. {
  484. // Get parameter 1 off the stack.
  485. RenderState::StateBlock* param1 = ScriptUtil::getObjectPointer<RenderState::StateBlock>(2, "RenderStateStateBlock", false);
  486. Material* instance = getInstance(state);
  487. instance->setStateBlock(param1);
  488. return 0;
  489. }
  490. else
  491. {
  492. lua_pushstring(state, "lua_Material_setStateBlock - Failed to match the given parameters to a valid function signature.");
  493. lua_error(state);
  494. }
  495. break;
  496. }
  497. default:
  498. {
  499. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  500. lua_error(state);
  501. break;
  502. }
  503. }
  504. return 0;
  505. }
  506. int lua_Material_setTechnique(lua_State* state)
  507. {
  508. // Get the number of parameters.
  509. int paramCount = lua_gettop(state);
  510. // Attempt to match the parameters to a valid binding.
  511. switch (paramCount)
  512. {
  513. case 2:
  514. {
  515. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  516. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  517. {
  518. // Get parameter 1 off the stack.
  519. const char* param1 = ScriptUtil::getString(2, false);
  520. Material* instance = getInstance(state);
  521. instance->setTechnique(param1);
  522. return 0;
  523. }
  524. else
  525. {
  526. lua_pushstring(state, "lua_Material_setTechnique - Failed to match the given parameters to a valid function signature.");
  527. lua_error(state);
  528. }
  529. break;
  530. }
  531. default:
  532. {
  533. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  534. lua_error(state);
  535. break;
  536. }
  537. }
  538. return 0;
  539. }
  540. int lua_Material_static_create(lua_State* state)
  541. {
  542. // Get the number of parameters.
  543. int paramCount = lua_gettop(state);
  544. // Attempt to match the parameters to a valid binding.
  545. switch (paramCount)
  546. {
  547. case 1:
  548. {
  549. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  550. {
  551. // Get parameter 1 off the stack.
  552. const char* param1 = ScriptUtil::getString(1, false);
  553. void* returnPtr = (void*)Material::create(param1);
  554. if (returnPtr)
  555. {
  556. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  557. object->instance = returnPtr;
  558. object->owns = true;
  559. luaL_getmetatable(state, "Material");
  560. lua_setmetatable(state, -2);
  561. }
  562. else
  563. {
  564. lua_pushnil(state);
  565. }
  566. return 1;
  567. }
  568. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL))
  569. {
  570. // Get parameter 1 off the stack.
  571. Properties* param1 = ScriptUtil::getObjectPointer<Properties>(1, "Properties", false);
  572. void* returnPtr = (void*)Material::create(param1);
  573. if (returnPtr)
  574. {
  575. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  576. object->instance = returnPtr;
  577. object->owns = true;
  578. luaL_getmetatable(state, "Material");
  579. lua_setmetatable(state, -2);
  580. }
  581. else
  582. {
  583. lua_pushnil(state);
  584. }
  585. return 1;
  586. }
  587. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL))
  588. {
  589. // Get parameter 1 off the stack.
  590. Effect* param1 = ScriptUtil::getObjectPointer<Effect>(1, "Effect", false);
  591. void* returnPtr = (void*)Material::create(param1);
  592. if (returnPtr)
  593. {
  594. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  595. object->instance = returnPtr;
  596. object->owns = true;
  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_Material_static_create - Failed to match the given parameters to a valid function signature.");
  609. lua_error(state);
  610. }
  611. break;
  612. }
  613. case 2:
  614. {
  615. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  616. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  617. {
  618. // Get parameter 1 off the stack.
  619. const char* param1 = ScriptUtil::getString(1, false);
  620. // Get parameter 2 off the stack.
  621. const char* param2 = ScriptUtil::getString(2, false);
  622. void* returnPtr = (void*)Material::create(param1, param2);
  623. if (returnPtr)
  624. {
  625. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  626. object->instance = returnPtr;
  627. object->owns = true;
  628. luaL_getmetatable(state, "Material");
  629. lua_setmetatable(state, -2);
  630. }
  631. else
  632. {
  633. lua_pushnil(state);
  634. }
  635. return 1;
  636. }
  637. else
  638. {
  639. lua_pushstring(state, "lua_Material_static_create - Failed to match the given parameters to a valid function signature.");
  640. lua_error(state);
  641. }
  642. break;
  643. }
  644. case 3:
  645. {
  646. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  647. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  648. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  649. {
  650. // Get parameter 1 off the stack.
  651. const char* param1 = ScriptUtil::getString(1, false);
  652. // Get parameter 2 off the stack.
  653. const char* param2 = ScriptUtil::getString(2, false);
  654. // Get parameter 3 off the stack.
  655. const char* param3 = ScriptUtil::getString(3, false);
  656. void* returnPtr = (void*)Material::create(param1, param2, param3);
  657. if (returnPtr)
  658. {
  659. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  660. object->instance = returnPtr;
  661. object->owns = true;
  662. luaL_getmetatable(state, "Material");
  663. lua_setmetatable(state, -2);
  664. }
  665. else
  666. {
  667. lua_pushnil(state);
  668. }
  669. return 1;
  670. }
  671. else
  672. {
  673. lua_pushstring(state, "lua_Material_static_create - Failed to match the given parameters to a valid function signature.");
  674. lua_error(state);
  675. }
  676. break;
  677. }
  678. default:
  679. {
  680. lua_pushstring(state, "Invalid number of parameters (expected 1, 2 or 3).");
  681. lua_error(state);
  682. break;
  683. }
  684. }
  685. return 0;
  686. }
  687. }