Node.pkg 21 KB

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