IronRuby и C #, исполняемый файл - PullRequest
0 голосов
/ 28 августа 2011

Почему эта работа:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using IronRuby;

class Tutorial
{
    static void Main(string[] args)
    {
       var engine = Ruby.CreateEngine();
       engine.Runtime.Globals.SetVariable("Holly",new Holly("Test"));
       engine.Execute("Holly.Say");
       Console.ReadLine();
   }
}
class Holly
{
   string speech;
   public Holly(string speech)
   {
       this.speech = speech;
   }
   public void Say()
   {
       Console.WriteLine("Hollu said " + this.speech);
   }
}

и это не работает

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using IronRuby;

class Tutorial
{
    static void Main(string[] args)
    {
       var engine = Ruby.CreateEngine();
       engine.Runtime.Globals.SetVariable("Mouse",new Holly("Test"));
       engine.ExecuteFile("./test.rb");
       Console.ReadLine();
   }
}
class Holly
{
   string speech;
   public Holly(string speech)
   {
       this.speech = speech;
   }
   public void Say()
   {
       Console.WriteLine("Hollu said " + this.speech);
   }
}

1 Ответ

0 голосов
/ 28 августа 2011

Попробуйте это

engine.ExecuteFile(@"..\test.rb");

Также добавьте код в оператор try / catch и проверьте исключение

try
{
    var engine = Ruby.CreateEngine();
    engine.Runtime.Globals.SetVariable("Holly",new Holly("Test"));
    engine.ExecuteFile(@"..\test.rb");
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}
...