How to get the name of the object?

Started by
4 comments, last by virious 13 years, 2 months ago
Referring to the "Debugging scripts" section in the manual, you wrote this code:

void PrintVariables(asIScriptContext *ctx, asUINT stackLevel)
{
asIScriptEngine *engine = ctx->GetEngine();

// First print the this pointer if this is a class method
int typeId = ctx->GetThisTypeId(stackLevel);
void *varPointer = ctx->GetThisPointer(stackLevel);
if( typeId )
{
printf(" this = 0x%x\n", varPointer);
}


How can I obtain the current object name?
Advertisement
ctx->GetFunction()->GetObjectName();´

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


ctx->GetFunction()->GetObjectName();´


Example code:
MyClass exampleObject(5);
With breakpoint set in MyClass constructor, your code returned "MyClass" instead of "exampleObject".
AngelScript is lexically scoped. Inside the constructor (or any other object method) the name of the current object will always be "this".
So you want to know the name of the variable which was used to invoke the class method? That isn't possible. I mean you can always try to scan the local variables in the caller on the callstack to see if any of them matches the this pointer. However, many times the this pointer is for a temporary object, or in the case of a constructor the this pointer is not stored in a variable until the constructor is completed.

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

I just solved it as it works in Visual Studio etc. and also as SiCrane suggested, I just return "this" in that case. Thanks for your answers :).

This topic is closed to new replies.

Advertisement