lua_AbsoluteLayout.cpp 6.3 KB

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