New Parent:: question,
by Vince Gee · in Torque 3D Professional · 03/07/2012 (9:17 am) · 4 replies
I figured out how to call a parent function of a object, that wasn't too difficult since I had the object and I could just walk the objects namespace.
But... In the case of Main.cs in the scripts folder...
How do I look a function up w/out an object so that I can find its parent in c++?
Vince
But... In the case of Main.cs in the scripts folder...
package fps{
.
.
.
function parseArgs()
{
Parent::parseArgs
..How do I look a function up w/out an object so that I can find its parent in c++?
Vince
About the author
www.winterleafentertainment.com
#2
03/08/2012 (12:51 pm)
Is it looking for the function in a Package at a higher level of the package stack? Please show us what you learned.
#3
The key here is finding the function, I realized that it would be in the global stack, and once I figured out that, the rest was easy. Code is pretty easy to follow.
The namespace depth is how many parents to go up. So, 0 is function->parent, 1 is function->parent->parent, etc.
Vince
03/08/2012 (1:19 pm)
Frank,The key here is finding the function, I realized that it would be in the global stack, and once I figured out that, the rest was easy. Code is pretty easy to follow.
The namespace depth is how many parents to go up. So, 0 is function->parent, 1 is function->parent->parent, etc.
Vince
extern "C" __declspec(dllexport) void ParentCallFunct(char* function,S32 namespacedepth,char* ret,S32 argc,char ** _argv,bool debug)
{
dSprintf(ret,1024,"%s","");
StringTableEntry callMethod = StringTable->insert( function );
if (!Con::isFunction(callMethod))
Con::errorf("Function Does not exist!");
else
Con::errorf("------>Found Function!!!");
Namespace* ns =Namespace::global()->lookup(callMethod)->mNamespace ;
if (!ns)
{
Con::errorf("Namespace not working");
return;
}
for (int i = 0;i<=namespacedepth;i++)
{
ns = ns->getParent();
if (!ns)
{
Con::errorf("OOOPS... NAMESPACE NOT FOUND");
return;
}
if (debug)
Con::errorf("Digging NameSpace for object (%s), Found NameSpace (%s) at a depth of (%i) on way to destination (%i)",function,ns->getName(), i,namespacedepth-1);
}
Con::errorf("Current NameSpace is %s",ns->mName);
std::vector<const char*> arguments;
for (int i =0;i<argc;i++)
{
if (debug)
Con::errorf("Adding '%s' to vector",_argv[i]);
arguments.push_back(_argv[i]);
}
const char** argv = &arguments[0];
Namespace::Entry* funct = ns->lookup(callMethod);
if (!funct)
{
Con::errorf("Cannot find parent Function!!!!!!!!!!!");
return;
}
Con::errorf("Calling Function");
const char* resultstring = funct->execute( argc,argv, &gEvalState);
if (dStrlen(resultstring)>0)
dSprintf(ret,1024,"%s",resultstring);
}
#4
I figured there are two different type of parent:: calls, one is when it's just a lone function that is overridden and the second is when it's a objects member function being overriden.
This one is similar to the one above except it wants an object, and then it finds the member function at what ever depth you tell it to execute.
03/08/2012 (1:23 pm)
Also,I figured there are two different type of parent:: calls, one is when it's just a lone function that is overridden and the second is when it's a objects member function being overriden.
This one is similar to the one above except it wants an object, and then it finds the member function at what ever depth you tell it to execute.
extern "C" __declspec(dllexport) void ParentCall(char* sim_object,char* function,S32 namespacedepth,char* ret,S32 argc,char ** _argv,bool debug)
{
dSprintf(ret,1024,"%s","");
SimObject* object = Sim::findObject(sim_object);
if (!object)
{
Con::errorf("Cannot find simobject");
return;
}
Namespace* ns = object->getNamespace();
for (int i = 0;i<=namespacedepth;i++)
{
ns = ns->getParent();
if (!ns)
{
Con::errorf("OOOPS... NAMESPACE NOT FOUND");
return;
}
if (debug)
Con::errorf("Digging NameSpace for object (%s), Found NameSpace (%s) at a depth of (%i) on way to destination (%i)",sim_object,ns->getName(), i,namespacedepth-1);
}
if (!ns)
{
Con::errorf("WARNING!!!! --->Cannot Find Namespace");
return;
}
std::vector<const char*> arguments;
for (int i =0;i<argc;i++)
{
if (debug)
Con::errorf("Adding '%s' to vector",_argv[i]);
arguments.push_back(_argv[i]);
}
const char** argv = &arguments[0];
StringTableEntry callMethod = StringTable->insert( function );
Namespace::Entry* funct = ns->lookup(callMethod);
if (!funct)
{
Con::errorf("Cannot find parent");
return;
}
const char* resultstring = funct->execute( argc,argv, &gEvalState);
if (dStrlen(resultstring)>0)
dSprintf(ret,1024,"%s",resultstring);
}
Torque Owner Vince Gee
WinterLeaf Entertainment