Jump to content
  • Advertisement
Sign in to follow this  
virious

How to get the name of the object?

This topic is 2764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

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


Example code:
MyClass exampleObject(5);
With breakpoint set in MyClass constructor, your code returned "MyClass" instead of "exampleObject".

Share this post


Link to post
Share on other sites
AngelScript is lexically scoped. Inside the constructor (or any other object method) the name of the current object will always be "this".

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!