Ray Linn
2010-May-13 13:22 UTC
[Ironruby-core] How to transfer scriptscrope to a RubyCommandLine
I found Ironruby 1.0 change a lot for some APIs, at previous version I can create a rubycommandline via C# like this IronRuby.Hosting.RubyCommandLine rubycommandline = new RubyCommandLine(new IronRuby.Runtime.RubyContext(ScriptDomainManager.CurrentManager)); but now the construction accept zero parameters, so How transfer a scriptscope to RubyCommandLine..? I used debug to verbose the instance of RubyCommandLine, its scriptscope is always null! -- Posted via http://www.ruby-forum.com/.
Ray Linn
2010-May-13 14:15 UTC
[Ironruby-core] How to transfer scriptscrope to a RubyCommandLine
Ray Linn wrote:> I found Ironruby 1.0 change a lot for some APIs, at previous version > > I can create a rubycommandline via C# like this > > IronRuby.Hosting.RubyCommandLine rubycommandline = new > RubyCommandLine(new > IronRuby.Runtime.RubyContext(ScriptDomainManager.CurrentManager)); > > but now the construction accept zero parameters, so How transfer a > scriptscope to RubyCommandLine..? > > I used debug to verbose the instance of RubyCommandLine, its scriptscope > is always null!2nd question why global variable does not work? Form frm = new Form(); ScriptEngine ruby = IronRuby.Ruby.GetEngine(IronRuby.Ruby.CreateRuntime()); ruby.Runtime.Globals.SetVariable("frm", frm); ScriptScope scriptscope = ruby.Runtime.CreateScope(); ScriptSource script = this.scriptengine.CreateScriptSourceFromFile("test.rb"); scriptscope.SetVariable("frm",frm); ruby.Execute(script.GetCode(),scriptscope); ----------------------------------------------- test.rb defined? $frm ---------but it is nil.... defied? frm it is ok... -- Posted via http://www.ruby-forum.com/.
Tomas Matousek
2010-May-13 16:29 UTC
[Ironruby-core] How to transfer scriptscrope to a RubyCommandLine
Ruby global variables are not accessible via hosting API. ScriptRuntime.Globals refers to global constants (constants defined on Object). ScriptEngine ruby = IronRuby.Ruby.CreateEngine(); ruby.Runtime.Globals.SetVariable("Bar", 2); ScritpScope scope = ruby.CreateScope(); scope.SetVariable("frm", 123); ruby.ExecuteFile("test.rb", file); where test.rb is p frm, defined?(frm), p Bar prints 123 Nil 2 frm is looked up via method_missing on the main object. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Ray Linn Sent: Thursday, May 13, 2010 7:15 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] How to transfer scriptscrope to a RubyCommandLine Ray Linn wrote:> I found Ironruby 1.0 change a lot for some APIs, at previous version > > I can create a rubycommandline via C# like this > > IronRuby.Hosting.RubyCommandLine rubycommandline = new > RubyCommandLine(new > IronRuby.Runtime.RubyContext(ScriptDomainManager.CurrentManager)); > > but now the construction accept zero parameters, so How transfer a > scriptscope to RubyCommandLine..? > > I used debug to verbose the instance of RubyCommandLine, its > scriptscope is always null!2nd question why global variable does not work? Form frm = new Form(); ScriptEngine ruby IronRuby.Ruby.GetEngine(IronRuby.Ruby.CreateRuntime()); ruby.Runtime.Globals.SetVariable("frm", frm); ScriptScope scriptscope = ruby.Runtime.CreateScope(); ScriptSource script = this.scriptengine.CreateScriptSourceFromFile("test.rb"); scriptscope.SetVariable("frm",frm); ruby.Execute(script.GetCode(),scriptscope); ----------------------------------------------- test.rb defined? $frm ---------but it is nil.... defied? frm it is ok... -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Tomas Matousek
2010-May-13 16:42 UTC
[Ironruby-core] How to transfer scriptscrope to a RubyCommandLine
Can you describe your scenario where you use the command line? What features you need? It''s relatively easy to implement a command line yourself (see e.g. http://blog.tomasm.net/2009/04/15/python-says-hello-to-ruby/). The APIs in Microsoft.Hosting.Shell are mostly legacy and I wouldn''t recommend using them. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Ray Linn Sent: Thursday, May 13, 2010 6:23 AM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] How to transfer scriptscrope to a RubyCommandLine I found Ironruby 1.0 change a lot for some APIs, at previous version I can create a rubycommandline via C# like this IronRuby.Hosting.RubyCommandLine rubycommandline = new RubyCommandLine(new IronRuby.Runtime.RubyContext(ScriptDomainManager.CurrentManager)); but now the construction accept zero parameters, so How transfer a scriptscope to RubyCommandLine..? I used debug to verbose the instance of RubyCommandLine, its scriptscope is always null! -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Ray Linn
2010-May-14 05:50 UTC
[Ironruby-core] How to transfer scriptscrope to a RubyCommandLine
Tomas Matousek wrote:> Can you describe your scenario where you use the command line? What > features you need? It''s relatively easy to implement a command line > yourself (see e.g. > http://blog.tomasm.net/2009/04/15/python-says-hello-to-ruby/). The APIs > in Microsoft.Hosting.Shell are mostly legacy and I wouldn''t recommend > using them. > > TomasI tried to store a WinForm in my script scope, and if i could transfer the script scope to the command line, that I have a chance to operate this WinForm in ruby console. As an example,I could change the title of the WinForm in command line like this: $frm.text="hello,world" seems in ironpython (refer to http://ludovic.chabant.com/devblog/2009/12/24/exposing-global-variables-in-ironpython/) I can get the global variables via import something, but to ironruby whatever require or include, I can not import a global variables. -- Posted via http://www.ruby-forum.com/.
Ray Linn
2010-May-14 05:55 UTC
[Ironruby-core] How to transfer scriptscrope to a RubyCommandLine
Tomas Matousek wrote:> Can you describe your scenario where you use the command line? What > features you need? It''s relatively easy to implement a command line > yourself (see e.g. > http://blog.tomasm.net/2009/04/15/python-says-hello-to-ruby/). The APIs > in Microsoft.Hosting.Shell are mostly legacy and I wouldn''t recommend > using them. > > TomasHi, Tomas Thanks a lot for your response. Here is an interesting example I found, but after upgrade to Ir 1.0 (.net 4) , it does not work now http://michaeldotnet.blogspot.com/2008/01/semi-practical-ironruby.html Thanks Ray Linn -- Posted via http://www.ruby-forum.com/.
Ray Linn
2010-May-14 06:24 UTC
[Ironruby-core] How to transfer scriptscrope to a RubyCommandLine
Tomas Matousek wrote:> Can you describe your scenario where you use the command line? What > features you need? It''s relatively easy to implement a command line > yourself (see e.g. > http://blog.tomasm.net/2009/04/15/python-says-hello-to-ruby/). The APIs > in Microsoft.Hosting.Shell are mostly legacy and I wouldn''t recommend > using them. > > TomasThanks Tomas At last, I found a thread you replied previously. if I used RubyContext context = GetExecutionContext(ruby); context.DefineGlobalVariable("logowin",logowin); it works as expected.. this made me a little confused, is the context.DefineGlobalVariable the same as ruby.Runtime.Globals.SetVariable the naming is just similiar and drive me crazy.. Regards Ray -- Posted via http://www.ruby-forum.com/.