That looks good for hosting code that can switch between languages  
easily. If you're just using Ruby, you can use  
IronRuby.Ruby.CreateEngine() instead of getting the engine by string,  
but I'd suggest staying with what you have; you can change to other  
languages easily.

For running code from strings, you don't necessarily need to create a  
ScriptSource; you can use engine.Execute(string, ScriptScope) instead.  
Creating a script source are for the cases where you want to compile  
the code and store it before executing, or you want to change the mode  
of source code execution (file, interactive, expressions, etc).

There is a dlr hosting spec on dlr.codeplex.com that shows various  
hosting scenarios and how the code should look.

Let us know if you have any other questions about hosting. I showed  
hosting at RubyConf this year, so keep an eye out for that blog post  
(I'll send mail to this list when it's done).

~Jimmy
Sent from my phone

On Nov 29, 2009, at 9:11 AM, "はしもとけんいち"  
<ken1hasim...@gmail.com> wrote:

> Hello, I'm kenichi hashimoto.
> I'm a Japanese. I don't write english well.
>
> Now I have a question about a canonical style for writing the IronRuby
> hosting code.
>
> [BACKGROUND]
> Now, I'm tring to host the IronRuby 1.0RC on C#.NET (Visual Studio  
> 2008).
> And, I have been trying to host it since IronRuby 0.5.
> However, I haven't understood about how to write code in right style  
> yet.
>
> [QUESTION]
> Could you please teach a canonical style for writing the IronRuby  
> hosting code.
>
> Now, I wrote below:
>
>    static void Main(string[] args)
>    {
>        // create the IronRuby engine.
>        ScriptRuntime runtime = IronRuby.Ruby.CreateRuntime();
>        var engine = runtime.GetEngine("rb");
>
>        // create the scope and set the local variable from C#
>        var scope = engine.CreateScope();
>        scope.SetVariable("x", 123);
>
>        // set the global variable from C#
>        IronRuby.Ruby.GetExecutionContext(engine).DefineGlobalVariable 
> ("xxx",
> 789);
>
>        // execute the script with the scope
>        var source = engine.CreateScriptSourceFromString(@"puts ""x is
> #{x}. $xxx is #{$xxx}."" ");
>        source.Execute(scope);
>
>        Console.ReadLine();
>    }
>
> Is it a canonical style?
>
> Thank you.
> B.R. Kenichi HASHIMOTO
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core@rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to