Node.pkg 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. $#include "File.h"
  2. $#include "Node.h"
  3. $#include "LuaScriptInstance.h"
  4. enum CreateMode
  5. {
  6. REPLICATED = 0,
  7. LOCAL = 1
  8. };
  9. enum TransformSpace
  10. {
  11. TS_LOCAL = 0,
  12. TS_PARENT,
  13. TS_WORLD
  14. };
  15. class Node : public Serializable
  16. {
  17. Node();
  18. virtual ~Node();
  19. tolua_outside bool NodeSaveXML @ SaveXML(File* dest) const;
  20. void SetName(const String name);
  21. void SetPosition(const Vector3& position);
  22. tolua_outside void NodeSetPositionXYZ @ SetPositionXYZ(float x, float y, float z);
  23. void SetRotation(const Quaternion& rotation);
  24. tolua_outside void NodeSetRotationXYZ @ SetRotationXYZ(float x, float y, float z);
  25. void SetDirection(const Vector3& direction);
  26. tolua_outside void NodeSetDirectionXYZ @ SetDirectionXYZ(float x, float y, float z);
  27. void SetScale(float scale);
  28. void SetScale(const Vector3& scale);
  29. tolua_outside void NodeSetScaleXYZ @ SetScaleXYZ(float x, float y, float z);
  30. void SetTransform(const Vector3& position, const Quaternion& rotation);
  31. void SetTransform(const Vector3& position, const Quaternion& rotation, float scale);
  32. void SetTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
  33. void SetWorldPosition(const Vector3& position);
  34. tolua_outside void NodeSetWorldPositionXYZ @ SetWorldPositionXYZ(float x, float y, float z);
  35. void SetWorldRotation(const Quaternion& rotation);
  36. tolua_outside void NodeSetWorldRotationXYZ @ SetWorldRotationXYZ(float x, float y, float z);
  37. void SetWorldDirection(const Vector3& direction);
  38. tolua_outside void NodeSetWorldDirectionXYZ @ SetWorldDirectionXYZ(float x, float y, float z);
  39. void SetWorldScale(float scale);
  40. void SetWorldScale(const Vector3& scale);
  41. tolua_outside void NodeSetWorldScaleXYZ @ SetWorldScaleXYZ(float x, float y, float z);
  42. void SetWorldTransform(const Vector3& position, const Quaternion& rotation);
  43. void SetWorldTransform(const Vector3& position, const Quaternion& rotation, float scale);
  44. void SetWorldTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale);
  45. void Translate(const Vector3& delta, TransformSpace space = TS_LOCAL);
  46. tolua_outside void NodeTranslateXYZ @ TranslateXYZ(float x, float y, float z, TransformSpace space = TS_LOCAL);
  47. void Rotate(const Quaternion& delta, TransformSpace space = TS_LOCAL);
  48. tolua_outside void NodeRotateXYZ @ RotateXYZ(float x, float y, float z, TransformSpace space = TS_LOCAL);
  49. void RotateAround(const Vector3& point, const Quaternion& delta, TransformSpace space = TS_LOCAL);
  50. tolua_outside void NodeRotateAroundXYZ @ RotateAroundXYZ(float pX, float pY, float pZ, float dX, float dY, float dZ, TransformSpace space = TS_LOCAL);
  51. void Pitch(float angle, TransformSpace space = TS_LOCAL);
  52. void Yaw(float angle, TransformSpace space = TS_LOCAL);
  53. void Roll(float angle, TransformSpace space = TS_LOCAL);
  54. bool LookAt(const Vector3& target, const Vector3& upAxis = Vector3::UP, TransformSpace space = TS_WORLD);
  55. tolua_outside bool NodeLookAtXYZ @ LookAtXYZ(float x, float y, float z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f, TransformSpace space = TS_WORLD);
  56. void Scale(float scale);
  57. void Scale(const Vector3& scale);
  58. tolua_outside void NodeScaleXYZ @ ScaleXYZ(float x, float y, float z);
  59. void SetEnabled(bool enable);
  60. void SetEnabled(bool enable, bool recursive);
  61. void SetOwner(Connection* owner);
  62. void MarkDirty();
  63. Node* CreateChild(const String name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
  64. void AddChild(Node* node, unsigned index = M_MAX_UNSIGNED);
  65. void RemoveChild(Node* node);
  66. void RemoveAllChildren();
  67. void RemoveChildren(bool removeReplicated, bool removeLocal, bool recursive);
  68. void RemoveComponent(Component* component);
  69. void RemoveComponent(ShortStringHash type);
  70. void RemoveComponent(const String type);
  71. void RemoveAllComponents();
  72. void RemoveComponents(bool removeReplicated, bool removeLocal);
  73. Node* Clone(CreateMode mode = REPLICATED);
  74. void Remove();
  75. void SetParent(Node* parent);
  76. void SetVar(ShortStringHash key, const Variant& value);
  77. void AddListener(Component* component);
  78. void RemoveListener(Component* component);
  79. // template <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
  80. Component* CreateComponent(const String type, CreateMode mode = REPLICATED, unsigned id = 0);
  81. int CreateScriptObject(const String scriptObjectType);
  82. int CreateScriptObject(const String fileName, const String scriptObjectType);
  83. int GetScriptObject() const;
  84. int GetScriptObject(const String scriptObjectType) const;
  85. unsigned GetID() const;
  86. const String GetName() const;
  87. StringHash GetNameHash() const;
  88. Node* GetParent() const;
  89. Scene* GetScene() const;
  90. bool IsEnabled() const;
  91. Connection* GetOwner() const;
  92. const Vector3& GetPosition() const;
  93. tolua_outside void NodeGetPositionXYZ @ GetPositionXYZ(float* x = 0.0f, float* y = 0.0f, float* z = 0.0f) const;
  94. const Quaternion& GetRotation() const;
  95. tolua_outside void NodeGetRotationXYZ @ GetRotationXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  96. tolua_outside void NodeGetRotationWXYZ @ GetRotationWXYZ(float* *w = 0.0f, float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  97. Vector3 GetDirection() const;
  98. tolua_outside void NodeGetDirectionXYZ @ GetDirectionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  99. Vector3 GetUp() const;
  100. tolua_outside void NodeGetUpXYZ @ GetUpXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  101. Vector3 GetRight() const;
  102. tolua_outside void NodeGetRightXYZ @ GetRightXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  103. const Vector3& GetScale() const;
  104. tolua_outside void NodeGetScaleXYZ @ GetScaleXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  105. Matrix3x4 GetTransform() const;
  106. Vector3 GetWorldPosition() const;
  107. tolua_outside void NodeGetWorldPositionXYZ @ GetWorldPositionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  108. Quaternion GetWorldRotation() const;
  109. tolua_outside void NodeGetWorldRotationXYZ @ GetWorldRotationXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  110. tolua_outside void NodeGetWorldRotationWXYZ @ GetWorldRotationWXYZ(float* *w = 0.0f, float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  111. Vector3 GetWorldDirection() const;
  112. tolua_outside void NodeGetWorldDirectionXYZ @ GetWorldDirectionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  113. Vector3 GetWorldUp() const;
  114. tolua_outside void NodeGetWorldUpXYZ @ GetWorldUpXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  115. Vector3 GetWorldRight() const;
  116. tolua_outside void NodeGetWorldRightXYZ @ GetWorldRightXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  117. Vector3 GetWorldScale() const;
  118. tolua_outside void NodeGetWorldScaleXYZ @ GetWorldScaleXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  119. const Matrix3x4& GetWorldTransform() const;
  120. Vector3 LocalToWorld(const Vector3& position) const;
  121. Vector3 LocalToWorld(const Vector4& vector) const;
  122. Vector3 WorldToLocal(const Vector3& position) const;
  123. Vector3 WorldToLocal(const Vector4& vector) const;
  124. bool IsDirty() const;
  125. unsigned GetNumChildren(bool recursive = false) const;
  126. Node* GetChild(const String name, bool recursive = false) const;
  127. Node* GetChild(StringHash nameHash, bool recursive = false) const;
  128. Node* GetChild(unsigned index) const;
  129. unsigned GetNumComponents() const;
  130. unsigned GetNumNetworkComponents() const;
  131. bool HasComponent(ShortStringHash type) const;
  132. bool HasComponent(const String type) const;
  133. const Variant& GetVar(ShortStringHash key) const;
  134. const VariantMap& GetVars() const;
  135. // template <class T> T* GetComponent() const;
  136. Component* GetComponent(const String type) const;
  137. void SetID(unsigned id);
  138. void SetScene(Scene* scene);
  139. void ResetScene();
  140. bool Load(Deserializer& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  141. bool LoadXML(const XMLElement& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  142. Node* CreateChild(unsigned id, CreateMode mode);
  143. void AddComponent(Component* component, unsigned id, CreateMode mode);
  144. tolua_property__get_set unsigned ID;
  145. tolua_property__get_set String name;
  146. tolua_readonly tolua_property__get_set StringHash nameHash;
  147. tolua_property__get_set Node* parent;
  148. tolua_property__get_set Scene* scene;
  149. tolua_property__is_set bool enabled;
  150. tolua_property__get_set Connection* owner;
  151. tolua_property__get_set Vector3& position;
  152. tolua_property__get_set Quaternion& rotation;
  153. tolua_property__get_set Vector3 direction;
  154. tolua_readonly tolua_property__get_set Vector3 up;
  155. tolua_readonly tolua_property__get_set Vector3 right;
  156. tolua_property__get_set Vector3& scale;
  157. tolua_readonly tolua_property__get_set Matrix3x4 transform;
  158. tolua_property__get_set Vector3 worldPosition;
  159. tolua_property__get_set Quaternion worldRotation;
  160. tolua_property__get_set Vector3 worldDirection;
  161. tolua_readonly tolua_property__get_set Vector3 worldUp;
  162. tolua_readonly tolua_property__get_set Vector3 worldRight;
  163. tolua_property__get_set Vector3 worldScale;
  164. tolua_readonly tolua_property__get_set Matrix3x4& worldTransform;
  165. tolua_readonly tolua_property__is_set bool dirty;
  166. tolua_readonly tolua_property__get_set unsigned numComponents;
  167. tolua_readonly tolua_property__get_set unsigned numNetworkComponents;
  168. };
  169. ${
  170. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_new00
  171. static int tolua_SceneLuaAPI_Node_new00(lua_State* tolua_S)
  172. {
  173. return ToluaNewObject<Node>(tolua_S);
  174. }
  175. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_new00_local
  176. static int tolua_SceneLuaAPI_Node_new00_local(lua_State* tolua_S)
  177. {
  178. return ToluaNewObjectGC<Node>(tolua_S);
  179. }
  180. static bool NodeSaveXML(const Node* node, File* file)
  181. {
  182. return file ? node->SaveXML(*file) : false;
  183. }
  184. static void NodeSetPositionXYZ(Node* node, float x, float y, float z)
  185. {
  186. node->SetPosition(Vector3(x, y, z));
  187. }
  188. static void NodeSetRotationXYZ(Node* node, float x, float y, float z)
  189. {
  190. node->SetRotation(Quaternion(x, y, z));
  191. }
  192. static void NodeSetDirectionXYZ(Node* node, float x, float y, float z)
  193. {
  194. node->SetDirection(Vector3(x, y, z));
  195. }
  196. static void NodeSetScaleXYZ(Node* node, float x, float y, float z)
  197. {
  198. node->SetScale(Vector3(x, y, z));
  199. }
  200. static void NodeSetWorldPositionXYZ(Node* node, float x, float y, float z)
  201. {
  202. node->SetWorldPosition(Vector3(x, y, z));
  203. }
  204. static void NodeSetWorldRotationXYZ(Node* node, float x, float y, float z)
  205. {
  206. node->SetWorldRotation(Quaternion(x, y, z));
  207. }
  208. static void NodeSetWorldDirectionXYZ(Node* node, float x, float y, float z)
  209. {
  210. node->SetWorldDirection(Vector3(x, y, z));
  211. }
  212. static void NodeSetWorldScaleXYZ(Node* node, float x, float y, float z)
  213. {
  214. node->SetWorldScale(Vector3(x, y, z));
  215. }
  216. static void NodeTranslateXYZ(Node* node, float x, float y, float z, TransformSpace space = TS_LOCAL)
  217. {
  218. node->Translate(Vector3(x, y, z), space);
  219. }
  220. static void NodeRotateXYZ(Node* node, float x, float y, float z, TransformSpace space = TS_LOCAL)
  221. {
  222. node->Rotate(Quaternion(x, y, z), space);
  223. }
  224. static void NodeRotateAroundXYZ(Node* node, float pX, float pY, float pZ, float rX, float rY, float rZ, TransformSpace space = TS_LOCAL)
  225. {
  226. node->RotateAround(Vector3(pX, pY, pZ), Quaternion(rX, rY, rZ), space);
  227. }
  228. static bool NodeLookAtXYZ(Node* node, float x, float y, float z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f, TransformSpace space = TS_WORLD)
  229. {
  230. return node->LookAt(Vector3(x, y, z), Vector3(upX, upY, upZ), space);
  231. }
  232. static void NodeScaleXYZ(Node* node, float x, float y, float z)
  233. {
  234. node->Scale(Vector3(x, y, z));
  235. }
  236. static void NodeGetPositionXYZ(const Node* node, float* x, float* y, float* z)
  237. {
  238. const Vector3& position = node->GetPosition();
  239. *x = position.x_;
  240. *y = position.y_;
  241. *z = position.z_;
  242. }
  243. static void NodeGetRotationXYZ(const Node* node, float* x, float* y, float* z)
  244. {
  245. const Quaternion& rotation = node->GetRotation();
  246. *x = rotation.x_;
  247. *y = rotation.y_;
  248. *z = rotation.z_;
  249. }
  250. static void NodeGetRotationWXYZ(const Node* node, float* w, float* x, float* y, float* z)
  251. {
  252. const Quaternion& rotation = node->GetRotation();
  253. *w = rotation.w_;
  254. *x = rotation.x_;
  255. *y = rotation.y_;
  256. *z = rotation.z_;
  257. }
  258. static void NodeGetDirectionXYZ(const Node* node, float* x, float* y, float* z)
  259. {
  260. const Vector3& direction = node->GetDirection();
  261. *x = direction.x_;
  262. *y = direction.y_;
  263. *z = direction.z_;
  264. }
  265. static void NodeGetUpXYZ(const Node* node, float* x, float* y, float* z)
  266. {
  267. const Vector3& up = node->GetUp();
  268. *x = up.x_;
  269. *y = up.y_;
  270. *z = up.z_;
  271. }
  272. static void NodeGetRightXYZ(const Node* node, float* x, float* y, float* z)
  273. {
  274. const Vector3& right = node->GetRight();
  275. *x = right.x_;
  276. *y = right.y_;
  277. *z = right.z_;
  278. }
  279. static void NodeGetScaleXYZ(const Node* node, float* x, float* y, float* z)
  280. {
  281. const Vector3& scale = node->GetScale();
  282. *x = scale.x_;
  283. *y = scale.y_;
  284. *z = scale.z_;
  285. }
  286. static void NodeGetWorldPositionXYZ(const Node* node, float* x, float* y, float* z)
  287. {
  288. Vector3 worldPosition = node->GetWorldPosition();
  289. *x = worldPosition.x_;
  290. *y = worldPosition.y_;
  291. *z = worldPosition.z_;
  292. }
  293. static void NodeGetWorldRotationXYZ(const Node* node, float* x, float* y, float* z)
  294. {
  295. Quaternion worldRotation = node->GetWorldRotation();
  296. *x = worldRotation.x_;
  297. *y = worldRotation.y_;
  298. *z = worldRotation.z_;
  299. }
  300. static void NodeGetWorldRotationWXYZ(const Node* node, float* w, float* x, float* y, float* z)
  301. {
  302. Quaternion worldRotation = node->GetWorldRotation();
  303. *w = worldRotation.w_;
  304. *x = worldRotation.x_;
  305. *y = worldRotation.y_;
  306. *z = worldRotation.z_;
  307. }
  308. static void NodeGetWorldDirectionXYZ(const Node* node, float* x, float* y, float* z)
  309. {
  310. Vector3 worldDirection = node->GetWorldDirection();
  311. *x = worldDirection.x_;
  312. *y = worldDirection.y_;
  313. *z = worldDirection.z_;
  314. }
  315. static void NodeGetWorldUpXYZ(const Node* node, float* x, float* y, float* z)
  316. {
  317. Vector3 worldUp = node->GetWorldUp();
  318. *x = worldUp.x_;
  319. *y = worldUp.y_;
  320. *z = worldUp.z_;
  321. }
  322. static void NodeGetWorldRightXYZ(const Node* node, float* x, float* y, float* z)
  323. {
  324. Vector3 worldRight = node->GetWorldRight();
  325. *x = worldRight.x_;
  326. *y = worldRight.y_;
  327. *z = worldRight.z_;
  328. }
  329. static void NodeGetWorldScaleXYZ(const Node* node, float* x, float* y, float* z)
  330. {
  331. Vector3 worldScale = node->GetWorldScale();
  332. *x = worldScale.x_;
  333. *y = worldScale.y_;
  334. *z = worldScale.z_;
  335. }
  336. // Disable generated CreateComponent function.
  337. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateComponent00
  338. static int tolua_SceneLuaAPI_Node_CreateComponent00(lua_State* tolua_S)
  339. {
  340. #ifndef TOLUA_RELEASE
  341. tolua_Error tolua_err;
  342. if (
  343. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  344. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  345. !tolua_isnumber(tolua_S,3,1,&tolua_err) ||
  346. !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
  347. !tolua_isnoobj(tolua_S,5,&tolua_err)
  348. )
  349. goto tolua_lerror;
  350. else
  351. #endif
  352. {
  353. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  354. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  355. CreateMode mode = ((CreateMode) (int) tolua_tonumber(tolua_S,3,REPLICATED));
  356. unsigned id = ((unsigned) tolua_tonumber(tolua_S,4,0));
  357. #ifndef TOLUA_RELEASE
  358. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateComponent'", NULL);
  359. #endif
  360. {
  361. Component* tolua_ret = (Component*) self->CreateComponent(type,mode,id);
  362. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  363. }
  364. }
  365. return 1;
  366. #ifndef TOLUA_RELEASE
  367. tolua_lerror:
  368. tolua_error(tolua_S,"#ferror in function 'CreateComponent'.",&tolua_err);
  369. return 0;
  370. #endif
  371. }
  372. // Disable generated GetComponent function.
  373. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetComponent00
  374. static int tolua_SceneLuaAPI_Node_GetComponent00(lua_State* tolua_S)
  375. {
  376. #ifndef TOLUA_RELEASE
  377. tolua_Error tolua_err;
  378. if (
  379. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  380. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  381. !tolua_isnoobj(tolua_S,3,&tolua_err)
  382. )
  383. goto tolua_lerror;
  384. else
  385. #endif
  386. {
  387. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  388. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  389. #ifndef TOLUA_RELEASE
  390. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetComponent'", NULL);
  391. #endif
  392. {
  393. Component* tolua_ret = (Component*) self->GetComponent(type);
  394. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  395. }
  396. }
  397. return 1;
  398. #ifndef TOLUA_RELEASE
  399. tolua_lerror:
  400. tolua_error(tolua_S,"#ferror in function 'GetComponent'.",&tolua_err);
  401. return 0;
  402. #endif
  403. }
  404. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject00
  405. static int tolua_SceneLuaAPI_Node_CreateScriptObject00(lua_State* tolua_S)
  406. {
  407. #ifndef TOLUA_RELEASE
  408. tolua_Error tolua_err;
  409. if (
  410. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  411. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  412. !tolua_isnoobj(tolua_S,3,&tolua_err)
  413. )
  414. goto tolua_lerror;
  415. else
  416. #endif
  417. {
  418. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  419. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  420. #ifndef TOLUA_RELEASE
  421. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL);
  422. #endif
  423. {
  424. LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
  425. if (!instance)
  426. lua_pushnil(tolua_S);
  427. else
  428. {
  429. instance->CreateObject(scriptObjectType);
  430. // Push script object to Lua stack.
  431. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  432. }
  433. }
  434. }
  435. return 1;
  436. #ifndef TOLUA_RELEASE
  437. tolua_lerror:
  438. tolua_error(tolua_S,"#ferror in function 'CreateScriptObject'.",&tolua_err);
  439. return 0;
  440. #endif
  441. }
  442. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject01
  443. static int tolua_SceneLuaAPI_Node_CreateScriptObject01(lua_State* tolua_S)
  444. {
  445. tolua_Error tolua_err;
  446. if (
  447. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  448. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  449. !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) ||
  450. !tolua_isnoobj(tolua_S,4,&tolua_err)
  451. )
  452. goto tolua_lerror;
  453. else
  454. {
  455. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  456. const String fileName = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  457. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,3,0));
  458. #ifndef TOLUA_RELEASE
  459. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL);
  460. #endif
  461. {
  462. LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
  463. if (!instance)
  464. lua_pushnil(tolua_S);
  465. else
  466. {
  467. instance->CreateObject(fileName, scriptObjectType);
  468. // Push script object to Lua stack.
  469. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  470. }
  471. }
  472. }
  473. return 1;
  474. tolua_lerror:
  475. return tolua_SceneLuaAPI_Node_CreateScriptObject00(tolua_S);
  476. }
  477. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject00
  478. static int tolua_SceneLuaAPI_Node_GetScriptObject00(lua_State* tolua_S)
  479. {
  480. #ifndef TOLUA_RELEASE
  481. tolua_Error tolua_err;
  482. if (
  483. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  484. !tolua_isnoobj(tolua_S,2,&tolua_err)
  485. )
  486. goto tolua_lerror;
  487. else
  488. #endif
  489. {
  490. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  491. #ifndef TOLUA_RELEASE
  492. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL);
  493. #endif
  494. {
  495. LuaScriptInstance* instance = self->GetComponent<LuaScriptInstance>();
  496. if (!instance)
  497. lua_pushnil(tolua_S);
  498. else
  499. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  500. }
  501. }
  502. return 1;
  503. #ifndef TOLUA_RELEASE
  504. tolua_lerror:
  505. tolua_error(tolua_S,"#ferror in function 'GetScriptObject'.",&tolua_err);
  506. return 0;
  507. #endif
  508. }
  509. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject01
  510. static int tolua_SceneLuaAPI_Node_GetScriptObject01(lua_State* tolua_S)
  511. {
  512. tolua_Error tolua_err;
  513. if (
  514. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  515. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  516. !tolua_isnoobj(tolua_S,3,&tolua_err)
  517. )
  518. goto tolua_lerror;
  519. else
  520. {
  521. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  522. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  523. #ifndef TOLUA_RELEASE
  524. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL);
  525. #endif
  526. {
  527. int scriptObjectRef = LUA_REFNIL;
  528. PODVector<LuaScriptInstance*> instances;
  529. self->GetComponents<LuaScriptInstance>(instances, false);
  530. for (unsigned i = 0; i < instances.Size(); ++i)
  531. {
  532. if (instances[i]->GetScriptObjectType() == scriptObjectType)
  533. {
  534. scriptObjectRef = instances[i]->GetScriptObjectRef();
  535. break;
  536. }
  537. }
  538. if (scriptObjectRef == LUA_REFNIL)
  539. lua_pushnil(tolua_S);
  540. else
  541. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, scriptObjectRef);
  542. }
  543. }
  544. return 1;
  545. tolua_lerror:
  546. return tolua_SceneLuaAPI_Node_GetScriptObject00(tolua_S);
  547. }
  548. $}