Skip to content

Commit ffbb7ed

Browse files
committed
Support unsigned long values for Dynamic
Fixes ambiguous calls when compiling with Xcode
1 parent 00985d5 commit ffbb7ed

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

include/Dynamic.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
3030
Dynamic(float inVal);
3131
Dynamic(cpp::Int64 inVal);
3232
Dynamic(cpp::UInt64 inVal);
33+
Dynamic(unsigned long inVal);
3334
Dynamic(hx::Object *inObj) : super(inObj) { }
3435
Dynamic(const String &inString);
3536
Dynamic(const null &inNull) : super(0) { }
@@ -40,7 +41,6 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
4041
Dynamic(const hx::Native<T *> &inInterface):super(inInterface.ptr ? inInterface->__GetRealObject() : (hx::Object *)0 ) { }
4142
#if !defined(__GNUC__) || defined(__MINGW32__) || (defined(__WORDSIZE) && (__WORDSIZE != 64))
4243
Dynamic(long inVal);
43-
Dynamic(unsigned long inVal);
4444
#endif
4545
#ifdef __OBJC__
4646
#ifdef HXCPP_OBJC
@@ -74,6 +74,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
7474
inline operator bool() const { return mPtr && mPtr->__ToInt(); }
7575
inline operator cpp::Int64() const { return mPtr ? mPtr->__ToInt64() : 0; }
7676
inline operator cpp::UInt64() const { return mPtr ? mPtr->__ToInt64() : 0; }
77+
inline operator unsigned long() const { return mPtr ? mPtr->__ToInt64() : 0; }
7778

7879
// Conversion to generic pointer requires you to tag the class with a typedef
7980
template<typename T>

include/cpp/Variant.h

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ namespace cpp
7070

7171
inline Variant(cpp::Int64 inValue) : type(typeInt64), valInt64(inValue) { }
7272
inline Variant(cpp::UInt64 inValue) : type(typeInt64), valInt64(inValue) { }
73+
inline Variant(unsigned long inValue) : type(typeInt64), valInt64(inValue) { }
7374
inline Variant(int inValue) : type(typeInt), valInt(inValue) { }
7475
inline Variant(cpp::UInt32 inValue) : type(typeInt), valInt(inValue) { }
7576
inline Variant(cpp::Int16 inValue) : type(typeInt), valInt(inValue) { }
@@ -111,6 +112,7 @@ namespace cpp
111112
inline operator signed char () const { return asInt(); }
112113
inline operator cpp::Int64 () const { return asInt64(); }
113114
inline operator cpp::UInt64 () const { return asInt64(); }
115+
inline operator unsigned long () const { return asInt64(); }
114116
inline bool operator !() const { return !asInt(); }
115117

116118
inline int Compare(hx::Object *inRHS) const;

include/hxString.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String
9595
String(const float &inRHS);
9696
String(const cpp::Int64 &inRHS);
9797
String(const cpp::UInt64 &inRHS);
98+
String(const unsigned long &inRHS);
9899
explicit String(const bool &inRHS);
99100
inline String(const null &inRHS) : __s(0), length(0) { }
100101
String(hx::Null< ::String > inRHS) : __s(inRHS.value.__s), length(inRHS.value.length) { }

include/null.h

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class null
9292
operator signed char () { return 0; }
9393
operator short () { return 0; }
9494
operator unsigned short () { return 0; }
95+
operator unsigned long () { return 0; }
9596
operator cpp::UInt64 () { return 0; }
9697
operator cpp::Int64 () { return 0; }
9798
template<typename T>

src/Dynamic.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,6 @@ Dynamic::Dynamic(short inVal)
367367
}
368368

369369
#if !defined(__GNUC__) || defined(__MINGW32__) || (defined(__WORDSIZE) && (__WORDSIZE != 64))
370-
Dynamic::Dynamic(unsigned long inVal)
371-
{
372-
mPtr = fromInt(inVal);
373-
}
374370
Dynamic::Dynamic(long inVal)
375371
{
376372
mPtr = fromInt(inVal);
@@ -440,6 +436,19 @@ Dynamic::Dynamic(cpp::UInt64 inVal)
440436
mPtr = (hx::Object *)new Int64Data(inVal);
441437
}
442438

439+
Dynamic::Dynamic(unsigned long inVal)
440+
{
441+
if ( (int)inVal==inVal && inVal<256 )
442+
{
443+
int idx = inVal+1;
444+
mPtr = sConstDynamicInts[idx].mPtr;
445+
if (!mPtr)
446+
mPtr = sConstDynamicInts[idx].mPtr = new (hx::NewObjConst)IntData(inVal);
447+
}
448+
else
449+
mPtr = (hx::Object *)new Int64Data(inVal);
450+
}
451+
443452

444453

445454

src/String.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,14 @@ String::String(const cpp::UInt64 &inRHS)
862862
__s = GCStringDup(buf,-1,&length);
863863
}
864864

865+
String::String(const unsigned long &inRHS)
866+
{
867+
char buf[100];
868+
SPRINTF(buf,100,"%llu", (unsigned long long int)inRHS);
869+
buf[99]='\0';
870+
__s = GCStringDup(buf,-1,&length);
871+
}
872+
865873
String::String(const float &inRHS)
866874
{
867875
char buf[100];

0 commit comments

Comments
 (0)