Thursday, March 10, 2011

Calling IronRuby in F# on Mono

This is just a hobby, but wonderful. Mono 2.10 only can do it as out-of-the-box!
Microsoft (R) F# 2.0 Interactive build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> #r "/Library/Frameworks/Mono.framework/Versions/Current/lib/ironruby/bin/IronRuby.dll";;

--> Referenced '/Library/Frameworks/Mono.framework/Versions/Current/lib/ironruby/bin/IronRuby.dll'

> #r "/Library/Frameworks/Mono.framework/Versions/Current/lib/ironruby/bin/IronRuby.Libraries.dll";;

--> Referenced '/Library/Frameworks/Mono.framework/Versions/Current/lib/ironruby/bin/IronRuby.Libraries.dll'

> #r "/Library/Frameworks/Mono.framework/Versions/Current/lib/ironruby/bin/Microsoft.Scripting.dll";;   

--> Referenced '/Library/Frameworks/Mono.framework/Versions/Current/lib/ironruby/bin/Microsoft.Scripting.dll'

> open IronRuby;;
> let runtime = IronRuby.Ruby.CreateRuntime();;          

val runtime : Microsoft.Scripting.Hosting.ScriptRuntime

> let engine = runtime.GetEngine("Ruby");;
Binding session to '/Library/Frameworks/Mono.framework/Versions/Current/lib/ironruby/bin/IronRuby.Libraries.dll'...
val engine : Microsoft.Scripting.Hosting.ScriptEngine

> engine.Execute("class Hello;def world;'Hello World';end;end");;
val it : obj = null
> engine.Execute("puts Hello.new.world");;
Hello World
val it : obj = null

No comments:

Post a Comment