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!

Ray L. 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…

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: [email protected]
[mailto:[email protected]] On Behalf Of Ray L.
Sent: Thursday, May 13, 2010 7:15 AM
To: [email protected]
Subject: Re: [Ironruby-core] How to transfer scriptscrope to a
RubyCommandLine

Ray L. wrote:

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
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

Tomas M. 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.
tomasm.net). The APIs
in Microsoft.Hosting.Shell are mostly legacy and I wouldn’t recommend
using them.

Tomas

I 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
Exposing global variables in IronPython – The Stochastic Game)

I can get the global variables via import something, but to ironruby
whatever require or include, I can not import a global variables.

Tomas M. 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.
tomasm.net). The APIs
in Microsoft.Hosting.Shell are mostly legacy and I wouldn’t recommend
using them.

Tomas

Hi, 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 L.

Tomas M. 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.
tomasm.net). The APIs
in Microsoft.Hosting.Shell are mostly legacy and I wouldn’t recommend
using them.

Tomas

Thanks 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

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.
tomasm.net). The APIs
in Microsoft.Hosting.Shell are mostly legacy and I wouldn’t recommend
using them.

Tomas