lua_RenderTarget.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "RenderTarget.h"
  4. #include "lua_RenderTarget.h"
  5. #include "lua_Global.h"
  6. namespace gameplay
  7. {
  8. void luaRegister_RenderTarget()
  9. {
  10. ScriptController* sc = ScriptController::getInstance();
  11. const luaL_Reg lua_members[] =
  12. {
  13. {"addRef", lua_RenderTarget_addRef},
  14. {"getId", lua_RenderTarget_getId},
  15. {"getRefCount", lua_RenderTarget_getRefCount},
  16. {"getTexture", lua_RenderTarget_getTexture},
  17. {"release", lua_RenderTarget_release},
  18. {NULL, NULL}
  19. };
  20. const luaL_Reg lua_statics[] =
  21. {
  22. {"create", lua_RenderTarget_static_create},
  23. {"getRenderTarget", lua_RenderTarget_static_getRenderTarget},
  24. {NULL, NULL}
  25. };
  26. std::vector<std::string> scopePath;
  27. sc->registerClass("RenderTarget", lua_members, NULL, lua_RenderTarget__gc, lua_statics, scopePath);
  28. }
  29. static RenderTarget* getInstance(lua_State* state)
  30. {
  31. void* userdata = luaL_checkudata(state, 1, "RenderTarget");
  32. luaL_argcheck(state, userdata != NULL, 1, "'RenderTarget' expected.");
  33. return (RenderTarget*)((ScriptController::LuaObject*)userdata)->instance;
  34. }
  35. int lua_RenderTarget__gc(lua_State* state)
  36. {
  37. // Get the number of parameters.
  38. int paramCount = lua_gettop(state);
  39. // Attempt to match the parameters to a valid binding.
  40. switch (paramCount)
  41. {
  42. case 1:
  43. {
  44. if ((lua_type(state, 1) == LUA_TUSERDATA))
  45. {
  46. void* userdata = luaL_checkudata(state, 1, "RenderTarget");
  47. luaL_argcheck(state, userdata != NULL, 1, "'RenderTarget' expected.");
  48. ScriptController::LuaObject* object = (ScriptController::LuaObject*)userdata;
  49. if (object->owns)
  50. {
  51. RenderTarget* instance = (RenderTarget*)object->instance;
  52. SAFE_RELEASE(instance);
  53. }
  54. return 0;
  55. }
  56. else
  57. {
  58. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  59. lua_error(state);
  60. }
  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. else
  88. {
  89. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  90. lua_error(state);
  91. }
  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_RenderTarget_getId(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. RenderTarget* instance = getInstance(state);
  115. const char* result = instance->getId();
  116. // Push the return value onto the stack.
  117. lua_pushstring(state, result);
  118. return 1;
  119. }
  120. else
  121. {
  122. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  123. lua_error(state);
  124. }
  125. break;
  126. }
  127. default:
  128. {
  129. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  130. lua_error(state);
  131. break;
  132. }
  133. }
  134. return 0;
  135. }
  136. int lua_RenderTarget_getRefCount(lua_State* state)
  137. {
  138. // Get the number of parameters.
  139. int paramCount = lua_gettop(state);
  140. // Attempt to match the parameters to a valid binding.
  141. switch (paramCount)
  142. {
  143. case 1:
  144. {
  145. if ((lua_type(state, 1) == LUA_TUSERDATA))
  146. {
  147. RenderTarget* instance = getInstance(state);
  148. unsigned int result = instance->getRefCount();
  149. // Push the return value onto the stack.
  150. lua_pushunsigned(state, result);
  151. return 1;
  152. }
  153. else
  154. {
  155. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  156. lua_error(state);
  157. }
  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_RenderTarget_getTexture(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. RenderTarget* instance = getInstance(state);
  181. void* returnPtr = (void*)instance->getTexture();
  182. if (returnPtr)
  183. {
  184. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  185. object->instance = returnPtr;
  186. object->owns = false;
  187. luaL_getmetatable(state, "Texture");
  188. lua_setmetatable(state, -2);
  189. }
  190. else
  191. {
  192. lua_pushnil(state);
  193. }
  194. return 1;
  195. }
  196. else
  197. {
  198. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  199. lua_error(state);
  200. }
  201. break;
  202. }
  203. default:
  204. {
  205. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  206. lua_error(state);
  207. break;
  208. }
  209. }
  210. return 0;
  211. }
  212. int lua_RenderTarget_release(lua_State* state)
  213. {
  214. // Get the number of parameters.
  215. int paramCount = lua_gettop(state);
  216. // Attempt to match the parameters to a valid binding.
  217. switch (paramCount)
  218. {
  219. case 1:
  220. {
  221. if ((lua_type(state, 1) == LUA_TUSERDATA))
  222. {
  223. RenderTarget* instance = getInstance(state);
  224. instance->release();
  225. return 0;
  226. }
  227. else
  228. {
  229. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  230. lua_error(state);
  231. }
  232. break;
  233. }
  234. default:
  235. {
  236. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  237. lua_error(state);
  238. break;
  239. }
  240. }
  241. return 0;
  242. }
  243. int lua_RenderTarget_static_create(lua_State* state)
  244. {
  245. // Get the number of parameters.
  246. int paramCount = lua_gettop(state);
  247. // Attempt to match the parameters to a valid binding.
  248. switch (paramCount)
  249. {
  250. case 3:
  251. {
  252. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  253. lua_type(state, 2) == LUA_TNUMBER &&
  254. lua_type(state, 3) == LUA_TNUMBER)
  255. {
  256. // Get parameter 1 off the stack.
  257. const char* param1 = ScriptController::getInstance()->getString(1, false);
  258. // Get parameter 2 off the stack.
  259. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  260. // Get parameter 3 off the stack.
  261. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 3);
  262. void* returnPtr = (void*)RenderTarget::create(param1, param2, param3);
  263. if (returnPtr)
  264. {
  265. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  266. object->instance = returnPtr;
  267. object->owns = false;
  268. luaL_getmetatable(state, "RenderTarget");
  269. lua_setmetatable(state, -2);
  270. }
  271. else
  272. {
  273. lua_pushnil(state);
  274. }
  275. return 1;
  276. }
  277. else
  278. {
  279. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  280. lua_error(state);
  281. }
  282. break;
  283. }
  284. default:
  285. {
  286. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  287. lua_error(state);
  288. break;
  289. }
  290. }
  291. return 0;
  292. }
  293. int lua_RenderTarget_static_getRenderTarget(lua_State* state)
  294. {
  295. // Get the number of parameters.
  296. int paramCount = lua_gettop(state);
  297. // Attempt to match the parameters to a valid binding.
  298. switch (paramCount)
  299. {
  300. case 1:
  301. {
  302. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  303. {
  304. // Get parameter 1 off the stack.
  305. const char* param1 = ScriptController::getInstance()->getString(1, false);
  306. void* returnPtr = (void*)RenderTarget::getRenderTarget(param1);
  307. if (returnPtr)
  308. {
  309. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  310. object->instance = returnPtr;
  311. object->owns = false;
  312. luaL_getmetatable(state, "RenderTarget");
  313. lua_setmetatable(state, -2);
  314. }
  315. else
  316. {
  317. lua_pushnil(state);
  318. }
  319. return 1;
  320. }
  321. else
  322. {
  323. lua_pushstring(state, "Failed to match the given parameters to a valid function signature.");
  324. lua_error(state);
  325. }
  326. break;
  327. }
  328. default:
  329. {
  330. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  331. lua_error(state);
  332. break;
  333. }
  334. }
  335. return 0;
  336. }
  337. }