lua_Curve.cpp 19 KB

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