lua_PhysicsControllerHitResult.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_PhysicsControllerHitResult.h"
  4. #include "Base.h"
  5. #include "Bundle.h"
  6. #include "Game.h"
  7. #include "MeshPart.h"
  8. #include "PhysicsCharacter.h"
  9. #include "PhysicsController.h"
  10. #include "PhysicsRigidBody.h"
  11. #include "lua_PhysicsControllerListenerEventType.h"
  12. namespace gameplay
  13. {
  14. void luaRegister_PhysicsControllerHitResult()
  15. {
  16. const luaL_Reg lua_members[] =
  17. {
  18. {"fraction", lua_PhysicsControllerHitResult_fraction},
  19. {"normal", lua_PhysicsControllerHitResult_normal},
  20. {"object", lua_PhysicsControllerHitResult_object},
  21. {"point", lua_PhysicsControllerHitResult_point},
  22. {NULL, NULL}
  23. };
  24. const luaL_Reg* lua_statics = NULL;
  25. std::vector<std::string> scopePath;
  26. scopePath.push_back("PhysicsController");
  27. ScriptUtil::registerClass("PhysicsControllerHitResult", lua_members, lua_PhysicsControllerHitResult__init, lua_PhysicsControllerHitResult__gc, lua_statics, scopePath);
  28. }
  29. static PhysicsController::HitResult* getInstance(lua_State* state)
  30. {
  31. void* userdata = luaL_checkudata(state, 1, "PhysicsControllerHitResult");
  32. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsControllerHitResult' expected.");
  33. return (PhysicsController::HitResult*)((ScriptUtil::LuaObject*)userdata)->instance;
  34. }
  35. int lua_PhysicsControllerHitResult__gc(lua_State* state)
  36. {
  37. // Get the number of parameters.
  38. int paramCount = lua_gettop(state);
  39. // Attempt to match the parameters to a valid binding.
  40. switch (paramCount)
  41. {
  42. case 1:
  43. {
  44. if ((lua_type(state, 1) == LUA_TUSERDATA))
  45. {
  46. void* userdata = luaL_checkudata(state, 1, "PhysicsControllerHitResult");
  47. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsControllerHitResult' expected.");
  48. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  49. if (object->owns)
  50. {
  51. PhysicsController::HitResult* instance = (PhysicsController::HitResult*)object->instance;
  52. SAFE_DELETE(instance);
  53. }
  54. return 0;
  55. }
  56. else
  57. {
  58. lua_pushstring(state, "lua_PhysicsControllerHitResult__gc - Failed to match the given parameters to a valid function signature.");
  59. lua_error(state);
  60. }
  61. break;
  62. }
  63. default:
  64. {
  65. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  66. lua_error(state);
  67. break;
  68. }
  69. }
  70. return 0;
  71. }
  72. int lua_PhysicsControllerHitResult__init(lua_State* state)
  73. {
  74. // Get the number of parameters.
  75. int paramCount = lua_gettop(state);
  76. // Attempt to match the parameters to a valid binding.
  77. switch (paramCount)
  78. {
  79. case 0:
  80. {
  81. void* returnPtr = (void*)new PhysicsController::HitResult();
  82. if (returnPtr)
  83. {
  84. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  85. object->instance = returnPtr;
  86. object->owns = true;
  87. luaL_getmetatable(state, "PhysicsControllerHitResult");
  88. lua_setmetatable(state, -2);
  89. }
  90. else
  91. {
  92. lua_pushnil(state);
  93. }
  94. return 1;
  95. break;
  96. }
  97. default:
  98. {
  99. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  100. lua_error(state);
  101. break;
  102. }
  103. }
  104. return 0;
  105. }
  106. int lua_PhysicsControllerHitResult_fraction(lua_State* state)
  107. {
  108. // Validate the number of parameters.
  109. if (lua_gettop(state) > 2)
  110. {
  111. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  112. lua_error(state);
  113. }
  114. PhysicsController::HitResult* instance = getInstance(state);
  115. if (lua_gettop(state) == 2)
  116. {
  117. // Get parameter 2 off the stack.
  118. float param2 = (float)luaL_checknumber(state, 2);
  119. instance->fraction = param2;
  120. return 0;
  121. }
  122. else
  123. {
  124. float result = instance->fraction;
  125. // Push the return value onto the stack.
  126. lua_pushnumber(state, result);
  127. return 1;
  128. }
  129. }
  130. int lua_PhysicsControllerHitResult_normal(lua_State* state)
  131. {
  132. // Validate the number of parameters.
  133. if (lua_gettop(state) > 2)
  134. {
  135. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  136. lua_error(state);
  137. }
  138. PhysicsController::HitResult* instance = getInstance(state);
  139. if (lua_gettop(state) == 2)
  140. {
  141. // Get parameter 2 off the stack.
  142. Vector3* param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  143. instance->normal = *param2;
  144. return 0;
  145. }
  146. else
  147. {
  148. void* returnPtr = (void*)new Vector3(instance->normal);
  149. if (returnPtr)
  150. {
  151. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  152. object->instance = returnPtr;
  153. object->owns = true;
  154. luaL_getmetatable(state, "Vector3");
  155. lua_setmetatable(state, -2);
  156. }
  157. else
  158. {
  159. lua_pushnil(state);
  160. }
  161. return 1;
  162. }
  163. }
  164. int lua_PhysicsControllerHitResult_object(lua_State* state)
  165. {
  166. // Validate the number of parameters.
  167. if (lua_gettop(state) > 2)
  168. {
  169. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  170. lua_error(state);
  171. }
  172. PhysicsController::HitResult* instance = getInstance(state);
  173. if (lua_gettop(state) == 2)
  174. {
  175. // Get parameter 2 off the stack.
  176. PhysicsCollisionObject* param2 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(2, "PhysicsCollisionObject", false);
  177. instance->object = param2;
  178. return 0;
  179. }
  180. else
  181. {
  182. void* returnPtr = (void*)instance->object;
  183. if (returnPtr)
  184. {
  185. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  186. object->instance = returnPtr;
  187. object->owns = false;
  188. luaL_getmetatable(state, "PhysicsCollisionObject");
  189. lua_setmetatable(state, -2);
  190. }
  191. else
  192. {
  193. lua_pushnil(state);
  194. }
  195. return 1;
  196. }
  197. }
  198. int lua_PhysicsControllerHitResult_point(lua_State* state)
  199. {
  200. // Validate the number of parameters.
  201. if (lua_gettop(state) > 2)
  202. {
  203. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  204. lua_error(state);
  205. }
  206. PhysicsController::HitResult* instance = getInstance(state);
  207. if (lua_gettop(state) == 2)
  208. {
  209. // Get parameter 2 off the stack.
  210. Vector3* param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  211. instance->point = *param2;
  212. return 0;
  213. }
  214. else
  215. {
  216. void* returnPtr = (void*)new Vector3(instance->point);
  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, "Vector3");
  223. lua_setmetatable(state, -2);
  224. }
  225. else
  226. {
  227. lua_pushnil(state);
  228. }
  229. return 1;
  230. }
  231. }
  232. }