Browse Source

Add type to some template method, lick Node::CreateComponent etc. Add LoadChunk and LoadAndExecute in LuaFile, Add DrawDebugGeometry in Renderer.

Aster Jian 12 years ago
parent
commit
90c29aecfb

+ 43 - 18
Source/Extras/LuaScript/LuaFile.cpp

@@ -23,6 +23,7 @@
 #include "Precompiled.h"
 #include "Context.h"
 #include "Deserializer.h"
+#include "FileSystem.h"
 #include "Log.h"
 #include "LuaFile.h"
 #include "ProcessUtils.h"
@@ -40,9 +41,10 @@ extern "C"
 namespace Urho3D
 {
 
-LuaFile::LuaFile(Context* context) : 
+LuaFile::LuaFile(Context* context) :
     Resource(context),
     size_(0),
+	hasLoaded_(false),
     hasExecuted_(false)
 {
 
@@ -85,30 +87,53 @@ bool LuaFile::Save(Serializer& dest) const
     return true;
 }
 
-bool LuaFile::Execute(lua_State* luaState)
+
+bool LuaFile::LoadChunk(lua_State* luaState)
 {
-    if (hasExecuted_)
-        return true;
+	if (hasLoaded_)
+		return true;
 
-    if (size_ == 0)
-        return false;
+	if (size_ == 0)
+		return false;
 
-    if (!luaState)
-        return false;
+	if (!luaState)
+		return false;
 
-    int top = lua_gettop(luaState);
+	int top = lua_gettop(luaState);
 
-    const char* name = GetName().CString();
-    int error = luaL_loadbuffer(luaState, data_, size_, name);
-    if (error)
-    {
-        const char* message = lua_tostring(luaState, -1);
+	// Get file name without extension.
+	String name = GetName();
+	unsigned extPos = name.FindLast('.');
+	if (extPos != String::NPOS)
+	{
+		name = name.Substring(0, extPos);
+	}
+
+	int error = luaL_loadbuffer(luaState, data_, size_, name.CString());
+	if (error)
+	{
+		const char* message = lua_tostring(luaState, -1);
         LOGERROR("Load Buffer failed for " + GetName() + ": " + String(message));
-        lua_settop(luaState, top);
-        return false;
-    }
+		lua_settop(luaState, top);
+		return false;
+	}
+
+	hasLoaded_ = true;
+
+	return true;
+}
+
+bool LuaFile::LoadAndExecute(lua_State* luaState)
+{
+	if (hasExecuted_)
+		return true;
+
+	if (!LoadChunk(luaState))
+		return false;
+
+	int top = lua_gettop(luaState);
 
-    if (lua_pcall(luaState, 0, 0, 0))
+	if (lua_pcall(luaState, 0, 0, 0))
     {
         const char* message = lua_tostring(luaState, -1);
         LOGERROR("Lua Execute failed for " + GetName() + ": " + String(message));

+ 7 - 2
Source/Extras/LuaScript/LuaFile.h

@@ -48,8 +48,10 @@ public:
     /// Save resource. Return true if successful.
     virtual bool Save(Serializer& dest) const;
 
-    /// Execute.
-    bool Execute(lua_State* luaState);
+    /// Load buffer as Lua chunk.
+    bool LoadChunk(lua_State* luaState);
+    /// Load buffer as lua chunk and execute.
+    bool LoadAndExecute(lua_State* luaState);
 
 private:
     /// File size.
@@ -58,6 +60,9 @@ private:
     /// File data.
     SharedArrayPtr<char> data_;
 
+    /// Has loaded.
+    bool hasLoaded_;
+
     /// Has executed.
     bool hasExecuted_;
 };

+ 11 - 23
Source/Extras/LuaScript/LuaScript.cpp

@@ -119,7 +119,7 @@ bool LuaScript::ExecuteFile(const String& fileName)
     if (!luaFile)
         return false;
 
-    return luaFile->Execute(luaState_);
+    return luaFile->LoadAndExecute(luaState_);
 }
 
 bool LuaScript::ExecuteString(const String& string)
@@ -191,11 +191,11 @@ void LuaScript::ScriptSubscribeToEvent(Object* object, const String& eventName,
 
 void LuaScript::RegisterLoader()
 {
+	// Get package.loaders table.
     lua_getglobal(luaState_, "package");
-
     lua_getfield(luaState_, -1, "loaders");
 
-    // Replace first loader.
+    // Set package.loaders[1] = LuaScript::Loader.
     lua_pushnumber(luaState_, 1);
     lua_pushcfunction(luaState_, &LuaScript::Loader);
     lua_settable(luaState_, -3);
@@ -207,28 +207,16 @@ int LuaScript::Loader(lua_State* L)
     if (!cache)
         return 0;
 
-    const char* name = luaL_checkstring(L, 1);
-    SharedPtr<File> file = cache->GetFile(String(name) + ".lua");
-    if (!file)
-        return 0;
-
-    unsigned size = file->GetSize();
-    char* buffer = new char[size];
-    file->Read(buffer, size);
-
-    int top = lua_gettop(L);
-    int error = luaL_loadbuffer(L, buffer, size, name);
-    delete [] buffer;
+	// Get module name.
+	const char* name = luaL_checkstring(L, 1);
 
-    if (error)
-    {
-        const char* message = lua_tostring(L, -1);
-        LOGERROR("Execute Lua file " + String(name) + " failed: " + String(message));
-        lua_settop(L, top);
-        return 0;
-    }
+	// Get Lua file from module name.
+	LuaFile* luaFile = cache->GetResource<LuaFile>(String(name) + ".lua");
+	if (!luaFile)
+		return false;
 
-    return 1;
+	// Load Lua file to Lua chunk.
+	return luaFile->LoadChunk(L) ? 1 : 0;
 }
 
 void LuaScript::ReplacePrint()

+ 2 - 0
Source/Extras/LuaScript/pkgs/Graphics/Renderer.pkg

@@ -165,6 +165,8 @@ class Renderer
     ShaderVariation* GetStencilPS() const;
     const FrameInfo& GetFrameInfo();
     
+    void DrawDebugGeometry(bool depthTest);
+    
     tolua_property__get_set unsigned numViewports;
     tolua_property__get_set RenderPath* defaultRenderPath;
     tolua_property__get_set bool specularLighting;

+ 71 - 30
Source/Extras/LuaScript/pkgs/Resource/ResourceCache.pkg

@@ -1,14 +1,4 @@
-$#include "Animation.h"
-$#include "Font.h"
-$#include "Image.h"
-$#include "Material.h"
-$#include "Model.h"
 $#include "ResourceCache.h"
-$#include "Sound.h"
-$#include "Technique.h"
-$#include "Texture2D.h"
-$#include "TextureCube.h"
-$#include "XMLFile.h"
 
 class ResourceCache
 {    
@@ -21,28 +11,10 @@ class ResourceCache
     void SetAutoReloadResources(bool enable);
     
     // template <class T> T* GetResource(const String& name);
-    Animation* GetResource<Animation> @ GetAnimation(const String& name);
-    Font* GetResource<Font> @ GetFont(const String& name);
-    Image* GetResource<Image> @ GetImage(const String& name);
-    Material* GetResource<Material> @ GetMaterial(const String& name);
-    Model* GetResource<Model> @ GetModel(const String& name);
-    Sound* GetResource<Sound> @ GetSound(const String& name);
-    Technique* GetResource<Technique> @ GetTechnique(const String& name);
-    Texture2D* GetResource<Texture2D> @ GetTexture2D(const String& name);
-    TextureCube* GetResource<TextureCube> @ GetTextureCube(const String& name);
-    XMLFile* GetResource<XMLFile> @ GetXMLFile(const String& name);
+    Resource* GetResource(const char* type, const String& name);
     
     // template <class T> T* GetResource(const char* name);
-    Animation* GetResource<Animation> @ GetAnimation(const char* name);
-    Font* GetResource<Font> @ GetFont(const char* name);
-    Image* GetResource<Image> @ GetImage(const char* name);
-    Material* GetResource<Material> @ GetMaterial(const char* name);
-    Model* GetResource<Model> @ GetModel(const char* name);
-    Sound* GetResource<Sound> @ GetSound(const char* name);
-    Technique* GetResource<Technique> @ GetTechnique(const char* name);
-    Texture2D* GetResource<Texture2D> @ GetTexture2D(const char* name);
-    TextureCube* GetResource<TextureCube> @ GetTextureCube(const char* name);
-    XMLFile* GetResource<XMLFile> @ GetXMLFile(const char* name);
+    Resource* GetResource(const char* type, const char* name);
     
     bool Exists(const String& name) const;
     bool Exists(StringHash nameHash) const;
@@ -57,3 +29,72 @@ class ResourceCache
     tolua_readonly tolua_property__get_set unsigned totalMemoryUse;
     tolua_readonly tolua_property__get_set bool autoReloadResources;
 };
+
+${
+
+// Disable generated GetResource funciton.
+#define TOLUA_DISABLE_tolua_ResourceLuaAPI_ResourceCache_GetResource00
+#define TOLUA_DISABLE_tolua_ResourceLuaAPI_ResourceCache_GetResource01
+
+static int tolua_ResourceLuaAPI_ResourceCache_GetResource00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+     !tolua_isusertype(tolua_S,1,"ResourceCache",0,&tolua_err) ||
+     !tolua_isstring(tolua_S,2,0,&tolua_err) ||
+     (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"const String",0,&tolua_err)) ||
+     !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+  goto tolua_lerror;
+ else
+#endif
+ {
+  ResourceCache* self = (ResourceCache*)  tolua_tousertype(tolua_S,1,0);
+  const char* type = ((const char*)  tolua_tostring(tolua_S,2,0));
+  const String* name = ((const String*)  tolua_tousertype(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetResource'", NULL);
+#endif
+  {
+   Resource* tolua_ret = (Resource*)  self->GetResource(type,*name);
+    tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
+  }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetResource'.",&tolua_err);
+ return 0;
+#endif
+}
+
+static int tolua_ResourceLuaAPI_ResourceCache_GetResource01(lua_State* tolua_S)
+{
+ tolua_Error tolua_err;
+ if (
+     !tolua_isusertype(tolua_S,1,"ResourceCache",0,&tolua_err) ||
+     !tolua_isstring(tolua_S,2,0,&tolua_err) ||
+     !tolua_isstring(tolua_S,3,0,&tolua_err) ||
+     !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+  goto tolua_lerror;
+ else
+ {
+  ResourceCache* self = (ResourceCache*)  tolua_tousertype(tolua_S,1,0);
+  const char* type = ((const char*)  tolua_tostring(tolua_S,2,0));
+  const char* name = ((const char*)  tolua_tostring(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetResource'", NULL);
+#endif
+  {
+   Resource* tolua_ret = (Resource*)  self->GetResource(type,name);
+    tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
+  }
+ }
+ return 1;
+tolua_lerror:
+ return tolua_ResourceLuaAPI_ResourceCache_GetResource00(tolua_S);
+}
+
+$}

+ 80 - 67
Source/Extras/LuaScript/pkgs/Scene/Node.pkg

@@ -1,26 +1,4 @@
-$#include "AnimationController.h"
-$#include "AnimatedModel.h"
-$#include "Camera.h"
-$#include "CollisionShape.h"
-$#include "Constraint.h"
-$#include "DebugRenderer.h"
-$#include "DecalSet.h"
-$#include "Drawable.h"
-$#include "Light.h"
-$#include "Navigable.h"
-$#include "NavigationMesh.h"
-$#include "NetworkPriority.h"
 $#include "Node.h"
-$#include "Octree.h"
-$#include "OffMeshConnection.h"
-$#include "PhysicsWorld.h"
-$#include "RigidBody.h"
-$#include "SmoothedTransform.h"
-$#include "SoundListener.h"
-$#include "SoundSource.h"
-$#include "StaticModel.h"
-$#include "Terrain.h"
-$#include "Zone.h"
 
 enum CreateMode
 {
@@ -89,29 +67,8 @@ class Node : public Serializable
     void RemoveListener(Component* component);
     
     // template <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
-    AnimationController* CreateComponent<AnimationController> @ CreateAnimationController(CreateMode mode = REPLICATED, unsigned id = 0);
-    AnimatedModel* CreateComponent<AnimatedModel> @ CreateAnimatedModel(CreateMode mode = REPLICATED, unsigned id = 0);
-    Camera* CreateComponent<Camera> @ CreateCamera(CreateMode mode = REPLICATED, unsigned id = 0);
-    CollisionShape* CreateComponent<CollisionShape> @ CreateCollisionShape(CreateMode mode = REPLICATED, unsigned id = 0);
-    Constraint* CreateComponent<Constraint> @ CreateConstraint(CreateMode mode = REPLICATED, unsigned id = 0);
-    DebugRenderer* CreateComponent<DebugRenderer> @ CreateDebugRenderer(CreateMode mode = REPLICATED, unsigned id = 0);
-    DecalSet* CreateComponent<DecalSet> @ CreateDecalSet(CreateMode mode = REPLICATED, unsigned id = 0);
-    Drawable* CreateComponent<Drawable> @ CreateDrawable(CreateMode mode = REPLICATED, unsigned id = 0);
-    Light* CreateComponent<Light> @ CreateLight(CreateMode mode = REPLICATED, unsigned id = 0);
-    Navigable* CreateComponent<Navigable> @ CreateNavigable(CreateMode mode = REPLICATED, unsigned id = 0);
-    NavigationMesh* CreateComponent<NavigationMesh> @ CreateNavigationMesh(CreateMode mode = REPLICATED, unsigned id = 0);
-    NetworkPriority* CreateComponent<NetworkPriority> @ CreateNetworkPriority(CreateMode mode = REPLICATED, unsigned id = 0);
-    Octree* CreateComponent<Octree> @ CreateOctree(CreateMode mode = REPLICATED, unsigned id = 0);
-    OffMeshConnection* CreateComponent<OffMeshConnection> @ CreateOffMeshConnection(CreateMode mode = REPLICATED, unsigned id = 0);
-    PhysicsWorld* CreateComponent<PhysicsWorld> @ CreatePhysicsWorld(CreateMode mode = REPLICATED, unsigned id = 0);
-    RigidBody* CreateComponent<RigidBody> @ CreateRigidBody(CreateMode mode = REPLICATED, unsigned id = 0);
-    SmoothedTransform* CreateComponent<SmoothedTransform> @ CreateSmoothedTransform(CreateMode mode = REPLICATED, unsigned id = 0);
-    SoundListener* CreateComponent<SoundListener> @ CreateSoundListener(CreateMode mode = REPLICATED, unsigned id = 0);
-    SoundSource* CreateComponent<SoundSource> @ CreateSoundSource(CreateMode mode = REPLICATED, unsigned id = 0);
-    StaticModel* CreateComponent<StaticModel> @ CreateStaticModel(CreateMode mode = REPLICATED, unsigned id = 0);
-    Terrain* CreateComponent<Terrain> @ CreateTerrain(CreateMode mode = REPLICATED, unsigned id = 0);
-    Zone* CreateComponent<Zone> @ CreateZone(CreateMode mode = REPLICATED, unsigned id = 0);
-
+    Component* CreateComponent(const char* type, CreateMode mode = REPLICATED, unsigned id = 0);
+    
     unsigned GetID() const;
     const String& GetName() const;
     StringHash GetNameHash() const;
@@ -150,29 +107,9 @@ class Node : public Serializable
     
     const Variant& GetVar(ShortStringHash key) const;
     const VariantMap& GetVars() const;
+    
     // template <class T> T* GetComponent() const;
-    AnimationController* GetComponent<AnimationController> @ GetAnimationController() const;
-    AnimatedModel* GetComponent<AnimatedModel> @ GetAnimatedModel() const;
-    Camera* GetComponent<Camera> @ GetCamera() const;
-    CollisionShape* GetComponent<CollisionShape> @ GetCollisionShape() const;
-    Constraint* GetComponent<Constraint> @ GetConstraint() const;
-    DebugRenderer* GetComponent<DebugRenderer> @ GetDebugRenderer() const;
-    DecalSet* GetComponent<DecalSet> @ GetDecalSet() const;
-    Drawable* GetComponent<Drawable> @ GetDrawable() const;
-    Light* GetComponent<Light> @ GetLight() const;
-    Navigable* GetComponent<Navigable> @ GetNavigable() const;
-    NavigationMesh* GetComponent<NavigationMesh> @ GetNavigationMesh() const;
-    NetworkPriority* GetComponent<NetworkPriority> @ GetNetworkPriority() const;
-    Octree* GetComponent<Octree> @ GetOctree() const;
-    OffMeshConnection* GetComponent<OffMeshConnection> @ GetOffMeshConnection() const;
-    PhysicsWorld* GetComponent<PhysicsWorld> @ GetPhysicsWorld() const;
-    RigidBody* GetComponent<RigidBody> @ GetRigidBody() const;
-    SmoothedTransform* GetComponent<SmoothedTransform> @ GetSmoothedTransform() const;
-    SoundListener* GetComponent<SoundListener> @ GetSoundListener() const;
-    SoundSource* GetComponent<SoundSource> @ GetSoundSource() const;
-    StaticModel* GetComponent<StaticModel> @ GetStaticModel() const;
-    Terrain* GetComponent<Terrain> @ GetTerrain() const;
-    Zone* GetComponent<Zone> @ GetZone() const;
+    Component* GetComponent(const char* type) const;
     
     void SetID(unsigned id);
     void SetScene(Scene* scene);
@@ -205,3 +142,79 @@ class Node : public Serializable
     tolua_readonly tolua_property__get_set unsigned numComponents;
     tolua_readonly tolua_property__get_set unsigned numNetworkComponents;
 };
+
+${
+
+// Disable generated CreateComponent funciton.
+#define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateComponent00
+
+static int tolua_SceneLuaAPI_Node_CreateComponent00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+     !tolua_isusertype(tolua_S,1,"Node",0,&tolua_err) ||
+     !tolua_isstring(tolua_S,2,0,&tolua_err) ||
+     !tolua_isnumber(tolua_S,3,1,&tolua_err) ||
+     !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
+     !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+  goto tolua_lerror;
+ else
+#endif
+ {
+  Node* self = (Node*)  tolua_tousertype(tolua_S,1,0);
+  const char* type = ((const char*)  tolua_tostring(tolua_S,2,0));
+  CreateMode mode = ((CreateMode) (int)  tolua_tonumber(tolua_S,3,REPLICATED));
+  unsigned id = ((unsigned)  tolua_tonumber(tolua_S,4,0));
+#ifndef TOLUA_RELEASE
+  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateComponent'", NULL);
+#endif
+  {
+   Component* tolua_ret = (Component*)  self->CreateComponent(type,mode,id);
+    tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
+  }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'CreateComponent'.",&tolua_err);
+ return 0;
+#endif
+}
+
+// Disable generated GetComponent funciton.
+#define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_GetComponent00
+
+static int tolua_SceneLuaAPI_Node_GetComponent00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+     !tolua_isusertype(tolua_S,1,"const Node",0,&tolua_err) ||
+     !tolua_isstring(tolua_S,2,0,&tolua_err) ||
+     !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+  goto tolua_lerror;
+ else
+#endif
+ {
+  const Node* self = (const Node*)  tolua_tousertype(tolua_S,1,0);
+  const char* type = ((const char*)  tolua_tostring(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetComponent'", NULL);
+#endif
+  {
+   Component* tolua_ret = (Component*)  self->GetComponent(type);
+    tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
+  }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetComponent'.",&tolua_err);
+ return 0;
+#endif
+}
+
+$}

+ 3 - 2
Source/Extras/LuaScript/pkgs/Scene/Scene.pkg

@@ -22,8 +22,9 @@ class Scene : public Node
     void SetSmoothingConstant(float constant);
     void SetSnapThreshold(float threshold);
     
-    Node* GetNode(unsigned id) const;
-    Component* GetComponent(unsigned id) const;
+    // Node* GetNode(unsigned id) const;
+    // Component* GetComponent(unsigned id) const;
+    
     bool IsUpdateEnabled() const;
     bool IsAsyncLoading() const;
     float GetAsyncProgress() const;

+ 99 - 17
Source/Extras/LuaScript/pkgs/UI/UIElement.pkg

@@ -127,7 +127,8 @@ class UIElement : public Serializable
     void BringToFront();
     
     // UIElement* CreateChild(ShortStringHash type, const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
-    // UIElement* CreateChild(const char* type, const char* name = 0, unsigned index = M_MAX_UNSIGNED);
+    UIElement* CreateChild(const char* type, const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
+    UIElement* CreateChild(const char* type, const char* name = 0, unsigned index = M_MAX_UNSIGNED);
     
     void AddChild(UIElement* element);
     void InsertChild(unsigned index, UIElement* element);
@@ -142,22 +143,7 @@ class UIElement : public Serializable
     void SetElementEventSender(bool flag);
 
     // template <class T> T* CreateChild(const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
-    BorderImage* CreateChild<BorderImage> @ CreateBorderImage(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    Button* CreateChild<Button> @ CreateButton(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    CheckBox* CreateChild<CheckBox> @ CreateCheckBox(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    Cursor* CreateChild<Cursor> @ CreateCursor(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    DropDownList* CreateChild<DropDownList> @ CreateDropDownList(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    LineEdit* CreateChild<LineEdit> @ CreateLineEdit(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    ListView* CreateChild<ListView> @ CreateListView(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    Menu* CreateChild<Menu> @ CreateMenu(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    ScrollBar* CreateChild<ScrollBar> @ CreateScrollBar(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    ScrollView* CreateChild<ScrollView> @ CreateScrollView(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    Slider* CreateChild<Slider> @ CreateSlider(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    Sprite* CreateChild<Sprite> @ CreateSprite(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    Text* CreateChild<Text> @ CreateText(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    UIElement* CreateChild<UIElement> @ CreateUIElement(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-    Window* CreateChild<Window> @ CreateWindow(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
-
+    
     const String& GetName() const;
     const IntVector2& GetPosition() const;
     const IntVector2& GetSize() const;
@@ -287,6 +273,102 @@ class UIElement : public Serializable
 
 ${
 
+// Disable generated CreateChild function.
+#define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_CreateChild00
+#define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_CreateChild01
+#define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_CreateChild02
+
+static int tolua_UILuaAPI_UIElement_CreateChild00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+     !tolua_isusertype(tolua_S,1,"UIElement",0,&tolua_err) ||
+     !tolua_isstring(tolua_S,2,0,&tolua_err) ||
+     !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+  goto tolua_lerror;
+ else
+#endif
+ {
+  UIElement* self = (UIElement*)  tolua_tousertype(tolua_S,1,0);
+  const char* type = ((const char*)  tolua_tostring(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateChild'", NULL);
+#endif
+  {
+   UIElement* tolua_ret = (UIElement*)  self->CreateChild(type);
+    tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
+  }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'CreateChild'.",&tolua_err);
+ return 0;
+#endif
+}
+
+static int tolua_UILuaAPI_UIElement_CreateChild01(lua_State* tolua_S)
+{
+ tolua_Error tolua_err;
+ if (
+     !tolua_isusertype(tolua_S,1,"UIElement",0,&tolua_err) ||
+     !tolua_isstring(tolua_S,2,0,&tolua_err) ||
+     (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"const String",0,&tolua_err)) ||
+     !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
+     !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+  goto tolua_lerror;
+ else
+ {
+  UIElement* self = (UIElement*)  tolua_tousertype(tolua_S,1,0);
+  const char* type = ((const char*)  tolua_tostring(tolua_S,2,0));
+  const String* name = ((const String*)  tolua_tousertype(tolua_S,3,0));
+  unsigned index = ((unsigned)  tolua_tonumber(tolua_S,4,M_MAX_UNSIGNED));
+#ifndef TOLUA_RELEASE
+  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateChild'", NULL);
+#endif
+  {
+   UIElement* tolua_ret = (UIElement*)  self->CreateChild(type,*name,index);
+    tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
+  }
+ }
+ return 1;
+tolua_lerror:
+ return tolua_UILuaAPI_UIElement_CreateChild00(tolua_S);
+}
+
+static int tolua_UILuaAPI_UIElement_CreateChild02(lua_State* tolua_S)
+{
+ tolua_Error tolua_err;
+ if (
+     !tolua_isusertype(tolua_S,1,"UIElement",0,&tolua_err) ||
+     !tolua_isstring(tolua_S,2,0,&tolua_err) ||
+     !tolua_isstring(tolua_S,3,1,&tolua_err) ||
+     !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
+     !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+  goto tolua_lerror;
+ else
+ {
+  UIElement* self = (UIElement*)  tolua_tousertype(tolua_S,1,0);
+  const char* type = ((const char*)  tolua_tostring(tolua_S,2,0));
+  const char* name = ((const char*)  tolua_tostring(tolua_S,3,0));
+  unsigned index = ((unsigned)  tolua_tonumber(tolua_S,4,M_MAX_UNSIGNED));
+#ifndef TOLUA_RELEASE
+  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateChild'", NULL);
+#endif
+  {
+   UIElement* tolua_ret = (UIElement*)  self->CreateChild(type,name,index);
+    tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
+  }
+ }
+ return 1;
+tolua_lerror:
+ return tolua_UILuaAPI_UIElement_CreateChild01(tolua_S);
+}
+
 static UIElement* UIElementGetChild(const UIElement* element, const char* name, bool recursive = false)
 {
     return element->GetChild(String(name), recursive);