lua_Curve.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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. gameplay::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*)((gameplay::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. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  57. if (object->owns)
  58. {
  59. Curve* instance = (Curve*)object->instance;
  60. SAFE_RELEASE(instance);
  61. }
  62. return 0;
  63. }
  64. lua_pushstring(state, "lua_Curve__gc - Failed to match the given parameters to a valid function signature.");
  65. lua_error(state);
  66. break;
  67. }
  68. default:
  69. {
  70. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  71. lua_error(state);
  72. break;
  73. }
  74. }
  75. return 0;
  76. }
  77. int lua_Curve_addRef(lua_State* state)
  78. {
  79. // Get the number of parameters.
  80. int paramCount = lua_gettop(state);
  81. // Attempt to match the parameters to a valid binding.
  82. switch (paramCount)
  83. {
  84. case 1:
  85. {
  86. if ((lua_type(state, 1) == LUA_TUSERDATA))
  87. {
  88. Curve* instance = getInstance(state);
  89. instance->addRef();
  90. return 0;
  91. }
  92. lua_pushstring(state, "lua_Curve_addRef - Failed to match the given parameters to a valid function signature.");
  93. lua_error(state);
  94. break;
  95. }
  96. default:
  97. {
  98. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  99. lua_error(state);
  100. break;
  101. }
  102. }
  103. return 0;
  104. }
  105. int lua_Curve_evaluate(lua_State* state)
  106. {
  107. // Get the number of parameters.
  108. int paramCount = lua_gettop(state);
  109. // Attempt to match the parameters to a valid binding.
  110. switch (paramCount)
  111. {
  112. case 3:
  113. {
  114. do
  115. {
  116. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  117. lua_type(state, 2) == LUA_TNUMBER &&
  118. (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA))
  119. {
  120. // Get parameter 1 off the stack.
  121. float param1 = (float)luaL_checknumber(state, 2);
  122. // Get parameter 2 off the stack.
  123. gameplay::ScriptUtil::LuaArray<float> param2 = gameplay::ScriptUtil::getFloatPointer(3);
  124. Curve* instance = getInstance(state);
  125. instance->evaluate(param1, param2);
  126. return 0;
  127. }
  128. } while (0);
  129. lua_pushstring(state, "lua_Curve_evaluate - Failed to match the given parameters to a valid function signature.");
  130. lua_error(state);
  131. break;
  132. }
  133. case 6:
  134. {
  135. do
  136. {
  137. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  138. lua_type(state, 2) == LUA_TNUMBER &&
  139. lua_type(state, 3) == LUA_TNUMBER &&
  140. lua_type(state, 4) == LUA_TNUMBER &&
  141. lua_type(state, 5) == LUA_TNUMBER &&
  142. (lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TLIGHTUSERDATA))
  143. {
  144. // Get parameter 1 off the stack.
  145. float param1 = (float)luaL_checknumber(state, 2);
  146. // Get parameter 2 off the stack.
  147. float param2 = (float)luaL_checknumber(state, 3);
  148. // Get parameter 3 off the stack.
  149. float param3 = (float)luaL_checknumber(state, 4);
  150. // Get parameter 4 off the stack.
  151. float param4 = (float)luaL_checknumber(state, 5);
  152. // Get parameter 5 off the stack.
  153. gameplay::ScriptUtil::LuaArray<float> param5 = gameplay::ScriptUtil::getFloatPointer(6);
  154. Curve* instance = getInstance(state);
  155. instance->evaluate(param1, param2, param3, param4, param5);
  156. return 0;
  157. }
  158. } while (0);
  159. lua_pushstring(state, "lua_Curve_evaluate - Failed to match the given parameters to a valid function signature.");
  160. lua_error(state);
  161. break;
  162. }
  163. default:
  164. {
  165. lua_pushstring(state, "Invalid number of parameters (expected 3 or 6).");
  166. lua_error(state);
  167. break;
  168. }
  169. }
  170. return 0;
  171. }
  172. int lua_Curve_getComponentCount(lua_State* state)
  173. {
  174. // Get the number of parameters.
  175. int paramCount = lua_gettop(state);
  176. // Attempt to match the parameters to a valid binding.
  177. switch (paramCount)
  178. {
  179. case 1:
  180. {
  181. if ((lua_type(state, 1) == LUA_TUSERDATA))
  182. {
  183. Curve* instance = getInstance(state);
  184. unsigned int result = instance->getComponentCount();
  185. // Push the return value onto the stack.
  186. lua_pushunsigned(state, result);
  187. return 1;
  188. }
  189. lua_pushstring(state, "lua_Curve_getComponentCount - Failed to match the given parameters to a valid function signature.");
  190. lua_error(state);
  191. break;
  192. }
  193. default:
  194. {
  195. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  196. lua_error(state);
  197. break;
  198. }
  199. }
  200. return 0;
  201. }
  202. int lua_Curve_getEndTime(lua_State* state)
  203. {
  204. // Get the number of parameters.
  205. int paramCount = lua_gettop(state);
  206. // Attempt to match the parameters to a valid binding.
  207. switch (paramCount)
  208. {
  209. case 1:
  210. {
  211. if ((lua_type(state, 1) == LUA_TUSERDATA))
  212. {
  213. Curve* instance = getInstance(state);
  214. float result = instance->getEndTime();
  215. // Push the return value onto the stack.
  216. lua_pushnumber(state, result);
  217. return 1;
  218. }
  219. lua_pushstring(state, "lua_Curve_getEndTime - Failed to match the given parameters to a valid function signature.");
  220. lua_error(state);
  221. break;
  222. }
  223. default:
  224. {
  225. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  226. lua_error(state);
  227. break;
  228. }
  229. }
  230. return 0;
  231. }
  232. int lua_Curve_getPointCount(lua_State* state)
  233. {
  234. // Get the number of parameters.
  235. int paramCount = lua_gettop(state);
  236. // Attempt to match the parameters to a valid binding.
  237. switch (paramCount)
  238. {
  239. case 1:
  240. {
  241. if ((lua_type(state, 1) == LUA_TUSERDATA))
  242. {
  243. Curve* instance = getInstance(state);
  244. unsigned int result = instance->getPointCount();
  245. // Push the return value onto the stack.
  246. lua_pushunsigned(state, result);
  247. return 1;
  248. }
  249. lua_pushstring(state, "lua_Curve_getPointCount - Failed to match the given parameters to a valid function signature.");
  250. lua_error(state);
  251. break;
  252. }
  253. default:
  254. {
  255. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  256. lua_error(state);
  257. break;
  258. }
  259. }
  260. return 0;
  261. }
  262. int lua_Curve_getRefCount(lua_State* state)
  263. {
  264. // Get the number of parameters.
  265. int paramCount = lua_gettop(state);
  266. // Attempt to match the parameters to a valid binding.
  267. switch (paramCount)
  268. {
  269. case 1:
  270. {
  271. if ((lua_type(state, 1) == LUA_TUSERDATA))
  272. {
  273. Curve* instance = getInstance(state);
  274. unsigned int result = instance->getRefCount();
  275. // Push the return value onto the stack.
  276. lua_pushunsigned(state, result);
  277. return 1;
  278. }
  279. lua_pushstring(state, "lua_Curve_getRefCount - Failed to match the given parameters to a valid function signature.");
  280. lua_error(state);
  281. break;
  282. }
  283. default:
  284. {
  285. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  286. lua_error(state);
  287. break;
  288. }
  289. }
  290. return 0;
  291. }
  292. int lua_Curve_getStartTime(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. Curve* instance = getInstance(state);
  304. float result = instance->getStartTime();
  305. // Push the return value onto the stack.
  306. lua_pushnumber(state, result);
  307. return 1;
  308. }
  309. lua_pushstring(state, "lua_Curve_getStartTime - Failed to match the given parameters to a valid function signature.");
  310. lua_error(state);
  311. break;
  312. }
  313. default:
  314. {
  315. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  316. lua_error(state);
  317. break;
  318. }
  319. }
  320. return 0;
  321. }
  322. int lua_Curve_release(lua_State* state)
  323. {
  324. // Get the number of parameters.
  325. int paramCount = lua_gettop(state);
  326. // Attempt to match the parameters to a valid binding.
  327. switch (paramCount)
  328. {
  329. case 1:
  330. {
  331. if ((lua_type(state, 1) == LUA_TUSERDATA))
  332. {
  333. Curve* instance = getInstance(state);
  334. instance->release();
  335. return 0;
  336. }
  337. lua_pushstring(state, "lua_Curve_release - Failed to match the given parameters to a valid function signature.");
  338. lua_error(state);
  339. break;
  340. }
  341. default:
  342. {
  343. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  344. lua_error(state);
  345. break;
  346. }
  347. }
  348. return 0;
  349. }
  350. int lua_Curve_setPoint(lua_State* state)
  351. {
  352. // Get the number of parameters.
  353. int paramCount = lua_gettop(state);
  354. // Attempt to match the parameters to a valid binding.
  355. switch (paramCount)
  356. {
  357. case 5:
  358. {
  359. do
  360. {
  361. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  362. lua_type(state, 2) == LUA_TNUMBER &&
  363. lua_type(state, 3) == LUA_TNUMBER &&
  364. (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
  365. (lua_type(state, 5) == LUA_TSTRING || lua_type(state, 5) == LUA_TNIL))
  366. {
  367. // Get parameter 1 off the stack.
  368. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  369. // Get parameter 2 off the stack.
  370. float param2 = (float)luaL_checknumber(state, 3);
  371. // Get parameter 3 off the stack.
  372. gameplay::ScriptUtil::LuaArray<float> param3 = gameplay::ScriptUtil::getFloatPointer(4);
  373. // Get parameter 4 off the stack.
  374. Curve::InterpolationType param4 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 5));
  375. Curve* instance = getInstance(state);
  376. instance->setPoint(param1, param2, param3, param4);
  377. return 0;
  378. }
  379. } while (0);
  380. lua_pushstring(state, "lua_Curve_setPoint - Failed to match the given parameters to a valid function signature.");
  381. lua_error(state);
  382. break;
  383. }
  384. case 7:
  385. {
  386. do
  387. {
  388. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  389. lua_type(state, 2) == LUA_TNUMBER &&
  390. lua_type(state, 3) == LUA_TNUMBER &&
  391. (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
  392. (lua_type(state, 5) == LUA_TSTRING || lua_type(state, 5) == LUA_TNIL) &&
  393. (lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TLIGHTUSERDATA) &&
  394. (lua_type(state, 7) == LUA_TTABLE || lua_type(state, 7) == LUA_TLIGHTUSERDATA))
  395. {
  396. // Get parameter 1 off the stack.
  397. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  398. // Get parameter 2 off the stack.
  399. float param2 = (float)luaL_checknumber(state, 3);
  400. // Get parameter 3 off the stack.
  401. gameplay::ScriptUtil::LuaArray<float> param3 = gameplay::ScriptUtil::getFloatPointer(4);
  402. // Get parameter 4 off the stack.
  403. Curve::InterpolationType param4 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 5));
  404. // Get parameter 5 off the stack.
  405. gameplay::ScriptUtil::LuaArray<float> param5 = gameplay::ScriptUtil::getFloatPointer(6);
  406. // Get parameter 6 off the stack.
  407. gameplay::ScriptUtil::LuaArray<float> param6 = gameplay::ScriptUtil::getFloatPointer(7);
  408. Curve* instance = getInstance(state);
  409. instance->setPoint(param1, param2, param3, param4, param5, param6);
  410. return 0;
  411. }
  412. } while (0);
  413. lua_pushstring(state, "lua_Curve_setPoint - Failed to match the given parameters to a valid function signature.");
  414. lua_error(state);
  415. break;
  416. }
  417. default:
  418. {
  419. lua_pushstring(state, "Invalid number of parameters (expected 5 or 7).");
  420. lua_error(state);
  421. break;
  422. }
  423. }
  424. return 0;
  425. }
  426. int lua_Curve_setTangent(lua_State* state)
  427. {
  428. // Get the number of parameters.
  429. int paramCount = lua_gettop(state);
  430. // Attempt to match the parameters to a valid binding.
  431. switch (paramCount)
  432. {
  433. case 5:
  434. {
  435. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  436. lua_type(state, 2) == LUA_TNUMBER &&
  437. (lua_type(state, 3) == LUA_TSTRING || lua_type(state, 3) == LUA_TNIL) &&
  438. (lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TLIGHTUSERDATA) &&
  439. (lua_type(state, 5) == LUA_TTABLE || lua_type(state, 5) == LUA_TLIGHTUSERDATA))
  440. {
  441. // Get parameter 1 off the stack.
  442. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  443. // Get parameter 2 off the stack.
  444. Curve::InterpolationType param2 = (Curve::InterpolationType)lua_enumFromString_CurveInterpolationType(luaL_checkstring(state, 3));
  445. // Get parameter 3 off the stack.
  446. gameplay::ScriptUtil::LuaArray<float> param3 = gameplay::ScriptUtil::getFloatPointer(4);
  447. // Get parameter 4 off the stack.
  448. gameplay::ScriptUtil::LuaArray<float> param4 = gameplay::ScriptUtil::getFloatPointer(5);
  449. Curve* instance = getInstance(state);
  450. instance->setTangent(param1, param2, param3, param4);
  451. return 0;
  452. }
  453. lua_pushstring(state, "lua_Curve_setTangent - Failed to match the given parameters to a valid function signature.");
  454. lua_error(state);
  455. break;
  456. }
  457. default:
  458. {
  459. lua_pushstring(state, "Invalid number of parameters (expected 5).");
  460. lua_error(state);
  461. break;
  462. }
  463. }
  464. return 0;
  465. }
  466. int lua_Curve_static_create(lua_State* state)
  467. {
  468. // Get the number of parameters.
  469. int paramCount = lua_gettop(state);
  470. // Attempt to match the parameters to a valid binding.
  471. switch (paramCount)
  472. {
  473. case 2:
  474. {
  475. if (lua_type(state, 1) == LUA_TNUMBER &&
  476. lua_type(state, 2) == LUA_TNUMBER)
  477. {
  478. // Get parameter 1 off the stack.
  479. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 1);
  480. // Get parameter 2 off the stack.
  481. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  482. void* returnPtr = (void*)Curve::create(param1, param2);
  483. if (returnPtr)
  484. {
  485. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  486. object->instance = returnPtr;
  487. object->owns = true;
  488. luaL_getmetatable(state, "Curve");
  489. lua_setmetatable(state, -2);
  490. }
  491. else
  492. {
  493. lua_pushnil(state);
  494. }
  495. return 1;
  496. }
  497. lua_pushstring(state, "lua_Curve_static_create - Failed to match the given parameters to a valid function signature.");
  498. lua_error(state);
  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. lua_pushstring(state, "lua_Curve_static_lerp - Failed to match the given parameters to a valid function signature.");
  535. lua_error(state);
  536. break;
  537. }
  538. default:
  539. {
  540. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  541. lua_error(state);
  542. break;
  543. }
  544. }
  545. return 0;
  546. }
  547. }