# 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.

## 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 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 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 ...

#ifndef AS_NO_CLASS_METHODS if( base == asCALL_THISCALL ) { internal->callConv = ICC_THISCALL; #ifdef GNU_STYLE_VIRTUAL_METHOD if( (size_t(ptr.ptr.f.func) & 1) ) internal->callConv = ICC_VIRTUAL_THISCALL; // Here it was wrongly setting as virtual #endif 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; #endif

[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 #define CDECL_RETURN_SIMPLE_IN_MEMORY #define STDCALL_RETURN_SIMPLE_IN_MEMORY #define THISCALL_RETURN_SIMPLE_IN_MEMORY #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 on other sites
Great!!!!

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.

Regards,

Andreas

##### Share on other sites
I've checked in the fix in revision 833.

Thanks!

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631739
• Total Posts
3001957
×