lua_Animation.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Animation.h"
  4. #include "Animation.h"
  5. #include "AnimationClip.h"
  6. #include "AnimationController.h"
  7. #include "AnimationTarget.h"
  8. #include "Base.h"
  9. #include "Game.h"
  10. #include "Properties.h"
  11. #include "Ref.h"
  12. #include "Transform.h"
  13. namespace gameplay
  14. {
  15. void luaRegister_Animation()
  16. {
  17. const luaL_Reg lua_members[] =
  18. {
  19. {"addRef", lua_Animation_addRef},
  20. {"createClip", lua_Animation_createClip},
  21. {"createClips", lua_Animation_createClips},
  22. {"getClip", lua_Animation_getClip},
  23. {"getClipCount", lua_Animation_getClipCount},
  24. {"getDuration", lua_Animation_getDuration},
  25. {"getId", lua_Animation_getId},
  26. {"getRefCount", lua_Animation_getRefCount},
  27. {"pause", lua_Animation_pause},
  28. {"play", lua_Animation_play},
  29. {"release", lua_Animation_release},
  30. {"stop", lua_Animation_stop},
  31. {"targets", lua_Animation_targets},
  32. {NULL, NULL}
  33. };
  34. const luaL_Reg* lua_statics = NULL;
  35. std::vector<std::string> scopePath;
  36. ScriptUtil::registerClass("Animation", lua_members, NULL, lua_Animation__gc, lua_statics, scopePath);
  37. }
  38. static Animation* getInstance(lua_State* state)
  39. {
  40. void* userdata = luaL_checkudata(state, 1, "Animation");
  41. luaL_argcheck(state, userdata != NULL, 1, "'Animation' expected.");
  42. return (Animation*)((ScriptUtil::LuaObject*)userdata)->instance;
  43. }
  44. int lua_Animation__gc(lua_State* state)
  45. {
  46. // Get the number of parameters.
  47. int paramCount = lua_gettop(state);
  48. // Attempt to match the parameters to a valid binding.
  49. switch (paramCount)
  50. {
  51. case 1:
  52. {
  53. if ((lua_type(state, 1) == LUA_TUSERDATA))
  54. {
  55. void* userdata = luaL_checkudata(state, 1, "Animation");
  56. luaL_argcheck(state, userdata != NULL, 1, "'Animation' expected.");
  57. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  58. if (object->owns)
  59. {
  60. Animation* instance = (Animation*)object->instance;
  61. SAFE_RELEASE(instance);
  62. }
  63. return 0;
  64. }
  65. lua_pushstring(state, "lua_Animation__gc - Failed to match the given parameters to a valid function signature.");
  66. lua_error(state);
  67. break;
  68. }
  69. default:
  70. {
  71. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  72. lua_error(state);
  73. break;
  74. }
  75. }
  76. return 0;
  77. }
  78. int lua_Animation_addRef(lua_State* state)
  79. {
  80. // Get the number of parameters.
  81. int paramCount = lua_gettop(state);
  82. // Attempt to match the parameters to a valid binding.
  83. switch (paramCount)
  84. {
  85. case 1:
  86. {
  87. if ((lua_type(state, 1) == LUA_TUSERDATA))
  88. {
  89. Animation* instance = getInstance(state);
  90. instance->addRef();
  91. return 0;
  92. }
  93. lua_pushstring(state, "lua_Animation_addRef - Failed to match the given parameters to a valid function signature.");
  94. lua_error(state);
  95. break;
  96. }
  97. default:
  98. {
  99. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  100. lua_error(state);
  101. break;
  102. }
  103. }
  104. return 0;
  105. }
  106. int lua_Animation_createClip(lua_State* state)
  107. {
  108. // Get the number of parameters.
  109. int paramCount = lua_gettop(state);
  110. // Attempt to match the parameters to a valid binding.
  111. switch (paramCount)
  112. {
  113. case 4:
  114. {
  115. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  116. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  117. lua_type(state, 3) == LUA_TNUMBER &&
  118. lua_type(state, 4) == LUA_TNUMBER)
  119. {
  120. // Get parameter 1 off the stack.
  121. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  122. // Get parameter 2 off the stack.
  123. unsigned long param2 = (unsigned long)luaL_checkunsigned(state, 3);
  124. // Get parameter 3 off the stack.
  125. unsigned long param3 = (unsigned long)luaL_checkunsigned(state, 4);
  126. Animation* instance = getInstance(state);
  127. void* returnPtr = (void*)instance->createClip(param1, param2, param3);
  128. if (returnPtr)
  129. {
  130. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  131. object->instance = returnPtr;
  132. object->owns = true;
  133. luaL_getmetatable(state, "AnimationClip");
  134. lua_setmetatable(state, -2);
  135. }
  136. else
  137. {
  138. lua_pushnil(state);
  139. }
  140. return 1;
  141. }
  142. lua_pushstring(state, "lua_Animation_createClip - Failed to match the given parameters to a valid function signature.");
  143. lua_error(state);
  144. break;
  145. }
  146. default:
  147. {
  148. lua_pushstring(state, "Invalid number of parameters (expected 4).");
  149. lua_error(state);
  150. break;
  151. }
  152. }
  153. return 0;
  154. }
  155. int lua_Animation_createClips(lua_State* state)
  156. {
  157. // Get the number of parameters.
  158. int paramCount = lua_gettop(state);
  159. // Attempt to match the parameters to a valid binding.
  160. switch (paramCount)
  161. {
  162. case 2:
  163. {
  164. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  165. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  166. {
  167. // Get parameter 1 off the stack.
  168. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  169. Animation* instance = getInstance(state);
  170. instance->createClips(param1);
  171. return 0;
  172. }
  173. lua_pushstring(state, "lua_Animation_createClips - Failed to match the given parameters to a valid function signature.");
  174. lua_error(state);
  175. break;
  176. }
  177. default:
  178. {
  179. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  180. lua_error(state);
  181. break;
  182. }
  183. }
  184. return 0;
  185. }
  186. int lua_Animation_getClip(lua_State* state)
  187. {
  188. // Get the number of parameters.
  189. int paramCount = lua_gettop(state);
  190. // Attempt to match the parameters to a valid binding.
  191. switch (paramCount)
  192. {
  193. case 1:
  194. {
  195. do
  196. {
  197. if ((lua_type(state, 1) == LUA_TUSERDATA))
  198. {
  199. Animation* instance = getInstance(state);
  200. void* returnPtr = (void*)instance->getClip();
  201. if (returnPtr)
  202. {
  203. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  204. object->instance = returnPtr;
  205. object->owns = false;
  206. luaL_getmetatable(state, "AnimationClip");
  207. lua_setmetatable(state, -2);
  208. }
  209. else
  210. {
  211. lua_pushnil(state);
  212. }
  213. return 1;
  214. }
  215. } while (0);
  216. lua_pushstring(state, "lua_Animation_getClip - Failed to match the given parameters to a valid function signature.");
  217. lua_error(state);
  218. break;
  219. }
  220. case 2:
  221. {
  222. do
  223. {
  224. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  225. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  226. {
  227. // Get parameter 1 off the stack.
  228. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  229. Animation* instance = getInstance(state);
  230. void* returnPtr = (void*)instance->getClip(param1);
  231. if (returnPtr)
  232. {
  233. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  234. object->instance = returnPtr;
  235. object->owns = false;
  236. luaL_getmetatable(state, "AnimationClip");
  237. lua_setmetatable(state, -2);
  238. }
  239. else
  240. {
  241. lua_pushnil(state);
  242. }
  243. return 1;
  244. }
  245. } while (0);
  246. do
  247. {
  248. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  249. lua_type(state, 2) == LUA_TNUMBER)
  250. {
  251. // Get parameter 1 off the stack.
  252. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  253. Animation* instance = getInstance(state);
  254. void* returnPtr = (void*)instance->getClip(param1);
  255. if (returnPtr)
  256. {
  257. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  258. object->instance = returnPtr;
  259. object->owns = false;
  260. luaL_getmetatable(state, "AnimationClip");
  261. lua_setmetatable(state, -2);
  262. }
  263. else
  264. {
  265. lua_pushnil(state);
  266. }
  267. return 1;
  268. }
  269. } while (0);
  270. lua_pushstring(state, "lua_Animation_getClip - Failed to match the given parameters to a valid function signature.");
  271. lua_error(state);
  272. break;
  273. }
  274. default:
  275. {
  276. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  277. lua_error(state);
  278. break;
  279. }
  280. }
  281. return 0;
  282. }
  283. int lua_Animation_getClipCount(lua_State* state)
  284. {
  285. // Get the number of parameters.
  286. int paramCount = lua_gettop(state);
  287. // Attempt to match the parameters to a valid binding.
  288. switch (paramCount)
  289. {
  290. case 1:
  291. {
  292. if ((lua_type(state, 1) == LUA_TUSERDATA))
  293. {
  294. Animation* instance = getInstance(state);
  295. unsigned int result = instance->getClipCount();
  296. // Push the return value onto the stack.
  297. lua_pushunsigned(state, result);
  298. return 1;
  299. }
  300. lua_pushstring(state, "lua_Animation_getClipCount - Failed to match the given parameters to a valid function signature.");
  301. lua_error(state);
  302. break;
  303. }
  304. default:
  305. {
  306. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  307. lua_error(state);
  308. break;
  309. }
  310. }
  311. return 0;
  312. }
  313. int lua_Animation_getDuration(lua_State* state)
  314. {
  315. // Get the number of parameters.
  316. int paramCount = lua_gettop(state);
  317. // Attempt to match the parameters to a valid binding.
  318. switch (paramCount)
  319. {
  320. case 1:
  321. {
  322. if ((lua_type(state, 1) == LUA_TUSERDATA))
  323. {
  324. Animation* instance = getInstance(state);
  325. unsigned long result = instance->getDuration();
  326. // Push the return value onto the stack.
  327. lua_pushunsigned(state, result);
  328. return 1;
  329. }
  330. lua_pushstring(state, "lua_Animation_getDuration - Failed to match the given parameters to a valid function signature.");
  331. lua_error(state);
  332. break;
  333. }
  334. default:
  335. {
  336. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  337. lua_error(state);
  338. break;
  339. }
  340. }
  341. return 0;
  342. }
  343. int lua_Animation_getId(lua_State* state)
  344. {
  345. // Get the number of parameters.
  346. int paramCount = lua_gettop(state);
  347. // Attempt to match the parameters to a valid binding.
  348. switch (paramCount)
  349. {
  350. case 1:
  351. {
  352. if ((lua_type(state, 1) == LUA_TUSERDATA))
  353. {
  354. Animation* instance = getInstance(state);
  355. const char* result = instance->getId();
  356. // Push the return value onto the stack.
  357. lua_pushstring(state, result);
  358. return 1;
  359. }
  360. lua_pushstring(state, "lua_Animation_getId - Failed to match the given parameters to a valid function signature.");
  361. lua_error(state);
  362. break;
  363. }
  364. default:
  365. {
  366. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  367. lua_error(state);
  368. break;
  369. }
  370. }
  371. return 0;
  372. }
  373. int lua_Animation_getRefCount(lua_State* state)
  374. {
  375. // Get the number of parameters.
  376. int paramCount = lua_gettop(state);
  377. // Attempt to match the parameters to a valid binding.
  378. switch (paramCount)
  379. {
  380. case 1:
  381. {
  382. if ((lua_type(state, 1) == LUA_TUSERDATA))
  383. {
  384. Animation* instance = getInstance(state);
  385. unsigned int result = instance->getRefCount();
  386. // Push the return value onto the stack.
  387. lua_pushunsigned(state, result);
  388. return 1;
  389. }
  390. lua_pushstring(state, "lua_Animation_getRefCount - Failed to match the given parameters to a valid function signature.");
  391. lua_error(state);
  392. break;
  393. }
  394. default:
  395. {
  396. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  397. lua_error(state);
  398. break;
  399. }
  400. }
  401. return 0;
  402. }
  403. int lua_Animation_pause(lua_State* state)
  404. {
  405. // Get the number of parameters.
  406. int paramCount = lua_gettop(state);
  407. // Attempt to match the parameters to a valid binding.
  408. switch (paramCount)
  409. {
  410. case 1:
  411. {
  412. if ((lua_type(state, 1) == LUA_TUSERDATA))
  413. {
  414. Animation* instance = getInstance(state);
  415. instance->pause();
  416. return 0;
  417. }
  418. lua_pushstring(state, "lua_Animation_pause - Failed to match the given parameters to a valid function signature.");
  419. lua_error(state);
  420. break;
  421. }
  422. case 2:
  423. {
  424. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  425. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  426. {
  427. // Get parameter 1 off the stack.
  428. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  429. Animation* instance = getInstance(state);
  430. instance->pause(param1);
  431. return 0;
  432. }
  433. lua_pushstring(state, "lua_Animation_pause - Failed to match the given parameters to a valid function signature.");
  434. lua_error(state);
  435. break;
  436. }
  437. default:
  438. {
  439. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  440. lua_error(state);
  441. break;
  442. }
  443. }
  444. return 0;
  445. }
  446. int lua_Animation_play(lua_State* state)
  447. {
  448. // Get the number of parameters.
  449. int paramCount = lua_gettop(state);
  450. // Attempt to match the parameters to a valid binding.
  451. switch (paramCount)
  452. {
  453. case 1:
  454. {
  455. if ((lua_type(state, 1) == LUA_TUSERDATA))
  456. {
  457. Animation* instance = getInstance(state);
  458. instance->play();
  459. return 0;
  460. }
  461. lua_pushstring(state, "lua_Animation_play - Failed to match the given parameters to a valid function signature.");
  462. lua_error(state);
  463. break;
  464. }
  465. case 2:
  466. {
  467. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  468. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  469. {
  470. // Get parameter 1 off the stack.
  471. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  472. Animation* instance = getInstance(state);
  473. instance->play(param1);
  474. return 0;
  475. }
  476. lua_pushstring(state, "lua_Animation_play - Failed to match the given parameters to a valid function signature.");
  477. lua_error(state);
  478. break;
  479. }
  480. default:
  481. {
  482. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  483. lua_error(state);
  484. break;
  485. }
  486. }
  487. return 0;
  488. }
  489. int lua_Animation_release(lua_State* state)
  490. {
  491. // Get the number of parameters.
  492. int paramCount = lua_gettop(state);
  493. // Attempt to match the parameters to a valid binding.
  494. switch (paramCount)
  495. {
  496. case 1:
  497. {
  498. if ((lua_type(state, 1) == LUA_TUSERDATA))
  499. {
  500. Animation* instance = getInstance(state);
  501. instance->release();
  502. return 0;
  503. }
  504. lua_pushstring(state, "lua_Animation_release - Failed to match the given parameters to a valid function signature.");
  505. lua_error(state);
  506. break;
  507. }
  508. default:
  509. {
  510. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  511. lua_error(state);
  512. break;
  513. }
  514. }
  515. return 0;
  516. }
  517. int lua_Animation_stop(lua_State* state)
  518. {
  519. // Get the number of parameters.
  520. int paramCount = lua_gettop(state);
  521. // Attempt to match the parameters to a valid binding.
  522. switch (paramCount)
  523. {
  524. case 1:
  525. {
  526. if ((lua_type(state, 1) == LUA_TUSERDATA))
  527. {
  528. Animation* instance = getInstance(state);
  529. instance->stop();
  530. return 0;
  531. }
  532. lua_pushstring(state, "lua_Animation_stop - Failed to match the given parameters to a valid function signature.");
  533. lua_error(state);
  534. break;
  535. }
  536. case 2:
  537. {
  538. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  539. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  540. {
  541. // Get parameter 1 off the stack.
  542. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  543. Animation* instance = getInstance(state);
  544. instance->stop(param1);
  545. return 0;
  546. }
  547. lua_pushstring(state, "lua_Animation_stop - Failed to match the given parameters to a valid function signature.");
  548. lua_error(state);
  549. break;
  550. }
  551. default:
  552. {
  553. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  554. lua_error(state);
  555. break;
  556. }
  557. }
  558. return 0;
  559. }
  560. int lua_Animation_targets(lua_State* state)
  561. {
  562. // Get the number of parameters.
  563. int paramCount = lua_gettop(state);
  564. // Attempt to match the parameters to a valid binding.
  565. switch (paramCount)
  566. {
  567. case 2:
  568. {
  569. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  570. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  571. {
  572. // Get parameter 1 off the stack.
  573. bool param1Valid;
  574. ScriptUtil::LuaArray<AnimationTarget> param1 = ScriptUtil::getObjectPointer<AnimationTarget>(2, "AnimationTarget", false, &param1Valid);
  575. if (!param1Valid)
  576. {
  577. lua_pushstring(state, "Failed to convert parameter 1 to type 'AnimationTarget'.");
  578. lua_error(state);
  579. }
  580. Animation* instance = getInstance(state);
  581. bool result = instance->targets(param1);
  582. // Push the return value onto the stack.
  583. lua_pushboolean(state, result);
  584. return 1;
  585. }
  586. lua_pushstring(state, "lua_Animation_targets - Failed to match the given parameters to a valid function signature.");
  587. lua_error(state);
  588. break;
  589. }
  590. default:
  591. {
  592. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  593. lua_error(state);
  594. break;
  595. }
  596. }
  597. return 0;
  598. }
  599. }