lua_Theme.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Theme.h"
  4. #include "Base.h"
  5. #include "Game.h"
  6. #include "Ref.h"
  7. #include "Theme.h"
  8. #include "ThemeStyle.h"
  9. namespace gameplay
  10. {
  11. void luaRegister_Theme()
  12. {
  13. const luaL_Reg lua_members[] =
  14. {
  15. {"addRef", lua_Theme_addRef},
  16. {"getEmptyStyle", lua_Theme_getEmptyStyle},
  17. {"getRefCount", lua_Theme_getRefCount},
  18. {"getStyle", lua_Theme_getStyle},
  19. {"release", lua_Theme_release},
  20. {NULL, NULL}
  21. };
  22. const luaL_Reg lua_statics[] =
  23. {
  24. {"create", lua_Theme_static_create},
  25. {NULL, NULL}
  26. };
  27. std::vector<std::string> scopePath;
  28. ScriptUtil::registerClass("Theme", lua_members, NULL, lua_Theme__gc, lua_statics, scopePath);
  29. }
  30. static Theme* getInstance(lua_State* state)
  31. {
  32. void* userdata = luaL_checkudata(state, 1, "Theme");
  33. luaL_argcheck(state, userdata != NULL, 1, "'Theme' expected.");
  34. return (Theme*)((ScriptUtil::LuaObject*)userdata)->instance;
  35. }
  36. int lua_Theme__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, "Theme");
  48. luaL_argcheck(state, userdata != NULL, 1, "'Theme' expected.");
  49. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  50. if (object->owns)
  51. {
  52. Theme* instance = (Theme*)object->instance;
  53. SAFE_RELEASE(instance);
  54. }
  55. return 0;
  56. }
  57. else
  58. {
  59. lua_pushstring(state, "lua_Theme__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_Theme_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. Theme* instance = getInstance(state);
  85. instance->addRef();
  86. return 0;
  87. }
  88. else
  89. {
  90. lua_pushstring(state, "lua_Theme_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_Theme_getEmptyStyle(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. Theme* instance = getInstance(state);
  116. void* returnPtr = (void*)instance->getEmptyStyle();
  117. if (returnPtr)
  118. {
  119. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  120. object->instance = returnPtr;
  121. object->owns = false;
  122. luaL_getmetatable(state, "ThemeStyle");
  123. lua_setmetatable(state, -2);
  124. }
  125. else
  126. {
  127. lua_pushnil(state);
  128. }
  129. return 1;
  130. }
  131. else
  132. {
  133. lua_pushstring(state, "lua_Theme_getEmptyStyle - Failed to match the given parameters to a valid function signature.");
  134. lua_error(state);
  135. }
  136. break;
  137. }
  138. default:
  139. {
  140. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  141. lua_error(state);
  142. break;
  143. }
  144. }
  145. return 0;
  146. }
  147. int lua_Theme_getRefCount(lua_State* state)
  148. {
  149. // Get the number of parameters.
  150. int paramCount = lua_gettop(state);
  151. // Attempt to match the parameters to a valid binding.
  152. switch (paramCount)
  153. {
  154. case 1:
  155. {
  156. if ((lua_type(state, 1) == LUA_TUSERDATA))
  157. {
  158. Theme* instance = getInstance(state);
  159. unsigned int result = instance->getRefCount();
  160. // Push the return value onto the stack.
  161. lua_pushunsigned(state, result);
  162. return 1;
  163. }
  164. else
  165. {
  166. lua_pushstring(state, "lua_Theme_getRefCount - Failed to match the given parameters to a valid function signature.");
  167. lua_error(state);
  168. }
  169. break;
  170. }
  171. default:
  172. {
  173. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  174. lua_error(state);
  175. break;
  176. }
  177. }
  178. return 0;
  179. }
  180. int lua_Theme_getStyle(lua_State* state)
  181. {
  182. // Get the number of parameters.
  183. int paramCount = lua_gettop(state);
  184. // Attempt to match the parameters to a valid binding.
  185. switch (paramCount)
  186. {
  187. case 2:
  188. {
  189. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  190. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  191. {
  192. // Get parameter 1 off the stack.
  193. const char* param1 = ScriptUtil::getString(2, false);
  194. Theme* instance = getInstance(state);
  195. void* returnPtr = (void*)instance->getStyle(param1);
  196. if (returnPtr)
  197. {
  198. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  199. object->instance = returnPtr;
  200. object->owns = false;
  201. luaL_getmetatable(state, "ThemeStyle");
  202. lua_setmetatable(state, -2);
  203. }
  204. else
  205. {
  206. lua_pushnil(state);
  207. }
  208. return 1;
  209. }
  210. else
  211. {
  212. lua_pushstring(state, "lua_Theme_getStyle - Failed to match the given parameters to a valid function signature.");
  213. lua_error(state);
  214. }
  215. break;
  216. }
  217. default:
  218. {
  219. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  220. lua_error(state);
  221. break;
  222. }
  223. }
  224. return 0;
  225. }
  226. int lua_Theme_release(lua_State* state)
  227. {
  228. // Get the number of parameters.
  229. int paramCount = lua_gettop(state);
  230. // Attempt to match the parameters to a valid binding.
  231. switch (paramCount)
  232. {
  233. case 1:
  234. {
  235. if ((lua_type(state, 1) == LUA_TUSERDATA))
  236. {
  237. Theme* instance = getInstance(state);
  238. instance->release();
  239. return 0;
  240. }
  241. else
  242. {
  243. lua_pushstring(state, "lua_Theme_release - Failed to match the given parameters to a valid function signature.");
  244. lua_error(state);
  245. }
  246. break;
  247. }
  248. default:
  249. {
  250. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  251. lua_error(state);
  252. break;
  253. }
  254. }
  255. return 0;
  256. }
  257. int lua_Theme_static_create(lua_State* state)
  258. {
  259. // Get the number of parameters.
  260. int paramCount = lua_gettop(state);
  261. // Attempt to match the parameters to a valid binding.
  262. switch (paramCount)
  263. {
  264. case 1:
  265. {
  266. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
  267. {
  268. // Get parameter 1 off the stack.
  269. const char* param1 = ScriptUtil::getString(1, false);
  270. void* returnPtr = (void*)Theme::create(param1);
  271. if (returnPtr)
  272. {
  273. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  274. object->instance = returnPtr;
  275. object->owns = true;
  276. luaL_getmetatable(state, "Theme");
  277. lua_setmetatable(state, -2);
  278. }
  279. else
  280. {
  281. lua_pushnil(state);
  282. }
  283. return 1;
  284. }
  285. else
  286. {
  287. lua_pushstring(state, "lua_Theme_static_create - Failed to match the given parameters to a valid function signature.");
  288. lua_error(state);
  289. }
  290. break;
  291. }
  292. default:
  293. {
  294. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  295. lua_error(state);
  296. break;
  297. }
  298. }
  299. return 0;
  300. }
  301. }