Really stumped on "GameCore::createGame();"
by Vince Gee · in Torque 3D Professional · 05/16/2012 (8:57 am) · 3 replies
The syntax GameCore::CreateGame as far as I understood meant to lookup the GameCore Package, and execute the function named CreateGame.
The code below finds the namespace, but the namespace doesn't have any functions in it's mEntryList, so it can't find the function.
I am really at a loss, I have a work around, but does anyone have a clue what I'm missing?
The code below finds the namespace, but the namespace doesn't have any functions in it's mEntryList, so it can't find the function.
I am really at a loss, I have a work around, but does anyone have a clue what I'm missing?
extern "C" __declspec(dllexport) void CallFunctNameSpace(char* snamespace,char* function,char* ret,S32 argc,char ** _argv,bool debug)
{
dSprintf(ret,1024,"%s","");
StringTableEntry sns = StringTable->insert( snamespace );
StringTableEntry callMethod = StringTable->insert( function );
if (!Con::isFunction(callMethod))
{
Con::errorf("Function Does not exist!");
return;
}
else
if (debug)
Con::errorf("------>Found Function!!!");
Namespace* ns = Namespace::find(sns,sns);
/*Namespace* ns =Namespace::global()->lookup(callMethod)->mNamespace ;
if (!ns)
{
Con::errorf("Namespace not working");
return;
}*/
bool found = false;
while (ns)
{
Con::errorf("Current package is '%s'",ns->mPackage);
if (ns->mPackage==sns)
{
Con::errorf("Found Package %s %s",ns->mPackage,sns);
found = true;
break;
}
ns = ns->getParent();
}
if (!ns)
{
Con::errorf("Namespace not working");
return;
}
if (!found)
{
Con::errorf("Namespace not found %s",sns);
return;
}
Namespace::Entry* funct=NULL;
///Con::errorf("----%s ",ns->mEntryList->mFunctionName);
for(Namespace::Entry *ewalk = ns->mEntryList; ewalk; ewalk = ewalk->mNext)
{
Con::errorf("%s", ewalk->mFunctionName);
if ( ewalk->mFunctionName==callMethod)
{
funct=ewalk;
break;
}
}
if (!funct)
{
Con::errorf("Cannot find Namespace Function (%s)::(%s)",sns,callMethod);
return;
}
if (debug)
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];
/*ns->dumpFunctions();
Namespace::Entry* funct = ns->lookup(callMethod);*/
//Con::errorf("Calling Function");
const char* resultstring = funct->execute( argc,argv, &gEvalState);
if (resultstring)
if (dStrlen(resultstring)>0)
dSprintf(ret,1024,"%s",resultstring);
arguments.clear();
}About the author
www.winterleafentertainment.com
#2
I found it, wow, simple now...
05/16/2012 (7:53 pm)
@Frank,I found it, wow, simple now...
extern "C" __declspec(dllexport) void Classname_Call(char* className,char* function, S32 argc,char ** _argv,char* ret,bool debug)
{
dSprintf(ret,1024,"%s","");
StringTableEntry nameSpace = StringTable->insert(className);
StringTableEntry name = StringTable->insert(function);
Namespace* ns = NULL;
if (!nameSpace || !dStrlen(nameSpace))
ns = Namespace::mGlobalNamespace;
else
{
nameSpace = StringTable->insert(nameSpace);
ns = Namespace::find(nameSpace); //can specify a package here, maybe need, maybe not
}
if (!ns)
{
Con::errorf("ERROR: Unable call function (%s) because Namespace (%s) not found.",name,nameSpace);
return ;
}
name = StringTable->insert(name);
Namespace::Entry* entry = ns->lookupRecursive(name);
if (!entry)
{
Con::errorf("ERROR: Unable to call function (%s::%s), cannot find entry for function.",nameSpace,name);
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];
if (debug)
Con::errorf("Calling function %s::%s",nameSpace,name);
const char* resultstring = entry->execute( argc,argv, &gEvalState);
if (resultstring)
if (dStrlen(resultstring)>0)
dSprintf(ret,1024,"%s",resultstring);
arguments.clear();
}
Torque Owner Demolishun
DemolishunConsulting Rocks!
- When is this function running? Has the function been created yet?
- isFunction is a global lookup.
- Go into c_scripting.cpp and look at this function: "script_get_namespace_entry" It should help give you some ideas.
Here is the code for isFunction, it does not search against the namespace:bool isFunction(const char *fn) { const char *string = StringTable->lookup(fn); if(!string) return false; else return Namespace::global()->lookup(string) != NULL; }