So, one of the "details" that are wrong is that we don't support multiple
isolated engines in a single process.
It's actually quite simple to do so via DLR Hosting API. The main concept here
is ScriptRuntime. This class represents the world for a dynamic language. The
class holds on loaded assemblies, .NET namespace references, etc. Each language
could also associate its own global state with the runtime. IronRuby has all
Ruby global state there: global variables table, class hierarchy etc. So,
unless you use CLR interop, there is no way how the script could get outside
this sandbox. If you want to isolate the runtimes even more (for CLR interop)
you can always create a ScriptRuntime inside a separate app-domain.
Let's show some example (a self-contained C# source code of a simple IronRuby
host follows):
using System.IO;
using Microsoft.Scripting.Hosting;
class RubyHostingExample {
public static void Main() {
const string write = @"C:\Temp\write.rb";
const string read = @"C:\Temp\read.rb";
File.WriteAllText(write, @"
$x = 'Hello from runtime #1!'
C = 'some constant'
module Kernel
def say_bye
puts 'bye'
end
end
");
File.WriteAllText(read, @"
puts $x
if defined? C
puts C
else
puts 'C not defined'
end
say_bye rescue puts $!
puts
");
ScriptRuntime runtime1 = ScriptRuntime.Create();
ScriptRuntime runtime2 = ScriptRuntime.Create();
runtime1.ExecuteFile(write);
runtime2.ExecuteFile(read);
runtime1.ExecuteFile(read);
}
}
---
Let's compile and run it:
C:\IronRuby\Bin\Debug>csc /r:Microsoft.Scripting.dll
/r:Microsoft.Scripting.Core.dll /r:IronRuby.dll rt.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.21022.8
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
C:\IronRuby\Bin\Debug>rt.exe
nil
C not defined
undefined local variable or method `say_bye' for main:Object
Hello from runtime #1!
some constant
bye
---
And if you want app-domain isolation, just do
ScriptRuntime.Create(System.AppDomain.CreateDomain("foo")).
That was easy, wasn't it?
Tomas
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Lam
(IRONRUBY)
Sent: Monday, April 28, 2008 7:05 AM
To: [email protected]
Subject: Re: [Ironruby-core] Regarding IronRuby... How true it sounds from this
blog
Sanghyeon Seo:
> It seems to be a rather good overview of the status to me. I mostly
> agree, except for the accusation that "Microsoft would never back an
> OSS web framework like Rails in preference to its own".
He also gets a number of important technical details wrong about IronRuby, I'll
respond later today.
Thanks,
-John
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core