Node.pkg 21 KB

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