lua_VertexAttributeBinding.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. gameplay::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*)((gameplay::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. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  51. if (object->owns)
  52. {
  53. VertexAttributeBinding* instance = (VertexAttributeBinding*)object->instance;
  54. SAFE_RELEASE(instance);
  55. }
  56. return 0;
  57. }
  58. lua_pushstring(state, "lua_VertexAttributeBinding__gc - Failed to match the given parameters to a valid function signature.");
  59. lua_error(state);
  60. break;
  61. }
  62. default:
  63. {
  64. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  65. lua_error(state);
  66. break;
  67. }
  68. }
  69. return 0;
  70. }
  71. int lua_VertexAttributeBinding_addRef(lua_State* state)
  72. {
  73. // Get the number of parameters.
  74. int paramCount = lua_gettop(state);
  75. // Attempt to match the parameters to a valid binding.
  76. switch (paramCount)
  77. {
  78. case 1:
  79. {
  80. if ((lua_type(state, 1) == LUA_TUSERDATA))
  81. {
  82. VertexAttributeBinding* instance = getInstance(state);
  83. instance->addRef();
  84. return 0;
  85. }
  86. lua_pushstring(state, "lua_VertexAttributeBinding_addRef - Failed to match the given parameters to a valid function signature.");
  87. lua_error(state);
  88. break;
  89. }
  90. default:
  91. {
  92. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  93. lua_error(state);
  94. break;
  95. }
  96. }
  97. return 0;
  98. }
  99. int lua_VertexAttributeBinding_bind(lua_State* state)
  100. {
  101. // Get the number of parameters.
  102. int paramCount = lua_gettop(state);
  103. // Attempt to match the parameters to a valid binding.
  104. switch (paramCount)
  105. {
  106. case 1:
  107. {
  108. if ((lua_type(state, 1) == LUA_TUSERDATA))
  109. {
  110. VertexAttributeBinding* instance = getInstance(state);
  111. instance->bind();
  112. return 0;
  113. }
  114. lua_pushstring(state, "lua_VertexAttributeBinding_bind - Failed to match the given parameters to a valid function signature.");
  115. lua_error(state);
  116. break;
  117. }
  118. default:
  119. {
  120. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  121. lua_error(state);
  122. break;
  123. }
  124. }
  125. return 0;
  126. }
  127. int lua_VertexAttributeBinding_getRefCount(lua_State* state)
  128. {
  129. // Get the number of parameters.
  130. int paramCount = lua_gettop(state);
  131. // Attempt to match the parameters to a valid binding.
  132. switch (paramCount)
  133. {
  134. case 1:
  135. {
  136. if ((lua_type(state, 1) == LUA_TUSERDATA))
  137. {
  138. VertexAttributeBinding* instance = getInstance(state);
  139. unsigned int result = instance->getRefCount();
  140. // Push the return value onto the stack.
  141. lua_pushunsigned(state, result);
  142. return 1;
  143. }
  144. lua_pushstring(state, "lua_VertexAttributeBinding_getRefCount - Failed to match the given parameters to a valid function signature.");
  145. lua_error(state);
  146. break;
  147. }
  148. default:
  149. {
  150. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  151. lua_error(state);
  152. break;
  153. }
  154. }
  155. return 0;
  156. }
  157. int lua_VertexAttributeBinding_release(lua_State* state)
  158. {
  159. // Get the number of parameters.
  160. int paramCount = lua_gettop(state);
  161. // Attempt to match the parameters to a valid binding.
  162. switch (paramCount)
  163. {
  164. case 1:
  165. {
  166. if ((lua_type(state, 1) == LUA_TUSERDATA))
  167. {
  168. VertexAttributeBinding* instance = getInstance(state);
  169. instance->release();
  170. return 0;
  171. }
  172. lua_pushstring(state, "lua_VertexAttributeBinding_release - Failed to match the given parameters to a valid function signature.");
  173. lua_error(state);
  174. break;
  175. }
  176. default:
  177. {
  178. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  179. lua_error(state);
  180. break;
  181. }
  182. }
  183. return 0;
  184. }
  185. int lua_VertexAttributeBinding_static_create(lua_State* state)
  186. {
  187. // Get the number of parameters.
  188. int paramCount = lua_gettop(state);
  189. // Attempt to match the parameters to a valid binding.
  190. switch (paramCount)
  191. {
  192. case 2:
  193. {
  194. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  195. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  196. {
  197. // Get parameter 1 off the stack.
  198. bool param1Valid;
  199. gameplay::ScriptUtil::LuaArray<Mesh> param1 = gameplay::ScriptUtil::getObjectPointer<Mesh>(1, "Mesh", false, &param1Valid);
  200. if (!param1Valid)
  201. {
  202. lua_pushstring(state, "Failed to convert parameter 1 to type 'Mesh'.");
  203. lua_error(state);
  204. }
  205. // Get parameter 2 off the stack.
  206. bool param2Valid;
  207. gameplay::ScriptUtil::LuaArray<Effect> param2 = gameplay::ScriptUtil::getObjectPointer<Effect>(2, "Effect", false, &param2Valid);
  208. if (!param2Valid)
  209. {
  210. lua_pushstring(state, "Failed to convert parameter 2 to type 'Effect'.");
  211. lua_error(state);
  212. }
  213. void* returnPtr = (void*)VertexAttributeBinding::create(param1, param2);
  214. if (returnPtr)
  215. {
  216. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  217. object->instance = returnPtr;
  218. object->owns = true;
  219. luaL_getmetatable(state, "VertexAttributeBinding");
  220. lua_setmetatable(state, -2);
  221. }
  222. else
  223. {
  224. lua_pushnil(state);
  225. }
  226. return 1;
  227. }
  228. lua_pushstring(state, "lua_VertexAttributeBinding_static_create - Failed to match the given parameters to a valid function signature.");
  229. lua_error(state);
  230. break;
  231. }
  232. default:
  233. {
  234. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  235. lua_error(state);
  236. break;
  237. }
  238. }
  239. return 0;
  240. }
  241. int lua_VertexAttributeBinding_unbind(lua_State* state)
  242. {
  243. // Get the number of parameters.
  244. int paramCount = lua_gettop(state);
  245. // Attempt to match the parameters to a valid binding.
  246. switch (paramCount)
  247. {
  248. case 1:
  249. {
  250. if ((lua_type(state, 1) == LUA_TUSERDATA))
  251. {
  252. VertexAttributeBinding* instance = getInstance(state);
  253. instance->unbind();
  254. return 0;
  255. }
  256. lua_pushstring(state, "lua_VertexAttributeBinding_unbind - Failed to match the given parameters to a valid function signature.");
  257. lua_error(state);
  258. break;
  259. }
  260. default:
  261. {
  262. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  263. lua_error(state);
  264. break;
  265. }
  266. }
  267. return 0;
  268. }
  269. }