lua_VisibleSet.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_VisibleSet.h"
  4. #include "VisibleSet.h"
  5. namespace gameplay
  6. {
  7. void luaRegister_VisibleSet()
  8. {
  9. const luaL_Reg lua_members[] =
  10. {
  11. {"getActiveCamera", lua_VisibleSet_getActiveCamera},
  12. {"getNext", lua_VisibleSet_getNext},
  13. {"reset", lua_VisibleSet_reset},
  14. {NULL, NULL}
  15. };
  16. const luaL_Reg* lua_statics = NULL;
  17. std::vector<std::string> scopePath;
  18. gameplay::ScriptUtil::registerClass("VisibleSet", lua_members, NULL, lua_VisibleSet__gc, lua_statics, scopePath);
  19. }
  20. static VisibleSet* getInstance(lua_State* state)
  21. {
  22. void* userdata = luaL_checkudata(state, 1, "VisibleSet");
  23. luaL_argcheck(state, userdata != NULL, 1, "'VisibleSet' expected.");
  24. return (VisibleSet*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  25. }
  26. int lua_VisibleSet__gc(lua_State* state)
  27. {
  28. // Get the number of parameters.
  29. int paramCount = lua_gettop(state);
  30. // Attempt to match the parameters to a valid binding.
  31. switch (paramCount)
  32. {
  33. case 1:
  34. {
  35. if ((lua_type(state, 1) == LUA_TUSERDATA))
  36. {
  37. void* userdata = luaL_checkudata(state, 1, "VisibleSet");
  38. luaL_argcheck(state, userdata != NULL, 1, "'VisibleSet' expected.");
  39. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  40. if (object->owns)
  41. {
  42. VisibleSet* instance = (VisibleSet*)object->instance;
  43. SAFE_DELETE(instance);
  44. }
  45. return 0;
  46. }
  47. lua_pushstring(state, "lua_VisibleSet__gc - Failed to match the given parameters to a valid function signature.");
  48. lua_error(state);
  49. break;
  50. }
  51. default:
  52. {
  53. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  54. lua_error(state);
  55. break;
  56. }
  57. }
  58. return 0;
  59. }
  60. int lua_VisibleSet_getActiveCamera(lua_State* state)
  61. {
  62. // Get the number of parameters.
  63. int paramCount = lua_gettop(state);
  64. // Attempt to match the parameters to a valid binding.
  65. switch (paramCount)
  66. {
  67. case 1:
  68. {
  69. if ((lua_type(state, 1) == LUA_TUSERDATA))
  70. {
  71. VisibleSet* instance = getInstance(state);
  72. void* returnPtr = (void*)instance->getActiveCamera();
  73. if (returnPtr)
  74. {
  75. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  76. object->instance = returnPtr;
  77. object->owns = false;
  78. luaL_getmetatable(state, "Camera");
  79. lua_setmetatable(state, -2);
  80. }
  81. else
  82. {
  83. lua_pushnil(state);
  84. }
  85. return 1;
  86. }
  87. lua_pushstring(state, "lua_VisibleSet_getActiveCamera - 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_VisibleSet_getNext(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. VisibleSet* instance = getInstance(state);
  112. void* returnPtr = (void*)instance->getNext();
  113. if (returnPtr)
  114. {
  115. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  116. object->instance = returnPtr;
  117. object->owns = false;
  118. luaL_getmetatable(state, "Node");
  119. lua_setmetatable(state, -2);
  120. }
  121. else
  122. {
  123. lua_pushnil(state);
  124. }
  125. return 1;
  126. }
  127. lua_pushstring(state, "lua_VisibleSet_getNext - Failed to match the given parameters to a valid function signature.");
  128. lua_error(state);
  129. break;
  130. }
  131. default:
  132. {
  133. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  134. lua_error(state);
  135. break;
  136. }
  137. }
  138. return 0;
  139. }
  140. int lua_VisibleSet_reset(lua_State* state)
  141. {
  142. // Get the number of parameters.
  143. int paramCount = lua_gettop(state);
  144. // Attempt to match the parameters to a valid binding.
  145. switch (paramCount)
  146. {
  147. case 1:
  148. {
  149. if ((lua_type(state, 1) == LUA_TUSERDATA))
  150. {
  151. VisibleSet* instance = getInstance(state);
  152. instance->reset();
  153. return 0;
  154. }
  155. lua_pushstring(state, "lua_VisibleSet_reset - Failed to match the given parameters to a valid function signature.");
  156. lua_error(state);
  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. }