Add console function to link namespaces

This commit is contained in:
James Urquhart 2014-10-14 18:40:59 +01:00
parent 561e26ea07
commit a22254ad0a

View file

@ -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;
}