グーグル先生に確認したら、そのままずばり、Reflector on Mono 1.2.3 というブログエントリを発見。ということで、実績はあるようなので安心して導入。
こんな感じ。バージョンは、5.1.6.0。
日々の思いつきと行動の記録を駄文で書き散らかしてみる
alias mir='mono $HOME/work/mono/ironruby-0.9.1/bin/ir.exe'
alias migem='mono $HOME/work/mono/ironruby-0.9.1/bin/ir.exe $HOME/work/mono/ironruby-0.9.1//bin/igem'で、Rake は
alias mirake='mono $HOME/work/mono/ironruby-0.9.1/bin/ir.exe $HOME/work/mono/ironruby-0.9.1//bin/irake'にした。
$ mirake
/Users/luckval/work/mono/ironruby-0.9.1/bin/../lib/ruby/site_ruby/1.8/rubygems.rb:827:in `report_activate_error': Could not find RubyGem rake (>= 0)
(Gem::LoadError)
from /Users/luckval/work/mono/ironruby-0.9.1/bin/../lib/ruby/site_ruby/1.8/rubygems.rb:261:in `activate'
from /Users/luckval/work/mono/ironruby-0.9.1/bin/../lib/ruby/site_ruby/1.8/rubygems.rb:68:in `gem'
from /Users/luckval/work/mono/ironruby-0.9.1//bin/irake:22
$ migem install rakeなんか、RDocのインストールにやたらと時間がかかったけど、無事完了。
1 gem installed
Installing ri documentation for rake-0.8.7...
Installing RDoc documentation for rake-0.8.7...
real 0m17.525s1つのタスクを実行するのに、17秒もかかってちゃだめやん。Windows 環境だともう少し速いような気がするけど、どうだったかな?明日しらべてみよ。
user 0m17.326s
sys 0m0.569s
$ vim winform_contextmenu.rb
1 require 'System'
2 require 'System.Windows.Forms'
3
4 Form = System::Windows::Forms::Form
5 Application = System::Windows::Forms::Application
6 MessageBox = System::Windows::Forms::MessageBox
7 ContextMenuStrip = System::Windows::Forms::ContextMenuStrip
8 ToolStripMenuItem = System::Windows::Forms::ToolStripMenuItem
9
10 class TestForm < Form
11 def initialize
12 self.Text = "Hello World Form"
13
14 cms = ContextMenuStrip.new
15 item = ToolStripMenuItem.new "hello"
16 item.click { MessageBox.show "hello" }
17 cms.items.add item
18 self.ContextMenuStrip = cms
19
20 end
21 end
22
23 Application.run TestForm.new
$ vim winform_blackmagic.rb
1 cms = ContextMenuStrip.new
2 cms.opening do
3 cms.items.clear
4 Dir.glob("hoge_*.rb").each do |file|
5 item = ToolStripMenuItem.new "#{file}"
6 cms.items.add item
7 end
8 end
9 self.ContextMenuStrip = cms
$ touch hoge_{1,2,3,4,5}.rb右クリックをすると、コンテキストメニューが表示される。
$ vim winform_blackmagic.rb
1 cms = ContextMenuStrip.new
2 cms.opening do
3 cms.items.clear
4 Dir.glob("eval_*.rb").each do |file|
5 item = ToolStripMenuItem.new "#{file}"
6 item.click do
7 begin
8 eval File.open(file) {|f| f.read}
9 rescue Exception => e
10 MessageBox.show e
11 end
12 end
13 cms.items.add item
14 end
15 end
16 self.ContextMenuStrip = cms
$ vim eval_msg.rb
1 MessageBox.show "hello"
$ vim eval_add_button.rb
1 self.text = "Hacked Form"
2 @button = System::Windows::Forms::Button.new
3 @button.text = "Hacked Button"
4 @button.click { MessageBox.show "Hacked!!" }
5 self.controls.add @button
$ vim hello.cs
1 using System;
2
3 public class Program
4 {
5 static public void Main()
6 {
7 Console.WriteLine("hogehoge");
8 }
9 }
$ mcs hello.cs
$ mono hello.exe
hogehoge
$ vim form.cs
1 using System;
2 using System.Windows.Forms;
3
4 public class Program
5 {
6 static public void Main()
7 {
8 Application.Run(new Hello());
9 }
10 }
11
12 public class Hello : Form
13 {
14 public Hello()
15 {
16 Text = "Hello World";
17 }
18 }
$ mcs form.cs
form.cs(2,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings
shell returned 1
って書いてあるのに、実行してみると・・・mcs hello.cs -pkg:dotnet ( .NET 1.1 アセンブリの場合)gmcs hello.cs -pkg:dotnet (.NET 2.0 アセンブリの場合)
Package dotnet was not found in the pkg-config search path.
Perhaps you should add the directory containing `dotnet.pc'
to the PKG_CONFIG_PATH environment variable
No package 'dotnet' found
error CS8027: Error running pkg-config. Check the above output.
$ mcs -r:System.Windows.Forms.dll form.cs
$ mono form.exe
$ find / -name "dotnet.pc"
/Library/Frameworks/Mono.framework/Versions/2.4.2.3/lib/pkgconfig/dotnet.pc
$ vim ~/.profile
export PKG_CONFIG_PATH=/Library/Frameworks/Mono.framework/Versions/2.4.2.3/lib/pkgconfig
$ source ~/.profile
$ gmcs form.cs -pkg:dotnet今度はコンパイルOK。これでアセンブリの指定は必要なくなった。
$ mono ../ironruby-0.9.0/bin/ir.exe -v
IronRuby 0.9.0.0 on .NET 2.0.0.0
$ mono ../ironruby-0.9.0/bin/ir.exe -e 'puts "hello"'
hello
$ vim winform.rb
1 require 'System'
2 require 'System.Windows.Forms'
3
4 Form = System::Windows::Forms::Form
5 Application = System::Windows::Forms::Application
6
7 class TestForm < Form
8 def initialize
9 self.Text = "Hello World Form"
10 end
11 end
12
13 Application.run TestForm.new
で動きましたとさ。
$ mono ../ironruby-0.9.0/bin/ir.exe winform.rb