Browse Source

Minor fixes: cleaning up comments, variable initilization, early return

SirNate0 8 years ago
parent
commit
b9f39755db

+ 22 - 24
Source/Urho3D/AngelScript/Script.cpp

@@ -321,34 +321,32 @@ const char **Script::GetEnumValues(int asTypeID)
     if (!type)
         return nullptr;
 
-    if (type->GetFlags() & asOBJ_ENUM)
+    if (!(type->GetFlags() & asOBJ_ENUM))
+        return nullptr;
+
+    unsigned count = type->GetEnumValueCount();
+    enumValues_[asTypeID].Resize(count + 1);
+    for (unsigned i = 0; i < count; ++i)
     {
-        unsigned count = type->GetEnumValueCount();
-        enumValues_[asTypeID].Resize(count + 1);
-        int val;
-        for (unsigned i = 0; i < count; ++i)
+        int val = -1;
+        const char* name = type->GetEnumValueByIndex(i,&val);
+        if ((unsigned)val >= count)// use unsigned for val so negative values will be flagged as invalid
         {
-            const char* name = type->GetEnumValueByIndex(i,&val);
-            if ((unsigned)val >= count)// use unsigned for val so negative values will be flagged as invalid
-            {
-                URHO3D_LOGDEBUGF("Could not register enum attribute names for type %d."
-                          "%s has value of %d, which is outside of the range [0,%d) for a 0-based enum.",
-                          asTypeID,name,val,count);
-
-                //fill with empty buffer
-                enumValues_[asTypeID] = PODVector<const char*>();
-                return nullptr;
-            }
-            else
-            {
-                enumValues_[asTypeID][i] = name;
-            }
+            URHO3D_LOGDEBUGF("Could not register enum attribute names for type %d."
+                      "%s has value of %d, which is outside of the range [0,%d) for a 0-based enum.",
+                      asTypeID,name,val,count);
+
+            //fill with empty buffer
+            enumValues_[asTypeID] = PODVector<const char*>();
+            return nullptr;
+        }
+        else
+        {
+            enumValues_[asTypeID][i] = name;
         }
-        enumValues_[asTypeID][count] = 0;
-        return enumValues_[asTypeID].Buffer();
     }
-    else
-        return nullptr;
+    enumValues_[asTypeID][count] = 0;
+    return enumValues_[asTypeID].Buffer();
 }
 
 asIScriptContext* Script::GetScriptFileContext()

+ 2 - 2
Source/Urho3D/AngelScript/Script.h

@@ -102,7 +102,7 @@ public:
     /// Return the script module create/delete mutex.
     Mutex& GetModuleMutex() { return moduleMutex_; }
 
-    /// Returns an array of strings of enum value names for Enum Attributes
+    /// Returns an array of strings of enum value names for Enum Attributes.
     const char** GetEnumValues(int asTypeID);
 
 
@@ -135,7 +135,7 @@ private:
     Vector<asIScriptContext*> scriptFileContexts_;
     /// Search cache for inbuilt object types.
     HashMap<const char*, asITypeInfo*> objectTypes_;
-    /// Cache of typeIds to array of enum value strings for attributes. Once found, the
+    /// Cache of typeIds to array of enum value strings for attributes.
     HashMap<int, PODVector<const char*>> enumValues_;
     /// AngelScript resource router.
     SharedPtr<ResourceRouter> router_;

+ 3 - 3
Source/Urho3D/AngelScript/ScriptInstance.cpp

@@ -641,9 +641,9 @@ void ScriptInstance::GetScriptAttributes()
     unsigned numProperties = scriptObject_->GetPropertyCount();
     for (unsigned i = 0; i < numProperties; ++i)
     {
-        const char* name;
-        int typeId;
-        bool isPrivate, isProtected, isHandle, isEnum;
+        const char* name = nullptr;
+        int typeId = 0; // AngelScript void typeid
+        bool isPrivate=false, isProtected=false, isHandle=false, isEnum=false;
 
         scriptObject_->GetObjectType()->GetProperty(i, &name, &typeId, &isPrivate, &isProtected);