[Ironruby-core] Still plugging away at some simple IronRuby stuff
Michael Letterle
michael.letterle at gmail.com
Mon Jan 28 08:26:51 EST 2008
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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[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 Akins <angrygreg at gmail.com> wrote:
> OK, I'm making progress.. Though my wife just got home, so this might
> not last much longer ;-)
>
> 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 Akins
> Software Development Manager
> SSI Services
>
> http://kc.vanadium.com
> http://www.pghcodingdojo.org
> http://www.insomnia-consulting.org/monologue
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
--
Michael Letterle
[Polymath Programmer]
http://michaeldotnet.blogspot.com
More information about the Ironruby-core
mailing list