Sign in to follow this  
Umiko

Call methods of C++ class in iPhone

Recommended Posts

Umiko    100
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
WitchLord    4677
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
Pogacha    122
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 ...


[code]#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[/code]

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

[code] #undef GNU_STYLE_VIRTUAL_METHOD // added by Pogacha[/code]

[font="Menlo"][size="3"][size=2]Just under this:
[/size][/size][/font][code]#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
[/code][font="arial, verdana, tahoma, sans-serif"][size="3"][color="#000000"][font="Menlo"][size="3"]
[font="arial, verdana, tahoma, sans-serif"][size="3"]And everything started working :)[/size][/font][/size][/font][/color][/size][/font]

[b]A question that would help me:
Does native calling convention works on Android?[/b]

Share this post


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