lua_RenderTarget.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_RenderTarget.h"
  4. #include "Base.h"
  5. #include "Game.h"
  6. #include "Ref.h"
  7. #include "RenderTarget.h"
  8. namespace gameplay
  9. {
  10. void luaRegister_RenderTarget()
  11. {
  12. const luaL_Reg lua_members[] =
  13. {
  14. {"addRef", lua_RenderTarget_addRef},
  15. {"getHeight", lua_RenderTarget_getHeight},
  16. {"getId", lua_RenderTarget_getId},
  17. {"getRefCount", lua_RenderTarget_getRefCount},
  18. {"getTexture", lua_RenderTarget_getTexture},
  19. {"getWidth", lua_RenderTarget_getWidth},
  20. {"release", lua_RenderTarget_release},
  21. {NULL, NULL}
  22. };
  23. const luaL_Reg lua_statics[] =
  24. {
  25. {"create", lua_RenderTarget_static_create},
  26. {"getRenderTarget", lua_RenderTarget_static_getRenderTarget},
  27. {NULL, NULL}
  28. };
  29. std::vector<std::string> scopePath;
  30. gameplay::ScriptUtil::registerClass("RenderTarget", lua_members, NULL, lua_RenderTarget__gc, lua_statics, scopePath);
  31. }
  32. static RenderTarget* getInstance(lua_State* state)
  33. {
  34. void* userdata = luaL_checkudata(state, 1, "RenderTarget");
  35. luaL_argcheck(state, userdata != NULL, 1, "'RenderTarget' expected.");
  36. return (RenderTarget*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  37. }
  38. int lua_RenderTarget__gc(lua_State* state)
  39. {
  40. // Get the number of parameters.
  41. int paramCount = lua_gettop(state);
  42. // Attempt to match the parameters to a valid binding.
  43. switch (paramCount)
  44. {
  45. case 1:
  46. {
  47. if ((lua_type(state, 1) == LUA_TUSERDATA))
  48. {
  49. void* userdata = luaL_checkudata(state, 1, "RenderTarget");
  50. luaL_argcheck(state, userdata != NULL, 1, "'RenderTarget' expected.");
  51. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  52. if (object->owns)
  53. {
  54. RenderTarget* instance = (RenderTarget*)object->instance;
  55. SAFE_RELEASE(instance);
  56. }
  57. return 0;
  58. }
  59. lua_pushstring(state, "lua_RenderTarget__gc - Failed to match the given parameters to a valid function signature.");
  60. lua_error(state);
  61. break;
  62. }
  63. default:
  64. {
  65. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  66. lua_error(state);
  67. break;
  68. }
  69. }
  70. return 0;
  71. }
  72. int lua_RenderTarget_addRef(lua_State* state)
  73. {
  74. // Get the number of parameters.
  75. int paramCount = lua_gettop(state);
  76. // Attempt to match the parameters to a valid binding.
  77. switch (paramCount)
  78. {
  79. case 1:
  80. {
  81. if ((lua_type(state, 1) == LUA_TUSERDATA))
  82. {
  83. RenderTarget* instance = getInstance(state);
  84. instance->addRef();
  85. return 0;
  86. }
  87. lua_pushstring(state, "lua_RenderTarget_addRef - Failed to match the given parameters to a valid function signature.");
  88. lua_error(state);
  89. break;
  90. }
  91. default:
  92. {
  93. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  94. lua_error(state);
  95. break;
  96. }
  97. }
  98. return 0;
  99. }
  100. int lua_RenderTarget_getHeight(lua_State* state)
  101. {
  102. // Get the number of parameters.
  103. int paramCount = lua_gettop(state);
  104. // Attempt to match the parameters to a valid binding.
  105. switch (paramCount)
  106. {
  107. case 1:
  108. {
  109. if ((lua_type(state, 1) == LUA_TUSERDATA))
  110. {
  111. RenderTarget* instance = getInstance(state);
  112. unsigned int result = instance->getHeight();
  113. // Push the return value onto the stack.
  114. lua_pushunsigned(state, result);
  115. return 1;
  116. }
  117. lua_pushstring(state, "lua_RenderTarget_getHeight - Failed to match the given parameters to a valid function signature.");
  118. lua_error(state);
  119. break;
  120. }
  121. default:
  122. {
  123. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  124. lua_error(state);
  125. break;
  126. }
  127. }
  128. return 0;
  129. }
  130. int lua_RenderTarget_getId(lua_State* state)
  131. {
  132. // Get the number of parameters.
  133. int paramCount = lua_gettop(state);
  134. // Attempt to match the parameters to a valid binding.
  135. switch (paramCount)
  136. {
  137. case 1:
  138. {
  139. if ((lua_type(state, 1) == LUA_TUSERDATA))
  140. {
  141. RenderTarget* instance = getInstance(state);
  142. const char* result = instance->getId();
  143. // Push the return value onto the stack.
  144. lua_pushstring(state, result);
  145. return 1;
  146. }
  147. lua_pushstring(state, "lua_RenderTarget_getId - Failed to match the given parameters to a valid function signature.");
  148. lua_error(state);
  149. break;
  150. }
  151. default:
  152. {
  153. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  154. lua_error(state);
  155. break;
  156. }
  157. }
  158. return 0;
  159. }
  160. int lua_RenderTarget_getRefCount(lua_State* state)
  161. {
  162. // Get the number of parameters.
  163. int paramCount = lua_gettop(state);
  164. // Attempt to match the parameters to a valid binding.
  165. switch (paramCount)
  166. {
  167. case 1:
  168. {
  169. if ((lua_type(state, 1) == LUA_TUSERDATA))
  170. {
  171. RenderTarget* instance = getInstance(state);
  172. unsigned int result = instance->getRefCount();
  173. // Push the return value onto the stack.
  174. lua_pushunsigned(state, result);
  175. return 1;
  176. }
  177. lua_pushstring(state, "lua_RenderTarget_getRefCount - Failed to match the given parameters to a valid function signature.");
  178. lua_error(state);
  179. break;
  180. }
  181. default:
  182. {
  183. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  184. lua_error(state);
  185. break;
  186. }
  187. }
  188. return 0;
  189. }
  190. int lua_RenderTarget_getTexture(lua_State* state)
  191. {
  192. // Get the number of parameters.
  193. int paramCount = lua_gettop(state);
  194. // Attempt to match the parameters to a valid binding.
  195. switch (paramCount)
  196. {
  197. case 1:
  198. {
  199. if ((lua_type(state, 1) == LUA_TUSERDATA))
  200. {
  201. RenderTarget* instance = getInstance(state);
  202. void* returnPtr = (void*)instance->getTexture();
  203. if (returnPtr)
  204. {
  205. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  206. object->instance = returnPtr;
  207. object->owns = false;
  208. luaL_getmetatable(state, "Texture");
  209. lua_setmetatable(state, -2);
  210. }
  211. else
  212. {
  213. lua_pushnil(state);
  214. }
  215. return 1;
  216. }
  217. lua_pushstring(state, "lua_RenderTarget_getTexture - Failed to match the given parameters to a valid function signature.");
  218. lua_error(state);
  219. break;
  220. }
  221. default:
  222. {
  223. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  224. lua_error(state);
  225. break;
  226. }
  227. }
  228. return 0;
  229. }
  230. int lua_RenderTarget_getWidth(lua_State* state)
  231. {
  232. // Get the number of parameters.
  233. int paramCount = lua_gettop(state);
  234. // Attempt to match the parameters to a valid binding.
  235. switch (paramCount)
  236. {
  237. case 1:
  238. {
  239. if ((lua_type(state, 1) == LUA_TUSERDATA))
  240. {
  241. RenderTarget* instance = getInstance(state);
  242. unsigned int result = instance->getWidth();
  243. // Push the return value onto the stack.
  244. lua_pushunsigned(state, result);
  245. return 1;
  246. }
  247. lua_pushstring(state, "lua_RenderTarget_getWidth - Failed to match the given parameters to a valid function signature.");
  248. lua_error(state);
  249. break;
  250. }
  251. default:
  252. {
  253. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  254. lua_error(state);
  255. break;
  256. }
  257. }
  258. return 0;
  259. }
  260. int lua_RenderTarget_release(lua_State* state)
  261. {
  262. // Get the number of parameters.
  263. int paramCount = lua_gettop(state);
  264. // Attempt to match the parameters to a valid binding.
  265. switch (paramCount)
  266. {
  267. case 1:
  268. {
  269. if ((lua_type(state, 1) == LUA_TUSERDATA))
  270. {
  271. RenderTarget* instance = getInstance(state);
  272. instance->release();
  273. return 0;
  274. }
  275. lua_pushstring(state, "lua_RenderTarget_release - Failed to match the given parameters to a valid function signature.");
  276. lua_error(state);
  277. break;
  278. }
  279. default:
  280. {
  281. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  282. lua_error(state);
  283. break;
  284. }
  285. }
  286. return 0;
  287. }
  288. int lua_RenderTarget_static_create(lua_State* state)
  289. {
  290. // Get the number of parameters.
  291. int paramCount = lua_gettop(state);
  292. // Attempt to match the parameters to a valid binding.
  293. switch (paramCount)
  294. {
  295. case 2:
  296. {
  297. do
  298. {
  299. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  300. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  301. {
  302. // Get parameter 1 off the stack.
  303. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  304. // Get parameter 2 off the stack.
  305. bool param2Valid;
  306. gameplay::ScriptUtil::LuaArray<Texture> param2 = gameplay::ScriptUtil::getObjectPointer<Texture>(2, "Texture", false, &param2Valid);
  307. if (!param2Valid)
  308. break;
  309. void* returnPtr = (void*)RenderTarget::create(param1, param2);
  310. if (returnPtr)
  311. {
  312. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  313. object->instance = returnPtr;
  314. object->owns = true;
  315. luaL_getmetatable(state, "RenderTarget");
  316. lua_setmetatable(state, -2);
  317. }
  318. else
  319. {
  320. lua_pushnil(state);
  321. }
  322. return 1;
  323. }
  324. } while (0);
  325. lua_pushstring(state, "lua_RenderTarget_static_create - Failed to match the given parameters to a valid function signature.");
  326. lua_error(state);
  327. break;
  328. }
  329. case 3:
  330. {
  331. do
  332. {
  333. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  334. lua_type(state, 2) == LUA_TNUMBER &&
  335. lua_type(state, 3) == LUA_TNUMBER)
  336. {
  337. // Get parameter 1 off the stack.
  338. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  339. // Get parameter 2 off the stack.
  340. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  341. // Get parameter 3 off the stack.
  342. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 3);
  343. void* returnPtr = (void*)RenderTarget::create(param1, param2, param3);
  344. if (returnPtr)
  345. {
  346. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  347. object->instance = returnPtr;
  348. object->owns = true;
  349. luaL_getmetatable(state, "RenderTarget");
  350. lua_setmetatable(state, -2);
  351. }
  352. else
  353. {
  354. lua_pushnil(state);
  355. }
  356. return 1;
  357. }
  358. } while (0);
  359. lua_pushstring(state, "lua_RenderTarget_static_create - Failed to match the given parameters to a valid function signature.");
  360. lua_error(state);
  361. break;
  362. }
  363. default:
  364. {
  365. lua_pushstring(state, "Invalid number of parameters (expected 2 or 3).");
  366. lua_error(state);
  367. break;
  368. }
  369. }
  370. return 0;
  371. }
  372. int lua_RenderTarget_static_getRenderTarget(lua_State* state)
  373. {
  374. // Get the number of parameters.
  375. int paramCount = lua_gettop(state);
  376. // Attempt to match the parameters to a valid binding.
  377. switch (paramCount)
  378. {
  379. case 1:
  380. {
  381. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  382. {
  383. // Get parameter 1 off the stack.
  384. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  385. void* returnPtr = (void*)RenderTarget::getRenderTarget(param1);
  386. if (returnPtr)
  387. {
  388. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  389. object->instance = returnPtr;
  390. object->owns = false;
  391. luaL_getmetatable(state, "RenderTarget");
  392. lua_setmetatable(state, -2);
  393. }
  394. else
  395. {
  396. lua_pushnil(state);
  397. }
  398. return 1;
  399. }
  400. lua_pushstring(state, "lua_RenderTarget_static_getRenderTarget - Failed to match the given parameters to a valid function signature.");
  401. lua_error(state);
  402. break;
  403. }
  404. default:
  405. {
  406. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  407. lua_error(state);
  408. break;
  409. }
  410. }
  411. return 0;
  412. }
  413. }