lua_Image.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Image.h"
  4. #include "Base.h"
  5. #include "FileSystem.h"
  6. #include "Game.h"
  7. #include "Image.h"
  8. #include "Ref.h"
  9. #include "lua_ImageFormat.h"
  10. namespace gameplay
  11. {
  12. void luaRegister_Image()
  13. {
  14. const luaL_Reg lua_members[] =
  15. {
  16. {"addRef", lua_Image_addRef},
  17. {"getFormat", lua_Image_getFormat},
  18. {"getHeight", lua_Image_getHeight},
  19. {"getRefCount", lua_Image_getRefCount},
  20. {"getWidth", lua_Image_getWidth},
  21. {"release", lua_Image_release},
  22. {NULL, NULL}
  23. };
  24. const luaL_Reg lua_statics[] =
  25. {
  26. {"create", lua_Image_static_create},
  27. {NULL, NULL}
  28. };
  29. std::vector<std::string> scopePath;
  30. gameplay::ScriptUtil::registerClass("Image", lua_members, NULL, lua_Image__gc, lua_statics, scopePath);
  31. }
  32. static Image* getInstance(lua_State* state)
  33. {
  34. void* userdata = luaL_checkudata(state, 1, "Image");
  35. luaL_argcheck(state, userdata != NULL, 1, "'Image' expected.");
  36. return (Image*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  37. }
  38. int lua_Image__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, "Image");
  50. luaL_argcheck(state, userdata != NULL, 1, "'Image' expected.");
  51. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  52. if (object->owns)
  53. {
  54. Image* instance = (Image*)object->instance;
  55. SAFE_RELEASE(instance);
  56. }
  57. return 0;
  58. }
  59. lua_pushstring(state, "lua_Image__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_Image_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. Image* instance = getInstance(state);
  84. instance->addRef();
  85. return 0;
  86. }
  87. lua_pushstring(state, "lua_Image_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_Image_getFormat(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. Image* instance = getInstance(state);
  112. Image::Format result = instance->getFormat();
  113. // Push the return value onto the stack.
  114. lua_pushstring(state, lua_stringFromEnum_ImageFormat(result));
  115. return 1;
  116. }
  117. lua_pushstring(state, "lua_Image_getFormat - 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_Image_getHeight(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. Image* instance = getInstance(state);
  142. unsigned int result = instance->getHeight();
  143. // Push the return value onto the stack.
  144. lua_pushunsigned(state, result);
  145. return 1;
  146. }
  147. lua_pushstring(state, "lua_Image_getHeight - 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_Image_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. Image* 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_Image_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_Image_getWidth(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. Image* instance = getInstance(state);
  202. unsigned int result = instance->getWidth();
  203. // Push the return value onto the stack.
  204. lua_pushunsigned(state, result);
  205. return 1;
  206. }
  207. lua_pushstring(state, "lua_Image_getWidth - Failed to match the given parameters to a valid function signature.");
  208. lua_error(state);
  209. break;
  210. }
  211. default:
  212. {
  213. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  214. lua_error(state);
  215. break;
  216. }
  217. }
  218. return 0;
  219. }
  220. int lua_Image_release(lua_State* state)
  221. {
  222. // Get the number of parameters.
  223. int paramCount = lua_gettop(state);
  224. // Attempt to match the parameters to a valid binding.
  225. switch (paramCount)
  226. {
  227. case 1:
  228. {
  229. if ((lua_type(state, 1) == LUA_TUSERDATA))
  230. {
  231. Image* instance = getInstance(state);
  232. instance->release();
  233. return 0;
  234. }
  235. lua_pushstring(state, "lua_Image_release - Failed to match the given parameters to a valid function signature.");
  236. lua_error(state);
  237. break;
  238. }
  239. default:
  240. {
  241. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  242. lua_error(state);
  243. break;
  244. }
  245. }
  246. return 0;
  247. }
  248. int lua_Image_static_create(lua_State* state)
  249. {
  250. // Get the number of parameters.
  251. int paramCount = lua_gettop(state);
  252. // Attempt to match the parameters to a valid binding.
  253. switch (paramCount)
  254. {
  255. case 1:
  256. {
  257. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  258. {
  259. // Get parameter 1 off the stack.
  260. const char* param1 = gameplay::ScriptUtil::getString(1, false);
  261. void* returnPtr = (void*)Image::create(param1);
  262. if (returnPtr)
  263. {
  264. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  265. object->instance = returnPtr;
  266. object->owns = true;
  267. luaL_getmetatable(state, "Image");
  268. lua_setmetatable(state, -2);
  269. }
  270. else
  271. {
  272. lua_pushnil(state);
  273. }
  274. return 1;
  275. }
  276. lua_pushstring(state, "lua_Image_static_create - 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. }