lua_MeshPart.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_MeshPart.h"
  4. #include "Base.h"
  5. #include "MeshPart.h"
  6. #include "lua_MeshIndexFormat.h"
  7. #include "lua_MeshPrimitiveType.h"
  8. namespace gameplay
  9. {
  10. void luaRegister_MeshPart()
  11. {
  12. const luaL_Reg lua_members[] =
  13. {
  14. {"getIndexBuffer", lua_MeshPart_getIndexBuffer},
  15. {"getIndexCount", lua_MeshPart_getIndexCount},
  16. {"getIndexFormat", lua_MeshPart_getIndexFormat},
  17. {"getMeshIndex", lua_MeshPart_getMeshIndex},
  18. {"getPrimitiveType", lua_MeshPart_getPrimitiveType},
  19. {"isDynamic", lua_MeshPart_isDynamic},
  20. {NULL, NULL}
  21. };
  22. const luaL_Reg* lua_statics = NULL;
  23. std::vector<std::string> scopePath;
  24. gameplay::ScriptUtil::registerClass("MeshPart", lua_members, NULL, lua_MeshPart__gc, lua_statics, scopePath);
  25. }
  26. static MeshPart* getInstance(lua_State* state)
  27. {
  28. void* userdata = luaL_checkudata(state, 1, "MeshPart");
  29. luaL_argcheck(state, userdata != NULL, 1, "'MeshPart' expected.");
  30. return (MeshPart*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  31. }
  32. int lua_MeshPart__gc(lua_State* state)
  33. {
  34. // Get the number of parameters.
  35. int paramCount = lua_gettop(state);
  36. // Attempt to match the parameters to a valid binding.
  37. switch (paramCount)
  38. {
  39. case 1:
  40. {
  41. if ((lua_type(state, 1) == LUA_TUSERDATA))
  42. {
  43. void* userdata = luaL_checkudata(state, 1, "MeshPart");
  44. luaL_argcheck(state, userdata != NULL, 1, "'MeshPart' expected.");
  45. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  46. if (object->owns)
  47. {
  48. MeshPart* instance = (MeshPart*)object->instance;
  49. SAFE_DELETE(instance);
  50. }
  51. return 0;
  52. }
  53. lua_pushstring(state, "lua_MeshPart__gc - Failed to match the given parameters to a valid function signature.");
  54. lua_error(state);
  55. break;
  56. }
  57. default:
  58. {
  59. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  60. lua_error(state);
  61. break;
  62. }
  63. }
  64. return 0;
  65. }
  66. int lua_MeshPart_getIndexBuffer(lua_State* state)
  67. {
  68. // Get the number of parameters.
  69. int paramCount = lua_gettop(state);
  70. // Attempt to match the parameters to a valid binding.
  71. switch (paramCount)
  72. {
  73. case 1:
  74. {
  75. if ((lua_type(state, 1) == LUA_TUSERDATA))
  76. {
  77. MeshPart* instance = getInstance(state);
  78. void* returnPtr = (void*)new GLuint(instance->getIndexBuffer());
  79. if (returnPtr)
  80. {
  81. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  82. object->instance = returnPtr;
  83. object->owns = true;
  84. luaL_getmetatable(state, "GLuint");
  85. lua_setmetatable(state, -2);
  86. }
  87. else
  88. {
  89. lua_pushnil(state);
  90. }
  91. return 1;
  92. }
  93. lua_pushstring(state, "lua_MeshPart_getIndexBuffer - Failed to match the given parameters to a valid function signature.");
  94. lua_error(state);
  95. break;
  96. }
  97. default:
  98. {
  99. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  100. lua_error(state);
  101. break;
  102. }
  103. }
  104. return 0;
  105. }
  106. int lua_MeshPart_getIndexCount(lua_State* state)
  107. {
  108. // Get the number of parameters.
  109. int paramCount = lua_gettop(state);
  110. // Attempt to match the parameters to a valid binding.
  111. switch (paramCount)
  112. {
  113. case 1:
  114. {
  115. if ((lua_type(state, 1) == LUA_TUSERDATA))
  116. {
  117. MeshPart* instance = getInstance(state);
  118. unsigned int result = instance->getIndexCount();
  119. // Push the return value onto the stack.
  120. lua_pushunsigned(state, result);
  121. return 1;
  122. }
  123. lua_pushstring(state, "lua_MeshPart_getIndexCount - Failed to match the given parameters to a valid function signature.");
  124. lua_error(state);
  125. break;
  126. }
  127. default:
  128. {
  129. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  130. lua_error(state);
  131. break;
  132. }
  133. }
  134. return 0;
  135. }
  136. int lua_MeshPart_getIndexFormat(lua_State* state)
  137. {
  138. // Get the number of parameters.
  139. int paramCount = lua_gettop(state);
  140. // Attempt to match the parameters to a valid binding.
  141. switch (paramCount)
  142. {
  143. case 1:
  144. {
  145. if ((lua_type(state, 1) == LUA_TUSERDATA))
  146. {
  147. MeshPart* instance = getInstance(state);
  148. Mesh::IndexFormat result = instance->getIndexFormat();
  149. // Push the return value onto the stack.
  150. lua_pushstring(state, lua_stringFromEnum_MeshIndexFormat(result));
  151. return 1;
  152. }
  153. lua_pushstring(state, "lua_MeshPart_getIndexFormat - Failed to match the given parameters to a valid function signature.");
  154. lua_error(state);
  155. break;
  156. }
  157. default:
  158. {
  159. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  160. lua_error(state);
  161. break;
  162. }
  163. }
  164. return 0;
  165. }
  166. int lua_MeshPart_getMeshIndex(lua_State* state)
  167. {
  168. // Get the number of parameters.
  169. int paramCount = lua_gettop(state);
  170. // Attempt to match the parameters to a valid binding.
  171. switch (paramCount)
  172. {
  173. case 1:
  174. {
  175. if ((lua_type(state, 1) == LUA_TUSERDATA))
  176. {
  177. MeshPart* instance = getInstance(state);
  178. unsigned int result = instance->getMeshIndex();
  179. // Push the return value onto the stack.
  180. lua_pushunsigned(state, result);
  181. return 1;
  182. }
  183. lua_pushstring(state, "lua_MeshPart_getMeshIndex - Failed to match the given parameters to a valid function signature.");
  184. lua_error(state);
  185. break;
  186. }
  187. default:
  188. {
  189. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  190. lua_error(state);
  191. break;
  192. }
  193. }
  194. return 0;
  195. }
  196. int lua_MeshPart_getPrimitiveType(lua_State* state)
  197. {
  198. // Get the number of parameters.
  199. int paramCount = lua_gettop(state);
  200. // Attempt to match the parameters to a valid binding.
  201. switch (paramCount)
  202. {
  203. case 1:
  204. {
  205. if ((lua_type(state, 1) == LUA_TUSERDATA))
  206. {
  207. MeshPart* instance = getInstance(state);
  208. Mesh::PrimitiveType result = instance->getPrimitiveType();
  209. // Push the return value onto the stack.
  210. lua_pushstring(state, lua_stringFromEnum_MeshPrimitiveType(result));
  211. return 1;
  212. }
  213. lua_pushstring(state, "lua_MeshPart_getPrimitiveType - Failed to match the given parameters to a valid function signature.");
  214. lua_error(state);
  215. break;
  216. }
  217. default:
  218. {
  219. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  220. lua_error(state);
  221. break;
  222. }
  223. }
  224. return 0;
  225. }
  226. int lua_MeshPart_isDynamic(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. MeshPart* instance = getInstance(state);
  238. bool result = instance->isDynamic();
  239. // Push the return value onto the stack.
  240. lua_pushboolean(state, result);
  241. return 1;
  242. }
  243. lua_pushstring(state, "lua_MeshPart_isDynamic - Failed to match the given parameters to a valid function signature.");
  244. lua_error(state);
  245. break;
  246. }
  247. default:
  248. {
  249. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  250. lua_error(state);
  251. break;
  252. }
  253. }
  254. return 0;
  255. }
  256. }