Sign in to follow this  
virious

How to get the name of the object?

Recommended Posts

Referring to the "[url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_debug.html"]Debugging scripts[/url]" section in the manual, you wrote this code:

[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);
}[/code]

How can I obtain the current object name?

Share this post


Link to post
Share on other sites
[quote name='WitchLord' timestamp='1298412985' post='4777727']
[code]ctx->GetFunction()->GetObjectName();´[/code]
[/quote]

Example code:
[code]MyClass exampleObject(5);[/code]
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this