Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How interoperability works

I know that many large-scale applications such as video games are created using multiple langages. For example, it's likely the game/physics engines are written in C++ while gameplay tasks, GUI are written in something like Python or Lua.

I understand why this division of roles is done; use lower-level languages for tasks that require extreme optimization, tweaking, efficiency and speed, while using higher-level languages to speed up production time, reduce nasty bugs ect.

Recently, I've decided to undertake a larger personal project and would like to divy-up parts of the project similar to above. At this point in time, I'm really confused about how this interoperability between languages (especially compiled vs interpreted) works.

I'm quite familiar with the details of going from ANSCII code test to loading an executable, when written in something like C/C++. I'm very curious at how something like a video game, built from many different languages, works. This is a large/broad question, but specifically I'm interested in:

  • How does the code-level logic work? I.e. how can I call Python code from a C++ program? Especially since they don't support the same built-in types?
  • What does the program image look like? From what I can tell, a video game is running in a single process, so what does the runtime image look like when running a C/C++ program that calls a Python function?
  • If calling code from an interpreted language from a compiled program, what are the sequence of events that occur? I.e If I'm inside my compiled executable, and for some reason have a call to an interpreted language inside a loop, do I have to wait for the interpreter every iteration?

I'm actually finding a hard time finding information on what happening at the machine-level, so any help would be appreciated. Although I'm curious in general about interoperation of software, I'm specifically interested in C++ and Python interaction.

Thank you very much for any insight, even if it's just pointing me to where I can find more information.

like image 289
gone Avatar asked Jul 06 '13 20:07

gone


People also ask

What are the three types of interoperability?

There are four levels of interoperability: foundational, structural, semantic, and organizational.

What makes interoperability possible?

For two systems to be interoperable, they must be able to exchange data and subsequently present that data such that it can be understood by a user.”

What is interoperability and how product or system achieves interoperability?

Interoperability refers to the basic ability of different computerized products or systems to readily connect and exchange information with one another, in either implementation or access, without restriction.

Why is interoperability needed?

Interoperability is defined as the ability for computer software to communicate with one another for the effective exchange and process of information. The purpose of interoperability is to make it so that different systems are able to “talk” and “understand” the information they pass to one another.


1 Answers

In the specific case of python, you have basically three options (and this generally applies across the board):

  1. Host python in C++: From the perspective of the C++ programme, the python interpreter is a C library. On the python side, you may or may not need to use something like ctypes to expose the C(++) api.

  2. Python uses C++ code as DLLs/SOs - C++ code likely knows nothing of python, python definitely has to use a foreign function interface.

  3. Interprocess communication - basically, two separate processes run, and they talk over a socket. These days you'd likely use some kind of web services architecture to accomplish this.

like image 78
Marcin Avatar answered Sep 25 '22 21:09

Marcin