lua_RenderTarget.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. {"getId", lua_RenderTarget_getId},
  16. {"getRefCount", lua_RenderTarget_getRefCount},
  17. {"getTexture", lua_RenderTarget_getTexture},
  18. {"release", lua_RenderTarget_release},
  19. {NULL, NULL}
  20. };
  21. const luaL_Reg lua_statics[] =
  22. {
  23. {"create", lua_RenderTarget_static_create},
  24. {"getRenderTarget", lua_RenderTarget_static_getRenderTarget},
  25. {NULL, NULL}
  26. };
  27. std::vector<std::string> scopePath;
  28. ScriptUtil::registerClass("RenderTarget", lua_members, NULL, lua_RenderTarget__gc, lua_statics, scopePath);
  29. }
  30. static RenderTarget* getInstance(lua_State* state)
  31. {
  32. void* userdata = luaL_checkudata(state, 1, "RenderTarget");
  33. luaL_argcheck(state, userdata != NULL, 1, "'RenderTarget' expected.");
  34. return (RenderTarget*)((ScriptUtil::LuaObject*)userdata)->instance;
  35. }
  36. int lua_RenderTarget__gc(lua_State* state)
  37. {
  38. // Get the number of parameters.
  39. int paramCount = lua_gettop(state);
  40. // Attempt to match the parameters to a valid binding.
  41. switch (paramCount)
  42. {
  43. case 1:
  44. {
  45. if ((lua_type(state, 1) == LUA_TUSERDATA))
  46. {
  47. void* userdata = luaL_checkudata(state, 1, "RenderTarget");
  48. luaL_argcheck(state, userdata != NULL, 1, "'RenderTarget' expected.");
  49. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  50. if (object->owns)
  51. {
  52. RenderTarget* instance = (RenderTarget*)object->instance;
  53. SAFE_RELEASE(instance);
  54. }
  55. return 0;
  56. }
  57. else
  58. {
  59. lua_pushstring(state, "lua_RenderTarget__gc - Failed to match the given parameters to a valid function signature.");
  60. lua_error(state);
  61. }
  62. break;
  63. }
  64. default:
  65. {
  66. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  67. lua_error(state);
  68. break;
  69. }
  70. }
  71. return 0;
  72. }
  73. int lua_RenderTarget_addRef(lua_State* state)
  74. {
  75. // Get the number of parameters.
  76. int paramCount = lua_gettop(state);
  77. // Attempt to match the parameters to a valid binding.
  78. switch (paramCount)
  79. {
  80. case 1:
  81. {
  82. if ((lua_type(state, 1) == LUA_TUSERDATA))
  83. {
  84. RenderTarget* instance = getInstance(state);
  85. instance->addRef();
  86. return 0;
  87. }
  88. else
  89. {
  90. lua_pushstring(state, "lua_RenderTarget_addRef - Failed to match the given parameters to a valid function signature.");
  91. lua_error(state);
  92. }
  93. break;
  94. }
  95. default:
  96. {
  97. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  98. lua_error(state);
  99. break;
  100. }
  101. }
  102. return 0;
  103. }
  104. int lua_RenderTarget_getId(lua_State* state)
  105. {
  106. // Get the number of parameters.
  107. int paramCount = lua_gettop(state);
  108. // Attempt to match the parameters to a valid binding.
  109. switch (paramCount)
  110. {
  111. case 1:
  112. {
  113. if ((lua_type(state, 1) == LUA_TUSERDATA))
  114. {
  115. RenderTarget* instance = getInstance(state);
  116. const char* result = instance->getId();
  117. // Push the return value onto the stack.
  118. lua_pushstring(state, result);
  119. return 1;
  120. }
  121. else
  122. {
  123. lua_pushstring(state, "lua_RenderTarget_getId - Failed to match the given parameters to a valid function signature.");
  124. lua_error(state);
  125. }
  126. break;
  127. }
  128. default:
  129. {
  130. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  131. lua_error(state);
  132. break;
  133. }
  134. }
  135. return 0;
  136. }
  137. int lua_RenderTarget_getRefCount(lua_State* state)
  138. {
  139. // Get the number of parameters.
  140. int paramCount = lua_gettop(state);
  141. // Attempt to match the parameters to a valid binding.
  142. switch (paramCount)
  143. {
  144. case 1:
  145. {
  146. if ((lua_type(state, 1) == LUA_TUSERDATA))
  147. {
  148. RenderTarget* instance = getInstance(state);
  149. unsigned int result = instance->getRefCount();
  150. // Push the return value onto the stack.
  151. lua_pushunsigned(state, result);
  152. return 1;
  153. }
  154. else
  155. {
  156. lua_pushstring(state, "lua_RenderTarget_getRefCount - Failed to match the given parameters to a valid function signature.");
  157. lua_error(state);
  158. }
  159. break;
  160. }
  161. default:
  162. {
  163. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  164. lua_error(state);
  165. break;
  166. }
  167. }
  168. return 0;
  169. }
  170. int lua_RenderTarget_getTexture(lua_State* state)
  171. {
  172. // Get the number of parameters.
  173. int paramCount = lua_gettop(state);
  174. // Attempt to match the parameters to a valid binding.
  175. switch (paramCount)
  176. {
  177. case 1:
  178. {
  179. if ((lua_type(state, 1) == LUA_TUSERDATA))
  180. {
  181. RenderTarget* instance = getInstance(state);
  182. void* returnPtr = (void*)instance->getTexture();
  183. if (returnPtr)
  184. {
  185. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  186. object->instance = returnPtr;
  187. object->owns = false;
  188. luaL_getmetatable(state, "Texture");
  189. lua_setmetatable(state, -2);
  190. }
  191. else
  192. {
  193. lua_pushnil(state);
  194. }
  195. return 1;
  196. }
  197. else
  198. {
  199. lua_pushstring(state, "lua_RenderTarget_getTexture - Failed to match the given parameters to a valid function signature.");
  200. lua_error(state);
  201. }
  202. break;
  203. }
  204. default:
  205. {
  206. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  207. lua_error(state);
  208. break;
  209. }
  210. }
  211. return 0;
  212. }
  213. int lua_RenderTarget_release(lua_State* state)
  214. {
  215. // Get the number of parameters.
  216. int paramCount = lua_gettop(state);
  217. // Attempt to match the parameters to a valid binding.
  218. switch (paramCount)
  219. {
  220. case 1:
  221. {
  222. if ((lua_type(state, 1) == LUA_TUSERDATA))
  223. {
  224. RenderTarget* instance = getInstance(state);
  225. instance->release();
  226. return 0;
  227. }
  228. else
  229. {
  230. lua_pushstring(state, "lua_RenderTarget_release - Failed to match the given parameters to a valid function signature.");
  231. lua_error(state);
  232. }
  233. break;
  234. }
  235. default:
  236. {
  237. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  238. lua_error(state);
  239. break;
  240. }
  241. }
  242. return 0;
  243. }
  244. int lua_RenderTarget_static_create(lua_State* state)
  245. {
  246. // Get the number of parameters.
  247. int paramCount = lua_gettop(state);
  248. // Attempt to match the parameters to a valid binding.
  249. switch (paramCount)
  250. {
  251. case 3:
  252. {
  253. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  254. lua_type(state, 2) == LUA_TNUMBER &&
  255. lua_type(state, 3) == LUA_TNUMBER)
  256. {
  257. // Get parameter 1 off the stack.
  258. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(1, false);
  259. // Get parameter 2 off the stack.
  260. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  261. // Get parameter 3 off the stack.
  262. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 3);
  263. void* returnPtr = (void*)RenderTarget::create(param1, param2, param3);
  264. if (returnPtr)
  265. {
  266. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  267. object->instance = returnPtr;
  268. object->owns = true;
  269. luaL_getmetatable(state, "RenderTarget");
  270. lua_setmetatable(state, -2);
  271. }
  272. else
  273. {
  274. lua_pushnil(state);
  275. }
  276. return 1;
  277. }
  278. else
  279. {
  280. lua_pushstring(state, "lua_RenderTarget_static_create - Failed to match the given parameters to a valid function signature.");
  281. lua_error(state);
  282. }
  283. break;
  284. }
  285. default:
  286. {
  287. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  288. lua_error(state);
  289. break;
  290. }
  291. }
  292. return 0;
  293. }
  294. int lua_RenderTarget_static_getRenderTarget(lua_State* state)
  295. {
  296. // Get the number of parameters.
  297. int paramCount = lua_gettop(state);
  298. // Attempt to match the parameters to a valid binding.
  299. switch (paramCount)
  300. {
  301. case 1:
  302. {
  303. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  304. {
  305. // Get parameter 1 off the stack.
  306. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(1, false);
  307. void* returnPtr = (void*)RenderTarget::getRenderTarget(param1);
  308. if (returnPtr)
  309. {
  310. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  311. object->instance = returnPtr;
  312. object->owns = false;
  313. luaL_getmetatable(state, "RenderTarget");
  314. lua_setmetatable(state, -2);
  315. }
  316. else
  317. {
  318. lua_pushnil(state);
  319. }
  320. return 1;
  321. }
  322. else
  323. {
  324. lua_pushstring(state, "lua_RenderTarget_static_getRenderTarget - Failed to match the given parameters to a valid function signature.");
  325. lua_error(state);
  326. }
  327. break;
  328. }
  329. default:
  330. {
  331. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  332. lua_error(state);
  333. break;
  334. }
  335. }
  336. return 0;
  337. }
  338. }