Jump to content
  • Advertisement
Sign in to follow this  
_Sigma

RegisterGlobalFunction - calling convention?

This topic is 4135 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

When using RegisterGlobalFunction, how does one decide what calling convention to use? I understand the differences between calling conventions, I just don't understand why I need to specify what one to use, if all my code is being compiled the same...obviously I've missed something - can anyone point me in the right direction? Cheers

Share this post


Link to post
Share on other sites
Advertisement
Different kinds of functions are called different ways. Specifically, members have an invisible this pointer that's not in the function's signature, but still needs to be passed. OBJLAST is the bastard child of CDECL and THISCALL, and just tells AngelScript to stick that this pointer on the end of the parameter list instead of the beginning.

Incidentally, a global function is always going to use CDECL or GENERIC.

Share this post


Link to post
Share on other sites
So is there a preference to use one over another? In your example, you said to stick 'this' at the end instead of the start. Why?

Cheers

Share this post


Link to post
Share on other sites
the compiler needs to know what object is going to be accessing it's own members, so instead of recreating the code per object, it adds the 'this' to the end of the call, and then, unknown to the coder, every access to an objects 'x' variable, becomes 'this->x' so that it knows who's 'x' to access. each calling convention has it's own set of rules that apply to it, which can be viewed here.
now, if I missed something here, or am incorrect about something, please inform me, because I don't really mess around with calling conventions often, and only have knowledge gained from reading about them.

hope it helps,
-Wynter Woods(aka Zerotri)

Share this post


Link to post
Share on other sites
zerotri - thank you. Will check that link out.

I guess I still don't understand when a should declare a function I am exposing to AS as STD or CDECL ... or other. Can you possibly give examples?

Share this post


Link to post
Share on other sites
Global function : CDECL
Member function : THISCALL
A global function in C++; but looks like a member function in AngelScript : OBJLAST
The above aren't implemented for your platform : GENERIC

Though, really, you need to do your own research about the this pointer. It's unlikely you have the theoretical basis to grok calling conventions just yet.

Share this post


Link to post
Share on other sites
Quote:
Original post by Deyja
Though, really, you need to do your own research about the this pointer. It's unlikely you have the theoretical basis to grok calling conventions just yet.

i'd agree. I know enough about it to know how it can pooch the stack at times, but past that... O_o

Thanks for the list. Very helpful!

Share this post


Link to post
Share on other sites
A global function in AngelScript and Member function in C++.

What call to do more correctly?

------------------------------------

int MyClass::Do(int tmp)
{
return 1;
}

asCSE->RegisterGlobalFunction("int Do(int tmp)", asMETHOD(MyClass, Do), ??????What Call??????);

------------------------------------

Share this post


Link to post
Share on other sites
Quote:
Original post by russian
A global function in AngelScript and Member function in C++.

What call to do more correctly?

------------------------------------

int MyClass::Do(int tmp)
{
return 1;
}

asCSE->RegisterGlobalFunction("int Do(int tmp)", asMETHOD(MyClass, Do), ??????What Call??????);

------------------------------------

THISCALL?

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!