[IronPython] IronPython and IronRuby interop with IronRuby 0.9
Michael Foord
fuzzyman at voidspace.org.uk
Sat Aug 22 17:29:01 CEST 2009
Hello all,
I've played a little bit with IronPython and IronRuby interop with the
IronRuby 0.9 binaries.
A very basic example works as expected:
IronPython 2.6 Beta 2 (2.6.0.20) on .NET 2.0.50727.4927
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> clr.AddReference('IronRuby')
>>> from IronRuby import Ruby
>>>
>>> engine = Ruby.CreateEngine()
>>> source = engine.CreateScriptSourceFromString("puts 'Hello from Ruby'")
>>> scope = engine.CreateScope()
>>>
>>> source.Execute(scope)
Hello from Ruby
>>>
However my attempts to use a Ruby library fails. The same code works
when executed from ir.exe:
>>> import clr
>>> clr.AddReference('IronRuby')
>>> clr.AddReference('Microsoft.Scripting')
>>>
>>> from Microsoft.Scripting import SourceCodeKind
>>> from IronRuby import Ruby
>>> engine = Ruby.CreateEngine()
>>> source = engine.CreateScriptSourceFromString("require 'date'",
SourceCodeKin
d.Statements)
>>> scope = engine.CreateScope()
>>> source.Execute(scope)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: no such file to load -- date
>>>
I tried adding a reference to IronRuby.Libraries to the runtime
associated with the Ruby engine (using runtime.LoadAssembly) but this
didn't help.
Requiring Ruby modules I've written myself doesn't blow-up but doesn't
populate the scriptscope they are executed in with anything. Likewise
calling engine.ExecuteFile('foo.rb') returns an empty ScriptScope.
Any ideas?
All the best,
Michael Foord
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
More information about the Ironpython-users
mailing list