tags:

views:

182

answers:

2

Let's say I need to use Python and C++. I can call Python function from C++ with Python C API, and reverse is possible with SWIG or equivalent.

How about .NET? I know there are IronPython and C# that finally produces .NET assembly. Is there any well-defined language interoperability mechanism in .NET so that one can use whatever function calls from whatever language?

  • If so, what are the mechanisms for that?
  • If not, what one can do to call functions from one language to another?
  • The .NET mechanism is the same as MONO in terms of language interoperability?
A: 

I don't know about Mono.

SLaks
+4  A: 

If you're talking about IronPython and C#, then the two languages can interoperate seamlessly via the CLI (that is, the Common Language Infrastructure). That means, the methods in the C# code are directly accessible from IronPython and vice versa.

For other languages that don't compile to .NET bytecode directly (e.g. Lua), then you will have to use P/Invoke to call the C API (or use one that someone else has already written, like LuaInterface for Lua).

Mono is basically the same, you just have to be careful with your P/Invoke declarations (i.e. you can't reference "lua51 .dll" because Linux has .so files, not .dll files)

Dean Harding
Mono automatically remaps the shared library names from lib.dll to whatever convention is used by the current operating system (lib.so on Linux, lib.dylib on OSX, etc), so you just need to have around a compatible shared library for the target operating system.
lupus
Oh, I didn't know that. I know if you just used "lib" instead of "lib.dll" or "lib.so" then it would work for both, but I guess that makes sense.
Dean Harding