From a22254ad0a8e66f74e157cb867c96b32461e7b8a Mon Sep 17 00:00:00 2001 From: James Urquhart Date: Tue, 14 Oct 2014 18:40:59 +0100 Subject: [PATCH] Add console function to link namespaces --- Engine/source/console/consoleObject.cpp | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Engine/source/console/consoleObject.cpp b/Engine/source/console/consoleObject.cpp index e4cd744ad..3c46e444e 100644 --- a/Engine/source/console/consoleObject.cpp +++ b/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; +} +