lua_VertexAttributeBinding.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_VertexAttributeBinding.h"
  4. #include "Base.h"
  5. #include "Effect.h"
  6. #include "Game.h"
  7. #include "Mesh.h"
  8. #include "Ref.h"
  9. #include "VertexAttributeBinding.h"
  10. namespace gameplay
  11. {
  12. void luaRegister_VertexAttributeBinding()
  13. {
  14. const luaL_Reg lua_members[] =
  15. {
  16. {"addRef", lua_VertexAttributeBinding_addRef},
  17. {"bind", lua_VertexAttributeBinding_bind},
  18. {"getRefCount", lua_VertexAttributeBinding_getRefCount},
  19. {"release", lua_VertexAttributeBinding_release},
  20. {"unbind", lua_VertexAttributeBinding_unbind},
  21. {NULL, NULL}
  22. };
  23. const luaL_Reg lua_statics[] =
  24. {
  25. {"create", lua_VertexAttributeBinding_static_create},
  26. {NULL, NULL}
  27. };
  28. std::vector<std::string> scopePath;
  29. ScriptUtil::registerClass("VertexAttributeBinding", lua_members, NULL, lua_VertexAttributeBinding__gc, lua_statics, scopePath);
  30. }
  31. static VertexAttributeBinding* getInstance(lua_State* state)
  32. {
  33. void* userdata = luaL_checkudata(state, 1, "VertexAttributeBinding");
  34. luaL_argcheck(state, userdata != NULL, 1, "'VertexAttributeBinding' expected.");
  35. return (VertexAttributeBinding*)((ScriptUtil::LuaObject*)userdata)->instance;
  36. }
  37. int lua_VertexAttributeBinding__gc(lua_State* state)
  38. {
  39. // Get the number of parameters.
  40. int paramCount = lua_gettop(state);
  41. // Attempt to match the parameters to a valid binding.
  42. switch (paramCount)
  43. {
  44. case 1:
  45. {
  46. if ((lua_type(state, 1) == LUA_TUSERDATA))
  47. {
  48. void* userdata = luaL_checkudata(state, 1, "VertexAttributeBinding");
  49. luaL_argcheck(state, userdata != NULL, 1, "'VertexAttributeBinding' expected.");
  50. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  51. if (object->owns)
  52. {
  53. VertexAttributeBinding* instance = (VertexAttributeBinding*)object->instance;
  54. SAFE_RELEASE(instance);
  55. }
  56. return 0;
  57. }
  58. else
  59. {
  60. lua_pushstring(state, "lua_VertexAttributeBinding__gc - Failed to match the given parameters to a valid function signature.");
  61. lua_error(state);
  62. }
  63. break;
  64. }
  65. default:
  66. {
  67. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  68. lua_error(state);
  69. break;
  70. }
  71. }
  72. return 0;
  73. }
  74. int lua_VertexAttributeBinding_addRef(lua_State* state)
  75. {
  76. // Get the number of parameters.
  77. int paramCount = lua_gettop(state);
  78. // Attempt to match the parameters to a valid binding.
  79. switch (paramCount)
  80. {
  81. case 1:
  82. {
  83. if ((lua_type(state, 1) == LUA_TUSERDATA))
  84. {
  85. VertexAttributeBinding* instance = getInstance(state);
  86. instance->addRef();
  87. return 0;
  88. }
  89. else
  90. {
  91. lua_pushstring(state, "lua_VertexAttributeBinding_addRef - Failed to match the given parameters to a valid function signature.");
  92. lua_error(state);
  93. }
  94. break;
  95. }
  96. default:
  97. {
  98. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  99. lua_error(state);
  100. break;
  101. }
  102. }
  103. return 0;
  104. }
  105. int lua_VertexAttributeBinding_bind(lua_State* state)
  106. {
  107. // Get the number of parameters.
  108. int paramCount = lua_gettop(state);
  109. // Attempt to match the parameters to a valid binding.
  110. switch (paramCount)
  111. {
  112. case 1:
  113. {
  114. if ((lua_type(state, 1) == LUA_TUSERDATA))
  115. {
  116. VertexAttributeBinding* instance = getInstance(state);
  117. instance->bind();
  118. return 0;
  119. }
  120. else
  121. {
  122. lua_pushstring(state, "lua_VertexAttributeBinding_bind - Failed to match the given parameters to a valid function signature.");
  123. lua_error(state);
  124. }
  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_VertexAttributeBinding_getRefCount(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. VertexAttributeBinding* instance = getInstance(state);
  148. unsigned int result = instance->getRefCount();
  149. // Push the return value onto the stack.
  150. lua_pushunsigned(state, result);
  151. return 1;
  152. }
  153. else
  154. {
  155. lua_pushstring(state, "lua_VertexAttributeBinding_getRefCount - Failed to match the given parameters to a valid function signature.");
  156. lua_error(state);
  157. }
  158. break;
  159. }
  160. default:
  161. {
  162. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  163. lua_error(state);
  164. break;
  165. }
  166. }
  167. return 0;
  168. }
  169. int lua_VertexAttributeBinding_release(lua_State* state)
  170. {
  171. // Get the number of parameters.
  172. int paramCount = lua_gettop(state);
  173. // Attempt to match the parameters to a valid binding.
  174. switch (paramCount)
  175. {
  176. case 1:
  177. {
  178. if ((lua_type(state, 1) == LUA_TUSERDATA))
  179. {
  180. VertexAttributeBinding* instance = getInstance(state);
  181. instance->release();
  182. return 0;
  183. }
  184. else
  185. {
  186. lua_pushstring(state, "lua_VertexAttributeBinding_release - Failed to match the given parameters to a valid function signature.");
  187. lua_error(state);
  188. }
  189. break;
  190. }
  191. default:
  192. {
  193. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  194. lua_error(state);
  195. break;
  196. }
  197. }
  198. return 0;
  199. }
  200. int lua_VertexAttributeBinding_static_create(lua_State* state)
  201. {
  202. // Get the number of parameters.
  203. int paramCount = lua_gettop(state);
  204. // Attempt to match the parameters to a valid binding.
  205. switch (paramCount)
  206. {
  207. case 2:
  208. {
  209. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  210. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  211. {
  212. // Get parameter 1 off the stack.
  213. ScriptUtil::LuaArray<Mesh> param1 = ScriptUtil::getObjectPointer<Mesh>(1, "Mesh", false);
  214. // Get parameter 2 off the stack.
  215. ScriptUtil::LuaArray<Effect> param2 = ScriptUtil::getObjectPointer<Effect>(2, "Effect", false);
  216. void* returnPtr = (void*)VertexAttributeBinding::create(param1, param2);
  217. if (returnPtr)
  218. {
  219. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  220. object->instance = returnPtr;
  221. object->owns = true;
  222. luaL_getmetatable(state, "VertexAttributeBinding");
  223. lua_setmetatable(state, -2);
  224. }
  225. else
  226. {
  227. lua_pushnil(state);
  228. }
  229. return 1;
  230. }
  231. else
  232. {
  233. lua_pushstring(state, "lua_VertexAttributeBinding_static_create - Failed to match the given parameters to a valid function signature.");
  234. lua_error(state);
  235. }
  236. break;
  237. }
  238. default:
  239. {
  240. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  241. lua_error(state);
  242. break;
  243. }
  244. }
  245. return 0;
  246. }
  247. int lua_VertexAttributeBinding_unbind(lua_State* state)
  248. {
  249. // Get the number of parameters.
  250. int paramCount = lua_gettop(state);
  251. // Attempt to match the parameters to a valid binding.
  252. switch (paramCount)
  253. {
  254. case 1:
  255. {
  256. if ((lua_type(state, 1) == LUA_TUSERDATA))
  257. {
  258. VertexAttributeBinding* instance = getInstance(state);
  259. instance->unbind();
  260. return 0;
  261. }
  262. else
  263. {
  264. lua_pushstring(state, "lua_VertexAttributeBinding_unbind - Failed to match the given parameters to a valid function signature.");
  265. lua_error(state);
  266. }
  267. break;
  268. }
  269. default:
  270. {
  271. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  272. lua_error(state);
  273. break;
  274. }
  275. }
  276. return 0;
  277. }
  278. }