Skip to content

Support unsigned long values for Dynamic #1214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/Dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
Dynamic(float inVal);
Dynamic(cpp::Int64 inVal);
Dynamic(cpp::UInt64 inVal);
Dynamic(unsigned long inVal);
Dynamic(hx::Object *inObj) : super(inObj) { }
Dynamic(const String &inString);
Dynamic(const null &inNull) : super(0) { }
Expand All @@ -40,7 +41,6 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
Dynamic(const hx::Native<T *> &inInterface):super(inInterface.ptr ? inInterface->__GetRealObject() : (hx::Object *)0 ) { }
#if !defined(__GNUC__) || defined(__MINGW32__) || (defined(__WORDSIZE) && (__WORDSIZE != 64))
Dynamic(long inVal);
Dynamic(unsigned long inVal);
#endif
#ifdef __OBJC__
#ifdef HXCPP_OBJC
Expand Down Expand Up @@ -74,6 +74,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
inline operator bool() const { return mPtr && mPtr->__ToInt(); }
inline operator cpp::Int64() const { return mPtr ? mPtr->__ToInt64() : 0; }
inline operator cpp::UInt64() const { return mPtr ? mPtr->__ToInt64() : 0; }
inline operator unsigned long() const { return mPtr ? mPtr->__ToInt64() : 0; }

// Conversion to generic pointer requires you to tag the class with a typedef
template<typename T>
Expand Down
2 changes: 2 additions & 0 deletions include/cpp/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace cpp

inline Variant(cpp::Int64 inValue) : type(typeInt64), valInt64(inValue) { }
inline Variant(cpp::UInt64 inValue) : type(typeInt64), valInt64(inValue) { }
inline Variant(unsigned long inValue) : type(typeInt64), valInt64(inValue) { }
inline Variant(int inValue) : type(typeInt), valInt(inValue) { }
inline Variant(cpp::UInt32 inValue) : type(typeInt), valInt(inValue) { }
inline Variant(cpp::Int16 inValue) : type(typeInt), valInt(inValue) { }
Expand Down Expand Up @@ -111,6 +112,7 @@ namespace cpp
inline operator signed char () const { return asInt(); }
inline operator cpp::Int64 () const { return asInt64(); }
inline operator cpp::UInt64 () const { return asInt64(); }
inline operator unsigned long () const { return asInt64(); }
inline bool operator !() const { return !asInt(); }

inline int Compare(hx::Object *inRHS) const;
Expand Down
1 change: 1 addition & 0 deletions include/hxString.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String
String(const float &inRHS);
String(const cpp::Int64 &inRHS);
String(const cpp::UInt64 &inRHS);
String(const unsigned long &inRHS);
explicit String(const bool &inRHS);
inline String(const null &inRHS) : __s(0), length(0) { }
String(hx::Null< ::String > inRHS) : __s(inRHS.value.__s), length(inRHS.value.length) { }
Expand Down
1 change: 1 addition & 0 deletions include/null.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class null
operator signed char () { return 0; }
operator short () { return 0; }
operator unsigned short () { return 0; }
operator unsigned long () { return 0; }
operator cpp::UInt64 () { return 0; }
operator cpp::Int64 () { return 0; }
template<typename T>
Expand Down
17 changes: 13 additions & 4 deletions src/Dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,6 @@ Dynamic::Dynamic(short inVal)
}

#if !defined(__GNUC__) || defined(__MINGW32__) || (defined(__WORDSIZE) && (__WORDSIZE != 64))
Dynamic::Dynamic(unsigned long inVal)
{
mPtr = fromInt(inVal);
}
Dynamic::Dynamic(long inVal)
{
mPtr = fromInt(inVal);
Expand Down Expand Up @@ -440,6 +436,19 @@ Dynamic::Dynamic(cpp::UInt64 inVal)
mPtr = (hx::Object *)new Int64Data(inVal);
}

Dynamic::Dynamic(unsigned long inVal)
{
if ( (int)inVal==inVal && inVal<256 )
{
int idx = inVal+1;
mPtr = sConstDynamicInts[idx].mPtr;
if (!mPtr)
mPtr = sConstDynamicInts[idx].mPtr = new (hx::NewObjConst)IntData(inVal);
}
else
mPtr = (hx::Object *)new Int64Data(inVal);
}




Expand Down
8 changes: 8 additions & 0 deletions src/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,14 @@ String::String(const cpp::UInt64 &inRHS)
__s = GCStringDup(buf,-1,&length);
}

String::String(const unsigned long &inRHS)
{
char buf[100];
SPRINTF(buf,100,"%llu", (unsigned long long int)inRHS);
buf[99]='\0';
__s = GCStringDup(buf,-1,&length);
}

String::String(const float &inRHS)
{
char buf[100];
Expand Down