Using Local Variable in Silverlight

Hi All,

I’m getting an exception when I try and use the code snippet below in
Silverlight. The snippet works ok with a normal .Net app.

What I am trying to do is use a Ruby script running in my Silverlight
app to call a method that updates the text on a text block.

public delegate void LogMessageDelegate(string message);

public partial class Page : UserControl
{

private void RunScript(object sender, System.Windows.RoutedEventArgs
e)
{
ScriptHelper scriptHelper = new ScriptHelper(WriteDebugMessage);

ScriptScope scriptScope =

IronRuby.CreateRuntime().CreateScope(“IronRuby”);
scriptScope.SetVariable(“sys”, scriptHelper);
scriptScope.Execute(“sys.Log(“hello world”)”);
}

private void WriteDebugMessage(string message)
{
m_scriptDebugText.Text = message; // m_scriptDebugText is a text
block.
}
}

public class ScriptHelper
{
private event LogMessageDelegate m_logMessage;

public ScriptHelper(LogMessageDelegate logMessage)
{
m_logMessage = logMessage;
}

public void Log(string message)
{
m_logMessage(message);
}
}

The exception I get back is:

“Ruby.Runtime.RubyTopLevelScope.TopMethodMissing(Microsoft.Scripting.Runtime.CodeContext,
System.Object, Ruby.Runtime.BlockParam, Microsoft.Scripting.SymbolId,
System.Object[])”

Is there a better approach to interacting between Silverlight UI
elements and the Ruby script? I’m not using any HTML as the whole
interface is built of SilverLight controls.

Regards,

Aaron

What’s the exception type and message? Could you please file this as a
bug?
It seems it should just work.

Tomas

Tomas M. wrote:

What’s the exception type and message?

The exception type is MethodAccessException and the message is:

“Ruby.Runtime.RubyTopLevelScope.TopMethodMissing(Microsoft.Scripting.Runtime.CodeContext,
System.Object, Ruby.Runtime.BlockParam, Microsoft.Scripting.SymbolId,
System.Object[])”

Could you please file this as a bug?

I submitted a bug report on the RubyForge site but is hasn’t shown up.
Hopefully that’s just to do with it ebing moderated.

The original code snippet works if changed to:

ScriptScope scriptScope =
IronRuby.CreateRuntime().CreateScope(“IronPython”);
or
ScriptScope scriptScope =
IronRuby.CreateRuntime().CreateScope(“jscript”);

Regards,

Aaron

Oh, I know what this is. Could you verify that the method is internal in
the bits you’re using?
The method should be public and it is in the current code.

Tomas

No, I mean: Ruby.Runtime.RubyTopLevelScope.TopMethodMissing.

I’m not sure you can build successfully against Silverlight. There might
have been some changes in Silverlight that required us to change
DLR/IronRuby code since the last public release.

Tomas

Tomas M. wrote:

Oh, I know what this is. Could you verify that the method is internal in
the bits you’re using?
The method should be public and it is in the current code.

Tomas

Hi Tomas,

Do you mean the CreateScope method, i.e.
IronRuby.CreateRuntime().CreateScope(“IronRuby”)?

I was using the IronRuby version from the Silverlight DLR SDK on
http://www.codeplex.com/sdlsdk release id 14254. I don’t think the
method CreateScope could have been internal as I wouldn’t have been able
to call it?

I did attempt to build the IronRuby code from svn with the SILVERLIGHT
pre-compilation option sent but got a fair few errors so tried the SDK
version instead. I’ll give building from SVN another attempt.

Regards,

Aaron

Tomas M. wrote:

No, I mean: Ruby.Runtime.RubyTopLevelScope.TopMethodMissing.

I’m not sure you can build successfully against Silverlight. There might
have been some changes in Silverlight that required us to change
DLR/IronRuby code since the last public release.

Tomas

Hi Tomas,

I’ve checked and you are correct
Ruby.Runtime.RubyTopLevelScope.TopMethodMissing is static internal .

Any idea when the next IronRuby DLR release is likely to be? I can get
by with using JScript within Silverlight for the time being.

Thanks,

Aaron

DevHawk wrote in his blog
(http://devhawk.net/2008/07/17/IronPython+Post+20+Roadmap.aspx):

“Besides IPy 2.1 and 3.0, the other major thing we’re working on is
Visual Studio integration for IronPython … … (it would be
nice if IronRuby could leverage our efforts down the road). Like
everything else we do in this group, we’ll be publishing the VS
Integration source code up on CodePlex as early and often as we can.”

Are there any plans for a similar VS integration for IronRuby?

/Johan

Yes and as we are in a planning stage, we are extremely eager to hear
what do you guys think about IronRuby VS integration.
What features you need, how does it need to look and feel? Don’t
hesitate to express your thoughts on this subject. We want to make it
useful and so need to know what do you want and expect.

VS integration is going to be open source like IronRuby itself and I
also hope we will be able to accept contributions into it too.

Oleg

Yes.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs