Given the following script code:
class Foo
{
void test()
{
print("hello");
}
}
Foo foo;
If given the strings "foo" and "test", I'm trying to programmatically execute foo.test(); The instructions here are straightforward, except that they assume that you have a asIObjectType and that's what I'm getting stuck on.
asIScriptFunction* GetScriptMethodToExecute(void*& objAddressOut)
{
int varIdx = scriptModule.GetGlobalVarIndexByName("foo");
if ( varIdx == asNO_GLOBAL_VAR )
varIdx = scriptModule.GetGlobalVarIndexByDecl("foo");
if ( varIdx < 0 )
return NULL;
objAddressOut = scriptModule.GetAddressOfGlobalVar(varIdx);
// Here's where the trouble starts.. I need an asIObjectType*
// try 1
{
int typeId = 0;
scriptModule.GetGlobalVar(varIdx, NULL, NULL, &typeId, NULL);
// this returns NULL (though typeId seems OK)
asIObjectType* pType = scriptModule.GetObjectTypeByIndex(typeId);
}
// try 2
{
// this returns NULL
asIObjectType* pType = scriptModule.GetObjectTypeByIndex(varIdx);
}
// try 3
{
// Note: it looks like this is returning "Foo ::foo". Should the space be in there?
const char* varDecl = scriptModule.GetGlobalVarDeclaration(varIdx, true);
// this returns NULL
asIObjectType* pType = scriptModule.GetObjectTypeByDecl(varDecl);
}
// try 4
{
// this returns NULL
asIObjectType* pType = scriptModule.GetObjectTypeByDecl("Foo::foo");
}
// try 5
{
// this works!
asIObjectType* pType = scriptModule.GetObjectTypeByDecl("Foo");
}
// try 6
{
// Note: this returns "Foo foo"
const char* varDecl = scriptModule.GetGlobalVarDeclaration(varIdx, false);
// this returns NULL
asIObjectType* pType = scriptModule.GetObjectTypeByDecl(varDecl);
}
asIScriptFunction* pScriptFunc = pType->GetMethodByName("test");
if ( NULL == pScriptFunc )
{
pScriptFunc = pType->GetMethodByDecl("test");
}
return pScriptFunc;
}
Given the above script and "foo" and "test", how can I get the variable type's asIObjectType* most directly?
Thank you!