Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


- - - - -

Angelscript with Objective-C


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 noizex   Members   -  Reputation: 879

Like
0Likes
Like

Posted 02 December 2012 - 03:38 PM

Hello,

I recently tried to code something on iOS using Xcode and Objective-C. I thought it would be nice if I could hook scripting with AS into my game, but I encounter a lot of problems, most of them come from mixing Obj-C and C++ (Angelscript). I managed to compile AS and even create script engine, but thats as far as I can go with my limited knowledge.

For example how this should be handled in Obj-C class that's some kind of ScriptManager (creating engine, handling pool and message callback):
[source lang="cpp"] r = engine->SetMessageCallback(asMETHOD(CScriptMgr, MessageCallback), this, asCALL_THISCALL); assert( r >= 0 );[/source]
I have no idea how to pass Obj-C method to asMETHOD() macro. Can I even do this? If not, how should I "bridge" such things with AS C++ API?

Its even worse when it comes to registering Obj-C classes (NSString, GLKVector etc.) - I have no idea where to start.

Did anyone make a successful implementation of AS on iOS and has any example that would let me start with this? Because I couldn't find a clue regarding working with AS and Objective-C.

Thanks,

noizex

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3416

Like
0Likes
Like

Posted 02 December 2012 - 04:32 PM

AngelScript is successfully on iOS in several projects. Though I do not know the details of those projects I do believe they have been implemented with C++ rather than Objective-C.

Unfortunately my knowledge of Objective-C is very limited. Perhaps it would be easier to integrate AngelScript through a pure C interface? Note, the C interface is a bit outdated and would have to be updated to the latest version of AngelScript to work, but it should be quite easy to do so by following the existing work.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 noizex   Members   -  Reputation: 879

Like
0Likes
Like

Posted 02 December 2012 - 04:41 PM

AngelScript is successfully on iOS in several projects. Though I do not know the details of those projects I do believe they have been implemented with C++ rather than Objective-C.

Unfortunately my knowledge of Objective-C is very limited. Perhaps it would be easier to integrate AngelScript through a pure C interface? Note, the C interface is a bit outdated and would have to be updated to the latest version of AngelScript to work, but it should be quite easy to do so by following the existing work.


Yeah, I suppose they're written in C++ because mixing C++ and Obj-C in a way that would be required for AS to work is beyond sanity for me. Some weird bridges just to pass a callback, so I don't even think about registering everything I need for scripting. Would either end up with tons of bridging functions and even then I'm not sure it will work okay. C could be easier actually, because it more lightweight and it seems it works better with Obj-C than C++ classes, but it will be probably a hard work filled with void* and emptiness ;)

I think I will just give up on this idea, I use Angelscript successfully for my C++ cross-platform project, so I wanted to try it in this little iOS project, but it seems that difficulty of implementing it with Obj-C outweights any benefits of scripting for such a simple game. I'll probably code game logic in a time that will take me to register some basic functionality with Obj-C++.

#4 Andreas Jonsson   Moderators   -  Reputation: 3416

Like
1Likes
Like

Posted 03 December 2012 - 07:23 AM

After reading up a little on Objective-C and Objective-C++ I understand that it is not possible to bind Objective-C class methods directly with AngelScript. Even if it is possible to somehow take the address of an Objective-C class method the way Objective-C works is completely different from C++. In Objective-C communication between classes are done through messaging and not direct calls of the class methods as is done in C++.

However, as Objective-C++ can include C++ code in the same program it should be straightforward to write global proxy functions that bridge the AngelScript to Objective-C interface. If you're using Objective-C then you will have to use the C interface for AngelScript, as Objective-C don't understand C++ code.

Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS