lua_NodeCloneContext.cpp 10 KB

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