[Ironruby-core] IronRuby, Silverlight and executing code dynamically in the browser

Jonas Follesø jonas at follesoe.no
Thu Jul 22 09:13:40 EDT 2010

I'm toying around with the idea of a simple in-browser "coding environment"
for IronRuby, think JSFiddle but for DLR languages. I'm fairly new to
IronRuby, but have lots of Silverlight experience. I have gotten the basics
up and running, but have ran into a couple issues.

My initial idea was to use the virtual file system the IronPython
Silverlight Host creates when it downloads files included using <script>
tags. However, turns out this virtual file system is read-only, so I cannot
write new Ruby files after the application is loaded.

My second idea was to simply use the DynamicEngine and simply execute the
code. The code I've written looks something like this:

            def run_tests
                code = window.eval("codeEditor.getCode()").to_s
                test = window.eval("testEditor.getCode()").to_s

                puts code

                    dyneng = DynamicEngine.new
                    engine = dyneng.runtime.get_engine("ruby")
                    scope = dyneng.create_scope

                    errorFormatter = ErrorFormatter::Sink.new

                    resultCode =
                    resultTest =

                    puts resultCode
                    puts resultTest
                rescue => ex
                    puts ex.to_s

It basically gets two pieces of Ruby code, then creates a new engine,
creates script  source, compiles it, and then executes it. If I do this with
valid Ruby code everything works as expected. However, if I try to execute
invalid code I was expecting my error handler to execute. But this does not
happen. All I get is an error in the FireBug console saying:

"Error calling method on NPObject!"

So does anyone have suggestions on how to handle errors when executing the
code dynamically in the browser. Secondly, does anyone have suggestions for
alternative approaches to implementing this - i.e. make the virtual file
system writable (write to isolated storage perhaps?).

Best regards,
Jonas Follesø
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100722/71809aea/attachment.html>

More information about the Ironruby-core mailing list