lua_PhysicsControllerHitResult.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 "ScriptController.h"
  12. #include "ScriptTarget.h"
  13. #include "Terrain.h"
  14. #include "lua_PhysicsControllerListenerEventType.h"
  15. namespace gameplay
  16. {
  17. void luaRegister_PhysicsControllerHitResult()
  18. {
  19. const luaL_Reg lua_members[] =
  20. {
  21. {"fraction", lua_PhysicsControllerHitResult_fraction},
  22. {"normal", lua_PhysicsControllerHitResult_normal},
  23. {"object", lua_PhysicsControllerHitResult_object},
  24. {"point", lua_PhysicsControllerHitResult_point},
  25. {NULL, NULL}
  26. };
  27. const luaL_Reg* lua_statics = NULL;
  28. std::vector<std::string> scopePath;
  29. scopePath.push_back("PhysicsController");
  30. ScriptUtil::registerClass("PhysicsControllerHitResult", lua_members, lua_PhysicsControllerHitResult__init, lua_PhysicsControllerHitResult__gc, lua_statics, scopePath);
  31. }
  32. static PhysicsController::HitResult* getInstance(lua_State* state)
  33. {
  34. void* userdata = luaL_checkudata(state, 1, "PhysicsControllerHitResult");
  35. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsControllerHitResult' expected.");
  36. return (PhysicsController::HitResult*)((ScriptUtil::LuaObject*)userdata)->instance;
  37. }
  38. int lua_PhysicsControllerHitResult__gc(lua_State* state)
  39. {
  40. // Get the number of parameters.
  41. int paramCount = lua_gettop(state);
  42. // Attempt to match the parameters to a valid binding.
  43. switch (paramCount)
  44. {
  45. case 1:
  46. {
  47. if ((lua_type(state, 1) == LUA_TUSERDATA))
  48. {
  49. void* userdata = luaL_checkudata(state, 1, "PhysicsControllerHitResult");
  50. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsControllerHitResult' expected.");
  51. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  52. if (object->owns)
  53. {
  54. PhysicsController::HitResult* instance = (PhysicsController::HitResult*)object->instance;
  55. SAFE_DELETE(instance);
  56. }
  57. return 0;
  58. }
  59. lua_pushstring(state, "lua_PhysicsControllerHitResult__gc - Failed to match the given parameters to a valid function signature.");
  60. lua_error(state);
  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. bool param2Valid;
  143. ScriptUtil::LuaArray<Vector3> param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true, &param2Valid);
  144. if (!param2Valid)
  145. {
  146. lua_pushstring(state, "Failed to convert parameter 2 to type 'Vector3'.");
  147. lua_error(state);
  148. }
  149. instance->normal = *param2;
  150. return 0;
  151. }
  152. else
  153. {
  154. void* returnPtr = (void*)new Vector3(instance->normal);
  155. if (returnPtr)
  156. {
  157. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  158. object->instance = returnPtr;
  159. object->owns = true;
  160. luaL_getmetatable(state, "Vector3");
  161. lua_setmetatable(state, -2);
  162. }
  163. else
  164. {
  165. lua_pushnil(state);
  166. }
  167. return 1;
  168. }
  169. }
  170. int lua_PhysicsControllerHitResult_object(lua_State* state)
  171. {
  172. // Validate the number of parameters.
  173. if (lua_gettop(state) > 2)
  174. {
  175. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  176. lua_error(state);
  177. }
  178. PhysicsController::HitResult* instance = getInstance(state);
  179. if (lua_gettop(state) == 2)
  180. {
  181. // Get parameter 2 off the stack.
  182. bool param2Valid;
  183. ScriptUtil::LuaArray<PhysicsCollisionObject> param2 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(2, "PhysicsCollisionObject", false, &param2Valid);
  184. if (!param2Valid)
  185. {
  186. lua_pushstring(state, "Failed to convert parameter 2 to type 'PhysicsCollisionObject'.");
  187. lua_error(state);
  188. }
  189. instance->object = param2;
  190. return 0;
  191. }
  192. else
  193. {
  194. void* returnPtr = (void*)instance->object;
  195. if (returnPtr)
  196. {
  197. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  198. object->instance = returnPtr;
  199. object->owns = false;
  200. luaL_getmetatable(state, "PhysicsCollisionObject");
  201. lua_setmetatable(state, -2);
  202. }
  203. else
  204. {
  205. lua_pushnil(state);
  206. }
  207. return 1;
  208. }
  209. }
  210. int lua_PhysicsControllerHitResult_point(lua_State* state)
  211. {
  212. // Validate the number of parameters.
  213. if (lua_gettop(state) > 2)
  214. {
  215. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  216. lua_error(state);
  217. }
  218. PhysicsController::HitResult* instance = getInstance(state);
  219. if (lua_gettop(state) == 2)
  220. {
  221. // Get parameter 2 off the stack.
  222. bool param2Valid;
  223. ScriptUtil::LuaArray<Vector3> param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true, &param2Valid);
  224. if (!param2Valid)
  225. {
  226. lua_pushstring(state, "Failed to convert parameter 2 to type 'Vector3'.");
  227. lua_error(state);
  228. }
  229. instance->point = *param2;
  230. return 0;
  231. }
  232. else
  233. {
  234. void* returnPtr = (void*)new Vector3(instance->point);
  235. if (returnPtr)
  236. {
  237. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  238. object->instance = returnPtr;
  239. object->owns = true;
  240. luaL_getmetatable(state, "Vector3");
  241. lua_setmetatable(state, -2);
  242. }
  243. else
  244. {
  245. lua_pushnil(state);
  246. }
  247. return 1;
  248. }
  249. }
  250. }