lua_Curve.cpp 19 KB

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