ecere/com/dataTypes: Fixed issues stringifying enums
[sdk] / ecere / src / com / dataTypes.ec
index d4812fd..6c9c9da 100644 (file)
@@ -201,13 +201,13 @@ public:
    switch(_class.typeSize)
    {
       case 1:
-         i64Data = !strcmp(_class.dataTypeString, "byte") ? *(byte *)data : *(char *)data;
+         i64Data = !strcmp(_class.dataTypeString, "byte") ? (int64)*(byte *)data : (int64)*(char *)data;
          break;
       case 2:
-         i64Data = !strcmp(_class.dataTypeString, "uint16") ? *(uint16 *)data : *(short *)data;
+         i64Data = !strcmp(_class.dataTypeString, "uint16") ? (int64)*(uint16 *)data : (int64)*(short *)data;
          break;
       case 4:
-         i64Data = !strcmp(_class.dataTypeString, "uint") ? *(uint *)data : *(int *)data;
+         i64Data = !strcmp(_class.dataTypeString, "uint") ? (int64)*(uint *)data : (int64)*(int *)data;
          break;
       case 8:
          i64Data = !strcmp(_class.dataTypeString, "uint64") ? *(int64 *)data : *(int64 *)data;
@@ -222,11 +222,15 @@ public:
    }
    if(item)
    {
-      strcpy(tempString, item.name);
-      if(!needClass || !*needClass)
-         tempString[0] = (char)toupper(tempString[0]);
-      return tempString;
-      //return item.name;
+      if(tempString)
+      {
+         strcpy(tempString, item.name);
+         if(!needClass || !*needClass)
+            tempString[0] = (char)toupper(tempString[0]);
+         return tempString;
+      }
+      else
+         return item.name;
    }
    else
       return null;
@@ -1090,7 +1094,25 @@ static bool OnGetDataFromString(Class _class, void ** data, const char * string)
                   if(memberType.type == noHeadClass || memberType.type == normalClass || memberType.type == structClass)
                      ((void (*)(void *, void *))(void *)((Property)thisMember).Set)(data, value.p);
                   else
-                     ((void (*)(void *, int))(void *)((Property)thisMember).Set)(data, value.i);
+                  {
+                     // TODO: Complete and improve this type of stuff throughout
+                     if(!strcmp(memberType.dataTypeString, "float"))
+                     {
+                        ((void (*)(void *, float))(void *)((Property)thisMember).Set)(data, value.f);
+                     }
+                     else if(!strcmp(memberType.dataTypeString, "double"))
+                     {
+                        ((void (*)(void *, double))(void *)((Property)thisMember).Set)(data, value.d);
+                     }
+                     else if(!strcmp(memberType.dataTypeString, "int64"))
+                     {
+                        ((void (*)(void *, int64))(void *)((Property)thisMember).Set)(data, value.i64);
+                     }
+                     else
+                     {
+                        ((void (*)(void *, int))(void *)((Property)thisMember).Set)(data, value.i);
+                     }
+                  }
                }
             }
          }
@@ -1106,12 +1128,18 @@ static bool OnGetDataFromString(Class _class, void ** data, const char * string)
 
 static void OnCopy(Class _class, void ** data, void * newData)
 {
-   // TO IMPROVE: Inherit from Unit class for better performance?
    if(_class.type == unitClass || _class.type == bitClass || _class.type == enumClass)
    {
+      // An OnCopy is pointless for these, just copy the value
+      /*
       Class dataType = eSystem_FindClass(_class.module, _class.dataTypeString);
       if(dataType)
          ((void (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCopy])(dataType, data, newData);
+      */
+      if(newData)
+         memcpy(data, newData, _class.typeSize);
+      else
+         memset(data, 0, _class.typeSize);
    }
    else if(_class.type != structClass && (_class.type != systemClass || _class.byValueSystemClass))
    {