<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v =
"urn:schemas-microsoft-com:vml" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word" xmlns:m =
"http://schemas.microsoft.com/office/2004/12/omml"><HEAD><TITLE>Accessing IronRuby method from C#</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16587" name=GENERATOR>
<STYLE>@font-face {
        font-family: Cambria Math;
}
@font-face {
        font-family: Calibri;
}
@font-face {
        font-family: Tahoma;
}
@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.0in 1.0in 1.0in; }
P.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif"
}
LI.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif"
}
DIV.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
P {
        FONT-SIZE: 12pt; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; FONT-FAMILY: "Times New Roman","serif"; mso-style-priority: 99; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto
}
SPAN.EmailStyle18 {
        COLOR: #1f497d; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal-reply
}
.MsoChpDefault {
        FONT-SIZE: 10pt; mso-style-type: export-only
}
DIV.Section1 {
        page: Section1
}
</STYLE>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=EN-US vLink=purple link=blue>
<DIV dir=ltr align=left><FONT face=Tahoma color=#0000ff size=2><SPAN
class=523334308-24012008>Thanks John for your reply!</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Tahoma color=#0000ff size=2><SPAN
class=523334308-24012008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Tahoma color=#0000ff size=2><SPAN
class=523334308-24012008>Still not getting my method calls to work from C# with
lambda either:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Tahoma color=#0000ff size=2><SPAN
class=523334308-24012008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008>[TestMethod]</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008>public void AccessMethod3()</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008>{</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008> ExecuteString(@"</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008> $m = lambda
do |par|</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008>
puts 'Hello from lambda: ' + par</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008>
end</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008> ");</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008> Proc m = (Proc) GetGlobalVar("m");
// OK</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff size=2><SPAN class=523334308-24012008><FONT
face="Courier New"> Operations.Call(m, "abc"); //
<STRONG><FONT color=#ff0000>InvalidCast: Cannot cast Proc to
BlockParam</FONT></STRONG></FONT></SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008> Delegate1 d =
Operations.ConvertTo<Delegate1>(m); // OK</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff size=2><SPAN class=523334308-24012008><FONT
face="Courier New"> d("abc"); // <STRONG><FONT
color=#ff0000>InvalidCast: Cannot cast Proc to
BlockParam</FONT></STRONG></FONT></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face="Courier New" color=#0000ff size=2><SPAN
class=523334308-24012008>}</SPAN></FONT></DIV>
<DIV><FONT face=Tahoma color=#0000ff size=2></FONT> </DIV>
<DIV dir=ltr align=left><B><SPAN lang=fi><FONT face=Tahoma><FONT size=2><SPAN
class=523334308-24012008>R</SPAN>obert
Brotherus<BR></FONT></FONT></SPAN></B><SPAN lang=fi><FONT face=Tahoma
size=2>Software architect<BR></FONT><B><FONT face=Tahoma size=2>Napa
Ltd<BR></FONT></B><FONT face=Tahoma size=2>Tammasaarenkatu 3, Helsinki
FI-00180<BR>P.O.Box 470, Helsinki
FI-00181<BR><BR>Tel. +358
9 22 813 1<BR>Direct. +358 9 22 813
611<BR>GSM +358 45 11 456
02 <BR>Fax. +358 9 22 813
800<BR><BR>Email: </FONT></SPAN><A href="mailto:Robert.Brotherus@napa.fi"><SPAN
lang=fi><U><FONT face=Tahoma color=#0000ff
size=2>Robert.Brotherus@napa.fi</FONT></U></SPAN></A><SPAN lang=fi><FONT
face=Tahoma size=2> <BR></FONT></SPAN><A href="http://www.napa.fi/"><SPAN
lang=fi><U><FONT face=Tahoma color=#0000ff
size=2>www.napa.fi</FONT></U></SPAN></A><SPAN lang=fi><BR></SPAN></DIV>
<DIV> </DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] <B>On Behalf Of </B>John Lam
(DLR)<BR><B>Sent:</B> 23. tammikuuta 2008 16:59<BR><B>To:</B>
ironruby-core@rubyforge.org<BR><B>Subject:</B> Re: [Ironruby-core] Accessing
IronRuby method from C#<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=Section1>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'">Today
we don’t support unbound methods yet (what you are trying to do via the call to
the method function). If you want first class functions, Proc.new and lambda
work just fine today.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'">I’ll
let Tomas chime in on AccessMethod2().<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'">Thanks,<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'">-John<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"><o:p> </o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"><o:p> </o:p></SPAN></P>
<DIV
style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: medium none; PADDING-LEFT: 4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: blue 1.5pt solid; PADDING-TOP: 0in; BORDER-BOTTOM: medium none">
<DIV>
<DIV
style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: medium none; PADDING-TOP: 3pt; BORDER-BOTTOM: medium none">
<P class=MsoNormal><B><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">From:</SPAN></B><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">
ironruby-core-bounces@rubyforge.org [mailto:ironruby-core-bounces@rubyforge.org]
<B>On Behalf Of </B>Robert Brotherus<BR><B>Sent:</B> Tuesday, January 22, 2008
8:20 AM<BR><B>To:</B> ironruby-core@rubyforge.org<BR><B>Subject:</B>
[Ironruby-core] Accessing IronRuby method from
C#<o:p></o:p></SPAN></P></DIV></DIV>
<P class=MsoNormal><o:p> </o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">Greetings to the
mighty IronRuby experts from a humble developer! :-)</SPAN><SPAN lang=FI>
</SPAN><o:p></o:p></P>
<P><SPAN lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">I
am testing the latest CVS snapshot (v. 73, downloaded an hour ago) of
IronRuby.</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">We
are evaluating IronRuby for possible usage in WPF project.
</SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">First, I want to
test a simple case of defining a method in Ruby and calling the method later
from C#.</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">Below I copy a test
program that tries this in two ways (methods AccessMethod1 and AccessMethod2).
</SPAN><BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">Both attempts fail
with exceptions that are written as comments in the code.</SPAN><SPAN lang=FI>
</SPAN><o:p></o:p></P>
<P><SPAN lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">I
understand that the DLR and IronRuby are in a flux at the moment but I still
suppose there must be some working way to perform such trivial interop
task...?</SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">Thanks in
advance!</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><B><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">Robert
Brotherus<BR></SPAN></B><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">Software
architect<BR><B>Napa Ltd</B></SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><B><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">---------------------</SPAN></B><SPAN
lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">using</SPAN><SPAN
lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> System;</SPAN>
<BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">using</SPAN><SPAN
lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
System.Collections.Generic;</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">using</SPAN><SPAN
lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> System.Linq;</SPAN>
<BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">using</SPAN><SPAN
lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> System.Text;</SPAN>
<BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">using</SPAN><SPAN
lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
Microsoft.Scripting;</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">using</SPAN><SPAN
lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
Microsoft.Scripting.Hosting;</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">using</SPAN><SPAN
lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
Ruby.Runtime;</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">using</SPAN><SPAN
lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
Ruby.Builtins;</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">namespace</SPAN><SPAN
lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
IronRubyTests</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> <SPAN
style="COLOR: blue">class</SPAN> <SPAN
style="COLOR: #2b91af">Program</SPAN></SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> {</SPAN>
<BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">private</SPAN> <SPAN
style="COLOR: #2b91af">IScriptEnvironment</SPAN> _scriptRuntime;</SPAN>
<BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN
style="COLOR: #2b91af">IScriptEnvironment</SPAN>
ScriptRuntime { <SPAN
style="COLOR: blue">get</SPAN> { <SPAN style="COLOR: blue">return</SPAN> <SPAN
style="COLOR: blue">this</SPAN>._scriptRuntime; } }</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN
style="COLOR: #2b91af">IScriptEngine</SPAN>
RubyEngine
{ <SPAN style="COLOR: blue">get</SPAN> { <SPAN style="COLOR: blue">return</SPAN>
ScriptRuntime.GetEngine(<SPAN style="COLOR: blue">typeof</SPAN>(<SPAN
style="COLOR: #2b91af">RubyContext</SPAN>)); } }</SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN
style="COLOR: #2b91af">ObjectOperations</SPAN>
Operations
{ <SPAN style="COLOR: blue">get</SPAN> { <SPAN style="COLOR: blue">return</SPAN>
RubyEngine.Operations; } }</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN
style="COLOR: #2b91af">RubyExecutionContext</SPAN>
ExecutionContext { <SPAN style="COLOR: blue">get</SPAN> {
<SPAN style="COLOR: blue">return</SPAN> Ruby.<SPAN
style="COLOR: #2b91af">IronRuby</SPAN>.GetExecutionContext(RubyEngine); }
}</SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN
style="COLOR: #2b91af">IAttributesCollection</SPAN>
GlobalItems { <SPAN
style="COLOR: blue">get</SPAN> { <SPAN style="COLOR: blue">return</SPAN>
ExecutionContext.GlobalScope.Dict; } }</SPAN><SPAN lang=FI>
</SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">delegate</SPAN> <SPAN style="COLOR: blue">void</SPAN>
<SPAN style="COLOR: #2b91af">TestDelegate</SPAN>();</SPAN><SPAN lang=FI>
</SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: blue">void</SPAN>
Main(<SPAN style="COLOR: blue">string</SPAN>[] args)</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">new</SPAN> <SPAN
style="COLOR: #2b91af">Program</SPAN>().RunAllTests();</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> Program()</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">this</SPAN>._scriptRuntime = Ruby.<SPAN
style="COLOR: #2b91af">IronRuby</SPAN>.CreateRuntime();</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">void</SPAN>
RunAllTests()</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: #2b91af">List</SPAN><<SPAN
style="COLOR: #2b91af">TestDelegate</SPAN>> tests = <SPAN
style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">List</SPAN><<SPAN
style="COLOR: #2b91af">TestDelegate</SPAN>> {</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">new</SPAN> <SPAN
style="COLOR: #2b91af">TestDelegate</SPAN>(SimpleTests), <SPAN
style="COLOR: blue">new</SPAN> <SPAN
style="COLOR: #2b91af">TestDelegate</SPAN>(AccessMethod1), <SPAN
style="COLOR: blue">new</SPAN> <SPAN
style="COLOR: #2b91af">TestDelegate</SPAN>(AccessMethod2)</SPAN> <BR><SPAN
lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
};</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">foreach</SPAN> (<SPAN
style="COLOR: #2b91af">TestDelegate</SPAN> test <SPAN
style="COLOR: blue">in</SPAN> tests)</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: #2b91af">Console</SPAN>.WriteLine(<SPAN
style="COLOR: #a31515">"================== EXECUTING: {0}
===================="</SPAN>, test.Method.Name);</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">try</SPAN> { test(); }</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">catch</SPAN> (<SPAN
style="COLOR: #2b91af">Exception</SPAN> ex) { <SPAN
style="COLOR: #2b91af">Console</SPAN>.WriteLine(ex); }</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN
style="COLOR: #2b91af">IScriptScope</SPAN> ExecuteString(<SPAN
style="COLOR: blue">string</SPAN> code)</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">return</SPAN> ScriptRuntime.ExecuteSourceUnit(</SPAN>
<BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
RubyEngine.CreateScriptSourceFromString(code)); </SPAN><BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">void</SPAN>
SetGlobalVar(<SPAN style="COLOR: blue">string</SPAN> varName, <SPAN
style="COLOR: blue">object</SPAN> value)</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
ExecutionContext.GlobalVariables[<SPAN
style="COLOR: #2b91af">SymbolTable</SPAN>.StringToId(varName)] = value;</SPAN>
<BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">object</SPAN>
GetGlobalVar(<SPAN style="COLOR: blue">string</SPAN> varName)</SPAN> <BR><SPAN
lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">return</SPAN> ExecutionContext.GlobalVariables[<SPAN
style="COLOR: #2b91af">SymbolTable</SPAN>.StringToId(varName)];</SPAN> <BR><SPAN
lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">object</SPAN>
GetGlobalConst(<SPAN style="COLOR: blue">string</SPAN> name)</SPAN> <BR><SPAN
lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">return</SPAN> GlobalItems.SymbolAttributes[<SPAN
style="COLOR: #2b91af">SymbolTable</SPAN>.StringToId(name)];</SPAN> <BR><SPAN
lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">void</SPAN>
SimpleTests()</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
ExecuteString(<SPAN style="COLOR: #a31515">"puts 'RUBY SAYS HELLO'"</SPAN>);
<SPAN style="COLOR: green">// OK</SPAN></SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
SetGlobalVar(<SPAN style="COLOR: #a31515">"x"</SPAN>, 666); <SPAN
style="COLOR: green">// OK</SPAN></SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
ExecuteString(<SPAN style="COLOR: #a31515">"$y=555"</SPAN>); <SPAN
style="COLOR: green">// OK</SPAN></SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
ExecuteString(<SPAN style="COLOR: #a31515">"puts \"ruby: $x = #{$x}\""</SPAN>);
<SPAN style="COLOR: green">// OK</SPAN></SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">void</SPAN>
AccessMethod1()</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: green">// Following fails with
System.MissingMethodException: undefined local variable or method 'method' for
main:Object</SPAN></SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
ExecuteString(<SPAN style="COLOR: #a31515">@"</SPAN></SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
def sayHello </SPAN><BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
puts 'Hello from method!' </SPAN><BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
end</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
$m = method(:sayHello)</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
"</SPAN><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">);</SPAN><SPAN lang=FI>
</SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: green">// Get the method object:</SPAN></SPAN> <BR><SPAN
lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">object</SPAN> m = GetGlobalVar(<SPAN
style="COLOR: #a31515">"m"</SPAN>);</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: green">// Here call the method, etc.</SPAN></SPAN> <BR><SPAN
lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">void</SPAN>
AccessMethod2()</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
{</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
ExecuteString(<SPAN style="COLOR: #a31515">@"</SPAN></SPAN><SPAN lang=FI>
</SPAN><BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
module MyMethods</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
def sayHello </SPAN><BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
puts 'Hello from method!' </SPAN><BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
end</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
end</SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'">
"</SPAN><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">);</SPAN><SPAN lang=FI>
</SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: #2b91af">RubyModule</SPAN> myModule = (<SPAN
style="COLOR: #2b91af">RubyModule</SPAN>) GetGlobalConst(<SPAN
style="COLOR: #a31515">"MyMethods"</SPAN>); <SPAN style="COLOR: green">//
OK</SPAN></SPAN> <BR><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: blue">object</SPAN> sayHello =
Operations.GetMember(myModule, <SPAN style="COLOR: #a31515">"sayHello"</SPAN>);
<SPAN style="COLOR: green">// Fails at Assertion at
ActionBinber.UpdateSiteAndExecute()</SPAN></SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<SPAN style="COLOR: green">// Here call the method, etc.</SPAN></SPAN> <BR><SPAN
lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
}</SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> } <SPAN
style="COLOR: green">// class</SPAN></SPAN><SPAN lang=FI> </SPAN><o:p></o:p></P>
<P><SPAN lang=FI style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">} <SPAN
style="COLOR: green">// namespace</SPAN></SPAN><SPAN lang=FI>
</SPAN><o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P></DIV></DIV></BODY></HTML>