lua_VertexFormatElement.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_VertexFormatElement.h"
  4. #include "Base.h"
  5. #include "VertexFormat.h"
  6. #include "lua_VertexFormatUsage.h"
  7. namespace gameplay
  8. {
  9. void luaRegister_VertexFormatElement()
  10. {
  11. const luaL_Reg lua_members[] =
  12. {
  13. {"size", lua_VertexFormatElement_size},
  14. {"usage", lua_VertexFormatElement_usage},
  15. {NULL, NULL}
  16. };
  17. const luaL_Reg* lua_statics = NULL;
  18. std::vector<std::string> scopePath;
  19. scopePath.push_back("VertexFormat");
  20. gameplay::ScriptUtil::registerClass("VertexFormatElement", lua_members, lua_VertexFormatElement__init, lua_VertexFormatElement__gc, lua_statics, scopePath);
  21. }
  22. static VertexFormat::Element* getInstance(lua_State* state)
  23. {
  24. void* userdata = luaL_checkudata(state, 1, "VertexFormatElement");
  25. luaL_argcheck(state, userdata != NULL, 1, "'VertexFormatElement' expected.");
  26. return (VertexFormat::Element*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  27. }
  28. int lua_VertexFormatElement__gc(lua_State* state)
  29. {
  30. // Get the number of parameters.
  31. int paramCount = lua_gettop(state);
  32. // Attempt to match the parameters to a valid binding.
  33. switch (paramCount)
  34. {
  35. case 1:
  36. {
  37. if ((lua_type(state, 1) == LUA_TUSERDATA))
  38. {
  39. void* userdata = luaL_checkudata(state, 1, "VertexFormatElement");
  40. luaL_argcheck(state, userdata != NULL, 1, "'VertexFormatElement' expected.");
  41. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  42. if (object->owns)
  43. {
  44. VertexFormat::Element* instance = (VertexFormat::Element*)object->instance;
  45. SAFE_DELETE(instance);
  46. }
  47. return 0;
  48. }
  49. lua_pushstring(state, "lua_VertexFormatElement__gc - Failed to match the given parameters to a valid function signature.");
  50. lua_error(state);
  51. break;
  52. }
  53. default:
  54. {
  55. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  56. lua_error(state);
  57. break;
  58. }
  59. }
  60. return 0;
  61. }
  62. int lua_VertexFormatElement__init(lua_State* state)
  63. {
  64. // Get the number of parameters.
  65. int paramCount = lua_gettop(state);
  66. // Attempt to match the parameters to a valid binding.
  67. switch (paramCount)
  68. {
  69. case 0:
  70. {
  71. void* returnPtr = (void*)new VertexFormat::Element();
  72. if (returnPtr)
  73. {
  74. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  75. object->instance = returnPtr;
  76. object->owns = true;
  77. luaL_getmetatable(state, "VertexFormatElement");
  78. lua_setmetatable(state, -2);
  79. }
  80. else
  81. {
  82. lua_pushnil(state);
  83. }
  84. return 1;
  85. break;
  86. }
  87. case 2:
  88. {
  89. do
  90. {
  91. if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL) &&
  92. lua_type(state, 2) == LUA_TNUMBER)
  93. {
  94. // Get parameter 1 off the stack.
  95. VertexFormat::Usage param1 = (VertexFormat::Usage)lua_enumFromString_VertexFormatUsage(luaL_checkstring(state, 1));
  96. // Get parameter 2 off the stack.
  97. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  98. void* returnPtr = (void*)new VertexFormat::Element(param1, param2);
  99. if (returnPtr)
  100. {
  101. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  102. object->instance = returnPtr;
  103. object->owns = true;
  104. luaL_getmetatable(state, "VertexFormatElement");
  105. lua_setmetatable(state, -2);
  106. }
  107. else
  108. {
  109. lua_pushnil(state);
  110. }
  111. return 1;
  112. }
  113. } while (0);
  114. lua_pushstring(state, "lua_VertexFormatElement__init - 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 0 or 2).");
  121. lua_error(state);
  122. break;
  123. }
  124. }
  125. return 0;
  126. }
  127. int lua_VertexFormatElement_size(lua_State* state)
  128. {
  129. // Validate the number of parameters.
  130. if (lua_gettop(state) > 2)
  131. {
  132. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  133. lua_error(state);
  134. }
  135. VertexFormat::Element* instance = getInstance(state);
  136. if (lua_gettop(state) == 2)
  137. {
  138. // Get parameter 2 off the stack.
  139. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 2);
  140. instance->size = param2;
  141. return 0;
  142. }
  143. else
  144. {
  145. unsigned int result = instance->size;
  146. // Push the return value onto the stack.
  147. lua_pushunsigned(state, result);
  148. return 1;
  149. }
  150. }
  151. int lua_VertexFormatElement_usage(lua_State* state)
  152. {
  153. // Validate the number of parameters.
  154. if (lua_gettop(state) > 2)
  155. {
  156. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  157. lua_error(state);
  158. }
  159. VertexFormat::Element* instance = getInstance(state);
  160. if (lua_gettop(state) == 2)
  161. {
  162. // Get parameter 2 off the stack.
  163. VertexFormat::Usage param2 = (VertexFormat::Usage)lua_enumFromString_VertexFormatUsage(luaL_checkstring(state, 2));
  164. instance->usage = param2;
  165. return 0;
  166. }
  167. else
  168. {
  169. VertexFormat::Usage result = instance->usage;
  170. // Push the return value onto the stack.
  171. lua_pushstring(state, lua_stringFromEnum_VertexFormatUsage(result));
  172. return 1;
  173. }
  174. }
  175. }