lua_MeshPart.cpp 9.0 KB

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