[IronPython] IronPython and IronRuby interop with IronRuby 0.9
Michael Foord
fuzzyman at voidspace.org.uk
Sat Aug 22 17:45:59 CEST 2009
Hehe - well I can fish the contents of the library I required from
engine.Runtime.Globals, which seems right as I'm requiring it in the
global namespace. I'm still surprised the ScriptScope is empty.
Michael
Michael Foord wrote:
> Ok, so setting the engine search paths solves the failure to find the
> library, but the ScriptScope is still coming back empty. In the
> example below I would have expected to see 'd' in the ScriptScope.
>
> c:\Binaries\IronRuby\bin>ipy.exe interop.py
> []
>
> From this code:
>
> import clr
> clr.AddReference('IronRuby')
> clr.AddReference('Microsoft.Scripting')
>
> from System import Array
>
> paths = [r'C:\Binaries\IronRuby\lib\IronRuby',
> r'C:\Binaries\IronRuby\lib\ruby\1.8']
> array = Array[str](paths)
>
> source_code = "require 'date'\nd = Date::civil(2003, 4, 8)\n"
>
> from Microsoft.Scripting import SourceCodeKind
> from IronRuby import Ruby
> engine = Ruby.CreateEngine()
> engine.SetSearchPaths(array)
> source = engine.CreateScriptSourceFromString(source_code,
> SourceCodeKind.Statements)
> scope = engine.CreateScope()
> source.Execute(scope)
>
> print dir(scope)
>
> Michael
>
> 2009/8/22 Michael Foord <fuzzyman at voidspace.org.uk
> <mailto:fuzzyman at voidspace.org.uk>>
>
> 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
>
>
>
>
>
> --
> http://www.ironpythoninaction.com/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
More information about the Ironpython-users
mailing list