Jump to content
  • Advertisement
Sign in to follow this  

Call methods of C++ class in iPhone

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

Hi, I'm trying to use AngelScript in an iPhone game that we are doing but we are having some problems. I'm beeing able to call global functions in the script but I'm not being able to call methods of a C++ class. Can it be a restriction when running AS in iphone? I had some compiling problems before ( you can see the thread here http://www.gamedev.net/community/forums/topic.asp?topic_id=569572 ) and I'm thinking that maybe that can be related. I know that in this forum there are some users that could use AS in iphone... Did they have problems registering C++ methods in AS engine? I'll appreciate any help. I really want to use AS in my project. Thanks a lot!

Share this post

Link to post
Share on other sites
If it is specific to class methods, then it is possible that nobody tried that yet.

If anyone has any ideas or can confirm if registering class methods work properly on the iPhone I would very much appreciate if you could let us know.

I wish I could investigate this myself, but I do not have an iPhone, and you said in the other thread that it works on the simulator, so unfortunately I'll have to rely on the community to help with this.

Share this post

Link to post
Share on other sites
I needed the fix and I think I found it, at least it is working on my iPhone :)

I can confirm the problem is on Class Methods and they are threatened as if they were virtual ...

if( base == asCALL_THISCALL )
internal->callConv = ICC_THISCALL;
if( (size_t(ptr.ptr.f.func) & 1) )
internal->callConv = ICC_VIRTUAL_THISCALL; // Here it was wrongly setting as virtual
internal->baseOffset = ( int )MULTI_BASE_OFFSET(ptr);
#if defined(AS_ARM) && defined(__GNUC__)
// As the least significant bit in func is used to switch to THUMB mode
// on ARM processors, the LSB in the __delta variable is used instead of
// the one in __pfn on ARM processors.
if( (size_t(internal->baseOffset) & 1) )
internal->callConv = ICC_VIRTUAL_THISCALL;

[color="#77482d"][color="#000000"][font="arial, verdana, tahoma, sans-serif"]What I did to fix it was to go to as_config.h and added this line at line 533[/font]

#undef GNU_STYLE_VIRTUAL_METHOD // added by Pogacha

[font="Menlo"][size=2]Just under this:
[/font]#elif (defined(_ARM_) || defined(__arm__))
// The IPhone use an ARM processor
#define AS_ARM
#define AS_IPHONE
#define AS_ALIGN

#undef GNU_STYLE_VIRTUAL_METHOD // added by Pogacha
[font="arial, verdana, tahoma, sans-serif"][color="#000000"][font="Menlo"]
[font="arial, verdana, tahoma, sans-serif"]And everything started working :)[/font][/font][/font]

A question that would help me:
Does native calling convention works on Android?

Share this post

Link to post
Share on other sites

This has been a known bug for a long time now. Thank you very much for finding the solution. I'll have it checked in as soon as possible.

As far as I know native calling conventions are working on Android OS as well. At least when using the GNUC compiler and the phone is using the ARM processor.



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!