Newbie questions regarding IronRuby in Silverlight

Hi Guys,

How do we, for example, use BigDecimal in IronRuby within a Silverlight
application? When we just require ‘bigdecimal’, we get an error saying
that file can’t be found. Do we have to add that and other ruby
standard library files to our application and if so, where do we put
them?

Note that we are actually developing a standard (non-dynamic) C#
Silverlight application (and hence are not using Chiron) and wish merely
to execute ruby scripts client-side at various times. We would like
these scripts to be split into different files, for obvious reasons. We
envisage that certain files (i.e. standard library and other non
changing code) may well be bound into the xap file somehow and other
files may well be dynamically obtained from the back-end.

So far, we’ve been able to execute ruby files deployed as “Build Action:
Resource” in VS2008 but, we have not, as yet, been able to get one file
to require another in a similar manner to the Chiron demos in IronRuby
0.9.1. (i.e. app.rb requires Silverlight.rb).

Any help would be greatly appreciated,

Thanks,

Zoltan.

I guess you will need to add the path to the libs directory when
creating
the XAP file.
When you create a XAP file with Chiron, there is a /path switch where
you
can pass semi-colon separated values with paths to include in the XAP
file.
Something like:
chr /z:myfile.xap /path:c:\IronRuby\libs

Have you tried that?

All the best,
Shay.


Shay F.
Author of IronRuby Unleashed
http://www.IronShay.com
Follow me: http://twitter.com/ironshay

But that will include all the files and gems you have installed on your
machine for ironruby.
It might be a better idea to copy the ruby files you need into a folder
in
your project.
You can use them as an embedded resource and then execute their code in
order to require them
ExecuteScript does that for you.

If you want to use the plain ruby require syntax then you can include
them
in the root folder of what gets included in the xap. If your Silverlight
application is a DynamicApplication then you have the necessary PAL
loaded
and you can use plain require statements


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

There are two ways to accomplish this, by adding the script files to the
XAP, or downloading them off the web-server:

(1) As Ivan described, you can copy any needed Ruby libraries to your
project and include them in the XAP through Visual Studio. As long as
your hosting the DLR correctly in Silverlight to allow for file-system
access to look inside the XAP, “require” will just work:

ScriptRuntimeSetup setup =
Microsoft.Scripting.Silverlight.DynamicEngine.CreateRuntimeSetup();
ScriptRuntime runtime = new ScriptRuntime();
ScriptEngine engine = runtime.GetEngine(“Ruby”);
engine.Execute(“require ‘bigdecimal’”);

(2) The latest release (0.9.1) also let you automatically download
scripts by just placing a

Then you can use it in your app without putting it in the XAP. Then you
can just put the whole Ruby standard library on your web-server, and the
app will only use what you tell it to. More info/documentation this
model:
http://jimmy.schementi.com/silverlight/sl-back-to-just-text.pdfhttp://jimmy.schementi.com/silverlight/

To get this working in a hosted app, you’ll have to do this somewhere
when your app starts up, and then put your app code inside the
inner-most lambda:

        var appManifest = new DynamicAppManifest();
        var langConfig = 

DynamicLanguageConfig.Create(appManifest.Assemblies);
var scriptTags = new DynamicScriptTags(LanguagesConfig);
LanguagesConfig.DownloadLanguages(appManifest, () => {
ScriptTags.DownloadExternalCode(() => {
// all your app code using any tags
goes here!
});
});

This will be encapsulated in one method on DynamicApplication in the
future, so let me know (if you do try this way) if you run into any
problems.

~js


From: [email protected]
[[email protected]] on behalf of Ivan Porto C.
[[email protected]]
Sent: Friday, October 02, 2009 1:20 AM
To: [email protected]
Subject: Re: [Ironruby-core] Newbie questions regarding IronRuby in
Silverlight…

But that will include all the files and gems you have installed on your
machine for ironruby.

It might be a better idea to copy the ruby files you need into a folder
in your project.
You can use them as an embedded resource and then execute their code in
order to require them
ExecuteScript does that for you.

If you want to use the plain ruby require syntax then you can include
them in the root folder of what gets included in the xap. If your
Silverlight application is a DynamicApplication then you have the
necessary PAL loaded and you can use plain require statements


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

On Fri, Oct 2, 2009 at 10:05 AM, Shay F.
<[email protected]mailto:[email protected]> wrote:
I guess you will need to add the path to the libs directory when
creating the XAP file.
When you create a XAP file with Chiron, there is a /path switch where
you can pass semi-colon separated values with paths to include in the
XAP file.
Something like:
chr /z:myfile.xap /path:c:\IronRuby\libs

Have you tried that?

All the best,
Shay.


Shay F.
Author of IronRuby Unleashed
http://www.IronShay.com
Follow me: http://twitter.com/ironshay

On Fri, Oct 2, 2009 at 9:45 AM, Zoltan Toth
<[email protected]mailto:[email protected]> wrote:
Hi Guys,

How do we, for example, use BigDecimal in IronRuby within a Silverlight
application? When we just require ‘bigdecimal’, we get an error saying
that file can’t be found. Do we have to add that and other ruby
standard library files to our application and if so, where do we put
them?

Note that we are actually developing a standard (non-dynamic) C#
Silverlight application (and hence are not using Chiron) and wish merely
to execute ruby scripts client-side at various times. We would like
these scripts to be split into different files, for obvious reasons. We
envisage that certain files (i.e. standard library and other non
changing code) may well be bound into the xap file somehow and other
files may well be dynamically obtained from the back-end.

So far, we’ve been able to execute ruby files deployed as “Build Action:
Resource” in VS2008 but, we have not, as yet, been able to get one file
to require another in a similar manner to the Chiron demos in IronRuby
0.9.1. (i.e. app.rb requires Silverlight.rb).

Any help would be greatly appreciated,

Thanks,

Zoltan.

Posted via http://www.ruby-forum.com/.


Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

However, in this case (where all you want is to use bigdecimal.rb, which
is entirely implemented in C#) you can just do this:

load_assembly ‘IronRuby.Libraries’,
‘IronRuby.StandardLibrary.BigDecimal’
Which is the entire contents of bigdecimal.rb :slight_smile:

~js


From: [email protected]
[[email protected]] on behalf of Jimmy S.
[[email protected]]
Sent: Friday, October 02, 2009 12:28 PM
To: [email protected]
Subject: Re: [Ironruby-core] Newbie questions regarding IronRuby in
Silverlight…

There are two ways to accomplish this, by adding the script files to the
XAP, or downloading them off the web-server:

(1) As Ivan described, you can copy any needed Ruby libraries to your
project and include them in the XAP through Visual Studio. As long as
your hosting the DLR correctly in Silverlight to allow for file-system
access to look inside the XAP, “require” will just work:

ScriptRuntimeSetup setup =
Microsoft.Scripting.Silverlight.DynamicEngine.CreateRuntimeSetup();
ScriptRuntime runtime = new ScriptRuntime();
ScriptEngine engine = runtime.GetEngine(“Ruby”);
engine.Execute(“require ‘bigdecimal’”);

(2) The latest release (0.9.1) also let you automatically download
scripts by just placing a

Then you can use it in your app without putting it in the XAP. Then you
can just put the whole Ruby standard library on your web-server, and the
app will only use what you tell it to. More info/documentation this
model:
http://jimmy.schementi.com/silverlight/sl-back-to-just-text.pdfhttp://jimmy.schementi.com/silverlight/

To get this working in a hosted app, you’ll have to do this somewhere
when your app starts up, and then put your app code inside the
inner-most lambda:

        var appManifest = new DynamicAppManifest();
        var langConfig = 

DynamicLanguageConfig.Create(appManifest.Assemblies);
var scriptTags = new DynamicScriptTags(LanguagesConfig);
LanguagesConfig.DownloadLanguages(appManifest, () => {
ScriptTags.DownloadExternalCode(() => {
// all your app code using any tags
goes here!
});
});

This will be encapsulated in one method on DynamicApplication in the
future, so let me know (if you do try this way) if you run into any
problems.

~js


From: [email protected]
[[email protected]] on behalf of Ivan Porto C.
[[email protected]]
Sent: Friday, October 02, 2009 1:20 AM
To: [email protected]
Subject: Re: [Ironruby-core] Newbie questions regarding IronRuby in
Silverlight…

But that will include all the files and gems you have installed on your
machine for ironruby.

It might be a better idea to copy the ruby files you need into a folder
in your project.
You can use them as an embedded resource and then execute their code in
order to require them
ExecuteScript does that for you.

If you want to use the plain ruby require syntax then you can include
them in the root folder of what gets included in the xap. If your
Silverlight application is a DynamicApplication then you have the
necessary PAL loaded and you can use plain require statements


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

On Fri, Oct 2, 2009 at 10:05 AM, Shay F.
<[email protected]mailto:[email protected]> wrote:
I guess you will need to add the path to the libs directory when
creating the XAP file.
When you create a XAP file with Chiron, there is a /path switch where
you can pass semi-colon separated values with paths to include in the
XAP file.
Something like:
chr /z:myfile.xap /path:c:\IronRuby\libs

Have you tried that?

All the best,
Shay.


Shay F.
Author of IronRuby Unleashed
http://www.IronShay.com
Follow me: http://twitter.com/ironshay

On Fri, Oct 2, 2009 at 9:45 AM, Zoltan Toth
<[email protected]mailto:[email protected]> wrote:
Hi Guys,

How do we, for example, use BigDecimal in IronRuby within a Silverlight
application? When we just require ‘bigdecimal’, we get an error saying
that file can’t be found. Do we have to add that and other ruby
standard library files to our application and if so, where do we put
them?

Note that we are actually developing a standard (non-dynamic) C#
Silverlight application (and hence are not using Chiron) and wish merely
to execute ruby scripts client-side at various times. We would like
these scripts to be split into different files, for obvious reasons. We
envisage that certain files (i.e. standard library and other non
changing code) may well be bound into the xap file somehow and other
files may well be dynamically obtained from the back-end.

So far, we’ve been able to execute ruby files deployed as “Build Action:
Resource” in VS2008 but, we have not, as yet, been able to get one file
to require another in a similar manner to the Chiron demos in IronRuby
0.9.1. (i.e. app.rb requires Silverlight.rb).

Any help would be greatly appreciated,

Thanks,

Zoltan.

Posted via http://www.ruby-forum.com/.


Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

Many thanks to all of your input. Much appreciated!
I’ll try your suggestions over the next few days and let you know the
results.

Thanks again,

Zoltan.

Once again thanks, we were able to get things working. Please note that
we have offline requirements that require us to deploy the portions of
the ruby standard library that we require, within our Silverlight
application.

My only other question is why does IronRuby ship with what appears to be
two versions of the Ruby standard library? There appears to be a
standard implementation (i.e. \lib\ruby\1.8 for IronRuby 0.9.1) that
uses ruby scripts and there also appears to be an implementation that
calls into the CLR (i.e. \lib\IronRuby) in order to do its stuf. Do we
have a choice of which to use or do we need to deploy both?

Many thanks for your help.

Zoltan.

I’ve been pondering the exact same thing - it is a touch confusing.

There are not two copies, one is ruby stdlib, and one is IronRuby’s
own lib. The ruby stdlib contains pieces implemented in ruby, as well
as C. In IronRuby we ported all the C stuff to C# (that’s what
IronRuby.Libraries.dll is), and redistribute the ruby code. So both
directories are all part of the standard library.

For Silverlight, I would suggest you only deploy the files that you
use; the entire stdlib is fairly large.

~Jimmy
Sent from my phone

It is not possible to completely and reliably automate such task in
general. You could run your application and see what files are being
required. You can monkey-patch Kernel#require and load so that they log
the files being required. However you would need to exercise all code
paths that might possibly load a file to get the full list.

Tomas

If you want to give it a try anyways you can also pass -ET LOAD_COMPILED
command line options to ir.exe to see what files are being loaded. For
example:

D:\M3\Merlin\Main\Languages\Ruby>rbx -ET LOAD_COMPILED
D:\M3\Merlin\Main\Languages\Ruby\Scripts\bin\iirb
LOAD_COMPILED: 1:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb.rb
LOAD_COMPILED: 2:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/e2mmap.rb
LOAD_COMPILED: 3:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/init.rb
LOAD_COMPILED: 4:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/context.rb
LOAD_COMPILED: 5:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/workspace.rb
LOAD_COMPILED: 6:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/extend-command.rb
LOAD_COMPILED: 7:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/ruby-lex.rb
LOAD_COMPILED: 8:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/slex.rb
LOAD_COMPILED: 9:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/notifier.rb
LOAD_COMPILED: 10:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/output-method.rb
LOAD_COMPILED: 11:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/ruby-token.rb
LOAD_COMPILED: 12:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/input-method.rb
LOAD_COMPILED: 13:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/site_ruby/1.8/readline.rb
LOAD_COMPILED: 14:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/site_ruby/1.8/rbreadline.rb
LOAD_COMPILED: 15: D:/M3/Merlin/Main/Languages/Ruby/libs/etc.rb
LOAD_COMPILED: 16: D:/M3/Merlin/Main/Languages/Ruby/libs/Win32API.rb
LOAD_COMPILED: 17:
D:/M3/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/irb/locale.rb
irb(main):001:0>

Tomas

Is anyone aware of a tool that can recursively detect (and possibly
extract) ruby dependencies given a top level .rb, or set of .rb files? I
could see it being a tedious process to discover manually what
components of the standard library were used by any given application.

Well, if you have good test coverage for your ruby code, that should be
doable :slight_smile: Probably monkey patching and good tests is the way to go then.
In your journeys through the Ruby standard libraries, have you noticed
that they tend to require/load dependencies dynamically (i.e. based on
magic strings a static automation tool could not follow) fairly
frequently? Or is it rather rare? Also, would it be feasible to host the
standard libraries on the web and rig up the hosting environment to fall
back to a web server if the libraries being dynamically loaded weren’t
properly deployed with the app?