<div dir="ltr">Kevin,<br>Yep i also needed to support input output but it all goes through the "$script" variable back to the backing C# object. for now, it makes it easier to have events and debugging. all in all the end result is that i provide an "API" exposed through $script.<br>
<br>Jimmy,<br>Thanks, I clearly overlooked that.<br><br><br><div class="gmail_quote">On Fri, Nov 6, 2009 at 11:16 PM, Jimmy Schementi <span dir="ltr"><<a href="mailto:Jimmy.Schementi@microsoft.com">Jimmy.Schementi@microsoft.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div link="blue" vlink="purple" lang="EN-US"><div><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Your solution sounds fine. To answer you first question though: engine.Execute("class Script; end") will always give you nil; classes return nil when defined:</span></p>
<p><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-size: 11pt; font-family: Consolas; color: rgb(31, 73, 125);">>>> class Foo</span></p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-size: 11pt; font-family: Consolas; color: rgb(31, 73, 125);">... end</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-size: 11pt; font-family: Consolas; color: rgb(31, 73, 125);">=> nil</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">You’ll have to do this to get the actual class object:</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p><p class="MsoNormal" style="text-indent: 0.5in;"><span style="font-size: 11pt; font-family: Consolas; color: rgb(31, 73, 125);">engine.Execute("class Script; end; Script")</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">~Jimmy</span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>
<div style="border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color blue; border-width: medium medium medium 1.5pt; padding: 0in 0in 0in 4pt;"><div><div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">
<p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> <a href="mailto:ironruby-core-bounces@rubyforge.org" target="_blank">ironruby-core-bounces@rubyforge.org</a> [mailto:<a href="mailto:ironruby-core-bounces@rubyforge.org" target="_blank">ironruby-core-bounces@rubyforge.org</a>] <b>On Behalf Of </b>Dotan N.<br>
<b>Sent:</b> Friday, November 06, 2009 11:17 AM<br><b>To:</b> <a href="mailto:ironruby-core@rubyforge.org" target="_blank">ironruby-core@rubyforge.org</a><br><b>Subject:</b> [Ironruby-core] ironruby hosting as scripting engine</span></p>
</div></div><div><div></div><div class="h5"><p class="MsoNormal"> </p><div><p class="MsoNormal" style="margin-bottom: 12pt;">Hi guys sorry for the lengthy mail but i believe this is interesting since i've found a solution that someone else could use.<br>
<br>just had a session of trying to embed IR in my application.<br>I'm defining a user script which contains some initialization code and a special worker function 'execute'<br><br>this is the "user script":<br>
<br>script1.s --------------------------------------------------------<br>$script.declare "version 1"<br><br>def execute<br> $script.report "success"<br>end<br>--------------------------------------------------------<br>
<br><br>what i'm doing is setting "script" as a global variable that is a gateway to my application.<br>I've tried this way first:<br><br>wrapping script1.s with "class Script <scriopt1.s content> end"<br>
and doing Engine.Execute on it.<br><br>I expected to get a RubyObject as a result, which is the Script class.<br><br>then with the RubyObject i would do ObjectOperations.Invoke("execute"); when ever i wish.<br><br>
I had 2 problems:<br><br>1. the RubyObject was always null. any idea why?<br>2. I couldn't really define a global variable properly (i've used the $a = a trick from the forum)<br><br><br><br>eventually i've realized this solution:<br>
1. set global variable via RubyContext.DefineGlobalVariable<br>2. i run everything on my script scope and Execute script1.s directly given a ScriptScope<br>3. do InvokeMember on the ScriptScope itself<br><br><br>from googling i've noticed the solution changed a lot along time.<br>
so what is the proper way to do it? <br><br><br>Thanks!<br><br><br></p></div></div></div></div></div></div><br>_______________________________________________<br>
Ironruby-core mailing list<br>
<a href="mailto:Ironruby-core@rubyforge.org">Ironruby-core@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/ironruby-core" target="_blank">http://rubyforge.org/mailman/listinfo/ironruby-core</a><br>
<br></blockquote></div><br></div>