lua_MaterialParameter.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "MaterialParameter.h"
  4. #include "lua_MaterialParameter.h"
  5. #include "lua_Global.h"
  6. namespace gameplay
  7. {
  8. void luaRegister_MaterialParameter()
  9. {
  10. ScriptController* sc = ScriptController::getInstance();
  11. const luaL_Reg lua_members[] =
  12. {
  13. {"addRef", lua_MaterialParameter_addRef},
  14. {"createAnimation", lua_MaterialParameter_createAnimation},
  15. {"createAnimationFromBy", lua_MaterialParameter_createAnimationFromBy},
  16. {"createAnimationFromTo", lua_MaterialParameter_createAnimationFromTo},
  17. {"destroyAnimation", lua_MaterialParameter_destroyAnimation},
  18. {"getAnimation", lua_MaterialParameter_getAnimation},
  19. {"getAnimationPropertyComponentCount", lua_MaterialParameter_getAnimationPropertyComponentCount},
  20. {"getAnimationPropertyValue", lua_MaterialParameter_getAnimationPropertyValue},
  21. {"getName", lua_MaterialParameter_getName},
  22. {"getRefCount", lua_MaterialParameter_getRefCount},
  23. {"release", lua_MaterialParameter_release},
  24. {"setAnimationPropertyValue", lua_MaterialParameter_setAnimationPropertyValue},
  25. {"setValue", lua_MaterialParameter_setValue},
  26. {NULL, NULL}
  27. };
  28. const luaL_Reg lua_statics[] =
  29. {
  30. {"ANIMATE_UNIFORM", lua_MaterialParameter_static_ANIMATE_UNIFORM},
  31. {NULL, NULL}
  32. };
  33. std::vector<std::string> scopePath;
  34. sc->registerClass("MaterialParameter", lua_members, NULL, lua_MaterialParameter__gc, lua_statics, scopePath);
  35. }
  36. static MaterialParameter* getInstance(lua_State* state)
  37. {
  38. void* userdata = luaL_checkudata(state, 1, "MaterialParameter");
  39. luaL_argcheck(state, userdata != NULL, 1, "'MaterialParameter' expected.");
  40. return (MaterialParameter*)((ScriptController::LuaObject*)userdata)->instance;
  41. }
  42. int lua_MaterialParameter__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 || lua_type(state, 1) == LUA_TNIL))
  52. {
  53. void* userdata = luaL_checkudata(state, 1, "MaterialParameter");
  54. luaL_argcheck(state, userdata != NULL, 1, "'MaterialParameter' expected.");
  55. ScriptController::LuaObject* object = (ScriptController::LuaObject*)userdata;
  56. if (object->owns)
  57. {
  58. MaterialParameter* instance = (MaterialParameter*)object->instance;
  59. SAFE_RELEASE(instance);
  60. }
  61. return 0;
  62. }
  63. else
  64. {
  65. lua_pushstring(state, "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_MaterialParameter_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 || lua_type(state, 1) == LUA_TNIL))
  89. {
  90. MaterialParameter* instance = getInstance(state);
  91. instance->addRef();
  92. return 0;
  93. }
  94. else
  95. {
  96. lua_pushstring(state, "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_MaterialParameter_createAnimation(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 3:
  118. {
  119. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  120. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  121. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL))
  122. {
  123. // Get parameter 1 off the stack.
  124. const char* param1 = ScriptController::getInstance()->getString(2, false);
  125. // Get parameter 2 off the stack.
  126. const char* param2 = ScriptController::getInstance()->getString(3, false);
  127. MaterialParameter* instance = getInstance(state);
  128. void* returnPtr = (void*)instance->createAnimation(param1, param2);
  129. if (returnPtr)
  130. {
  131. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  132. object->instance = returnPtr;
  133. object->owns = false;
  134. luaL_getmetatable(state, "Animation");
  135. lua_setmetatable(state, -2);
  136. }
  137. else
  138. {
  139. lua_pushnil(state);
  140. }
  141. return 1;
  142. }
  143. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  144. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  145. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  146. {
  147. // Get parameter 1 off the stack.
  148. const char* param1 = ScriptController::getInstance()->getString(2, false);
  149. // Get parameter 2 off the stack.
  150. Properties* param2 = ScriptController::getInstance()->getObjectPointer<Properties>(3, "Properties", false);
  151. MaterialParameter* instance = getInstance(state);
  152. void* returnPtr = (void*)instance->createAnimation(param1, param2);
  153. if (returnPtr)
  154. {
  155. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  156. object->instance = returnPtr;
  157. object->owns = false;
  158. luaL_getmetatable(state, "Animation");
  159. lua_setmetatable(state, -2);
  160. }
  161. else
  162. {
  163. lua_pushnil(state);
  164. }
  165. return 1;
  166. }
  167. else
  168. {
  169. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  170. lua_error(state);
  171. }
  172. break;
  173. }
  174. case 7:
  175. {
  176. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  177. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  178. lua_type(state, 3) == LUA_TNUMBER &&
  179. lua_type(state, 4) == LUA_TNUMBER &&
  180. (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
  181. (lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TLIGHTUSERDATA) &&
  182. (lua_type(state, 7) == LUA_TSTRING || lua_type(state, 7) == LUA_TNIL))
  183. {
  184. // Get parameter 1 off the stack.
  185. const char* param1 = ScriptController::getInstance()->getString(2, false);
  186. // Get parameter 2 off the stack.
  187. int param2 = (int)luaL_checkint(state, 3);
  188. // Get parameter 3 off the stack.
  189. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  190. // Get parameter 4 off the stack.
  191. unsigned long* param4 = ScriptController::getInstance()->getUnsignedLongPointer(5);
  192. // Get parameter 5 off the stack.
  193. float* param5 = ScriptController::getInstance()->getFloatPointer(6);
  194. // Get parameter 6 off the stack.
  195. Curve::InterpolationType param6 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 7));
  196. MaterialParameter* instance = getInstance(state);
  197. void* returnPtr = (void*)instance->createAnimation(param1, param2, param3, param4, param5, param6);
  198. if (returnPtr)
  199. {
  200. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  201. object->instance = returnPtr;
  202. object->owns = false;
  203. luaL_getmetatable(state, "Animation");
  204. lua_setmetatable(state, -2);
  205. }
  206. else
  207. {
  208. lua_pushnil(state);
  209. }
  210. return 1;
  211. }
  212. else
  213. {
  214. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  215. lua_error(state);
  216. }
  217. break;
  218. }
  219. case 9:
  220. {
  221. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  222. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  223. lua_type(state, 3) == LUA_TNUMBER &&
  224. lua_type(state, 4) == LUA_TNUMBER &&
  225. (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
  226. (lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TLIGHTUSERDATA) &&
  227. (lua_type(state, 7) == LUA_TTABLE || lua_type(state, 7) == LUA_TLIGHTUSERDATA) &&
  228. (lua_type(state, 8) == LUA_TTABLE || lua_type(state, 8) == LUA_TLIGHTUSERDATA) &&
  229. (lua_type(state, 9) == LUA_TSTRING || lua_type(state, 9) == LUA_TNIL))
  230. {
  231. // Get parameter 1 off the stack.
  232. const char* param1 = ScriptController::getInstance()->getString(2, false);
  233. // Get parameter 2 off the stack.
  234. int param2 = (int)luaL_checkint(state, 3);
  235. // Get parameter 3 off the stack.
  236. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  237. // Get parameter 4 off the stack.
  238. unsigned long* param4 = ScriptController::getInstance()->getUnsignedLongPointer(5);
  239. // Get parameter 5 off the stack.
  240. float* param5 = ScriptController::getInstance()->getFloatPointer(6);
  241. // Get parameter 6 off the stack.
  242. float* param6 = ScriptController::getInstance()->getFloatPointer(7);
  243. // Get parameter 7 off the stack.
  244. float* param7 = ScriptController::getInstance()->getFloatPointer(8);
  245. // Get parameter 8 off the stack.
  246. Curve::InterpolationType param8 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 9));
  247. MaterialParameter* instance = getInstance(state);
  248. void* returnPtr = (void*)instance->createAnimation(param1, param2, param3, param4, param5, param6, param7, param8);
  249. if (returnPtr)
  250. {
  251. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  252. object->instance = returnPtr;
  253. object->owns = false;
  254. luaL_getmetatable(state, "Animation");
  255. lua_setmetatable(state, -2);
  256. }
  257. else
  258. {
  259. lua_pushnil(state);
  260. }
  261. return 1;
  262. }
  263. else
  264. {
  265. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  266. lua_error(state);
  267. }
  268. break;
  269. }
  270. default:
  271. {
  272. lua_pushstring(state, "Invalid number of parameters (expected 3, 7 or 9).");
  273. lua_error(state);
  274. break;
  275. }
  276. }
  277. return 0;
  278. }
  279. int lua_MaterialParameter_createAnimationFromBy(lua_State* state)
  280. {
  281. // Get the number of parameters.
  282. int paramCount = lua_gettop(state);
  283. // Attempt to match the parameters to a valid binding.
  284. switch (paramCount)
  285. {
  286. case 7:
  287. {
  288. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  289. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  290. lua_type(state, 3) == LUA_TNUMBER &&
  291. (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
  292. (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
  293. (lua_type(state, 6) == LUA_TSTRING || lua_type(state, 6) == LUA_TNIL) &&
  294. lua_type(state, 7) == LUA_TNUMBER)
  295. {
  296. // Get parameter 1 off the stack.
  297. const char* param1 = ScriptController::getInstance()->getString(2, false);
  298. // Get parameter 2 off the stack.
  299. int param2 = (int)luaL_checkint(state, 3);
  300. // Get parameter 3 off the stack.
  301. float* param3 = ScriptController::getInstance()->getFloatPointer(4);
  302. // Get parameter 4 off the stack.
  303. float* param4 = ScriptController::getInstance()->getFloatPointer(5);
  304. // Get parameter 5 off the stack.
  305. Curve::InterpolationType param5 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 6));
  306. // Get parameter 6 off the stack.
  307. unsigned long param6 = (unsigned long)luaL_checkunsigned(state, 7);
  308. MaterialParameter* instance = getInstance(state);
  309. void* returnPtr = (void*)instance->createAnimationFromBy(param1, param2, param3, param4, param5, param6);
  310. if (returnPtr)
  311. {
  312. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  313. object->instance = returnPtr;
  314. object->owns = false;
  315. luaL_getmetatable(state, "Animation");
  316. lua_setmetatable(state, -2);
  317. }
  318. else
  319. {
  320. lua_pushnil(state);
  321. }
  322. return 1;
  323. }
  324. else
  325. {
  326. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  327. lua_error(state);
  328. }
  329. break;
  330. }
  331. default:
  332. {
  333. lua_pushstring(state, "Invalid number of parameters (expected 7).");
  334. lua_error(state);
  335. break;
  336. }
  337. }
  338. return 0;
  339. }
  340. int lua_MaterialParameter_createAnimationFromTo(lua_State* state)
  341. {
  342. // Get the number of parameters.
  343. int paramCount = lua_gettop(state);
  344. // Attempt to match the parameters to a valid binding.
  345. switch (paramCount)
  346. {
  347. case 7:
  348. {
  349. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  350. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  351. lua_type(state, 3) == LUA_TNUMBER &&
  352. (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
  353. (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA) &&
  354. (lua_type(state, 6) == LUA_TSTRING || lua_type(state, 6) == LUA_TNIL) &&
  355. lua_type(state, 7) == LUA_TNUMBER)
  356. {
  357. // Get parameter 1 off the stack.
  358. const char* param1 = ScriptController::getInstance()->getString(2, false);
  359. // Get parameter 2 off the stack.
  360. int param2 = (int)luaL_checkint(state, 3);
  361. // Get parameter 3 off the stack.
  362. float* param3 = ScriptController::getInstance()->getFloatPointer(4);
  363. // Get parameter 4 off the stack.
  364. float* param4 = ScriptController::getInstance()->getFloatPointer(5);
  365. // Get parameter 5 off the stack.
  366. Curve::InterpolationType param5 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 6));
  367. // Get parameter 6 off the stack.
  368. unsigned long param6 = (unsigned long)luaL_checkunsigned(state, 7);
  369. MaterialParameter* instance = getInstance(state);
  370. void* returnPtr = (void*)instance->createAnimationFromTo(param1, param2, param3, param4, param5, param6);
  371. if (returnPtr)
  372. {
  373. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  374. object->instance = returnPtr;
  375. object->owns = false;
  376. luaL_getmetatable(state, "Animation");
  377. lua_setmetatable(state, -2);
  378. }
  379. else
  380. {
  381. lua_pushnil(state);
  382. }
  383. return 1;
  384. }
  385. else
  386. {
  387. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  388. lua_error(state);
  389. }
  390. break;
  391. }
  392. default:
  393. {
  394. lua_pushstring(state, "Invalid number of parameters (expected 7).");
  395. lua_error(state);
  396. break;
  397. }
  398. }
  399. return 0;
  400. }
  401. int lua_MaterialParameter_destroyAnimation(lua_State* state)
  402. {
  403. // Get the number of parameters.
  404. int paramCount = lua_gettop(state);
  405. // Attempt to match the parameters to a valid binding.
  406. switch (paramCount)
  407. {
  408. case 1:
  409. {
  410. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  411. {
  412. MaterialParameter* instance = getInstance(state);
  413. instance->destroyAnimation();
  414. return 0;
  415. }
  416. else
  417. {
  418. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  419. lua_error(state);
  420. }
  421. break;
  422. }
  423. case 2:
  424. {
  425. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  426. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  427. {
  428. // Get parameter 1 off the stack.
  429. const char* param1 = ScriptController::getInstance()->getString(2, false);
  430. MaterialParameter* instance = getInstance(state);
  431. instance->destroyAnimation(param1);
  432. return 0;
  433. }
  434. else
  435. {
  436. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  437. lua_error(state);
  438. }
  439. break;
  440. }
  441. default:
  442. {
  443. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  444. lua_error(state);
  445. break;
  446. }
  447. }
  448. return 0;
  449. }
  450. int lua_MaterialParameter_getAnimation(lua_State* state)
  451. {
  452. // Get the number of parameters.
  453. int paramCount = lua_gettop(state);
  454. // Attempt to match the parameters to a valid binding.
  455. switch (paramCount)
  456. {
  457. case 1:
  458. {
  459. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  460. {
  461. MaterialParameter* instance = getInstance(state);
  462. void* returnPtr = (void*)instance->getAnimation();
  463. if (returnPtr)
  464. {
  465. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  466. object->instance = returnPtr;
  467. object->owns = false;
  468. luaL_getmetatable(state, "Animation");
  469. lua_setmetatable(state, -2);
  470. }
  471. else
  472. {
  473. lua_pushnil(state);
  474. }
  475. return 1;
  476. }
  477. else
  478. {
  479. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  480. lua_error(state);
  481. }
  482. break;
  483. }
  484. case 2:
  485. {
  486. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  487. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  488. {
  489. // Get parameter 1 off the stack.
  490. const char* param1 = ScriptController::getInstance()->getString(2, false);
  491. MaterialParameter* instance = getInstance(state);
  492. void* returnPtr = (void*)instance->getAnimation(param1);
  493. if (returnPtr)
  494. {
  495. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  496. object->instance = returnPtr;
  497. object->owns = false;
  498. luaL_getmetatable(state, "Animation");
  499. lua_setmetatable(state, -2);
  500. }
  501. else
  502. {
  503. lua_pushnil(state);
  504. }
  505. return 1;
  506. }
  507. else
  508. {
  509. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  510. lua_error(state);
  511. }
  512. break;
  513. }
  514. default:
  515. {
  516. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  517. lua_error(state);
  518. break;
  519. }
  520. }
  521. return 0;
  522. }
  523. int lua_MaterialParameter_getAnimationPropertyComponentCount(lua_State* state)
  524. {
  525. // Get the number of parameters.
  526. int paramCount = lua_gettop(state);
  527. // Attempt to match the parameters to a valid binding.
  528. switch (paramCount)
  529. {
  530. case 2:
  531. {
  532. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  533. lua_type(state, 2) == LUA_TNUMBER)
  534. {
  535. // Get parameter 1 off the stack.
  536. int param1 = (int)luaL_checkint(state, 2);
  537. MaterialParameter* instance = getInstance(state);
  538. unsigned int result = instance->getAnimationPropertyComponentCount(param1);
  539. // Push the return value onto the stack.
  540. lua_pushunsigned(state, result);
  541. return 1;
  542. }
  543. else
  544. {
  545. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  546. lua_error(state);
  547. }
  548. break;
  549. }
  550. default:
  551. {
  552. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  553. lua_error(state);
  554. break;
  555. }
  556. }
  557. return 0;
  558. }
  559. int lua_MaterialParameter_getAnimationPropertyValue(lua_State* state)
  560. {
  561. // Get the number of parameters.
  562. int paramCount = lua_gettop(state);
  563. // Attempt to match the parameters to a valid binding.
  564. switch (paramCount)
  565. {
  566. case 3:
  567. {
  568. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  569. lua_type(state, 2) == LUA_TNUMBER &&
  570. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  571. {
  572. // Get parameter 1 off the stack.
  573. int param1 = (int)luaL_checkint(state, 2);
  574. // Get parameter 2 off the stack.
  575. AnimationValue* param2 = ScriptController::getInstance()->getObjectPointer<AnimationValue>(3, "AnimationValue", false);
  576. MaterialParameter* instance = getInstance(state);
  577. instance->getAnimationPropertyValue(param1, param2);
  578. return 0;
  579. }
  580. else
  581. {
  582. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  583. lua_error(state);
  584. }
  585. break;
  586. }
  587. default:
  588. {
  589. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  590. lua_error(state);
  591. break;
  592. }
  593. }
  594. return 0;
  595. }
  596. int lua_MaterialParameter_getName(lua_State* state)
  597. {
  598. // Get the number of parameters.
  599. int paramCount = lua_gettop(state);
  600. // Attempt to match the parameters to a valid binding.
  601. switch (paramCount)
  602. {
  603. case 1:
  604. {
  605. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  606. {
  607. MaterialParameter* instance = getInstance(state);
  608. const char* result = instance->getName();
  609. // Push the return value onto the stack.
  610. lua_pushstring(state, result);
  611. return 1;
  612. }
  613. else
  614. {
  615. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  616. lua_error(state);
  617. }
  618. break;
  619. }
  620. default:
  621. {
  622. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  623. lua_error(state);
  624. break;
  625. }
  626. }
  627. return 0;
  628. }
  629. int lua_MaterialParameter_getRefCount(lua_State* state)
  630. {
  631. // Get the number of parameters.
  632. int paramCount = lua_gettop(state);
  633. // Attempt to match the parameters to a valid binding.
  634. switch (paramCount)
  635. {
  636. case 1:
  637. {
  638. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  639. {
  640. MaterialParameter* instance = getInstance(state);
  641. unsigned int result = instance->getRefCount();
  642. // Push the return value onto the stack.
  643. lua_pushunsigned(state, result);
  644. return 1;
  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 1).");
  656. lua_error(state);
  657. break;
  658. }
  659. }
  660. return 0;
  661. }
  662. int lua_MaterialParameter_release(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 1:
  670. {
  671. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  672. {
  673. MaterialParameter* instance = getInstance(state);
  674. instance->release();
  675. return 0;
  676. }
  677. else
  678. {
  679. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  680. lua_error(state);
  681. }
  682. break;
  683. }
  684. default:
  685. {
  686. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  687. lua_error(state);
  688. break;
  689. }
  690. }
  691. return 0;
  692. }
  693. int lua_MaterialParameter_setAnimationPropertyValue(lua_State* state)
  694. {
  695. // Get the number of parameters.
  696. int paramCount = lua_gettop(state);
  697. // Attempt to match the parameters to a valid binding.
  698. switch (paramCount)
  699. {
  700. case 3:
  701. {
  702. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  703. lua_type(state, 2) == LUA_TNUMBER &&
  704. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL))
  705. {
  706. // Get parameter 1 off the stack.
  707. int param1 = (int)luaL_checkint(state, 2);
  708. // Get parameter 2 off the stack.
  709. AnimationValue* param2 = ScriptController::getInstance()->getObjectPointer<AnimationValue>(3, "AnimationValue", false);
  710. MaterialParameter* instance = getInstance(state);
  711. instance->setAnimationPropertyValue(param1, param2);
  712. return 0;
  713. }
  714. else
  715. {
  716. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  717. lua_error(state);
  718. }
  719. break;
  720. }
  721. case 4:
  722. {
  723. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  724. lua_type(state, 2) == LUA_TNUMBER &&
  725. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
  726. lua_type(state, 4) == LUA_TNUMBER)
  727. {
  728. // Get parameter 1 off the stack.
  729. int param1 = (int)luaL_checkint(state, 2);
  730. // Get parameter 2 off the stack.
  731. AnimationValue* param2 = ScriptController::getInstance()->getObjectPointer<AnimationValue>(3, "AnimationValue", false);
  732. // Get parameter 3 off the stack.
  733. float param3 = (float)luaL_checknumber(state, 4);
  734. MaterialParameter* instance = getInstance(state);
  735. instance->setAnimationPropertyValue(param1, param2, param3);
  736. return 0;
  737. }
  738. else
  739. {
  740. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  741. lua_error(state);
  742. }
  743. break;
  744. }
  745. default:
  746. {
  747. lua_pushstring(state, "Invalid number of parameters (expected 3 or 4).");
  748. lua_error(state);
  749. break;
  750. }
  751. }
  752. return 0;
  753. }
  754. int lua_MaterialParameter_setValue(lua_State* state)
  755. {
  756. // Get the number of parameters.
  757. int paramCount = lua_gettop(state);
  758. // Attempt to match the parameters to a valid binding.
  759. switch (paramCount)
  760. {
  761. case 2:
  762. {
  763. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  764. lua_type(state, 2) == LUA_TNUMBER)
  765. {
  766. // Get parameter 1 off the stack.
  767. float param1 = (float)luaL_checknumber(state, 2);
  768. MaterialParameter* instance = getInstance(state);
  769. instance->setValue(param1);
  770. return 0;
  771. }
  772. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  773. lua_type(state, 2) == LUA_TNUMBER)
  774. {
  775. // Get parameter 1 off the stack.
  776. int param1 = (int)luaL_checkint(state, 2);
  777. MaterialParameter* instance = getInstance(state);
  778. instance->setValue(param1);
  779. return 0;
  780. }
  781. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  782. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
  783. {
  784. // Get parameter 1 off the stack.
  785. float* param1 = ScriptController::getInstance()->getFloatPointer(2);
  786. MaterialParameter* instance = getInstance(state);
  787. instance->setValue(param1);
  788. return 0;
  789. }
  790. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  791. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
  792. {
  793. // Get parameter 1 off the stack.
  794. int* param1 = ScriptController::getInstance()->getIntPointer(2);
  795. MaterialParameter* instance = getInstance(state);
  796. instance->setValue(param1);
  797. return 0;
  798. }
  799. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  800. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  801. {
  802. // Get parameter 1 off the stack.
  803. Vector2* param1 = ScriptController::getInstance()->getObjectPointer<Vector2>(2, "Vector2", true);
  804. MaterialParameter* instance = getInstance(state);
  805. instance->setValue(*param1);
  806. return 0;
  807. }
  808. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  809. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  810. {
  811. // Get parameter 1 off the stack.
  812. Vector2* param1 = ScriptController::getInstance()->getObjectPointer<Vector2>(2, "Vector2", false);
  813. MaterialParameter* instance = getInstance(state);
  814. instance->setValue(param1);
  815. return 0;
  816. }
  817. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  818. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  819. {
  820. // Get parameter 1 off the stack.
  821. Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
  822. MaterialParameter* instance = getInstance(state);
  823. instance->setValue(*param1);
  824. return 0;
  825. }
  826. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  827. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  828. {
  829. // Get parameter 1 off the stack.
  830. Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", false);
  831. MaterialParameter* instance = getInstance(state);
  832. instance->setValue(param1);
  833. return 0;
  834. }
  835. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  836. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  837. {
  838. // Get parameter 1 off the stack.
  839. Vector4* param1 = ScriptController::getInstance()->getObjectPointer<Vector4>(2, "Vector4", true);
  840. MaterialParameter* instance = getInstance(state);
  841. instance->setValue(*param1);
  842. return 0;
  843. }
  844. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  845. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  846. {
  847. // Get parameter 1 off the stack.
  848. Vector4* param1 = ScriptController::getInstance()->getObjectPointer<Vector4>(2, "Vector4", false);
  849. MaterialParameter* instance = getInstance(state);
  850. instance->setValue(param1);
  851. return 0;
  852. }
  853. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  854. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  855. {
  856. // Get parameter 1 off the stack.
  857. Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(2, "Matrix", true);
  858. MaterialParameter* instance = getInstance(state);
  859. instance->setValue(*param1);
  860. return 0;
  861. }
  862. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  863. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  864. {
  865. // Get parameter 1 off the stack.
  866. Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(2, "Matrix", false);
  867. MaterialParameter* instance = getInstance(state);
  868. instance->setValue(param1);
  869. return 0;
  870. }
  871. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  872. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  873. {
  874. // Get parameter 1 off the stack.
  875. Texture::Sampler* param1 = ScriptController::getInstance()->getObjectPointer<Texture::Sampler>(2, "TextureSampler", false);
  876. MaterialParameter* instance = getInstance(state);
  877. instance->setValue(param1);
  878. return 0;
  879. }
  880. else
  881. {
  882. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  883. lua_error(state);
  884. }
  885. break;
  886. }
  887. case 3:
  888. {
  889. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  890. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
  891. lua_type(state, 3) == LUA_TNUMBER)
  892. {
  893. // Get parameter 1 off the stack.
  894. float* param1 = ScriptController::getInstance()->getFloatPointer(2);
  895. // Get parameter 2 off the stack.
  896. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
  897. MaterialParameter* instance = getInstance(state);
  898. instance->setValue(param1, param2);
  899. return 0;
  900. }
  901. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  902. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
  903. lua_type(state, 3) == LUA_TNUMBER)
  904. {
  905. // Get parameter 1 off the stack.
  906. int* param1 = ScriptController::getInstance()->getIntPointer(2);
  907. // Get parameter 2 off the stack.
  908. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
  909. MaterialParameter* instance = getInstance(state);
  910. instance->setValue(param1, param2);
  911. return 0;
  912. }
  913. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  914. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  915. lua_type(state, 3) == LUA_TNUMBER)
  916. {
  917. // Get parameter 1 off the stack.
  918. Vector2* param1 = ScriptController::getInstance()->getObjectPointer<Vector2>(2, "Vector2", false);
  919. // Get parameter 2 off the stack.
  920. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
  921. MaterialParameter* instance = getInstance(state);
  922. instance->setValue(param1, param2);
  923. return 0;
  924. }
  925. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  926. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  927. lua_type(state, 3) == LUA_TNUMBER)
  928. {
  929. // Get parameter 1 off the stack.
  930. Vector3* param1 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", false);
  931. // Get parameter 2 off the stack.
  932. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
  933. MaterialParameter* instance = getInstance(state);
  934. instance->setValue(param1, param2);
  935. return 0;
  936. }
  937. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  938. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  939. lua_type(state, 3) == LUA_TNUMBER)
  940. {
  941. // Get parameter 1 off the stack.
  942. Vector4* param1 = ScriptController::getInstance()->getObjectPointer<Vector4>(2, "Vector4", false);
  943. // Get parameter 2 off the stack.
  944. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
  945. MaterialParameter* instance = getInstance(state);
  946. instance->setValue(param1, param2);
  947. return 0;
  948. }
  949. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  950. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  951. lua_type(state, 3) == LUA_TNUMBER)
  952. {
  953. // Get parameter 1 off the stack.
  954. Matrix* param1 = ScriptController::getInstance()->getObjectPointer<Matrix>(2, "Matrix", false);
  955. // Get parameter 2 off the stack.
  956. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
  957. MaterialParameter* instance = getInstance(state);
  958. instance->setValue(param1, param2);
  959. return 0;
  960. }
  961. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  962. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  963. lua_type(state, 3) == LUA_TBOOLEAN)
  964. {
  965. // Get parameter 1 off the stack.
  966. const char* param1 = ScriptController::getInstance()->getString(2, false);
  967. // Get parameter 2 off the stack.
  968. bool param2 = (luaL_checkint(state, 3) != 0);
  969. MaterialParameter* instance = getInstance(state);
  970. void* returnPtr = (void*)instance->setValue(param1, param2);
  971. if (returnPtr)
  972. {
  973. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  974. object->instance = returnPtr;
  975. object->owns = false;
  976. luaL_getmetatable(state, "TextureSampler");
  977. lua_setmetatable(state, -2);
  978. }
  979. else
  980. {
  981. lua_pushnil(state);
  982. }
  983. return 1;
  984. }
  985. else
  986. {
  987. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  988. lua_error(state);
  989. }
  990. break;
  991. }
  992. default:
  993. {
  994. lua_pushstring(state, "Invalid number of parameters (expected 2 or 3).");
  995. lua_error(state);
  996. break;
  997. }
  998. }
  999. return 0;
  1000. }
  1001. int lua_MaterialParameter_static_ANIMATE_UNIFORM(lua_State* state)
  1002. {
  1003. // Validate the number of parameters.
  1004. if (lua_gettop(state) > 0)
  1005. {
  1006. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  1007. lua_error(state);
  1008. }
  1009. int result = MaterialParameter::ANIMATE_UNIFORM;
  1010. // Push the return value onto the stack.
  1011. lua_pushinteger(state, result);
  1012. return 1;
  1013. }
  1014. }