Browse Source

AS bindings for BigInt | Tests for AS bindings

1vanK 3 years ago
parent
commit
78ecde1a43

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

@@ -301,6 +301,12 @@ static string CppMethodNameToAS(const MethodAnalyzer& methodAnalyzer)
     if (name == "operator>")
     if (name == "operator>")
         throw Exception("Registerd as opCmp separately");
         throw Exception("Registerd as opCmp separately");
 
 
+    if (name == "operator++")
+        throw Exception("TODO");
+
+    if (name == "operator--")
+        throw Exception("TODO");
+
     return name;
     return name;
 }
 }
 
 

+ 58 - 0
Source/Urho3D/AngelScript/Generated_Classes.cpp

@@ -294,6 +294,63 @@ static void Register_BiasParameters(asIScriptEngine* engine)
     RegisterImplicitlyDeclaredAssignOperatorIfPossible<BiasParameters>(engine, "BiasParameters");
     RegisterImplicitlyDeclaredAssignOperatorIfPossible<BiasParameters>(engine, "BiasParameters");
 }
 }
 
 
+// BigInt::BigInt(const String& str)
+static void BigInt__BigInt_constspStringamp(BigInt* _ptr, const String& str)
+{
+    new(_ptr) BigInt(str);
+}
+
+// BigInt::BigInt(i32 value)
+static void BigInt__BigInt_i32(BigInt* _ptr, i32 value)
+{
+    new(_ptr) BigInt(value);
+}
+
+// BigInt::BigInt(i64 value)
+static void BigInt__BigInt_i64(BigInt* _ptr, i64 value)
+{
+    new(_ptr) BigInt(value);
+}
+
+// BigInt::BigInt(u32 value)
+static void BigInt__BigInt_u32(BigInt* _ptr, u32 value)
+{
+    new(_ptr) BigInt(value);
+}
+
+// BigInt::BigInt(u64 value)
+static void BigInt__BigInt_u64(BigInt* _ptr, u64 value)
+{
+    new(_ptr) BigInt(value);
+}
+
+// class BigInt | File: ../Math/BigInt.h
+static void Register_BigInt(asIScriptEngine* engine)
+{
+    // BigInt::BigInt(const String& str)
+    engine->RegisterObjectBehaviour("BigInt", asBEHAVE_CONSTRUCT, "void f(const String&in)", AS_FUNCTION_OBJFIRST(BigInt__BigInt_constspStringamp), AS_CALL_CDECL_OBJFIRST);
+    // BigInt::BigInt(i32 value)
+    engine->RegisterObjectBehaviour("BigInt", asBEHAVE_CONSTRUCT, "void f(int)", AS_FUNCTION_OBJFIRST(BigInt__BigInt_i32), AS_CALL_CDECL_OBJFIRST);
+    // BigInt::BigInt(i64 value)
+    engine->RegisterObjectBehaviour("BigInt", asBEHAVE_CONSTRUCT, "void f(int64)", AS_FUNCTION_OBJFIRST(BigInt__BigInt_i64), AS_CALL_CDECL_OBJFIRST);
+    // BigInt::BigInt(u32 value)
+    engine->RegisterObjectBehaviour("BigInt", asBEHAVE_CONSTRUCT, "void f(uint)", AS_FUNCTION_OBJFIRST(BigInt__BigInt_u32), AS_CALL_CDECL_OBJFIRST);
+    // BigInt::BigInt(u64 value)
+    engine->RegisterObjectBehaviour("BigInt", asBEHAVE_CONSTRUCT, "void f(uint64)", AS_FUNCTION_OBJFIRST(BigInt__BigInt_u64), AS_CALL_CDECL_OBJFIRST);
+
+    // BigInt::~BigInt() | Implicitly-declared
+    engine->RegisterObjectBehaviour("BigInt", asBEHAVE_DESTRUCT, "void f()", AS_DESTRUCTOR(BigInt), AS_CALL_CDECL_OBJFIRST);
+
+    RegisterMembers_BigInt<BigInt>(engine, "BigInt");
+
+    #ifdef REGISTER_CLASS_MANUAL_PART_BigInt
+        REGISTER_CLASS_MANUAL_PART_BigInt();
+    #endif
+
+    // BigInt& BigInt::operator =(const BigInt&) | Possible implicitly-declared
+    RegisterImplicitlyDeclaredAssignOperatorIfPossible<BigInt>(engine, "BigInt");
+}
+
 // struct Billboard | File: ../Graphics/BillboardSet.h
 // struct Billboard | File: ../Graphics/BillboardSet.h
 static void Register_Billboard(asIScriptEngine* engine)
 static void Register_Billboard(asIScriptEngine* engine)
 {
 {
@@ -8355,6 +8412,7 @@ void ASRegisterGeneratedClasses(asIScriptEngine* engine)
     Register_BatchGroupKey(engine);
     Register_BatchGroupKey(engine);
     Register_BatchQueue(engine);
     Register_BatchQueue(engine);
     Register_BiasParameters(engine);
     Register_BiasParameters(engine);
+    Register_BigInt(engine);
     Register_Billboard(engine);
     Register_Billboard(engine);
     Register_Bone(engine);
     Register_Bone(engine);
     Register_BoundingBox(engine);
     Register_BoundingBox(engine);

+ 3 - 0
Source/Urho3D/AngelScript/Generated_DefaultConstructors.cpp

@@ -51,6 +51,9 @@ void ASRegisterGeneratedDefaultConstructors(asIScriptEngine* engine)
     // BiasParameters::BiasParameters() = default | File: ../Graphics/Light.h
     // BiasParameters::BiasParameters() = default | File: ../Graphics/Light.h
     engine->RegisterObjectBehaviour("BiasParameters", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<BiasParameters>), AS_CALL_CDECL_OBJFIRST);
     engine->RegisterObjectBehaviour("BiasParameters", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<BiasParameters>), AS_CALL_CDECL_OBJFIRST);
 
 
+    // BigInt::BigInt() | File: ../Math/BigInt.h
+    engine->RegisterObjectBehaviour("BigInt", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<BigInt>), AS_CALL_CDECL_OBJFIRST);
+
     // BoundingBox::BoundingBox() noexcept | File: ../Math/BoundingBox.h
     // BoundingBox::BoundingBox() noexcept | File: ../Math/BoundingBox.h
     engine->RegisterObjectBehaviour("BoundingBox", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<BoundingBox>), AS_CALL_CDECL_OBJFIRST);
     engine->RegisterObjectBehaviour("BoundingBox", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ASCompatibleConstructor<BoundingBox>), AS_CALL_CDECL_OBJFIRST);
 
 

+ 51 - 0
Source/Urho3D/AngelScript/Generated_Members.h

@@ -494,12 +494,63 @@ template <class T> void RegisterMembers_BiasParameters(asIScriptEngine* engine,
     #endif
     #endif
 }
 }
 
 
+// bool BigInt::operator <(const BigInt& rhs) const
+template <class T> int BigInt_bool_operatorles_constspBigIntamp(const T& lhs, const T& rhs)
+{
+    if (lhs < rhs)
+        return -1;
+
+    if (lhs > rhs)
+        return 1;
+
+    return 0;
+}
+
 // class BigInt | File: ../Math/BigInt.h
 // class BigInt | File: ../Math/BigInt.h
 template <class T> void RegisterMembers_BigInt(asIScriptEngine* engine, const char* className)
 template <class T> void RegisterMembers_BigInt(asIScriptEngine* engine, const char* className)
 {
 {
+    // bool BigInt::operator !=(const BigInt& rhs) const
+    // Only operator == is needed
+    // BigInt& BigInt::operator ++()
+    // TODO
+    // BigInt BigInt::operator ++(int)
+    // TODO
+    // BigInt& BigInt::operator --()
+    // TODO
+    // BigInt BigInt::operator --(int)
+    // TODO
+    // bool BigInt::operator <(const BigInt& rhs) const
+    // Registerd as opCmp separately
+    // bool BigInt::operator>(const BigInt& rhs) const
+    // Registerd as opCmp separately
+
+    // BigInt BigInt::operator *(const BigInt& rhs) const
+    engine->RegisterObjectMethod(className, "BigInt opMul(const BigInt&in) const", AS_METHODPR(T, operator*, (const BigInt&) const, BigInt), AS_CALL_THISCALL);
+
+    // BigInt& BigInt::operator *=(const BigInt& rhs)
+    engine->RegisterObjectMethod(className, "BigInt& opMulAssign(const BigInt&in)", AS_METHODPR(T, operator*=, (const BigInt&), BigInt&), AS_CALL_THISCALL);
+
+    // BigInt BigInt::operator +(const BigInt& rhs) const
+    engine->RegisterObjectMethod(className, "BigInt opAdd(const BigInt&in) const", AS_METHODPR(T, operator+, (const BigInt&) const, BigInt), AS_CALL_THISCALL);
+
+    // BigInt& BigInt::operator +=(const BigInt& rhs)
+    engine->RegisterObjectMethod(className, "BigInt& opAddAssign(const BigInt&in)", AS_METHODPR(T, operator+=, (const BigInt&), BigInt&), AS_CALL_THISCALL);
+
+    // BigInt BigInt::operator -(const BigInt& rhs) const
+    engine->RegisterObjectMethod(className, "BigInt opSub(const BigInt&in) const", AS_METHODPR(T, operator-, (const BigInt&) const, BigInt), AS_CALL_THISCALL);
+
+    // BigInt& BigInt::operator -=(const BigInt& rhs)
+    engine->RegisterObjectMethod(className, "BigInt& opSubAssign(const BigInt&in)", AS_METHODPR(T, operator-=, (const BigInt&), BigInt&), AS_CALL_THISCALL);
+
+    // bool BigInt::operator ==(const BigInt& rhs) const
+    engine->RegisterObjectMethod(className, "bool opEquals(const BigInt&in) const", AS_METHODPR(T, operator==, (const BigInt&) const, bool), AS_CALL_THISCALL);
+
     // String BigInt::ToString() const
     // String BigInt::ToString() const
     engine->RegisterObjectMethod(className, "String ToString() const", AS_METHODPR(T, ToString, () const, String), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "String ToString() const", AS_METHODPR(T, ToString, () const, String), AS_CALL_THISCALL);
 
 
+    // bool BigInt::operator <(const BigInt& rhs) const
+    engine->RegisterObjectMethod(className, "int opCmp(const BigInt& in) const", AS_FUNCTION_OBJFIRST(BigInt_bool_operatorles_constspBigIntamp<T>), AS_CALL_CDECL_OBJFIRST);
+
     #ifdef REGISTER_MEMBERS_MANUAL_PART_BigInt
     #ifdef REGISTER_MEMBERS_MANUAL_PART_BigInt
         REGISTER_MEMBERS_MANUAL_PART_BigInt();
         REGISTER_MEMBERS_MANUAL_PART_BigInt();
     #endif
     #endif

+ 1 - 1
Source/Urho3D/AngelScript/Generated_ObjectTypes.cpp

@@ -64,7 +64,7 @@ void ASRegisterGeneratedObjectTypes(asIScriptEngine* engine)
     engine->RegisterObjectType("BiasParameters", sizeof(BiasParameters), asOBJ_VALUE | asGetTypeTraits<BiasParameters>() | asOBJ_POD | asOBJ_APP_CLASS_ALLFLOATS);
     engine->RegisterObjectType("BiasParameters", sizeof(BiasParameters), asOBJ_VALUE | asGetTypeTraits<BiasParameters>() | asOBJ_POD | asOBJ_APP_CLASS_ALLFLOATS);
 
 
     // class BigInt | File: ../Math/BigInt.h
     // class BigInt | File: ../Math/BigInt.h
-    // Not registered because have @nobind mark
+    engine->RegisterObjectType("BigInt", sizeof(BigInt), asOBJ_VALUE | asGetTypeTraits<BigInt>());
 
 
     // struct Billboard | File: ../Graphics/BillboardSet.h
     // struct Billboard | File: ../Graphics/BillboardSet.h
     engine->RegisterObjectType("Billboard", 0, asOBJ_REF | asOBJ_NOCOUNT);
     engine->RegisterObjectType("Billboard", 0, asOBJ_REF | asOBJ_NOCOUNT);

+ 0 - 1
Source/Urho3D/Math/BigInt.h

@@ -11,7 +11,6 @@
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
-/// @nobind
 class URHO3D_API BigInt
 class URHO3D_API BigInt
 {
 {
 public:
 public:

+ 9 - 0
bin/Data/Scripts/Tests.as

@@ -0,0 +1,9 @@
+// Test AS bindings
+
+#include "Tests/Math/BigInt.as"
+
+void Start()
+{
+    Test_Math_BigInt();
+    engine.Exit();
+}

+ 18 - 0
bin/Data/Scripts/Tests/Math/BigInt.as

@@ -0,0 +1,18 @@
+#include "Scripts/Utilities/Assert.as"
+
+void Test_Math_BigInt()
+{
+    Assert(BigInt().ToString() == "0");
+    Assert(BigInt("9999999999999").ToString() == "9999999999999");
+
+    {
+        BigInt bi1("9999999999999");
+        BigInt bi2("1");
+        Assert((bi1 + bi2).ToString() == "10000000000000");
+    }
+
+    {
+        BigInt bi("9999999999999");
+        Assert((bi += 1).ToString() == "10000000000000");
+    }
+}

+ 9 - 0
bin/Data/Scripts/Utilities/Assert.as

@@ -0,0 +1,9 @@
+void Assert(bool condition)
+{
+    if (!condition)
+    {
+        PrintCallStack();
+        ErrorDialog("Assert", "Call stack is printed to log");
+        engine.Exit();
+    }
+}