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: [email protected] [[email protected]]
on behalf of Ivan Porto Carrero [[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 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
<[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 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
<[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
_______________________________________________
Ironruby-core mailing list
[email protected]<mailto:[email protected]>
http://rubyforge.org/mailman/listinfo/ironruby-core
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core