Still plugging away at some simple IronRuby stuff

OK, I’m making progress… Though my wife just got home, so this might
not last much longer :wink:

I am following the example at
http://ironruby.rubyforge.org/wiki/wiki.pl?ExecutingIronRubyFromCSharp

NOTE: I tried to be helpful and update that page with the examples
that were just posted to the list, but now the page includes this the
IScriptModule().SetVariable code - which doesn’t appear to be valid
anymore)

This is what I’m using instead and I get a MissingMethod error on
widget. I’d try using this method (
scriptenvironment.ExecuteSourceUnit(rubyengine.CreateScriptSourceFromString(script)
); ) but CreateScriptSourceFromString doesn’t appear to have a
signature for IScriptModule, or IScriptScope.

Thoughts?

       IScriptEnvironment scriptenvironment =

ScriptEnvironment.GetEnvironment();
IScriptEngine rubyengine =
scriptenvironment.GetEngine(“ruby”);

       string script = "puts 'Ruby and  ' + widget.to_s + '

together at last’";
IScriptScope scope = scriptenvironment.CreateScope();
scope.SetVariable(“widget”, “.Net”);
rubyengine.Execute(scope,
rubyengine.CreateScriptSourceFromString(script));
Console.ReadKey();


Greg A.
Software Development Manager
SSI Services

http://kc.vanadium.com
http://www.pghcodingdojo.org
http://www.insomnia-consulting.org/monologue

IScriptModule is now IScriptScope from what I understand. I couldn’t
figure out how to create or access local or instance variables, but
you can use a global.

I got this:

using System;
using Ruby;
using Ruby.Runtime;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
namespace RubyExample
{
static class Program
{
///


/// The main entry point for the application.
///

[STAThread]
static void Main()
{
IScriptEngine rubyengine =
IronRuby.GetEngine(IronRuby.CreateRuntime());
IronRuby.GetExecutionContext(rubyengine.Runtime).GlobalVariables[SymbolTable.StringToId(“widget”)]
= “.NET”;
rubyengine.Execute(rubyengine.CreateScope(),
rubyengine.CreateScriptSourceFromString(“puts ‘Ruby and ’ +
$widget.to_s + ’ together at last’”));

        Console.ReadKey();


    }
}

}

On Jan 27, 2008 8:30 PM, Greg A. [email protected] wrote:

       IScriptEngine rubyengine = scriptenvironment.GetEngine("ruby");

[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com

On Jan 27, 2008 8:30 PM, Greg A. [email protected] wrote:

I am following the example at
http://ironruby.rubyforge.org/wiki/wiki.pl?ExecutingIronRubyFromCSharp

NOTE: I tried to be helpful and update that page with the examples
that were just posted to the list, but now the page includes this the
IScriptModule().SetVariable code - which doesn’t appear to be valid
anymore)

FYI, I just updated this page to fix the problem I caused last weekend.


Greg A.
Software Development Manager
SSI Services

http://kc.vanadium.com
http://www.pghcodingdojo.org
http://www.insomnia-consulting.org/monologue

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs