Browse Source

Merge pull request #829 from jamesu/namespace_link

Add console function to link namespaces
Daniel Buckmaster 11 years ago
parent
commit
b88d3fde1f
1 changed files with 41 additions and 0 deletions
  1. 41 0
      Engine/source/console/consoleObject.cpp

+ 41 - 0
Engine/source/console/consoleObject.cpp

@@ -834,3 +834,44 @@ DefineEngineFunction( sizeof, S32, ( const char *objectOrClass ),,
    Con::warnf("could not find a class rep for that object or class name.");
    return 0;
 }
+
+
+DefineEngineFunction(linkNamespaces, bool, ( String childNSName, String parentNSName  ),,
+                     "@brief Links childNS to parentNS.\n\n"
+                     "Links childNS to parentNS, or nothing if parentNS is NULL.\n"
+                     "Will unlink the namespace from previous namespace if a parent already exists.\n"
+                     "@internal\n")
+{
+   StringTableEntry childNSSTE = StringTable->insert(childNSName.c_str());
+   StringTableEntry parentNSSTE = StringTable->insert(parentNSName.c_str());
+   
+   Namespace *childNS = Namespace::find(childNSSTE);
+   Namespace *parentNS = Namespace::find(parentNSSTE);
+   Namespace *currentParent = childNS->getParent();
+   
+   if (!childNS)
+   {
+      return false;
+   }
+   
+   // Link to new NS if applicable
+   
+   if (currentParent != parentNS)
+   {
+      if (currentParent != NULL)
+      {
+         if (!childNS->unlinkClass(currentParent))
+         {
+            return false;
+         }
+      }
+      
+      if (parentNS != NULL)
+      {
+         return childNS->classLinkTo(parentNS);
+      }
+   }
+   
+   return true;
+}
+