Replaced a ton of ConsoleMethods with the DefineConsoleMethod Macro.

This commit is contained in:
Vincent Gee 2014-11-03 22:42:51 -05:00
parent 378a933894
commit acb192e2a5
133 changed files with 1716 additions and 2087 deletions

View file

@ -1179,7 +1179,7 @@ static bool isInSet(char c, const char *set)
return false;
}
ConsoleFunction( nextToken, const char *, 4, 4, "( string str, string token, string delimiters ) "
DefineConsoleFunction( nextToken, const char*, ( const char* str1, const char* token, const char* delim), , "( string str, string token, string delimiters ) "
"Tokenize a string using a set of delimiting characters.\n"
"This function first skips all leading charaters in @a str that are contained in @a delimiters. "
"From that position, it then scans for the next character in @a str that is contained in @a delimiters and stores all characters "
@ -1207,12 +1207,7 @@ ConsoleFunction( nextToken, const char *, 4, 4, "( string str, string token, str
"@endtsexample\n\n"
"@ingroup Strings" )
{
char buffer[4096];
dStrncpy(buffer, argv[1], 4096);
char *str = buffer;
const char *token = argv[2];
const char *delim = argv[3];
char *str = (char *)str1;
if( str )
{
// skip over any characters that are a member of delim
@ -1242,9 +1237,7 @@ ConsoleFunction( nextToken, const char *, 4, 4, "( string str, string token, str
str++;
}
char *ret = Con::getReturnBuffer(dStrlen(str)+1);
dStrncpy(ret, str, dStrlen(str)+1);
return ret;
return str;
}
//=============================================================================
@ -1289,7 +1282,7 @@ DefineEngineFunction( detag, const char*, ( const char* str ),,
return str;
}
ConsoleFunction(getTag, const char *, 2, 2, "(string textTagString)"
DefineConsoleFunction( getTag, const char*, ( const char* textTagString ), , "( string textTagString ) "
"@brief Extracts the tag from a tagged string\n\n"
"Should only be used within the context of a function that receives a tagged "
@ -1303,26 +1296,24 @@ ConsoleFunction(getTag, const char *, 2, 2, "(string textTagString)"
"@see detag()\n"
"@ingroup Networking")
{
TORQUE_UNUSED(argc);
if(argv[1][0] == StringTagPrefixByte)
if(textTagString[0] == StringTagPrefixByte)
{
const char *arg = argv[1];
const char * space = dStrchr(argv[1], ' ');
const char * space = dStrchr(textTagString, ' ');
U32 len;
U64 len;
if(space)
len = space - arg;
len = space - textTagString;
else
len = dStrlen(arg) + 1;
len = dStrlen(textTagString) + 1;
char * ret = Con::getReturnBuffer(len);
dStrncpy(ret, arg + 1, len - 1);
dStrncpy(ret, textTagString + 1, len - 1);
ret[len - 1] = 0;
return(ret);
}
else
return(argv[1]);
return(textTagString);
}
@ -1512,13 +1503,12 @@ DefineConsoleFunction( quit, void, ( ),,
//-----------------------------------------------------------------------------
#ifdef TORQUE_DEMO_PURCHASE
ConsoleFunction( realQuit, void, 1, 1, "" )
DefineConsoleFunction( realQuit, void, (), , "")
{
TORQUE_UNUSED(argc); TORQUE_UNUSED(argv);
Platform::postQuitMessage(0);
}
#endif
//-----------------------------------------------------------------------------
@ -2185,87 +2175,86 @@ DefineEngineFunction( exec, bool, ( const char* fileName, bool noCalls, bool jou
return ret;
}
ConsoleFunction(eval, const char *, 2, 2, "eval(consoleString)")
DefineConsoleFunction( eval, const char*, ( const char* consoleString ), , "eval(consoleString)" )
{
TORQUE_UNUSED(argc);
return Con::evaluate(argv[1], false, NULL);
return Con::evaluate(consoleString, false, NULL);
}
ConsoleFunction(getVariable, const char *, 2, 2, "(string varName)\n"
DefineConsoleFunction( getVariable, const char*, ( const char* varName ), , "(string varName)\n"
"@brief Returns the value of the named variable or an empty string if not found.\n\n"
"@varName Name of the variable to search for\n"
"@return Value contained by varName, \"\" if the variable does not exist\n"
"@ingroup Scripting")
{
return Con::getVariable(argv[1]);
return Con::getVariable(varName);
}
ConsoleFunction(setVariable, void, 3, 3, "(string varName, string value)\n"
DefineConsoleFunction( setVariable, void, ( const char* varName, const char* value ), , "(string varName, string value)\n"
"@brief Sets the value of the named variable.\n\n"
"@param varName Name of the variable to locate\n"
"@param value New value of the variable\n"
"@return True if variable was successfully found and set\n"
"@ingroup Scripting")
{
return Con::setVariable(argv[1], argv[2]);
return Con::setVariable(varName, value);
}
ConsoleFunction(isFunction, bool, 2, 2, "(string funcName)"
DefineConsoleFunction( isFunction, bool, ( const char* funcName ), , "(string funcName)"
"@brief Determines if a function exists or not\n\n"
"@param funcName String containing name of the function\n"
"@return True if the function exists, false if not\n"
"@ingroup Scripting")
{
return Con::isFunction(argv[1]);
return Con::isFunction(funcName);
}
ConsoleFunction(getFunctionPackage, const char*, 2, 2, "(string funcName)"
DefineConsoleFunction( getFunctionPackage, const char*, ( const char* funcName ), , "(string funcName)"
"@brief Provides the name of the package the function belongs to\n\n"
"@param funcName String containing name of the function\n"
"@return The name of the function's package\n"
"@ingroup Packages")
{
Namespace::Entry* nse = Namespace::global()->lookup( StringTable->insert( argv[1] ) );
Namespace::Entry* nse = Namespace::global()->lookup( StringTable->insert( funcName ) );
if( !nse )
return "";
return nse->mPackage;
}
ConsoleFunction(isMethod, bool, 3, 3, "(string namespace, string method)"
DefineConsoleFunction( isMethod, bool, ( const char* nameSpace, const char* method ), , "(string namespace, string method)"
"@brief Determines if a class/namespace method exists\n\n"
"@param namespace Class or namespace, such as Player\n"
"@param method Name of the function to search for\n"
"@return True if the method exists, false if not\n"
"@ingroup Scripting\n")
{
Namespace* ns = Namespace::find( StringTable->insert( argv[1] ) );
Namespace::Entry* nse = ns->lookup( StringTable->insert( argv[2] ) );
Namespace* ns = Namespace::find( StringTable->insert( nameSpace ) );
Namespace::Entry* nse = ns->lookup( StringTable->insert( method ) );
if( !nse )
return false;
return true;
}
ConsoleFunction(getMethodPackage, const char*, 3, 3, "(string namespace, string method)"
DefineConsoleFunction( getMethodPackage, const char*, ( const char* nameSpace, const char* method ), , "(string namespace, string method)"
"@brief Provides the name of the package the method belongs to\n\n"
"@param namespace Class or namespace, such as Player\n"
"@param method Name of the funciton to search for\n"
"@return The name of the method's package\n"
"@ingroup Packages")
{
Namespace* ns = Namespace::find( StringTable->insert( argv[1] ) );
Namespace* ns = Namespace::find( StringTable->insert( nameSpace ) );
if( !ns )
return "";
Namespace::Entry* nse = ns->lookup( StringTable->insert( argv[2] ) );
Namespace::Entry* nse = ns->lookup( StringTable->insert( method ) );
if( !nse )
return "";
return nse->mPackage;
}
ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
DefineConsoleFunction( isDefined, bool, ( const char* varName, const char* varValue ), ("") , "(string varName)"
"@brief Determines if a variable exists and contains a value\n"
"@param varName Name of the variable to search for\n"
"@return True if the variable was defined in script, false if not\n"
@ -2274,13 +2263,13 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
"@endtsexample\n\n"
"@ingroup Scripting")
{
if(dStrlen(argv[1]) == 0)
if(dStrlen(varName) == 0)
{
Con::errorf("isDefined() - did you forget to put quotes around the variable name?");
return false;
}
StringTableEntry name = StringTable->insert(argv[1]);
StringTableEntry name = StringTable->insert(varName);
// Deal with <var>.<value>
if (dStrchr(name, '.'))
@ -2331,7 +2320,7 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
if (!value)
{
obj->setDataField(valName, 0, argv[2]);
obj->setDataField(valName, 0, varValue);
return false;
}
@ -2350,8 +2339,11 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
{
if (dStrlen(value) > 0)
return true;
else if (argc > 2)
obj->setDataField(valName, 0, argv[2]);
else if (dStrcmp(varValue,"")!=0)
{
obj->setDataField(valName, 0, varValue);
}
}
}
}
@ -2365,8 +2357,10 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
if (ent)
return true;
else if (argc > 2)
gEvalState.getCurrentFrame().setVariable(name, argv[2]);
else if (dStrcmp (varValue,"")!=0)
{
gEvalState.getCurrentFrame().setVariable(name, varValue);
}
}
else
Con::errorf("%s() - no local variable frame.", __FUNCTION__);
@ -2378,16 +2372,20 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
if (ent)
return true;
else if (argc > 2)
gEvalState.globalVars.setVariable(name, argv[2]);
else if (dStrcmp( varValue,"") != 0)
{
gEvalState.globalVars.setVariable(name, varValue);
}
}
else
{
// Is it an object?
if (dStrcmp(argv[1], "0") && dStrcmp(argv[1], "") && (Sim::findObject(argv[1]) != NULL))
if (dStrcmp(varName, "0") && dStrcmp(varName, "") && (Sim::findObject(varName) != NULL))
return true;
else if (argc > 2)
Con::errorf("%s() - can't assign a value to a variable of the form \"%s\"", __FUNCTION__, (const char*)argv[1]);
else if (varValue != "")
{
Con::errorf("%s() - can't assign a value to a variable of the form \"%s\"", __FUNCTION__, varValue);
}
}
return false;
@ -2395,39 +2393,39 @@ ConsoleFunction(isDefined, bool, 2, 3, "(string varName)"
//-----------------------------------------------------------------------------
ConsoleFunction( isCurrentScriptToolScript, bool, 1, 1,
"() Returns true if the calling script is a tools script.\n"
DefineConsoleFunction( isCurrentScriptToolScript, bool, (), , "()"
"Returns true if the calling script is a tools script.\n"
"@hide")
{
return Con::isCurrentScriptToolScript();
}
ConsoleFunction(getModNameFromPath, const char *, 2, 2, "(string path)"
DefineConsoleFunction( getModNameFromPath, const char *, ( const char* path ), , "(string path)"
"@brief Attempts to extract a mod directory from path. Returns empty string on failure.\n\n"
"@param File path of mod folder\n"
"@note This is no longer relevant in Torque 3D (which does not use mod folders), should be deprecated\n"
"@internal")
{
StringTableEntry modPath = Con::getModNameFromPath(argv[1]);
StringTableEntry modPath = Con::getModNameFromPath(path);
return modPath ? modPath : "";
}
//-----------------------------------------------------------------------------
ConsoleFunction( pushInstantGroup, void, 1, 2, "([group])"
DefineConsoleFunction( pushInstantGroup, void, ( String group ),("") , "([group])"
"@brief Pushes the current $instantGroup on a stack "
"and sets it to the given value (or clears it).\n\n"
"@note Currently only used for editors\n"
"@ingroup Editors\n"
"@internal")
{
if( argc > 1 )
Con::pushInstantGroup( (const char*)argv[ 1 ] );
if( group.size() > 0 )
Con::pushInstantGroup( group );
else
Con::pushInstantGroup();
}
ConsoleFunction( popInstantGroup, void, 1, 1, "()"
DefineConsoleFunction( popInstantGroup, void, (), , "()"
"@brief Pop and restore the last setting of $instantGroup off the stack.\n\n"
"@note Currently only used for editors\n\n"
"@ingroup Editors\n"
@ -2438,11 +2436,11 @@ ConsoleFunction( popInstantGroup, void, 1, 1, "()"
//-----------------------------------------------------------------------------
ConsoleFunction(getPrefsPath, const char *, 1, 2, "([relativeFileName])"
DefineConsoleFunction( getPrefsPath, const char *, ( const char* relativeFileName ), , "([relativeFileName])"
"@note Appears to be useless in Torque 3D, should be deprecated\n"
"@internal")
{
const char *filename = Platform::getPrefsPath(argc > 1 ? (const char*)argv[1] : NULL);
const char *filename = Platform::getPrefsPath(relativeFileName);
if(filename == NULL || *filename == 0)
return "";