lua_Effect.cpp 37 KB

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