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 Linn
Sent: Thursday, May 13, 2010 7:15 AM
To: [email protected]
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
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core