forked from Mirrors/openclonk
Backed out changeset e06fd6359b15
While the changeset did in fact fix the coercion of numeric function parameters, it also broke proplist refcounting somewhat badly.floating-point
parent
c12e4fd937
commit
f4ac79858b
|
@ -60,9 +60,9 @@ void C4Value::DelDataRef(C4V_Data Data, C4V_Type Type, C4Value *pNextRef)
|
|||
// clean up
|
||||
switch (Type)
|
||||
{
|
||||
case C4V_C4Object: case C4V_PropList: assert(Data.PropList); Data.PropList->DelRef(this, pNextRef); break;
|
||||
case C4V_Array: assert(Data.Array); Data.Array->DecRef(); break;
|
||||
case C4V_String: assert(Data.Str); Data.Str->DecRef(); break;
|
||||
case C4V_C4Object: case C4V_PropList: Data.PropList->DelRef(this, pNextRef); break;
|
||||
case C4V_Array: Data.Array->DecRef(); break;
|
||||
case C4V_String: Data.Str->DecRef(); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,17 +106,17 @@ public:
|
|||
// Checked getters
|
||||
int32_t getInt() const
|
||||
{
|
||||
if (!CanConvertTo(C4V_Int))
|
||||
if (!ConvertTo(C4V_Int))
|
||||
return 0;
|
||||
else if (Type == C4V_Float)
|
||||
return C4Real(Data.Float);
|
||||
else
|
||||
return Data.Int;
|
||||
}
|
||||
bool getBool() const { return CanConvertTo(C4V_Bool) ? !! Data : 0; }
|
||||
bool getBool() const { return ConvertTo(C4V_Bool) ? !! Data : 0; }
|
||||
C4Real getFloat() const
|
||||
{
|
||||
if (!CanConvertTo(C4V_Float))
|
||||
if (!ConvertTo(C4V_Float))
|
||||
return C4Real(0);
|
||||
else if (Type == C4V_Float)
|
||||
return Data.Float;
|
||||
|
@ -124,10 +124,10 @@ public:
|
|||
return static_cast<int32_t>(Data.Int);
|
||||
}
|
||||
C4ID getC4ID() const;
|
||||
C4Object * getObj() const { return CanConvertTo(C4V_C4Object) ? Data.Obj : NULL; }
|
||||
C4PropList * getPropList() const { return CanConvertTo(C4V_PropList) ? Data.PropList : NULL; }
|
||||
C4String * getStr() const { return CanConvertTo(C4V_String) ? Data.Str : NULL; }
|
||||
C4ValueArray * getArray() const { return CanConvertTo(C4V_Array) ? Data.Array : NULL; }
|
||||
C4Object * getObj() const { return ConvertTo(C4V_C4Object) ? Data.Obj : NULL; }
|
||||
C4PropList * getPropList() const { return ConvertTo(C4V_PropList) ? Data.PropList : NULL; }
|
||||
C4String * getStr() const { return ConvertTo(C4V_String) ? Data.Str : NULL; }
|
||||
C4ValueArray * getArray() const { return ConvertTo(C4V_Array) ? Data.Array : NULL; }
|
||||
|
||||
// Unchecked getters
|
||||
int32_t _getInt() const { return Data.Int; }
|
||||
|
@ -236,7 +236,7 @@ public:
|
|||
|
||||
StdStrBuf GetDataString() const;
|
||||
|
||||
inline bool CanConvertTo(C4V_Type vtToType) const // convert to dest type
|
||||
inline bool ConvertTo(C4V_Type vtToType) const // convert to dest type
|
||||
{
|
||||
switch (C4ScriptCnvMap[Type][vtToType].Function)
|
||||
{
|
||||
|
@ -247,29 +247,9 @@ public:
|
|||
case C4VCnvFn::CnvF2I: return Type == C4V_Float && (vtToType == C4V_Int || vtToType == C4V_Bool);
|
||||
case C4VCnvFn::CnvI2F: return (Type == C4V_Int || Type == C4V_Bool) && vtToType == C4V_Float;
|
||||
}
|
||||
assert(!"C4Value::CanConvertTo: Invalid conversion function specified");
|
||||
return false;
|
||||
}
|
||||
inline bool ConvertTo(C4V_Type vtToType)
|
||||
{
|
||||
// Don't actually convert to C4V_Any; it's used as a marker where multiple types are acceptable
|
||||
if (Data && vtToType == C4V_Any) return true;
|
||||
if (!CanConvertTo(vtToType)) return false;
|
||||
switch (C4ScriptCnvMap[Type][vtToType].Function)
|
||||
{
|
||||
case C4VCnvFn::CnvOK: case C4VCnvFn::CnvOK0:
|
||||
if (Data || IsNullableType(vtToType))
|
||||
Type = vtToType;
|
||||
return true;
|
||||
case C4VCnvFn::CnvError: return false;
|
||||
case C4VCnvFn::CnvObject: Type = C4V_C4Object; return true;
|
||||
case C4VCnvFn::CnvF2I: SetInt(getFloat()); return true;
|
||||
case C4VCnvFn::CnvI2F: SetFloat(getInt()); return true;
|
||||
}
|
||||
assert(!"C4Value::ConvertTo: Invalid conversion function specified");
|
||||
return false;
|
||||
}
|
||||
|
||||
inline static bool WarnAboutConversion(C4V_Type vtFromType, C4V_Type vtToType)
|
||||
{
|
||||
return C4ScriptCnvMap[vtFromType][vtToType].Warn;
|
||||
|
|
Loading…
Reference in New Issue