5

I was just wondering how API's can be shared between different Programming languages.

I mean, MS have .Net which uses VB.net C# and various other technologies.
I doubt .Net is written for each programming language.
How are structs and classes shared between languages?

Also the same for Unity3D - Javascript shares API's with C# and BOO.
How?

gnat
  • 21,442
  • 29
  • 112
  • 288
  • This topic may be relevant: http://programmers.stackexchange.com/questions/157536/how-can-i-write-a-set-of-functions-that-can-be-invoked-from-almost-any-program – Anderson Green Jul 26 '12 at 17:06

2 Answers2

6

They're based on the Common Language Infrastructure, or CLI. It's basically a virtual machine where all of these languages compile to the same bytecode and read out assemblies which are in terms of the CLI. This provides an abstraction over the source and target language.

DeadMG
  • 36,794
  • 8
  • 70
  • 139
1

There are two basic approaches. One is to compile to virtual machine bytecode, so you basically need a compiler for every targeted language. The other is to create what's called a language "binding" using a native interface. Most languages have a way to link with native code, so you make an implementation in C, for example, then make a wrapper API in the target language that translates the calls and data structures to the C API.

Karl Bielefeldt
  • 146,727
  • 38
  • 279
  • 479
  • There's no reason at all to implement in C- every language can export to a C interface as well as import them. – DeadMG Apr 23 '12 at 10:34