lua_HeightField.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_HeightField.h"
  4. #include "Base.h"
  5. #include "FileSystem.h"
  6. #include "Game.h"
  7. #include "HeightField.h"
  8. #include "Image.h"
  9. #include "Ref.h"
  10. namespace gameplay
  11. {
  12. void luaRegister_HeightField()
  13. {
  14. const luaL_Reg lua_members[] =
  15. {
  16. {"addRef", lua_HeightField_addRef},
  17. {"getArray", lua_HeightField_getArray},
  18. {"getColumnCount", lua_HeightField_getColumnCount},
  19. {"getHeight", lua_HeightField_getHeight},
  20. {"getRefCount", lua_HeightField_getRefCount},
  21. {"getRowCount", lua_HeightField_getRowCount},
  22. {"release", lua_HeightField_release},
  23. {NULL, NULL}
  24. };
  25. const luaL_Reg lua_statics[] =
  26. {
  27. {"create", lua_HeightField_static_create},
  28. {"createFromImage", lua_HeightField_static_createFromImage},
  29. {"createFromRAW", lua_HeightField_static_createFromRAW},
  30. {NULL, NULL}
  31. };
  32. std::vector<std::string> scopePath;
  33. gameplay::ScriptUtil::registerClass("HeightField", lua_members, NULL, lua_HeightField__gc, lua_statics, scopePath);
  34. }
  35. static HeightField* getInstance(lua_State* state)
  36. {
  37. void* userdata = luaL_checkudata(state, 1, "HeightField");
  38. luaL_argcheck(state, userdata != NULL, 1, "'HeightField' expected.");
  39. return (HeightField*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  40. }
  41. int lua_HeightField__gc(lua_State* state)
  42. {
  43. // Get the number of parameters.
  44. int paramCount = lua_gettop(state);
  45. // Attempt to match the parameters to a valid binding.
  46. switch (paramCount)
  47. {
  48. case 1:
  49. {
  50. if ((lua_type(state, 1) == LUA_TUSERDATA))
  51. {
  52. void* userdata = luaL_checkudata(state, 1, "HeightField");
  53. luaL_argcheck(state, userdata != NULL, 1, "'HeightField' expected.");
  54. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  55. if (object->owns)
  56. {
  57. HeightField* instance = (HeightField*)object->instance;
  58. SAFE_RELEASE(instance);
  59. }
  60. return 0;
  61. }
  62. lua_pushstring(state, "lua_HeightField__gc - Failed to match the given parameters to a valid function signature.");
  63. lua_error(state);
  64. break;
  65. }
  66. default:
  67. {
  68. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  69. lua_error(state);
  70. break;
  71. }
  72. }
  73. return 0;
  74. }
  75. int lua_HeightField_addRef(lua_State* state)
  76. {
  77. // Get the number of parameters.
  78. int paramCount = lua_gettop(state);
  79. // Attempt to match the parameters to a valid binding.
  80. switch (paramCount)
  81. {
  82. case 1:
  83. {
  84. if ((lua_type(state, 1) == LUA_TUSERDATA))
  85. {
  86. HeightField* instance = getInstance(state);
  87. instance->addRef();
  88. return 0;
  89. }
  90. lua_pushstring(state, "lua_HeightField_addRef - Failed to match the given parameters to a valid function signature.");
  91. lua_error(state);
  92. break;
  93. }
  94. default:
  95. {
  96. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  97. lua_error(state);
  98. break;
  99. }
  100. }
  101. return 0;
  102. }
  103. int lua_HeightField_getArray(lua_State* state)
  104. {
  105. // Get the number of parameters.
  106. int paramCount = lua_gettop(state);
  107. // Attempt to match the parameters to a valid binding.
  108. switch (paramCount)
  109. {
  110. case 1:
  111. {
  112. if ((lua_type(state, 1) == LUA_TUSERDATA))
  113. {
  114. HeightField* instance = getInstance(state);
  115. float* result = instance->getArray();
  116. // Push the return value onto the stack.
  117. lua_pushlightuserdata(state, result);
  118. return 1;
  119. }
  120. lua_pushstring(state, "lua_HeightField_getArray - Failed to match the given parameters to a valid function signature.");
  121. lua_error(state);
  122. break;
  123. }
  124. default:
  125. {
  126. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  127. lua_error(state);
  128. break;
  129. }
  130. }
  131. return 0;
  132. }
  133. int lua_HeightField_getColumnCount(lua_State* state)
  134. {
  135. // Get the number of parameters.
  136. int paramCount = lua_gettop(state);
  137. // Attempt to match the parameters to a valid binding.
  138. switch (paramCount)
  139. {
  140. case 1:
  141. {
  142. if ((lua_type(state, 1) == LUA_TUSERDATA))
  143. {
  144. HeightField* instance = getInstance(state);
  145. unsigned int result = instance->getColumnCount();
  146. // Push the return value onto the stack.
  147. lua_pushunsigned(state, result);
  148. return 1;
  149. }
  150. lua_pushstring(state, "lua_HeightField_getColumnCount - Failed to match the given parameters to a valid function signature.");
  151. lua_error(state);
  152. break;
  153. }
  154. default:
  155. {
  156. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  157. lua_error(state);
  158. break;
  159. }
  160. }
  161. return 0;
  162. }
  163. int lua_HeightField_getHeight(lua_State* state)
  164. {
  165. // Get the number of parameters.
  166. int paramCount = lua_gettop(state);
  167. // Attempt to match the parameters to a valid binding.
  168. switch (paramCount)
  169. {
  170. case 3:
  171. {
  172. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  173. lua_type(state, 2) == LUA_TNUMBER &&
  174. lua_type(state, 3) == LUA_TNUMBER)
  175. {
  176. // Get parameter 1 off the stack.
  177. float param1 = (float)luaL_checknumber(state, 2);
  178. // Get parameter 2 off the stack.
  179. float param2 = (float)luaL_checknumber(state, 3);
  180. HeightField* instance = getInstance(state);
  181. float result = instance->getHeight(param1, param2);
  182. // Push the return value onto the stack.
  183. lua_pushnumber(state, result);
  184. return 1;
  185. }
  186. lua_pushstring(state, "lua_HeightField_getHeight - 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 3).");
  193. lua_error(state);
  194. break;
  195. }
  196. }
  197. return 0;
  198. }
  199. int lua_HeightField_getRefCount(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. HeightField* instance = getInstance(state);
  211. unsigned int result = instance->getRefCount();
  212. // Push the return value onto the stack.
  213. lua_pushunsigned(state, result);
  214. return 1;
  215. }
  216. lua_pushstring(state, "lua_HeightField_getRefCount - 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_HeightField_getRowCount(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. HeightField* instance = getInstance(state);
  241. unsigned int result = instance->getRowCount();
  242. // Push the return value onto the stack.
  243. lua_pushunsigned(state, result);
  244. return 1;
  245. }
  246. lua_pushstring(state, "lua_HeightField_getRowCount - 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_HeightField_release(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. HeightField* instance = getInstance(state);
  271. instance->release();
  272. return 0;
  273. }
  274. lua_pushstring(state, "lua_HeightField_release - Failed to match the given parameters to a valid function signature.");
  275. lua_error(state);
  276. break;
  277. }
  278. default:
  279. {
  280. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  281. lua_error(state);
  282. break;
  283. }
  284. }
  285. return 0;
  286. }
  287. int lua_HeightField_static_create(lua_State* state)
  288. {
  289. // Get the number of parameters.
  290. int paramCount = lua_gettop(state);
  291. // Attempt to match the parameters to a valid binding.
  292. switch (paramCount)
  293. {
  294. case 2:
  295. {
  296. if (lua_type(state, 1) == LUA_TNUMBER &&
  297. lua_type(state, 2) == LUA_TNUMBER)
  298. {
  299. // Get parameter 1 off the stack.
  300. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 1);
  301. // Get parameter 2 off the stack.
  302. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  303. void* returnPtr = (void*)HeightField::create(param1, param2);
  304. if (returnPtr)
  305. {
  306. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  307. object->instance = returnPtr;
  308. object->owns = false;
  309. luaL_getmetatable(state, "HeightField");
  310. lua_setmetatable(state, -2);
  311. }
  312. else
  313. {
  314. lua_pushnil(state);
  315. }
  316. return 1;
  317. }
  318. lua_pushstring(state, "lua_HeightField_static_create - Failed to match the given parameters to a valid function signature.");
  319. lua_error(state);
  320. break;
  321. }
  322. default:
  323. {
  324. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  325. lua_error(state);
  326. break;
  327. }
  328. }
  329. return 0;
  330. }
  331. int lua_HeightField_static_createFromImage(lua_State* state)
  332. {
  333. // Get the number of parameters.
  334. int paramCount = lua_gettop(state);
  335. // Attempt to match the parameters to a valid binding.
  336. switch (paramCount)
  337. {
  338. case 1:
  339. {
  340. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  341. {
  342. // Get parameter 1 off the stack.
  343. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  344. void* returnPtr = (void*)HeightField::createFromImage(param1);
  345. if (returnPtr)
  346. {
  347. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  348. object->instance = returnPtr;
  349. object->owns = false;
  350. luaL_getmetatable(state, "HeightField");
  351. lua_setmetatable(state, -2);
  352. }
  353. else
  354. {
  355. lua_pushnil(state);
  356. }
  357. return 1;
  358. }
  359. lua_pushstring(state, "lua_HeightField_static_createFromImage - Failed to match the given parameters to a valid function signature.");
  360. lua_error(state);
  361. break;
  362. }
  363. case 2:
  364. {
  365. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  366. lua_type(state, 2) == LUA_TNUMBER)
  367. {
  368. // Get parameter 1 off the stack.
  369. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  370. // Get parameter 2 off the stack.
  371. float param2 = (float)luaL_checknumber(state, 2);
  372. void* returnPtr = (void*)HeightField::createFromImage(param1, param2);
  373. if (returnPtr)
  374. {
  375. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  376. object->instance = returnPtr;
  377. object->owns = false;
  378. luaL_getmetatable(state, "HeightField");
  379. lua_setmetatable(state, -2);
  380. }
  381. else
  382. {
  383. lua_pushnil(state);
  384. }
  385. return 1;
  386. }
  387. lua_pushstring(state, "lua_HeightField_static_createFromImage - Failed to match the given parameters to a valid function signature.");
  388. lua_error(state);
  389. break;
  390. }
  391. case 3:
  392. {
  393. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  394. lua_type(state, 2) == LUA_TNUMBER &&
  395. lua_type(state, 3) == LUA_TNUMBER)
  396. {
  397. // Get parameter 1 off the stack.
  398. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  399. // Get parameter 2 off the stack.
  400. float param2 = (float)luaL_checknumber(state, 2);
  401. // Get parameter 3 off the stack.
  402. float param3 = (float)luaL_checknumber(state, 3);
  403. void* returnPtr = (void*)HeightField::createFromImage(param1, param2, param3);
  404. if (returnPtr)
  405. {
  406. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  407. object->instance = returnPtr;
  408. object->owns = false;
  409. luaL_getmetatable(state, "HeightField");
  410. lua_setmetatable(state, -2);
  411. }
  412. else
  413. {
  414. lua_pushnil(state);
  415. }
  416. return 1;
  417. }
  418. lua_pushstring(state, "lua_HeightField_static_createFromImage - Failed to match the given parameters to a valid function signature.");
  419. lua_error(state);
  420. break;
  421. }
  422. default:
  423. {
  424. lua_pushstring(state, "Invalid number of parameters (expected 1, 2 or 3).");
  425. lua_error(state);
  426. break;
  427. }
  428. }
  429. return 0;
  430. }
  431. int lua_HeightField_static_createFromRAW(lua_State* state)
  432. {
  433. // Get the number of parameters.
  434. int paramCount = lua_gettop(state);
  435. // Attempt to match the parameters to a valid binding.
  436. switch (paramCount)
  437. {
  438. case 3:
  439. {
  440. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  441. lua_type(state, 2) == LUA_TNUMBER &&
  442. lua_type(state, 3) == LUA_TNUMBER)
  443. {
  444. // Get parameter 1 off the stack.
  445. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  446. // Get parameter 2 off the stack.
  447. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  448. // Get parameter 3 off the stack.
  449. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 3);
  450. void* returnPtr = (void*)HeightField::createFromRAW(param1, param2, param3);
  451. if (returnPtr)
  452. {
  453. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  454. object->instance = returnPtr;
  455. object->owns = false;
  456. luaL_getmetatable(state, "HeightField");
  457. lua_setmetatable(state, -2);
  458. }
  459. else
  460. {
  461. lua_pushnil(state);
  462. }
  463. return 1;
  464. }
  465. lua_pushstring(state, "lua_HeightField_static_createFromRAW - Failed to match the given parameters to a valid function signature.");
  466. lua_error(state);
  467. break;
  468. }
  469. case 4:
  470. {
  471. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  472. lua_type(state, 2) == LUA_TNUMBER &&
  473. lua_type(state, 3) == LUA_TNUMBER &&
  474. lua_type(state, 4) == LUA_TNUMBER)
  475. {
  476. // Get parameter 1 off the stack.
  477. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  478. // Get parameter 2 off the stack.
  479. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  480. // Get parameter 3 off the stack.
  481. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 3);
  482. // Get parameter 4 off the stack.
  483. float param4 = (float)luaL_checknumber(state, 4);
  484. void* returnPtr = (void*)HeightField::createFromRAW(param1, param2, param3, param4);
  485. if (returnPtr)
  486. {
  487. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  488. object->instance = returnPtr;
  489. object->owns = false;
  490. luaL_getmetatable(state, "HeightField");
  491. lua_setmetatable(state, -2);
  492. }
  493. else
  494. {
  495. lua_pushnil(state);
  496. }
  497. return 1;
  498. }
  499. lua_pushstring(state, "lua_HeightField_static_createFromRAW - Failed to match the given parameters to a valid function signature.");
  500. lua_error(state);
  501. break;
  502. }
  503. case 5:
  504. {
  505. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  506. lua_type(state, 2) == LUA_TNUMBER &&
  507. lua_type(state, 3) == LUA_TNUMBER &&
  508. lua_type(state, 4) == LUA_TNUMBER &&
  509. lua_type(state, 5) == LUA_TNUMBER)
  510. {
  511. // Get parameter 1 off the stack.
  512. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  513. // Get parameter 2 off the stack.
  514. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  515. // Get parameter 3 off the stack.
  516. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 3);
  517. // Get parameter 4 off the stack.
  518. float param4 = (float)luaL_checknumber(state, 4);
  519. // Get parameter 5 off the stack.
  520. float param5 = (float)luaL_checknumber(state, 5);
  521. void* returnPtr = (void*)HeightField::createFromRAW(param1, param2, param3, param4, param5);
  522. if (returnPtr)
  523. {
  524. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  525. object->instance = returnPtr;
  526. object->owns = false;
  527. luaL_getmetatable(state, "HeightField");
  528. lua_setmetatable(state, -2);
  529. }
  530. else
  531. {
  532. lua_pushnil(state);
  533. }
  534. return 1;
  535. }
  536. lua_pushstring(state, "lua_HeightField_static_createFromRAW - Failed to match the given parameters to a valid function signature.");
  537. lua_error(state);
  538. break;
  539. }
  540. default:
  541. {
  542. lua_pushstring(state, "Invalid number of parameters (expected 3, 4 or 5).");
  543. lua_error(state);
  544. break;
  545. }
  546. }
  547. return 0;
  548. }
  549. }