lua_Layout.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Layout.h"
  4. #include "Base.h"
  5. #include "Container.h"
  6. #include "Control.h"
  7. #include "Game.h"
  8. #include "Layout.h"
  9. #include "Ref.h"
  10. #include "lua_LayoutType.h"
  11. namespace gameplay
  12. {
  13. void luaRegister_Layout()
  14. {
  15. const luaL_Reg lua_members[] =
  16. {
  17. {"addRef", lua_Layout_addRef},
  18. {"getRefCount", lua_Layout_getRefCount},
  19. {"getType", lua_Layout_getType},
  20. {"release", lua_Layout_release},
  21. {NULL, NULL}
  22. };
  23. const luaL_Reg* lua_statics = NULL;
  24. std::vector<std::string> scopePath;
  25. ScriptUtil::registerClass("Layout", lua_members, NULL, lua_Layout__gc, lua_statics, scopePath);
  26. }
  27. static Layout* getInstance(lua_State* state)
  28. {
  29. void* userdata = luaL_checkudata(state, 1, "Layout");
  30. luaL_argcheck(state, userdata != NULL, 1, "'Layout' expected.");
  31. return (Layout*)((ScriptUtil::LuaObject*)userdata)->instance;
  32. }
  33. int lua_Layout__gc(lua_State* state)
  34. {
  35. // Get the number of parameters.
  36. int paramCount = lua_gettop(state);
  37. // Attempt to match the parameters to a valid binding.
  38. switch (paramCount)
  39. {
  40. case 1:
  41. {
  42. if ((lua_type(state, 1) == LUA_TUSERDATA))
  43. {
  44. void* userdata = luaL_checkudata(state, 1, "Layout");
  45. luaL_argcheck(state, userdata != NULL, 1, "'Layout' expected.");
  46. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  47. if (object->owns)
  48. {
  49. Layout* instance = (Layout*)object->instance;
  50. SAFE_RELEASE(instance);
  51. }
  52. return 0;
  53. }
  54. else
  55. {
  56. lua_pushstring(state, "lua_Layout__gc - Failed to match the given parameters to a valid function signature.");
  57. lua_error(state);
  58. }
  59. break;
  60. }
  61. default:
  62. {
  63. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  64. lua_error(state);
  65. break;
  66. }
  67. }
  68. return 0;
  69. }
  70. int lua_Layout_addRef(lua_State* state)
  71. {
  72. // Get the number of parameters.
  73. int paramCount = lua_gettop(state);
  74. // Attempt to match the parameters to a valid binding.
  75. switch (paramCount)
  76. {
  77. case 1:
  78. {
  79. if ((lua_type(state, 1) == LUA_TUSERDATA))
  80. {
  81. Layout* instance = getInstance(state);
  82. instance->addRef();
  83. return 0;
  84. }
  85. else
  86. {
  87. lua_pushstring(state, "lua_Layout_addRef - Failed to match the given parameters to a valid function signature.");
  88. lua_error(state);
  89. }
  90. break;
  91. }
  92. default:
  93. {
  94. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  95. lua_error(state);
  96. break;
  97. }
  98. }
  99. return 0;
  100. }
  101. int lua_Layout_getRefCount(lua_State* state)
  102. {
  103. // Get the number of parameters.
  104. int paramCount = lua_gettop(state);
  105. // Attempt to match the parameters to a valid binding.
  106. switch (paramCount)
  107. {
  108. case 1:
  109. {
  110. if ((lua_type(state, 1) == LUA_TUSERDATA))
  111. {
  112. Layout* instance = getInstance(state);
  113. unsigned int result = instance->getRefCount();
  114. // Push the return value onto the stack.
  115. lua_pushunsigned(state, result);
  116. return 1;
  117. }
  118. else
  119. {
  120. lua_pushstring(state, "lua_Layout_getRefCount - Failed to match the given parameters to a valid function signature.");
  121. lua_error(state);
  122. }
  123. break;
  124. }
  125. default:
  126. {
  127. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  128. lua_error(state);
  129. break;
  130. }
  131. }
  132. return 0;
  133. }
  134. int lua_Layout_getType(lua_State* state)
  135. {
  136. // Get the number of parameters.
  137. int paramCount = lua_gettop(state);
  138. // Attempt to match the parameters to a valid binding.
  139. switch (paramCount)
  140. {
  141. case 1:
  142. {
  143. if ((lua_type(state, 1) == LUA_TUSERDATA))
  144. {
  145. Layout* instance = getInstance(state);
  146. Layout::Type result = instance->getType();
  147. // Push the return value onto the stack.
  148. lua_pushstring(state, lua_stringFromEnum_LayoutType(result));
  149. return 1;
  150. }
  151. else
  152. {
  153. lua_pushstring(state, "lua_Layout_getType - Failed to match the given parameters to a valid function signature.");
  154. lua_error(state);
  155. }
  156. break;
  157. }
  158. default:
  159. {
  160. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  161. lua_error(state);
  162. break;
  163. }
  164. }
  165. return 0;
  166. }
  167. int lua_Layout_release(lua_State* state)
  168. {
  169. // Get the number of parameters.
  170. int paramCount = lua_gettop(state);
  171. // Attempt to match the parameters to a valid binding.
  172. switch (paramCount)
  173. {
  174. case 1:
  175. {
  176. if ((lua_type(state, 1) == LUA_TUSERDATA))
  177. {
  178. Layout* instance = getInstance(state);
  179. instance->release();
  180. return 0;
  181. }
  182. else
  183. {
  184. lua_pushstring(state, "lua_Layout_release - Failed to match the given parameters to a valid function signature.");
  185. lua_error(state);
  186. }
  187. break;
  188. }
  189. default:
  190. {
  191. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  192. lua_error(state);
  193. break;
  194. }
  195. }
  196. return 0;
  197. }
  198. }