lua_Layout.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. gameplay::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*)((gameplay::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. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  47. if (object->owns)
  48. {
  49. Layout* instance = (Layout*)object->instance;
  50. SAFE_RELEASE(instance);
  51. }
  52. return 0;
  53. }
  54. lua_pushstring(state, "lua_Layout__gc - Failed to match the given parameters to a valid function signature.");
  55. lua_error(state);
  56. break;
  57. }
  58. default:
  59. {
  60. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  61. lua_error(state);
  62. break;
  63. }
  64. }
  65. return 0;
  66. }
  67. int lua_Layout_addRef(lua_State* state)
  68. {
  69. // Get the number of parameters.
  70. int paramCount = lua_gettop(state);
  71. // Attempt to match the parameters to a valid binding.
  72. switch (paramCount)
  73. {
  74. case 1:
  75. {
  76. if ((lua_type(state, 1) == LUA_TUSERDATA))
  77. {
  78. Layout* instance = getInstance(state);
  79. instance->addRef();
  80. return 0;
  81. }
  82. lua_pushstring(state, "lua_Layout_addRef - Failed to match the given parameters to a valid function signature.");
  83. lua_error(state);
  84. break;
  85. }
  86. default:
  87. {
  88. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  89. lua_error(state);
  90. break;
  91. }
  92. }
  93. return 0;
  94. }
  95. int lua_Layout_getRefCount(lua_State* state)
  96. {
  97. // Get the number of parameters.
  98. int paramCount = lua_gettop(state);
  99. // Attempt to match the parameters to a valid binding.
  100. switch (paramCount)
  101. {
  102. case 1:
  103. {
  104. if ((lua_type(state, 1) == LUA_TUSERDATA))
  105. {
  106. Layout* instance = getInstance(state);
  107. unsigned int result = instance->getRefCount();
  108. // Push the return value onto the stack.
  109. lua_pushunsigned(state, result);
  110. return 1;
  111. }
  112. lua_pushstring(state, "lua_Layout_getRefCount - Failed to match the given parameters to a valid function signature.");
  113. lua_error(state);
  114. break;
  115. }
  116. default:
  117. {
  118. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  119. lua_error(state);
  120. break;
  121. }
  122. }
  123. return 0;
  124. }
  125. int lua_Layout_getType(lua_State* state)
  126. {
  127. // Get the number of parameters.
  128. int paramCount = lua_gettop(state);
  129. // Attempt to match the parameters to a valid binding.
  130. switch (paramCount)
  131. {
  132. case 1:
  133. {
  134. if ((lua_type(state, 1) == LUA_TUSERDATA))
  135. {
  136. Layout* instance = getInstance(state);
  137. Layout::Type result = instance->getType();
  138. // Push the return value onto the stack.
  139. lua_pushstring(state, lua_stringFromEnum_LayoutType(result));
  140. return 1;
  141. }
  142. lua_pushstring(state, "lua_Layout_getType - Failed to match the given parameters to a valid function signature.");
  143. lua_error(state);
  144. break;
  145. }
  146. default:
  147. {
  148. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  149. lua_error(state);
  150. break;
  151. }
  152. }
  153. return 0;
  154. }
  155. int lua_Layout_release(lua_State* state)
  156. {
  157. // Get the number of parameters.
  158. int paramCount = lua_gettop(state);
  159. // Attempt to match the parameters to a valid binding.
  160. switch (paramCount)
  161. {
  162. case 1:
  163. {
  164. if ((lua_type(state, 1) == LUA_TUSERDATA))
  165. {
  166. Layout* instance = getInstance(state);
  167. instance->release();
  168. return 0;
  169. }
  170. lua_pushstring(state, "lua_Layout_release - Failed to match the given parameters to a valid function signature.");
  171. lua_error(state);
  172. break;
  173. }
  174. default:
  175. {
  176. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  177. lua_error(state);
  178. break;
  179. }
  180. }
  181. return 0;
  182. }
  183. }