lua_Animation.cpp 22 KB

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