lua_NodeCloneContext.cpp 10 KB

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