diff --git a/Engine/source/console/consoleInternal.cpp b/Engine/source/console/consoleInternal.cpp index e1de30ab1..803b23b38 100644 --- a/Engine/source/console/consoleInternal.cpp +++ b/Engine/source/console/consoleInternal.cpp @@ -1776,6 +1776,45 @@ String Namespace::Entry::getPrototypeString() const return str.end(); } +String Namespace::Entry::getPrototypeSig() const +{ + StringBuilder str; + + // Add function name and arguments. + + if (mType == ScriptCallbackType) + str.append(cb.mCallbackName); + else + str.append(mFunctionName); + if (mHeader) + { + Vector< String > argList; + sParseList(mHeader->mArgString, argList); + + const U32 numArgs = argList.size(); + + str.append("(%this"); + + if (numArgs > 0) + str.append(','); + for (U32 i = 0; i < numArgs; ++i) + { + // Add separator if not first arg. + + String name; + String type; + + if (i > 0) + str.append(','); + str.append('%'); + sGetArgNameAndType(argList[i], type, name); + str.append(name); + } + str.append(')'); + } + + return str.end(); +} //----------------------------------------------------------------------------- StringTableEntry Namespace::mActivePackages[Namespace::MaxActivePackages]; diff --git a/Engine/source/console/consoleInternal.h b/Engine/source/console/consoleInternal.h index 9b8ab1e19..f54637513 100644 --- a/Engine/source/console/consoleInternal.h +++ b/Engine/source/console/consoleInternal.h @@ -164,6 +164,10 @@ public: /// Return a full prototype string for the function including return type, function name, /// and arguments. String getPrototypeString() const; + + /// Return a minimalized prototype string for the function including return type, function name, + /// and arguments. + String getPrototypeSig() const; }; Entry* mEntryList; diff --git a/Engine/source/console/simObject.cpp b/Engine/source/console/simObject.cpp index 42f2f5c07..03178ace1 100644 --- a/Engine/source/console/simObject.cpp +++ b/Engine/source/console/simObject.cpp @@ -2655,6 +2655,50 @@ DefineEngineMethod( SimObject, dumpMethods, ArrayObject*, (),, return dictionary; } +DefineEngineMethod(SimObject, getMethodSigs, ArrayObject*, (), , + "List the methods defined on this object.\n\n" + "Each description is a newline-separated vector with the following elements:\n" + "- method prototype string.\n" + "- Documentation string (not including prototype). This takes up the remainder of the vector.\n" + "@return An ArrayObject populated with (name,description) pairs of all methods defined on the object.") +{ + Namespace* ns = object->getNamespace(); + if (!ns) + return 0; + + ArrayObject* dictionary = new ArrayObject(); + dictionary->registerObject(); + + VectorPtr vec(__FILE__, __LINE__); + ns->getEntryList(&vec); + for (Vector< Namespace::Entry* >::iterator j = vec.begin(); j != vec.end(); j++) + { + Namespace::Entry* e = *j; + + if (e->mType != Namespace::Entry::ScriptCallbackType) + continue; + + StringBuilder str; + str.append("function "); + str.append(ns->getName()); + str.append("::"); + str.append(e->getPrototypeSig()); + str.append('\n'); + str.append("{"); + String docs = e->getDocString(); + if (!docs.isEmpty()) + { + str.append("\n/*"); + str.append(docs); + str.append("\n*/"); + } + str.append('\n'); + str.append("}"); + dictionary->push_back(e->mFunctionName, str.end()); + } + + return dictionary; +} //----------------------------------------------------------------------------- namespace {