Node.pkg 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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(Context* context);
  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. static bool NodeSaveXML(const Node* node, File* file)
  165. {
  166. return file ? node->SaveXML(*file) : false;
  167. }
  168. static void NodeSetPositionXYZ(Node* node, float x, float y, float z)
  169. {
  170. node->SetPosition(Vector3(x, y, z));
  171. }
  172. static void NodeSetRotationXYZ(Node* node, float x, float y, float z)
  173. {
  174. node->SetRotation(Quaternion(x, y, z));
  175. }
  176. static void NodeSetDirectionXYZ(Node* node, float x, float y, float z)
  177. {
  178. node->SetDirection(Vector3(x, y, z));
  179. }
  180. static void NodeSetScaleXYZ(Node* node, float x, float y, float z)
  181. {
  182. node->SetScale(Vector3(x, y, z));
  183. }
  184. static void NodeSetWorldPositionXYZ(Node* node, float x, float y, float z)
  185. {
  186. node->SetWorldPosition(Vector3(x, y, z));
  187. }
  188. static void NodeSetWorldRotationXYZ(Node* node, float x, float y, float z)
  189. {
  190. node->SetWorldRotation(Quaternion(x, y, z));
  191. }
  192. static void NodeSetWorldDirectionXYZ(Node* node, float x, float y, float z)
  193. {
  194. node->SetWorldDirection(Vector3(x, y, z));
  195. }
  196. static void NodeSetWorldScaleXYZ(Node* node, float x, float y, float z)
  197. {
  198. node->SetWorldScale(Vector3(x, y, z));
  199. }
  200. static void NodeTranslateXYZ(Node* node, float x, float y, float z)
  201. {
  202. node->Translate(Vector3(x, y, z));
  203. }
  204. static void NodeTranslateRelativeXYZ(Node* node, float x, float y, float z)
  205. {
  206. node->TranslateRelative(Vector3(x, y, z));
  207. }
  208. static void NodeRotateXYZ(Node* node, float x, float y, float z, bool fixedAxis = false)
  209. {
  210. node->Rotate(Quaternion(x, y, z), fixedAxis);
  211. }
  212. static void NodeLookAtXYZ(Node* node, float x, float y, float z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f)
  213. {
  214. node->LookAt(Vector3(x, y, z), Vector3(upX, upY, upZ));
  215. }
  216. static void NodeScaleXYZ(Node* node, float x, float y, float z)
  217. {
  218. node->Scale(Vector3(x, y, z));
  219. }
  220. static void NodeGetPositionXYZ(const Node* node, float* x, float* y, float* z)
  221. {
  222. const Vector3& position = node->GetPosition();
  223. *x = position.x_;
  224. *y = position.y_;
  225. *z = position.z_;
  226. }
  227. static void NodeGetRotationXYZ(const Node* node, float* x, float* y, float* z)
  228. {
  229. const Quaternion& rotation = node->GetRotation();
  230. *x = rotation.x_;
  231. *y = rotation.y_;
  232. *z = rotation.z_;
  233. }
  234. static void NodeGetRotationWXYZ(const Node* node, float* w, float* x, float* y, float* z)
  235. {
  236. const Quaternion& rotation = node->GetRotation();
  237. *w = rotation.w_;
  238. *x = rotation.x_;
  239. *y = rotation.y_;
  240. *z = rotation.z_;
  241. }
  242. static void NodeGetDirectionXYZ(const Node* node, float* x, float* y, float* z)
  243. {
  244. const Vector3& direction = node->GetDirection();
  245. *x = direction.x_;
  246. *y = direction.y_;
  247. *z = direction.z_;
  248. }
  249. static void NodeGetUpXYZ(const Node* node, float* x, float* y, float* z)
  250. {
  251. const Vector3& up = node->GetUp();
  252. *x = up.x_;
  253. *y = up.y_;
  254. *z = up.z_;
  255. }
  256. static void NodeGetRightXYZ(const Node* node, float* x, float* y, float* z)
  257. {
  258. const Vector3& right = node->GetRight();
  259. *x = right.x_;
  260. *y = right.y_;
  261. *z = right.z_;
  262. }
  263. static void NodeGetScaleXYZ(const Node* node, float* x, float* y, float* z)
  264. {
  265. const Vector3& scale = node->GetScale();
  266. *x = scale.x_;
  267. *y = scale.y_;
  268. *z = scale.z_;
  269. }
  270. static void NodeGetWorldPositionXYZ(const Node* node, float* x, float* y, float* z)
  271. {
  272. Vector3 worldPosition = node->GetWorldPosition();
  273. *x = worldPosition.x_;
  274. *y = worldPosition.y_;
  275. *z = worldPosition.z_;
  276. }
  277. static void NodeGetWorldRotationXYZ(const Node* node, float* x, float* y, float* z)
  278. {
  279. Quaternion worldRotation = node->GetWorldRotation();
  280. *x = worldRotation.x_;
  281. *y = worldRotation.y_;
  282. *z = worldRotation.z_;
  283. }
  284. static void NodeGetWorldRotationWXYZ(const Node* node, float* w, float* x, float* y, float* z)
  285. {
  286. Quaternion worldRotation = node->GetWorldRotation();
  287. *w = worldRotation.w_;
  288. *x = worldRotation.x_;
  289. *y = worldRotation.y_;
  290. *z = worldRotation.z_;
  291. }
  292. static void NodeGetWorldDirectionXYZ(const Node* node, float* x, float* y, float* z)
  293. {
  294. Vector3 worldDirection = node->GetWorldDirection();
  295. *x = worldDirection.x_;
  296. *y = worldDirection.y_;
  297. *z = worldDirection.z_;
  298. }
  299. static void NodeGetWorldUpXYZ(const Node* node, float* x, float* y, float* z)
  300. {
  301. Vector3 worldUp = node->GetWorldUp();
  302. *x = worldUp.x_;
  303. *y = worldUp.y_;
  304. *z = worldUp.z_;
  305. }
  306. static void NodeGetWorldRightXYZ(const Node* node, float* x, float* y, float* z)
  307. {
  308. Vector3 worldRight = node->GetWorldRight();
  309. *x = worldRight.x_;
  310. *y = worldRight.y_;
  311. *z = worldRight.z_;
  312. }
  313. static void NodeGetWorldScaleXYZ(const Node* node, float* x, float* y, float* z)
  314. {
  315. Vector3 worldScale = node->GetWorldScale();
  316. *x = worldScale.x_;
  317. *y = worldScale.y_;
  318. *z = worldScale.z_;
  319. }
  320. // Disable generated CreateComponent function.
  321. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateComponent00
  322. static int tolua_SceneLuaAPI_Node_CreateComponent00(lua_State* tolua_S)
  323. {
  324. #ifndef TOLUA_RELEASE
  325. tolua_Error tolua_err;
  326. if (
  327. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  328. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  329. !tolua_isnumber(tolua_S,3,1,&tolua_err) ||
  330. !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
  331. !tolua_isnoobj(tolua_S,5,&tolua_err)
  332. )
  333. goto tolua_lerror;
  334. else
  335. #endif
  336. {
  337. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  338. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  339. CreateMode mode = ((CreateMode) (int) tolua_tonumber(tolua_S,3,REPLICATED));
  340. unsigned id = ((unsigned) tolua_tonumber(tolua_S,4,0));
  341. #ifndef TOLUA_RELEASE
  342. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateComponent'", NULL);
  343. #endif
  344. {
  345. Component* tolua_ret = (Component*) self->CreateComponent(type,mode,id);
  346. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  347. }
  348. }
  349. return 1;
  350. #ifndef TOLUA_RELEASE
  351. tolua_lerror:
  352. tolua_error(tolua_S,"#ferror in function 'CreateComponent'.",&tolua_err);
  353. return 0;
  354. #endif
  355. }
  356. // Disable generated GetComponent function.
  357. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetComponent00
  358. static int tolua_SceneLuaAPI_Node_GetComponent00(lua_State* tolua_S)
  359. {
  360. #ifndef TOLUA_RELEASE
  361. tolua_Error tolua_err;
  362. if (
  363. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  364. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  365. !tolua_isnoobj(tolua_S,3,&tolua_err)
  366. )
  367. goto tolua_lerror;
  368. else
  369. #endif
  370. {
  371. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  372. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  373. #ifndef TOLUA_RELEASE
  374. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetComponent'", NULL);
  375. #endif
  376. {
  377. Component* tolua_ret = (Component*) self->GetComponent(type);
  378. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  379. }
  380. }
  381. return 1;
  382. #ifndef TOLUA_RELEASE
  383. tolua_lerror:
  384. tolua_error(tolua_S,"#ferror in function 'GetComponent'.",&tolua_err);
  385. return 0;
  386. #endif
  387. }
  388. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject00
  389. static int tolua_SceneLuaAPI_Node_CreateScriptObject00(lua_State* tolua_S)
  390. {
  391. #ifndef TOLUA_RELEASE
  392. tolua_Error tolua_err;
  393. if (
  394. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  395. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  396. !tolua_isnoobj(tolua_S,3,&tolua_err)
  397. )
  398. goto tolua_lerror;
  399. else
  400. #endif
  401. {
  402. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  403. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  404. #ifndef TOLUA_RELEASE
  405. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL);
  406. #endif
  407. {
  408. LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
  409. if (!instance)
  410. lua_pushnil(tolua_S);
  411. else
  412. {
  413. instance->CreateObject(scriptObjectType);
  414. // Push script object to Lua stack.
  415. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  416. }
  417. }
  418. }
  419. return 1;
  420. #ifndef TOLUA_RELEASE
  421. tolua_lerror:
  422. tolua_error(tolua_S,"#ferror in function 'CreateScriptObject'.",&tolua_err);
  423. return 0;
  424. #endif
  425. }
  426. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject01
  427. static int tolua_SceneLuaAPI_Node_CreateScriptObject01(lua_State* tolua_S)
  428. {
  429. tolua_Error tolua_err;
  430. if (
  431. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  432. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  433. !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) ||
  434. !tolua_isnoobj(tolua_S,4,&tolua_err)
  435. )
  436. goto tolua_lerror;
  437. else
  438. {
  439. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  440. const String fileName = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  441. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,3,0));
  442. #ifndef TOLUA_RELEASE
  443. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL);
  444. #endif
  445. {
  446. LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
  447. if (!instance)
  448. lua_pushnil(tolua_S);
  449. else
  450. {
  451. instance->CreateObject(fileName, scriptObjectType);
  452. // Push script object to Lua stack.
  453. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  454. }
  455. }
  456. }
  457. return 1;
  458. tolua_lerror:
  459. return tolua_SceneLuaAPI_Node_CreateScriptObject00(tolua_S);
  460. }
  461. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject00
  462. static int tolua_SceneLuaAPI_Node_GetScriptObject00(lua_State* tolua_S)
  463. {
  464. #ifndef TOLUA_RELEASE
  465. tolua_Error tolua_err;
  466. if (
  467. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  468. !tolua_isnoobj(tolua_S,2,&tolua_err)
  469. )
  470. goto tolua_lerror;
  471. else
  472. #endif
  473. {
  474. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  475. #ifndef TOLUA_RELEASE
  476. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL);
  477. #endif
  478. {
  479. LuaScriptInstance* instance = self->GetComponent<LuaScriptInstance>();
  480. if (!instance)
  481. lua_pushnil(tolua_S);
  482. else
  483. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  484. }
  485. }
  486. return 1;
  487. #ifndef TOLUA_RELEASE
  488. tolua_lerror:
  489. tolua_error(tolua_S,"#ferror in function 'GetScriptObject'.",&tolua_err);
  490. return 0;
  491. #endif
  492. }
  493. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject01
  494. static int tolua_SceneLuaAPI_Node_GetScriptObject01(lua_State* tolua_S)
  495. {
  496. tolua_Error tolua_err;
  497. if (
  498. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  499. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  500. !tolua_isnoobj(tolua_S,3,&tolua_err)
  501. )
  502. goto tolua_lerror;
  503. else
  504. {
  505. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  506. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  507. #ifndef TOLUA_RELEASE
  508. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL);
  509. #endif
  510. {
  511. int scriptObjectRef = LUA_REFNIL;
  512. PODVector<LuaScriptInstance*> instances;
  513. self->GetComponents<LuaScriptInstance>(instances, false);
  514. for (unsigned i = 0; i < instances.Size(); ++i)
  515. {
  516. if (instances[i]->GetScriptObjectType() == scriptObjectType)
  517. {
  518. scriptObjectRef = instances[i]->GetScriptObjectRef();
  519. break;
  520. }
  521. }
  522. if (scriptObjectRef == LUA_REFNIL)
  523. lua_pushnil(tolua_S);
  524. else
  525. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, scriptObjectRef);
  526. }
  527. }
  528. return 1;
  529. tolua_lerror:
  530. return tolua_SceneLuaAPI_Node_GetScriptObject00(tolua_S);
  531. }
  532. $}