Node.pkg 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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. const Vector3& GetScale() const;
  94. tolua_outside void NodeGetScaleXYZ @ GetScaleXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  95. Matrix3x4 GetTransform() const;
  96. Vector3 GetWorldPosition() const;
  97. tolua_outside void NodeGetWorldPositionXYZ @ GetWorldPositionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  98. Quaternion GetWorldRotation() const;
  99. tolua_outside void NodeGetWorldRotationXYZ @ GetWorldRotationXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  100. tolua_outside void NodeGetWorldRotationWXYZ @ GetWorldRotationWXYZ(float* *w = 0.0f, float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  101. Vector3 GetWorldDirection() const;
  102. tolua_outside void NodeGetWorldDirectionXYZ @ GetWorldDirectionXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  103. Vector3 GetWorldScale() const;
  104. tolua_outside void NodeGetWorldScaleXYZ @ GetWorldScaleXYZ(float* *x = 0.0f, float* *y = 0.0f, float* *z = 0.0f) const;
  105. const Matrix3x4& GetWorldTransform() const;
  106. Vector3 LocalToWorld(const Vector3& position) const;
  107. Vector3 LocalToWorld(const Vector4& vector) const;
  108. Vector3 WorldToLocal(const Vector3& position) const;
  109. Vector3 WorldToLocal(const Vector4& vector) const;
  110. bool IsDirty() const;
  111. unsigned GetNumChildren(bool recursive = false) const;
  112. Node* GetChild(unsigned index) const;
  113. Node* GetChild(const String name, bool recursive = false) const;
  114. Node* GetChild(StringHash nameHash, bool recursive = false) const;
  115. unsigned GetNumComponents() const;
  116. unsigned GetNumNetworkComponents() const;
  117. bool HasComponent(ShortStringHash type) const;
  118. bool HasComponent(const String type) const;
  119. const Variant& GetVar(ShortStringHash key) const;
  120. const VariantMap& GetVars() const;
  121. // template <class T> T* GetComponent() const;
  122. Component* GetComponent(const String type) const;
  123. void SetID(unsigned id);
  124. void SetScene(Scene* scene);
  125. void ResetScene();
  126. bool Load(Deserializer& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  127. bool LoadXML(const XMLElement& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
  128. Node* CreateChild(unsigned id, CreateMode mode);
  129. void AddComponent(Component* component, unsigned id, CreateMode mode);
  130. tolua_property__get_set unsigned ID;
  131. tolua_property__get_set String& name;
  132. tolua_readonly tolua_property__get_set StringHash nameHash;
  133. tolua_property__get_set Node* parent;
  134. tolua_property__get_set Scene* scene;
  135. tolua_property__is_set bool enabled;
  136. tolua_property__get_set Connection* owner;
  137. tolua_property__get_set Vector3& position;
  138. tolua_property__get_set Quaternion& rotation;
  139. tolua_property__get_set Vector3 direction;
  140. tolua_property__get_set Vector3& scale;
  141. tolua_readonly tolua_property__get_set Matrix3x4 transform;
  142. tolua_property__get_set Vector3 worldPosition;
  143. tolua_property__get_set Quaternion worldRotation;
  144. tolua_property__get_set Vector3 worldDirection;
  145. tolua_property__get_set Vector3 worldScale;
  146. tolua_readonly tolua_property__get_set Matrix3x4& worldTransform;
  147. tolua_readonly tolua_property__is_set bool dirty;
  148. tolua_readonly tolua_property__get_set unsigned numComponents;
  149. tolua_readonly tolua_property__get_set unsigned numNetworkComponents;
  150. };
  151. ${
  152. static bool NodeSaveXML(const Node* node, File* file)
  153. {
  154. return file ? node->SaveXML(*file) : false;
  155. }
  156. static void NodeSetPositionXYZ(Node* node, float x, float y, float z)
  157. {
  158. node->SetPosition(Vector3(x, y, z));
  159. }
  160. static void NodeSetRotationXYZ(Node* node, float x, float y, float z)
  161. {
  162. node->SetRotation(Quaternion(x, y, z));
  163. }
  164. static void NodeSetDirectionXYZ(Node* node, float x, float y, float z)
  165. {
  166. node->SetDirection(Vector3(x, y, z));
  167. }
  168. static void NodeSetScaleXYZ(Node* node, float x, float y, float z)
  169. {
  170. node->SetScale(Vector3(x, y, z));
  171. }
  172. static void NodeSetWorldPositionXYZ(Node* node, float x, float y, float z)
  173. {
  174. node->SetWorldPosition(Vector3(x, y, z));
  175. }
  176. static void NodeSetWorldRotationXYZ(Node* node, float x, float y, float z)
  177. {
  178. node->SetWorldRotation(Quaternion(x, y, z));
  179. }
  180. static void NodeSetWorldDirectionXYZ(Node* node, float x, float y, float z)
  181. {
  182. node->SetWorldDirection(Vector3(x, y, z));
  183. }
  184. static void NodeSetWorldScaleXYZ(Node* node, float x, float y, float z)
  185. {
  186. node->SetWorldScale(Vector3(x, y, z));
  187. }
  188. static void NodeTranslateXYZ(Node* node, float x, float y, float z)
  189. {
  190. node->Translate(Vector3(x, y, z));
  191. }
  192. static void NodeTranslateRelativeXYZ(Node* node, float x, float y, float z)
  193. {
  194. node->TranslateRelative(Vector3(x, y, z));
  195. }
  196. static void NodeRotateXYZ(Node* node, float x, float y, float z, bool fixedAxis = false)
  197. {
  198. node->Rotate(Quaternion(x, y, z), fixedAxis);
  199. }
  200. static void NodeLookAtXYZ(Node* node, float x, float y, float z, float upX = 0.0f, float upY = 1.0f, float upZ = 0.0f)
  201. {
  202. node->LookAt(Vector3(x, y, z), Vector3(upX, upY, upZ));
  203. }
  204. static void NodeScaleXYZ(Node* node, float x, float y, float z)
  205. {
  206. node->Scale(Vector3(x, y, z));
  207. }
  208. static void NodeGetPositionXYZ(const Node* node, float* x, float* y, float* z)
  209. {
  210. const Vector3& position = node->GetPosition();
  211. *x = position.x_;
  212. *y = position.y_;
  213. *z = position.z_;
  214. }
  215. static void NodeGetRotationXYZ(const Node* node, float* x, float* y, float* z)
  216. {
  217. const Quaternion& rotation = node->GetRotation();
  218. *x = rotation.x_;
  219. *y = rotation.y_;
  220. *z = rotation.z_;
  221. }
  222. static void NodeGetRotationWXYZ(const Node* node, float* w, float* x, float* y, float* z)
  223. {
  224. const Quaternion& rotation = node->GetRotation();
  225. *w = rotation.w_;
  226. *x = rotation.x_;
  227. *y = rotation.y_;
  228. *z = rotation.z_;
  229. }
  230. static void NodeGetDirectionXYZ(const Node* node, float* x, float* y, float* z)
  231. {
  232. const Vector3& direction = node->GetDirection();
  233. *x = direction.x_;
  234. *y = direction.y_;
  235. *z = direction.z_;
  236. }
  237. static void NodeGetScaleXYZ(const Node* node, float* x, float* y, float* z)
  238. {
  239. const Vector3& scale = node->GetScale();
  240. *x = scale.x_;
  241. *y = scale.y_;
  242. *z = scale.z_;
  243. }
  244. static void NodeGetWorldPositionXYZ(const Node* node, float* x, float* y, float* z)
  245. {
  246. Vector3 worldPosition = node->GetWorldPosition();
  247. *x = worldPosition.x_;
  248. *y = worldPosition.y_;
  249. *z = worldPosition.z_;
  250. }
  251. static void NodeGetWorldRotationXYZ(const Node* node, float* x, float* y, float* z)
  252. {
  253. Quaternion worldRotation = node->GetWorldRotation();
  254. *x = worldRotation.x_;
  255. *y = worldRotation.y_;
  256. *z = worldRotation.z_;
  257. }
  258. static void NodeGetWorldRotationWXYZ(const Node* node, float* w, float* x, float* y, float* z)
  259. {
  260. Quaternion worldRotation = node->GetWorldRotation();
  261. *w = worldRotation.w_;
  262. *x = worldRotation.x_;
  263. *y = worldRotation.y_;
  264. *z = worldRotation.z_;
  265. }
  266. static void NodeGetWorldDirectionXYZ(const Node* node, float* x, float* y, float* z)
  267. {
  268. Vector3 worldDirection = node->GetWorldDirection();
  269. *x = worldDirection.x_;
  270. *y = worldDirection.y_;
  271. *z = worldDirection.z_;
  272. }
  273. static void NodeGetWorldScaleXYZ(const Node* node, float* x, float* y, float* z)
  274. {
  275. Vector3 worldScale = node->GetWorldScale();
  276. *x = worldScale.x_;
  277. *y = worldScale.y_;
  278. *z = worldScale.z_;
  279. }
  280. // Disable generated CreateComponent function.
  281. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateComponent00
  282. static int tolua_SceneLuaAPI_Node_CreateComponent00(lua_State* tolua_S)
  283. {
  284. #ifndef TOLUA_RELEASE
  285. tolua_Error tolua_err;
  286. if (
  287. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  288. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  289. !tolua_isnumber(tolua_S,3,1,&tolua_err) ||
  290. !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
  291. !tolua_isnoobj(tolua_S,5,&tolua_err)
  292. )
  293. goto tolua_lerror;
  294. else
  295. #endif
  296. {
  297. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  298. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  299. CreateMode mode = ((CreateMode) (int) tolua_tonumber(tolua_S,3,REPLICATED));
  300. unsigned id = ((unsigned) tolua_tonumber(tolua_S,4,0));
  301. #ifndef TOLUA_RELEASE
  302. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateComponent'", NULL);
  303. #endif
  304. {
  305. Component* tolua_ret = (Component*) self->CreateComponent(type,mode,id);
  306. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  307. }
  308. }
  309. return 1;
  310. #ifndef TOLUA_RELEASE
  311. tolua_lerror:
  312. tolua_error(tolua_S,"#ferror in function 'CreateComponent'.",&tolua_err);
  313. return 0;
  314. #endif
  315. }
  316. // Disable generated GetComponent function.
  317. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetComponent00
  318. static int tolua_SceneLuaAPI_Node_GetComponent00(lua_State* tolua_S)
  319. {
  320. #ifndef TOLUA_RELEASE
  321. tolua_Error tolua_err;
  322. if (
  323. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  324. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  325. !tolua_isnoobj(tolua_S,3,&tolua_err)
  326. )
  327. goto tolua_lerror;
  328. else
  329. #endif
  330. {
  331. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  332. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  333. #ifndef TOLUA_RELEASE
  334. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetComponent'", NULL);
  335. #endif
  336. {
  337. Component* tolua_ret = (Component*) self->GetComponent(type);
  338. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  339. }
  340. }
  341. return 1;
  342. #ifndef TOLUA_RELEASE
  343. tolua_lerror:
  344. tolua_error(tolua_S,"#ferror in function 'GetComponent'.",&tolua_err);
  345. return 0;
  346. #endif
  347. }
  348. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject00
  349. static int tolua_SceneLuaAPI_Node_CreateScriptObject00(lua_State* tolua_S)
  350. {
  351. #ifndef TOLUA_RELEASE
  352. tolua_Error tolua_err;
  353. if (
  354. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  355. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  356. !tolua_isnoobj(tolua_S,3,&tolua_err)
  357. )
  358. goto tolua_lerror;
  359. else
  360. #endif
  361. {
  362. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  363. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  364. #ifndef TOLUA_RELEASE
  365. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL);
  366. #endif
  367. {
  368. LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
  369. if (!instance)
  370. lua_pushnil(tolua_S);
  371. else
  372. {
  373. instance->CreateObject(scriptObjectType);
  374. // Push script object to Lua stack.
  375. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  376. }
  377. }
  378. }
  379. return 1;
  380. #ifndef TOLUA_RELEASE
  381. tolua_lerror:
  382. tolua_error(tolua_S,"#ferror in function 'CreateScriptObject'.",&tolua_err);
  383. return 0;
  384. #endif
  385. }
  386. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject01
  387. static int tolua_SceneLuaAPI_Node_CreateScriptObject01(lua_State* tolua_S)
  388. {
  389. tolua_Error tolua_err;
  390. if (
  391. !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
  392. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  393. !tolua_isurho3dstring(tolua_S,3,0,&tolua_err) ||
  394. !tolua_isnoobj(tolua_S,4,&tolua_err)
  395. )
  396. goto tolua_lerror;
  397. else
  398. {
  399. Node* self = (Node*) tolua_tousertype(tolua_S,1,0);
  400. const String fileName = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  401. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,3,0));
  402. #ifndef TOLUA_RELEASE
  403. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NodeCreateScriptObject'", NULL);
  404. #endif
  405. {
  406. LuaScriptInstance* instance = self->CreateComponent<LuaScriptInstance>();
  407. if (!instance)
  408. lua_pushnil(tolua_S);
  409. else
  410. {
  411. instance->CreateObject(fileName, scriptObjectType);
  412. // Push script object to Lua stack.
  413. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  414. }
  415. }
  416. }
  417. return 1;
  418. tolua_lerror:
  419. return tolua_SceneLuaAPI_Node_CreateScriptObject00(tolua_S);
  420. }
  421. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject00
  422. static int tolua_SceneLuaAPI_Node_GetScriptObject00(lua_State* tolua_S)
  423. {
  424. #ifndef TOLUA_RELEASE
  425. tolua_Error tolua_err;
  426. if (
  427. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  428. !tolua_isnoobj(tolua_S,2,&tolua_err)
  429. )
  430. goto tolua_lerror;
  431. else
  432. #endif
  433. {
  434. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  435. #ifndef TOLUA_RELEASE
  436. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL);
  437. #endif
  438. {
  439. LuaScriptInstance* instance = self->GetComponent<LuaScriptInstance>();
  440. if (!instance)
  441. lua_pushnil(tolua_S);
  442. else
  443. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, instance->GetScriptObjectRef());
  444. }
  445. }
  446. return 1;
  447. #ifndef TOLUA_RELEASE
  448. tolua_lerror:
  449. tolua_error(tolua_S,"#ferror in function 'GetScriptObject'.",&tolua_err);
  450. return 0;
  451. #endif
  452. }
  453. #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetScriptObject01
  454. static int tolua_SceneLuaAPI_Node_GetScriptObject01(lua_State* tolua_S)
  455. {
  456. tolua_Error tolua_err;
  457. if (
  458. !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
  459. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  460. !tolua_isnoobj(tolua_S,3,&tolua_err)
  461. )
  462. goto tolua_lerror;
  463. else
  464. {
  465. const Node* self = (const Node*) tolua_tousertype(tolua_S,1,0);
  466. const String scriptObjectType = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  467. #ifndef TOLUA_RELEASE
  468. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetScriptObject'", NULL);
  469. #endif
  470. {
  471. int scriptObjectRef = LUA_REFNIL;
  472. PODVector<LuaScriptInstance*> instances;
  473. self->GetComponents<LuaScriptInstance>(instances, false);
  474. for (unsigned i = 0; i < instances.Size(); ++i)
  475. {
  476. if (instances[i]->GetScriptObjectType() == scriptObjectType)
  477. {
  478. scriptObjectRef = instances[i]->GetScriptObjectRef();
  479. break;
  480. }
  481. }
  482. if (scriptObjectRef == LUA_REFNIL)
  483. lua_pushnil(tolua_S);
  484. else
  485. lua_rawgeti(tolua_S, LUA_REGISTRYINDEX, scriptObjectRef);
  486. }
  487. }
  488. return 1;
  489. tolua_lerror:
  490. return tolua_SceneLuaAPI_Node_GetScriptObject00(tolua_S);
  491. }
  492. $}