lua_Effect.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "Effect.h"
  4. #include "lua_Effect.h"
  5. #include "lua_Global.h"
  6. namespace gameplay
  7. {
  8. void luaRegister_Effect()
  9. {
  10. ScriptController* sc = ScriptController::getInstance();
  11. const luaL_Reg lua_members[] =
  12. {
  13. {"addRef", lua_Effect_addRef},
  14. {"bind", lua_Effect_bind},
  15. {"getId", lua_Effect_getId},
  16. {"getRefCount", lua_Effect_getRefCount},
  17. {"getUniform", lua_Effect_getUniform},
  18. {"getUniformCount", lua_Effect_getUniformCount},
  19. {"getVertexAttribute", lua_Effect_getVertexAttribute},
  20. {"release", lua_Effect_release},
  21. {"setValue", lua_Effect_setValue},
  22. {NULL, NULL}
  23. };
  24. const luaL_Reg lua_statics[] =
  25. {
  26. {"createFromFile", lua_Effect_static_createFromFile},
  27. {"createFromSource", lua_Effect_static_createFromSource},
  28. {"getCurrentEffect", lua_Effect_static_getCurrentEffect},
  29. {NULL, NULL}
  30. };
  31. std::vector<std::string> scopePath;
  32. sc->registerClass("Effect", lua_members, NULL, lua_Effect__gc, lua_statics, scopePath);
  33. }
  34. static Effect* getInstance(lua_State* state)
  35. {
  36. void* userdata = luaL_checkudata(state, 1, "Effect");
  37. luaL_argcheck(state, userdata != NULL, 1, "'Effect' expected.");
  38. return (Effect*)((ScriptController::LuaObject*)userdata)->instance;
  39. }
  40. int lua_Effect__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, "Effect");
  52. luaL_argcheck(state, userdata != NULL, 1, "'Effect' expected.");
  53. ScriptController::LuaObject* object = (ScriptController::LuaObject*)userdata;
  54. if (object->owns)
  55. {
  56. Effect* instance = (Effect*)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_Effect_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. Effect* 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_Effect_bind(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 1:
  116. {
  117. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  118. {
  119. Effect* instance = getInstance(state);
  120. instance->bind();
  121. return 0;
  122. }
  123. else
  124. {
  125. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  126. lua_error(state);
  127. }
  128. break;
  129. }
  130. default:
  131. {
  132. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  133. lua_error(state);
  134. break;
  135. }
  136. }
  137. return 0;
  138. }
  139. int lua_Effect_getId(lua_State* state)
  140. {
  141. // Get the number of parameters.
  142. int paramCount = lua_gettop(state);
  143. // Attempt to match the parameters to a valid binding.
  144. switch (paramCount)
  145. {
  146. case 1:
  147. {
  148. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  149. {
  150. Effect* instance = getInstance(state);
  151. const char* result = instance->getId();
  152. // Push the return value onto the stack.
  153. lua_pushstring(state, result);
  154. return 1;
  155. }
  156. else
  157. {
  158. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  159. lua_error(state);
  160. }
  161. break;
  162. }
  163. default:
  164. {
  165. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  166. lua_error(state);
  167. break;
  168. }
  169. }
  170. return 0;
  171. }
  172. int lua_Effect_getRefCount(lua_State* state)
  173. {
  174. // Get the number of parameters.
  175. int paramCount = lua_gettop(state);
  176. // Attempt to match the parameters to a valid binding.
  177. switch (paramCount)
  178. {
  179. case 1:
  180. {
  181. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  182. {
  183. Effect* instance = getInstance(state);
  184. unsigned int result = instance->getRefCount();
  185. // Push the return value onto the stack.
  186. lua_pushunsigned(state, result);
  187. return 1;
  188. }
  189. else
  190. {
  191. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  192. lua_error(state);
  193. }
  194. break;
  195. }
  196. default:
  197. {
  198. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  199. lua_error(state);
  200. break;
  201. }
  202. }
  203. return 0;
  204. }
  205. int lua_Effect_getUniform(lua_State* state)
  206. {
  207. // Get the number of parameters.
  208. int paramCount = lua_gettop(state);
  209. // Attempt to match the parameters to a valid binding.
  210. switch (paramCount)
  211. {
  212. case 2:
  213. {
  214. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  215. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  216. {
  217. // Get parameter 1 off the stack.
  218. const char* param1 = ScriptController::getInstance()->getString(2, false);
  219. Effect* instance = getInstance(state);
  220. void* returnPtr = (void*)instance->getUniform(param1);
  221. if (returnPtr)
  222. {
  223. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  224. object->instance = returnPtr;
  225. object->owns = false;
  226. luaL_getmetatable(state, "Uniform");
  227. lua_setmetatable(state, -2);
  228. }
  229. else
  230. {
  231. lua_pushnil(state);
  232. }
  233. return 1;
  234. }
  235. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  236. lua_type(state, 2) == LUA_TNUMBER)
  237. {
  238. // Get parameter 1 off the stack.
  239. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  240. Effect* instance = getInstance(state);
  241. void* returnPtr = (void*)instance->getUniform(param1);
  242. if (returnPtr)
  243. {
  244. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  245. object->instance = returnPtr;
  246. object->owns = false;
  247. luaL_getmetatable(state, "Uniform");
  248. lua_setmetatable(state, -2);
  249. }
  250. else
  251. {
  252. lua_pushnil(state);
  253. }
  254. return 1;
  255. }
  256. else
  257. {
  258. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  259. lua_error(state);
  260. }
  261. break;
  262. }
  263. default:
  264. {
  265. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  266. lua_error(state);
  267. break;
  268. }
  269. }
  270. return 0;
  271. }
  272. int lua_Effect_getUniformCount(lua_State* state)
  273. {
  274. // Get the number of parameters.
  275. int paramCount = lua_gettop(state);
  276. // Attempt to match the parameters to a valid binding.
  277. switch (paramCount)
  278. {
  279. case 1:
  280. {
  281. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  282. {
  283. Effect* instance = getInstance(state);
  284. unsigned int result = instance->getUniformCount();
  285. // Push the return value onto the stack.
  286. lua_pushunsigned(state, result);
  287. return 1;
  288. }
  289. else
  290. {
  291. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  292. lua_error(state);
  293. }
  294. break;
  295. }
  296. default:
  297. {
  298. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  299. lua_error(state);
  300. break;
  301. }
  302. }
  303. return 0;
  304. }
  305. int lua_Effect_getVertexAttribute(lua_State* state)
  306. {
  307. // Get the number of parameters.
  308. int paramCount = lua_gettop(state);
  309. // Attempt to match the parameters to a valid binding.
  310. switch (paramCount)
  311. {
  312. case 2:
  313. {
  314. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  315. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  316. {
  317. // Get parameter 1 off the stack.
  318. const char* param1 = ScriptController::getInstance()->getString(2, false);
  319. Effect* instance = getInstance(state);
  320. void* returnPtr = (void*)new GLint(instance->getVertexAttribute(param1));
  321. if (returnPtr)
  322. {
  323. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  324. object->instance = returnPtr;
  325. object->owns = true;
  326. luaL_getmetatable(state, "GLint");
  327. lua_setmetatable(state, -2);
  328. }
  329. else
  330. {
  331. lua_pushnil(state);
  332. }
  333. return 1;
  334. }
  335. else
  336. {
  337. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  338. lua_error(state);
  339. }
  340. break;
  341. }
  342. default:
  343. {
  344. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  345. lua_error(state);
  346. break;
  347. }
  348. }
  349. return 0;
  350. }
  351. int lua_Effect_release(lua_State* state)
  352. {
  353. // Get the number of parameters.
  354. int paramCount = lua_gettop(state);
  355. // Attempt to match the parameters to a valid binding.
  356. switch (paramCount)
  357. {
  358. case 1:
  359. {
  360. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  361. {
  362. Effect* instance = getInstance(state);
  363. instance->release();
  364. return 0;
  365. }
  366. else
  367. {
  368. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  369. lua_error(state);
  370. }
  371. break;
  372. }
  373. default:
  374. {
  375. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  376. lua_error(state);
  377. break;
  378. }
  379. }
  380. return 0;
  381. }
  382. int lua_Effect_setValue(lua_State* state)
  383. {
  384. // Get the number of parameters.
  385. int paramCount = lua_gettop(state);
  386. // Attempt to match the parameters to a valid binding.
  387. switch (paramCount)
  388. {
  389. case 3:
  390. {
  391. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  392. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  393. lua_type(state, 3) == LUA_TNUMBER)
  394. {
  395. // Get parameter 1 off the stack.
  396. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  397. // Get parameter 2 off the stack.
  398. float param2 = (float)luaL_checknumber(state, 3);
  399. Effect* instance = getInstance(state);
  400. instance->setValue(param1, param2);
  401. return 0;
  402. }
  403. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  404. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  405. (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA))
  406. {
  407. // Get parameter 1 off the stack.
  408. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  409. // Get parameter 2 off the stack.
  410. float* param2 = ScriptController::getInstance()->getFloatPointer(3);
  411. Effect* instance = getInstance(state);
  412. instance->setValue(param1, param2);
  413. return 0;
  414. }
  415. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  416. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  417. lua_type(state, 3) == LUA_TNUMBER)
  418. {
  419. // Get parameter 1 off the stack.
  420. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  421. // Get parameter 2 off the stack.
  422. int param2 = (int)luaL_checkint(state, 3);
  423. Effect* instance = getInstance(state);
  424. instance->setValue(param1, param2);
  425. return 0;
  426. }
  427. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  428. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  429. (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA))
  430. {
  431. // Get parameter 1 off the stack.
  432. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  433. // Get parameter 2 off the stack.
  434. int* param2 = ScriptController::getInstance()->getIntPointer(3);
  435. Effect* instance = getInstance(state);
  436. instance->setValue(param1, param2);
  437. return 0;
  438. }
  439. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  440. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  441. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  442. {
  443. // Get parameter 1 off the stack.
  444. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  445. // Get parameter 2 off the stack.
  446. Matrix* param2 = ScriptController::getInstance()->getObjectPointer<Matrix>(3, "Matrix", true);
  447. Effect* instance = getInstance(state);
  448. instance->setValue(param1, *param2);
  449. return 0;
  450. }
  451. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  452. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  453. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  454. {
  455. // Get parameter 1 off the stack.
  456. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  457. // Get parameter 2 off the stack.
  458. Matrix* param2 = ScriptController::getInstance()->getObjectPointer<Matrix>(3, "Matrix", false);
  459. Effect* instance = getInstance(state);
  460. instance->setValue(param1, param2);
  461. return 0;
  462. }
  463. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  464. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  465. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  466. {
  467. // Get parameter 1 off the stack.
  468. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  469. // Get parameter 2 off the stack.
  470. Vector2* param2 = ScriptController::getInstance()->getObjectPointer<Vector2>(3, "Vector2", true);
  471. Effect* instance = getInstance(state);
  472. instance->setValue(param1, *param2);
  473. return 0;
  474. }
  475. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  476. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  477. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  478. {
  479. // Get parameter 1 off the stack.
  480. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  481. // Get parameter 2 off the stack.
  482. Vector2* param2 = ScriptController::getInstance()->getObjectPointer<Vector2>(3, "Vector2", false);
  483. Effect* instance = getInstance(state);
  484. instance->setValue(param1, param2);
  485. return 0;
  486. }
  487. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  488. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  489. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  490. {
  491. // Get parameter 1 off the stack.
  492. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  493. // Get parameter 2 off the stack.
  494. Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", true);
  495. Effect* instance = getInstance(state);
  496. instance->setValue(param1, *param2);
  497. return 0;
  498. }
  499. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  500. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  501. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  502. {
  503. // Get parameter 1 off the stack.
  504. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  505. // Get parameter 2 off the stack.
  506. Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", false);
  507. Effect* instance = getInstance(state);
  508. instance->setValue(param1, param2);
  509. return 0;
  510. }
  511. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  512. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  513. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  514. {
  515. // Get parameter 1 off the stack.
  516. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  517. // Get parameter 2 off the stack.
  518. Vector4* param2 = ScriptController::getInstance()->getObjectPointer<Vector4>(3, "Vector4", true);
  519. Effect* instance = getInstance(state);
  520. instance->setValue(param1, *param2);
  521. return 0;
  522. }
  523. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  524. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  525. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  526. {
  527. // Get parameter 1 off the stack.
  528. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  529. // Get parameter 2 off the stack.
  530. Vector4* param2 = ScriptController::getInstance()->getObjectPointer<Vector4>(3, "Vector4", false);
  531. Effect* instance = getInstance(state);
  532. instance->setValue(param1, param2);
  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_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  537. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  538. {
  539. // Get parameter 1 off the stack.
  540. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  541. // Get parameter 2 off the stack.
  542. Texture::Sampler* param2 = ScriptController::getInstance()->getObjectPointer<Texture::Sampler>(3, "TextureSampler", false);
  543. Effect* instance = getInstance(state);
  544. instance->setValue(param1, param2);
  545. return 0;
  546. }
  547. else
  548. {
  549. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  550. lua_error(state);
  551. }
  552. break;
  553. }
  554. case 4:
  555. {
  556. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  557. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  558. (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA) &&
  559. lua_type(state, 4) == LUA_TNUMBER)
  560. {
  561. // Get parameter 1 off the stack.
  562. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  563. // Get parameter 2 off the stack.
  564. float* param2 = ScriptController::getInstance()->getFloatPointer(3);
  565. // Get parameter 3 off the stack.
  566. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  567. Effect* instance = getInstance(state);
  568. instance->setValue(param1, param2, param3);
  569. return 0;
  570. }
  571. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  572. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  573. (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA) &&
  574. lua_type(state, 4) == LUA_TNUMBER)
  575. {
  576. // Get parameter 1 off the stack.
  577. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  578. // Get parameter 2 off the stack.
  579. int* param2 = ScriptController::getInstance()->getIntPointer(3);
  580. // Get parameter 3 off the stack.
  581. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  582. Effect* instance = getInstance(state);
  583. instance->setValue(param1, param2, param3);
  584. return 0;
  585. }
  586. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  587. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  588. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
  589. lua_type(state, 4) == LUA_TNUMBER)
  590. {
  591. // Get parameter 1 off the stack.
  592. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  593. // Get parameter 2 off the stack.
  594. Matrix* param2 = ScriptController::getInstance()->getObjectPointer<Matrix>(3, "Matrix", false);
  595. // Get parameter 3 off the stack.
  596. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  597. Effect* instance = getInstance(state);
  598. instance->setValue(param1, param2, param3);
  599. return 0;
  600. }
  601. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  602. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  603. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
  604. lua_type(state, 4) == LUA_TNUMBER)
  605. {
  606. // Get parameter 1 off the stack.
  607. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  608. // Get parameter 2 off the stack.
  609. Vector2* param2 = ScriptController::getInstance()->getObjectPointer<Vector2>(3, "Vector2", false);
  610. // Get parameter 3 off the stack.
  611. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  612. Effect* instance = getInstance(state);
  613. instance->setValue(param1, param2, param3);
  614. return 0;
  615. }
  616. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  617. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  618. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
  619. lua_type(state, 4) == LUA_TNUMBER)
  620. {
  621. // Get parameter 1 off the stack.
  622. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  623. // Get parameter 2 off the stack.
  624. Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(3, "Vector3", false);
  625. // Get parameter 3 off the stack.
  626. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  627. Effect* instance = getInstance(state);
  628. instance->setValue(param1, param2, param3);
  629. return 0;
  630. }
  631. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  632. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  633. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
  634. lua_type(state, 4) == LUA_TNUMBER)
  635. {
  636. // Get parameter 1 off the stack.
  637. Uniform* param1 = ScriptController::getInstance()->getObjectPointer<Uniform>(2, "Uniform", false);
  638. // Get parameter 2 off the stack.
  639. Vector4* param2 = ScriptController::getInstance()->getObjectPointer<Vector4>(3, "Vector4", false);
  640. // Get parameter 3 off the stack.
  641. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  642. Effect* instance = getInstance(state);
  643. instance->setValue(param1, param2, param3);
  644. return 0;
  645. }
  646. else
  647. {
  648. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  649. lua_error(state);
  650. }
  651. break;
  652. }
  653. default:
  654. {
  655. lua_pushstring(state, "Invalid number of parameters (expected 3 or 4).");
  656. lua_error(state);
  657. break;
  658. }
  659. }
  660. return 0;
  661. }
  662. int lua_Effect_static_createFromFile(lua_State* state)
  663. {
  664. // Get the number of parameters.
  665. int paramCount = lua_gettop(state);
  666. // Attempt to match the parameters to a valid binding.
  667. switch (paramCount)
  668. {
  669. case 2:
  670. {
  671. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  672. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  673. {
  674. // Get parameter 1 off the stack.
  675. const char* param1 = ScriptController::getInstance()->getString(1, false);
  676. // Get parameter 2 off the stack.
  677. const char* param2 = ScriptController::getInstance()->getString(2, false);
  678. void* returnPtr = (void*)Effect::createFromFile(param1, param2);
  679. if (returnPtr)
  680. {
  681. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  682. object->instance = returnPtr;
  683. object->owns = false;
  684. luaL_getmetatable(state, "Effect");
  685. lua_setmetatable(state, -2);
  686. }
  687. else
  688. {
  689. lua_pushnil(state);
  690. }
  691. return 1;
  692. }
  693. else
  694. {
  695. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  696. lua_error(state);
  697. }
  698. break;
  699. }
  700. case 3:
  701. {
  702. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  703. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  704. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  705. {
  706. // Get parameter 1 off the stack.
  707. const char* param1 = ScriptController::getInstance()->getString(1, false);
  708. // Get parameter 2 off the stack.
  709. const char* param2 = ScriptController::getInstance()->getString(2, false);
  710. // Get parameter 3 off the stack.
  711. const char* param3 = ScriptController::getInstance()->getString(3, false);
  712. void* returnPtr = (void*)Effect::createFromFile(param1, param2, param3);
  713. if (returnPtr)
  714. {
  715. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  716. object->instance = returnPtr;
  717. object->owns = false;
  718. luaL_getmetatable(state, "Effect");
  719. lua_setmetatable(state, -2);
  720. }
  721. else
  722. {
  723. lua_pushnil(state);
  724. }
  725. return 1;
  726. }
  727. else
  728. {
  729. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  730. lua_error(state);
  731. }
  732. break;
  733. }
  734. default:
  735. {
  736. lua_pushstring(state, "Invalid number of parameters (expected 2 or 3).");
  737. lua_error(state);
  738. break;
  739. }
  740. }
  741. return 0;
  742. }
  743. int lua_Effect_static_createFromSource(lua_State* state)
  744. {
  745. // Get the number of parameters.
  746. int paramCount = lua_gettop(state);
  747. // Attempt to match the parameters to a valid binding.
  748. switch (paramCount)
  749. {
  750. case 2:
  751. {
  752. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  753. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  754. {
  755. // Get parameter 1 off the stack.
  756. const char* param1 = ScriptController::getInstance()->getString(1, false);
  757. // Get parameter 2 off the stack.
  758. const char* param2 = ScriptController::getInstance()->getString(2, false);
  759. void* returnPtr = (void*)Effect::createFromSource(param1, param2);
  760. if (returnPtr)
  761. {
  762. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  763. object->instance = returnPtr;
  764. object->owns = false;
  765. luaL_getmetatable(state, "Effect");
  766. lua_setmetatable(state, -2);
  767. }
  768. else
  769. {
  770. lua_pushnil(state);
  771. }
  772. return 1;
  773. }
  774. else
  775. {
  776. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  777. lua_error(state);
  778. }
  779. break;
  780. }
  781. case 3:
  782. {
  783. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  784. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  785. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  786. {
  787. // Get parameter 1 off the stack.
  788. const char* param1 = ScriptController::getInstance()->getString(1, false);
  789. // Get parameter 2 off the stack.
  790. const char* param2 = ScriptController::getInstance()->getString(2, false);
  791. // Get parameter 3 off the stack.
  792. const char* param3 = ScriptController::getInstance()->getString(3, false);
  793. void* returnPtr = (void*)Effect::createFromSource(param1, param2, param3);
  794. if (returnPtr)
  795. {
  796. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  797. object->instance = returnPtr;
  798. object->owns = false;
  799. luaL_getmetatable(state, "Effect");
  800. lua_setmetatable(state, -2);
  801. }
  802. else
  803. {
  804. lua_pushnil(state);
  805. }
  806. return 1;
  807. }
  808. else
  809. {
  810. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  811. lua_error(state);
  812. }
  813. break;
  814. }
  815. default:
  816. {
  817. lua_pushstring(state, "Invalid number of parameters (expected 2 or 3).");
  818. lua_error(state);
  819. break;
  820. }
  821. }
  822. return 0;
  823. }
  824. int lua_Effect_static_getCurrentEffect(lua_State* state)
  825. {
  826. // Get the number of parameters.
  827. int paramCount = lua_gettop(state);
  828. // Attempt to match the parameters to a valid binding.
  829. switch (paramCount)
  830. {
  831. case 0:
  832. {
  833. void* returnPtr = (void*)Effect::getCurrentEffect();
  834. if (returnPtr)
  835. {
  836. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  837. object->instance = returnPtr;
  838. object->owns = false;
  839. luaL_getmetatable(state, "Effect");
  840. lua_setmetatable(state, -2);
  841. }
  842. else
  843. {
  844. lua_pushnil(state);
  845. }
  846. return 1;
  847. break;
  848. }
  849. default:
  850. {
  851. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  852. lua_error(state);
  853. break;
  854. }
  855. }
  856. return 0;
  857. }
  858. }