Question

I know Objective-C++ can exist because Objective-C and C++ share common ground in C. But how can Objective-C coexist with Python? I know it must be possible because wxPython uses Cocoa to draw interfaces.

I'm writing a card game engine for OS X. It will be able to play more than one game (Klondike, Spider, Free Cell, maybe even Hearts or Poker). It's going to work with Game Center, so I need to have the Cocoa framework available, but I'd like to write a Python API, so I can write the games themselves in Python (because it's easier to use and more dynamic). How would I go about implementing that sort of language blend in my own application?

Was it helpful?

Solution

If a Python application uses compiled external libraries, then this is extending Python. The documentation for doing that is here.

If a compiled application uses Python for scripting, then this is embedding Python. The documentation for doing that is here.

OTHER TIPS

I'm not an expert on Cocoa, but I think you misunderstood the sense of using it. Cocoa is just a library that exports some functions. It is usable from anything that is capable of understanding the functions' signatures. It does not mean that that thing must be objective-C compatible. It just means that it must be capable of understanding the call-convention..

I'm quite sure however, that Python can run both on standard-C and on ObjC runtime (as IIRC it is extension to the former), so I dont see why would it be impossible to make Cocoa bindings for Python.. Apple seems to support it https://developer.apple.com/technologies/mac/cocoa.html

Objective-C’s dynamic runtime is similar to many modern scripting languages, making it easy to map Cocoa’s features to other languages using the Cocoa Bridge. With the Cocoa Bridge, developers can create first-class Mac OS X applications using AppleScript, Ruby, and Python.

So, your next keyword to check is: Cocoa Bridge and maybe https://developer.apple.com/cocoa/pyobjc.html too?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top