开发者

Language Interoperability in .NET (CLR) and Mono

开发者 https://www.devze.com 2022-12-22 18:53 出处:网络
Let\'s say I need to use Python and C开发者_如何学JAVA++. I can call Python function from C++ with Python C API, and reverse is possible with SWIG or equivalent.

Let's say I need to use Python and C开发者_如何学JAVA++. 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?


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)


  • .Net methods can call native methods using Platform Invoke or COM Interop.
  • Native code can call .Net code by exporting a native DLL export or by exporting the assembly as a COM component.

I don't know about Mono.

0

精彩评论

暂无评论...
验证码 换一张
取 消