C# アプリケーションで RubyGem を使用したいと考えています。
IronRuby をダウンロードしましたが、起動して実行する方法がわかりません。ダウンロードには ir.exe が含まれており、IronRuby.dll などのいくつかの DLL が含まれています。
.NET プロジェクトで IronRuby.dll が参照されたら、*.rb ファイルのオブジェクトとメソッドを C# コードに公開するにはどうすればよいですか?
どうもありがとう、
マイケル
これが相互運用の方法です。
IronRuby
、、およびへIronRuby.Libraries
の参照があることを確認してくださいMicrosoft.Scripting
Microsoft.Scripting.Core
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IronRuby;
using IronRuby.Builtins;
using IronRuby.Runtime;
namespace ConsoleApplication7 {
class Program {
static void Main(string[] args) {
var runtime = Ruby.CreateRuntime();
var engine = runtime.GetRubyEngine();
engine.Execute("def hello; puts 'hello world'; end");
string s = engine.Execute("hello") as string;
Console.WriteLine(s);
// outputs "hello world"
engine.Execute("class Foo; def bar; puts 'hello from bar'; end; end");
object o = engine.Execute("Foo.new");
var operations = engine.CreateOperations();
string s2 = operations.InvokeMember(o, "bar") as string;
Console.WriteLine(s2);
// outputs "hello from bar"
Console.ReadKey();
}
}
}
Runtimeには、ファイルの実行に使用できるExecuteFileがあることに注意してください。
宝石を動かすには
igem.exe