lua_NodeCloneContext.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_NodeCloneContext.h"
  4. #include "Animation.h"
  5. #include "AnimationTarget.h"
  6. #include "AudioSource.h"
  7. #include "Base.h"
  8. #include "Game.h"
  9. #include "Joint.h"
  10. #include "Node.h"
  11. #include "PhysicsCharacter.h"
  12. #include "PhysicsGhostObject.h"
  13. #include "PhysicsRigidBody.h"
  14. #include "PhysicsVehicle.h"
  15. #include "PhysicsVehicleWheel.h"
  16. #include "Ref.h"
  17. #include "Scene.h"
  18. #include "ScriptController.h"
  19. #include "ScriptTarget.h"
  20. #include "Terrain.h"
  21. #include "Transform.h"
  22. #include "lua_CurveInterpolationType.h"
  23. #include "lua_NodeType.h"
  24. #include "lua_PhysicsCollisionObjectType.h"
  25. namespace gameplay
  26. {
  27. void luaRegister_NodeCloneContext()
  28. {
  29. const luaL_Reg lua_members[] =
  30. {
  31. {"findClonedAnimation", lua_NodeCloneContext_findClonedAnimation},
  32. {"findClonedNode", lua_NodeCloneContext_findClonedNode},
  33. {"registerClonedAnimation", lua_NodeCloneContext_registerClonedAnimation},
  34. {"registerClonedNode", lua_NodeCloneContext_registerClonedNode},
  35. {NULL, NULL}
  36. };
  37. const luaL_Reg* lua_statics = NULL;
  38. std::vector<std::string> scopePath;
  39. gameplay::ScriptUtil::registerClass("NodeCloneContext", lua_members, lua_NodeCloneContext__init, lua_NodeCloneContext__gc, lua_statics, scopePath);
  40. }
  41. static NodeCloneContext* getInstance(lua_State* state)
  42. {
  43. void* userdata = luaL_checkudata(state, 1, "NodeCloneContext");
  44. luaL_argcheck(state, userdata != NULL, 1, "'NodeCloneContext' expected.");
  45. return (NodeCloneContext*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  46. }
  47. int lua_NodeCloneContext__gc(lua_State* state)
  48. {
  49. // Get the number of parameters.
  50. int paramCount = lua_gettop(state);
  51. // Attempt to match the parameters to a valid binding.
  52. switch (paramCount)
  53. {
  54. case 1:
  55. {
  56. if ((lua_type(state, 1) == LUA_TUSERDATA))
  57. {
  58. void* userdata = luaL_checkudata(state, 1, "NodeCloneContext");
  59. luaL_argcheck(state, userdata != NULL, 1, "'NodeCloneContext' expected.");
  60. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  61. if (object->owns)
  62. {
  63. NodeCloneContext* instance = (NodeCloneContext*)object->instance;
  64. SAFE_DELETE(instance);
  65. }
  66. return 0;
  67. }
  68. lua_pushstring(state, "lua_NodeCloneContext__gc - Failed to match the given parameters to a valid function signature.");
  69. lua_error(state);
  70. break;
  71. }
  72. default:
  73. {
  74. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  75. lua_error(state);
  76. break;
  77. }
  78. }
  79. return 0;
  80. }
  81. int lua_NodeCloneContext__init(lua_State* state)
  82. {
  83. // Get the number of parameters.
  84. int paramCount = lua_gettop(state);
  85. // Attempt to match the parameters to a valid binding.
  86. switch (paramCount)
  87. {
  88. case 0:
  89. {
  90. void* returnPtr = (void*)new NodeCloneContext();
  91. if (returnPtr)
  92. {
  93. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  94. object->instance = returnPtr;
  95. object->owns = true;
  96. luaL_getmetatable(state, "NodeCloneContext");
  97. lua_setmetatable(state, -2);
  98. }
  99. else
  100. {
  101. lua_pushnil(state);
  102. }
  103. return 1;
  104. break;
  105. }
  106. default:
  107. {
  108. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  109. lua_error(state);
  110. break;
  111. }
  112. }
  113. return 0;
  114. }
  115. int lua_NodeCloneContext_findClonedAnimation(lua_State* state)
  116. {
  117. // Get the number of parameters.
  118. int paramCount = lua_gettop(state);
  119. // Attempt to match the parameters to a valid binding.
  120. switch (paramCount)
  121. {
  122. case 2:
  123. {
  124. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  125. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  126. {
  127. // Get parameter 1 off the stack.
  128. bool param1Valid;
  129. gameplay::ScriptUtil::LuaArray<Animation> param1 = gameplay::ScriptUtil::getObjectPointer<Animation>(2, "Animation", false, &param1Valid);
  130. if (!param1Valid)
  131. {
  132. lua_pushstring(state, "Failed to convert parameter 1 to type 'Animation'.");
  133. lua_error(state);
  134. }
  135. NodeCloneContext* instance = getInstance(state);
  136. void* returnPtr = (void*)instance->findClonedAnimation(param1);
  137. if (returnPtr)
  138. {
  139. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  140. object->instance = returnPtr;
  141. object->owns = false;
  142. luaL_getmetatable(state, "Animation");
  143. lua_setmetatable(state, -2);
  144. }
  145. else
  146. {
  147. lua_pushnil(state);
  148. }
  149. return 1;
  150. }
  151. lua_pushstring(state, "lua_NodeCloneContext_findClonedAnimation - Failed to match the given parameters to a valid function signature.");
  152. lua_error(state);
  153. break;
  154. }
  155. default:
  156. {
  157. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  158. lua_error(state);
  159. break;
  160. }
  161. }
  162. return 0;
  163. }
  164. int lua_NodeCloneContext_findClonedNode(lua_State* state)
  165. {
  166. // Get the number of parameters.
  167. int paramCount = lua_gettop(state);
  168. // Attempt to match the parameters to a valid binding.
  169. switch (paramCount)
  170. {
  171. case 2:
  172. {
  173. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  174. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  175. {
  176. // Get parameter 1 off the stack.
  177. bool param1Valid;
  178. gameplay::ScriptUtil::LuaArray<Node> param1 = gameplay::ScriptUtil::getObjectPointer<Node>(2, "Node", false, &param1Valid);
  179. if (!param1Valid)
  180. {
  181. lua_pushstring(state, "Failed to convert parameter 1 to type 'Node'.");
  182. lua_error(state);
  183. }
  184. NodeCloneContext* instance = getInstance(state);
  185. void* returnPtr = (void*)instance->findClonedNode(param1);
  186. if (returnPtr)
  187. {
  188. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  189. object->instance = returnPtr;
  190. object->owns = false;
  191. luaL_getmetatable(state, "Node");
  192. lua_setmetatable(state, -2);
  193. }
  194. else
  195. {
  196. lua_pushnil(state);
  197. }
  198. return 1;
  199. }
  200. lua_pushstring(state, "lua_NodeCloneContext_findClonedNode - Failed to match the given parameters to a valid function signature.");
  201. lua_error(state);
  202. break;
  203. }
  204. default:
  205. {
  206. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  207. lua_error(state);
  208. break;
  209. }
  210. }
  211. return 0;
  212. }
  213. int lua_NodeCloneContext_registerClonedAnimation(lua_State* state)
  214. {
  215. // Get the number of parameters.
  216. int paramCount = lua_gettop(state);
  217. // Attempt to match the parameters to a valid binding.
  218. switch (paramCount)
  219. {
  220. case 3:
  221. {
  222. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  223. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  224. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  225. {
  226. // Get parameter 1 off the stack.
  227. bool param1Valid;
  228. gameplay::ScriptUtil::LuaArray<Animation> param1 = gameplay::ScriptUtil::getObjectPointer<Animation>(2, "Animation", false, &param1Valid);
  229. if (!param1Valid)
  230. {
  231. lua_pushstring(state, "Failed to convert parameter 1 to type 'Animation'.");
  232. lua_error(state);
  233. }
  234. // Get parameter 2 off the stack.
  235. bool param2Valid;
  236. gameplay::ScriptUtil::LuaArray<Animation> param2 = gameplay::ScriptUtil::getObjectPointer<Animation>(3, "Animation", false, &param2Valid);
  237. if (!param2Valid)
  238. {
  239. lua_pushstring(state, "Failed to convert parameter 2 to type 'Animation'.");
  240. lua_error(state);
  241. }
  242. NodeCloneContext* instance = getInstance(state);
  243. instance->registerClonedAnimation(param1, param2);
  244. return 0;
  245. }
  246. lua_pushstring(state, "lua_NodeCloneContext_registerClonedAnimation - Failed to match the given parameters to a valid function signature.");
  247. lua_error(state);
  248. break;
  249. }
  250. default:
  251. {
  252. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  253. lua_error(state);
  254. break;
  255. }
  256. }
  257. return 0;
  258. }
  259. int lua_NodeCloneContext_registerClonedNode(lua_State* state)
  260. {
  261. // Get the number of parameters.
  262. int paramCount = lua_gettop(state);
  263. // Attempt to match the parameters to a valid binding.
  264. switch (paramCount)
  265. {
  266. case 3:
  267. {
  268. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  269. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  270. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  271. {
  272. // Get parameter 1 off the stack.
  273. bool param1Valid;
  274. gameplay::ScriptUtil::LuaArray<Node> param1 = gameplay::ScriptUtil::getObjectPointer<Node>(2, "Node", false, &param1Valid);
  275. if (!param1Valid)
  276. {
  277. lua_pushstring(state, "Failed to convert parameter 1 to type 'Node'.");
  278. lua_error(state);
  279. }
  280. // Get parameter 2 off the stack.
  281. bool param2Valid;
  282. gameplay::ScriptUtil::LuaArray<Node> param2 = gameplay::ScriptUtil::getObjectPointer<Node>(3, "Node", false, &param2Valid);
  283. if (!param2Valid)
  284. {
  285. lua_pushstring(state, "Failed to convert parameter 2 to type 'Node'.");
  286. lua_error(state);
  287. }
  288. NodeCloneContext* instance = getInstance(state);
  289. instance->registerClonedNode(param1, param2);
  290. return 0;
  291. }
  292. lua_pushstring(state, "lua_NodeCloneContext_registerClonedNode - Failed to match the given parameters to a valid function signature.");
  293. lua_error(state);
  294. break;
  295. }
  296. default:
  297. {
  298. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  299. lua_error(state);
  300. break;
  301. }
  302. }
  303. return 0;
  304. }
  305. }