lua_Material.cpp 26 KB

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