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 :)

~js
________________________________
From: ironruby-core-boun...@rubyforge.org [ironruby-core-boun...@rubyforge.org] 
on behalf of Jimmy Schementi [jimmy.scheme...@microsoft.com]
Sent: Friday, October 02, 2009 12:28 PM
To: ironruby-core@rubyforge.org
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 <script> tag on the HTML page where the Silverlight control is 
hosted. So if you did this:

<script type="text/ruby" src="path/to/rubylibs/bigdecimal.rb"></script>

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.pdf<http://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 <script src=""> 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: ironruby-core-boun...@rubyforge.org [ironruby-core-boun...@rubyforge.org] 
on behalf of Ivan Porto Carrero [i...@flanders.co.nz]
Sent: Friday, October 02, 2009 1:20 AM
To: ironruby-core@rubyforge.org
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 Carrero
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 Friedman 
<shay.fried...@gmail.com<mailto:shay.fried...@gmail.com>> 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 Friedman
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 
<li...@ruby-forum.com<mailto:li...@ruby-forum.com>> 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
Ironruby-core@rubyforge.org<mailto:Ironruby-core@rubyforge.org>
http://rubyforge.org/mailman/listinfo/ironruby-core


_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org<mailto:Ironruby-core@rubyforge.org>
http://rubyforge.org/mailman/listinfo/ironruby-core


_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to