С++ vs AS type detection

Started by
6 comments, last by 1vanK 2 years ago
class URHO3D_API BigInt
{
private:
    // If the value can be stored in i32, it is stored here. Otherwise, this field is -1 or +1.
    i32 signOrShortValue_;

public:
    BigInt(i32 value = 0)
        : signOrShortValue_(value)
    {
    }

    BigInt(u32 value)
        : signOrShortValue_(+1)
    {
    }

    String ToString() const
    {
        return String(signOrShortValue_);
    }
};
// BigInt::BigInt(i32 value = 0)
static void BigInt__BigInt_i32(BigInt* _ptr, i32 value)
{
    new(_ptr) BigInt(value);
}
// BigInt::BigInt(u32 value)
static void BigInt__BigInt_u32(BigInt* _ptr, u32 value)
{
    new(_ptr) BigInt(value);
}

    // BigInt::BigInt(i32 value = 0)
    engine->RegisterObjectBehaviour("BigInt", asBEHAVE_CONSTRUCT, "void f(int = 0)", AS_FUNCTION_OBJFIRST(BigInt__BigInt_i32), 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);
// C++
    {
        BigInt bigInt = -7; // -7 is int
        assert(bigInt.ToString() == "-7");
    }

    {
        BigInt bigInt = 0xFFFFFFFF; // 0xFFFFFFFF is unsigned
        assert(bigInt.ToString() == "1");
    }
    
    {
        BigInt bigInt = 0xFFFFFFF; // 0xFFFFFFF is int
        assert(bigInt.ToString() != "1");
    }
// AngelScript

void Start()
{
    BigInt i1(2147483647); 
    log.Error(i1.ToString()); // print 2147483647 (used int constructor)
    BigInt u1(2147483648);
    log.Error(u1.ToString()); // print -2147483648 (used int constructor)
    BigInt i2(0xFF);
    log.Error(i2.ToString()); // print 1 (used uint constructor)
    BigInt u2(0xFFFFFFFF);
    log.Error(u2.ToString());  // print 1 (used uint constructor)
}

p.s. I known about uint(xxx), but a user can easily forget about it

Advertisement

I'll take a look at this. Thanks for the report.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This is already fixed in the latest WIP version. Which version of angelscript are you currently using?

In the latest WIP version the following compiles with an error:

BigInt u1(2147483648);

It gives the error:

test (3, 11) : Error   : Multiple matching signatures to 'BigInt(const int64)
test (3, 11) : Info    : BigInt::BigInt(int = 0)
test (3, 11) : Info    : BigInt::BigInt(uint)

This is the same behavior as in C++.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This version https://github.com/urho3d/Urho3D/blob/master/Source/ThirdParty/AngelScript/Urho3DNotes.txt

Also

typedef int32_t i32;
typedef uint32_t u32;

and C++17 enabled

OK. So you are already using the WIP version, just not the latest revision.

I think the commit in rev 2750 is what you need to fix the problem you identified.

https://sourceforge.net/p/angelscript/code/2750/​​

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks!

This topic is closed to new replies.

Advertisement