Integration of C #, F #, IronPython and IronRuby

I was told that assembly files created from C # and F # source are compatible because they are compiled into a .NET assembly.

  • Q1: Does this mean that C # can call F # functions in the same way as C # functions?
  • Q2: What about IronPython and IronRuby? I do not see assembly DLLs from IronPython / IronRuby.
  • Q3: Is there an easy way to use IronPython / IronRuby functions from C # or F #?

Any code sample would be great.

+5
source share
3 answers

1) Yes. Using a simple example, in F # I can call the main method of a C # console application:

open SampleApp

SampleApp.Program.Main([| "Hello"; "World" |])

2) DLR, , -. , Python ();

ScriptEngine engine = Python.CreateEngine();
ScriptSource script = engine.CreateScriptFromSourceFile("myPythonScript.py");
ScriptScope scope = engine.CreateScope();

script.Execute(scope);

, .

3) DLL DLL-, #/F #, . Microsoft DLR.

+5

, # F # .NET.

, F # #. F # .. #, .

IronPython/Ruby #, . :

http://www.highoncoding.com/Articles/573_First_Look_at_the_IronRuby.aspx

+3

Q3: IronPython/IronRuby # F #?

You can take a look at Deploying IronPython in a C # application

Basically what it does (simplified code):

var engine = Python.CreateEngine();
var scriptSource = engine.CreateScriptSourceFromString(@"
def foo(s):
  print s", SourceCodeKind.Statements);

var scope = engine.CreateScope();
scriptSource.Execute(scope);

//Get a reference to the function
Func<string, decimal> foo = scope.GetVariable<Func<string, decimal>>("foo");

//Execute it
Console.WriteLine(foo("a"));
+2
source

All Articles