lua_Material.cpp 26 KB

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