Advertisement

Can't get method param's name at runtime

Started by June 16, 2015 06:41 PM
3 comments, last by dkrusu 9 years, 5 months ago

Hi, I'm trying to get information about a script class's methods and parameters. Getting the name of the method and then the type id of each of the parameters works just fine, but when I try to get the name or default arguments it gives me a nullptr. I saw in asIScriptFunction::GetParam you have a comment that says that it doesn't work with pre-compiled bytecode w/o debug symbols, but this wasn't pre-compiled. The size of parameterNames in asIScriptFunction is 0.

Thanks,

dkrusu

Is this for all script functions or just in some cases? What does the script function look like?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

Is this for all script functions or just in some cases? What does the script function look like?

None work, here is a test case


#include <angelscript.h>
#include <scripthelper.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

void MessageCallback(const asSMessageInfo *msg, void *param)
{
	const char *type = "ERR ";
	if( msg->type == asMSGTYPE_WARNING ) 
		type = "WARN";
	else if( msg->type == asMSGTYPE_INFORMATION ) 
		type = "INFO";

	printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
}

void printMethods(void *ref, int typeId)
{
    asIObjectType* objType = asGetActiveContext()->GetEngine()->GetObjectTypeById(typeId);
    uint32_t count = objType->GetMethodCount();
    for( uint32_t i=0; i<count; i++ )
    {
        asIScriptFunction* method = objType->GetMethodByIndex(i);
        uint32_t paramCount = method->GetParamCount();
        for( uint32_t j=0; j<count; j++ )
        {
            int paramTypeId;
            const char *paramName;
            method->GetParam(j, &paramTypeId, 0, &paramName);
            printf("%s\n", paramName);
        }        
    }
}

const char *script = 
            "class Test {\n"
            "   void test(int argumentName) { }\n"
            "}\n"
            "void test() {\n"
            "   Test t;\n"
            "   printMethods(t);\n"
            "}\n";

int main()
{
    asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
    engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL);

    int r = engine->RegisterGlobalFunction("void printMethods(?&in)", asFUNCTION(printMethods), asCALL_CDECL); assert(r>=0);
    asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);

    r = mod->AddScriptSection("script", script, strlen(script));assert(r>=0);
    r = mod->Build(); assert(r>=0);

    asIScriptContext* ctx = engine->CreateContext();
    ctx->Prepare(mod->GetFunctionByDecl("void test()"));
    ctx->Execute();

    engine->Release();

    return 0;

}

Am I doing something wrong?

Try getting the non-virtual function descriptor for the class method. That one should hold the name of the parameters.

asIScriptFunction* method = objType->GetMethodByIndex(I, false); // get actual method implementation

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Yes! Thanks for your excellent support and library.

This topic is closed to new replies.

Advertisement