Browse Source

AS Bindings: Use templates for default factories glue (#2787)

1vanK 4 years ago
parent
commit
fff115a0c0

+ 5 - 0
Source/Tools/BindingGenerator/ASClassBinder.cpp

@@ -264,6 +264,11 @@ static void RegisterRefCountedConstructor(const MethodAnalyzer& methodAnalyzer,
 
     string args = ExtractCleanedFunctionArgsstring(methodAnalyzer.GetMemberdef());
 
+    bool isDefaultConstructor = args.empty();
+
+    if (isDefaultConstructor)
+        return;
+
     //shared_ptr<ASGeneratedFile_Members> result = GetGeneratedFile(functionAnalyzer.GetClass().GetClassName());
     ASGeneratedFile_Base* result = templateVersion ? (ASGeneratedFile_Base*)_result_Templates.get() : (ASGeneratedFile_Base*)GetGeneratedFile(methodAnalyzer.GetClass().GetClassName()).get();
 

+ 13 - 16
Source/Tools/BindingGenerator/ASClassBinderNew.cpp

@@ -140,15 +140,13 @@ static void RegisterConstructor(const MethodAnalyzer& methodAnalyzer, ProcessedC
     if (params.empty()) // Default constructor
     {
         if (classAnalyzer.IsRefCounted() || Contains(classAnalyzer.GetComment(), "FAKE_REF"))
-        {
-        }
+            result.registration_ = "engine->RegisterObjectBehaviour(\"" + asClassName + "\", asBEHAVE_FACTORY, \"" + asClassName + "@+ f()\", asFUNCTION(ASCompatibleFactory<" + cppClassName + ">), AS_CALL_CDECL);";
         else
-        {
-            result.comment_ = methodAnalyzer.GetLocation(); // Rewrite comment
             result.registration_ = "engine->RegisterObjectBehaviour(\"" + asClassName + "\", asBEHAVE_CONSTRUCT, \"void f()\", asFUNCTION(ASCompatibleConstructor<" + cppClassName + ">), AS_CALL_CDECL_OBJFIRST);";
-            processedClass.defaultConstructor_ = make_shared<MemberRegistration>(result);
-            return;
-        }
+
+        result.comment_ = methodAnalyzer.GetLocation(); // Rewrite comment
+        processedClass.defaultConstructor_ = make_shared<MemberRegistration>(result);
+        return;
     }
 }
 
@@ -252,18 +250,17 @@ static void ProcessClass(const ClassAnalyzer& classAnalyzer)
 
     if (!classAnalyzer.HasThisConstructor() && IsConstructorRequired(classAnalyzer))
     {
+        shared_ptr<MemberRegistration> result = make_shared<MemberRegistration>();
+        string cppClassName = classAnalyzer.GetClassName();
+        string asClassName = classAnalyzer.GetClassName();
+
         if (classAnalyzer.IsRefCounted() || Contains(classAnalyzer.GetComment(), "FAKE_REF"))
-        {
-        }
+            result->registration_ = "engine->RegisterObjectBehaviour(\"" + asClassName + "\", asBEHAVE_FACTORY, \"" + asClassName + "@+ f()\", asFUNCTION(ASCompatibleFactory<" + cppClassName + ">), AS_CALL_CDECL);";
         else
-        {
-            shared_ptr<MemberRegistration> result = make_shared<MemberRegistration>();
-            string cppClassName = classAnalyzer.GetClassName();
-            string asClassName = classAnalyzer.GetClassName();
-            result->comment_ = cppClassName + "::" + cppClassName + "() | Implicitly-declared";
             result->registration_ = "engine->RegisterObjectBehaviour(\"" + asClassName + "\", asBEHAVE_CONSTRUCT, \"void f()\", asFUNCTION(ASCompatibleConstructor<" + cppClassName + ">), AS_CALL_CDECL_OBJFIRST);";
-            processedClass.defaultConstructor_ = result;
-        }
+
+        result->comment_ = cppClassName + "::" + cppClassName + "() | Implicitly-declared";
+        processedClass.defaultConstructor_ = result;
     }
 
     RegisterDestructor(classAnalyzer, processedClass);

+ 85 - 2
Source/Tools/BindingGenerator/ASTemplateGenerator.cpp

@@ -51,7 +51,7 @@ void WriteConstructors(ofstream& ofs)
             ">\n"
             "void ASCompatibleConstructor(asIScriptGeneric* gen)\n"
             "{\n"
-            "    new (gen->GetObject()) C(";
+            "    new (gen->GetObject()) C("; // Placement new
 
         for (int paramIndex = 0; paramIndex < numParams; paramIndex++)
         {
@@ -88,7 +88,89 @@ void WriteConstructors(ofstream& ofs)
         ofs <<
             ")\n"
             "{\n"
-            "    new (ptr) C(";
+            "    new (ptr) C("; // Placement new
+
+        for (int paramIndex = 0; paramIndex < numParams; paramIndex++)
+        {
+            if (paramIndex != 0)
+                ofs << ", ";
+
+            ofs << "p" << paramIndex;
+        }
+
+        ofs <<
+            ");\n"
+            "}\n"
+            "\n";
+    }
+
+    ofs <<
+        "#endif\n"
+        "\n";
+}
+
+void WriteFactories(ofstream& ofs)
+{
+    ofs <<
+        "// Factories that don't require parameter conversion between C++ and AngelScript\n"
+        "\n"
+        "#ifdef AS_MAX_PORTABILITY\n"
+        "\n";
+
+    for (int numParams = 0; numParams <= MAX_PARAMS; numParams++)
+    {
+        ofs << "template <class C";
+
+        for (int paramIndex = 0; paramIndex < numParams; paramIndex++)
+            ofs << ", typename P" << paramIndex;
+
+        ofs <<
+            ">\n"
+            "void ASCompatibleFactory(asIScriptGeneric* gen)\n"
+            "{\n"
+            "    gen->SetReturnAddress(new C(";
+
+        for (int paramIndex = 0; paramIndex < numParams; paramIndex++)
+        {
+            if (paramIndex != 0)
+                ofs << ",\n                                ";
+
+            ofs << "*reinterpret_cast<P" << paramIndex << "*>(gen->GetAddressOfArg(" << paramIndex << "))";
+        }
+
+        ofs <<
+            "));\n"
+            "}\n"
+            "\n";
+    }
+
+    ofs <<
+        "#else\n"
+        "\n";
+
+    for (int numParams = 0; numParams <= MAX_PARAMS; numParams++)
+    {
+        ofs << "template <class C";
+
+        for (int paramIndex = 0; paramIndex < numParams; paramIndex++)
+            ofs << ", typename P" << paramIndex;
+
+        ofs <<
+            ">\n"
+            "C* ASCompatibleFactory(";
+
+        for (int paramIndex = 0; paramIndex < numParams; paramIndex++)
+        {
+            if (paramIndex != 0)
+                ofs << ", ";
+
+            ofs << "P" << paramIndex << " p" << paramIndex;
+        }
+
+        ofs <<
+            ")\n"
+            "{\n"
+            "    return new C(";
 
         for (int paramIndex = 0; paramIndex < numParams; paramIndex++)
         {
@@ -127,6 +209,7 @@ void GenerateTemplates(const string& outputBasePath)
         "\n";
  
     WriteConstructors(ofs);
+    WriteFactories(ofs);
 
     ofs << "} // namespace Urho3D\n";
 }

+ 42 - 0
Source/Urho3D/AngelScript/GeneratedDefaultConstructors.cpp

@@ -18,12 +18,18 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // AllocatorNode::AllocatorNode() | Implicitly-declared
     engine->RegisterObjectBehaviour("AllocatorNode", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<AllocatorNode>), AS_CALL_CDECL_OBJFIRST);
 
+    // AnimationControl::AnimationControl() | File: ../Graphics/AnimationController.h
+    engine->RegisterObjectBehaviour("AnimationControl", asBEHAVE_FACTORY, "AnimationControl@+ f()", asFUNCTION(ASCompatibleFactory<AnimationControl>), AS_CALL_CDECL);
+
     // AnimationKeyFrame::AnimationKeyFrame() | File: ../Graphics/Animation.h
     engine->RegisterObjectBehaviour("AnimationKeyFrame", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<AnimationKeyFrame>), AS_CALL_CDECL_OBJFIRST);
 
     // AnimationStateTrack::AnimationStateTrack() | File: ../Graphics/AnimationState.h
     engine->RegisterObjectBehaviour("AnimationStateTrack", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<AnimationStateTrack>), AS_CALL_CDECL_OBJFIRST);
 
+    // AnimationTrack::AnimationTrack() | File: ../Graphics/Animation.h
+    engine->RegisterObjectBehaviour("AnimationTrack", asBEHAVE_FACTORY, "AnimationTrack@+ f()", asFUNCTION(ASCompatibleFactory<AnimationTrack>), AS_CALL_CDECL);
+
     // AnimationTriggerPoint::AnimationTriggerPoint() | File: ../Graphics/Animation.h
     engine->RegisterObjectBehaviour("AnimationTriggerPoint", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<AnimationTriggerPoint>), AS_CALL_CDECL_OBJFIRST);
 
@@ -54,9 +60,15 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // BiasParameters::BiasParameters()=default | File: ../Graphics/Light.h
     engine->RegisterObjectBehaviour("BiasParameters", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<BiasParameters>), AS_CALL_CDECL_OBJFIRST);
 
+    // Bone::Bone() | File: ../Graphics/Skeleton.h
+    engine->RegisterObjectBehaviour("Bone", asBEHAVE_FACTORY, "Bone@+ f()", asFUNCTION(ASCompatibleFactory<Bone>), AS_CALL_CDECL);
+
     // BoundingBox::BoundingBox() noexcept | File: ../Math/BoundingBox.h
     engine->RegisterObjectBehaviour("BoundingBox", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<BoundingBox>), AS_CALL_CDECL_OBJFIRST);
 
+    // BufferedSoundStream::BufferedSoundStream() | File: ../Audio/BufferedSoundStream.h
+    engine->RegisterObjectBehaviour("BufferedSoundStream", asBEHAVE_FACTORY, "BufferedSoundStream@+ f()", asFUNCTION(ASCompatibleFactory<BufferedSoundStream>), AS_CALL_CDECL);
+
     // CascadeParameters::CascadeParameters()=default | File: ../Graphics/Light.h
     engine->RegisterObjectBehaviour("CascadeParameters", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<CascadeParameters>), AS_CALL_CDECL_OBJFIRST);
 
@@ -66,6 +78,9 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // Color::Color() noexcept | File: ../Math/Color.h
     engine->RegisterObjectBehaviour("Color", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<Color>), AS_CALL_CDECL_OBJFIRST);
 
+    // ColorFrame::ColorFrame() | File: ../Graphics/ParticleEffect.h
+    engine->RegisterObjectBehaviour("ColorFrame", asBEHAVE_FACTORY, "ColorFrame@+ f()", asFUNCTION(ASCompatibleFactory<ColorFrame>), AS_CALL_CDECL);
+
     // ComponentReplicationState::ComponentReplicationState() | Implicitly-declared
     engine->RegisterObjectBehaviour("ComponentReplicationState", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<ComponentReplicationState>), AS_CALL_CDECL_OBJFIRST);
 
@@ -75,6 +90,9 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // Condition::Condition() | File: ../Core/Condition.h
     engine->RegisterObjectBehaviour("Condition", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<Condition>), AS_CALL_CDECL_OBJFIRST);
 
+    // Context::Context() | File: ../Core/Context.h
+    engine->RegisterObjectBehaviour("Context", asBEHAVE_FACTORY, "Context@+ f()", asFUNCTION(ASCompatibleFactory<Context>), AS_CALL_CDECL);
+
     // Controls::Controls() | File: ../Input/Controls.h
     engine->RegisterObjectBehaviour("Controls", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<Controls>), AS_CALL_CDECL_OBJFIRST);
 
@@ -96,6 +114,9 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // DirtyBits::DirtyBits()=default | File: ../Scene/ReplicationState.h
     engine->RegisterObjectBehaviour("DirtyBits", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<DirtyBits>), AS_CALL_CDECL_OBJFIRST);
 
+    // EventReceiverGroup::EventReceiverGroup() | File: ../Core/Context.h
+    engine->RegisterObjectBehaviour("EventReceiverGroup", asBEHAVE_FACTORY, "EventReceiverGroup@+ f()", asFUNCTION(ASCompatibleFactory<EventReceiverGroup>), AS_CALL_CDECL);
+
     // FileSelectorEntry::FileSelectorEntry() | Implicitly-declared
     engine->RegisterObjectBehaviour("FileSelectorEntry", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<FileSelectorEntry>), AS_CALL_CDECL_OBJFIRST);
 
@@ -228,6 +249,12 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // RefCount::RefCount() | File: ../Container/RefCounted.h
     engine->RegisterObjectBehaviour("RefCount", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<RefCount>), AS_CALL_CDECL_OBJFIRST);
 
+    // RefCounted::RefCounted() | File: ../Container/RefCounted.h
+    engine->RegisterObjectBehaviour("RefCounted", asBEHAVE_FACTORY, "RefCounted@+ f()", asFUNCTION(ASCompatibleFactory<RefCounted>), AS_CALL_CDECL);
+
+    // RenderPath::RenderPath() | File: ../Graphics/RenderPath.h
+    engine->RegisterObjectBehaviour("RenderPath", asBEHAVE_FACTORY, "RenderPath@+ f()", asFUNCTION(ASCompatibleFactory<RenderPath>), AS_CALL_CDECL);
+
     // RenderPathCommand::RenderPathCommand() | Implicitly-declared
     engine->RegisterObjectBehaviour("RenderPathCommand", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<RenderPathCommand>), AS_CALL_CDECL_OBJFIRST);
 
@@ -267,6 +294,9 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // ShadowBatchQueue::ShadowBatchQueue() | Implicitly-declared
     engine->RegisterObjectBehaviour("ShadowBatchQueue", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<ShadowBatchQueue>), AS_CALL_CDECL_OBJFIRST);
 
+    // Skeleton::Skeleton() | File: ../Graphics/Skeleton.h
+    engine->RegisterObjectBehaviour("Skeleton", asBEHAVE_FACTORY, "Skeleton@+ f()", asFUNCTION(ASCompatibleFactory<Skeleton>), AS_CALL_CDECL);
+
     // SourceBatch::SourceBatch() | File: ../Graphics/Drawable.h
     engine->RegisterObjectBehaviour("SourceBatch", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<SourceBatch>), AS_CALL_CDECL_OBJFIRST);
 
@@ -291,6 +321,9 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // TechniqueEntry::TechniqueEntry() noexcept | File: ../Graphics/Material.h
     engine->RegisterObjectBehaviour("TechniqueEntry", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<TechniqueEntry>), AS_CALL_CDECL_OBJFIRST);
 
+    // TextureFrame::TextureFrame() | File: ../Graphics/ParticleEffect.h
+    engine->RegisterObjectBehaviour("TextureFrame", asBEHAVE_FACTORY, "TextureFrame@+ f()", asFUNCTION(ASCompatibleFactory<TextureFrame>), AS_CALL_CDECL);
+
     // Timer::Timer() | File: ../Core/Timer.h
     engine->RegisterObjectBehaviour("Timer", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<Timer>), AS_CALL_CDECL_OBJFIRST);
 
@@ -397,9 +430,18 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // PhysicsRaycastResult2D::PhysicsRaycastResult2D() | Implicitly-declared
     engine->RegisterObjectBehaviour("PhysicsRaycastResult2D", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<PhysicsRaycastResult2D>), AS_CALL_CDECL_OBJFIRST);
 
+    // PropertySet2D::PropertySet2D() | File: ../Urho2D/TileMapDefs2D.h
+    engine->RegisterObjectBehaviour("PropertySet2D", asBEHAVE_FACTORY, "PropertySet2D@+ f()", asFUNCTION(ASCompatibleFactory<PropertySet2D>), AS_CALL_CDECL);
+
     // SourceBatch2D::SourceBatch2D() | File: ../Urho2D/Drawable2D.h
     engine->RegisterObjectBehaviour("SourceBatch2D", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<SourceBatch2D>), AS_CALL_CDECL_OBJFIRST);
 
+    // Tile2D::Tile2D() | File: ../Urho2D/TileMapDefs2D.h
+    engine->RegisterObjectBehaviour("Tile2D", asBEHAVE_FACTORY, "Tile2D@+ f()", asFUNCTION(ASCompatibleFactory<Tile2D>), AS_CALL_CDECL);
+
+    // TileMapObject2D::TileMapObject2D() | File: ../Urho2D/TileMapDefs2D.h
+    engine->RegisterObjectBehaviour("TileMapObject2D", asBEHAVE_FACTORY, "TileMapObject2D@+ f()", asFUNCTION(ASCompatibleFactory<TileMapObject2D>), AS_CALL_CDECL);
+
     // Vertex2D::Vertex2D() | Implicitly-declared
     engine->RegisterObjectBehaviour("Vertex2D", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<Vertex2D>), AS_CALL_CDECL_OBJFIRST);
 #endif

+ 0 - 16
Source/Urho3D/AngelScript/Generated_Members_A.cpp

@@ -216,18 +216,6 @@ static void Audio_UnsubscribeFromAllEventsExcept_PODVectorStringHash_bool(Audio*
     ptr->UnsubscribeFromAllEventsExcept(exceptions, onlyUserData);
 }
 
-// AnimationControl::AnimationControl() | File: ../Graphics/AnimationController.h
-static AnimationControl* AnimationControl_AnimationControl_void()
-{
-    return new AnimationControl();
-}
-
-// AnimationTrack::AnimationTrack() | File: ../Graphics/Animation.h
-static AnimationTrack* AnimationTrack_AnimationTrack_void()
-{
-    return new AnimationTrack();
-}
-
 void ASRegisterGenerated_Members_A(asIScriptEngine* engine)
 {
     // virtual unsigned Deserializer::GetChecksum() | File: ../IO/Deserializer.h
@@ -2951,8 +2939,6 @@ void ASRegisterGenerated_Members_A(asIScriptEngine* engine)
     engine->RegisterObjectProperty("AnimationControl", "float speed", offsetof(AnimationControl, speed_));
     // float AnimationControl::targetWeight_ | File: ../Graphics/AnimationController.h
     engine->RegisterObjectProperty("AnimationControl", "float targetWeight", offsetof(AnimationControl, targetWeight_));
-    // AnimationControl::AnimationControl() | File: ../Graphics/AnimationController.h
-    engine->RegisterObjectBehaviour("AnimationControl", asBEHAVE_FACTORY, "AnimationControl@+ f()", AS_FUNCTION(AnimationControl_AnimationControl_void), AS_CALL_CDECL);
     // AnimationControl& AnimationControl::operator=(const AnimationControl&) | Possible implicitly-declared
     RegisterImplicitlyDeclaredAssignOperatorIfPossible<AnimationControl>(engine, "AnimationControl");
     engine->RegisterObjectBehaviour("AnimationControl", asBEHAVE_ADDREF, "void f()", AS_FUNCTION_OBJLAST(FakeAddRef), AS_CALL_CDECL_OBJLAST);
@@ -3001,8 +2987,6 @@ void ASRegisterGenerated_Members_A(asIScriptEngine* engine)
     engine->RegisterObjectProperty("AnimationTrack", "StringHash nameHash", offsetof(AnimationTrack, nameHash_));
     // void AnimationTrack::AddKeyFrame(const AnimationKeyFrame& keyFrame) | File: ../Graphics/Animation.h
     engine->RegisterObjectMethod("AnimationTrack", "void AddKeyFrame(const AnimationKeyFrame&in)", AS_METHODPR(AnimationTrack, AddKeyFrame, (const AnimationKeyFrame&), void), AS_CALL_THISCALL);
-    // AnimationTrack::AnimationTrack() | File: ../Graphics/Animation.h
-    engine->RegisterObjectBehaviour("AnimationTrack", asBEHAVE_FACTORY, "AnimationTrack@+ f()", AS_FUNCTION(AnimationTrack_AnimationTrack_void), AS_CALL_CDECL);
     // AnimationKeyFrame* AnimationTrack::GetKeyFrame(unsigned index) | File: ../Graphics/Animation.h
     // Error: type "AnimationKeyFrame*" can not automatically bind
     // bool AnimationTrack::GetKeyFrameIndex(float time, unsigned& index) const | File: ../Graphics/Animation.h

+ 0 - 16
Source/Urho3D/AngelScript/Generated_Members_B.cpp

@@ -136,12 +136,6 @@ static void BoundingBox_BoundingBox_Sphere(BoundingBox* ptr, const Sphere &spher
     new(ptr) BoundingBox(sphere);
 }
 
-// BufferedSoundStream::BufferedSoundStream() | File: ../Audio/BufferedSoundStream.h
-static BufferedSoundStream* BufferedSoundStream_BufferedSoundStream_void()
-{
-    return new BufferedSoundStream();
-}
-
 // void UIElement::AddTags(const StringVector& tags) | File: ../UI/UIElement.h
 static void Button_AddTags_StringVector(Button* ptr, CScriptArray* tags_conv)
 {
@@ -221,12 +215,6 @@ static void BiasParameters_BiasParameters_float_float_float(BiasParameters* ptr,
     new(ptr) BiasParameters(constantBias, slopeScaledBias, normalOffset);
 }
 
-// Bone::Bone() | File: ../Graphics/Skeleton.h
-static Bone* Bone_Bone_void()
-{
-    return new Bone();
-}
-
 void ASRegisterGenerated_Members_B(asIScriptEngine* engine)
 {
     // void Drawable::AddLight(Light* light) | File: ../Graphics/Drawable.h
@@ -1671,8 +1659,6 @@ void ASRegisterGenerated_Members_B(asIScriptEngine* engine)
     // Error: type "const SharedArrayPtr<signed short>&" can not automatically bind
     // void RefCounted::AddRef() | File: ../Container/RefCounted.h
     engine->RegisterObjectBehaviour("BufferedSoundStream", asBEHAVE_ADDREF, "void f()", AS_METHODPR(BufferedSoundStream, AddRef, (), void), AS_CALL_THISCALL);
-    // BufferedSoundStream::BufferedSoundStream() | File: ../Audio/BufferedSoundStream.h
-    engine->RegisterObjectBehaviour("BufferedSoundStream", asBEHAVE_FACTORY, "BufferedSoundStream@+ f()", AS_FUNCTION(BufferedSoundStream_BufferedSoundStream_void), AS_CALL_CDECL);
     // void BufferedSoundStream::Clear() | File: ../Audio/BufferedSoundStream.h
     engine->RegisterObjectMethod("BufferedSoundStream", "void Clear()", AS_METHODPR(BufferedSoundStream, Clear, (), void), AS_CALL_THISCALL);
     // float BufferedSoundStream::GetBufferLength() const | File: ../Audio/BufferedSoundStream.h
@@ -2845,8 +2831,6 @@ void ASRegisterGenerated_Members_B(asIScriptEngine* engine)
     engine->RegisterObjectProperty("Bone", "uint parentIndex", offsetof(Bone, parentIndex_));
     // float Bone::radius_ | File: ../Graphics/Skeleton.h
     engine->RegisterObjectProperty("Bone", "float radius", offsetof(Bone, radius_));
-    // Bone::Bone() | File: ../Graphics/Skeleton.h
-    engine->RegisterObjectBehaviour("Bone", asBEHAVE_FACTORY, "Bone@+ f()", AS_FUNCTION(Bone_Bone_void), AS_CALL_CDECL);
     // Bone& Bone::operator=(const Bone&) | Possible implicitly-declared
     RegisterImplicitlyDeclaredAssignOperatorIfPossible<Bone>(engine, "Bone");
     engine->RegisterObjectBehaviour("Bone", asBEHAVE_ADDREF, "void f()", AS_FUNCTION_OBJLAST(FakeAddRef), AS_CALL_CDECL_OBJLAST);

+ 0 - 16
Source/Urho3D/AngelScript/Generated_Members_Cn_Cz.cpp

@@ -243,12 +243,6 @@ static void ConstantBuffer_UnsubscribeFromAllEventsExcept_PODVectorStringHash_bo
     ptr->UnsubscribeFromAllEventsExcept(exceptions, onlyUserData);
 }
 
-// Context::Context() | File: ../Core/Context.h
-static Context* Context_Context_void()
-{
-    return new Context();
-}
-
 // SharedPtr<Object> Context::CreateObject(StringHash objectType) | File: ../Core/Context.h
 static Object* Context_CreateObject_StringHash(Context* ptr, StringHash objectType)
 {
@@ -381,12 +375,6 @@ static void CustomGeometry_UnsubscribeFromAllEventsExcept_PODVectorStringHash_bo
     ptr->UnsubscribeFromAllEventsExcept(exceptions, onlyUserData);
 }
 
-// ColorFrame::ColorFrame() | File: ../Graphics/ParticleEffect.h
-static ColorFrame* ColorFrame_ColorFrame_void()
-{
-    return new ColorFrame();
-}
-
 // explicit ColorFrame::ColorFrame(const Color& color) | File: ../Graphics/ParticleEffect.h
 static ColorFrame* ColorFrame_ColorFrame_Color(const Color &color)
 {
@@ -3921,8 +3909,6 @@ void ASRegisterGenerated_Members_Cn_Cz(asIScriptEngine* engine)
 
     // void RefCounted::AddRef() | File: ../Container/RefCounted.h
     engine->RegisterObjectBehaviour("Context", asBEHAVE_ADDREF, "void f()", AS_METHODPR(Context, AddRef, (), void), AS_CALL_THISCALL);
-    // Context::Context() | File: ../Core/Context.h
-    engine->RegisterObjectBehaviour("Context", asBEHAVE_FACTORY, "Context@+ f()", AS_FUNCTION(Context_Context_void), AS_CALL_CDECL);
     // void Context::CopyBaseAttributes(StringHash baseType, StringHash derivedType) | File: ../Core/Context.h
     engine->RegisterObjectMethod("Context", "void CopyBaseAttributes(StringHash, StringHash)", AS_METHODPR(Context, CopyBaseAttributes, (StringHash, StringHash), void), AS_CALL_THISCALL);
     // template<class T, class U> void Context::CopyBaseAttributes() | File: ../Core/Context.h
@@ -6141,8 +6127,6 @@ void ASRegisterGenerated_Members_Cn_Cz(asIScriptEngine* engine)
     engine->RegisterObjectProperty("ColorFrame", "Color color", offsetof(ColorFrame, color_));
     // float ColorFrame::time_ | File: ../Graphics/ParticleEffect.h
     engine->RegisterObjectProperty("ColorFrame", "float time", offsetof(ColorFrame, time_));
-    // ColorFrame::ColorFrame() | File: ../Graphics/ParticleEffect.h
-    engine->RegisterObjectBehaviour("ColorFrame", asBEHAVE_FACTORY, "ColorFrame@+ f()", AS_FUNCTION(ColorFrame_ColorFrame_void), AS_CALL_CDECL);
     // explicit ColorFrame::ColorFrame(const Color& color) | File: ../Graphics/ParticleEffect.h
     engine->RegisterObjectBehaviour("ColorFrame", asBEHAVE_FACTORY, "ColorFrame@+ f(const Color&in)", AS_FUNCTION(ColorFrame_ColorFrame_Color), AS_CALL_CDECL);
     // ColorFrame::ColorFrame(const Color& color, float time) | File: ../Graphics/ParticleEffect.h

+ 0 - 8
Source/Urho3D/AngelScript/Generated_Members_E.cpp

@@ -46,12 +46,6 @@ static void EventProfiler_UnsubscribeFromAllEventsExcept_PODVectorStringHash_boo
     ptr->UnsubscribeFromAllEventsExcept(exceptions, onlyUserData);
 }
 
-// EventReceiverGroup::EventReceiverGroup() | File: ../Core/Context.h
-static EventReceiverGroup* EventReceiverGroup_EventReceiverGroup_void()
-{
-    return new EventReceiverGroup();
-}
-
 void ASRegisterGenerated_Members_E(asIScriptEngine* engine)
 {
     // void RefCounted::AddRef() | File: ../Container/RefCounted.h
@@ -389,8 +383,6 @@ void ASRegisterGenerated_Members_E(asIScriptEngine* engine)
     engine->RegisterObjectMethod("EventReceiverGroup", "void BeginSendEvent()", AS_METHODPR(EventReceiverGroup, BeginSendEvent, (), void), AS_CALL_THISCALL);
     // void EventReceiverGroup::EndSendEvent() | File: ../Core/Context.h
     engine->RegisterObjectMethod("EventReceiverGroup", "void EndSendEvent()", AS_METHODPR(EventReceiverGroup, EndSendEvent, (), void), AS_CALL_THISCALL);
-    // EventReceiverGroup::EventReceiverGroup() | File: ../Core/Context.h
-    engine->RegisterObjectBehaviour("EventReceiverGroup", asBEHAVE_FACTORY, "EventReceiverGroup@+ f()", AS_FUNCTION(EventReceiverGroup_EventReceiverGroup_void), AS_CALL_CDECL);
     // RefCount* RefCounted::RefCountPtr() | File: ../Container/RefCounted.h
     // Error: type "RefCount*" can not automatically bind
     // int RefCounted::Refs() const | File: ../Container/RefCounted.h

+ 0 - 10
Source/Urho3D/AngelScript/Generated_Members_P.cpp

@@ -331,14 +331,6 @@ static void ProgressBar_UnsubscribeFromAllEventsExcept_PODVectorStringHash_bool(
     ptr->UnsubscribeFromAllEventsExcept(exceptions, onlyUserData);
 }
 
-#ifdef URHO3D_URHO2D
-// PropertySet2D::PropertySet2D() | File: ../Urho2D/TileMapDefs2D.h
-static PropertySet2D* PropertySet2D_PropertySet2D_void()
-{
-    return new PropertySet2D();
-}
-#endif
-
 void ASRegisterGenerated_Members_P(asIScriptEngine* engine)
 {
     // void RefCounted::AddRef() | File: ../Container/RefCounted.h
@@ -4231,8 +4223,6 @@ void ASRegisterGenerated_Members_P(asIScriptEngine* engine)
     engine->RegisterObjectMethod("PropertySet2D", "bool HasProperty(const String&in) const", AS_METHODPR(PropertySet2D, HasProperty, (const String&) const, bool), AS_CALL_THISCALL);
     // void PropertySet2D::Load(const XMLElement& element) | File: ../Urho2D/TileMapDefs2D.h
     engine->RegisterObjectMethod("PropertySet2D", "void Load(const XMLElement&in)", AS_METHODPR(PropertySet2D, Load, (const XMLElement&), void), AS_CALL_THISCALL);
-    // PropertySet2D::PropertySet2D() | File: ../Urho2D/TileMapDefs2D.h
-    engine->RegisterObjectBehaviour("PropertySet2D", asBEHAVE_FACTORY, "PropertySet2D@+ f()", AS_FUNCTION(PropertySet2D_PropertySet2D_void), AS_CALL_CDECL);
     // RefCount* RefCounted::RefCountPtr() | File: ../Container/RefCounted.h
     // Error: type "RefCount*" can not automatically bind
     // int RefCounted::Refs() const | File: ../Container/RefCounted.h

+ 0 - 16
Source/Urho3D/AngelScript/Generated_Members_R.cpp

@@ -57,12 +57,6 @@ static void Rect_Rect_Rect(Rect* ptr, const Rect &rect)
     new(ptr) Rect(rect);
 }
 
-// RefCounted::RefCounted() | File: ../Container/RefCounted.h
-static RefCounted* RefCounted_RefCounted_void()
-{
-    return new RefCounted();
-}
-
 // SharedPtr<RenderPath> RenderPath::Clone() | File: ../Graphics/RenderPath.h
 static RenderPath* RenderPath_Clone_void(RenderPath* ptr)
 {
@@ -70,12 +64,6 @@ static RenderPath* RenderPath_Clone_void(RenderPath* ptr)
     return result.Detach();
 }
 
-// RenderPath::RenderPath() | File: ../Graphics/RenderPath.h
-static RenderPath* RenderPath_RenderPath_void()
-{
-    return new RenderPath();
-}
-
 // explicit RenderSurface::RenderSurface(Texture* parentTexture) | File: ../Graphics/RenderSurface.h
 static RenderSurface* RenderSurface_RenderSurface_Texture(Texture *parentTexture)
 {
@@ -868,8 +856,6 @@ void ASRegisterGenerated_Members_R(asIScriptEngine* engine)
 
     // void RefCounted::AddRef() | File: ../Container/RefCounted.h
     engine->RegisterObjectBehaviour("RefCounted", asBEHAVE_ADDREF, "void f()", AS_METHODPR(RefCounted, AddRef, (), void), AS_CALL_THISCALL);
-    // RefCounted::RefCounted() | File: ../Container/RefCounted.h
-    engine->RegisterObjectBehaviour("RefCounted", asBEHAVE_FACTORY, "RefCounted@+ f()", AS_FUNCTION(RefCounted_RefCounted_void), AS_CALL_CDECL);
     // RefCount* RefCounted::RefCountPtr() | File: ../Container/RefCounted.h
     // Error: type "RefCount*" can not automatically bind
     // int RefCounted::Refs() const | File: ../Container/RefCounted.h
@@ -936,8 +922,6 @@ void ASRegisterGenerated_Members_R(asIScriptEngine* engine)
     engine->RegisterObjectMethod("RenderPath", "void RemoveRenderTarget(const String&in)", AS_METHODPR(RenderPath, RemoveRenderTarget, (const String&), void), AS_CALL_THISCALL);
     // void RenderPath::RemoveRenderTargets(const String& tag) | File: ../Graphics/RenderPath.h
     engine->RegisterObjectMethod("RenderPath", "void RemoveRenderTargets(const String&in)", AS_METHODPR(RenderPath, RemoveRenderTargets, (const String&), void), AS_CALL_THISCALL);
-    // RenderPath::RenderPath() | File: ../Graphics/RenderPath.h
-    engine->RegisterObjectBehaviour("RenderPath", asBEHAVE_FACTORY, "RenderPath@+ f()", AS_FUNCTION(RenderPath_RenderPath_void), AS_CALL_CDECL);
     // void RenderPath::SetCommand(unsigned index, const RenderPathCommand& command) | File: ../Graphics/RenderPath.h
     engine->RegisterObjectMethod("RenderPath", "void SetCommand(uint, const RenderPathCommand&in)", AS_METHODPR(RenderPath, SetCommand, (unsigned, const RenderPathCommand&), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod("RenderPath", "void set_commands(uint, const RenderPathCommand&in)", AS_METHODPR(RenderPath, SetCommand, (unsigned, const RenderPathCommand&), void), AS_CALL_THISCALL);

+ 0 - 8
Source/Urho3D/AngelScript/Generated_Members_Sa_Sm.cpp

@@ -270,12 +270,6 @@ static ShaderVariation* ShaderVariation_ShaderVariation_Shader_ShaderType(Shader
     return new ShaderVariation(owner, type);
 }
 
-// Skeleton::Skeleton() | File: ../Graphics/Skeleton.h
-static Skeleton* Skeleton_Skeleton_void()
-{
-    return new Skeleton();
-}
-
 // const PODVector<Light*>& Drawable::GetLights() const | File: ../Graphics/Drawable.h
 static CScriptArray* Skybox_GetLights_void(Skybox* ptr)
 {
@@ -3621,8 +3615,6 @@ void ASRegisterGenerated_Members_Sa_Sm(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Skeleton", "bool Save(Serializer&) const", AS_METHODPR(Skeleton, Save, (Serializer&) const, bool), AS_CALL_THISCALL);
     // void Skeleton::SetRootBoneIndex(unsigned index) | File: ../Graphics/Skeleton.h
     engine->RegisterObjectMethod("Skeleton", "void SetRootBoneIndex(uint)", AS_METHODPR(Skeleton, SetRootBoneIndex, (unsigned), void), AS_CALL_THISCALL);
-    // Skeleton::Skeleton() | File: ../Graphics/Skeleton.h
-    engine->RegisterObjectBehaviour("Skeleton", asBEHAVE_FACTORY, "Skeleton@+ f()", AS_FUNCTION(Skeleton_Skeleton_void), AS_CALL_CDECL);
     // Skeleton& Skeleton::operator=(const Skeleton&) | Possible implicitly-declared
     RegisterImplicitlyDeclaredAssignOperatorIfPossible<Skeleton>(engine, "Skeleton");
     engine->RegisterObjectBehaviour("Skeleton", asBEHAVE_ADDREF, "void f()", AS_FUNCTION_OBJLAST(FakeAddRef), AS_CALL_CDECL_OBJLAST);

+ 0 - 28
Source/Urho3D/AngelScript/Generated_Members_Ta_Tm.cpp

@@ -254,14 +254,6 @@ static void TextureCube_UnsubscribeFromAllEventsExcept_PODVectorStringHash_bool(
     ptr->UnsubscribeFromAllEventsExcept(exceptions, onlyUserData);
 }
 
-#ifdef URHO3D_URHO2D
-// Tile2D::Tile2D() | File: ../Urho2D/TileMapDefs2D.h
-static Tile2D* Tile2D_Tile2D_void()
-{
-    return new Tile2D();
-}
-#endif
-
 #ifdef URHO3D_URHO2D
 // Vector<SharedPtr<TileMapObject2D>> TileMap2D::GetTileCollisionShapes(unsigned gid) const | File: ../Urho2D/TileMap2D.h
 static CScriptArray* TileMap2D_GetTileCollisionShapes_unsigned(TileMap2D* ptr, unsigned gid)
@@ -305,14 +297,6 @@ static void TileMapLayer2D_UnsubscribeFromAllEventsExcept_PODVectorStringHash_bo
 }
 #endif
 
-#ifdef URHO3D_URHO2D
-// TileMapObject2D::TileMapObject2D() | File: ../Urho2D/TileMapDefs2D.h
-static TileMapObject2D* TileMapObject2D_TileMapObject2D_void()
-{
-    return new TileMapObject2D();
-}
-#endif
-
 // explicit Time::Time(Context* context) | File: ../Core/Timer.h
 static Time* Time_Time_Context()
 {
@@ -390,12 +374,6 @@ static void TechniqueEntry_TechniqueEntry_Technique_MaterialQuality_float(Techni
     new(ptr) TechniqueEntry(tech, qualityLevel, lodDistance);
 }
 
-// TextureFrame::TextureFrame() | File: ../Graphics/ParticleEffect.h
-static TextureFrame* TextureFrame_TextureFrame_void()
-{
-    return new TextureFrame();
-}
-
 void ASRegisterGenerated_Members_Ta_Tm(asIScriptEngine* engine)
 {
     // unsigned Technique::alphaPassIndex | File: ../Graphics/Technique.h
@@ -4749,8 +4727,6 @@ void ASRegisterGenerated_Members_Ta_Tm(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Tile2D", "int get_refs() const", AS_METHODPR(Tile2D, Refs, () const, int), AS_CALL_THISCALL);
     // void RefCounted::ReleaseRef() | File: ../Container/RefCounted.h
     engine->RegisterObjectBehaviour("Tile2D", asBEHAVE_RELEASE, "void f()", AS_METHODPR(Tile2D, ReleaseRef, (), void), AS_CALL_THISCALL);
-    // Tile2D::Tile2D() | File: ../Urho2D/TileMapDefs2D.h
-    engine->RegisterObjectBehaviour("Tile2D", asBEHAVE_FACTORY, "Tile2D@+ f()", AS_FUNCTION(Tile2D_Tile2D_void), AS_CALL_CDECL);
     // int RefCounted::WeakRefs() const | File: ../Container/RefCounted.h
     engine->RegisterObjectMethod("Tile2D", "int WeakRefs() const", AS_METHODPR(Tile2D, WeakRefs, () const, int), AS_CALL_THISCALL);
     engine->RegisterObjectMethod("Tile2D", "int get_weakRefs() const", AS_METHODPR(Tile2D, WeakRefs, () const, int), AS_CALL_THISCALL);
@@ -5439,8 +5415,6 @@ void ASRegisterGenerated_Members_Ta_Tm(asIScriptEngine* engine)
     engine->RegisterObjectMethod("TileMapObject2D", "int get_refs() const", AS_METHODPR(TileMapObject2D, Refs, () const, int), AS_CALL_THISCALL);
     // void RefCounted::ReleaseRef() | File: ../Container/RefCounted.h
     engine->RegisterObjectBehaviour("TileMapObject2D", asBEHAVE_RELEASE, "void f()", AS_METHODPR(TileMapObject2D, ReleaseRef, (), void), AS_CALL_THISCALL);
-    // TileMapObject2D::TileMapObject2D() | File: ../Urho2D/TileMapDefs2D.h
-    engine->RegisterObjectBehaviour("TileMapObject2D", asBEHAVE_FACTORY, "TileMapObject2D@+ f()", AS_FUNCTION(TileMapObject2D_TileMapObject2D_void), AS_CALL_CDECL);
     // int RefCounted::WeakRefs() const | File: ../Container/RefCounted.h
     engine->RegisterObjectMethod("TileMapObject2D", "int WeakRefs() const", AS_METHODPR(TileMapObject2D, WeakRefs, () const, int), AS_CALL_THISCALL);
     engine->RegisterObjectMethod("TileMapObject2D", "int get_weakRefs() const", AS_METHODPR(TileMapObject2D, WeakRefs, () const, int), AS_CALL_THISCALL);
@@ -5991,8 +5965,6 @@ void ASRegisterGenerated_Members_Ta_Tm(asIScriptEngine* engine)
     engine->RegisterObjectProperty("TextureFrame", "float time", offsetof(TextureFrame, time_));
     // Rect TextureFrame::uv_ | File: ../Graphics/ParticleEffect.h
     engine->RegisterObjectProperty("TextureFrame", "Rect uv", offsetof(TextureFrame, uv_));
-    // TextureFrame::TextureFrame() | File: ../Graphics/ParticleEffect.h
-    engine->RegisterObjectBehaviour("TextureFrame", asBEHAVE_FACTORY, "TextureFrame@+ f()", AS_FUNCTION(TextureFrame_TextureFrame_void), AS_CALL_CDECL);
     // TextureFrame& TextureFrame::operator=(const TextureFrame&) | Possible implicitly-declared
     RegisterImplicitlyDeclaredAssignOperatorIfPossible<TextureFrame>(engine, "TextureFrame");
     engine->RegisterObjectBehaviour("TextureFrame", asBEHAVE_ADDREF, "void f()", AS_FUNCTION_OBJLAST(FakeAddRef), AS_CALL_CDECL_OBJLAST);

+ 144 - 0
Source/Urho3D/AngelScript/Generated_Templates_New.h

@@ -153,4 +153,148 @@ void ASCompatibleConstructor(C* ptr, P0 p0, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P
 
 #endif
 
+// Factories that don't require parameter conversion between C++ and AngelScript
+
+#ifdef AS_MAX_PORTABILITY
+
+template <class C>
+void ASCompatibleFactory(asIScriptGeneric* gen)
+{
+    gen->SetReturnAddress(new C());
+}
+
+template <class C, typename P0>
+void ASCompatibleFactory(asIScriptGeneric* gen)
+{
+    gen->SetReturnAddress(new C(*reinterpret_cast<P0*>(gen->GetAddressOfArg(0))));
+}
+
+template <class C, typename P0, typename P1>
+void ASCompatibleFactory(asIScriptGeneric* gen)
+{
+    gen->SetReturnAddress(new C(*reinterpret_cast<P0*>(gen->GetAddressOfArg(0)),
+                                *reinterpret_cast<P1*>(gen->GetAddressOfArg(1))));
+}
+
+template <class C, typename P0, typename P1, typename P2>
+void ASCompatibleFactory(asIScriptGeneric* gen)
+{
+    gen->SetReturnAddress(new C(*reinterpret_cast<P0*>(gen->GetAddressOfArg(0)),
+                                *reinterpret_cast<P1*>(gen->GetAddressOfArg(1)),
+                                *reinterpret_cast<P2*>(gen->GetAddressOfArg(2))));
+}
+
+template <class C, typename P0, typename P1, typename P2, typename P3>
+void ASCompatibleFactory(asIScriptGeneric* gen)
+{
+    gen->SetReturnAddress(new C(*reinterpret_cast<P0*>(gen->GetAddressOfArg(0)),
+                                *reinterpret_cast<P1*>(gen->GetAddressOfArg(1)),
+                                *reinterpret_cast<P2*>(gen->GetAddressOfArg(2)),
+                                *reinterpret_cast<P3*>(gen->GetAddressOfArg(3))));
+}
+
+template <class C, typename P0, typename P1, typename P2, typename P3, typename P4>
+void ASCompatibleFactory(asIScriptGeneric* gen)
+{
+    gen->SetReturnAddress(new C(*reinterpret_cast<P0*>(gen->GetAddressOfArg(0)),
+                                *reinterpret_cast<P1*>(gen->GetAddressOfArg(1)),
+                                *reinterpret_cast<P2*>(gen->GetAddressOfArg(2)),
+                                *reinterpret_cast<P3*>(gen->GetAddressOfArg(3)),
+                                *reinterpret_cast<P4*>(gen->GetAddressOfArg(4))));
+}
+
+template <class C, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
+void ASCompatibleFactory(asIScriptGeneric* gen)
+{
+    gen->SetReturnAddress(new C(*reinterpret_cast<P0*>(gen->GetAddressOfArg(0)),
+                                *reinterpret_cast<P1*>(gen->GetAddressOfArg(1)),
+                                *reinterpret_cast<P2*>(gen->GetAddressOfArg(2)),
+                                *reinterpret_cast<P3*>(gen->GetAddressOfArg(3)),
+                                *reinterpret_cast<P4*>(gen->GetAddressOfArg(4)),
+                                *reinterpret_cast<P5*>(gen->GetAddressOfArg(5))));
+}
+
+template <class C, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
+void ASCompatibleFactory(asIScriptGeneric* gen)
+{
+    gen->SetReturnAddress(new C(*reinterpret_cast<P0*>(gen->GetAddressOfArg(0)),
+                                *reinterpret_cast<P1*>(gen->GetAddressOfArg(1)),
+                                *reinterpret_cast<P2*>(gen->GetAddressOfArg(2)),
+                                *reinterpret_cast<P3*>(gen->GetAddressOfArg(3)),
+                                *reinterpret_cast<P4*>(gen->GetAddressOfArg(4)),
+                                *reinterpret_cast<P5*>(gen->GetAddressOfArg(5)),
+                                *reinterpret_cast<P6*>(gen->GetAddressOfArg(6))));
+}
+
+template <class C, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
+void ASCompatibleFactory(asIScriptGeneric* gen)
+{
+    gen->SetReturnAddress(new C(*reinterpret_cast<P0*>(gen->GetAddressOfArg(0)),
+                                *reinterpret_cast<P1*>(gen->GetAddressOfArg(1)),
+                                *reinterpret_cast<P2*>(gen->GetAddressOfArg(2)),
+                                *reinterpret_cast<P3*>(gen->GetAddressOfArg(3)),
+                                *reinterpret_cast<P4*>(gen->GetAddressOfArg(4)),
+                                *reinterpret_cast<P5*>(gen->GetAddressOfArg(5)),
+                                *reinterpret_cast<P6*>(gen->GetAddressOfArg(6)),
+                                *reinterpret_cast<P7*>(gen->GetAddressOfArg(7))));
+}
+
+#else
+
+template <class C>
+C* ASCompatibleFactory()
+{
+    return new C();
+}
+
+template <class C, typename P0>
+C* ASCompatibleFactory(P0 p0)
+{
+    return new C(p0);
+}
+
+template <class C, typename P0, typename P1>
+C* ASCompatibleFactory(P0 p0, P1 p1)
+{
+    return new C(p0, p1);
+}
+
+template <class C, typename P0, typename P1, typename P2>
+C* ASCompatibleFactory(P0 p0, P1 p1, P2 p2)
+{
+    return new C(p0, p1, p2);
+}
+
+template <class C, typename P0, typename P1, typename P2, typename P3>
+C* ASCompatibleFactory(P0 p0, P1 p1, P2 p2, P3 p3)
+{
+    return new C(p0, p1, p2, p3);
+}
+
+template <class C, typename P0, typename P1, typename P2, typename P3, typename P4>
+C* ASCompatibleFactory(P0 p0, P1 p1, P2 p2, P3 p3, P4 p4)
+{
+    return new C(p0, p1, p2, p3, p4);
+}
+
+template <class C, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
+C* ASCompatibleFactory(P0 p0, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
+{
+    return new C(p0, p1, p2, p3, p4, p5);
+}
+
+template <class C, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
+C* ASCompatibleFactory(P0 p0, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
+{
+    return new C(p0, p1, p2, p3, p4, p5, p6);
+}
+
+template <class C, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
+C* ASCompatibleFactory(P0 p0, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
+{
+    return new C(p0, p1, p2, p3, p4, p5, p6, p7);
+}
+
+#endif
+
 } // namespace Urho3D