I figured out that ScriptRuntime and ScriptScope are still language 
agnostic.
So if you want to host IronRuby in your application you're always 
looking at Level 2 hosting as soon as you want some communication 
between Host and IronRuby, because you need the RubyEngine.

I'm still a bit unsure of how the ScriptScope ties in to everything.

I understand that the ScriptRuntime is like the complete host for dyn 
languages and you can create a bunch of them they will always run in 
isolation.
But how does ScriptScope work because so far I've been unsuccessful in 
talking to a ScriptScope ?

Is this hosting API still too much of a moving target to really get into 
it?


Ivan Porto Carrero wrote:
> Hi,
> 
> I updated the hosting wiki page to work with the current revision. But 
> this
> raises a couple of questions.
> 
> I'm just working my way through the dlr-hosting-spec.
> And if I read it correctly then there are 3 levels of 
> hosting/integration
> possible.
> 
> Now AFAICT level 1 hosting is only supposed to work with external files,
> because for compiling to a source unit you need a different class than
> either ScriptRuntime or ScriptScope
> I was expecting when I set a variable in globals that it becomes a 
> global
> variable or do I have to access that differently?
> 
> So I tried the following bit of code:
> 
> ScriptRuntime runtime = IronRuby.CreateRuntime();
> runtime.Globals.SetVariable("version", "simplest test possible with a
> variable succeeded");
> runtime.ExecuteFile("commands.rb");
> 
> and the file commands.rb contains one line of ruby code: puts $version
> put the output of that code is nil instead of the expected string.
> 
> This returns nil. I have trouble reconciling that with what I read in 
> the
> hosting spec. Because this should be totally doable with Level 1 hosting 
> or
> am I wrong in this assumption?
> 
> When I create a ScriptRuntime shouldn't it then have a DefaultScope
> (Globals) that is language-specific to ruby because I create it with the
> static method on IronRuby?
> 
> Also for as far as i understand it a ScriptScope is like a container for
> your scripts so globals in that container are only alive in that script
> scope?
> 
> Anyway when I go and use level 2 hosting because I need the execution
> context and script engine and these are only introduced in level 2 
> hosting.
> I can set global variables and then things do work
> 
> ScriptRuntime runtime = IronRuby.CreateRuntime();
> ScriptEngine rubyengine = IronRuby.GetEngine(runtime);
> RubyExecutionContext ctx = IronRuby.GetExecutionContext(runtime);
> 
> ctx.GlobalVariables[SymbolTable.StringToId("variable")] = "simplest test
> possible with a variable succeeded";
> runtime.ExecuteSourceUnit(rubyengine.CreateScriptSourceFromString("puts
> \"#{$variable}\""));
> 
> And in the level 2 hosting sample the RubyExecutionContext seems to do 
> what
> I was expecting ScriptScope to do.
> 
> Am I reading the spec wrong ?
> 
> Cheers
> Ivan

-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to